|
@ -6,8 +6,8 @@ module.exports = function (app, opts) { |
|
|
const timorHoliday = app.fs.scheduleInit( |
|
|
const timorHoliday = app.fs.scheduleInit( |
|
|
{ |
|
|
{ |
|
|
interval: '54 42 4 */7 * * *', |
|
|
interval: '54 42 4 */7 * * *', |
|
|
immediate: true, |
|
|
// immediate: true,
|
|
|
// proRun: true,
|
|
|
proRun: true, |
|
|
}, |
|
|
}, |
|
|
async () => { |
|
|
async () => { |
|
|
const { timorApiUrl } = opts |
|
|
const { timorApiUrl } = opts |
|
@ -18,79 +18,78 @@ module.exports = function (app, opts) { |
|
|
let begainDay = existCount ? moment() : moment('2022-01-01') |
|
|
let begainDay = existCount ? moment() : moment('2022-01-01') |
|
|
let endDay = moment().add(3, 'months').endOf('month') |
|
|
let endDay = moment().add(3, 'months').endOf('month') |
|
|
let checkDay = begainDay.clone() |
|
|
let checkDay = begainDay.clone() |
|
|
// while (checkDay.isSameOrBefore(endDay)) {
|
|
|
while (checkDay.isSameOrBefore(endDay)) { |
|
|
// try {
|
|
|
try { |
|
|
// let start = (new Date()).getTime();
|
|
|
const checkDayStr = checkDay.format('YYYY-MM-DD') |
|
|
// const checkDayStr = checkDay.format('YYYY-MM-DD')
|
|
|
let holidayRes = await request.get( |
|
|
// let holidayRes = await request.get(
|
|
|
timorApiUrl + `holiday/info/${checkDayStr}`, |
|
|
// timorApiUrl + `holiday/info/${checkDayStr}`,
|
|
|
) |
|
|
// )
|
|
|
let holidayData = holidayRes.body || {} |
|
|
// let holidayData = holidayRes.body || {}
|
|
|
if (holidayData.code == 0) { |
|
|
// if (holidayData.code == 0) {
|
|
|
|
|
|
|
|
|
|
|
|
// let holidayType = holidayData.type.type
|
|
|
let holidayType = holidayData.type.type |
|
|
// let dayType = ''
|
|
|
let dayType = '' |
|
|
// if (
|
|
|
if ( |
|
|
// holidayType == 2
|
|
|
holidayType == 2 |
|
|
// && holidayData.holiday
|
|
|
&& holidayData.holiday |
|
|
// && holidayData.holiday.wage == 3
|
|
|
&& holidayData.holiday.wage == 3 |
|
|
// ) {
|
|
|
) { |
|
|
// // 正经节假日 3倍工资那种
|
|
|
// 正经节假日 3倍工资那种
|
|
|
// // festivals
|
|
|
// festivals
|
|
|
// dayType = 'festivals'
|
|
|
dayType = 'festivals' |
|
|
// } else if (
|
|
|
} else if ( |
|
|
// holidayType == 1
|
|
|
holidayType == 1 |
|
|
// || (
|
|
|
|| ( |
|
|
// holidayType == 2
|
|
|
holidayType == 2 |
|
|
// && holidayData.holiday
|
|
|
&& holidayData.holiday |
|
|
// && holidayData.holiday.wage < 3
|
|
|
&& holidayData.holiday.wage < 3 |
|
|
// )
|
|
|
) |
|
|
// ) {
|
|
|
) { |
|
|
// // 普假 休息日非节假日
|
|
|
// 普假 休息日非节假日
|
|
|
// dayType = 'dayoff'
|
|
|
dayType = 'dayoff' |
|
|
// } else if (holidayType == 0 || holidayType == 3) {
|
|
|
} else if (holidayType == 0 || holidayType == 3) { |
|
|
// // 工作日或补班
|
|
|
// 工作日或补班
|
|
|
// dayType = 'workday'
|
|
|
dayType = 'workday' |
|
|
// }
|
|
|
} |
|
|
|
|
|
|
|
|
// const dbRes = await models.Holiday.findOne({
|
|
|
const dbRes = await models.Holiday.findOne({ |
|
|
// where: {
|
|
|
where: { |
|
|
// day: checkDayStr
|
|
|
day: checkDayStr |
|
|
// }
|
|
|
} |
|
|
// })
|
|
|
}) |
|
|
// if (dbRes) {
|
|
|
if (dbRes) { |
|
|
// await models.Holiday.update({
|
|
|
await models.Holiday.update({ |
|
|
// holiday: holidayData,
|
|
|
holiday: holidayData, |
|
|
// type: dayType
|
|
|
type: dayType |
|
|
// }, {
|
|
|
}, { |
|
|
// where: {
|
|
|
where: { |
|
|
// day: checkDayStr
|
|
|
day: checkDayStr |
|
|
// }
|
|
|
} |
|
|
// })
|
|
|
}) |
|
|
// } else {
|
|
|
} else { |
|
|
// await models.Holiday.create({
|
|
|
await models.Holiday.create({ |
|
|
// day: checkDayStr,
|
|
|
day: checkDayStr, |
|
|
// holiday: holidayData,
|
|
|
holiday: holidayData, |
|
|
// type: dayType
|
|
|
type: dayType |
|
|
// })
|
|
|
}) |
|
|
// }
|
|
|
} |
|
|
// }
|
|
|
} |
|
|
// checkDay = checkDay.add(1, 'day')
|
|
|
checkDay = checkDay.add(1, 'day') |
|
|
|
|
|
|
|
|
// await new Promise(resolve => setTimeout(() => resolve(), 3000));
|
|
|
await new Promise(resolve => setTimeout(() => resolve(), 3000)); |
|
|
// } catch (error) {
|
|
|
} catch (error) { |
|
|
// console.error(error);
|
|
|
console.error(error); |
|
|
// }
|
|
|
} |
|
|
// }
|
|
|
} |
|
|
|
|
|
|
|
|
let existLastDayRes = await models.Holiday.findOne({ |
|
|
let existLastDayRes = await models.Holiday.findOne({ |
|
|
order: [['day', 'DESC']] |
|
|
order: [['day', 'DESC']] |
|
|
}) |
|
|
}) |
|
|
console.log(moment(existLastDayRes.day).diff(moment(), 'day')); |
|
|
if (!opts.dev && (!existLastDayRes || moment(existLastDayRes.day).diff(moment(), 'day') < 32)) { |
|
|
if (moment(existLastDayRes.day).diff(moment(), 'day') < 32 || 1) { |
|
|
|
|
|
console.log(1); |
|
|
|
|
|
await pushByEmail({ |
|
|
await pushByEmail({ |
|
|
email:[] |
|
|
email: ['gao.zhiyuan@free-sun.com.cn', 'li.yupeng@free-sun.com.cn'], |
|
|
|
|
|
title: '人资系统[TimorHoliday]定时任务告警', |
|
|
|
|
|
text: '已有日期已少于 32 天,当尽快排查最新日志完善日期信息;' |
|
|
}) |
|
|
}) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|