Просмотр исходного кода

Merge branch 'master' of http://git.cc-lotus.info/new_train/service-center

cheny 4 лет назад
Родитель
Сommit
6674f6a9df
4 измененных файлов с 29 добавлено и 0 удалено
  1. 5 0
      app/controller/trainplan.js
  2. 1 0
      app/router.js
  3. 9 0
      app/service/school.js
  4. 14 0
      app/service/trainplan.js

+ 5 - 0
app/controller/trainplan.js

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

+ 1 - 0
app/router.js

@@ -88,6 +88,7 @@ module.exports = app => {
   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.post('/api/train/trainplan/updatereteacher', controller.trainplan.updatereteacher);
 
   // 培训计划年度批次表设置路由
   router.resources('trainplanyear', '/api/train/trainplanyear', controller.trainplanyear); // index、create、show、destroy

+ 9 - 0
app/service/school.js

@@ -27,6 +27,12 @@ class SchoolService extends CrudService {
     if (!plan) {
       throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '计划信息不存在');
     }
+    const schs = await plan.school;
+    const sch_ = _.find(schs, { code: schid });
+    let num_ = '0';
+    if (sch_) {
+      num_ = sch_.num;
+    }
     const planid = plan.id;
     const planyearid = plan.planyearid;
     // 取得excle中数据
@@ -34,6 +40,9 @@ class SchoolService extends CrudService {
     console.log(_filepath);
     const studatas = await this.getImportXLSXData(_filepath, termid, schid, planid, planyearid);
     console.log(studatas);
+    if (studatas.length > Number(num_)) {
+      throw new BusinessError(ErrorCode.SERVICE_FAULT, '学校上传人数超过预期人数');
+    }
     // 将得到的数据校验
     const datacheck = await this.datacheck(studatas);
     if (datacheck.errorcode === '1') {

+ 14 - 0
app/service/trainplan.js

@@ -356,5 +356,19 @@ class TrainplanService extends CrudService {
     return await trainplan.save();
   }
 
+  async updatereteacher({ trainplanid, termid, reteacher }) {
+    assert(trainplanid && termid && reteacher, '缺少参数项');
+    // 根据全年计划表id查出对应的全年计划详细信息
+    const trainplan = await this.model.findById(trainplanid);
+    if (!trainplan) {
+      throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '全年计划信息不存在');
+    }
+    const term = await trainplan.termnum.id(termid);
+    if (term) {
+      term.reteacher = reteacher;
+    }
+    return await trainplan.save();
+  }
+
 }
 module.exports = TrainplanService;