lrf402788946 3 年 前
コミット
f9e765bcce
3 ファイル変更52 行追加25 行削除
  1. 30 25
      app/controller/apply.js
  2. 2 0
      app/router.js
  3. 20 0
      app/service/apply.js

+ 30 - 25
app/controller/apply.js

@@ -1,25 +1,30 @@
-'use strict';
-
-const _ = require('lodash');
-const meta = require('./.apply.js');
-const Controller = require('egg').Controller;
-const { CrudController } = require('naf-framework-mongoose/lib/controller');
-
-// 教师申请讲课表管理
-class ApplyController extends Controller {
-  constructor(ctx) {
-    super(ctx);
-    this.service = this.ctx.service.apply;
-  }
-
-  async queryteacher() {
-    const data = await this.service.queryteacher(this.ctx.request.query);
-    this.ctx.ok({ data });
-  }
-  async arrange() {
-    const data = await this.service.arrangeteacher(this.ctx.request.body);
-    this.ctx.ok({ data });
-  }
-}
-
-module.exports = CrudController(ApplyController, meta);
+'use strict';
+
+const _ = require('lodash');
+const meta = require('./.apply.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose/lib/controller');
+
+// 教师申请讲课表管理
+class ApplyController extends Controller {
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.apply;
+  }
+
+  async queryteacher() {
+    const data = await this.service.queryteacher(this.ctx.request.query);
+    this.ctx.ok({ data });
+  }
+  async arrange() {
+    const data = await this.service.arrangeteacher(this.ctx.request.body);
+    this.ctx.ok({ data });
+  }
+
+  async clearArrange() {
+    const data = await this.service.clearArrange(this.ctx.request.body);
+    this.ctx.ok({ data });
+  }
+}
+
+module.exports = CrudController(ApplyController, meta);

+ 2 - 0
app/router.js

@@ -331,6 +331,8 @@ module.exports = app => {
 
   // 计划自动排教师
   router.post('apply', '/api/train/apply/arrange', controller.apply.arrange);
+  // 清除预课表教师安排
+  router.post('apply', '/api/train/apply/clearArrange', controller.apply.clearArrange);
   // 计划自动排教师
   router.post('apply', '/api/train/apply/sendmsg/:planid', controller.apply.sendmsg);
   // 计划自动排教师

+ 20 - 0
app/service/apply.js

@@ -539,6 +539,26 @@ class ApplyService extends CrudService {
       { ...trainPlan }
     );
   }
+
+  async clearArrange({ planid, ids }) {
+    let trainPlan = await this.ctx.model.Trainplan.findById(planid);
+    trainPlan = JSON.parse(JSON.stringify(trainPlan));
+    for (const term of trainPlan.termnum) {
+      const in_ids = ids.find(f => ObjectId(f).equals(term._id));
+      if (in_ids) {
+        for (const batch of term.batchnum) {
+          for (const c of batch.class) {
+            for (const l of c.lessons) {
+              l.teaid = undefined;
+              l.teaname = undefined;
+            }
+          }
+        }
+      }
+    }
+    delete trainPlan.meta;
+    await this.ctx.model.Trainplan.updateOne({ _id: planid }, trainPlan);
+  }
 }
 
 module.exports = ApplyService;