|
|
@ -5,7 +5,7 @@ async function overtimeStatistic (ctx) { |
|
|
|
try { |
|
|
|
const { models } = ctx.fs.dc; |
|
|
|
const { clickHouse } = ctx.app.fs |
|
|
|
const { judgeHoliday, memberList } = ctx.app.fs.utils |
|
|
|
const { memberList, packageUserData, overtimeStatisticListDayType } = ctx.app.fs.utils |
|
|
|
const { |
|
|
|
keywordTarget, keyword, limit, page, orderBy, orderDirection, |
|
|
|
startDate, endDate, |
|
|
@ -21,87 +21,69 @@ async function overtimeStatistic (ctx) { |
|
|
|
overtimeCountStatisticendDate: endDate, |
|
|
|
}) |
|
|
|
|
|
|
|
let returnD = [] |
|
|
|
let pepUserIds = [] |
|
|
|
userRes.rows.forEach(u => { |
|
|
|
let existUser = returnD.find(r => r.pepUserId == u.pepUserId) |
|
|
|
if (existUser) { |
|
|
|
if (u.depId && !existUser.departmrnt.some(d => d.id == u.depId)) { |
|
|
|
existUser.departmrnt.push({ |
|
|
|
id: u.depId, |
|
|
|
name: u.depName |
|
|
|
let { packageUser: returnD, pepUserIds } = await packageUserData(userRes) |
|
|
|
|
|
|
|
const sumRes = await overtimeStatisticListDayType({ |
|
|
|
startDate, endDate, pepUserIds |
|
|
|
}) |
|
|
|
} |
|
|
|
if (u.roleId && !existUser.role.some(r => r.id == u.roleId)) { |
|
|
|
existUser.role.push({ |
|
|
|
id: u.roleId, |
|
|
|
name: u.roleName |
|
|
|
|
|
|
|
returnD.forEach(u => { |
|
|
|
u.overtimeStatistic = sumRes.filter(s => s.pepUserId == u.pepUserId) |
|
|
|
}) |
|
|
|
ctx.status = 200; |
|
|
|
ctx.body = { |
|
|
|
count: userRes.count, |
|
|
|
rows: returnD |
|
|
|
} |
|
|
|
} else { |
|
|
|
let obj = {} |
|
|
|
for (let k in u) { |
|
|
|
let nextKey = k.replace('hrMember.', '') |
|
|
|
.replace('member.', '') |
|
|
|
if (nextKey.includes('_')) { |
|
|
|
nextKey = nextKey.toLowerCase() |
|
|
|
.replace( |
|
|
|
/(_)[a-z]/g, |
|
|
|
(L) => L.toUpperCase() |
|
|
|
) |
|
|
|
.replace(/_/g, '') |
|
|
|
} catch (error) { |
|
|
|
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
|
|
|
ctx.status = 400; |
|
|
|
ctx.body = { |
|
|
|
message: typeof error == 'string' ? error : undefined |
|
|
|
} |
|
|
|
obj[nextKey] = u[k] |
|
|
|
} |
|
|
|
pepUserIds.push(u.pepUserId) |
|
|
|
returnD.push({ |
|
|
|
...obj, |
|
|
|
departmrnt: u.depId ? [{ |
|
|
|
id: u.depId, |
|
|
|
name: u.depName |
|
|
|
}] : [], |
|
|
|
role: u.roleId ? [{ |
|
|
|
id: u.roleId, |
|
|
|
name: u.roleName |
|
|
|
}] : [], |
|
|
|
del: undefined, |
|
|
|
pepuserid: undefined, |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
async function exportOvertimeStatistic (ctx) { |
|
|
|
try { |
|
|
|
const { models } = ctx.fs.dc; |
|
|
|
const { clickHouse } = ctx.app.fs |
|
|
|
const { memberList, packageUserData, overtimeStatisticListDayType } = ctx.app.fs.utils |
|
|
|
const { |
|
|
|
keywordTarget, keyword, limit, page, orderBy, orderDirection, |
|
|
|
startDate, endDate, |
|
|
|
} = ctx.query |
|
|
|
|
|
|
|
const userRes = await memberList({ |
|
|
|
keywordTarget, keyword, limit, page, |
|
|
|
orderBy, orderDirection, |
|
|
|
overtimeDayStatisticStartDate: startDate, |
|
|
|
overtimeDayStatisticendDate: endDate, |
|
|
|
overtimeCountStatistic: true, |
|
|
|
overtimeCountStatisticStartDate: startDate, |
|
|
|
overtimeCountStatisticendDate: endDate, |
|
|
|
}) |
|
|
|
|
|
|
|
const sumRes = await clickHouse.hr.query(` |
|
|
|
SELECT |
|
|
|
overtime.pep_user_id AS pepUserId, |
|
|
|
holiday.type AS dayType, |
|
|
|
overtime.compensate AS compensate, |
|
|
|
sum(overtime_day.duration) AS duration |
|
|
|
FROM overtime_day |
|
|
|
INNER JOIN overtime |
|
|
|
ON overtime.id = overtime_day.overtime_id |
|
|
|
AND overtime.pep_user_id IN (${pepUserIds.join(',')}) |
|
|
|
LEFT JOIN holiday |
|
|
|
ON holiday.day = overtime_day.day |
|
|
|
WHERE overtime.pep_user_id IN (${pepUserIds.join(',')}) |
|
|
|
${startDate ? ` |
|
|
|
AND overtime_day.day >= '${moment(startDate).format('YYYY-MM-DD')}' |
|
|
|
`: ''}
|
|
|
|
${endDate ? ` |
|
|
|
AND overtime_day.day <= '${moment(endDate).format('YYYY-MM-DD')}' |
|
|
|
` : ''}
|
|
|
|
GROUP BY holiday.type, overtime.compensate, overtime.pep_user_id |
|
|
|
`).toPromise()
|
|
|
|
let { packageUser: returnD, pepUserIds } = await packageUserData(userRes) |
|
|
|
|
|
|
|
const sumRes = await overtimeStatisticListDayType({ |
|
|
|
startDate, endDate, pepUserIds |
|
|
|
}) |
|
|
|
|
|
|
|
returnD.forEach(u => { |
|
|
|
u.overtimeStatistic = sumRes.filter(s => s.pepUserId == u.pepUserId) |
|
|
|
}) |
|
|
|
|
|
|
|
const fileName = `人员信息_${moment().format('YYYYMMDDHHmmss')}` + '.csv' |
|
|
|
const filePath = await simpleExcelDown({ data: exportD, header, fileName: fileName }) |
|
|
|
const fileData = fs.readFileSync(filePath); |
|
|
|
|
|
|
|
ctx.status = 200; |
|
|
|
ctx.body = { |
|
|
|
count: userRes.count, |
|
|
|
rows: returnD |
|
|
|
} |
|
|
|
ctx.set('Content-Type', 'application/x-xls'); |
|
|
|
ctx.set('Content-disposition', 'attachment; filename=' + encodeURI(fileName)); |
|
|
|
ctx.body = fileData; |
|
|
|
} catch (error) { |
|
|
|
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
|
|
|
ctx.fs.logger.error(`path: ${ctx.path}, error: error`); |
|
|
|
ctx.status = 400; |
|
|
|
ctx.body = { |
|
|
|
message: typeof error == 'string' ? error : undefined |
|
|
@ -113,7 +95,7 @@ async function vacateStatistic (ctx) { |
|
|
|
try { |
|
|
|
const { models } = ctx.fs.dc; |
|
|
|
const { clickHouse } = ctx.app.fs |
|
|
|
const { judgeHoliday, memberList } = ctx.app.fs.utils |
|
|
|
const { judgeHoliday, memberList, packageUserData, vacateStatisticListDayType } = ctx.app.fs.utils |
|
|
|
const { |
|
|
|
keywordTarget, keyword, limit, page, orderBy, orderDirection, |
|
|
|
startDate, endDate, |
|
|
@ -130,73 +112,11 @@ async function vacateStatistic (ctx) { |
|
|
|
vacateCountStatisticendDate: endDate, |
|
|
|
}) |
|
|
|
|
|
|
|
let returnD = [] |
|
|
|
let pepUserIds = [] |
|
|
|
userRes.rows.forEach(u => { |
|
|
|
let existUser = returnD.find(r => r.pepUserId == u.pepUserId) |
|
|
|
if (existUser) { |
|
|
|
if (u.depId && !existUser.departmrnt.some(d => d.id == u.depId)) { |
|
|
|
existUser.departmrnt.push({ |
|
|
|
id: u.depId, |
|
|
|
name: u.depName |
|
|
|
}) |
|
|
|
} |
|
|
|
if (u.roleId && !existUser.role.some(r => r.id == u.roleId)) { |
|
|
|
existUser.role.push({ |
|
|
|
id: u.roleId, |
|
|
|
name: u.roleName |
|
|
|
}) |
|
|
|
} |
|
|
|
} else { |
|
|
|
let obj = {} |
|
|
|
for (let k in u) { |
|
|
|
let nextKey = k.replace('hrMember.', '') |
|
|
|
.replace('member.', '') |
|
|
|
if (nextKey.includes('_')) { |
|
|
|
nextKey = nextKey.toLowerCase() |
|
|
|
.replace( |
|
|
|
/(_)[a-z]/g, |
|
|
|
(L) => L.toUpperCase() |
|
|
|
) |
|
|
|
.replace(/_/g, '') |
|
|
|
} |
|
|
|
obj[nextKey] = u[k] |
|
|
|
} |
|
|
|
pepUserIds.push(u.pepUserId) |
|
|
|
returnD.push({ |
|
|
|
...obj, |
|
|
|
departmrnt: u.depId ? [{ |
|
|
|
id: u.depId, |
|
|
|
name: u.depName |
|
|
|
}] : [], |
|
|
|
role: u.roleId ? [{ |
|
|
|
id: u.roleId, |
|
|
|
name: u.roleName |
|
|
|
}] : [], |
|
|
|
del: undefined, |
|
|
|
pepuserid: undefined, |
|
|
|
}) |
|
|
|
} |
|
|
|
}) |
|
|
|
let { packageUser: returnD, pepUserIds } = await packageUserData(userRes) |
|
|
|
|
|
|
|
const sumRes = await clickHouse.hr.query(` |
|
|
|
SELECT |
|
|
|
vacate.pep_user_id AS pepUserId, |
|
|
|
vacate.type AS type, |
|
|
|
sum(vacate_day.duration) AS duration |
|
|
|
FROM vacate_day |
|
|
|
INNER JOIN vacate |
|
|
|
ON vacate.id = vacate_day.vacate_id |
|
|
|
AND vacate.pep_user_id IN (${pepUserIds.join(',')}) |
|
|
|
WHERE vacate.pep_user_id IN (${pepUserIds.join(',')}) |
|
|
|
${startDate ? ` |
|
|
|
AND vacate_day.day >= '${moment(startDate).format('YYYY-MM-DD')}' |
|
|
|
`: ''}
|
|
|
|
${endDate ? ` |
|
|
|
AND vacate_day.day <= '${moment(endDate).format('YYYY-MM-DD')}' |
|
|
|
` : ''}
|
|
|
|
GROUP BY vacate.type, vacate.pep_user_id |
|
|
|
`).toPromise()
|
|
|
|
const sumRes = await vacateStatisticListDayType({ |
|
|
|
startDate, endDate, pepUserIds |
|
|
|
}) |
|
|
|
|
|
|
|
returnD.forEach(u => { |
|
|
|
u.vacateStatistic = sumRes.filter(s => s.pepUserId == u.pepUserId) |
|
|
|