Browse Source

(*)注释无用代码

master
wuqun 2 years ago
parent
commit
e96ba90aea
  1. 240
      api/app/lib/controllers/salesDistribution/index.js
  2. 4
      api/app/lib/routes/salesDistribution/index.js

240
api/app/lib/controllers/salesDistribution/index.js

@ -156,125 +156,125 @@ async function del(ctx) {
} }
} }
async function exportData(ctx) { // async function exportData(ctx) {
try { // try {
const { models } = ctx.fs.dc; // const { models } = ctx.fs.dc;
const { clickHouse, opts: { qiniu } } = ctx.app.fs // const { clickHouse, opts: { qiniu } } = ctx.app.fs
const { simpleExcelDown, memberList, packageUserData } = ctx.app.fs.utils // const { simpleExcelDown, memberList, packageUserData } = ctx.app.fs.utils
const { // const {
keywordTarget, keyword, limit, page, state, keys = '', // keywordTarget, keyword, limit, page, state, keys = '',
hiredateStart, hiredateEnd, marital, native, workPlace, // hiredateStart, hiredateEnd, marital, native, workPlace,
orderBy, orderDirection, // orderBy, orderDirection,
} = ctx.query // } = ctx.query
const userRes = await memberList({ // const userRes = await memberList({
keywordTarget, keyword, limit, page, state, // keywordTarget, keyword, limit, page, state,
hiredateStart, hiredateEnd, marital, native, workPlace, // hiredateStart, hiredateEnd, marital, native, workPlace,
orderBy, orderDirection, // orderBy, orderDirection,
nowAttendanceTime: true // nowAttendanceTime: true
}) // })
const tableAttributes = models['Member'].tableAttributes // const tableAttributes = models['Member'].tableAttributes
const optionKeys = keys.split(',') // const optionKeys = keys.split(',')
let { packageUser: exportD, pepUserIds } = await packageUserData(userRes) // let { packageUser: exportD, pepUserIds } = await packageUserData(userRes)
let preHeader = [{ // let preHeader = [{
title: '员工编号', // title: '员工编号',
key: 'userCode', // key: 'userCode',
}, { // }, {
title: '姓名', // title: '姓名',
key: 'userName', // key: 'userName',
}] // }]
let header = [].concat(preHeader) // let header = [].concat(preHeader)
for (let k in tableAttributes) { // for (let k in tableAttributes) {
const comment = tableAttributes[k].comment // const comment = tableAttributes[k].comment
if (k != 'id' && k != 'pepUserId' && comment) { // if (k != 'id' && k != 'pepUserId' && comment) {
if ([].includes(k)) { // if ([].includes(k)) {
// 截住不想导出的字段 // // 截住不想导出的字段
continue // continue
} // }
header.push({ // header.push({
title: comment || '-', // title: comment || '-',
key: k, // key: k,
// index: tableAttributes[k].index, // // index: tableAttributes[k].index,
}) // })
} // }
} // }
if (optionKeys.includes('overtimeStatistic')) { // if (optionKeys.includes('overtimeStatistic')) {
header = header.concat([{ // header = header.concat([{
title: '累计加班次数', // title: '累计加班次数',
key: 'overTimeCount', // key: 'overTimeCount',
}, { // }, {
title: '累计加班总时长 / h', // title: '累计加班总时长 / h',
key: 'overTimeDuration', // key: 'overTimeDuration',
},]) // },])
} // }
if (optionKeys.includes('vacateStatistic')) { // if (optionKeys.includes('vacateStatistic')) {
header = header.concat([{ // header = header.concat([{
title: '累计请假次数', // title: '累计请假次数',
key: 'vacateCount', // key: 'vacateCount',
}, { // }, {
title: '累计请假总时长 / h', // title: '累计请假总时长 / h',
key: 'vacateDuration', // key: 'vacateDuration',
},]) // },])
} // }
// 查询累计加班次数及总时长 // // 查询累计加班次数及总时长
const statisticOvertimeRes = await clickHouse.hr.query(` // const statisticOvertimeRes = await clickHouse.hr.query(`
SELECT // SELECT
pep_user_id AS pepUserId, // pep_user_id AS pepUserId,
count(id) AS count, // count(id) AS count,
sum(duration) AS duration // sum(duration) AS duration
FROM // FROM
overtime // overtime
WHERE pep_user_id IN (${pepUserIds.join(',')}) // WHERE pep_user_id IN (${pepUserIds.join(',')})
GROUP BY pep_user_id // GROUP BY pep_user_id
`).toPromise() // `).toPromise()
const statisticVacateRes = await clickHouse.hr.query(` // const statisticVacateRes = await clickHouse.hr.query(`
SELECT // SELECT
pep_user_id AS pepUserId, // pep_user_id AS pepUserId,
count(id) AS count, // count(id) AS count,
sum(duration) AS duration // sum(duration) AS duration
FROM // FROM
vacate // vacate
WHERE pep_user_id IN (${pepUserIds.join(',')}) // WHERE pep_user_id IN (${pepUserIds.join(',')})
GROUP BY pep_user_id // GROUP BY pep_user_id
`).toPromise() // `).toPromise()
exportD.forEach(d => { // exportD.forEach(d => {
d.departmrnt = d.departmrnt.map(dep => dep.name).join('、') // d.departmrnt = d.departmrnt.map(dep => dep.name).join('、')
d.role = d.role.map(r => r.name).join('、') // d.role = d.role.map(r => r.name).join('、')
d.idPhoto ? d.idPhoto = qiniu.domain + '/' + d.idPhoto : '' // d.idPhoto ? d.idPhoto = qiniu.domain + '/' + d.idPhoto : ''
d.vitae ? d.vitae = qiniu.domain + '/' + d.vitae : '' // d.vitae ? d.vitae = qiniu.domain + '/' + d.vitae : ''
const corOverTime = statisticOvertimeRes.find(so => so.pepUserId == d.pepUserId) // const corOverTime = statisticOvertimeRes.find(so => so.pepUserId == d.pepUserId)
d.overTimeCount = corOverTime ? corOverTime.count : 0 // d.overTimeCount = corOverTime ? corOverTime.count : 0
d.overTimeDuration = corOverTime ? (corOverTime.duration / 3600).toFixed(1) : 0 // d.overTimeDuration = corOverTime ? (corOverTime.duration / 3600).toFixed(1) : 0
const corVacate = statisticVacateRes.find(so => so.pepUserId == d.pepUserId) // const corVacate = statisticVacateRes.find(so => so.pepUserId == d.pepUserId)
d.vacateCount = corVacate ? corVacate.count : 0 // d.vacateCount = corVacate ? corVacate.count : 0
d.vacateDuration = corVacate ? (corVacate.duration / 3600).toFixed(1) : 0 // d.vacateDuration = corVacate ? (corVacate.duration / 3600).toFixed(1) : 0
}) // })
const fileName = `人员信息_${moment().format('YYYYMMDDHHmmss')}` + '.csv' // const fileName = `人员信息_${moment().format('YYYYMMDDHHmmss')}` + '.csv'
const filePath = await simpleExcelDown({ data: exportD, header, fileName: fileName }) // const filePath = await simpleExcelDown({ data: exportD, header, fileName: fileName })
const fileData = fs.readFileSync(filePath); // const fileData = fs.readFileSync(filePath);
ctx.status = 200; // ctx.status = 200;
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;
ctx.body = { // ctx.body = {
message: typeof error == 'string' ? error : undefined // message: typeof error == 'string' ? error : undefined
} // }
} // }
} // }
async function addSalesMemberBulk(ctx) { async function addSalesMemberBulk(ctx) {
let errorMsg = { message: '导入销售人员信息失败' }; let errorMsg = { message: '导入销售人员信息失败' };
@ -329,6 +329,6 @@ module.exports = {
add, add,
edit, edit,
del, del,
exportData, //exportData,
addSalesMemberBulk, addSalesMemberBulk,
} }

4
api/app/lib/routes/salesDistribution/index.js

@ -19,6 +19,6 @@ module.exports = function (app, router, opts) {
app.fs.api.logAttr['POST/add/sales/members/bulk'] = { content: '导入销售人员信息', visible: true }; app.fs.api.logAttr['POST/add/sales/members/bulk'] = { content: '导入销售人员信息', visible: true };
router.post('/add/sales/members/bulk', salesDistribution.addSalesMemberBulk); router.post('/add/sales/members/bulk', salesDistribution.addSalesMemberBulk);
app.fs.api.logAttr['GET/sales/members/export'] = { content: '导出销售人员信息', visible: true }; // app.fs.api.logAttr['GET/sales/members/export'] = { content: '导出销售人员信息', visible: true };
router.get('/sales/members/export', salesDistribution.exportData); // router.get('/sales/members/export', salesDistribution.exportData);
}; };
Loading…
Cancel
Save