lrf402788946 há 4 anos atrás
pai
commit
fcb79d1af7

+ 5 - 0
app/controller/.setting.js

@@ -13,6 +13,7 @@ module.exports = {
       "bd_start",
       "bd_end",
       "ques_setting",
+      "template_term",
     ],
   },
   destroy: {
@@ -34,6 +35,7 @@ module.exports = {
       "bd_start",
       "bd_end",
       "ques_setting",
+      "template_term",
     ],
   },
   show: {
@@ -62,4 +64,7 @@ module.exports = {
       count: true,
     },
   },
+  termList:{
+    service:'termList'
+  }
 };

+ 1 - 1
app/model/leave.js

@@ -16,7 +16,7 @@ const LeaveSchema = {
   endtime: { type: String, required: false, maxLength: 500 }, // 结束时间
   reason: { type: String, required: false, maxLength: 2000 }, // 请假理由
   status: { type: String, required: false, maxLength: 200, default: '0' }, // 状态,0-审核中,1-通过,2-未通过
-  refcause: { type: String, required: false, maxLength: 2000 }, // 拒绝原因
+  refcause: { type: String, required: false, maxLength: 2000 }, // 拒绝原因/备注
   type: { type: String, required: false, maxLength: 200 }, // 类型,0-请假,1-退出
 };
 

+ 1 - 0
app/model/setting.js

@@ -16,6 +16,7 @@ const SettingSchema = {
   bd_start: { type: String, required: false, maxLength: 20 }, // 寝室开始时间
   bd_end: { type: String, required: false, maxLength: 20 }, // 寝室结束时间
   ques_setting: { type: [ Object ], required: false, maxLength: 1000 }, // 问卷设置默认导出字段
+  template_term: { type: String, required: false }, // 默认期模板
 };
 
 

+ 1 - 0
app/router.js

@@ -17,6 +17,7 @@ module.exports = app => {
   router.get('/api/train/common/findbymodel', controller.common.findbymodel);
   router.get('/api/train/common/findyear', controller.common.findyear);
   // 基础设置表路由
+  router.get('/api/train/setting/termlist', controller.setting.termList); // 请求所有期
   router.get('/api/train/setting/findone', controller.setting.findone);
   router.resources('setting', '/api/train/setting', controller.setting); // index、create、show、destroy
   router.post(

+ 46 - 29
app/service/class.js

@@ -105,38 +105,12 @@ class ClassService extends CrudService {
     }
     // 循环出所有班级进行添加操作
     const term = await res.termnum.id(termid);
-    let yclocationid = ''; // 用餐地点
-    let kzjhlocationid = ''; // 拓展计划地点
-    let kbyslocationid = ''; // 开班仪式地点
-    let jslocationid = ''; // 教室位置
-    const locations = await this.locamodel.find();
-    const jslocationids = _.filter(locations, { type: '0' });
-    const kbyslocationids = _.filter(locations, { type: '1' });
-    const kzjhlocationids = _.filter(locations, { type: '2' });
-    const yclocationids = _.filter(locations, { type: '3' });
     for (const batch of term.batchnum) {
       const classs = await batch.class;
       for (const cla of classs) {
-        // 取得班级各个地点
-        // 同一地点同期只能使用一次
-        if (jslocationids.length > 0) {
-          jslocationid = jslocationids[0].id;
-          _.remove(jslocationids, { id: jslocationid });
-        }
-        if (kbyslocationids.length > 0) {
-          kbyslocationid = kbyslocationids[0].id;
-          _.remove(kbyslocationids, { id: kbyslocationid });
-        }
-        if (kzjhlocationids.length > 0) {
-          kzjhlocationid = kzjhlocationids[0].id;
-          _.remove(kzjhlocationids, { id: kzjhlocationid });
-        }
-        if (yclocationids.length > 0) {
-          yclocationid = yclocationids[0].id;
-          _.remove(yclocationids, { id: yclocationid });
-        }
-        const newdata = { name: cla.name, number: cla.number, batchid: batch.id, termid: term.id, planid: res.id, type: cla.type, headteacherid: cla.headteacherid, jslocationid, kbyslocationid, kzjhlocationid, yclocationid };
-        await this.model.create(newdata);
+        const newdata = { name: cla.name, number: cla.number, batchid: batch.id, termid: term.id, planid: res.id, type: cla.type };
+        const rescla = await this.model.create(newdata);
+        await this.toSetClassSetting({ classid: rescla._id });
       }
     }
   }
@@ -207,6 +181,7 @@ class ClassService extends CrudService {
           termid,
           planid: trainplan.id,
           type: class_.type,
+          headteacherid: class_.headteacherid,
         };
         const rescla = await this.model.create(newdata);
         if (rescla) {
@@ -226,6 +201,8 @@ class ClassService extends CrudService {
     }
     // 添加,给学生排序号
     await this.ctx.service.student.arrangeNumber({ classid: classid_ });
+    // TODO 根据模板复制班级信息
+    await this.toSetClassSetting({ classid: classid_ });
 
   }
 
@@ -397,6 +374,46 @@ class ClassService extends CrudService {
     classes.teachers = teachers;
     return classes;
   }
+  // 根据模板设置班级信息
+  async toSetClassSetting({ classid }) {
+    const setting = await this.ctx.model.Setting.findOne();
+    if (!setting) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到系统设置');
+    const { template_term } = setting;
+    if (!template_term) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到班级模板设置');
+    const templateList = await this.query({ termid: template_term });
+    const tClass = await this.model.findById(classid);
+    if (!tClass) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '班级不存在,无法复制设定的班级设置');
+    const { name, termid, batchid } = tClass;
+    const r = templateList.find(f => f.name === name);
+    if (r) {
+      // 说明这个是正常班,且从模板中找得到; 除了礼仪教师外,都复制过来
+      const { jslocationid, kbyslocationid, kzjhlocationid, yclocationid } = r;
+      if (!tClass.jslocation && jslocationid) tClass.jslocationid = jslocationid;
+      if (!tClass.kbyslocationid && kbyslocationid) tClass.kbyslocationid = kbyslocationid;
+      if (!tClass.kzjhlocationid && kzjhlocationid) tClass.kzjhlocationid = kzjhlocationid;
+      if (!tClass.yclocationid && yclocationid) tClass.yclocationid = yclocationid;
+      await tClass.save();
+    } else {
+      // 没找到,有可能是普通班,也有可能是非普通班
+      // 找这个班级的同批次
+      const tClassBatch = await this.query({ termid, batchid });
+      const r = tClassBatch.find(f => ObjectId(tClass._id).equals(f._id));
+      const ri = tClassBatch.findIndex(f => ObjectId(tClass._id).equals(f._id));
+      if (r) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '无法确定班级批次排序');
+      else {
+        const { batch: tAllClassBatch } = r;
+        const templateBatchList = templateList.filter(f => f.batch === tAllClassBatch);
+        // 根据该班级所在批次的顺序,找到对应模板,然后复制
+        const copyTemplate = templateBatchList[ri];
+        const { jslocationid, kbyslocationid, kzjhlocationid, yclocationid } = copyTemplate;
+        if (!tClass.jslocation && jslocationid) tClass.jslocationid = jslocationid;
+        if (!tClass.kbyslocationid && kbyslocationid) tClass.kbyslocationid = kbyslocationid;
+        if (!tClass.kzjhlocationid && kzjhlocationid) tClass.kzjhlocationid = kzjhlocationid;
+        if (!tClass.yclocationid && yclocationid) tClass.yclocationid = yclocationid;
+        await tClass.save();
+      }
+    }
+  }
 }
 
 module.exports = ClassService;

+ 0 - 1
app/service/lesson.js

@@ -604,7 +604,6 @@ class LessonService extends CrudService {
         }
         // 最后整合
         const classLesson = { ...lessinfo, lessons };
-        console.log(classLesson);
         // 保存
         await this.model.create(classLesson);
       }

+ 20 - 1
app/service/setting.js

@@ -17,7 +17,7 @@ class SettingService extends CrudService {
     return await this.model.findOne();
   }
 
-  async update({ id }, { planyearid, planid, termid, user_email, auth_code, am_start, am_end, pm_start, pm_end, bd_start, bd_end,ques_setting }) {
+  async update({ id }, { planyearid, planid, termid, user_email, auth_code, am_start, am_end, pm_start, pm_end, bd_start, bd_end, ques_setting, template_term }) {
     assert(id, '缺少部分信息项');
     const setting = await this.model.findById(id);
     if (!setting) {
@@ -59,10 +59,29 @@ class SettingService extends CrudService {
     if (ques_setting) {
       setting.ques_setting = ques_setting;
     }
+    if (template_term) {
+      setting.template_term = template_term;
+    }
     await setting.save();
     return setting;
   }
 
+  async termList() {
+    let res = await this.ctx.model.Trainplan.find();
+    if (res && _.isArray(res)) {
+      res = res.map(i => {
+        if (_.isArray(i.termnum)) {
+          i.termnum = i.termnum.map(t => {
+            return { term: t.term * 1, _id: t._id };
+          });
+          i.termnum = _.orderBy(i.termnum, [ 'term' ], [ 'asc' ]);
+        }
+        return i.termnum;
+      });
+    }
+    return res.flat();
+  }
+
 }
 
 module.exports = SettingService;