|
@@ -525,8 +525,11 @@ class LessonService extends CrudService {
|
|
|
// 指定期的数据
|
|
|
termnum = JSON.parse(JSON.stringify(termnum));
|
|
|
if (!termnum) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '该期不存在');
|
|
|
- // 该期的课表,没有就添加
|
|
|
- await this.model.deleteMany({ termid });
|
|
|
+ // // 该期的课表,没有就添加
|
|
|
+ const has_lesson = await this.model.find({ termid });
|
|
|
+ const classids = has_lesson.map(i => ObjectId(i.classid));
|
|
|
+ // console.log(has_lesson);
|
|
|
+ const has_classList = await this.clamodel.find({ _id: { $in: classids } }, { name: 1 });
|
|
|
const sterm = termnum.find(f => f._id === termid);
|
|
|
const { batchnum } = sterm;
|
|
|
// 确保batchnum是数组
|
|
@@ -540,6 +543,9 @@ class LessonService extends CrudService {
|
|
|
for (const c of clist) {
|
|
|
// 排指定班
|
|
|
const { name, ...lessinfo } = await this.partsOfClass(c);
|
|
|
+ // 查看该班级是否已经有课表
|
|
|
+ const is_has = has_classList.find(f => f.name === name);
|
|
|
+ if (is_has) continue;
|
|
|
// 找到指定班级的安排 这里目前只能用name找,这个地方很不稳定,需要找到其他的具有唯一性的判断来执行这个find
|
|
|
const clalr = classArrange.find(f => f.name === name);
|
|
|
// 没找到指定班级的安排
|
|
@@ -598,6 +604,7 @@ class LessonService extends CrudService {
|
|
|
}
|
|
|
// 最后整合
|
|
|
const classLesson = { ...lessinfo, lessons };
|
|
|
+ console.log(classLesson);
|
|
|
// 保存
|
|
|
await this.model.create(classLesson);
|
|
|
}
|