lrf402788946 преди 4 години
родител
ревизия
e7252333a1
променени са 2 файла, в които са добавени 109 реда и са изтрити 8 реда
  1. 1 0
      app/model/trainplan.js
  2. 108 8
      app/service/trainplan.js

+ 1 - 0
app/model/trainplan.js

@@ -17,6 +17,7 @@ const batchInfo = new Schema({
   class: { type: [ classInfo ], required: false, select: true }, // 班级数
   startdate: { type: String, required: false, maxLength: 200 }, // 开始日期
   enddate: { type: String, required: false, maxLength: 200 }, // 结束日期
+  lessons: { type: [ Object ], required: false }, // 课程表
   // type: { type: String, required: false, maxLength: 200 }, // 类型:0-正常,1-特殊
   // name: { type: String, required: false, maxLength: 200 }, // 名称
   // number: { type: String, required: false, maxLength: 200 }, // 人数

+ 108 - 8
app/service/trainplan.js

@@ -19,6 +19,7 @@ class TrainplanService extends CrudService {
     this.tmodel = this.ctx.model.Teacher;
     this.stumodel = this.ctx.model.Student;
     this.schmodel = this.ctx.model.Schtime;
+    this.lmmodel = this.ctx.model.Lessonmode;
   }
 
   async create(data) {
@@ -38,8 +39,7 @@ class TrainplanService extends CrudService {
       const schtimeres = await this.schmodel.create(obj);
       if (schtimeres) schtimeArr.push(schtimeres);
     }
-    if (!schtimeArr.every(e => e)) throw new BusinessError(ErrorCode.DATA_INVALID, '学校计划生成失败');
-    else return res;
+    if (!schtimeArr.every(e => e)) { throw new BusinessError(ErrorCode.DATA_INVALID, '学校计划生成失败'); } else return res;
   }
 
   async update({ id }, data) {
@@ -66,6 +66,12 @@ class TrainplanService extends CrudService {
     if (status === '1') {
       trainplan.status = status;
     }
+    // 日历安排中添加课表信息,查询每种班级类型的课表,然后显示
+    if (trainplan.termnum) {
+      // trainplan.termnum =
+      trainplan.termnum = await this.termGetLesson(trainplan.termnum);
+    }
+
     // 如果培训计划状态改为发布,发送培训计划信息,并自动生成班级
     const res = await trainplan.save();
     if (res) {
@@ -122,6 +128,66 @@ class TrainplanService extends CrudService {
     return res;
   }
 
+  async termGetLesson(termnum) {
+    const lessonModelList = await this.lmmodel.find();
+    for (const term of termnum) {
+      for (const batch of term.batchnum) {
+        const { class: classes, startdate, enddate } = batch;
+        // 获取每批次下每个班的班级类型
+        const typeList = _.uniq(classes.map(i => i.type));
+        const h = _.head(typeList);
+        if (!h) continue;
+        const tem = lessonModelList.find(f => f.type === h);
+        let { lessons } = tem;
+        lessons = JSON.parse(lessons);
+        // 过滤出上课的时间段
+        lessons = lessons.filter(f => {
+          const keys = Object.keys(f).filter(f => f.includes('subid'));
+          return keys.length > 0;
+        });
+        // 记录上课的时间
+        const times = [];
+        // 记录所有的科目
+        let subject = [];
+        lessons.map(i => {
+          times.push(i.time);
+          const keys = Object.keys(i);
+          let arr = [];
+          for (const key of keys) {
+            if (key.match(/\d/g)) arr.push(_.head(key.match(/\d/g)));
+          }
+          arr = _.uniq(arr);
+          for (const ai of arr) {
+            if (i[`day${ai}subid`]) {
+              subject.push({
+                subname: i[`day${ai}`],
+                subid: i[`day${ai}subid`],
+                day: ai,
+              });
+            }
+          }
+          // console.log(arr);
+          return i;
+        });
+        // 去重
+        subject = _.uniqBy(subject, 'subid');
+        // 获得天列表
+        const dnum = moment(enddate).diff(moment(startdate), 'days') + 1;
+        const dayList = [];
+        for (let ind = 0; ind < dnum; ind++) {
+          dayList.push(moment(startdate).add(ind, 'd').format('YYYY-MM-DD'));
+        }
+        // 将subject中的day换成日期
+        for (const sub of subject) {
+          sub.day = dayList[sub.day * 1 - 1];
+          sub.time = times;
+        }
+        batch.lessons = subject;
+      }
+    }
+    return termnum;
+  }
+
   // 自动生成班级私有方法
   async autoclassNew(res) {
     // 删除所有计划下的班级
@@ -614,7 +680,10 @@ class TrainplanService extends CrudService {
     const styleMonth = [];
 
     // 这里是假期颜色
-    const festivalsCell = { v: '', s: { fill: { fgColor: { rgb: 'A2CD5A' } } } };
+    const festivalsCell = {
+      v: '',
+      s: { fill: { fgColor: { rgb: 'A2CD5A' } } },
+    };
     // 坐标
     const festivalsCellstyle = 0;
     let festivalsRowstyle = 0;
@@ -737,7 +806,11 @@ class TrainplanService extends CrudService {
 
       const resDate = this.makeCalendar(trainplan.year, index);
       data.push([ '' ]);
-      data.push([[ this.getBigMonth(index) + '月' ]].concat(resDate.dlist).concat([ '人数' ].concat([ '班级数' ])));
+      data.push(
+        [[ this.getBigMonth(index) + '月' ]]
+          .concat(resDate.dlist)
+          .concat([ '人数' ].concat([ '班级数' ]))
+      );
       data.push([ '' ].concat(resDate.tlist));
       // 加列数组
       for (let i = 0; i < classNum; i++) {
@@ -806,7 +879,20 @@ class TrainplanService extends CrudService {
   }
   // 获取大月份传过来的值是以1月份开始的
   getBigMonth(index) {
-    const monthBig = [ '一', '二', '三', '四', '五', '六', '七', '八', '九', '十', '十一', '十二' ];
+    const monthBig = [
+      '一',
+      '二',
+      '三',
+      '四',
+      '五',
+      '六',
+      '七',
+      '八',
+      '九',
+      '十',
+      '十一',
+      '十二',
+    ];
     return monthBig[index - 1];
   }
   // 获取这个月份的所有日期1~30号或者31或者28,或者29
@@ -827,7 +913,14 @@ class TrainplanService extends CrudService {
     const tlist = [];
     const all = {};
     for (let index = 0; index < days; index++) {
-      dlist.push(month0 + '月' + moment(year + '-' + month).add(index, 'days').format('D') + '日');
+      dlist.push(
+        month0 +
+          '月' +
+          moment(year + '-' + month)
+            .add(index, 'days')
+            .format('D') +
+          '日'
+      );
       let dayy = parseInt(index + 1);
       if (dayy * 1 < 10) dayy = '0' + dayy;
       tlist.push(this.getWeekDay(year + '-' + month + '-' + dayy));
@@ -850,7 +943,10 @@ class TrainplanService extends CrudService {
   //   assert(trainplanid && classid && rightHeader, '缺少参数项');
 
   async updateclass({ trainplanid, termid, batchid, classid, rightHeader }) {
-    assert(trainplanid && termid && batchid && classid && rightHeader, '缺少参数项');
+    assert(
+      trainplanid && termid && batchid && classid && rightHeader,
+      '缺少参数项'
+    );
     // 根据全年计划表id查出对应的全年计划详细信息
     const trainplan = await this.model.findById(trainplanid);
     if (!trainplan) {
@@ -870,7 +966,11 @@ class TrainplanService extends CrudService {
     }
     const res = await trainplan.save();
     if (res) {
-      const cla_ = await this.clamodel.findOne({ termid, batchid, name: class_.name });
+      const cla_ = await this.clamodel.findOne({
+        termid,
+        batchid,
+        name: class_.name,
+      });
       if (cla_) {
         cla_.headteacherid = rightHeader;
         await cla_.save();