|
@@ -19,49 +19,42 @@ class ClassService extends CrudService {
|
|
}
|
|
}
|
|
|
|
|
|
async divide(data) {
|
|
async divide(data) {
|
|
- const { classname, number, type, termid, batchid } = data;
|
|
+ const { planid, termid } = data;
|
|
- const classdata = { name: classname, batchid, termid, number, type };
|
|
+ assert(planid, '计划id为必填项');
|
|
- console.log(classdata);
|
|
+ assert(termid, '期id为必填项');
|
|
-
|
|
+
|
|
- const newclass = await this.model.findOne({ name: classname });
|
|
+ const newclass = await this.model.find({ planid, termid });
|
|
- console.log(newclass);
|
|
+ if (!newclass) {
|
|
-
|
|
+ throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '班级信息不存在');
|
|
- if (newclass) {
|
|
+ }
|
|
- throw new BusinessError(ErrorCode.DATA_EXIST, '班级名称已存在');
|
|
+
|
|
-
|
|
+ const newstudent = await this.stumodel.find({ termid }).sort({ schid: 1 });
|
|
-
|
|
+ if (!newstudent) {
|
|
-
|
|
+ throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '学生信息不存在');
|
|
-
|
|
+ }
|
|
-
|
|
+ let _students = _.map(newstudent, 'id');
|
|
-
|
|
+ for (const _class of newclass) {
|
|
-
|
|
+
|
|
-
|
|
+ const stunum = _class.number;
|
|
-
|
|
+
|
|
-
|
|
+ const beforestu = _.take(_students, stunum);
|
|
-
|
|
+
|
|
-
|
|
+ await this.studentup(_class.id, beforestu);
|
|
-
|
|
+
|
|
- } else {
|
|
+ _students = _.difference(_students, beforestu);
|
|
-
|
|
+ }
|
|
- const newdata = await this.model.create(classdata);
|
|
+ }
|
|
-
|
|
+
|
|
- const classid = newdata._id;
|
|
+
|
|
-
|
|
+ async studentup(classid, beforestu) {
|
|
- for (const studentid of data.students) {
|
|
+
|
|
-
|
|
+ for (const stuid of beforestu) {
|
|
- const student = await this.stumodel.findById(studentid);
|
|
+ const student = await this.stumodel.findById(stuid);
|
|
|
|
+ if (student) {
|
|
student.classid = classid;
|
|
student.classid = classid;
|
|
- student.batchid = batchid;
|
|
|
|
- student.termid = termid;
|
|
|
|
await student.save();
|
|
await student.save();
|
|
}
|
|
}
|
|
- for (let i = 1; i <= 7; i++) {
|
|
|
|
- const groupname = i + '组';
|
|
|
|
- const groupdata = { termid, batchid, classid, name: groupname };
|
|
|
|
- await this.gmodel.create(groupdata);
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
|
|
async notice(data) {
|
|
async notice(data) {
|