|
@@ -16,6 +16,8 @@ class TeaplanService extends CrudService {
|
|
|
this.tmodel = this.ctx.model.Trainplan;
|
|
|
this.cmodel = this.ctx.model.Class;
|
|
|
this.dmodel = this.ctx.model.Department;
|
|
|
+ this.submodel = this.ctx.model.Subject;
|
|
|
+ this.teamodel = this.ctx.model.Teacher;
|
|
|
}
|
|
|
|
|
|
|
|
@@ -29,25 +31,40 @@ class TeaplanService extends CrudService {
|
|
|
}
|
|
|
const term = await trainplan.termnum.id(termid);
|
|
|
if (!term) {
|
|
|
- throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '全年计划内期信息不存在');
|
|
|
+ throw new BusinessError(
|
|
|
+ ErrorCode.DATA_NOT_EXIST,
|
|
|
+ '全年计划内期信息不存在'
|
|
|
+ );
|
|
|
}
|
|
|
const batch = await term.batchnum.id(batchid);
|
|
|
if (!batch) {
|
|
|
- throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '全年计划内批次信息不存在');
|
|
|
+ throw new BusinessError(
|
|
|
+ ErrorCode.DATA_NOT_EXIST,
|
|
|
+ '全年计划内批次信息不存在'
|
|
|
+ );
|
|
|
}
|
|
|
const newheadteachers = [];
|
|
|
|
|
|
for (const headteacher of headteachers) {
|
|
|
|
|
|
- const teaplan = await this.model.findOne({ headteacherid: headteacher.id });
|
|
|
+ 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);
|
|
|
+ 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 });
|
|
|
+ newheadteachers.push({
|
|
|
+ ...JSON.parse(JSON.stringify(headteacher)),
|
|
|
+ disabled: true,
|
|
|
+ });
|
|
|
}
|
|
|
} else {
|
|
|
newheadteachers.push(headteacher);
|
|
@@ -102,18 +119,30 @@ class TeaplanService extends CrudService {
|
|
|
|
|
|
for (const term of trainplan.termnum) {
|
|
|
for (const batch of term.batchnum) {
|
|
|
- const teaListAll = _.cloneDeep(JSON.parse(JSON.stringify(headteacherList)));
|
|
|
+ const teaListAll = _.cloneDeep(
|
|
|
+ JSON.parse(JSON.stringify(headteacherList))
|
|
|
+ );
|
|
|
for (const teaplan of teaplanList) {
|
|
|
- if (teaplan.nodate && (teaplan.nodate).length > 0) {
|
|
|
+ if (teaplan.nodate && teaplan.nodate.length > 0) {
|
|
|
|
|
|
for (const nodate of teaplan.nodate) {
|
|
|
-
|
|
|
- if (moment(nodate).isBetween(batch.startdate, batch.enddate, null, '[]')) {
|
|
|
+
|
|
|
+ if (
|
|
|
+ moment(nodate).isBetween(
|
|
|
+ batch.startdate,
|
|
|
+ batch.enddate,
|
|
|
+ null,
|
|
|
+ '[]'
|
|
|
+ )
|
|
|
+ ) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- _.remove(teaListAll, item => item.id === teaplan.headteacherid);
|
|
|
+ _.remove(
|
|
|
+ teaListAll,
|
|
|
+ item => item.id === teaplan.headteacherid
|
|
|
+ );
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -138,7 +167,9 @@ class TeaplanService extends CrudService {
|
|
|
let index = 0;
|
|
|
for (const _tea of teaListAll_) {
|
|
|
|
|
|
- const deptinfo = _.find(departmentList, function(o) { return o.deparmentid === _tea.department; });
|
|
|
+ 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);
|
|
@@ -176,14 +207,137 @@ class TeaplanService extends CrudService {
|
|
|
departmentList = _.uniqWith(departmentList, _.isEqual);
|
|
|
for (const department of departmentList) {
|
|
|
|
|
|
- const dnum = _.filter(teaList, item => item.department === department.deparmentid).length;
|
|
|
+ const dnum = _.filter(
|
|
|
+ teaList,
|
|
|
+ item => item.department === department.deparmentid
|
|
|
+ ).length;
|
|
|
department.dnum = dnum;
|
|
|
|
|
|
- const dcount = await this.hmodel.count({ department: department.deparmentid });
|
|
|
+ const dcount = await this.hmodel.count({
|
|
|
+ department: department.deparmentid,
|
|
|
+ });
|
|
|
department.dcount = dcount;
|
|
|
}
|
|
|
return departmentList;
|
|
|
}
|
|
|
+
|
|
|
+ async arrangeteacher({ planid }) {
|
|
|
+ const trainplan = await this.tmodel.findOne({ id: planid });
|
|
|
+ if (!trainplan) { throw new BusinessError(ErrorCode.DATA_EXISTED, '年度计划不存在'); }
|
|
|
+
|
|
|
+ const teacherList = await this.teamodel.find();
|
|
|
+
|
|
|
+ const teaplanList = await this.model.find();
|
|
|
+
|
|
|
+ const subjectList = await this.submodel.find();
|
|
|
+ const termList = _.cloneDeep(trainplan.termnum);
|
|
|
+ const { termnum } = termList;
|
|
|
+ if (!termnum) return;
|
|
|
+
|
|
|
+ const arr = [];
|
|
|
+ for (const t of termnum) {
|
|
|
+ const { batchnum, term, _id: termid } = t;
|
|
|
+
|
|
|
+ for (const b of batchnum) {
|
|
|
+ const { class: classes, lessons, startdate, enddate, _id: batchid } = b;
|
|
|
+ const claslesList = this.setList(term, termid, batchid, classes, lessons);
|
|
|
+ arr.push(...claslesList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ const afterList = [];
|
|
|
+
|
|
|
+ for (const l of arr) {
|
|
|
+ const { termid, subid, day: date, teaid } = l;
|
|
|
+ if (teaid) { afterList.push(l); continue; }
|
|
|
+ const subject = subjectList.find(f => ObjectId(subid).equals(f._id));
|
|
|
+ if (subject.need_teacher !== '0') continue;
|
|
|
+
|
|
|
+ let applyList = teaplanList.filter(f => f.termid === termid && f.subid === subid && f.date === date);
|
|
|
+ applyList = applyList.map(i => {
|
|
|
+ const r = this.teacherList.find(f => ObjectId(i.teacherid).equals(f._id));
|
|
|
+ if (r) {
|
|
|
+ const { name: teaname, xsscore: score } = r;
|
|
|
+ i.teaname = teaname;
|
|
|
+ i.score = score * 1;
|
|
|
+ }
|
|
|
+ return i;
|
|
|
+ });
|
|
|
+ applyList = _.orderBy(applyList, [ 'score' ], [ 'desc' ]);
|
|
|
+
|
|
|
+ for (const atea of applyList) {
|
|
|
+
|
|
|
+ const tr = afterList.find(f => f.teaid === atea.teacherid && f.day === atea.date);
|
|
|
+ if (tr) continue;
|
|
|
+ else {
|
|
|
+ l.teaid = tr.teacherid;
|
|
|
+ l.teaname = tr.teaname;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ afterList.push(l);
|
|
|
+ }
|
|
|
+
|
|
|
+ let newTermnum = [];
|
|
|
+ for (const l of afterList) {
|
|
|
+ const { termid, batchid, classid, ...info } = l;
|
|
|
+ const updata = _.pick(info, [ 'day', 'subid', 'subname', 'teaid', 'teaname', 'time' ]);
|
|
|
+ newTermnum = trainplan.termnum.map(t => {
|
|
|
+
|
|
|
+ if (ObjectId(termid).equals(t._id)) {
|
|
|
+ t.batchnum = t.batchnum.map(b => {
|
|
|
+ if (ObjectId(batchid).equals(b._id)) {
|
|
|
+
|
|
|
+ b.class = b.class.map(c => {
|
|
|
+ if (ObjectId(classid).equals(c._id)) {
|
|
|
+ if (c.lessons) {
|
|
|
+
|
|
|
+ const r = c.lessons.find(f => f.subid === updata.subid);
|
|
|
+ if (r) {
|
|
|
+ const rindex = c.lessons.findIndex(
|
|
|
+ f => f.subid === updata.subid
|
|
|
+ );
|
|
|
+ c.lessons[rindex] = updata;
|
|
|
+ } else {
|
|
|
+ c.lessons.push(updata);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+
|
|
|
+ c.lessons = [ updata ];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return c;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return b;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return t;
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ trainplan.termnum = newTermnum;
|
|
|
+ return await trainplan.save();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ setList(term, termid, batchid, classes, lessonTemplate) {
|
|
|
+ const arr = [];
|
|
|
+
|
|
|
+ for (const cla of classes) {
|
|
|
+ cla.term = term;
|
|
|
+ cla.termid = termid;
|
|
|
+ cla.batchid = batchid;
|
|
|
+ const { lessons } = cla;
|
|
|
+ if (!lessons) cla.lessons = lessonTemplate;
|
|
|
+ cla.lessons.map(i => {
|
|
|
+ let obj = _.omit(cla, [ 'lessons' ]);
|
|
|
+ obj = { ...obj, ...i, classid: _.clone(cla._id) };
|
|
|
+ arr.push(obj);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return arr;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
module.exports = TeaplanService;
|