liuyu преди 4 години
родител
ревизия
03aeadec78
променени са 1 файла, в които са добавени 21 реда и са изтрити 4 реда
  1. 21 4
      app/service/trainplan.js

+ 21 - 4
app/service/trainplan.js

@@ -67,6 +67,8 @@ class TrainplanService extends CrudService {
       if (status === '1') {
         // 自动生成班级
         await this.autoclass(res, trainplanold);
+        // 将生成的班级重新将班级排班名
+        await this.autoclassname(res);
         // 发送培训计划信息通知给相应人员
         // 查询所有入库的教师
         const teachers = await this.tmodel.find({ status: '4' });
@@ -123,7 +125,7 @@ class TrainplanService extends CrudService {
           // 取得当前批次的班级数
           const classnum = batchnum.class;
           for (let i = 1; i <= classnum; i++) {
-            const newdata = { name: i + '班', number: batchnum.number, batchid: batchnum.id, termid: el.id, planid: res.id };
+            const newdata = { name: i, number: batchnum.number, batchid: batchnum.id, termid: el.id, planid: res.id };
             await this.clamodel.create(newdata);
           }
         }
@@ -149,7 +151,7 @@ class TrainplanService extends CrudService {
             // 取得当前批次的班级数
             const classnum = batchnum.class;
             for (let i = 1; i <= classnum; i++) {
-              const newdata = { name: i + '班', number: batchnum.number, batchid: batchnum.id, termid: el.id, planid: res.id };
+              const newdata = { name: i, number: batchnum.number, batchid: batchnum.id, termid: el.id, planid: res.id };
               await this.clamodel.create(newdata);
             }
           } else {
@@ -164,7 +166,7 @@ class TrainplanService extends CrudService {
               } else {
                 const classnum = batchnum.class;
                 for (let i = 1; i <= classnum; i++) {
-                  const newdata = { name: i + '班', number: batchnum.number, batchid: batchnum.id, termid: el.id, planid: res.id };
+                  const newdata = { name: i, number: batchnum.number, batchid: batchnum.id, termid: el.id, planid: res.id };
                   await this.clamodel.create(newdata);
                 }
               }
@@ -174,7 +176,7 @@ class TrainplanService extends CrudService {
               await this.clamodel.deleteMany({ termid: el.id, batchid: batchnum.id });
               const classnum = batchnum.class;
               for (let i = 1; i <= classnum; i++) {
-                const newdata = { name: i + '班', number: batchnum.number, batchid: batchnum.id, termid: el.id, planid: res.id };
+                const newdata = { name: i, number: batchnum.number, batchid: batchnum.id, termid: el.id, planid: res.id };
                 await this.clamodel.create(newdata);
               }
             }
@@ -185,5 +187,20 @@ class TrainplanService extends CrudService {
 
   }
 
+  // 将分好的班级重新编排名字
+  async autoclassname(res) {
+    // 取得所有期id
+    const tremid_res = _.map(res.termnum, 'id');
+    for (const termid of tremid_res) {
+      const classs = await this.clamodel.find({ planid: res.id, termid });
+      let i = 0;
+      for (const cla of classs) {
+        i = i + 1;
+        cla.name = i;
+        await cla.save();
+      }
+    }
+  }
+
 }
 module.exports = TrainplanService;