Преглед на файлове

变更计划并加入班级类型表

liuyu преди 4 години
родител
ревизия
7b59f4c4e7
променени са 8 файла, в които са добавени 148 реда и са изтрити 28 реда
  1. 46 0
      app/controller/.classtype.js
  2. 17 0
      app/controller/classtype.js
  3. 21 0
      app/model/classtype.js
  4. 7 1
      app/model/trainmodel.js
  5. 12 4
      app/model/trainplan.js
  6. 4 0
      app/router.js
  7. 18 0
      app/service/classtype.js
  8. 23 23
      app/service/trainplan.js

+ 46 - 0
app/controller/.classtype.js

@@ -0,0 +1,46 @@
+module.exports = {
+  create: {
+    requestBody: [
+      '!name',
+      'code',
+      'bedroom',
+      'sign'
+    ]
+  },
+  destroy: {
+    params: ['!id'],
+    service: 'delete'
+  },
+  update: {
+    params: ['!id'],
+    requestBody: [
+      'name',
+      'code',
+      'bedroom',
+      'sign'
+    ]
+  },
+  show: {
+    parameters: {
+      params: ['!id']
+    },
+    service: 'fetch'
+  },
+  index: {
+    parameters: {
+      query: {
+        name: 'name',
+        code  :'code',
+        bedroom:'bedroom',
+        sign: 'sign'
+      }
+    },
+    service: 'query',
+    options: {
+      query: ['skip', 'limit'],
+      sort: ['meta.createdAt'],
+      desc: true,
+      count: true
+    }
+  },
+};

+ 17 - 0
app/controller/classtype.js

@@ -0,0 +1,17 @@
+'use strict';
+
+const _ = require('lodash');
+const meta = require('./.classtype.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose/lib/controller');
+
+// 班级类型管理
+class ClasstypeController extends Controller {
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.classtype;
+  }
+
+}
+
+module.exports = CrudController(ClasstypeController, meta);

+ 21 - 0
app/model/classtype.js

@@ -0,0 +1,21 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
+
+// 班级表
+const ClasstypeSchema = {
+  name: { type: String, required: true, maxLength: 500 }, // 班级类型名称
+  code: { type: String, required: false, maxLength: 200 }, // 班级类型代码(自定义)
+  bedroom: { type: String, required: false, maxLength: 200 }, // 0分配;1填写 寝室
+  sign: { type: String, required: false, maxLength: 200 }, // 0学生签到;1教师签到
+};
+
+
+const schema = new Schema(ClasstypeSchema, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Classtype', schema, 'classtype');
+};

+ 7 - 1
app/model/trainmodel.js

@@ -2,6 +2,12 @@
 const Schema = require('mongoose').Schema;
 const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
 
+// 期信息表
+const classInfo = new Schema({
+  class: { type: String, required: false, maxLength: 200 }, // 班级名
+  number: { type: String, required: false, maxLength: 200 }, // 人数
+});
+
 // 全年计划模板表
 const TrainmodelSchema = {
   total: { type: String, required: false, maxLength: 200 }, // 总人数
@@ -10,7 +16,7 @@ const TrainmodelSchema = {
   planyearid: { type: String, required: true, maxLength: 200 }, // 大批次id
   planid: { type: String, required: true, maxLength: 200 }, // 计划id
   batchnum: { type: String, required: false, maxLength: 200 }, // 默认期下生成的批次数
-  classnum: { type: String, required: false, maxLength: 200 }, // 默认批次下生成的班级数
+  classnum: { type: [ classInfo ], required: false, select: true }, // 默认批次下生成的班级数
   stunum: { type: String, required: false, maxLength: 200 }, // 默认每班学生数
   carpnum: { type: String, required: false, maxLength: 200 }, // 默认每辆车的学生数
 };

+ 12 - 4
app/model/trainplan.js

@@ -2,15 +2,23 @@
 const Schema = require('mongoose').Schema;
 const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
 
+// 班级信息表
+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 }, // 类型
+  hasclass: { type: String, required: false, maxLength: 200 }, // 是否生成班级: 0未生成;1已生成
+});
+
 // 批次信息表
 const batchInfo = new Schema({
   batch: { type: String, required: false, maxLength: 200 }, // 批次
-  class: { type: String, required: false, maxLength: 200 }, // 班级数
+  class: { type: [ classInfo ], required: false, select: true }, // 班级数
   startdate: { type: String, required: false, maxLength: 200 }, // 开始日期
   enddate: { type: String, required: false, maxLength: 200 }, // 结束日期
-  type: { type: String, required: false, maxLength: 200 }, // 类型:0-正常,1-特殊
-  name: { type: String, required: false, maxLength: 200 }, // 名称
-  number: { type: String, required: false, maxLength: 200 }, // 人数
+  // type: { type: String, required: false, maxLength: 200 }, // 类型:0-正常,1-特殊
+  // name: { type: String, required: false, maxLength: 200 }, // 名称
+  // number: { type: String, required: false, maxLength: 200 }, // 人数
   color: { type: String, required: false, maxLength: 200 }, // 颜色
 });
 

+ 4 - 0
app/router.js

@@ -229,4 +229,8 @@ module.exports = app => {
   // 按学校统计查询设置路由
   router.get('/api/train/count/countschstu/:id', controller.count.countschstu);
 
+  // 班级类型表配置路由
+  router.resources('classtype', '/api/train/classtype', controller.classtype); // index、create、show、destroy
+  router.post('classtype', '/api/train/classtype/update/:id', controller.classtype.update);
+
 };

+ 18 - 0
app/service/classtype.js

@@ -0,0 +1,18 @@
+'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 ClasstypeService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'classtype');
+    this.model = this.ctx.model.Classtype;
+  }
+
+}
+
+module.exports = ClasstypeService;

+ 23 - 23
app/service/trainplan.js

@@ -68,7 +68,7 @@ class TrainplanService extends CrudService {
         // 自动生成班级
         await this.autoclass(res, trainplanold);
         // 将生成的班级重新将班级排班名
-        await this.autoclassname(res);
+        // await this.autoclassname(res);
         // 发送培训计划信息通知给相应人员
         // 查询所有入库的教师
         const teachers = await this.tmodel.find({ status: '4' });
@@ -124,8 +124,8 @@ class TrainplanService extends CrudService {
         for (const batchnum of batchnums) {
           // 取得当前批次的班级数
           const classnum = batchnum.class;
-          for (let i = 1; i <= classnum; i++) {
-            const newdata = { name: i, number: batchnum.number, batchid: batchnum.id, termid: el.id, planid: res.id };
+          for (const cla of classnum) {
+            const newdata = { name: cla.name, number: cla.number, batchid: batchnum.id, termid: el.id, planid: res.id, type: cla.type };
             await this.clamodel.create(newdata);
           }
         }
@@ -150,8 +150,8 @@ class TrainplanService extends CrudService {
           if (_.indexOf(addbatch, batchnum.id) !== -1) {
             // 取得当前批次的班级数
             const classnum = batchnum.class;
-            for (let i = 1; i <= classnum; i++) {
-              const newdata = { name: i, number: batchnum.number, batchid: batchnum.id, termid: el.id, planid: res.id };
+            for (const cla of classnum) {
+              const newdata = { name: cla.name, number: cla.number, batchid: batchnum.id, termid: el.id, planid: res.id, type: cla.type };
               await this.clamodel.create(newdata);
             }
           } else {
@@ -165,8 +165,8 @@ class TrainplanService extends CrudService {
                 }
               } else {
                 const classnum = batchnum.class;
-                for (let i = 1; i <= classnum; i++) {
-                  const newdata = { name: i, number: batchnum.number, batchid: batchnum.id, termid: el.id, planid: res.id };
+                for (const cla of classnum) {
+                  const newdata = { name: cla.name, number: cla.number, batchid: batchnum.id, termid: el.id, planid: res.id, type: cla.type };
                   await this.clamodel.create(newdata);
                 }
               }
@@ -175,8 +175,8 @@ class TrainplanService extends CrudService {
               // 删除所有班级 并重新生成班级
               await this.clamodel.deleteMany({ termid: el.id, batchid: batchnum.id });
               const classnum = batchnum.class;
-              for (let i = 1; i <= classnum; i++) {
-                const newdata = { name: i, number: batchnum.number, batchid: batchnum.id, termid: el.id, planid: res.id };
+              for (const cla of classnum) {
+                const newdata = { name: cla.name, number: cla.number, batchid: batchnum.id, termid: el.id, planid: res.id, type: cla.type };
                 await this.clamodel.create(newdata);
               }
             }
@@ -187,20 +187,20 @@ class TrainplanService extends CrudService {
 
   }
 
-  // 将分好的班级重新编排名字
-  async autoclassname(res) {
-    // 取得所有期id
-    const tremid_res = _.map(res.termnum, 'id');
-    for (const termid of tremid_res) {
-      const classs = await this.clamodel.find({ planid: res.id, termid });
-      let i = 0;
-      for (const cla of classs) {
-        i = i + 1;
-        cla.name = i;
-        await cla.save();
-      }
-    }
-  }
+  // // 将分好的班级重新编排名字
+  // async autoclassname(res) {
+  //   // 取得所有期id
+  //   const tremid_res = _.map(res.termnum, 'id');
+  //   for (const termid of tremid_res) {
+  //     const classs = await this.clamodel.find({ planid: res.id, termid });
+  //     let i = 0;
+  //     for (const cla of classs) {
+  //       i = i + 1;
+  //       cla.name = i;
+  //       await cla.save();
+  //     }
+  //   }
+  // }
 
 }
 module.exports = TrainplanService;