|
@@ -8,6 +8,7 @@ const { BusinessError, ErrorCode } = require('naf-core').Error;
|
|
|
const XLSX = require('xlsx');
|
|
|
const utils = require('../utils/utils.js');
|
|
|
const moment = require('moment');
|
|
|
+const XLSXStyle = require('xlsx-style');
|
|
|
class TrainplanService extends CrudService {
|
|
|
constructor(ctx) {
|
|
|
super(ctx, 'trainplan');
|
|
@@ -565,25 +566,59 @@ class TrainplanService extends CrudService {
|
|
|
const monthList = [];
|
|
|
// 月份合并单元格
|
|
|
const colzb = 0;
|
|
|
- const rowzb = 1;
|
|
|
+ let rowzb = 1;
|
|
|
// 头部合并单元格
|
|
|
const coltb = 0;
|
|
|
- const rowtb = 0;
|
|
|
+ let rowtb = 0;
|
|
|
// 人数合并单元格
|
|
|
const colrs = 0;
|
|
|
- const rowrs = 1;
|
|
|
+ let rowrs = 1;
|
|
|
// 人数数量合并单元格
|
|
|
const colrssl = 0;
|
|
|
- const rowrssl = 3;
|
|
|
+ let rowrssl = 3;
|
|
|
|
|
|
// 班级数合并单元格
|
|
|
const colbjs = 0;
|
|
|
- const rowbjs = 1;
|
|
|
+ let rowbjs = 1;
|
|
|
// 班级数数量合并单元格
|
|
|
const colbjssl = 0;
|
|
|
- const rowbjssl = 3;
|
|
|
+ let rowbjssl = 3;
|
|
|
// 数据
|
|
|
const data = [];
|
|
|
+ let colRowBJSSL = {};
|
|
|
+ // 这里是头部颜色
|
|
|
+ const tatleCell = { v: '', s: { fill: { fgColor: { rgb: '191970' } } } };
|
|
|
+ // 坐标
|
|
|
+ const tatleCellstyle = 0;
|
|
|
+ let tatleRowstyle = 0;
|
|
|
+ const styleTatle = [];
|
|
|
+ // 这里是月份颜色
|
|
|
+ const monthCell = [
|
|
|
+ { v: '一月', s: { fill: { fgColor: { rgb: 'B0E2FF' } } } },
|
|
|
+ { v: '二月', s: { fill: { fgColor: { rgb: 'B0E2FF' } } } },
|
|
|
+ { v: '三月', s: { fill: { fgColor: { rgb: 'B0E2FF' } } } },
|
|
|
+ { v: '四月', s: { fill: { fgColor: { rgb: 'B0E2FF' } } } },
|
|
|
+ { v: '五月', s: { fill: { fgColor: { rgb: 'B0E2FF' } } } },
|
|
|
+ { v: '六月', s: { fill: { fgColor: { rgb: 'B0E2FF' } } } },
|
|
|
+ { v: '七月', s: { fill: { fgColor: { rgb: 'B0E2FF' } } } },
|
|
|
+ { v: '八月', s: { fill: { fgColor: { rgb: 'B0E2FF' } } } },
|
|
|
+ { v: '九月', s: { fill: { fgColor: { rgb: 'B0E2FF' } } } },
|
|
|
+ { v: '十月', s: { fill: { fgColor: { rgb: 'B0E2FF' } } } },
|
|
|
+ { v: '十一月', s: { fill: { fgColor: { rgb: 'B0E2FF' } } } },
|
|
|
+ { v: '十二月', s: { fill: { fgColor: { rgb: 'B0E2FF' } } } },
|
|
|
+ ];
|
|
|
+ // 坐标
|
|
|
+ const monthCellstyle = 0;
|
|
|
+ let monthRowstyle = 1;
|
|
|
+ const styleMonth = [];
|
|
|
+
|
|
|
+ // 这里是假期颜色
|
|
|
+ const festivalsCell = { v: '', s: { fill: { fgColor: { rgb: 'A2CD5A' } } } };
|
|
|
+ // 坐标
|
|
|
+ const festivalsCellstyle = 0;
|
|
|
+ let festivalsRowstyle = 0;
|
|
|
+ const stylefestivals = [];
|
|
|
+
|
|
|
// 计划表
|
|
|
const trainplan = await this.model.findOne({ _id: trainplanId });
|
|
|
const termnum = trainplan.termnum;
|
|
@@ -597,102 +632,147 @@ class TrainplanService extends CrudService {
|
|
|
// 得到所有的节日日期的数组,然后循环时注意得到一个删除一个
|
|
|
const festivals = trainplan.festivals;
|
|
|
const festivalList = this.getfestivalList(festivals);
|
|
|
+ console.log(utils.begindateEnddateSum('2020-01-25', '2020-02-05'));
|
|
|
const termnumList = this.gettermnumList(termnum);
|
|
|
- console.log(termnumList);
|
|
|
+ // console.log(termnumList);
|
|
|
// 得到所有班级的数组,然后循环时注意得到一个删除一个
|
|
|
|
|
|
// 循环12个月,得到12个月以及每个月的数据
|
|
|
- // for (let index = 1; index < 13; index++) {
|
|
|
- // // 添加月份坐标
|
|
|
- // const colRow = {
|
|
|
- // s: { c: colzb, r: rowzb },
|
|
|
- // // 保证留下7个空行,如果需要在上面加值,直接在下面加入即可第几空行加入就行
|
|
|
- // e: { c: colzb, r: rowzb + classNum + 1 },
|
|
|
- // };
|
|
|
- // // rowzb为上一次终止,那么起始需+1,这里加3,代表头部+月份+星期,所以+3
|
|
|
- // rowzb = rowzb + classNum + 3;
|
|
|
- // monthList.push(colRow);
|
|
|
-
|
|
|
- // // 添加头部坐标
|
|
|
- // const colRowTB = {
|
|
|
- // s: { c: coltb, r: rowtb },
|
|
|
- // // 保证留下7个空行,如果需要在上面加值,直接在下面加入即可第几空行加入就行
|
|
|
- // e: { c: coltb + 33, r: rowtb },
|
|
|
- // };
|
|
|
- // // rowzb为上一次终止,那么起始需+1,
|
|
|
- // rowtb = rowtb + classNum + 3;
|
|
|
- // monthList.push(colRowTB);
|
|
|
-
|
|
|
- // // 添加人数坐标
|
|
|
- // const colRowRS = {
|
|
|
- // s: { c: colrs + 32, r: rowrs },
|
|
|
- // // 保证留下7个空行,如果需要在上面加值,直接在下面加入即可第几空行加入就行
|
|
|
- // e: { c: colrs + 32, r: rowrs + 1 },
|
|
|
- // };
|
|
|
- // // rowzb为上一次终止,那么起始需+1,
|
|
|
- // rowrs = rowrs + classNum + 3;
|
|
|
- // monthList.push(colRowRS);
|
|
|
-
|
|
|
- // // 添加人数数量坐标
|
|
|
- // const colRowRSSL = {
|
|
|
- // s: { c: colrssl + 32, r: rowrssl },
|
|
|
- // // 保证留下7个空行,如果需要在上面加值,直接在下面加入即可第几空行加入就行
|
|
|
- // e: { c: colrssl + 32, r: rowrssl + classNum - 1 },
|
|
|
- // };
|
|
|
- // // rowzb为上一次终止,那么起始需+1,
|
|
|
- // rowrssl = rowrssl + classNum + 3;
|
|
|
- // monthList.push(colRowRSSL);
|
|
|
-
|
|
|
- // // 添加班级数坐标
|
|
|
- // const colRowBJS = {
|
|
|
- // s: { c: colbjs + 33, r: rowbjs },
|
|
|
- // // 保证留下7个空行,如果需要在上面加值,直接在下面加入即可第几空行加入就行
|
|
|
- // e: { c: colbjs + 33, r: rowbjs + 1 },
|
|
|
- // };
|
|
|
- // // rowzb为上一次终止,那么起始需+1,
|
|
|
- // rowbjs = rowbjs + classNum + 3;
|
|
|
- // monthList.push(colRowBJS);
|
|
|
-
|
|
|
- // // 添加班级数数量坐标
|
|
|
- // const colRowBJSSL = {
|
|
|
- // s: { c: colbjssl + 33, r: rowbjssl },
|
|
|
- // // 保证留下7个空行,如果需要在上面加值,直接在下面加入即可第几空行加入就行
|
|
|
- // e: { c: colbjssl + 33, r: rowbjssl + classNum - 1 },
|
|
|
- // };
|
|
|
- // // rowzb为上一次终止,那么起始需+1,
|
|
|
- // rowbjssl = rowbjssl + classNum + 3;
|
|
|
- // 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));
|
|
|
-
|
|
|
- // // 加列数组
|
|
|
- // for (let i = 0; i < classNum; i++) {
|
|
|
- // data.push('');
|
|
|
- // }
|
|
|
- // }
|
|
|
- // // console.log(data);
|
|
|
-
|
|
|
- // // ...以此类推即可
|
|
|
- // /** 头部-行列信息*/
|
|
|
- // const ws = XLSX.utils.aoa_to_sheet(data);
|
|
|
-
|
|
|
- // // 构建 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 wb = XLSX.utils.book_new();
|
|
|
- // XLSX.utils.book_append_sheet(wb, ws, 'Sheet1');
|
|
|
- // ws['!cols'] = wscols;
|
|
|
- // ws['!merges'] = monthList;
|
|
|
- // // console.log(xuhao);
|
|
|
- // XLSX.writeFile(wb, path);
|
|
|
- // return respath;
|
|
|
+ for (let index = 1; index < 13; index++) {
|
|
|
+ // 这里增加表格头部下标
|
|
|
+ const tatleCells = XLSX.utils.encode_cell({
|
|
|
+ c: tatleCellstyle,
|
|
|
+ r: tatleRowstyle,
|
|
|
+ });
|
|
|
+ tatleRowstyle = tatleRowstyle + classNum + 3;
|
|
|
+ styleTatle.push(tatleCells);
|
|
|
+ // 这里是月份颜色
|
|
|
+ const monthCells = XLSX.utils.encode_cell({
|
|
|
+ c: monthCellstyle,
|
|
|
+ r: monthRowstyle,
|
|
|
+ });
|
|
|
+ monthRowstyle = monthRowstyle + classNum + 3;
|
|
|
+ styleMonth.push(monthCells);
|
|
|
+ for (let j = 0; j < festivalList.length; j++) {
|
|
|
+ const festival = festivalList[j];
|
|
|
+ // console.log(festival);
|
|
|
+ // 如果月份相同时才会增加
|
|
|
+ const yue = parseInt(festival.substr(5, 2));
|
|
|
+ const lie = parseInt(festival.substr(8, 2));
|
|
|
+ if (index === yue) {
|
|
|
+ // 这里是假期颜色这一列列7行都是这个颜色
|
|
|
+ for (let k = 0; k < classNum; k++) {
|
|
|
+ const festivalsCells = XLSX.utils.encode_cell({
|
|
|
+ // 列
|
|
|
+ c: festivalsCellstyle + lie,
|
|
|
+ r: festivalsRowstyle + k + 3,
|
|
|
+ });
|
|
|
+ stylefestivals.push(festivalsCells);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ festivalsRowstyle = festivalsRowstyle + classNum + 3;
|
|
|
+ // console.log(stylefestivals);
|
|
|
+
|
|
|
+ // 添加月份坐标
|
|
|
+ const colRow = {
|
|
|
+ s: { c: colzb, r: rowzb },
|
|
|
+ // 保证留下7个空行,如果需要在上面加值,直接在下面加入即可第几空行加入就行
|
|
|
+ e: { c: colzb, r: rowzb + classNum + 1 },
|
|
|
+ };
|
|
|
+ // rowzb为上一次终止,那么起始需+1,这里加3,代表头部+月份+星期,所以+3
|
|
|
+ rowzb = rowzb + classNum + 3;
|
|
|
+ monthList.push(colRow);
|
|
|
+
|
|
|
+ // 添加头部坐标
|
|
|
+ const colRowTB = {
|
|
|
+ s: { c: coltb, r: rowtb },
|
|
|
+ // 保证留下7个空行,如果需要在上面加值,直接在下面加入即可第几空行加入就行
|
|
|
+ e: { c: coltb + 33, r: rowtb },
|
|
|
+ };
|
|
|
+ // rowzb为上一次终止,那么起始需+1,
|
|
|
+ rowtb = rowtb + classNum + 3;
|
|
|
+ monthList.push(colRowTB);
|
|
|
+
|
|
|
+ // 添加人数坐标
|
|
|
+ const colRowRS = {
|
|
|
+ s: { c: colrs + 32, r: rowrs },
|
|
|
+ // 保证留下7个空行,如果需要在上面加值,直接在下面加入即可第几空行加入就行
|
|
|
+ e: { c: colrs + 32, r: rowrs + 1 },
|
|
|
+ };
|
|
|
+ // rowzb为上一次终止,那么起始需+1,
|
|
|
+ rowrs = rowrs + classNum + 3;
|
|
|
+ monthList.push(colRowRS);
|
|
|
+
|
|
|
+ // 添加人数数量坐标
|
|
|
+ const colRowRSSL = {
|
|
|
+ s: { c: colrssl + 32, r: rowrssl },
|
|
|
+ // 保证留下7个空行,如果需要在上面加值,直接在下面加入即可第几空行加入就行
|
|
|
+ e: { c: colrssl + 32, r: rowrssl + classNum - 1 },
|
|
|
+ };
|
|
|
+ // rowzb为上一次终止,那么起始需+1,
|
|
|
+ rowrssl = rowrssl + classNum + 3;
|
|
|
+ monthList.push(colRowRSSL);
|
|
|
+
|
|
|
+ // 添加班级数坐标
|
|
|
+ const colRowBJS = {
|
|
|
+ s: { c: colbjs + 33, r: rowbjs },
|
|
|
+ // 保证留下7个空行,如果需要在上面加值,直接在下面加入即可第几空行加入就行
|
|
|
+ e: { c: colbjs + 33, r: rowbjs + 1 },
|
|
|
+ };
|
|
|
+ // rowzb为上一次终止,那么起始需+1,
|
|
|
+ rowbjs = rowbjs + classNum + 3;
|
|
|
+ monthList.push(colRowBJS);
|
|
|
+
|
|
|
+ // 添加班级数数量坐标
|
|
|
+ colRowBJSSL = {
|
|
|
+ s: { c: colbjssl + 33, r: rowbjssl },
|
|
|
+ // 保证留下7个空行,如果需要在上面加值,直接在下面加入即可第几空行加入就行
|
|
|
+ e: { c: colbjssl + 33, r: rowbjssl + classNum - 1 },
|
|
|
+ };
|
|
|
+ // rowzb为上一次终止,那么起始需+1,
|
|
|
+ rowbjssl = rowbjssl + classNum + 3;
|
|
|
+ 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));
|
|
|
+ // 加列数组
|
|
|
+ for (let i = 0; i < classNum; i++) {
|
|
|
+ data.push('');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // ...以此类推即可
|
|
|
+ /** 头部-行列信息*/
|
|
|
+ const ws = XLSX.utils.aoa_to_sheet(data);
|
|
|
+
|
|
|
+ // 构建 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 wb = XLSX.utils.book_new();
|
|
|
+ XLSX.utils.book_append_sheet(wb, ws, 'Sheet1');
|
|
|
+ ws['!cols'] = wscols;
|
|
|
+ ws['!merges'] = monthList;
|
|
|
+ // 头部赋值颜色需要计算出坐标
|
|
|
+ for (const tatlezb of styleTatle) {
|
|
|
+ ws[tatlezb] = tatleCell;
|
|
|
+ }
|
|
|
+ // 月份赋值颜色需要计算出坐标
|
|
|
+ for (let index = 0; index < styleMonth.length; index++) {
|
|
|
+ ws[styleMonth[index]] = monthCell[index];
|
|
|
+ }
|
|
|
+ // 假期赋值颜色需要计算出坐标
|
|
|
+ for (const festivals of stylefestivals) {
|
|
|
+ ws[festivals] = festivalsCell;
|
|
|
+ }
|
|
|
+ XLSXStyle.writeFile(wb, path);
|
|
|
+ return respath;
|
|
|
}
|
|
|
// 获取批次日期列表
|
|
|
gettermnumList(termnums) {
|