var ReportTemplateCycleEnums = {
HOUR: "1",
WORK: "2",
DAY: "3",
WEEK: "4",
MONTH: "5",
QUARTER: "6",
HALFAYEAR: "7",
YEAR: "8",
OTHER: "9"
};
function currentSPSYS(parameter) {
var res = [];
var cycle = parameter.cycle;
var rowIndex = parameter.rowIndex;
var colIndex = parameter.colIndex;
var year = parameter.year;
var startTime = parameter.startTime;
var endTime = parameter.endTime;
var shiftDOList = parameter.factoryCalendarDTO.shiftDOList;
var lastTenYears = parameter.factoryCalendarDTO.lastTenYears;
var obj = {
"sysName": "",
"sheetIndex": parameter.sheetIndex,
"rowIndex": rowIndex,
"colIndex": colIndex,
};
switch (cycle) {
case ReportTemplateCycleEnums.YEAR:
var item = JSON.parse(JSON.stringify(obj));
item.sysName = year + '年';
res.push(item);
break;
case ReportTemplateCycleEnums.HALFAYEAR:
var item = JSON.parse(JSON.stringify(obj));
var yearNum = parameter.yearNum;
item.sysName = year + '年上半年';
if (yearNum == 2) {
item.sysName = year + '年下半年';
}
res.push(item);
break;
case ReportTemplateCycleEnums.QUARTER:
var item = JSON.parse(JSON.stringify(obj));
var quarter = parameter.quarter;
item.sysName = year + '年第一季度';
if (quarter == 2) {
item.sysName = year + '年第二季度';
} else if (quarter == 3) {
item.sysName = year + '年第三季度';
} else if (quarter == 4) {
item.sysName = year + '年第四季度';
}
res.push(item);
break;
case ReportTemplateCycleEnums.MONTH:
var item = JSON.parse(JSON.stringify(obj));
var month = parameter.month;
item.sysName = year + '年' + month + '月';
res.push(item);
break;
case ReportTemplateCycleEnums.WEEK:
var item = JSON.parse(JSON.stringify(obj));
var week = moment(startTime).add(3, 'days').format("W");
item.sysName = year + '年第' + week + '周';
res.push(item);
break;
case ReportTemplateCycleEnums.DAY:
var item = JSON.parse(JSON.stringify(obj));
var month = parameter.month;
var day = parameter.day;
for (var i = 0; i < lastTenYears.length; i++) {
if (lastTenYears[i].year == year && lastTenYears[i].month == month) {
var dayNum = moment(lastTenYears[i].endTime).diff(moment(lastTenYears[i].startTime), 'days') + 1;
for (var j = 0; j < dayNum; j++) {
if (j + 1 == day) {
item.sysName = moment(lastTenYears[i].startTime).add(j, 'days').format("YYYY-MM-DD")
}
}
}
}
res.push(item);
break;
case ReportTemplateCycleEnums.WORK:
var item = JSON.parse(JSON.stringify(obj));
var month = parameter.month;
var day = parameter.day;
for (var i = 0; i < lastTenYears.length; i++) {
if (lastTenYears[i].year == year && lastTenYears[i].month == month) {
var dayNum = moment(lastTenYears[i].endTime).diff(moment(lastTenYears[i].startTime), 'days') + 1;
for (var j = 0; j < dayNum; j++) {
if (j + 1 == day) {
item.sysName = moment(lastTenYears[i].startTime).add(j, 'days').format("YYYY-MM-DD")
for (var k = 0; k < shiftDOList.length; k++) {
var startTimeSMS = startTime.substring(11, 19);
var endTimeSMS = endTime.substring(11, 19);
if (shiftDOList[k].startTime == startTimeSMS && shiftDOList[k].endTime == endTimeSMS) {
item.sysName = moment(lastTenYears[i].startTime).add(j, 'days').format("YYYY-MM-DD") + ' ' + shiftDOList[k].name;
}
}
}
}
}
}
res.push(item);
break;
default:
};
// 必须转为json格式
return JSON.stringify(res);
}
var para = {
"colIndex": 1,
"cycle": "班",
"day": 2,
"endTime": "2022-08-03 00:00:00",
"entId": "87685456",
"factoryCalendarDTO": {
"calendarDOList": [{
"endTime": "2022-08-31 00:00:00",
"month": 8,
"startTime": "2022-08-01 00:00:00",
"year": 2022
}],
"lastTenYears": [{
"endTime": "2022-01-31 00:00:00",
"month": 1,
"startTime": "2022-01-01 00:00:00",
"year": 2022
}, {
"endTime": "2022-02-28 00:00:00",
"month": 2,
"startTime": "2022-02-01 00:00:00",
"year": 2022
}, {
"endTime": "2022-03-31 00:00:00",
"month": 3,
"startTime": "2022-03-01 00:00:00",
"year": 2022
}, {
"endTime": "2022-04-30 00:00:00",
"month": 4,
"startTime": "2022-04-01 00:00:00",
"year": 2022
}, {
"endTime": "2022-05-31 00:00:00",
"month": 5,
"startTime": "2022-05-01 00:00:00",
"year": 2022
}, {
"endTime": "2022-06-30 00:00:00",
"month": 6,
"startTime": "2022-06-01 00:00:00",
"year": 2022
}, {
"endTime": "2022-07-31 00:00:00",
"month": 7,
"startTime": "2022-07-01 00:00:00",
"year": 2022
}, {
"endTime": "2022-08-31 00:00:00",
"month": 8,
"startTime": "2022-08-01 00:00:00",
"year": 2022
}, {
"endTime": "2022-09-30 00:00:00",
"month": 9,
"startTime": "2022-09-01 00:00:00",
"year": 2022
}, {
"endTime": "2022-10-31 00:00:00",
"month": 10,
"startTime": "2022-10-01 00:00:00",
"year": 2022
}, {
"endTime": "2022-11-30 00:00:00",
"month": 11,
"startTime": "2022-11-01 00:00:00",
"year": 2022
}, {
"endTime": "2022-12-31 00:00:00",
"month": 12,
"startTime": "2022-12-01 00:00:00",
"year": 2022
}, {
"endTime": "2021-01-31 00:00:00",
"month": 1,
"startTime": "2021-01-01 00:00:00",
"year": 2021
}, {
"endTime": "2021-02-28 00:00:00",
"month": 2,
"startTime": "2021-02-01 00:00:00",
"year": 2021
}, {
"endTime": "2021-03-31 00:00:00",
"month": 3,
"startTime": "2021-03-01 00:00:00",
"year": 2021
}, {
"endTime": "2021-04-30 00:00:00",
"month": 4,
"startTime": "2021-04-01 00:00:00",
"year": 2021
}, {
"endTime": "2021-05-31 00:00:00",
"month": 5,
"startTime": "2021-05-01 00:00:00",
"year": 2021
}, {
"endTime": "2021-06-30 00:00:00",
"month": 6,
"startTime": "2021-06-01 00:00:00",
"year": 2021
}, {
"endTime": "2021-07-31 00:00:00",
"month": 7,
"startTime": "2021-07-01 00:00:00",
"year": 2021
}, {
"endTime": "2021-08-31 00:00:00",
"month": 8,
"startTime": "2021-08-01 00:00:00",
"year": 2021
}, {
"endTime": "2021-09-30 00:00:00",
"month": 9,
"startTime": "2021-09-01 00:00:00",
"year": 2021
}, {
"endTime": "2021-10-31 00:00:00",
"month": 10,
"startTime": "2021-10-01 00:00:00",
"year": 2021
}, {
"endTime": "2021-11-30 00:00:00",
"month": 11,
"startTime": "2021-11-01 00:00:00",
"year": 2021
}, {
"endTime": "2021-12-31 00:00:00",
"month": 12,
"startTime": "2021-12-01 00:00:00",
"year": 2021
}, {
"endTime": "2020-01-31 00:00:00",
"month": 1,
"startTime": "2020-01-01 00:00:00",
"year": 2020
}, {
"endTime": "2020-02-29 00:00:00",
"month": 2,
"startTime": "2020-02-01 00:00:00",
"year": 2020
}, {
"endTime": "2020-03-31 00:00:00",
"month": 3,
"startTime": "2020-03-01 00:00:00",
"year": 2020
}, {
"endTime": "2020-04-30 00:00:00",
"month": 4,
"startTime": "2020-04-01 00:00:00",
"year": 2020
}, {
"endTime": "2020-05-31 00:00:00",
"month": 5,
"startTime": "2020-05-01 00:00:00",
"year": 2020
}, {
"endTime": "2020-06-30 00:00:00",
"month": 6,
"startTime": "2020-06-01 00:00:00",
"year": 2020
}, {
"endTime": "2020-07-31 00:00:00",
"month": 7,
"startTime": "2020-07-01 00:00:00",
"year": 2020
}, {
"endTime": "2020-08-31 00:00:00",
"month": 8,
"startTime": "2020-08-01 00:00:00",
"year": 2020
}, {
"endTime": "2020-09-30 00:00:00",
"month": 9,
"startTime": "2020-09-01 00:00:00",
"year": 2020
}, {
"endTime": "2020-10-31 00:00:00",
"month": 10,
"startTime": "2020-10-01 00:00:00",
"year": 2020
}, {
"endTime": "2020-11-30 00:00:00",
"month": 11,
"startTime": "2020-11-01 00:00:00",
"year": 2020
}, {
"endTime": "2020-12-31 00:00:00",
"month": 12,
"startTime": "2020-12-01 00:00:00",
"year": 2020
}, {
"endTime": "2019-01-31 00:00:00",
"month": 1,
"startTime": "2019-01-01 00:00:00",
"year": 2019
}, {
"endTime": "2019-02-28 00:00:00",
"month": 2,
"startTime": "2019-02-01 00:00:00",
"year": 2019
}, {
"endTime": "2019-03-31 00:00:00",
"month": 3,
"startTime": "2019-03-01 00:00:00",
"year": 2019
}, {
"endTime": "2019-04-30 00:00:00",
"month": 4,
"startTime": "2019-04-01 00:00:00",
"year": 2019
}, {
"endTime": "2019-05-31 00:00:00",
"month": 5,
"startTime": "2019-05-01 00:00:00",
"year": 2019
}, {
"endTime": "2019-06-30 00:00:00",
"month": 6,
"startTime": "2019-06-01 00:00:00",
"year": 2019
}, {
"endTime": "2019-07-31 00:00:00",
"month": 7,
"startTime": "2019-07-01 00:00:00",
"year": 2019
}, {
"endTime": "2019-08-31 00:00:00",
"month": 8,
"startTime": "2019-08-01 00:00:00",
"year": 2019
}, {
"endTime": "2019-09-30 00:00:00",
"month": 9,
"startTime": "2019-09-01 00:00:00",
"year": 2019
}, {
"endTime": "2019-10-31 00:00:00",
"month": 10,
"startTime": "2019-10-01 00:00:00",
"year": 2019
}, {
"endTime": "2019-11-30 00:00:00",
"month": 11,
"startTime": "2019-11-01 00:00:00",
"year": 2019
}, {
"endTime": "2019-12-31 00:00:00",
"month": 12,
"startTime": "2019-12-01 00:00:00",
"year": 2019
}, {
"endTime": "2018-01-31 00:00:00",
"month": 1,
"startTime": "2018-01-01 00:00:00",
"year": 2018
}, {
"endTime": "2018-02-28 00:00:00",
"month": 2,
"startTime": "2018-02-01 00:00:00",
"year": 2018
}, {
"endTime": "2018-03-31 00:00:00",
"month": 3,
"startTime": "2018-03-01 00:00:00",
"year": 2018
}, {
"endTime": "2018-04-30 00:00:00",
"month": 4,
"startTime": "2018-04-01 00:00:00",
"year": 2018
}, {
"endTime": "2018-05-31 00:00:00",
"month": 5,
"startTime": "2018-05-01 00:00:00",
"year": 2018
}, {
"endTime": "2018-06-30 00:00:00",
"month": 6,
"startTime": "2018-06-01 00:00:00",
"year": 2018
}, {
"endTime": "2018-07-31 00:00:00",
"month": 7,
"startTime": "2018-07-01 00:00:00",
"year": 2018
}, {
"endTime": "2018-08-31 00:00:00",
"month": 8,
"startTime": "2018-08-01 00:00:00",
"year": 2018
}, {
"endTime": "2018-09-30 00:00:00",
"month": 9,
"startTime": "2018-09-01 00:00:00",
"year": 2018
}, {
"endTime": "2018-10-31 00:00:00",
"month": 10,
"startTime": "2018-10-01 00:00:00",
"year": 2018
}, {
"endTime": "2018-11-30 00:00:00",
"month": 11,
"startTime": "2018-11-01 00:00:00",
"year": 2018
}, {
"endTime": "2018-12-31 00:00:00",
"month": 12,
"startTime": "2018-12-01 00:00:00",
"year": 2018
}, {
"endTime": "2017-01-31 00:00:00",
"month": 1,
"startTime": "2017-01-01 00:00:00",
"year": 2017
}, {
"endTime": "2017-02-28 00:00:00",
"month": 2,
"startTime": "2017-02-01 00:00:00",
"year": 2017
}, {
"endTime": "2017-03-31 00:00:00",
"month": 3,
"startTime": "2017-03-01 00:00:00",
"year": 2017
}, {
"endTime": "2017-04-30 00:00:00",
"month": 4,
"startTime": "2017-04-01 00:00:00",
"year": 2017
}, {
"endTime": "2017-05-31 00:00:00",
"month": 5,
"startTime": "2017-05-01 00:00:00",
"year": 2017
}, {
"endTime": "2017-06-30 00:00:00",
"month": 6,
"startTime": "2017-06-01 00:00:00",
"year": 2017
}, {
"endTime": "2017-07-31 00:00:00",
"month": 7,
"startTime": "2017-07-01 00:00:00",
"year": 2017
}, {
"endTime": "2017-08-31 00:00:00",
"month": 8,
"startTime": "2017-08-01 00:00:00",
"year": 2017
}, {
"endTime": "2017-09-30 00:00:00",
"month": 9,
"startTime": "2017-09-01 00:00:00",
"year": 2017
}, {
"endTime": "2017-10-31 00:00:00",
"month": 10,
"startTime": "2017-10-01 00:00:00",
"year": 2017
}, {
"endTime": "2017-11-30 00:00:00",
"month": 11,
"startTime": "2017-11-01 00:00:00",
"year": 2017
}, {
"endTime": "2017-12-31 00:00:00",
"month": 12,
"startTime": "2017-12-01 00:00:00",
"year": 2017
}, {
"endTime": "2016-01-31 00:00:00",
"month": 1,
"startTime": "2016-01-01 00:00:00",
"year": 2016
}, {
"endTime": "2016-02-29 00:00:00",
"month": 2,
"startTime": "2016-02-01 00:00:00",
"year": 2016
}, {
"endTime": "2016-03-31 00:00:00",
"month": 3,
"startTime": "2016-03-01 00:00:00",
"year": 2016
}, {
"endTime": "2016-04-30 00:00:00",
"month": 4,
"startTime": "2016-04-01 00:00:00",
"year": 2016
}, {
"endTime": "2016-05-31 00:00:00",
"month": 5,
"startTime": "2016-05-01 00:00:00",
"year": 2016
}, {
"endTime": "2016-06-30 00:00:00",
"month": 6,
"startTime": "2016-06-01 00:00:00",
"year": 2016
}, {
"endTime": "2016-07-31 00:00:00",
"month": 7,
"startTime": "2016-07-01 00:00:00",
"year": 2016
}, {
"endTime": "2016-08-31 00:00:00",
"month": 8,
"startTime": "2016-08-01 00:00:00",
"year": 2016
}, {
"endTime": "2016-09-30 00:00:00",
"month": 9,
"startTime": "2016-09-01 00:00:00",
"year": 2016
}, {
"endTime": "2016-10-31 00:00:00",
"month": 10,
"startTime": "2016-10-01 00:00:00",
"year": 2016
}, {
"endTime": "2016-11-30 00:00:00",
"month": 11,
"startTime": "2016-11-01 00:00:00",
"year": 2016
}, {
"endTime": "2016-12-31 00:00:00",
"month": 12,
"startTime": "2016-12-01 00:00:00",
"year": 2016
}, {
"endTime": "2015-01-31 00:00:00",
"month": 1,
"startTime": "2015-01-01 00:00:00",
"year": 2015
}, {
"endTime": "2015-02-28 00:00:00",
"month": 2,
"startTime": "2015-02-01 00:00:00",
"year": 2015
}, {
"endTime": "2015-03-31 00:00:00",
"month": 3,
"startTime": "2015-03-01 00:00:00",
"year": 2015
}, {
"endTime": "2015-04-30 00:00:00",
"month": 4,
"startTime": "2015-04-01 00:00:00",
"year": 2015
}, {
"endTime": "2015-05-31 00:00:00",
"month": 5,
"startTime": "2015-05-01 00:00:00",
"year": 2015
}, {
"endTime": "2015-06-30 00:00:00",
"month": 6,
"startTime": "2015-06-01 00:00:00",
"year": 2015
}, {
"endTime": "2015-07-31 00:00:00",
"month": 7,
"startTime": "2015-07-01 00:00:00",
"year": 2015
}, {
"endTime": "2015-08-31 00:00:00",
"month": 8,
"startTime": "2015-08-01 00:00:00",
"year": 2015
}, {
"endTime": "2015-09-30 00:00:00",
"month": 9,
"startTime": "2015-09-01 00:00:00",
"year": 2015
}, {
"endTime": "2015-10-31 00:00:00",
"month": 10,
"startTime": "2015-10-01 00:00:00",
"year": 2015
}, {
"endTime": "2015-11-30 00:00:00",
"month": 11,
"startTime": "2015-11-01 00:00:00",
"year": 2015
}, {
"endTime": "2015-12-31 00:00:00",
"month": 12,
"startTime": "2015-12-01 00:00:00",
"year": 2015
}, {
"endTime": "2014-01-31 00:00:00",
"month": 1,
"startTime": "2014-01-01 00:00:00",
"year": 2014
}, {
"endTime": "2014-02-28 00:00:00",
"month": 2,
"startTime": "2014-02-01 00:00:00",
"year": 2014
}, {
"endTime": "2014-03-31 00:00:00",
"month": 3,
"startTime": "2014-03-01 00:00:00",
"year": 2014
}, {
"endTime": "2014-04-30 00:00:00",
"month": 4,
"startTime": "2014-04-01 00:00:00",
"year": 2014
}, {
"endTime": "2014-05-31 00:00:00",
"month": 5,
"startTime": "2014-05-01 00:00:00",
"year": 2014
}, {
"endTime": "2014-06-30 00:00:00",
"month": 6,
"startTime": "2014-06-01 00:00:00",
"year": 2014
}, {
"endTime": "2014-07-31 00:00:00",
"month": 7,
"startTime": "2014-07-01 00:00:00",
"year": 2014
}, {
"endTime": "2014-08-31 00:00:00",
"month": 8,
"startTime": "2014-08-01 00:00:00",
"year": 2014
}, {
"endTime": "2014-09-30 00:00:00",
"month": 9,
"startTime": "2014-09-01 00:00:00",
"year": 2014
}, {
"endTime": "2014-10-31 00:00:00",
"month": 10,
"startTime": "2014-10-01 00:00:00",
"year": 2014
}, {
"endTime": "2014-11-30 00:00:00",
"month": 11,
"startTime": "2014-11-01 00:00:00",
"year": 2014
}, {
"endTime": "2014-12-31 00:00:00",
"month": 12,
"startTime": "2014-12-01 00:00:00",
"year": 2014
}, {
"endTime": "2013-01-31 00:00:00",
"month": 1,
"startTime": "2013-01-01 00:00:00",
"year": 2013
}, {
"endTime": "2013-02-28 00:00:00",
"month": 2,
"startTime": "2013-02-01 00:00:00",
"year": 2013
}, {
"endTime": "2013-03-31 00:00:00",
"month": 3,
"startTime": "2013-03-01 00:00:00",
"year": 2013
}, {
"endTime": "2013-04-30 00:00:00",
"month": 4,
"startTime": "2013-04-01 00:00:00",
"year": 2013
}, {
"endTime": "2013-05-31 00:00:00",
"month": 5,
"startTime": "2013-05-01 00:00:00",
"year": 2013
}, {
"endTime": "2013-06-30 00:00:00",
"month": 6,
"startTime": "2013-06-01 00:00:00",
"year": 2013
}, {
"endTime": "2013-07-31 00:00:00",
"month": 7,
"startTime": "2013-07-01 00:00:00",
"year": 2013
}, {
"endTime": "2013-08-31 00:00:00",
"month": 8,
"startTime": "2013-08-01 00:00:00",
"year": 2013
}, {
"endTime": "2013-09-30 00:00:00",
"month": 9,
"startTime": "2013-09-01 00:00:00",
"year": 2013
}, {
"endTime": "2013-10-31 00:00:00",
"month": 10,
"startTime": "2013-10-01 00:00:00",
"year": 2013
}, {
"endTime": "2013-11-30 00:00:00",
"month": 11,
"startTime": "2013-11-01 00:00:00",
"year": 2013
}, {
"endTime": "2013-12-31 00:00:00",
"month": 12,
"startTime": "2013-12-01 00:00:00",
"year": 2013
}, {
"endTime": "2012-01-31 00:00:00",
"month": 1,
"startTime": "2012-01-01 00:00:00",
"year": 2012
}, {
"endTime": "2012-02-29 00:00:00",
"month": 2,
"startTime": "2012-02-01 00:00:00",
"year": 2012
}, {
"endTime": "2012-03-31 00:00:00",
"month": 3,
"startTime": "2012-03-01 00:00:00",
"year": 2012
}, {
"endTime": "2012-04-30 00:00:00",
"month": 4,
"startTime": "2012-04-01 00:00:00",
"year": 2012
}, {
"endTime": "2012-05-31 00:00:00",
"month": 5,
"startTime": "2012-05-01 00:00:00",
"year": 2012
}, {
"endTime": "2012-06-30 00:00:00",
"month": 6,
"startTime": "2012-06-01 00:00:00",
"year": 2012
}, {
"endTime": "2012-07-31 00:00:00",
"month": 7,
"startTime": "2012-07-01 00:00:00",
"year": 2012
}, {
"endTime": "2012-08-31 00:00:00",
"month": 8,
"startTime": "2012-08-01 00:00:00",
"year": 2012
}, {
"endTime": "2012-09-30 00:00:00",
"month": 9,
"startTime": "2012-09-01 00:00:00",
"year": 2012
}, {
"endTime": "2012-10-31 00:00:00",
"month": 10,
"startTime": "2012-10-01 00:00:00",
"year": 2012
}, {
"endTime": "2012-11-30 00:00:00",
"month": 11,
"startTime": "2012-11-01 00:00:00",
"year": 2012
}, {
"endTime": "2012-12-31 00:00:00",
"month": 12,
"startTime": "2012-12-01 00:00:00",
"year": 2012
}],
"shiftDOList": [{
"name":"第一班",
"endTDay": 1,
"endTime": "08:00:00",
"startDay": 1,
"startTime": "00:00:00"
}, {
"name":"第二班",
"endTDay": 1,
"endTime": "16:00:00",
"startDay": 1,
"startTime": "08:00:00"
}, {
"name":"第三班",
"endTDay": 2,
"endTime": "00:00:00",
"startDay": 1,
"startTime": "16:00:00"
}]
},
"month": 8,
"quarter": 3,
"rowIndex": 1,
"sheetIndex": 0,
"startTime": "2022-08-02 16:00:00",
"templateVarValType": "采集值",
"unitId": "396731776942485518",
"year": 2022,
"yearNum": 2
};
console.log(currentSPSYS(para));
console