|
@@ -22,35 +22,45 @@ class BedroomService extends CrudService {
|
|
|
assert(termid, 'termid不能为空');
|
|
|
assert(batchid, 'batchid不能为空');
|
|
|
// 根据计划id取得当前计划
|
|
|
- const trainplan = await this.tmodel.findById({ id: trainplanid });
|
|
|
+ const trainplan = await this.tmodel.findById(trainplanid);
|
|
|
// 根据期id取得当前期信息
|
|
|
const term = trainplan.termnum.find(p => p.id === termid);
|
|
|
// 根据批次id查询批次信息
|
|
|
const _batch = term.batchnum.find(p => p.id === batchid);
|
|
|
// 查询所有寝室列表
|
|
|
const bedroomList = await this.model.find({ batch: _batch.batch });
|
|
|
-
|
|
|
// 循环所有当前批次下的寝室列表进行分寝处理
|
|
|
+ const studentList = await this.getstudents(termid, batchid);
|
|
|
+ console.log('stulen-->' + studentList.length);
|
|
|
for (const bedroom of bedroomList) {
|
|
|
+ console.log(bedroom.code);
|
|
|
// 判断当前寝室号是否已有
|
|
|
// 根据期id查找所有当期学生列表
|
|
|
- const studentList = await this.getstudents(termid, batchid);
|
|
|
- const _stu = studentList.find(p => p.bedroomid === bedroom.id);
|
|
|
+ const _stu = await this.getbedroomstudents(termid, batchid, bedroom.id);
|
|
|
+ console.log(_stu.length);
|
|
|
if (bedroom.number !== _stu.length) {
|
|
|
let i = 0;
|
|
|
let _gender = '';
|
|
|
for (const stud of studentList) {
|
|
|
+ console.log('stu---' + stud.bedroom);
|
|
|
+ if (stud.bedroomid) {
|
|
|
+ if (stud.bedroomid === bedroom.id) {
|
|
|
+ i = i + 1;
|
|
|
+ }
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ console.log('i--->' + i);
|
|
|
if (i === 0) {
|
|
|
if (!bedroom.gender) {
|
|
|
stud.bedroomid = bedroom.id;
|
|
|
- stud.bedroom = bedroom.number;
|
|
|
+ stud.bedroom = bedroom.code;
|
|
|
await stud.save();
|
|
|
i = i + 1;
|
|
|
_gender = stud.gender;
|
|
|
} else {
|
|
|
if (bedroom.gender === stud.gender) {
|
|
|
stud.bedroomid = bedroom.id;
|
|
|
- stud.bedroom = bedroom.number;
|
|
|
+ stud.bedroom = bedroom.code;
|
|
|
await stud.save();
|
|
|
i = i + 1;
|
|
|
_gender = stud.gender;
|
|
@@ -59,7 +69,7 @@ class BedroomService extends CrudService {
|
|
|
} else if (i < bedroom.number) {
|
|
|
if (_gender === stud.gender) {
|
|
|
stud.bedroomid = bedroom.id;
|
|
|
- stud.bedroom = bedroom.number;
|
|
|
+ stud.bedroom = bedroom.code;
|
|
|
await stud.save();
|
|
|
i = i + 1;
|
|
|
}
|
|
@@ -79,6 +89,13 @@ class BedroomService extends CrudService {
|
|
|
const studentList = await this.umodel.find({ termid, batchid });
|
|
|
return studentList;
|
|
|
}
|
|
|
+
|
|
|
+ // 取得符合条件的学生列表
|
|
|
+ async getbedroomstudents(termid, batchid, bedroomid) {
|
|
|
+ // 根据期id查找所有当期学生列表
|
|
|
+ const studentList = await this.umodel.find({ termid, batchid, bedroomid });
|
|
|
+ return studentList;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
module.exports = BedroomService;
|