'use strict'; 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, 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 } } } async function vacateStatistic (ctx) { try { const { models } = ctx.fs.dc; const { clickHouse } = ctx.app.fs const { judgeHoliday, memberList, packageUserData, vacateStatisticListDayType } = 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, vacateDayStatisticStartDate: startDate, vacateDayStatisticendDate: endDate, vacateDurationStatistic: true, vacateCountStatistic: true, vacateCountStatisticStartDate: startDate, vacateCountStatisticendDate: endDate, }) let { packageUser: returnD, pepUserIds } = await packageUserData(userRes) const sumRes = await vacateStatisticListDayType({ startDate, endDate, pepUserIds }) 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, vacateStatistic, };