123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- 'use strict';
- const assert = require('assert');
- const _ = require('lodash');
- const { ObjectId } = require('mongoose').Types;
- const { CrudService } = require('naf-framework-mongoose/lib/service');
- const { BusinessError, ErrorCode } = require('naf-core').Error;
- class UploadquestionService extends CrudService {
- constructor(ctx) {
- super(ctx, 'uploadquestion');
- this.model = this.ctx.model.Uploadquestion;
- this.umodel = this.ctx.model.Roomuser;
- this.rmodel = this.ctx.model.Room;
- this.questionnairemodel = this.ctx.model.Questionnaire;
- this.lumodel = this.ctx.model.Lookuser;
- }
- // 完成度查询
- async completion(data) {
- const { type, typeid, roomid, questionnaireid } = data;
- assert(type, '缺少部分信息项');
- const datas = [];
- const answertotal = '';
- const alltotal = '';
- // 如果是期查询
- if (type === '0') {
- const rooms = await this.rmodel.find();
- for (const room of rooms) {
- let upcount = 0;
- if (room.queid) {
- upcount = await this.model.count({ roomid: room.id });
- }
- const lcount = await this.lumodel.count({ roomid: room.id });
- const newdata = { id: room.id, roomname: room.name, upcount, lcount };
- datas.push(newdata);
- }
- } else if (type === '1') {
- const ques = await this.questionnairemodel.find({ status: '1' });
- for (const elm of ques) {
- const upcount = await this.model.count({ questionnaireid: elm.id });
- const newdata = { id: elm.id, name: elm.name, upcount };
- datas.push(newdata);
- }
- }
- const newdata = { data: datas };
- return newdata;
- }
- async query({ skip, limit, ...info }) {
- const total = await this.model.count(info);
- const res = await this.model.find(info).skip(Number(skip)).limit(Number(limit));
- const data = [];
- for (const _res of res) {
- const elm = _.cloneDeep(JSON.parse(JSON.stringify(_res)));
- const stu = await this.umodel.findById(elm.userid);
- elm.username = stu.name;
- data.push(elm);
- }
- return { data, total };
- }
- }
- module.exports = UploadquestionService;
|