diff --git a/api/app/lib/schedule/attendance.js b/api/app/lib/schedule/attendance.js index 3642fb5..7b07e07 100644 --- a/api/app/lib/schedule/attendance.js +++ b/api/app/lib/schedule/attendance.js @@ -264,7 +264,7 @@ module.exports = function (app, opts) { let lunchBreakDuration = 3600 * 1 while (curTime.isBefore(endTime_) && durationDayAddDay < durationSec) { let curDayStr = curTime.format('YYYY-MM-DD') - const holidayRes = await judgeHoliday(curDayStr) + const holidayRes = await judgeHoliday(curDayStr, true) if (holidayRes && holidayRes.workday) { // 只有上班的日子才计算 @@ -451,7 +451,7 @@ module.exports = function (app, opts) { day: curDayStr, duration: duration_ }) - const holidayRes = await judgeHoliday(curDayStr) + const holidayRes = await judgeHoliday(curDayStr, true) if (holidayRes) { if (compensate.value && compensate.value.indexOf('调休') >= 0) { if (holidayRes.workday) { diff --git a/api/app/lib/utils/days.js b/api/app/lib/utils/days.js index be9bdcd..47d709c 100644 --- a/api/app/lib/utils/days.js +++ b/api/app/lib/utils/days.js @@ -4,7 +4,7 @@ const request = require('superagent'); module.exports = function (app, opts) { - async function judgeHoliday (dayStr) { + async function judgeHoliday (dayStr, coolDown) { const { timorApiUrl } = opts const { models } = app.fs.dc let dayStr_ = dayStr || moment().format('YYYY-MM-DD') @@ -14,13 +14,18 @@ module.exports = function (app, opts) { day: dayStr_ } }) + let needCreate = false if (dbRes) { holidayData = dbRes.dataValues.holiday } else { + needCreate = true console.log("提莫 HOLIDAY 请求" + dayStr_); let holidayRes = await request.get( timorApiUrl + `holiday/info/${dayStr_}` ) + // 冷却一下 + if (coolDown) + await new Promise(resolve => setTimeout(() => resolve(), 3000)); holidayData = holidayRes.body || {} } @@ -31,6 +36,7 @@ module.exports = function (app, opts) { festivals: false, params: holidayData.type } + dayType = null let holidayType = holidayData.type.type if ( holidayType == 2 @@ -40,6 +46,7 @@ module.exports = function (app, opts) { // 正经节假日 3倍工资那种 // festivals returnD.festivals = true + dayType = 'festivals' } else if ( holidayType == 1 || ( @@ -50,9 +57,18 @@ module.exports = function (app, opts) { ) { // 普假 休息日非节假日 returnD.dayoff = true + dayType = 'dayoff' } else if (holidayType == 0 || holidayType == 3) { // 工作日或补班 returnD.workday = true + dayType = 'workday' + } + if (needCreate && dayType) { + await models.Holiday.create({ + day: dayStr_, + holiday: holidayData, + type: dayType + }) } return returnD } else {