|
@@ -93,6 +93,7 @@ class TeaplanService extends CrudService {
|
|
|
batchList.push(batch);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
// 查询本培训计划中班主任全年计划表的全部信息
|
|
|
const teaplanList = await this.model.find({ trainplanid });
|
|
|
// 查询所有班主任信息
|
|
@@ -101,78 +102,65 @@ class TeaplanService extends CrudService {
|
|
|
// 过滤出班主任信息表中id为此班主任全年计划信息班主任id的数据
|
|
|
const headteacherInfo = _.filter(headteacherList, item => item.id === teaplan.headteacherid);
|
|
|
// 如果班主任信息列表中班主任上报了班主任全年计划,将其移除
|
|
|
- if (headteacherInfo.length >= 1) {
|
|
|
+ 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 teaList = _.concat(teaplanList, headteacherList);
|
|
|
- let noteaList = [];
|
|
|
+ const noteaList = [];
|
|
|
// 遍历所有批次信息
|
|
|
for (const batch of batchList) {
|
|
|
- let _teaList = [];
|
|
|
- for (const teaplan of teaList) {
|
|
|
+ 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_);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- // 过滤出已分配的数据中该班主任的数据
|
|
|
- const teaInfo = _.filter(data, item => item.headteacherid === teaplan.headteacherid);
|
|
|
+ }
|
|
|
+ // 将班主任排班次数填入数组中
|
|
|
+ let teaListAll_ = [];
|
|
|
+ for (const teac of teaListAll) {
|
|
|
// 计算出每个班主任担任过班主任的次数
|
|
|
- teaplan.teacount = await this.cmodel.count({ headteacherid: teaplan.headteacherid }) + teaInfo.length;
|
|
|
- // 如果已分配的数据中该班主任的数据长度大于0
|
|
|
- if (teaInfo.length > 0) {
|
|
|
- // 遍历已分配的数据中该班主任的数据
|
|
|
- for (const _teaInfo of teaInfo) {
|
|
|
- // 查询该班主任已分配的数据中的班级信息
|
|
|
- const _class = await this.cmodel.findById(_teaInfo.classid);
|
|
|
- // 根据班级的批次id查出该班级的开始时间和结束时间
|
|
|
- const batchInfo = _.filter(batchList, item => item.id === _class.batchid);
|
|
|
- // 如果该班级的开始时间和结束时间于当前遍历批次的开始时间和结束时间有重合部分,将该班主任加入不能上课的班主任数组中
|
|
|
- if (await this.isrepeat(batchInfo.startdate, batchInfo.enddate, batch.startdate, batch.enddate)) {
|
|
|
- noteaList.push(teaplan);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- // 将数组去重
|
|
|
- noteaList = _.uniqWith(noteaList, _.isEqual);
|
|
|
- // 将班主任全年计划表过滤,去除在不能上课的班主任数组中已存在的数据
|
|
|
- _teaList = _.difference(teaList, noteaList);
|
|
|
- // 将不能上课的班主任数组清空
|
|
|
- noteaList = [];
|
|
|
- const departmentList = await this.departmentcount(_teaList);
|
|
|
- for (const department of departmentList) {
|
|
|
- // 如果部门中人员的数量减去能部门中上课的班主任数量小于一,那么将能上课的班主任数组中部门为该部门的班主任移除一个
|
|
|
- if ((department.dcount - department.dnum) < 1) {
|
|
|
- let _noteaList = _.filter(_teaList, item => item.deparment === department.deparmentid);
|
|
|
- _noteaList = _.orderBy(_noteaList, [ 'teacount' ], [ 'desc' ]);
|
|
|
- _teaList = _.difference(_teaList, _noteaList[0]);
|
|
|
- }
|
|
|
- }
|
|
|
- // 将该批次最终筛选出的能上课的班主任数组按每个班主任担任过班主任的次数倒序排序
|
|
|
- _teaList = _.orderBy(_teaList, [ 'teacount' ], [ 'asc' ]);
|
|
|
-
|
|
|
+ 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 });
|
|
|
- // 循环该批次下所有的班级
|
|
|
- let index = 0;
|
|
|
for (const _class of classList) {
|
|
|
- if (_teaList.length > 0 && _teaList[index]) {
|
|
|
- data.push({ classid: _class.id, headteacherid: _teaList[index].headteacherid, teacount: _teaList[index].teacount });
|
|
|
- } else {
|
|
|
- data.push({ classid: _class.id, headteacherid: undefined });
|
|
|
+ // 取出所有部门和部门可用人数
|
|
|
+ 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;
|
|
|
+ }
|
|
|
}
|
|
|
- index = index + 1;
|
|
|
}
|
|
|
}
|
|
|
return data;
|