lrf402788946 4 anos atrás
pai
commit
7cfb752e96
4 arquivos alterados com 90 adições e 42 exclusões
  1. 7 1
      app/controller/.student.js
  2. 2 1
      app/router.js
  3. 10 0
      app/service/student.js
  4. 71 40
      app/service/trainplan.js

+ 7 - 1
app/controller/.student.js

@@ -151,7 +151,13 @@ module.exports = {
     service: "arrangeNumber",
   },
   printCert: {
-    requestBody: ['ids'],
+    requestBody: ["ids"],
     service: "printCert",
   },
+  getSchoolStudent: {
+    parameters: {
+      query: { planid: "planid" },
+    },
+    service: "getSchoolStudent",
+  },
 };

+ 2 - 1
app/router.js

@@ -88,6 +88,8 @@ module.exports = app => {
     '/api/train/questionnaire/show/:id',
     controller.questionnaire.show
   );
+  // 查询学校是否上报学生
+  router.get('student', '/api/train/student/school', controller.student.getSchoolStudent);
   // 班级学生排号
   router.get('sutdent', '/api/train/student/arrangeNumber', controller.student.arrangeNumber);
 
@@ -675,5 +677,4 @@ module.exports = app => {
   router.post('task', '/api/train/task/export', controller.task.export);
   // 学生证书打印状态更改
   router.post('student', '/api/train/student/printcert', controller.student.printCert);
-
 };

+ 10 - 0
app/service/student.js

@@ -572,6 +572,16 @@ class StudentService extends CrudService {
   }
 
 
+  // 根据计划id找到学校是否上传学生
+  async getSchoolStudent({ planid }) {
+    const res = await this.model.aggregate([
+      { $match: { planid } },
+      { $group: { _id: '$schid', sum: { $sum: 1 } } },
+      { $project: { _id: 0, schid: '$_id', schnum: '$sum' } },
+    ]);
+    return res;
+  }
+
   // excel导出表头设置
   metaBx(type) {
     const header = [

+ 71 - 40
app/service/trainplan.js

@@ -69,8 +69,9 @@ class TrainplanService extends CrudService {
     if (trainplan.termnum) {
       // trainplan.termnum =
       trainplan.termnum = await this.termGetLesson(trainplan.termnum);
+      // 重新查看每个班级是否有课程
+      trainplan.termnum = this.setClassLesson(trainplan.termnum);
     }
-
     // 如果培训计划状态改为发布,发送培训计划信息,并自动生成班级
     const res = await trainplan.save();
     if (res) {
@@ -82,46 +83,47 @@ class TrainplanService extends CrudService {
         // await this.autoclassname(res);
         // 发送培训计划信息通知给相应人员
         // 查询所有入库的教师
-        const teachers = await this.tmodel.find({ status: '4' });
-        for (const teacher of teachers) {
-          const teacherid = teacher._id;
-          const _teacher = await this.umodel.findOne({
-            uid: teacherid,
-            type: '3',
-          });
-          const openid = _teacher.openid;
-          const detail = trainplan.title + '已发布,请注意查收!';
-          const date = await this.ctx.service.util.updatedate();
-          const remark = '感谢您的使用';
-          if (openid) {
-            this.ctx.service.weixin.sendTemplateMsg(
-              this.ctx.app.config.REVIEW_TEMPLATE_ID,
-              openid,
-              '您有一个新的通知',
-              detail,
-              date,
-              remark
-            );
-          }
-        }
+        // 不需要给教师发信息
+        // const teachers = await this.tmodel.find({ status: '4' });
+        // for (const teacher of teachers) {
+        //   const teacherid = teacher._id;
+        //   const _teacher = await this.umodel.findOne({
+        //     uid: teacherid,
+        //     type: '3',
+        //   });
+        //   const openid = _teacher.openid;
+        //   const detail = trainplan.title + '已发布,请注意查收!';
+        //   const date = await this.ctx.service.util.updatedate();
+        //   const remark = '感谢您的使用';
+        //   if (openid) {
+        //     this.ctx.service.weixin.sendTemplateMsg(
+        //       this.ctx.app.config.REVIEW_TEMPLATE_ID,
+        //       openid,
+        //       '您有一个新的通知',
+        //       detail,
+        //       date,
+        //       remark
+        //     );
+        //   }
+        // }
         // 查询所有学校用户
-        const schools = await this.umodel.find({ type: '2' });
-        for (const school of schools) {
-          const openid = school.openid;
-          const detail = trainplan.title + '已发布,请注意查收!';
-          const date = await this.ctx.service.util.updatedate();
-          const remark = '感谢您的使用';
-          if (openid) {
-            this.ctx.service.weixin.sendTemplateMsg(
-              this.ctx.app.config.REVIEW_TEMPLATE_ID,
-              openid,
-              '您有一个新的通知',
-              detail,
-              date,
-              remark
-            );
-          }
-        }
+        // const schools = await this.umodel.find({ type: '2' });
+        // for (const school of schools) {
+        //   const openid = school.openid;
+        //   const detail = trainplan.title + '已发布,请注意查收!';
+        //   const date = await this.ctx.service.util.updatedate();
+        //   const remark = '感谢您的使用';
+        //   if (openid) {
+        //     this.ctx.service.weixin.sendTemplateMsg(
+        //       this.ctx.app.config.REVIEW_TEMPLATE_ID,
+        //       openid,
+        //       '您有一个新的通知',
+        //       detail,
+        //       date,
+        //       remark
+        //     );
+        //   }
+        // }
       }
       // 查哪个学校schtime表没有生成,就给生成了
       const schoolList = await this.smodel.find();
@@ -195,6 +197,35 @@ class TrainplanService extends CrudService {
     }
     return termnum;
   }
+  // 设置课表模板到班级上
+  setClassLesson(termnum) {
+    // 为班级设置lessons,有的就不设置了
+    for (const t of termnum) {
+      const { batchnum } = t;
+      if (!batchnum || !_.isArray(batchnum)) {
+        this.$message.error(`第${t.term}期的批次数据错误!`);
+        continue;
+      }
+      for (const b of t.batchnum) {
+        const { class: cla, lessons: ltemplate } = b;
+        if (!cla) {
+          console.warn(`${t.term}期${b.batch}批次没有班级列表`);
+          continue;
+        }
+        if (!ltemplate) {
+          console.warn(`${t.term}期${b.batch}批次没有课表`);
+          continue;
+        }
+        for (const c of b.class) {
+          const { lessons } = c;
+          if (lessons) {
+            if (lessons.length <= 0) c.lessons = ltemplate;
+          }
+        }
+      }
+    }
+    return termnum;
+  }
 
   // 自动生成班级私有方法
   async autoclassNew(res) {