cheny 4 tahun lalu
induk
melakukan
ccda88c44b
5 mengubah file dengan 92 tambahan dan 58 penghapusan
  1. 4 0
      app/controller/trainplan.js
  2. 2 0
      app/model/trainplan.js
  3. 1 0
      app/router.js
  4. 49 57
      app/service/teaplan.js
  5. 36 1
      app/service/trainplan.js

+ 4 - 0
app/controller/trainplan.js

@@ -17,6 +17,10 @@ class TrainplanController extends Controller {
     const data = await this.service.exportExcel(this.ctx.request.body);
     this.ctx.ok({ data });
   }
+  async updateclass() {
+    const data = await this.service.updateclass(this.ctx.request.body);
+    this.ctx.ok({ data });
+  }
 }
 
 module.exports = CrudController(TrainplanController, meta);

+ 2 - 0
app/model/trainplan.js

@@ -7,6 +7,7 @@ const classInfo = new Schema({
   name: { type: String, required: false, maxLength: 200 }, // 名称
   number: { type: String, required: false, maxLength: 200 }, // 人数
   type: { type: String, required: false, maxLength: 200 }, // 类型
+  headteacherid: { type: String, required: false, maxLength: 200 }, // 班主任id
   hasclass: { type: String, required: false, maxLength: 200 }, // 是否生成班级: 0未生成;1已生成
 });
 
@@ -41,6 +42,7 @@ const termInfo = new Schema({
   term: { type: String, required: false, maxLength: 200 }, // 期数
   classnum: { type: String, required: false, maxLength: 200 }, // 班级数
   batchnum: { type: [ batchInfo ], select: true }, // 批
+  reteacher: { type: String, required: false, maxLength: 2000 }, // 督导教师
 });
 
 // 节假日信息表

+ 1 - 0
app/router.js

@@ -87,6 +87,7 @@ module.exports = app => {
   router.resources('trainplan', '/api/train/trainplan', controller.trainplan); // index、create、show、destroy
   router.post('trainplan', '/api/train/trainplan/update/:id', controller.trainplan.update);
   router.post('/api/train/trainplan/exportExcel', controller.trainplan.exportExcel);// 导出
+  router.post('/api/train/trainplan/updateclass', controller.trainplan.updateclass);
 
   // 培训计划年度批次表设置路由
   router.resources('trainplanyear', '/api/train/trainplanyear', controller.trainplanyear); // index、create、show、destroy

+ 49 - 57
app/service/teaplan.js

@@ -86,14 +86,6 @@ class TeaplanService extends CrudService {
     const data = [];
     // 根据全年计划表id查出对应的全年计划详细信息
     const trainplan = await this.tmodel.findById(trainplanid);
-    // 将全年计划中的批次信息取出放在一个数组中
-    const batchList = [];
-    for (const term of trainplan.termnum) {
-      for (const batch of term.batchnum) {
-        batchList.push(batch);
-      }
-    }
-
     // 查询本培训计划中班主任全年计划表的全部信息
     const teaplanList = await this.model.find({ trainplanid });
     // 查询所有班主任信息
@@ -104,66 +96,66 @@ class TeaplanService extends CrudService {
       // 如果班主任信息列表中班主任上报了班主任全年计划,将其移除
       if (headteacherInfo.length === 0) {
         _.remove(headteacherList, item => item.id === teaplan.headteacherid);
-        teaplan.department = headteacherInfo[0].department;
       }
     }
-    // 先将所有没上报的放入可使用班主任中
-    let teaListAll = [];
-    // 遍历班主任信息,将班主任的id放在headteacherid字段中
-    for (const headteacher of headteacherList) {
-      headteacher.headteacherid = headteacher.id;
-    }
-    const noteaList = [];
     // 遍历所有批次信息
-    for (const batch of batchList) {
-      teaListAll = [];
-      teaListAll = headteacherList;
-      for (const teaplan of teaplanList) {
-        if (teaplan.nodate && (teaplan.nodate).length > 0) {
-          // 遍历班主任全年计划表中的不能上课的日期
-          for (const nodate of teaplan.nodate) {
-          // 如果不能上课的日期在该批次的开始时间和结束时间中,将该班主任从班主任列表中删除
-            if (moment(nodate).isBetween(batch.startdate, batch.enddate, null, '[]')) {
-              noteaList.push(teaplan);
-            } else {
-              const headteacher_ = await this.hmodel.findById(teaplan.headteacherid);
-              if (headteacher_) {
-                teaListAll.push(headteacher_);
+    // 将全年计划中的批次信息取出放在一个数组中
+    let teaListKfp = [];
+    let teaListAll = headteacherList;
+    for (const term of trainplan.termnum) {
+      for (const batch of term.batchnum) {
+        if (teaListAll.length === 0) {
+          teaListAll = teaListKfp;
+          teaListKfp = [];
+        }
+        for (const teaplan of teaplanList) {
+          if (teaplan.nodate && (teaplan.nodate).length > 0) {
+            // 遍历班主任全年计划表中的不能上课的日期
+            for (const nodate of teaplan.nodate) {
+            // 如果不能上课的日期在该批次的开始时间和结束时间中,将该班主任从班主任列表中删除
+              if (!moment(nodate).isBetween(batch.startdate, batch.enddate, null, '[]')) {
+                const headteacher_ = await this.hmodel.findById(teaplan.headteacherid);
+                if (headteacher_) {
+                  teaListAll.push(headteacher_);
+                }
               }
             }
           }
         }
-      }
-      // 将班主任排班次数填入数组中
-      let teaListAll_ = [];
-      for (const teac of teaListAll) {
-        // 计算出每个班主任担任过班主任的次数
-        const teacount = await this.cmodel.count({ headteacherid: teac.id });
-        const newdata = { ...JSON.parse(JSON.stringify(teac)), teacount };
-        teaListAll_.push(newdata);
-      }
-      // 将班主任按排次数排序
-      teaListAll_ = _.orderBy(teaListAll_, [ 'teacount' ], [ 'asc' ]);
-      // 查出该批次下所有的班级
-      const classList = await this.cmodel.find({ batchid: batch.id });
-      for (const _class of classList) {
-        // 取出所有部门和部门可用人数
-        const departmentList = await this.departmentcount(teaListAll_);
-        let index = 0;
-        for (const _tea of teaListAll_) {
-          // 过滤出当前教师的部门和部门可用人数
-          const deptinfo = _.find(departmentList, function(o) { return o.deparmentid === _tea.department; });
-          if (deptinfo.dcount - index > 1) {
-            _class.headteacherid = _tea.id;
-            await _class.save();
-            _.remove(teaListAll_, item => item.id === _tea.id);
-            index = index + 1;
-            break;
+        // 将班主任排班次数填入数组中
+        let teaListAll_ = [];
+        for (const teac of teaListAll) {
+          // 计算出每个班主任担任过班主任的次数
+          const teacount = await this.cmodel.count({ headteacherid: teac.id });
+          const newdata = { ...JSON.parse(JSON.stringify(teac)), teacount };
+          teaListAll_.push(newdata);
+        }
+        // 将班主任按排次数排序
+        teaListAll_ = _.orderBy(teaListAll_, [ 'teacount' ], [ 'asc' ]);
+        // 查出该批次下所有的班级
+
+        const classList = await batch.class;
+        console.log(classList);
+        for (const _class of classList) {
+          // 取出所有部门和部门可用人数
+          const departmentList = await this.departmentcount(teaListAll_);
+          let index = 0;
+          for (const _tea of teaListAll_) {
+            // 过滤出当前教师的部门和部门可用人数
+            const deptinfo = _.find(departmentList, function(o) { return o.deparmentid === _tea.department; });
+            if (deptinfo.dcount - index > 1) {
+              _class.headteacherid = _tea.id;
+              _.remove(teaListAll_, item => item.id === _tea.id);
+              _.remove(teaListAll, item => item.id === _tea.id);
+              teaListKfp.push(_tea);
+              index = index + 1;
+              break;
+            }
           }
         }
       }
     }
-    return data;
+    return await trainplan.save();
   }
 
   // 判断两个时间段是否有重合部分

+ 36 - 1
app/service/trainplan.js

@@ -65,7 +65,8 @@ class TrainplanService extends CrudService {
     if (res) {
       if (status === '1') {
         // 自动生成班级
-        await this.autoclass(res, trainplanold);
+        // await this.autoclass(res, trainplanold);
+        await this.autoclassNew(res, trainplanold);
         // 将生成的班级重新将班级排班名
         // await this.autoclassname(res);
         // 发送培训计划信息通知给相应人员
@@ -98,6 +99,22 @@ class TrainplanService extends CrudService {
     return res;
   }
 
+  // 自动生成班级私有方法
+  async autoclassNew(res) {
+    // 删除所有计划下的班级
+    await this.clamodel.deleteMany({ planid: res.id });
+    // 循环出所有班级进行添加操作
+    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);
+        }
+      }
+    }
+  }
+
   // 自动生成班级私有方法
   async autoclass(res, trainplanold) {
     // 首先比较当前数据和原数据的值是否有不同
@@ -318,5 +335,23 @@ class TrainplanService extends CrudService {
     return respath;
   }
 
+  async updateclass({ trainplanid, classid, rightHeader }) {
+    assert(trainplanid && classid && rightHeader, '缺少参数项');
+    // 根据全年计划表id查出对应的全年计划详细信息
+    const trainplan = await this.model.findById(trainplanid);
+    if (!trainplan) {
+      throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '全年计划信息不存在');
+    }
+    for (const term of trainplan.termnum) {
+      for (const batch of term.batchnum) {
+        const class_ = await batch.class.id(classid);
+        if (class_) {
+          class_.headteacherid = rightHeader;
+        }
+      }
+    }
+    return await trainplan.save();
+  }
+
 }
 module.exports = TrainplanService;