lrf402788946 4 lat temu
rodzic
commit
fd75a5deba
3 zmienionych plików z 80 dodań i 0 usunięć
  1. 22 0
      app/controller/cerconfirm.js
  2. 1 0
      app/router.js
  3. 57 0
      app/service/cerconfirm.js

+ 22 - 0
app/controller/cerconfirm.js

@@ -0,0 +1,22 @@
+'use strict';
+
+const _ = require('lodash');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose/lib/controller');
+
+// 寝室管理
+class CerconfirmController extends Controller {
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.cerconfirm;
+  }
+
+  // 一键分寝
+  async index() {
+    const res = await this.service.getStudentList(this.ctx.query);
+    this.ctx.ok({ data: res });
+  }
+
+}
+
+module.exports = CrudController(CerconfirmController, {});

+ 1 - 0
app/router.js

@@ -622,4 +622,5 @@ module.exports = app => {
     '/api/train/groupscore/opera',
     controller.groupscore.opera
   );
+  router.get('/api/train/cerconfirm', controller.cerconfirm.index);
 };

+ 57 - 0
app/service/cerconfirm.js

@@ -0,0 +1,57 @@
+'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 CerconfirmService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'cerconfirm');
+    this.uqmodel = this.ctx.model.Uploadquestion; // 上传的问卷答案
+    this.tqmodel = this.ctx.model.Termquest; // 该期的非常用问卷
+    this.stumodel = this.ctx.model.Student; // 学生
+    this.questionnairemodel = this.ctx.model.Questionnaire; // 问卷
+    // TODO考勤规则没有
+  }
+  /**
+   * 根据条件,查找学生,
+   * @param {Object} data 可能有classid,termid
+   */
+  async getStudentList(data) {
+    const { classid } = data;
+    // 根据范围查找学生列表
+    const stuList = await this.stumodel.find({ classid });
+    const stuHead = _.head(stuList);
+    // 一个学生没有就没必要继续了
+    if (!stuHead) return [];
+    const { termid } = stuHead;
+    // 找到该期需要答的特殊问卷
+    const allinnormal = await this.tqmodel.findOne({ termid });
+    let innormal = [];
+    if (allinnormal) {
+      const { questionnaireid } = allinnormal;
+      innormal = questionnaireid;
+    }
+    // 根据期id,和问卷得到学生应该答的问卷
+    const allquestionList = await this.questionnairemodel.find({ $or: [{ _id: { $in: innormal } }, { type: '0' }] }); // { type: '0', $or: [{ _id: { $in: innormal } }] }
+    const allquestionidList = allquestionList.map(i => JSON.parse(JSON.stringify(i._id))); // 整理成单纯的id数组,反正下面只要判断有没有就行
+    console.log(allquestionidList);
+    // 根据范围查找填写的问卷
+    const uqList = await this.uqmodel.find({ classid });
+    const list = [];
+    // 判断学生是否将所有问卷都答完了
+    for (const student of stuList) {
+      const answerList = uqList.filter(f => ObjectId(f.studentid).equals(student._id)).map(i => i.questionnaireid); // 该学生填写过的问卷
+      if (answerList.length > 0) {
+        const res = _.difference(allquestionidList, answerList);
+        if (res.length <= 0)list.push(student);
+      }
+
+    }
+    return list;
+  }
+}
+
+module.exports = CerconfirmService;