|
@@ -1,6 +1,5 @@
|
|
|
'use strict';
|
|
|
|
|
|
-
|
|
|
const _ = require('lodash');
|
|
|
const { CrudService } = require('naf-framework-mongoose/lib/service');
|
|
|
const assert = require('assert');
|
|
@@ -37,15 +36,21 @@ class TrainplanService extends CrudService {
|
|
|
if (res) planid = res._id;
|
|
|
const schoolList = await this.smodel.find();
|
|
|
const schtimeArr = [];
|
|
|
+ // 为学校创建不可以培训的数据
|
|
|
for (const sch of schoolList) {
|
|
|
const { code } = sch;
|
|
|
+ // 没有学校编码就下一个
|
|
|
+ if (!code) continue;
|
|
|
const obj = { schid: code, year, planid };
|
|
|
let schtimeres;
|
|
|
schtimeres = await this.schmodel.findOne(obj);
|
|
|
- if (!schtimeres)schtimeres = await this.schmodel.create(obj);
|
|
|
+ if (!schtimeres) 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) {
|
|
@@ -137,6 +142,8 @@ class TrainplanService extends CrudService {
|
|
|
for (const school of schoolList) {
|
|
|
const r = await this.schmodel.findOne({ year: trainplan.year, planid: id, schid: school.code });
|
|
|
if (r) continue;
|
|
|
+ // 学校没有编码直接跳过
|
|
|
+ if (!school.code) continue;
|
|
|
const obj = { schid: school.code, year: trainplan.year, planid: id };
|
|
|
await this.schmodel.create(obj);
|
|
|
}
|
|
@@ -150,24 +157,24 @@ class TrainplanService extends CrudService {
|
|
|
for (const batch of term.batchnum) {
|
|
|
const { class: classes, startdate, enddate } = batch;
|
|
|
// 获取每批次下每个班的班级类型
|
|
|
- const typeList = _.uniq(classes.map(i => i.type));
|
|
|
+ const typeList = _.uniq(classes.map((i) => i.type));
|
|
|
const h = _.head(typeList);
|
|
|
if (!h) continue;
|
|
|
- const tem = lessonModelList.find(f => f.type === h);
|
|
|
+ const tem = lessonModelList.find((f) => f.type === h);
|
|
|
if (!tem) continue;
|
|
|
let { lessons } = tem;
|
|
|
if (!lessons) continue;
|
|
|
lessons = JSON.parse(lessons);
|
|
|
// 过滤出上课的时间段
|
|
|
- lessons = lessons.filter(f => {
|
|
|
- const keys = Object.keys(f).filter(f => f.includes('subid'));
|
|
|
+ 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 => {
|
|
|
+ lessons.map((i) => {
|
|
|
times.push(i.time);
|
|
|
const keys = Object.keys(i);
|
|
|
let arr = [];
|
|
@@ -300,10 +307,7 @@ class TrainplanService extends CrudService {
|
|
|
// 保存后所有期id
|
|
|
const batchid_res = _.map(el.batchnum, 'id');
|
|
|
// 保存前所有期id
|
|
|
- const batchid_old = _.map(
|
|
|
- trainplanold.termnum.id(el.id).batchnum,
|
|
|
- 'id'
|
|
|
- );
|
|
|
+ const batchid_old = _.map(trainplanold.termnum.id(el.id).batchnum, 'id');
|
|
|
// 取得要删除的期id,进行班级中删除已删除期的班级
|
|
|
const delbatchs = _.difference(batchid_old, batchid_res);
|
|
|
// 循环删除已经删除期的所有班级
|
|
@@ -331,10 +335,7 @@ class TrainplanService extends CrudService {
|
|
|
await this.clamodel.create(newdata);
|
|
|
}
|
|
|
} else {
|
|
|
- if (
|
|
|
- batchnum.class ===
|
|
|
- trainplanold.termnum.id(el.id).batchnum.id(batchnum.id).class
|
|
|
- ) {
|
|
|
+ if (batchnum.class === trainplanold.termnum.id(el.id).batchnum.id(batchnum.id).class) {
|
|
|
// 编辑只会针对班级人数进行修改。
|
|
|
const _class = await this.clamodel.find({
|
|
|
termid: el.id,
|
|
@@ -421,7 +422,7 @@ class TrainplanService extends CrudService {
|
|
|
student.isComming = utils.getIsNot(student.isComming);
|
|
|
student.trainplandName = trainplandName;
|
|
|
// 期次
|
|
|
- const term = trainplan.termnum.filter(term => {
|
|
|
+ const term = trainplan.termnum.filter((term) => {
|
|
|
return term.id === student.termid;
|
|
|
});
|
|
|
if (term.length > 0) {
|
|
@@ -429,7 +430,7 @@ class TrainplanService extends CrudService {
|
|
|
}
|
|
|
// 批次
|
|
|
if (term.length !== 0) {
|
|
|
- const batch = term[0].batchnum.filter(batch => {
|
|
|
+ const batch = term[0].batchnum.filter((batch) => {
|
|
|
return batch.id === student.batchid;
|
|
|
});
|
|
|
if (batch.length > 0) {
|
|
@@ -473,30 +474,13 @@ class TrainplanService extends CrudService {
|
|
|
const _data = studentList;
|
|
|
const headers = _headers
|
|
|
.map(({ title }) => title)
|
|
|
- .map((v, i) =>
|
|
|
- Object.assign({}, { v, position: String.fromCharCode(65 + i) + 1 })
|
|
|
- )
|
|
|
- .reduce(
|
|
|
- (prev, next) =>
|
|
|
- Object.assign({}, prev, { [next.position]: { v: next.v } }),
|
|
|
- {}
|
|
|
- );
|
|
|
+ .map((v, i) => Object.assign({}, { v, position: String.fromCharCode(65 + i) + 1 }))
|
|
|
+ .reduce((prev, next) => Object.assign({}, prev, { [next.position]: { v: next.v } }), {});
|
|
|
|
|
|
const data = _data
|
|
|
- .map((v, i) =>
|
|
|
- _headers.map(({ key }, j) =>
|
|
|
- Object.assign(
|
|
|
- {},
|
|
|
- { v: v[key], position: String.fromCharCode(65 + j) + (i + 2) }
|
|
|
- )
|
|
|
- )
|
|
|
- )
|
|
|
+ .map((v, i) => _headers.map(({ key }, j) => Object.assign({}, { v: v[key], position: String.fromCharCode(65 + j) + (i + 2) })))
|
|
|
.reduce((prev, next) => prev.concat(next))
|
|
|
- .reduce(
|
|
|
- (prev, next) =>
|
|
|
- Object.assign({}, prev, { [next.position]: { v: next.v } }),
|
|
|
- {}
|
|
|
- );
|
|
|
+ .reduce((prev, next) => Object.assign({}, prev, { [next.position]: { v: next.v } }), {});
|
|
|
|
|
|
// 合并 headers 和 data
|
|
|
const output = Object.assign({}, headers, data);
|
|
@@ -519,15 +503,13 @@ class TrainplanService extends CrudService {
|
|
|
// 导出学校大表
|
|
|
async exportSchool({ trainplanId }) {
|
|
|
const rows = [
|
|
|
- [ '学校名称', '期数' ],
|
|
|
- [ ' ', '班级数' ],
|
|
|
- [ ' ', '时间' ],
|
|
|
- [ ' ', '备注' ],
|
|
|
+ ['学校名称', '期数'],
|
|
|
+ [' ', '班级数'],
|
|
|
+ [' ', '时间'],
|
|
|
+ [' ', '备注'],
|
|
|
];
|
|
|
// 操作
|
|
|
- const operaList = [
|
|
|
- { startRow: 1, startCol: 1, endRow: 5, endCol: 1 },
|
|
|
- ];
|
|
|
+ const operaList = [{ startRow: 1, startCol: 1, endRow: 5, endCol: 1 }];
|
|
|
// 操作:
|
|
|
// step1: 班级类型的动态列
|
|
|
// step2: 1行:期数需要合并列:需要合并的列数根据下面的批次决定
|
|
@@ -538,7 +520,7 @@ class TrainplanService extends CrudService {
|
|
|
// 批次期次都在这里面
|
|
|
let trainplan = await this.model.findById(trainplanId);
|
|
|
if (trainplan) trainplan = JSON.parse(JSON.stringify(trainplan));
|
|
|
- const fn = trainplan.title;// 文件名
|
|
|
+ const fn = trainplan.title; // 文件名
|
|
|
let classType = await this.ctmodel.find();
|
|
|
if (classType) classType = JSON.parse(JSON.stringify(classType));
|
|
|
let schtime = await this.schmodel.find({ planid: trainplanId });
|
|
@@ -546,13 +528,13 @@ class TrainplanService extends CrudService {
|
|
|
// step1
|
|
|
// 整理班级类型的顺序
|
|
|
if (_.isArray(classType) && classType.length > 0) {
|
|
|
- classType = classType.map(i => {
|
|
|
+ classType = classType.map((i) => {
|
|
|
i.sort = parseInt(i.code);
|
|
|
return i;
|
|
|
});
|
|
|
- classType = _.orderBy(classType, [ 'sort' ], [ 'desc' ]);
|
|
|
+ classType = _.orderBy(classType, ['sort'], ['desc']);
|
|
|
}
|
|
|
- const row5 = [ '' ];
|
|
|
+ const row5 = [''];
|
|
|
for (const ct of classType) {
|
|
|
const { name } = ct;
|
|
|
row5.push(name);
|
|
@@ -621,23 +603,23 @@ class TrainplanService extends CrudService {
|
|
|
sortPlan(termnum) {
|
|
|
if (_.isArray(termnum) && termnum.length > 0) {
|
|
|
// 数据排序
|
|
|
- termnum = termnum.map(t => {
|
|
|
+ termnum = termnum.map((t) => {
|
|
|
const { batchnum, term } = t;
|
|
|
t.termnum = parseInt(term);
|
|
|
- t.batchnum = batchnum.map(b => {
|
|
|
+ t.batchnum = batchnum.map((b) => {
|
|
|
const { batch, class: classes } = b;
|
|
|
b.batchnum = _.isNumber(parseInt(batch)) ? parseInt(batch) : batch;
|
|
|
- b.class = classes.map(c => {
|
|
|
+ b.class = classes.map((c) => {
|
|
|
const { name } = c;
|
|
|
c.classnum = _.isNumber(parseInt(name)) ? parseInt(name) : name;
|
|
|
return c;
|
|
|
});
|
|
|
- b.class = _.orderBy(b.class, [ 'classnum' ], [ 'asc' ]);
|
|
|
+ b.class = _.orderBy(b.class, ['classnum'], ['asc']);
|
|
|
return b;
|
|
|
});
|
|
|
return t;
|
|
|
});
|
|
|
- termnum = _.orderBy(termnum, [ 'termnum' ], [ 'asc' ]);
|
|
|
+ termnum = _.orderBy(termnum, ['termnum'], ['asc']);
|
|
|
}
|
|
|
return termnum;
|
|
|
}
|
|
@@ -652,7 +634,7 @@ class TrainplanService extends CrudService {
|
|
|
let word = '';
|
|
|
if (c) {
|
|
|
const { type } = c;
|
|
|
- const r = classType.find(f => f.code === type);
|
|
|
+ const r = classType.find((f) => f.code === type);
|
|
|
word = classes.length;
|
|
|
if (r) word = `${word}(${r.name})`;
|
|
|
}
|
|
@@ -677,7 +659,7 @@ class TrainplanService extends CrudService {
|
|
|
// 整理完备注,按照顺序,依次去找,是否有备注,有就推进去备注,没有推空
|
|
|
const remarks = _.cloneDeep(remarkRowData);
|
|
|
for (const b of batchs) {
|
|
|
- const r = arr.find(f => ObjectId(f.batchid).equals(b._id));
|
|
|
+ const r = arr.find((f) => ObjectId(f.batchid).equals(b._id));
|
|
|
if (r) remarks.push(r.remark);
|
|
|
else remarks.push('');
|
|
|
}
|
|
@@ -704,11 +686,11 @@ class TrainplanService extends CrudService {
|
|
|
// 学校按code排序
|
|
|
if (schoolList && schoolList.length > 0) {
|
|
|
schoolList = JSON.parse(JSON.stringify(schoolList));
|
|
|
- schoolList = schoolList.map(i => {
|
|
|
+ schoolList = schoolList.map((i) => {
|
|
|
i.schnum = this.toParseInt(i.code);
|
|
|
return i;
|
|
|
});
|
|
|
- schoolList = _.orderBy(schoolList, [ 'schnum' ], [ 'asc' ]);
|
|
|
+ schoolList = _.orderBy(schoolList, ['schnum'], ['asc']);
|
|
|
}
|
|
|
|
|
|
// 实际安排的学校计划
|
|
@@ -725,15 +707,15 @@ class TrainplanService extends CrudService {
|
|
|
for (const sch of schoolList) {
|
|
|
const { name, code } = sch;
|
|
|
// 该学校的数据
|
|
|
- const arr = [ name ];
|
|
|
+ const arr = [name];
|
|
|
|
|
|
// 学校实际分配的计划, 先不管别的,先把计划的问题处理了
|
|
|
- const reaFRes = schArrange.filter(f => f.schid === code);
|
|
|
+ const reaFRes = schArrange.filter((f) => f.schid === code);
|
|
|
// 过滤出来学校已经分配的数据后,需要知道是什么类型的
|
|
|
const reaObj = { total: 0, reaTotal: 0 }; // key:班级类型, value:为实际分配的人数
|
|
|
for (const rr of reaFRes) {
|
|
|
const { batchid, number } = rr;
|
|
|
- const r = batchs.find(f => f._id === batchid);
|
|
|
+ const r = batchs.find((f) => f._id === batchid);
|
|
|
if (r) {
|
|
|
const { type } = r;
|
|
|
reaObj[type] = (this.toParseInt(reaObj[type]) || 0) + this.toParseInt(number); // 计划人数累加
|
|
@@ -742,14 +724,14 @@ class TrainplanService extends CrudService {
|
|
|
}
|
|
|
|
|
|
// 先查预计划有没有
|
|
|
- const p = schPlan.find(f => f.code === code);
|
|
|
+ const p = schPlan.find((f) => f.code === code);
|
|
|
if (p) {
|
|
|
// 获取到预设的学校计划
|
|
|
const { classnum } = p;
|
|
|
// 班级类型对应的计划
|
|
|
for (const ct of classType) {
|
|
|
const { code } = ct;
|
|
|
- const r = classnum.find(f => f.code === code);
|
|
|
+ const r = classnum.find((f) => f.code === code);
|
|
|
// n为要求的人数
|
|
|
let n = 0;
|
|
|
if (r) {
|
|
@@ -762,7 +744,7 @@ class TrainplanService extends CrudService {
|
|
|
let word = _.subtract(n - rea);
|
|
|
// n===0:表示原来计划里没有这个类型,word再为0,说明实际上也没有这个类型,就不需要显示了
|
|
|
if (n === 0 && word === 0) word = '';
|
|
|
- reaObj.total = _.add(reaObj.total, n);// 计划人数累加
|
|
|
+ reaObj.total = _.add(reaObj.total, n); // 计划人数累加
|
|
|
arr.push(word);
|
|
|
}
|
|
|
} else {
|
|
@@ -770,10 +752,10 @@ class TrainplanService extends CrudService {
|
|
|
const keys = Object.keys(reaObj);
|
|
|
for (const ct of classType) {
|
|
|
if (keys.length <= 0) {
|
|
|
- // 没分配,填充,下一个
|
|
|
+ // 没分配,填充,下一个
|
|
|
arr.push('');
|
|
|
} else {
|
|
|
- // 没计划但是实际分配了,就需要体现出来了
|
|
|
+ // 没计划但是实际分配了,就需要体现出来了
|
|
|
const word = reaObj[ct.code];
|
|
|
if (word && word !== 0) {
|
|
|
arr.push(`-${word}`);
|
|
@@ -789,7 +771,7 @@ class TrainplanService extends CrudService {
|
|
|
|
|
|
// 循环学校列表,找到学校的所有安排,然后找到对应的索引,进行数据整理
|
|
|
for (const rea of reaFRes) {
|
|
|
- const index = batchs.findIndex(f => f._id === rea.batchid);
|
|
|
+ const index = batchs.findIndex((f) => f._id === rea.batchid);
|
|
|
if (index < 0) continue;
|
|
|
arr[index + 5] = rea.number;
|
|
|
}
|
|
@@ -797,7 +779,7 @@ class TrainplanService extends CrudService {
|
|
|
}
|
|
|
// 合计行:只有学校列不计算,其他的列全部计算=>批次列(batchs.length)+班级类型列(classType.length)+总人数列(1)+实际分配人数列(1)
|
|
|
const colTotal = batchs.length + classType.length + 1 + 1;
|
|
|
- const count = [ '合计' ];
|
|
|
+ const count = ['合计'];
|
|
|
// 第一列不需要,是学校/合计列
|
|
|
for (let i = 1; i <= colTotal; i++) {
|
|
|
const cmid = [];
|
|
@@ -833,7 +815,7 @@ class TrainplanService extends CrudService {
|
|
|
const head = _.head(classes);
|
|
|
if (head) {
|
|
|
const { type } = head;
|
|
|
- if (type)obj.type = type;
|
|
|
+ if (type) obj.type = type;
|
|
|
}
|
|
|
const all = classes.reduce((p, n) => p + (parseInt(n.number) || 0), 0);
|
|
|
if (_.isNumber(all)) b.all = all;
|
|
@@ -1021,13 +1003,9 @@ class TrainplanService extends CrudService {
|
|
|
monthList.push(colRowBJSSL);
|
|
|
|
|
|
const resDate = this.makeCalendar(trainplan.year, index);
|
|
|
- data.push([ '' ]);
|
|
|
- data.push(
|
|
|
- [[ this.getBigMonth(index) + '月' ]]
|
|
|
- .concat(resDate.dlist)
|
|
|
- .concat([ '人数' ].concat([ '班级数' ]))
|
|
|
- );
|
|
|
- data.push([ '' ].concat(resDate.tlist));
|
|
|
+ data.push(['']);
|
|
|
+ data.push([[this.getBigMonth(index) + '月']].concat(resDate.dlist).concat(['人数'].concat(['班级数'])));
|
|
|
+ data.push([''].concat(resDate.tlist));
|
|
|
// 加列数组
|
|
|
for (let i = 0; i < classNum; i++) {
|
|
|
data.push('');
|
|
@@ -1040,10 +1018,8 @@ class TrainplanService extends CrudService {
|
|
|
|
|
|
// 构建 workbook 对象
|
|
|
const nowDate = new Date().getTime();
|
|
|
- const path =
|
|
|
- 'D:\\wwwroot\\service\\service-file\\upload\\train\\' + nowDate + '.xlsx';
|
|
|
- const respath =
|
|
|
- 'http://free.liaoningdoupo.com:80/files/train/' + nowDate + '.xlsx';
|
|
|
+ const path = 'D:\\wwwroot\\service\\service-file\\upload\\train\\' + nowDate + '.xlsx';
|
|
|
+ const respath = 'http://free.liaoningdoupo.com:80/files/train/' + nowDate + '.xlsx';
|
|
|
// 导出
|
|
|
const wb = XLSX.utils.book_new();
|
|
|
XLSX.utils.book_append_sheet(wb, ws, 'Sheet1');
|
|
@@ -1083,32 +1059,13 @@ class TrainplanService extends CrudService {
|
|
|
getfestivalList(festivals) {
|
|
|
let dateList = [];
|
|
|
for (let index = 0; index < festivals.length; index++) {
|
|
|
- dateList = [
|
|
|
- ...dateList,
|
|
|
- ...utils.begindateEnddateSum(
|
|
|
- festivals[index].begindate,
|
|
|
- festivals[index].finishdate
|
|
|
- ),
|
|
|
- ];
|
|
|
+ dateList = [...dateList, ...utils.begindateEnddateSum(festivals[index].begindate, festivals[index].finishdate)];
|
|
|
}
|
|
|
return dateList;
|
|
|
}
|
|
|
// 获取大月份传过来的值是以1月份开始的
|
|
|
getBigMonth(index) {
|
|
|
- const monthBig = [
|
|
|
- '一',
|
|
|
- '二',
|
|
|
- '三',
|
|
|
- '四',
|
|
|
- '五',
|
|
|
- '六',
|
|
|
- '七',
|
|
|
- '八',
|
|
|
- '九',
|
|
|
- '十',
|
|
|
- '十一',
|
|
|
- '十二',
|
|
|
- ];
|
|
|
+ const monthBig = ['一', '二', '三', '四', '五', '六', '七', '八', '九', '十', '十一', '十二'];
|
|
|
return monthBig[index - 1];
|
|
|
}
|
|
|
// 获取这个月份的所有日期1~30号或者31或者28,或者29
|
|
@@ -1149,7 +1106,7 @@ class TrainplanService extends CrudService {
|
|
|
getWeekDay(datestr) {
|
|
|
const weekday = moment(datestr).weekday();
|
|
|
if (weekday || weekday === 0) {
|
|
|
- const arr = [ '日', '一', '二', '三', '四', '五', '六' ];
|
|
|
+ const arr = ['日', '一', '二', '三', '四', '五', '六'];
|
|
|
return '星期' + arr[weekday];
|
|
|
}
|
|
|
return '';
|
|
@@ -1158,10 +1115,7 @@ class TrainplanService extends CrudService {
|
|
|
// assert(trainplanid && classid && rightHeader, '缺少参数项');
|
|
|
|
|
|
async updateclass({ trainplanid, termid, batchid, classid, rightHeader }) {
|
|
|
- assert(
|
|
|
- trainplanid && termid && batchid && classid && rightHeader,
|
|
|
- '缺少参数项'
|
|
|
- );
|
|
|
+ assert(trainplanid && termid && batchid && classid && rightHeader, '缺少参数项');
|
|
|
// 根据全年计划表id查出对应的全年计划详细信息
|
|
|
const trainplan = await this.model.findById(trainplanid);
|
|
|
if (!trainplan) {
|
|
@@ -1209,4 +1163,3 @@ class TrainplanService extends CrudService {
|
|
|
}
|
|
|
}
|
|
|
module.exports = TrainplanService;
|
|
|
-
|