|
@@ -86,14 +86,6 @@ class TeaplanService extends CrudService {
|
|
|
const data = [];
|
|
|
// 根据全年计划表id查出对应的全年计划详细信息
|
|
|
const trainplan = await this.tmodel.findById(trainplanid);
|
|
|
- // 将全年计划中的批次信息取出放在一个数组中
|
|
|
- const batchList = [];
|
|
|
- for (const term of trainplan.termnum) {
|
|
|
- for (const batch of term.batchnum) {
|
|
|
- batchList.push(batch);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
// 查询本培训计划中班主任全年计划表的全部信息
|
|
|
const teaplanList = await this.model.find({ trainplanid });
|
|
|
// 查询所有班主任信息
|
|
@@ -104,66 +96,66 @@ class TeaplanService extends CrudService {
|
|
|
// 如果班主任信息列表中班主任上报了班主任全年计划,将其移除
|
|
|
if (headteacherInfo.length === 0) {
|
|
|
_.remove(headteacherList, item => item.id === teaplan.headteacherid);
|
|
|
- teaplan.department = headteacherInfo[0].department;
|
|
|
}
|
|
|
}
|
|
|
- // 先将所有没上报的放入可使用班主任中
|
|
|
- let teaListAll = [];
|
|
|
- // 遍历班主任信息,将班主任的id放在headteacherid字段中
|
|
|
- for (const headteacher of headteacherList) {
|
|
|
- headteacher.headteacherid = headteacher.id;
|
|
|
- }
|
|
|
- const noteaList = [];
|
|
|
// 遍历所有批次信息
|
|
|
- for (const batch of batchList) {
|
|
|
- teaListAll = [];
|
|
|
- teaListAll = headteacherList;
|
|
|
- for (const teaplan of teaplanList) {
|
|
|
- if (teaplan.nodate && (teaplan.nodate).length > 0) {
|
|
|
- // 遍历班主任全年计划表中的不能上课的日期
|
|
|
- for (const nodate of teaplan.nodate) {
|
|
|
- // 如果不能上课的日期在该批次的开始时间和结束时间中,将该班主任从班主任列表中删除
|
|
|
- if (moment(nodate).isBetween(batch.startdate, batch.enddate, null, '[]')) {
|
|
|
- noteaList.push(teaplan);
|
|
|
- } else {
|
|
|
- const headteacher_ = await this.hmodel.findById(teaplan.headteacherid);
|
|
|
- if (headteacher_) {
|
|
|
- teaListAll.push(headteacher_);
|
|
|
+ // 将全年计划中的批次信息取出放在一个数组中
|
|
|
+ let teaListKfp = [];
|
|
|
+ let teaListAll = headteacherList;
|
|
|
+ for (const term of trainplan.termnum) {
|
|
|
+ for (const batch of term.batchnum) {
|
|
|
+ if (teaListAll.length === 0) {
|
|
|
+ teaListAll = teaListKfp;
|
|
|
+ teaListKfp = [];
|
|
|
+ }
|
|
|
+ for (const teaplan of teaplanList) {
|
|
|
+ if (teaplan.nodate && (teaplan.nodate).length > 0) {
|
|
|
+ // 遍历班主任全年计划表中的不能上课的日期
|
|
|
+ for (const nodate of teaplan.nodate) {
|
|
|
+ // 如果不能上课的日期在该批次的开始时间和结束时间中,将该班主任从班主任列表中删除
|
|
|
+ if (!moment(nodate).isBetween(batch.startdate, batch.enddate, null, '[]')) {
|
|
|
+ const headteacher_ = await this.hmodel.findById(teaplan.headteacherid);
|
|
|
+ if (headteacher_) {
|
|
|
+ teaListAll.push(headteacher_);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
- // 将班主任排班次数填入数组中
|
|
|
- let teaListAll_ = [];
|
|
|
- for (const teac of teaListAll) {
|
|
|
- // 计算出每个班主任担任过班主任的次数
|
|
|
- const teacount = await this.cmodel.count({ headteacherid: teac.id });
|
|
|
- const newdata = { ...JSON.parse(JSON.stringify(teac)), teacount };
|
|
|
- teaListAll_.push(newdata);
|
|
|
- }
|
|
|
- // 将班主任按排次数排序
|
|
|
- teaListAll_ = _.orderBy(teaListAll_, [ 'teacount' ], [ 'asc' ]);
|
|
|
- // 查出该批次下所有的班级
|
|
|
- const classList = await this.cmodel.find({ batchid: batch.id });
|
|
|
- for (const _class of classList) {
|
|
|
- // 取出所有部门和部门可用人数
|
|
|
- const departmentList = await this.departmentcount(teaListAll_);
|
|
|
- let index = 0;
|
|
|
- for (const _tea of teaListAll_) {
|
|
|
- // 过滤出当前教师的部门和部门可用人数
|
|
|
- const deptinfo = _.find(departmentList, function(o) { return o.deparmentid === _tea.department; });
|
|
|
- if (deptinfo.dcount - index > 1) {
|
|
|
- _class.headteacherid = _tea.id;
|
|
|
- await _class.save();
|
|
|
- _.remove(teaListAll_, item => item.id === _tea.id);
|
|
|
- index = index + 1;
|
|
|
- break;
|
|
|
+ // 将班主任排班次数填入数组中
|
|
|
+ let teaListAll_ = [];
|
|
|
+ for (const teac of teaListAll) {
|
|
|
+ // 计算出每个班主任担任过班主任的次数
|
|
|
+ const teacount = await this.cmodel.count({ headteacherid: teac.id });
|
|
|
+ const newdata = { ...JSON.parse(JSON.stringify(teac)), teacount };
|
|
|
+ teaListAll_.push(newdata);
|
|
|
+ }
|
|
|
+ // 将班主任按排次数排序
|
|
|
+ teaListAll_ = _.orderBy(teaListAll_, [ 'teacount' ], [ 'asc' ]);
|
|
|
+ // 查出该批次下所有的班级
|
|
|
+
|
|
|
+ const classList = await batch.class;
|
|
|
+ console.log(classList);
|
|
|
+ for (const _class of classList) {
|
|
|
+ // 取出所有部门和部门可用人数
|
|
|
+ const departmentList = await this.departmentcount(teaListAll_);
|
|
|
+ let index = 0;
|
|
|
+ for (const _tea of teaListAll_) {
|
|
|
+ // 过滤出当前教师的部门和部门可用人数
|
|
|
+ const deptinfo = _.find(departmentList, function(o) { return o.deparmentid === _tea.department; });
|
|
|
+ if (deptinfo.dcount - index > 1) {
|
|
|
+ _class.headteacherid = _tea.id;
|
|
|
+ _.remove(teaListAll_, item => item.id === _tea.id);
|
|
|
+ _.remove(teaListAll, item => item.id === _tea.id);
|
|
|
+ teaListKfp.push(_tea);
|
|
|
+ index = index + 1;
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- return data;
|
|
|
+ return await trainplan.save();
|
|
|
}
|
|
|
|
|
|
// 判断两个时间段是否有重合部分
|