liuyu 4 роки тому
батько
коміт
0527523ecf
6 змінених файлів з 168 додано та 3 видалено
  1. 67 0
      app/controller/.job.js
  2. 18 0
      app/controller/job.js
  3. 27 0
      app/model/job.js
  4. 4 0
      app/router.js
  5. 35 0
      app/service/job.js
  6. 17 3
      app/service/school.js

+ 67 - 0
app/controller/.job.js

@@ -0,0 +1,67 @@
+module.exports = {
+  create: {
+    requestBody: [
+      'code',
+      'name',
+      'planid',
+      'termid',
+      'term',
+      'filepath',
+      'studs',
+      'plannum',
+      'schnum',
+      'isstore',
+      'createtime'
+    ]
+  },
+  destroy: {
+    params: ['!id'],
+    service: 'delete'
+  },
+  update: {
+    params: ['!id'],
+    requestBody: [
+      'code',
+      'name',
+      'planid',
+      'termid',
+      'term',
+      'filepath',
+      'studs',
+      'plannum',
+      'schnum',
+      'isstore',
+      'createtime'
+    ]
+  },
+  show: {
+    parameters: {
+      params: ['!id']
+    },
+    service: 'fetch'
+  },
+  index: {
+    parameters: {
+      query: {
+        code: 'code',
+        name: 'name',
+        planid: 'planid',
+        termid: 'termid',
+        term: 'term',
+        filepath: 'filepath',
+        studs: 'studs',
+        plannum: 'plannum',
+        schnum: 'schnum',
+        isstore: 'isstore',
+        createtime: 'createtime'
+      }
+    },
+    service: 'query',
+    options: {
+      query: ['skip', 'limit'],
+      sort: ['meta.createdAt'],
+      desc: true,
+      count: true
+    }
+  },
+};

+ 18 - 0
app/controller/job.js

@@ -0,0 +1,18 @@
+'use strict';
+
+const _ = require('lodash');
+const meta = require('./.job.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose/lib/controller');
+
+// 任务表管理
+class JobController extends Controller {
+
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.job;
+  }
+
+}
+
+module.exports = CrudController(JobController, meta);

+ 27 - 0
app/model/job.js

@@ -0,0 +1,27 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
+
+// 任务表
+const JobSchema = {
+  code: { type: String, required: false, maxLength: 200 }, // 学校代码
+  name: { type: String, required: false, maxLength: 500 }, // 学校名称
+  planid: { type: String, required: false, maxLength: 200 }, // 计划id
+  termid: { type: String, required: false, maxLength: 200 }, // 期id
+  term: { type: String, required: false, maxLength: 500 }, // 期名称
+  filepath: { type: String, required: false, maxLength: 500 }, // 文件地址
+  studs: { type: String, required: false }, // 学生数据
+  plannum: { type: String, required: false, maxLength: 20 }, // 计划人数
+  schnum: { type: String, required: false, maxLength: 20 }, // 学校上传人数
+  isstore: { type: String, required: false, maxLength: 20 }, // 是否入库 0、不入库1、入库
+  createtime: { type: String, required: false, maxLength: 200 }, // 上传时间
+};
+
+const schema = new Schema(JobSchema, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Job', schema, 'job');
+};

+ 4 - 0
app/router.js

@@ -236,4 +236,8 @@ module.exports = app => {
   router.resources('classtype', '/api/train/classtype', controller.classtype); // index、create、show、destroy
   router.post('classtype', '/api/train/classtype/update/:id', controller.classtype.update);
 
+  // 职责说明表设置路由
+  router.resources('job', '/api/train/job', controller.job); // index、create、show、destroy
+  router.post('job', '/api/train/job/update/:id', controller.job.update);
+
 };

+ 35 - 0
app/service/job.js

@@ -0,0 +1,35 @@
+'use strict';
+
+
+const assert = require('assert');
+const _ = require('lodash');
+const { ObjectId } = require('mongoose').Types;
+const { CrudService } = require('naf-framework-mongoose/lib/service');
+const { BusinessError, ErrorCode } = require('naf-core').Error;
+
+class JobService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'job');
+    this.model = this.ctx.model.Job;
+    this.smodel = this.ctx.model.Student;
+  }
+
+  async uptea({ id }, data) {
+    const job = await this.model.findById(id);
+    if (!job) {
+      throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '任务信息不存在');
+    }
+    job.isstore = data.isstore;
+    const res = await job.save();
+    if (res && data.isstore === '1') {
+      const studatas = job.studs;
+      for (const stu of studatas) {
+        await this.smodel.create(stu);
+      }
+    }
+    return res;
+  }
+
+}
+
+module.exports = JobService;

+ 17 - 3
app/service/school.js

@@ -6,6 +6,7 @@ const _ = require('lodash');
 const { ObjectId } = require('mongoose').Types;
 const { CrudService } = require('naf-framework-mongoose/lib/service');
 const { BusinessError, ErrorCode } = require('naf-core').Error;
+const moment = require('moment');
 const XLSX = require('xlsx');
 
 class SchoolService extends CrudService {
@@ -15,6 +16,7 @@ class SchoolService extends CrudService {
     this.smodel = this.ctx.model.Student;
     this.umodel = this.ctx.model.User;
     this.tmodel = this.ctx.model.Trainplan;
+    this.jmodel = this.ctx.model.Job;
   }
 
   async stuimport(data) {
@@ -40,14 +42,26 @@ 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') {
       return datacheck;
     }
+    const school_ = await this.smodel.findOne({ code: schid });
+    const trem_ = await plan.termnum.id(termid);
+    if (!trem_) {
+      throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '期信息不存在');
+    }
+    const nowtime = moment().locale('zh-cn').format('YYYY-MM-DD HH:mm:ss');
+    if (studatas.length > Number(num_)) {
+      const jobdata = { code: schid, name: school_.name, planid: plan.id, termid, term: trem_.term, filepath, studs: JSON.stringify(studatas), plannum: num_, schnum: studatas.length, isstore: '0', createtime: nowtime };
+      await this.jmodel.create(jobdata);
+      throw new BusinessError(ErrorCode.SERVICE_FAULT, '学校上传人数超过预期人数');
+    } else if (studatas.length < Number(num_)) {
+      const jobdata = { code: schid, name: school_.name, planid: plan.id, termid, term: trem_.term, filepath, studs: JSON.stringify(studatas), plannum: num_, schnum: studatas.length, isstore: '0', createtime: nowtime };
+      await this.jmodel.create(jobdata);
+      throw new BusinessError(ErrorCode.SERVICE_FAULT, '学校上传人数少于预期人数');
+    }
     // 将数据存入数据库中
     for (const stu of studatas) {
       const res = await this.smodel.create(stu);