liuyu 4 gadi atpakaļ
vecāks
revīzija
705fd008ab
2 mainītis faili ar 24 papildinājumiem un 1 dzēšanām
  1. 23 0
      app/service/class.js
  2. 1 1
      app/service/trainplan.js

+ 23 - 0
app/service/class.js

@@ -25,6 +25,8 @@ class ClassService extends CrudService {
     const { planid, termid } = data;
     assert(planid, '计划id为必填项');
     assert(termid, '期id为必填项');
+    // 先自动生成班级
+    await this.autoclass(planid, termid);
     // 根据计划id与期id查询所有批次下的班级
     const newclass = await this.model.find({ planid, termid });
     if (!newclass) {
@@ -50,6 +52,27 @@ class ClassService extends CrudService {
     }
   }
 
+  // 自动生成班级私有方法
+  async autoclass(planid, termid) {
+    // 删除所有计划下的班级
+    await this.clamodel.deleteMany({ planid, termid });
+    // 根据批次id取得当前批次具体信息
+    const res = await this.tmodel.findById(planid);
+    if (!res) {
+      throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '全年计划信息不存在');
+    }
+    // 循环出所有班级进行添加操作
+    for (const term of res.termnum) {
+      for (const batch of term.batchnum) {
+        const classs = await batch.class;
+        for (const cla of classs) {
+          const newdata = { name: cla.name, number: cla.number, batchid: batch.id, termid: term.id, planid: res.id, type: cla.type, headteacherid: cla.headteacherid };
+          await this.clamodel.create(newdata);
+        }
+      }
+    }
+  }
+
   // 根据传入的学生列表和班级id更新学生信息
   async studentup(classid, batchid, beforestu) {
     // 循环学生id

+ 1 - 1
app/service/trainplan.js

@@ -68,7 +68,7 @@ class TrainplanService extends CrudService {
       if (status === '1') {
         // 自动生成班级
         // await this.autoclass(res, trainplanold);
-        await this.autoclassNew(res, trainplanold);
+        // await this.autoclassNew(res, trainplanold);
         // 将生成的班级重新将班级排班名
         // await this.autoclassname(res);
         // 发送培训计划信息通知给相应人员