|
|
@ -31,7 +31,7 @@ async function add (ctx) { |
|
|
|
} |
|
|
|
}) |
|
|
|
} else { |
|
|
|
await models.create(storageData) |
|
|
|
await models.Member.create(storageData) |
|
|
|
} |
|
|
|
|
|
|
|
ctx.status = 204; |
|
|
@ -384,10 +384,156 @@ async function list (ctx) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
async function overTimeStatistics (ctx) { |
|
|
|
try { |
|
|
|
const { models } = ctx.fs.dc; |
|
|
|
const { clickHouse } = ctx.app.fs |
|
|
|
const { database: pepEmis } = clickHouse.pepEmis.opts.config |
|
|
|
const { startDate, endDate, pepUserId } = ctx.query |
|
|
|
|
|
|
|
const timeOption = [] |
|
|
|
if (startDate && endDate) { |
|
|
|
timeOption.push( |
|
|
|
`wpStory.create_at <= '${moment(endDate).format('YYYY-MM-DD HH:mm:ss')}'
|
|
|
|
AND wpStory.create_at > '${moment(startDate).format('YYYY-MM-DD HH:mm:ss')}'` |
|
|
|
) |
|
|
|
} |
|
|
|
const dataRes = await clickHouse.hr.query(` |
|
|
|
SELECT |
|
|
|
compensate, |
|
|
|
create_at AS createTime, |
|
|
|
start_time AS startTime, |
|
|
|
end_time AS endTime, |
|
|
|
pay_dayoff AS payDayoff, |
|
|
|
pay_festivals AS payFestivals, |
|
|
|
pay_workday AS payWorkday, |
|
|
|
reason, |
|
|
|
take_rest_dayoff AS takeRestDayoff, |
|
|
|
take_rest_festivals AS takeRestFestivals, |
|
|
|
take_rest_workday AS takeRestWorkday, |
|
|
|
wpStory.id AS storyId |
|
|
|
FROM |
|
|
|
overtime |
|
|
|
INNER JOIN ${pepEmis}.workflow_process_history AS wpStory |
|
|
|
ON wpStory.id = overtime.pep_process_story_id |
|
|
|
${timeOption.length ? `AND ${timeOption.join(' AND ')}` : ''} |
|
|
|
WHERE overtime.pep_user_id = ${pepUserId} |
|
|
|
`).toPromise()
|
|
|
|
|
|
|
|
const statisticRes = await clickHouse.hr.query(` |
|
|
|
SELECT |
|
|
|
count(overtime.id) AS overTimeCount, |
|
|
|
sum(pay_dayoff) AS sumPayDayoff, |
|
|
|
sum(pay_festivals) AS sumPayFestivals, |
|
|
|
sum(pay_workday) AS sumPayWorkday, |
|
|
|
sum(take_rest_dayoff) AS sumTakeRestDayoff, |
|
|
|
sum(take_rest_festivals) AS sumTakeRestFestivals, |
|
|
|
sum(take_rest_workday) AS sumTakeRestWorkday |
|
|
|
FROM |
|
|
|
overtime |
|
|
|
INNER JOIN ${pepEmis}.workflow_process_history AS wpStory |
|
|
|
ON wpStory.id = overtime.pep_process_story_id |
|
|
|
${timeOption.length ? `AND ${timeOption.join(' AND ')}` : ''} |
|
|
|
WHERE overtime.pep_user_id = ${pepUserId} |
|
|
|
GROUP BY overtime.pep_user_id |
|
|
|
`).toPromise()
|
|
|
|
|
|
|
|
let returnD = { |
|
|
|
...(statisticRes.length ? statisticRes[0] : {}), |
|
|
|
data: dataRes |
|
|
|
} |
|
|
|
ctx.status = 200; |
|
|
|
ctx.body = 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 vacateStatistics (ctx) { |
|
|
|
try { |
|
|
|
const { models } = ctx.fs.dc; |
|
|
|
const { clickHouse } = ctx.app.fs |
|
|
|
const { database: pepEmis } = clickHouse.pepEmis.opts.config |
|
|
|
const { startDate, endDate, pepUserId } = ctx.query |
|
|
|
|
|
|
|
const timeOption = [] |
|
|
|
if (startDate && endDate) { |
|
|
|
timeOption.push( |
|
|
|
`wpStory.create_at <= '${moment(endDate).format('YYYY-MM-DD HH:mm:ss')}'
|
|
|
|
AND wpStory.create_at > '${moment(startDate).format('YYYY-MM-DD HH:mm:ss')}'` |
|
|
|
) |
|
|
|
} |
|
|
|
const dataRes = await clickHouse.hr.query(` |
|
|
|
SELECT |
|
|
|
type, |
|
|
|
create_at AS createTime, |
|
|
|
start_time AS startTime, |
|
|
|
end_time AS endTime, |
|
|
|
duration, |
|
|
|
reason, |
|
|
|
wpStory.id AS storyId |
|
|
|
FROM |
|
|
|
vacate |
|
|
|
INNER JOIN ${pepEmis}.workflow_process_history AS wpStory |
|
|
|
ON wpStory.id = vacate.pep_process_story_id |
|
|
|
${timeOption.length ? `AND ${timeOption.join(' AND ')}` : ''} |
|
|
|
WHERE vacate.pep_user_id = ${pepUserId} |
|
|
|
`).toPromise()
|
|
|
|
|
|
|
|
const statisticRes = await clickHouse.hr.query(` |
|
|
|
SELECT |
|
|
|
type, |
|
|
|
count(vacate.id) AS count, |
|
|
|
sum(duration) AS sumDuration |
|
|
|
FROM |
|
|
|
vacate |
|
|
|
INNER JOIN ${pepEmis}.workflow_process_history AS wpStory |
|
|
|
ON wpStory.id = vacate.pep_process_story_id |
|
|
|
${timeOption.length ? `AND ${timeOption.join(' AND ')}` : ''} |
|
|
|
WHERE vacate.pep_user_id = ${pepUserId} |
|
|
|
GROUP BY type |
|
|
|
`).toPromise()
|
|
|
|
|
|
|
|
let returnD = { |
|
|
|
statistic: statisticRes, |
|
|
|
data: dataRes |
|
|
|
} |
|
|
|
ctx.status = 200; |
|
|
|
ctx.body = 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 exportData (ctx) { |
|
|
|
try { |
|
|
|
const { models } = ctx.fs.dc; |
|
|
|
|
|
|
|
ctx.status = 20; |
|
|
|
} catch (error) { |
|
|
|
ctx.fs.logger.error(`path: ${ctx.path}, error: error`); |
|
|
|
ctx.status = 400; |
|
|
|
ctx.body = { |
|
|
|
message: typeof error == 'string' ? error : undefined |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
module.exports = { |
|
|
|
add, |
|
|
|
edit, |
|
|
|
del, |
|
|
|
searchPepMember, |
|
|
|
list, |
|
|
|
overTimeStatistics, |
|
|
|
vacateStatistics, |
|
|
|
exportData, |
|
|
|
}; |