From cb26cbeb1697b577dbffba09f81c3336e6769123 Mon Sep 17 00:00:00 2001 From: zhangminghua Date: Thu, 1 Dec 2022 16:07:13 +0800 Subject: [PATCH] =?UTF-8?q?(*)=E5=90=88=E5=90=8C=E6=98=8E=E7=BB=86?= =?UTF-8?q?=E5=AF=BC=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/app/lib/controllers/report/achievement.js | 32 ++++++++++++++++++- api/app/lib/routes/report/index.js | 3 ++ api/app/lib/utils/xlsxDownload.js | 18 +++++++---- .../performanceReport/contractDetails.jsx | 2 +- .../performanceReport/invoicingDetails.jsx | 2 +- 5 files changed, 47 insertions(+), 10 deletions(-) diff --git a/api/app/lib/controllers/report/achievement.js b/api/app/lib/controllers/report/achievement.js index 80090f3..d6faa95 100644 --- a/api/app/lib/controllers/report/achievement.js +++ b/api/app/lib/controllers/report/achievement.js @@ -310,9 +310,39 @@ async function getInvoicingDetail(ctx) { ctx.body = { name: 'FindError', message: '查询开票明细表数据失败' } } } + +/** + * 导出合同明细表数据 + */ +async function exportContractDetail(ctx) { + try { + const { models } = ctx.fs.dc; + let exportData = await models.ContractDetail.findAll({ + order: [['id', 'DESC']] + }); + const { utils: { simpleExcelDown, contractDetailsColumnKeys } } = ctx.app.fs; + let header = []; + Object.keys(contractDetailsColumnKeys).map(key => { + header.push({ title: contractDetailsColumnKeys[key], key: key }); + }) + const fileName = `合同明细表_${moment().format('YYYYMMDDHHmmss')}` + '.xlsx' + const filePath = await simpleExcelDown({ data: exportData, header, fileName: fileName, needIndexCell: false }) + 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 = { name: 'ExportAllError', message: '导出合同明细表数据失败' } + } +} + module.exports = { getReceivedDetail,//回款 getAchievementDetail,//业绩 getContractDetail, - getInvoicingDetail + getInvoicingDetail, + exportContractDetail } \ No newline at end of file diff --git a/api/app/lib/routes/report/index.js b/api/app/lib/routes/report/index.js index 59cab38..22f6b33 100644 --- a/api/app/lib/routes/report/index.js +++ b/api/app/lib/routes/report/index.js @@ -21,4 +21,7 @@ module.exports = function (app, router, opts) { app.fs.api.logAttr['GET/invoicing/detail'] = { content: '查询开票明细表', visible: false }; router.get('/invoicing/detail', achieve.getInvoicingDetail); + + app.fs.api.logAttr['GET/export/contract/detail'] = { content: '导出合同明细表', visible: false }; + router.get('/export/contract/detail', achieve.exportContractDetail); }; \ No newline at end of file diff --git a/api/app/lib/utils/xlsxDownload.js b/api/app/lib/utils/xlsxDownload.js index 1aa03e7..c52d445 100644 --- a/api/app/lib/utils/xlsxDownload.js +++ b/api/app/lib/utils/xlsxDownload.js @@ -19,7 +19,7 @@ module.exports = function (app, opts) { } } - async function simpleExcelDown({ data = [], header = [], fileName = moment().format('YYYY-MM-DD HH:mm:ss') } = {}) { + async function simpleExcelDown({ data = [], header = [], fileName = moment().format('YYYY-MM-DD HH:mm:ss'), needIndexCell = true } = {}) { const fileDirPath = path.join(__dirname, `../../downloadFiles`) makeDir(fileDirPath) const file = new xlsx.File(); @@ -35,9 +35,11 @@ module.exports = function (app, opts) { headerStyle.border.bottomColor = '#000000'; const headerRow = sheet_1.addRow(); - const indexCell = headerRow.addCell(); - indexCell.value = '序号' - indexCell.style = headerStyle + if (needIndexCell) { + const indexCell = headerRow.addCell(); + indexCell.value = '序号' + indexCell.style = headerStyle + } for (let h of header) { const cell = headerRow.addCell(); cell.value = h.title; @@ -54,9 +56,11 @@ module.exports = function (app, opts) { style.border.bottomColor = '#000000'; for (let i = 0; i < data.length; i++) { const row = sheet_1.addRow(); - const indexCell = row.addCell(); - indexCell.value = i + 1 - indexCell.style = headerStyle + if (needIndexCell) { + const indexCell = row.addCell(); + indexCell.value = i + 1 + indexCell.style = headerStyle + } for (let h of header) { const cell = row.addCell(); cell.value = data[i][h.key] || h.defaultValue || '-'; diff --git a/web/client/src/sections/business/containers/performanceReport/contractDetails.jsx b/web/client/src/sections/business/containers/performanceReport/contractDetails.jsx index ba5c6c5..e76512c 100644 --- a/web/client/src/sections/business/containers/performanceReport/contractDetails.jsx +++ b/web/client/src/sections/business/containers/performanceReport/contractDetails.jsx @@ -9,7 +9,7 @@ import '../../style.less'; import moment from 'moment' const ContractDetails = (props) => { - const { dispatch, actions } = props + const { dispatch, actions, user } = props const { businessManagement } = actions; const [keywordTarget, setKeywordTarget] = useState('contractNo'); const [keyword, setKeyword] = useState('');//搜索内容 diff --git a/web/client/src/sections/business/containers/performanceReport/invoicingDetails.jsx b/web/client/src/sections/business/containers/performanceReport/invoicingDetails.jsx index 851ae5c..c5686ff 100644 --- a/web/client/src/sections/business/containers/performanceReport/invoicingDetails.jsx +++ b/web/client/src/sections/business/containers/performanceReport/invoicingDetails.jsx @@ -9,7 +9,7 @@ import '../../style.less'; import moment from 'moment' const InvoicingDetails = (props) => { - const { dispatch, actions } = props + const { dispatch, actions, user } = props const { businessManagement } = actions; const [keywordTarget, setKeywordTarget] = useState('contractNo'); const [keyword, setKeyword] = useState('');//搜索内容