Forráskód Böngészése

增加完成度查询

liuyu 5 éve
szülő
commit
3b55b4778d

+ 5 - 0
app/controller/uploadquestion.js

@@ -13,6 +13,11 @@ class UploadquestionController extends Controller {
     this.service = this.ctx.service.uploadquestion;
   }
 
+  // 完成度查询
+  async completion() {
+    const res = await this.service.completion(this.ctx.query);
+    this.ctx.ok({ ...res });
+  }
 
 }
 

+ 3 - 0
app/model/uploadquestion.js

@@ -21,6 +21,9 @@ const UploadquestionSchema = {
 
 const schema = new Schema(UploadquestionSchema, { toJSON: { virtuals: true } });
 schema.index({ id: 1 });
+schema.index({ termid: 1 });
+schema.index({ batchid: 1 });
+schema.index({ classid: 1 });
 schema.plugin(metaPlugin);
 
 module.exports = app => {

+ 1 - 0
app/router.js

@@ -103,6 +103,7 @@ module.exports = app => {
   router.post('uploadtask', '/api/train/uploadtask/update/:id', controller.uploadtask.update);
 
   // 学生上传问卷表设置路由
+  router.get('/api/train/uploadquestion/completion', controller.uploadquestion.completion); // 统计完成度
   router.resources('uploadquestion', '/api/train/uploadquestion', controller.uploadquestion); // index、create、show、destroy
   router.post('uploadquestion', '/api/train/uploadquestion/update/:id', controller.uploadquestion.update);
 

+ 28 - 0
app/service/uploadquestion.js

@@ -11,6 +11,34 @@ class UploadquestionService extends CrudService {
   constructor(ctx) {
     super(ctx, 'uploadquestion');
     this.model = this.ctx.model.Uploadquestion;
+    this.smodel = this.ctx.model.Student;
+  }
+
+  // 完成度查询
+  async completion(data) {
+    const { type, typeid } = data;
+    let allcount = '';
+    let answercount = '';
+    // 如果是期查询
+    if (type === '0') {
+      // 取得当前期学生总数
+      allcount = await this.smodel.count({ termid: typeid });
+      // 取得当前期学生答问卷数
+      answercount = await this.model.count({ termid: typeid });
+    } else if (type === '1') {
+      // 取得当前期学生总数
+      allcount = await this.smodel.count({ batchid: typeid });
+      // 取得当前期学生答问卷数
+      answercount = await this.model.count({ batchid: typeid });
+    } else if (type === '2') {
+      // 取得当前期学生总数
+      allcount = await this.smodel.count({ classid: typeid });
+      // 取得当前期学生答问卷数
+      answercount = await this.model.count({ classid: typeid });
+    }
+
+    const newdata = { allcount, answercount };
+    return newdata;
   }
 
 }