|
@@ -25,6 +25,8 @@ class ClassService extends CrudService {
|
|
|
const { planid, termid } = data;
|
|
|
assert(planid, '计划id为必填项');
|
|
|
assert(termid, '期id为必填项');
|
|
|
+ // 先自动生成班级
|
|
|
+ await this.autoclass(planid, termid);
|
|
|
// 根据计划id与期id查询所有批次下的班级
|
|
|
const newclass = await this.model.find({ planid, termid });
|
|
|
if (!newclass) {
|
|
@@ -50,6 +52,27 @@ class ClassService extends CrudService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // 自动生成班级私有方法
|
|
|
+ async autoclass(planid, termid) {
|
|
|
+ // 删除所有计划下的班级
|
|
|
+ await this.clamodel.deleteMany({ planid, termid });
|
|
|
+ // 根据批次id取得当前批次具体信息
|
|
|
+ const res = await this.tmodel.findById(planid);
|
|
|
+ if (!res) {
|
|
|
+ throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '全年计划信息不存在');
|
|
|
+ }
|
|
|
+ // 循环出所有班级进行添加操作
|
|
|
+ for (const term of res.termnum) {
|
|
|
+ for (const batch of term.batchnum) {
|
|
|
+ const classs = await batch.class;
|
|
|
+ for (const cla of classs) {
|
|
|
+ const newdata = { name: cla.name, number: cla.number, batchid: batch.id, termid: term.id, planid: res.id, type: cla.type, headteacherid: cla.headteacherid };
|
|
|
+ await this.clamodel.create(newdata);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// 根据传入的学生列表和班级id更新学生信息
|
|
|
async studentup(classid, batchid, beforestu) {
|
|
|
// 循环学生id
|