|
@@ -19,6 +19,7 @@ class TrainplanService extends CrudService {
|
|
|
this.tmodel = this.ctx.model.Teacher;
|
|
|
this.stumodel = this.ctx.model.Student;
|
|
|
this.schmodel = this.ctx.model.Schtime;
|
|
|
+ this.lmmodel = this.ctx.model.Lessonmode;
|
|
|
}
|
|
|
|
|
|
async create(data) {
|
|
@@ -38,8 +39,7 @@ class TrainplanService extends CrudService {
|
|
|
const schtimeres = await this.schmodel.create(obj);
|
|
|
if (schtimeres) schtimeArr.push(schtimeres);
|
|
|
}
|
|
|
- if (!schtimeArr.every(e => e)) throw new BusinessError(ErrorCode.DATA_INVALID, '学校计划生成失败');
|
|
|
- else return res;
|
|
|
+ if (!schtimeArr.every(e => e)) { throw new BusinessError(ErrorCode.DATA_INVALID, '学校计划生成失败'); } else return res;
|
|
|
}
|
|
|
|
|
|
async update({ id }, data) {
|
|
@@ -66,6 +66,12 @@ class TrainplanService extends CrudService {
|
|
|
if (status === '1') {
|
|
|
trainplan.status = status;
|
|
|
}
|
|
|
+
|
|
|
+ if (trainplan.termnum) {
|
|
|
+
|
|
|
+ trainplan.termnum = await this.termGetLesson(trainplan.termnum);
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
const res = await trainplan.save();
|
|
|
if (res) {
|
|
@@ -122,6 +128,66 @@ class TrainplanService extends CrudService {
|
|
|
return res;
|
|
|
}
|
|
|
|
|
|
+ async termGetLesson(termnum) {
|
|
|
+ const lessonModelList = await this.lmmodel.find();
|
|
|
+ for (const term of termnum) {
|
|
|
+ for (const batch of term.batchnum) {
|
|
|
+ const { class: classes, startdate, enddate } = batch;
|
|
|
+
|
|
|
+ const typeList = _.uniq(classes.map(i => i.type));
|
|
|
+ const h = _.head(typeList);
|
|
|
+ if (!h) continue;
|
|
|
+ const tem = lessonModelList.find(f => f.type === h);
|
|
|
+ let { lessons } = tem;
|
|
|
+ lessons = JSON.parse(lessons);
|
|
|
+
|
|
|
+ lessons = lessons.filter(f => {
|
|
|
+ const keys = Object.keys(f).filter(f => f.includes('subid'));
|
|
|
+ return keys.length > 0;
|
|
|
+ });
|
|
|
+
|
|
|
+ const times = [];
|
|
|
+
|
|
|
+ let subject = [];
|
|
|
+ lessons.map(i => {
|
|
|
+ times.push(i.time);
|
|
|
+ const keys = Object.keys(i);
|
|
|
+ let arr = [];
|
|
|
+ for (const key of keys) {
|
|
|
+ if (key.match(/\d/g)) arr.push(_.head(key.match(/\d/g)));
|
|
|
+ }
|
|
|
+ arr = _.uniq(arr);
|
|
|
+ for (const ai of arr) {
|
|
|
+ if (i[`day${ai}subid`]) {
|
|
|
+ subject.push({
|
|
|
+ subname: i[`day${ai}`],
|
|
|
+ subid: i[`day${ai}subid`],
|
|
|
+ day: ai,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return i;
|
|
|
+ });
|
|
|
+
|
|
|
+ subject = _.uniqBy(subject, 'subid');
|
|
|
+
|
|
|
+ const dnum = moment(enddate).diff(moment(startdate), 'days') + 1;
|
|
|
+ const dayList = [];
|
|
|
+ for (let ind = 0; ind < dnum; ind++) {
|
|
|
+ dayList.push(moment(startdate).add(ind, 'd').format('YYYY-MM-DD'));
|
|
|
+ }
|
|
|
+
|
|
|
+ for (const sub of subject) {
|
|
|
+ sub.day = dayList[sub.day * 1 - 1];
|
|
|
+ sub.time = times;
|
|
|
+ }
|
|
|
+ batch.lessons = subject;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return termnum;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
async autoclassNew(res) {
|
|
|
|
|
@@ -614,7 +680,10 @@ class TrainplanService extends CrudService {
|
|
|
const styleMonth = [];
|
|
|
|
|
|
|
|
|
- const festivalsCell = { v: '', s: { fill: { fgColor: { rgb: 'A2CD5A' } } } };
|
|
|
+ const festivalsCell = {
|
|
|
+ v: '',
|
|
|
+ s: { fill: { fgColor: { rgb: 'A2CD5A' } } },
|
|
|
+ };
|
|
|
|
|
|
const festivalsCellstyle = 0;
|
|
|
let festivalsRowstyle = 0;
|
|
@@ -737,7 +806,11 @@ class TrainplanService extends CrudService {
|
|
|
|
|
|
const resDate = this.makeCalendar(trainplan.year, index);
|
|
|
data.push([ '' ]);
|
|
|
- data.push([[ this.getBigMonth(index) + '月' ]].concat(resDate.dlist).concat([ '人数' ].concat([ '班级数' ])));
|
|
|
+ data.push(
|
|
|
+ [[ this.getBigMonth(index) + '月' ]]
|
|
|
+ .concat(resDate.dlist)
|
|
|
+ .concat([ '人数' ].concat([ '班级数' ]))
|
|
|
+ );
|
|
|
data.push([ '' ].concat(resDate.tlist));
|
|
|
|
|
|
for (let i = 0; i < classNum; i++) {
|
|
@@ -806,7 +879,20 @@ class TrainplanService extends CrudService {
|
|
|
}
|
|
|
|
|
|
getBigMonth(index) {
|
|
|
- const monthBig = [ '一', '二', '三', '四', '五', '六', '七', '八', '九', '十', '十一', '十二' ];
|
|
|
+ const monthBig = [
|
|
|
+ '一',
|
|
|
+ '二',
|
|
|
+ '三',
|
|
|
+ '四',
|
|
|
+ '五',
|
|
|
+ '六',
|
|
|
+ '七',
|
|
|
+ '八',
|
|
|
+ '九',
|
|
|
+ '十',
|
|
|
+ '十一',
|
|
|
+ '十二',
|
|
|
+ ];
|
|
|
return monthBig[index - 1];
|
|
|
}
|
|
|
|
|
@@ -827,7 +913,14 @@ class TrainplanService extends CrudService {
|
|
|
const tlist = [];
|
|
|
const all = {};
|
|
|
for (let index = 0; index < days; index++) {
|
|
|
- dlist.push(month0 + '月' + moment(year + '-' + month).add(index, 'days').format('D') + '日');
|
|
|
+ dlist.push(
|
|
|
+ month0 +
|
|
|
+ '月' +
|
|
|
+ moment(year + '-' + month)
|
|
|
+ .add(index, 'days')
|
|
|
+ .format('D') +
|
|
|
+ '日'
|
|
|
+ );
|
|
|
let dayy = parseInt(index + 1);
|
|
|
if (dayy * 1 < 10) dayy = '0' + dayy;
|
|
|
tlist.push(this.getWeekDay(year + '-' + month + '-' + dayy));
|
|
@@ -850,7 +943,10 @@ class TrainplanService extends CrudService {
|
|
|
|
|
|
|
|
|
async updateclass({ trainplanid, termid, batchid, classid, rightHeader }) {
|
|
|
- assert(trainplanid && termid && batchid && classid && rightHeader, '缺少参数项');
|
|
|
+ assert(
|
|
|
+ trainplanid && termid && batchid && classid && rightHeader,
|
|
|
+ '缺少参数项'
|
|
|
+ );
|
|
|
|
|
|
const trainplan = await this.model.findById(trainplanid);
|
|
|
if (!trainplan) {
|
|
@@ -870,7 +966,11 @@ class TrainplanService extends CrudService {
|
|
|
}
|
|
|
const res = await trainplan.save();
|
|
|
if (res) {
|
|
|
- const cla_ = await this.clamodel.findOne({ termid, batchid, name: class_.name });
|
|
|
+ const cla_ = await this.clamodel.findOne({
|
|
|
+ termid,
|
|
|
+ batchid,
|
|
|
+ name: class_.name,
|
|
|
+ });
|
|
|
if (cla_) {
|
|
|
cla_.headteacherid = rightHeader;
|
|
|
await cla_.save();
|