|
|
@ -1,6 +1,7 @@ |
|
|
|
'use strict'; |
|
|
|
const moment = require('moment') |
|
|
|
const fs = require('fs'); |
|
|
|
const { getDataRange } = require('../auth/index') |
|
|
|
|
|
|
|
async function add(ctx) { |
|
|
|
try { |
|
|
@ -283,12 +284,19 @@ async function list(ctx) { |
|
|
|
hiredateStart, hiredateEnd, marital, native, workPlace, |
|
|
|
orderBy, orderDirection, |
|
|
|
} = ctx.query |
|
|
|
|
|
|
|
let dataRange = await getDataRange(ctx); |
|
|
|
if (dataRange.userIds && dataRange.userIds.length === 0) { |
|
|
|
ctx.status = 200; |
|
|
|
ctx.body = { |
|
|
|
count: 0, |
|
|
|
rows: [] |
|
|
|
} |
|
|
|
} else { |
|
|
|
const userRes = await memberList({ |
|
|
|
keywordTarget, keyword, limit, page, state, |
|
|
|
hiredateStart, hiredateEnd, marital, native, workPlace, |
|
|
|
orderBy, orderDirection, |
|
|
|
nowAttendanceTime: true |
|
|
|
nowAttendanceTime: true, userIds: dataRange.userIds |
|
|
|
}) |
|
|
|
|
|
|
|
let { packageUser: returnD, pepUserIds } = await packageUserData(userRes, { |
|
|
@ -300,6 +308,7 @@ async function list(ctx) { |
|
|
|
count: userRes.count, |
|
|
|
rows: returnD |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (error) { |
|
|
|
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
|
|
|
ctx.status = 400; |
|
|
@ -498,19 +507,65 @@ async function exportData(ctx) { |
|
|
|
hiredateStart, hiredateEnd, marital, native, workPlace, |
|
|
|
orderBy, orderDirection, |
|
|
|
} = ctx.query |
|
|
|
|
|
|
|
const tableAttributes = models['Member'].tableAttributes |
|
|
|
const optionKeys = keys.split(',') |
|
|
|
let exportD = null; |
|
|
|
let dataRange = await getDataRange(ctx); |
|
|
|
if (dataRange.userIds && dataRange.userIds.length === 0) { |
|
|
|
exportD = []; |
|
|
|
} else { |
|
|
|
const userRes = await memberList({ |
|
|
|
keywordTarget, keyword, limit, page, state, |
|
|
|
hiredateStart, hiredateEnd, marital, native, workPlace, |
|
|
|
orderBy, orderDirection, |
|
|
|
nowAttendanceTime: true |
|
|
|
nowAttendanceTime: true, userIds: dataRange.userIds |
|
|
|
}) |
|
|
|
|
|
|
|
const tableAttributes = models['Member'].tableAttributes |
|
|
|
const optionKeys = keys.split(',') |
|
|
|
let { packageUser, pepUserIds } = await packageUserData(userRes) |
|
|
|
exportD = packageUser; |
|
|
|
|
|
|
|
let { packageUser: exportD, pepUserIds } = await packageUserData(userRes) |
|
|
|
// 查询累计加班次数及总时长
|
|
|
|
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.userJob = d.userJob ? UserAttribute.jobDataSource[d.userJob - 1] : ''; |
|
|
|
d.userActiveStatus = d.userActiveStatus ? UserAttribute.activeStatusDataSource[d.userActiveStatus - 1] : ''; |
|
|
|
d.userOrganization = d.userOrganization ? UserAttribute.organizationDataSource[d.userOrganization - 1] : ''; |
|
|
|
|
|
|
|
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 |
|
|
|
}) |
|
|
|
} |
|
|
|
let preHeader = [{ |
|
|
|
title: '员工编号', |
|
|
|
key: 'userCode', |
|
|
@ -573,49 +628,6 @@ async function exportData(ctx) { |
|
|
|
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.userJob = d.userJob ? UserAttribute.jobDataSource[d.userJob - 1] : ''; |
|
|
|
d.userActiveStatus = d.userActiveStatus ? UserAttribute.activeStatusDataSource[d.userActiveStatus - 1] : ''; |
|
|
|
d.userOrganization = d.userOrganization ? UserAttribute.organizationDataSource[d.userOrganization - 1] : ''; |
|
|
|
|
|
|
|
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); |
|
|
@ -714,7 +726,9 @@ async function getPositionRating(ctx) { |
|
|
|
findObj.limit = Number(limit); |
|
|
|
findObj.offset = Number(page) * Number(limit); |
|
|
|
} |
|
|
|
|
|
|
|
let dataRange = await getDataRange(ctx); |
|
|
|
if (dataRange.userIds) |
|
|
|
findObj.where = { pepUserId: { $in: dataRange.userIds || [] } } |
|
|
|
const list = await models.PositionRating.findAndCountAll(findObj); |
|
|
|
if (list.rows.length) { |
|
|
|
const userIds = list.rows.map(u => u.pepUserId); |
|
|
|