人力资源
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

141 lines
4.4 KiB

'use strict';
2 years ago
const moment = require('moment')
async function overtimeStatistic (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,
2 years ago
overtimeDayStatisticendDate: endDate,
overtimeCountStatistic: true,
overtimeCountStatisticStartDate: startDate,
overtimeCountStatisticendDate: endDate,
})
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)
})
ctx.status = 200;
ctx.body = {
count: userRes.count,
rows: returnD
}
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400;
ctx.body = {
message: typeof error == 'string' ? error : 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,
})
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.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
}
}
}
2 years ago
async function vacateStatistic (ctx) {
try {
const { models } = ctx.fs.dc;
const { clickHouse } = ctx.app.fs
const { judgeHoliday, memberList, packageUserData, vacateStatisticListDayType } = ctx.app.fs.utils
2 years ago
const {
keywordTarget, keyword, limit, page, orderBy, orderDirection,
startDate, endDate,
} = ctx.query
const userRes = await memberList({
keywordTarget, keyword, limit, page,
orderBy, orderDirection,
vacateDayStatisticStartDate: startDate,
vacateDayStatisticendDate: endDate,
vacateDurationStatistic: true,
vacateCountStatistic: true,
vacateCountStatisticStartDate: startDate,
vacateCountStatisticendDate: endDate,
})
let { packageUser: returnD, pepUserIds } = await packageUserData(userRes)
2 years ago
const sumRes = await vacateStatisticListDayType({
startDate, endDate, pepUserIds
})
2 years ago
returnD.forEach(u => {
u.vacateStatistic = sumRes.filter(s => s.pepUserId == u.pepUserId)
})
ctx.status = 200;
ctx.body = {
count: userRes.count,
rows: returnD
}
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400;
ctx.body = {
message: typeof error == 'string' ? error : undefined
}
}
}
module.exports = {
overtimeStatistic,
2 years ago
vacateStatistic,
};