|
@@ -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;
|