Ver Fonte

添加每日时间安排按课表模板校准

lrf402788946 há 4 anos atrás
pai
commit
3e12c0693e
3 ficheiros alterados com 65 adições e 1 exclusões
  1. 8 0
      app/controller/.lesson.js
  2. 2 1
      app/router.js
  3. 55 0
      app/service/lesson.js

+ 8 - 0
app/controller/.lesson.js

@@ -46,4 +46,12 @@ module.exports = {
     },
     service: "teaIndex",
   },
+  timeCollate:{
+    parameters: {
+      query: {
+        termid: "termid",
+      },
+    },
+    service: "timeCollate",
+  }
 };

+ 2 - 1
app/router.js

@@ -278,7 +278,8 @@ module.exports = app => {
   // 新自动排课表
   router.post('/api/train/lesson/newarrange', controller.lesson.newArrange);
 
-
+  // 按系统设置->课表模板,校对某期课表的时间
+  router.get('/api/train/lesson/timeCollate', controller.lesson.timeCollate);
   // 课程表设置路由
   router.get('/api/train/lesson/teaclass', controller.lesson.teaclass);
   router.post(

+ 55 - 0
app/service/lesson.js

@@ -651,6 +651,61 @@ class LessonService extends CrudService {
     res = _.uniqWith(res, _.isEqual);
     return res;
   }
+
+  // 按系统设置->课表模板,进行对应班级类型的时间更新
+  async timeCollate({ termid }) {
+    // 找到课表模板
+    const templates = await this.lmodel.find();
+    // 找到该期下的班级
+    const classes = await this.clamodel.find({ termid });
+    // 找到这些班级的课表
+    const cids = classes.map(i => i._id);
+    let lList = await this.model.find({ classid: cids });
+    if (lList.length > 0) lList = JSON.parse(JSON.stringify(lList));
+    for (const l of lList) {
+      // 确定是班级类型
+      const c = classes.find(f => ObjectId(f._id).equals(l.classid));
+      if (!c) continue;
+      // 确定模板拿哪个类型
+      const { type } = c;
+      const t = templates.find(f => f.type === type);
+      if (!t) continue;
+      // 整理出时间列表(默认顺序就可以)
+      const { lessons: tl } = t;
+      const tlarr = JSON.parse(tl);
+      const timeArr = tlarr.map(i => i.time);
+      // 改课表中的每天的时间
+      // 1,需要按天分组,然后进行排序
+      const { lessons: lls } = l;
+      const glls = _.groupBy(lls, 'date');
+      const llsVal = Object.values(glls);
+      // console.log(llsVal);
+      let lastData = [];
+      // 副本,排序,更新时间,赋回
+      for (const ll of llsVal) {
+        let dup = _.cloneDeep(ll);
+        dup = this.sortLesson(dup);
+        for (let i = 0; i < dup.length; i++) {
+          dup[i].time = timeArr[i];
+        }
+        lastData.push(dup);
+      }
+      lastData = _.flatten(lastData);
+      l.lessons = lastData;
+      await this.model.updateOne({ _id: l._id }, { lessons: lastData });
+    }
+
+  }
+  // 按时间升序排序
+  sortLesson(arr) {
+    arr = arr.map(i => {
+      i.fulltime = `${i.date} ${i.time}`;
+      return i;
+    });
+    arr = _.orderBy(arr, [ 'fulltime' ], [ 'asc' ]);
+    arr = arr.map(i => _.omit(i, [ 'fulltime' ]));
+    return arr;
+  }
 }
 
 module.exports = LessonService;