|
|
@ -156,125 +156,125 @@ async function del(ctx) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
async function exportData(ctx) { |
|
|
|
try { |
|
|
|
const { models } = ctx.fs.dc; |
|
|
|
const { clickHouse, opts: { qiniu } } = ctx.app.fs |
|
|
|
const { simpleExcelDown, memberList, packageUserData } = ctx.app.fs.utils |
|
|
|
const { |
|
|
|
keywordTarget, keyword, limit, page, state, keys = '', |
|
|
|
hiredateStart, hiredateEnd, marital, native, workPlace, |
|
|
|
orderBy, orderDirection, |
|
|
|
} = ctx.query |
|
|
|
|
|
|
|
const userRes = await memberList({ |
|
|
|
keywordTarget, keyword, limit, page, state, |
|
|
|
hiredateStart, hiredateEnd, marital, native, workPlace, |
|
|
|
orderBy, orderDirection, |
|
|
|
nowAttendanceTime: true |
|
|
|
}) |
|
|
|
|
|
|
|
const tableAttributes = models['Member'].tableAttributes |
|
|
|
const optionKeys = keys.split(',') |
|
|
|
|
|
|
|
let { packageUser: exportD, pepUserIds } = await packageUserData(userRes) |
|
|
|
|
|
|
|
let preHeader = [{ |
|
|
|
title: '员工编号', |
|
|
|
key: 'userCode', |
|
|
|
}, { |
|
|
|
title: '姓名', |
|
|
|
key: 'userName', |
|
|
|
}] |
|
|
|
let header = [].concat(preHeader) |
|
|
|
for (let k in tableAttributes) { |
|
|
|
const comment = tableAttributes[k].comment |
|
|
|
if (k != 'id' && k != 'pepUserId' && comment) { |
|
|
|
if ([].includes(k)) { |
|
|
|
// 截住不想导出的字段
|
|
|
|
continue |
|
|
|
} |
|
|
|
header.push({ |
|
|
|
title: comment || '-', |
|
|
|
key: k, |
|
|
|
// index: tableAttributes[k].index,
|
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (optionKeys.includes('overtimeStatistic')) { |
|
|
|
header = header.concat([{ |
|
|
|
title: '累计加班次数', |
|
|
|
key: 'overTimeCount', |
|
|
|
}, { |
|
|
|
title: '累计加班总时长 / h', |
|
|
|
key: 'overTimeDuration', |
|
|
|
},]) |
|
|
|
} |
|
|
|
if (optionKeys.includes('vacateStatistic')) { |
|
|
|
header = header.concat([{ |
|
|
|
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 }) |
|
|
|
const fileData = fs.readFileSync(filePath); |
|
|
|
|
|
|
|
ctx.status = 200; |
|
|
|
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.status = 400; |
|
|
|
ctx.body = { |
|
|
|
message: typeof error == 'string' ? error : undefined |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
// async function exportData(ctx) {
|
|
|
|
// try {
|
|
|
|
// const { models } = ctx.fs.dc;
|
|
|
|
// const { clickHouse, opts: { qiniu } } = ctx.app.fs
|
|
|
|
// const { simpleExcelDown, memberList, packageUserData } = ctx.app.fs.utils
|
|
|
|
// const {
|
|
|
|
// keywordTarget, keyword, limit, page, state, keys = '',
|
|
|
|
// hiredateStart, hiredateEnd, marital, native, workPlace,
|
|
|
|
// orderBy, orderDirection,
|
|
|
|
// } = ctx.query
|
|
|
|
|
|
|
|
// const userRes = await memberList({
|
|
|
|
// keywordTarget, keyword, limit, page, state,
|
|
|
|
// hiredateStart, hiredateEnd, marital, native, workPlace,
|
|
|
|
// orderBy, orderDirection,
|
|
|
|
// nowAttendanceTime: true
|
|
|
|
// })
|
|
|
|
|
|
|
|
// const tableAttributes = models['Member'].tableAttributes
|
|
|
|
// const optionKeys = keys.split(',')
|
|
|
|
|
|
|
|
// let { packageUser: exportD, pepUserIds } = await packageUserData(userRes)
|
|
|
|
|
|
|
|
// let preHeader = [{
|
|
|
|
// title: '员工编号',
|
|
|
|
// key: 'userCode',
|
|
|
|
// }, {
|
|
|
|
// title: '姓名',
|
|
|
|
// key: 'userName',
|
|
|
|
// }]
|
|
|
|
// let header = [].concat(preHeader)
|
|
|
|
// for (let k in tableAttributes) {
|
|
|
|
// const comment = tableAttributes[k].comment
|
|
|
|
// if (k != 'id' && k != 'pepUserId' && comment) {
|
|
|
|
// if ([].includes(k)) {
|
|
|
|
// // 截住不想导出的字段
|
|
|
|
// continue
|
|
|
|
// }
|
|
|
|
// header.push({
|
|
|
|
// title: comment || '-',
|
|
|
|
// key: k,
|
|
|
|
// // index: tableAttributes[k].index,
|
|
|
|
// })
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
// if (optionKeys.includes('overtimeStatistic')) {
|
|
|
|
// header = header.concat([{
|
|
|
|
// title: '累计加班次数',
|
|
|
|
// key: 'overTimeCount',
|
|
|
|
// }, {
|
|
|
|
// title: '累计加班总时长 / h',
|
|
|
|
// key: 'overTimeDuration',
|
|
|
|
// },])
|
|
|
|
// }
|
|
|
|
// if (optionKeys.includes('vacateStatistic')) {
|
|
|
|
// header = header.concat([{
|
|
|
|
// 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 })
|
|
|
|
// const fileData = fs.readFileSync(filePath);
|
|
|
|
|
|
|
|
// ctx.status = 200;
|
|
|
|
// 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.status = 400;
|
|
|
|
// ctx.body = {
|
|
|
|
// message: typeof error == 'string' ? error : undefined
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
async function addSalesMemberBulk(ctx) { |
|
|
|
let errorMsg = { message: '导入销售人员信息失败' }; |
|
|
@ -329,6 +329,6 @@ module.exports = { |
|
|
|
add, |
|
|
|
edit, |
|
|
|
del, |
|
|
|
exportData, |
|
|
|
//exportData,
|
|
|
|
addSalesMemberBulk, |
|
|
|
} |