liuyu 4 年之前
父节点
当前提交
45fdf2b744
共有 1 个文件被更改,包括 20 次插入55 次删除
  1. 20 55
      app/service/uploadquestion.js

+ 20 - 55
app/service/uploadquestion.js

@@ -12,74 +12,39 @@ class UploadquestionService extends CrudService {
     super(ctx, 'uploadquestion');
     super(ctx, 'uploadquestion');
     this.model = this.ctx.model.Uploadquestion;
     this.model = this.ctx.model.Uploadquestion;
     this.umodel = this.ctx.model.Roomuser;
     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) {
   async completion(data) {
-    const { type, typeid, trainplanid, questionnaireid } = data;
-    assert(type && typeid && questionnaireid, '缺少部分信息项');
+    const { type, typeid, roomid, questionnaireid } = data;
+    assert(type, '缺少部分信息项');
     const datas = [];
     const datas = [];
-    let answertotal = '';
-    let alltotal = '';
+    const answertotal = '';
+    const alltotal = '';
     // 如果是期查询
     // 如果是期查询
     if (type === '0') {
     if (type === '0') {
-      const trainplan = await this.tmodel.findById(trainplanid);
-      const term = await trainplan.termnum.id(typeid);
-      const batchs = await term.batchnum;
-      for (const batch of batchs) {
-        // 取得当前期学生总数
-        const allcount = await this.smodel.count({ batchid: batch.id });
-        // 取得当前期学生答问卷数
-        const answercount = await this.model.count({ batchid: batch.id, questionnaireid });
-        let completion = (answercount / allcount * 100).toFixed(2);
-        completion = completion + '%';
-        const newdata = { id: batch.id, name: batch.name, allcount, answercount, completion };
+      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);
         datas.push(newdata);
       }
       }
-      // 取得当前期学生总数
-      alltotal = await this.smodel.count({ termid: typeid });
-      // 取得当前期学生答问卷数
-      answertotal = await this.model.count({ termid: typeid, questionnaireid });
     } else if (type === '1') {
     } else if (type === '1') {
-      const classs = await this.cmodel.find({ batchid: typeid });
-      for (const elm of classs) {
-        // 取得当前期学生总数
-        const allcount = await this.smodel.count({ classid: elm.id });
-        // 取得当前期学生答问卷数
-        const answercount = await this.model.count({ classid: elm.id, questionnaireid });
-        let completion = (answercount / allcount * 100).toFixed(2);
-        completion = completion + '%';
-        const newdata = { id: elm.id, name: elm.name, allcount, answercount, completion };
+      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);
         datas.push(newdata);
       }
       }
-      // 取得当前期学生总数
-      alltotal = await this.smodel.count({ batchid: typeid });
-      // 取得当前期学生答问卷数
-      answertotal = await this.model.count({ batchid: typeid, questionnaireid });
-    } else if (type === '2') {
-      // 取得当前期学生总数
-      const stus = await this.smodel.find({ classid: typeid });
-      for (const elm of stus) {
-        // 取得当前期学生答问卷数
-        const answer = await this.model.findOne({ studentid: elm.id, questionnaireid });
-        let completion = '';
-        if (answer) {
-          completion = '100%';
-        } else {
-          completion = '0%';
-        }
-        const newdata = { id: elm.id, name: elm.name, completion };
-        datas.push(newdata);
-      }
-      // 取得当前期学生总数
-      alltotal = await this.smodel.count({ classid: typeid });
-      // 取得当前期学生答问卷数
-      answertotal = await this.model.count({ classid: typeid, questionnaireid });
-
     }
     }
-    let completiontotal = (answertotal / alltotal * 100).toFixed(2);
-    completiontotal = completiontotal + '%';
-    const newdata = { data: datas, answertotal, alltotal, completiontotal };
+    const newdata = { data: datas };
     return newdata;
     return newdata;
   }
   }