|
|
@ -65,68 +65,121 @@ module.exports = function (app, opts) { |
|
|
|
keys: ['leaveType'], |
|
|
|
require: true, |
|
|
|
}, |
|
|
|
hrAffirmType: { |
|
|
|
keyWord: ['核定请假类别'], |
|
|
|
}, |
|
|
|
duration: { |
|
|
|
keyWord: ['请假时长(小时)', '请假小时'], |
|
|
|
keys: ['leaveTime'] |
|
|
|
}, |
|
|
|
hrAffirmType: { |
|
|
|
keyWord: ['核定请假类别'], |
|
|
|
}, |
|
|
|
hrAffirmDuration: { |
|
|
|
keyWord: ['核定请假小时'], |
|
|
|
}, |
|
|
|
hrAffirmItem: { |
|
|
|
array: { |
|
|
|
hrAffirmType: { keyWord: ['核定请假类别'] }, |
|
|
|
hrAffirmDuration: { keyWord: ['核定请假小时'] } |
|
|
|
} |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
const schemaRecursionObj = ({ |
|
|
|
jsonSchema, keyWord, targetKeys = [], schemaPath, require |
|
|
|
}) => { |
|
|
|
let schemaPath_ = JSON.parse(JSON.stringify(schemaPath)) |
|
|
|
const schemaRecursionObj = ({ jsonSchema, keyWord, targetKeys = [], schemaPath, require, propKey, valueKey }) => { |
|
|
|
let schemaPath_ = JSON.parse(JSON.stringify(schemaPath)); |
|
|
|
if (jsonSchema.properties) { |
|
|
|
for (let prKey in jsonSchema.properties) { |
|
|
|
if ( |
|
|
|
keyWord.includes(jsonSchema.properties[prKey].title) |
|
|
|
|| targetKeys.includes(prKey) |
|
|
|
) { |
|
|
|
schemaPath_.push({ |
|
|
|
prKey, |
|
|
|
...jsonSchema.properties[prKey] |
|
|
|
}) |
|
|
|
return schemaPath_ |
|
|
|
} else if (jsonSchema.properties[prKey].properties) { |
|
|
|
schemaPath_.push({ |
|
|
|
prKey, |
|
|
|
...jsonSchema.properties[prKey] |
|
|
|
}) |
|
|
|
schemaPath_ = schemaRecursionObj({ |
|
|
|
jsonSchema: jsonSchema.properties[prKey], |
|
|
|
keyWord, |
|
|
|
targetKeys, |
|
|
|
schemaPath: schemaPath_, |
|
|
|
require, |
|
|
|
}) |
|
|
|
if (!schemaPath_.length && require) { |
|
|
|
console.warn('数据字段查找错误:', jsonSchema.properties); |
|
|
|
} |
|
|
|
if (schemaPath_.length > schemaPath.length) { |
|
|
|
if (Array.isArray(keyWord)) { //分组vacateNeedData的keyWord传的是数值对象
|
|
|
|
if (keyWord.includes(jsonSchema.properties[prKey].title) || targetKeys.includes(prKey)) { |
|
|
|
if (propKey) {//分组的请假事项和请假时长放在一起,目的多条数据取值不错乱
|
|
|
|
const propKeyIndex = schemaPath_.findIndex(i => i.prKey == propKey); |
|
|
|
if (propKeyIndex > -1) { |
|
|
|
schemaPath_[propKeyIndex].child.push({ |
|
|
|
key: valueKey, |
|
|
|
prKey, |
|
|
|
...jsonSchema.properties[prKey] |
|
|
|
}) |
|
|
|
} |
|
|
|
} else {//非分组场景
|
|
|
|
schemaPath_.push({ |
|
|
|
prKey, |
|
|
|
...jsonSchema.properties[prKey] |
|
|
|
}); |
|
|
|
} |
|
|
|
return schemaPath_; |
|
|
|
} else if (jsonSchema.properties[prKey].properties) { |
|
|
|
schemaPath_.push({ |
|
|
|
prKey, |
|
|
|
...jsonSchema.properties[prKey] |
|
|
|
}); |
|
|
|
schemaPath_ = schemaRecursionObj({ |
|
|
|
jsonSchema: jsonSchema.properties[prKey], |
|
|
|
keyWord, |
|
|
|
targetKeys, |
|
|
|
schemaPath: schemaPath_, |
|
|
|
require, |
|
|
|
}); |
|
|
|
if (!schemaPath_.length && require) { |
|
|
|
console.warn('数据字段查找错误:', jsonSchema.properties); |
|
|
|
} |
|
|
|
if (schemaPath_.length > schemaPath.length) { |
|
|
|
return schemaPath_ |
|
|
|
} |
|
|
|
} else if (jsonSchema.properties[prKey].items && jsonSchema.properties[prKey].items.properties) { |
|
|
|
if (valueKey) { |
|
|
|
const propKeyObj = schemaPath_.findIndex(i => i.prKey == prKey); |
|
|
|
if (-1 == propKeyObj) { |
|
|
|
schemaPath_.push({ |
|
|
|
prKey, |
|
|
|
child: [] |
|
|
|
}) |
|
|
|
} |
|
|
|
schemaPath_ = schemaRecursionObj({ |
|
|
|
jsonSchema: jsonSchema.properties[prKey].items, |
|
|
|
keyWord, |
|
|
|
targetKeys, |
|
|
|
schemaPath: schemaPath_, |
|
|
|
require, |
|
|
|
propKey: prKey, //分组请假类型按照数组嵌套多个属性方式取值
|
|
|
|
valueKey: valueKey |
|
|
|
}) |
|
|
|
} |
|
|
|
if (!schemaPath_.length && require) { |
|
|
|
console.warn('数据字段查找错误:', jsonSchema.properties); |
|
|
|
} |
|
|
|
return schemaPath_ |
|
|
|
} |
|
|
|
} else {//vacateNeedData中核定请假信息hrAffirmItem特殊处理
|
|
|
|
for (let item in keyWord) { |
|
|
|
schemaPath_ = schemaRecursionObj({ |
|
|
|
jsonSchema: jsonSchema, |
|
|
|
keyWord: keyWord[item].keyWord, |
|
|
|
targetKeys, |
|
|
|
schemaPath: schemaPath_, |
|
|
|
require, |
|
|
|
propKey: null, |
|
|
|
valueKey: item //用于多条请假记录key,方便最后数组对象取值
|
|
|
|
}); |
|
|
|
} |
|
|
|
return schemaPath_; |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
return schemaPath_ |
|
|
|
return schemaPath_; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
const dataRecursionObj = (dataObj, index, needData, lastKeyObj, nd) => { |
|
|
|
const keyObj = needData[nd].schemaPath[index] |
|
|
|
const keyObj = needData[nd].schemaPath[index]; |
|
|
|
if (dataObj.hasOwnProperty(keyObj.prKey)) { |
|
|
|
if (lastKeyObj.prKey == keyObj.prKey) { |
|
|
|
if (keyObj.child) {//schemaRecursionObj()处理时对分组用child标记,此处取值特殊处理
|
|
|
|
return dataRecursionChildObj(dataObj[keyObj.prKey], keyObj.child); |
|
|
|
} |
|
|
|
let gotValue = dataObj[keyObj.prKey] |
|
|
|
if (keyObj.enum) { |
|
|
|
let vIndex = keyObj.enum.findIndex(ke => ke == gotValue) |
|
|
|
gotValue = keyObj.enumNames[vIndex] |
|
|
|
let vIndex = keyObj.enum.findIndex(ke => ke == gotValue); |
|
|
|
gotValue = keyObj.enumNames[vIndex]; |
|
|
|
} |
|
|
|
return gotValue |
|
|
|
return gotValue; |
|
|
|
} else { |
|
|
|
return dataRecursionObj( |
|
|
|
dataObj[keyObj.prKey], |
|
|
@ -139,6 +192,22 @@ module.exports = function (app, opts) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
const dataRecursionChildObj = (dataObj, keyObj) => { |
|
|
|
return dataObj.map(data => { |
|
|
|
let retObj = {}; |
|
|
|
for (let item in data) { |
|
|
|
const keyToData = keyObj.find(k => k.prKey == item); |
|
|
|
let value = data[item]; |
|
|
|
if (keyToData.enum) { |
|
|
|
let vIndex = keyToData.enum.findIndex(ke => ke == value); |
|
|
|
value = keyToData.enumNames[vIndex]; |
|
|
|
} |
|
|
|
retObj[keyToData.key] = value; |
|
|
|
} |
|
|
|
return retObj; |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
const getData = (applyDetail, needData) => { |
|
|
|
for (let nd in needData) { |
|
|
|
if (needData[nd].noProcess) { |
|
|
@ -148,35 +217,25 @@ module.exports = function (app, opts) { |
|
|
|
const { jsonSchema } = JSON.parse(applyDetail.formSchema) |
|
|
|
needData[nd].schemaPath = schemaRecursionObj({ |
|
|
|
jsonSchema: jsonSchema || {}, |
|
|
|
keyWord: needData[nd]['keyWord'], |
|
|
|
keyWord: needData[nd]['keyWord'] || needData[nd]['array'], |
|
|
|
targetKeys: needData[nd]['keys'], |
|
|
|
schemaPath: [], |
|
|
|
require: nd.require |
|
|
|
}) |
|
|
|
if ( |
|
|
|
needData[nd].schemaPath |
|
|
|
&& needData[nd].schemaPath.length |
|
|
|
) { |
|
|
|
const lastKeyObj = needData[nd] |
|
|
|
.schemaPath[needData[nd].schemaPath.length - 1] |
|
|
|
if (needData[nd].schemaPath && needData[nd].schemaPath.length) { |
|
|
|
const lastKeyObj = needData[nd].schemaPath[needData[nd].schemaPath.length - 1]; |
|
|
|
if (applyDetail.formData) { |
|
|
|
const formData = JSON.parse(applyDetail.formData) |
|
|
|
needData[nd].value = dataRecursionObj( |
|
|
|
formData, 0, needData, lastKeyObj, nd |
|
|
|
) |
|
|
|
} else { |
|
|
|
console.warn( |
|
|
|
`表单数据缺失:[${nd}]`, |
|
|
|
applyDetail |
|
|
|
); |
|
|
|
console.warn(`表单数据缺失:[${nd}]`, applyDetail); |
|
|
|
} |
|
|
|
} else { |
|
|
|
if (needData[nd].require) { |
|
|
|
// 记录错误 关键数据没找到
|
|
|
|
console.warn( |
|
|
|
`数据字段查找错误:${nd.needData[nd]['keyWord'].join('、')}`, |
|
|
|
jsonSchema |
|
|
|
); |
|
|
|
console.warn(`数据字段查找错误:${nd.needData[nd]['keyWord'].join('、')}`, jsonSchema); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -218,10 +277,11 @@ module.exports = function (app, opts) { |
|
|
|
` +
|
|
|
|
` |
|
|
|
${existOvertimeCount || existVacateCount ? |
|
|
|
`WHERE story.create_at > '${moment().subtract(1, 'month').format('YYYY-MM-DD HH:mm:ss')}'` |
|
|
|
`WHERE story.create_at > '2023-03-16 00:00:00'` |
|
|
|
: ''} |
|
|
|
` |
|
|
|
).toPromise() |
|
|
|
// `WHERE story.create_at > '${moment().subtract(1, 'month').format('YYYY-MM-DD HH:mm:ss')}'`
|
|
|
|
|
|
|
|
let insertCount = 0, updateCount = 0, invalidCount = 0, unCompletedCount = 0, unknowCount = 0 |
|
|
|
for (let a of attendanceRes) { |
|
|
@ -229,29 +289,75 @@ module.exports = function (app, opts) { |
|
|
|
if (a.processName) { |
|
|
|
if ('COMPLETED' == a.state) { |
|
|
|
if (a.processName.indexOf('请假') > -1) { |
|
|
|
let needData = JSON.parse(JSON.stringify(vacateNeedData)) |
|
|
|
getData(a, needData) |
|
|
|
const { begainTime, endTime, type, hrAffirmType, duration, hrAffirmDuration, reason } = needData |
|
|
|
if ( |
|
|
|
begainTime.value && endTime.value && type.value |
|
|
|
&& (duration.value || hrAffirmDuration.value) |
|
|
|
) { |
|
|
|
let durationSec = 0 |
|
|
|
let needData = JSON.parse(JSON.stringify(vacateNeedData)); |
|
|
|
getData(a, needData); |
|
|
|
|
|
|
|
const vacateDurationSecDeal = (hrAffirmDuration, duration) => { |
|
|
|
let durationSec = 0; |
|
|
|
if (hrAffirmDuration.value) { |
|
|
|
durationSec = parseFloat(hrAffirmDuration.value) * 3600 |
|
|
|
} else if (duration.value) { |
|
|
|
durationSec = parseFloat(duration.value) * 3600 |
|
|
|
} |
|
|
|
return durationSec; |
|
|
|
}; |
|
|
|
|
|
|
|
if ( |
|
|
|
typeof durationSec != 'number' |
|
|
|
|| isNaN(durationSec) |
|
|
|
|| durationSec <= 0 |
|
|
|
) { |
|
|
|
console.warn('请假时长计算结果错误', hrAffirmDuration, duration); |
|
|
|
invalidCount++ |
|
|
|
const { begainTime, endTime, type, hrAffirmItem, duration, hrAffirmDuration, reason } = needData; |
|
|
|
|
|
|
|
if (begainTime.value && endTime.value && type.value && hrAffirmItem.value) {//核定请假分组,后面历史表单全部走完后,可把hrAffirmType、hrAffirmDuration取值的去掉
|
|
|
|
const existRes = await models.Vacate.findOne({ where: { pepProcessStoryId: a.historyId } }); |
|
|
|
if (existRes) { |
|
|
|
updateCount++; |
|
|
|
} else { |
|
|
|
const storageD = []; |
|
|
|
const packageDay = []; |
|
|
|
for (let index in hrAffirmItem.value) { |
|
|
|
const { hrAffirmDuration, hrAffirmType } = hrAffirmItem.value[index]; |
|
|
|
const durationSec = vacateDurationSecDeal({ value: hrAffirmDuration }, duration); |
|
|
|
|
|
|
|
if (typeof durationSec != 'number' || isNaN(durationSec) || durationSec <= 0) { |
|
|
|
console.warn('请假时长计算结果错误', hrAffirmDuration, duration); |
|
|
|
invalidCount++; |
|
|
|
} else { |
|
|
|
storageD.push({ |
|
|
|
pepUserId: a.pepUserId, |
|
|
|
pepProcessStoryId: a.historyId, |
|
|
|
startTime: moment(begainTime.value).format('YYYY-MM-DD HH:mm:ss'), |
|
|
|
endTime: moment(endTime.value).format('YYYY-MM-DD HH:mm:ss'), |
|
|
|
duration: durationSec, |
|
|
|
type: hrAffirmType, |
|
|
|
wfProcessState: a.state, |
|
|
|
reason: reason.value |
|
|
|
}); |
|
|
|
packageDay.push({ |
|
|
|
index: { |
|
|
|
day: moment(begainTime.value).format('YYYY-MM-DD'), |
|
|
|
duration: durationSec |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
if (storageD.length) { |
|
|
|
let res = await models.Vacate.bulkCreate(storageD, { returning: true }); |
|
|
|
insertCount++; |
|
|
|
|
|
|
|
for (let item of res) { |
|
|
|
await models.VacateDay.create({ |
|
|
|
day: moment(item.startTime).format('YYYY-MM-DD'), |
|
|
|
duration: item.duration, |
|
|
|
vacateId: item.id |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} else if (begainTime.value && endTime.value && type.value && (duration.value || hrAffirmDuration.value)) {//历史请假表单,无核定请假分组
|
|
|
|
const durationSec = vacateDurationSecDeal(hrAffirmDuration, duration); |
|
|
|
|
|
|
|
if (typeof durationSec != 'number' || isNaN(durationSec) || durationSec <= 0) { |
|
|
|
console.warn('请假时长计算结果错误', hrAffirmDuration, duration); |
|
|
|
invalidCount++; |
|
|
|
} else { |
|
|
|
const { hrAffirmType } = needData; |
|
|
|
// 计算每个工作日请了多少假
|
|
|
|
let begainTime_ = moment(begainTime.value) |
|
|
|
let endTime_ = moment(endTime.value) |
|
|
|