|
|
@ -221,7 +221,7 @@ async function list (ctx) { |
|
|
|
) |
|
|
|
.replace(/_/g, '') |
|
|
|
} |
|
|
|
obj[nextKey] = u[k] |
|
|
|
obj[nextKey] = u[k] == '1970-01-01 00:00:00.000000' ? null : u[k] |
|
|
|
} |
|
|
|
returnD.push({ |
|
|
|
...obj, |
|
|
@ -234,7 +234,7 @@ async function list (ctx) { |
|
|
|
name: u.roleName |
|
|
|
}] : [], |
|
|
|
del: undefined, |
|
|
|
pepuserid: undefined |
|
|
|
pepuserid: undefined, |
|
|
|
}) |
|
|
|
} |
|
|
|
}) |
|
|
@ -382,6 +382,7 @@ async function vacateStatistics (ctx) { |
|
|
|
async function exportData (ctx) { |
|
|
|
try { |
|
|
|
const { models } = ctx.fs.dc; |
|
|
|
const { clickHouse, opts: { qiniu } } = ctx.app.fs |
|
|
|
const { simpleExcelDown, memberList } = ctx.app.fs.utils |
|
|
|
const { keywordTarget, keyword, limit, page, state, keys = '' } = ctx.query |
|
|
|
|
|
|
@ -391,6 +392,7 @@ async function exportData (ctx) { |
|
|
|
const optionKeys = keys.split(',') |
|
|
|
|
|
|
|
let exportD = [] |
|
|
|
let pepUserIds = [] |
|
|
|
userRes.forEach(u => { |
|
|
|
let existUser = exportD.find(r => r.pepUserId == u.pepUserId) |
|
|
|
if (existUser) { |
|
|
@ -419,8 +421,9 @@ async function exportData (ctx) { |
|
|
|
) |
|
|
|
.replace(/_/g, '') |
|
|
|
} |
|
|
|
obj[nextKey] = u[k] |
|
|
|
obj[nextKey] = u[k] == '1970-01-01 00:00:00.000000' ? null : u[k] |
|
|
|
} |
|
|
|
pepUserIds.push(u.pepUserId) |
|
|
|
exportD.push({ |
|
|
|
...obj, |
|
|
|
departmrnt: u.depId ? [{ |
|
|
@ -456,6 +459,56 @@ async function exportData (ctx) { |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
header = header.concat([{ |
|
|
|
title: '累计加班次数', |
|
|
|
key: 'overTimeCount', |
|
|
|
}, { |
|
|
|
title: '累计加班总时长 / h', |
|
|
|
key: 'overTimeDuration', |
|
|
|
}, { |
|
|
|
title: '累计请假次数', |
|
|
|
key: 'vacateCount', |
|
|
|
}, { |
|
|
|
title: '累计请假总时长 / h', |
|
|
|
key: 'vacateDuration', |
|
|
|
},]) |
|
|
|
// 查询累计加班次数及总时长
|
|
|
|
const statisticOvertimeRes = await clickHouse.hr.query(` |
|
|
|
SELECT |
|
|
|
pep_user_id AS pepUserId, |
|
|
|
count(id) AS count, |
|
|
|
sum(duration) AS duration |
|
|
|
FROM |
|
|
|
overtime |
|
|
|
WHERE pep_user_id IN (${pepUserIds.join(',')}) |
|
|
|
GROUP BY pep_user_id |
|
|
|
`).toPromise()
|
|
|
|
|
|
|
|
const statisticVacateRes = await clickHouse.hr.query(` |
|
|
|
SELECT |
|
|
|
pep_user_id AS pepUserId, |
|
|
|
count(id) AS count, |
|
|
|
sum(duration) AS duration |
|
|
|
FROM |
|
|
|
vacate |
|
|
|
WHERE pep_user_id IN (${pepUserIds.join(',')}) |
|
|
|
GROUP BY pep_user_id |
|
|
|
`).toPromise()
|
|
|
|
|
|
|
|
exportD.forEach(d => { |
|
|
|
d.departmrnt = d.departmrnt.map(dep => dep.name).join('、') |
|
|
|
d.role = d.role.map(r => r.name).join('、') |
|
|
|
|
|
|
|
d.idPhoto ? d.idPhoto = qiniu.domain + d.idPhoto : '' |
|
|
|
d.vitae ? d.vitae = qiniu.domain + d.vitae : '' |
|
|
|
|
|
|
|
const corOverTime = statisticOvertimeRes.find(so => so.pepUserId == d.pepUserId) |
|
|
|
d.overTimeCount = corOverTime ? corOverTime.count : 0 |
|
|
|
d.overTimeDuration = corOverTime ? (corOverTime.duration / 3600).toFixed(1) : 0 |
|
|
|
const corVacate = statisticVacateRes.find(so => so.pepUserId == d.pepUserId) |
|
|
|
d.vacateCount = corVacate ? corVacate.count : 0 |
|
|
|
d.vacateDuration = corVacate ? (corVacate.duration / 3600).toFixed(1) : 0 |
|
|
|
}) |
|
|
|
|
|
|
|
const fileName = `人员信息_${moment().format('YYYYMMDDHHmmss')}` + '.csv' |
|
|
|
const filePath = await simpleExcelDown({ data: exportD, header, fileName: fileName }) |
|
|
|