人力资源
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.
 
 
 
 

68 lines
2.1 KiB

'use strict';
const moment = require('moment')
const request = require('superagent');
module.exports = function (app, opts) {
async function overtimeStatisticListDayType ({
startDate, endDate, pepUserIds = []
}) {
const { clickHouse } = app.fs
const sumRes = await clickHouse.hr.query(`
SELECT
overtime.pep_user_id AS pepUserId,
holiday.type AS dayType,
overtime.compensate AS compensate,
sum(overtime_day.duration) AS duration
FROM overtime_day
INNER JOIN overtime
ON overtime.id = overtime_day.overtime_id
AND overtime.pep_user_id IN (${pepUserIds.join(',')})
LEFT JOIN holiday
ON holiday.day = overtime_day.day
WHERE overtime.pep_user_id IN (${pepUserIds.join(',')})
${startDate ? `
AND overtime_day.day >= '${moment(startDate).format('YYYY-MM-DD')}'
`: ''}
${endDate ? `
AND overtime_day.day <= '${moment(endDate).format('YYYY-MM-DD')}'
` : ''}
GROUP BY holiday.type, overtime.compensate, overtime.pep_user_id
`).toPromise()
return sumRes
}
async function vacateStatisticListDayType ({
startDate, endDate, pepUserIds = []
}) {
const { clickHouse } = app.fs
const sumRes = await clickHouse.hr.query(`
SELECT
vacate.pep_user_id AS pepUserId,
vacate.type AS type,
sum(vacate_day.duration) AS duration
FROM vacate_day
INNER JOIN vacate
ON vacate.id = vacate_day.vacate_id
AND vacate.pep_user_id IN (${pepUserIds.join(',')})
WHERE vacate.pep_user_id IN (${pepUserIds.join(',')})
${startDate ? `
AND vacate_day.day >= '${moment(startDate).format('YYYY-MM-DD')}'
`: ''}
${endDate ? `
AND vacate_day.day <= '${moment(endDate).format('YYYY-MM-DD')}'
` : ''}
GROUP BY vacate.type, vacate.pep_user_id
`).toPromise()
return sumRes
}
return {
overtimeStatisticListDayType,
vacateStatisticListDayType,
}
}