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