Procházet zdrojové kódy

增加批量更新接口

liuyu před 5 roky
rodič
revize
e826cf2cb2
4 změnil soubory, kde provedl 22 přidání a 0 odebrání
  1. 4 0
      app/controller/schtime.js
  2. 1 0
      app/model/schtime.js
  3. 1 0
      app/router.js
  4. 16 0
      app/service/schtime.js

+ 4 - 0
app/controller/schtime.js

@@ -13,6 +13,10 @@ class SchtimeController extends Controller {
     this.service = this.ctx.service.schtime;
   }
 
+  async updateschtimes() {
+    const res = await this.service.updateschtimes(this.ctx.request.body);
+    this.ctx.ok({ msg: 'updated', data: res });
+  }
 
 }
 

+ 1 - 0
app/model/schtime.js

@@ -7,6 +7,7 @@ const termInfo = new Schema({
   termid: { type: String, required: false, maxLength: 200 }, // 期id
   number: { type: String, required: false, maxLength: 200 }, // 人数
   type: { type: String, required: false, maxLength: 200 }, // 类别
+  carnum: { type: String, required: false, maxLength: 200 }, // 派车数量
 });
 
 // 培训计划学校上报时间表

+ 1 - 0
app/router.js

@@ -78,6 +78,7 @@ module.exports = app => {
   // 培训计划学校上报时间表设置路由
   router.resources('schtime', '/api/train/schtime', controller.schtime); // index、create、show、destroy
   router.post('schtime', '/api/train/schtime/update/:id', controller.schtime.update);
+  router.post('schtime', '/api/train/schtime/updateschtimes', controller.schtime.updateschtimes);
 
   // 班主任全年计划表设置路由
   // router.get('teaplan', '/api/train/teaplan/findteacher', controller.teaplan.findteacher);

+ 16 - 0
app/service/schtime.js

@@ -13,6 +13,22 @@ class SchtimeService extends CrudService {
     this.model = this.ctx.model.Schtime;
   }
 
+  async updateschtimes(data) {
+    assert(data, '缺少信息项');
+    for (const elm of data) {
+      const schtime = await this.model.findById();
+      if (schtime) {
+        schtime.schid = elm.schid;
+        schtime.year = elm.year;
+        schtime.planid = elm.planid;
+        schtime.remark = elm.remark;
+        schtime.daterange = elm.daterange;
+        schtime.term = elm.term;
+        await schtime.save();
+      }
+
+    }
+  }
 
 }