|
@ -1,6 +1,7 @@ |
|
|
'use strict'; |
|
|
'use strict'; |
|
|
const moment = require('moment') |
|
|
const moment = require('moment') |
|
|
const fs = require('fs'); |
|
|
const fs = require('fs'); |
|
|
|
|
|
const { getDataRange } = require('../auth/index') |
|
|
|
|
|
|
|
|
async function overtimeStatistic(ctx) { |
|
|
async function overtimeStatistic(ctx) { |
|
|
try { |
|
|
try { |
|
@ -12,6 +13,14 @@ async function overtimeStatistic(ctx) { |
|
|
startDate, endDate, |
|
|
startDate, endDate, |
|
|
} = ctx.query |
|
|
} = 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({ |
|
|
const userRes = await memberList({ |
|
|
keywordTarget, keyword, limit, page, |
|
|
keywordTarget, keyword, limit, page, |
|
|
orderBy, orderDirection, |
|
|
orderBy, orderDirection, |
|
@ -20,6 +29,7 @@ async function overtimeStatistic(ctx) { |
|
|
overtimeCountStatistic: true, |
|
|
overtimeCountStatistic: true, |
|
|
overtimeCountStatisticStartDate: startDate, |
|
|
overtimeCountStatisticStartDate: startDate, |
|
|
overtimeCountStatisticendDate: endDate, |
|
|
overtimeCountStatisticendDate: endDate, |
|
|
|
|
|
userIds: dataRange.userIds |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
let { packageUser: returnD, pepUserIds } = await packageUserData(userRes) |
|
|
let { packageUser: returnD, pepUserIds } = await packageUserData(userRes) |
|
@ -38,6 +48,7 @@ async function overtimeStatistic(ctx) { |
|
|
count: userRes.count, |
|
|
count: userRes.count, |
|
|
rows: returnD |
|
|
rows: returnD |
|
|
} |
|
|
} |
|
|
|
|
|
} |
|
|
} catch (error) { |
|
|
} catch (error) { |
|
|
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
|
|
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
|
|
ctx.status = 400; |
|
|
ctx.status = 400; |
|
@ -56,7 +67,11 @@ async function exportOvertimeStatistic(ctx) { |
|
|
keywordTarget, keyword, limit, page, orderBy, orderDirection, |
|
|
keywordTarget, keyword, limit, page, orderBy, orderDirection, |
|
|
startDate, endDate, |
|
|
startDate, endDate, |
|
|
} = ctx.query |
|
|
} = ctx.query |
|
|
|
|
|
let returnD = null; |
|
|
|
|
|
let dataRange = await getDataRange(ctx); |
|
|
|
|
|
if (dataRange.userIds && dataRange.userIds.length === 0) { |
|
|
|
|
|
returnD = []; |
|
|
|
|
|
} else { |
|
|
const userRes = await memberList({ |
|
|
const userRes = await memberList({ |
|
|
keywordTarget, keyword, limit, page, |
|
|
keywordTarget, keyword, limit, page, |
|
|
orderBy, orderDirection, |
|
|
orderBy, orderDirection, |
|
@ -65,10 +80,11 @@ async function exportOvertimeStatistic(ctx) { |
|
|
overtimeCountStatistic: true, |
|
|
overtimeCountStatistic: true, |
|
|
overtimeCountStatisticStartDate: startDate, |
|
|
overtimeCountStatisticStartDate: startDate, |
|
|
overtimeCountStatisticendDate: endDate, |
|
|
overtimeCountStatisticendDate: endDate, |
|
|
|
|
|
userIds: dataRange.userIds |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
let { packageUser: returnD, pepUserIds } = await packageUserData(userRes) |
|
|
let { packageUser, pepUserIds } = await packageUserData(userRes) |
|
|
|
|
|
returnD = packageUser; |
|
|
const sumRes = await overtimeStatisticListDayType({ |
|
|
const sumRes = await overtimeStatisticListDayType({ |
|
|
startDate, endDate, pepUserIds |
|
|
startDate, endDate, pepUserIds |
|
|
}) |
|
|
}) |
|
@ -89,7 +105,7 @@ async function exportOvertimeStatistic(ctx) { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
for (let overtimeTypeKey in overtimeType) { |
|
|
for (let overtimeTypeKey in overtimeType) { |
|
|
d['sum' + overtimeTypeKey] = overtimeStatistic.reduce((sum, o) => { |
|
|
d['sum' + overtimeTypeKey] = overtimeStatistic((sum, o) => { |
|
|
if (o.compensate == overtimeTypeKey) { |
|
|
if (o.compensate == overtimeTypeKey) { |
|
|
sum += o.duration / 3600 |
|
|
sum += o.duration / 3600 |
|
|
// totalDuration += o.duration / 3600
|
|
|
// totalDuration += o.duration / 3600
|
|
@ -99,7 +115,7 @@ async function exportOvertimeStatistic(ctx) { |
|
|
} |
|
|
} |
|
|
d.totalDuration = totalDuration |
|
|
d.totalDuration = totalDuration |
|
|
}) |
|
|
}) |
|
|
|
|
|
} |
|
|
let overtimeTypeHeader = [] |
|
|
let overtimeTypeHeader = [] |
|
|
let sumOvertimeTypeHeader = [] |
|
|
let sumOvertimeTypeHeader = [] |
|
|
for (let overtimeTypeKey in overtimeType) { |
|
|
for (let overtimeTypeKey in overtimeType) { |
|
@ -149,6 +165,7 @@ async function exportOvertimeStatistic(ctx) { |
|
|
ctx.set('Content-Type', 'application/x-xls'); |
|
|
ctx.set('Content-Type', 'application/x-xls'); |
|
|
ctx.set('Content-disposition', 'attachment; filename=' + encodeURI(fileName)); |
|
|
ctx.set('Content-disposition', 'attachment; filename=' + encodeURI(fileName)); |
|
|
ctx.body = fileData; |
|
|
ctx.body = fileData; |
|
|
|
|
|
|
|
|
} catch (error) { |
|
|
} catch (error) { |
|
|
ctx.fs.logger.error(`path: ${ctx.path}, error: error`); |
|
|
ctx.fs.logger.error(`path: ${ctx.path}, error: error`); |
|
|
ctx.status = 400; |
|
|
ctx.status = 400; |
|
@ -188,6 +205,14 @@ async function vacateStatistic(ctx) { |
|
|
startDate, endDate, |
|
|
startDate, endDate, |
|
|
} = ctx.query |
|
|
} = 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({ |
|
|
const userRes = await memberList({ |
|
|
keywordTarget, keyword, limit, page, |
|
|
keywordTarget, keyword, limit, page, |
|
|
orderBy, orderDirection, |
|
|
orderBy, orderDirection, |
|
@ -197,6 +222,7 @@ async function vacateStatistic(ctx) { |
|
|
vacateCountStatistic: true, |
|
|
vacateCountStatistic: true, |
|
|
vacateCountStatisticStartDate: startDate, |
|
|
vacateCountStatisticStartDate: startDate, |
|
|
vacateCountStatisticendDate: endDate, |
|
|
vacateCountStatisticendDate: endDate, |
|
|
|
|
|
userIds: dataRange.userIds |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
let { packageUser: returnD, pepUserIds } = await packageUserData(userRes) |
|
|
let { packageUser: returnD, pepUserIds } = await packageUserData(userRes) |
|
@ -219,6 +245,7 @@ async function vacateStatistic(ctx) { |
|
|
count: userRes.count, |
|
|
count: userRes.count, |
|
|
rows: returnD |
|
|
rows: returnD |
|
|
} |
|
|
} |
|
|
|
|
|
} |
|
|
} catch (error) { |
|
|
} catch (error) { |
|
|
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
|
|
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
|
|
ctx.status = 400; |
|
|
ctx.status = 400; |
|
@ -241,7 +268,11 @@ async function exportVacateStatistic(ctx) { |
|
|
const vacateTypeRes = await clickHouse.hr.query(` |
|
|
const vacateTypeRes = await clickHouse.hr.query(` |
|
|
SELECT type FROM vacate GROUP BY type ORDER BY type DESC |
|
|
SELECT type FROM vacate GROUP BY type ORDER BY type DESC |
|
|
`).toPromise()
|
|
|
`).toPromise()
|
|
|
|
|
|
let returnD = null; |
|
|
|
|
|
let dataRange = await getDataRange(ctx); |
|
|
|
|
|
if (dataRange.userIds && dataRange.userIds.length === 0) { |
|
|
|
|
|
returnD = []; |
|
|
|
|
|
} else { |
|
|
const userRes = await memberList({ |
|
|
const userRes = await memberList({ |
|
|
keywordTarget, keyword, limit, page, |
|
|
keywordTarget, keyword, limit, page, |
|
|
orderBy, orderDirection, |
|
|
orderBy, orderDirection, |
|
@ -251,10 +282,11 @@ async function exportVacateStatistic(ctx) { |
|
|
vacateCountStatistic: true, |
|
|
vacateCountStatistic: true, |
|
|
vacateCountStatisticStartDate: startDate, |
|
|
vacateCountStatisticStartDate: startDate, |
|
|
vacateCountStatisticendDate: endDate, |
|
|
vacateCountStatisticendDate: endDate, |
|
|
|
|
|
userIds: dataRange.userIds |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
let { packageUser: returnD, pepUserIds } = await packageUserData(userRes) |
|
|
let { packageUser, pepUserIds } = await packageUserData(userRes) |
|
|
|
|
|
returnD = packageUser; |
|
|
const sumRes = await vacateStatisticListDayType({ |
|
|
const sumRes = await vacateStatisticListDayType({ |
|
|
startDate, endDate, pepUserIds |
|
|
startDate, endDate, pepUserIds |
|
|
}) |
|
|
}) |
|
@ -279,7 +311,7 @@ async function exportVacateStatistic(ctx) { |
|
|
let remarkData = remarkList.filter(e => e.pepUserId == u.pepUserId) |
|
|
let remarkData = remarkList.filter(e => e.pepUserId == u.pepUserId) |
|
|
u.remark = remarkData.length ? (remarkData[0].remark == '' ? '无' : remarkData[0].remark) : '无' |
|
|
u.remark = remarkData.length ? (remarkData[0].remark == '' ? '无' : remarkData[0].remark) : '无' |
|
|
}) |
|
|
}) |
|
|
|
|
|
} |
|
|
const header = [{ |
|
|
const header = [{ |
|
|
title: '员工编号', |
|
|
title: '员工编号', |
|
|
key: 'userCode', |
|
|
key: 'userCode', |
|
|