|
@@ -18,28 +18,69 @@ class TeaplanService extends CrudService {
|
|
|
this.dmodel = this.ctx.model.Department;
|
|
|
}
|
|
|
|
|
|
- // async findteacher({ batchid }) {
|
|
|
- // // 查询所有班主任信息
|
|
|
- // const headteachers = await this.hmodel.find();
|
|
|
- // const newheadteachers = [];
|
|
|
- // // 遍历班主任信息
|
|
|
- // for (const headteacher of headteachers) {
|
|
|
- // // 查询某班主任对应的班主任全年计划表
|
|
|
- // const teaplan = await this.model.findOne({ headteacherid: headteacher.id });
|
|
|
- // if (teaplan) {
|
|
|
- // const nobatchids = teaplan.nobatchid;
|
|
|
- // // 如果有对应的全年计划表并且该计划表中的不能上课的批次包含指定批次,则添加status='0'的标记
|
|
|
- // if (nobatchids.includes(batchid)) {
|
|
|
- // newheadteachers.push({ ...JSON.parse(JSON.stringify(headteacher)), status: '0' });
|
|
|
- // } else {
|
|
|
- // newheadteachers.push(headteacher);
|
|
|
- // }
|
|
|
- // } else {
|
|
|
- // newheadteachers.push(headteacher);
|
|
|
- // }
|
|
|
- // }
|
|
|
- // return newheadteachers;
|
|
|
- // }
|
|
|
+ // 查询所有班主任带是否能带班标记
|
|
|
+ async findteacher({ planid, termid, batchid }) {
|
|
|
+ // 查询所有班主任信息
|
|
|
+ const headteachers = await this.hmodel.find();
|
|
|
+ // 根据批次id取得当前批次具体信息
|
|
|
+ const trainplan = await this.tmodel.findById(planid);
|
|
|
+ if (!trainplan) {
|
|
|
+ throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '全年计划信息不存在');
|
|
|
+ }
|
|
|
+ const term = await trainplan.termnum.id(termid);
|
|
|
+ if (!term) {
|
|
|
+ throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '全年计划内期信息不存在');
|
|
|
+ }
|
|
|
+ const batch = await term.batchnum.id(batchid);
|
|
|
+ if (!batch) {
|
|
|
+ throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '全年计划内批次信息不存在');
|
|
|
+ }
|
|
|
+ const newheadteachers = [];
|
|
|
+ // 遍历班主任信息
|
|
|
+ for (const headteacher of headteachers) {
|
|
|
+ // 查询某班主任对应的班主任全年计划表
|
|
|
+ const teaplan = await this.model.findOne({ headteacherid: headteacher.id });
|
|
|
+ if (teaplan) {
|
|
|
+ // 取得所有不能排班的日期列表
|
|
|
+ const nodates = teaplan.nodate;
|
|
|
+ const iswork = await this.teacheriswork(nodates, batch.startdate, batch.enddate);
|
|
|
+ if (iswork) {
|
|
|
+ newheadteachers.push(headteacher);
|
|
|
+ } else {
|
|
|
+ newheadteachers.push({ ...JSON.parse(JSON.stringify(headteacher)), disabled: true });
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ newheadteachers.push(headteacher);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return newheadteachers;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 判断当前日期是否在两个日期之间
|
|
|
+ async betweendate(curdate, startdate, enddate) {
|
|
|
+ // 比较开始日期,如果小于0 为不在此区间
|
|
|
+ // 比较结束日期 如果大于0 为不在此区间
|
|
|
+ const sres = moment(curdate).diff(moment(startdate), 'days');
|
|
|
+ const eres = moment(curdate).diff(moment(enddate), 'days');
|
|
|
+ let result = true;
|
|
|
+ if (sres < 0 || eres > 0) {
|
|
|
+ result = false;
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 判断班主任不能带班日期是否在批次日期里
|
|
|
+ async teacheriswork(nodates, startdate, enddate) {
|
|
|
+ let result = true;
|
|
|
+ for (const nodate of nodates) {
|
|
|
+ const res = this.betweendate(nodate, startdate, enddate);
|
|
|
+ if (res) {
|
|
|
+ result = false;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
|
|
|
async divide({ trainplanid }) {
|
|
|
const data = [];
|