From a7f20acb8efed95c875049b7e150d29f88074654 Mon Sep 17 00:00:00 2001 From: ww664853070 Date: Thu, 8 Dec 2022 15:07:02 +0800 Subject: [PATCH] =?UTF-8?q?(*)=E4=B8=9A=E7=BB=A9=E6=B1=87=E6=80=BB?= =?UTF-8?q?=E8=A1=A8=E5=AF=BC=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lib/controllers/salePerformance/index.js | 125 +++++++++++++++++- api/app/lib/routes/salePerformance/index.js | 7 +- .../business/actions/performanceSummary.js | 11 ++ .../src/sections/business/constants/index.js | 36 +++++ .../importPerformanceSummaryModal.jsx | 6 +- web/client/src/utils/webapi.js | 1 + web/package.json | 2 +- 7 files changed, 178 insertions(+), 10 deletions(-) diff --git a/api/app/lib/controllers/salePerformance/index.js b/api/app/lib/controllers/salePerformance/index.js index 0659c4d..cb7d47d 100644 --- a/api/app/lib/controllers/salePerformance/index.js +++ b/api/app/lib/controllers/salePerformance/index.js @@ -1,5 +1,18 @@ 'use strict'; - +const MONTH_CONVERSION = { + one: 1, + two: 2, + three: 3, + four: 4, + five: 5, + six: 6, + seven: 7, + eight: 8, + nine: 9, + ten: 10, + eleven: 11, + twelve: 12 +} // 查询业绩汇总表-->关联sale表 async function getSalePerformance(ctx, next) { const { type } = ctx.params; @@ -8,10 +21,9 @@ async function getSalePerformance(ctx, next) { try { rslt = await models.sale.findAll({ order: [['id', 'DESC']], - include:[{ - model:models.salePerformance + include: [{ + model: models.salePerformance }] - // where: { type: type } }) ctx.status = 200 ctx.body = rslt @@ -22,6 +34,111 @@ async function getSalePerformance(ctx, next) { } } +async function importSalePerformance(ctx) { + let errorMsg = { message: '导入业绩汇总失败' }; + const transaction = await ctx.fs.dc.orm.transaction(); + try { + const models = ctx.fs.dc.models; + const body = ctx.request.body; + let importData = []; + const imporNames = []; + for (let item of body) {//循环捞数据 + const { name, ...rest } = item; + const data = []; + imporNames.push(name); + Object.keys(rest).map(value => { + if (MONTH_CONVERSION[value.replace("ActualPerformance", "")]) { + const index = data.findIndex(d => d.month == MONTH_CONVERSION[value.replace("ActualPerformance", "")]); + if (index > -1) { + data[index].actualPerformance = item[value]; + } else { + data.push({ + saleName: item.name, + month: MONTH_CONVERSION[value.replace("ActualPerformance", "")], + actualPerformance: item[value] + }); + } + } else if (MONTH_CONVERSION[value.replace("AssessmentPerformance", "")]) { + const index = data.findIndex(d => d.month == MONTH_CONVERSION[value.replace("AssessmentPerformance", "")]); + if (index > -1) { + data[index].assessmentPerformance = item[value]; + } else { + data.push({ + saleName: item.name, + month: MONTH_CONVERSION[value.replace("AssessmentPerformance", "")], + assessmentPerformance: item[value] + }); + } + } else if (MONTH_CONVERSION[value.replace("Task", "")]) { + const index = data.findIndex(d => d.month == MONTH_CONVERSION[value.replace("Task", "")]); + if (index > -1) { + data[index].task = item[value]; + } else { + data.push({ + saleName: item.name, + month: MONTH_CONVERSION[value.replace("Task", "")], + task: item[value] + }); + } + } else if (MONTH_CONVERSION[value.replace("Amount", "")]) { + const index = data.findIndex(d => d.month == MONTH_CONVERSION[value.replace("Amount", "")]); + if (index > -1) { + data[index].amount = item[value]; + } else { + data.push({ + saleName: item.name, + month: MONTH_CONVERSION[value.replace("Amount", "")], + amount: item[value] + }); + } + } else { + + } + }) + if (data.length) { + importData = importData.concat(data); + } + } + + /**查出历史数据进行比对 + * 1. 比对是否存在的月份+销售名称 + * a. 存在:记录id(用于删除) + * b. 不存在,记录数据 + * 2. 批量删除记录的ids + * 3. 批量插入导入数据 + * + * PS:库里的数据以导入的数据为准(如果历史数据task字段有值,导入的数据该字段为空,即库里的task为空值) + */ + if (imporNames.length) { + const delDataIds = []; + const oldData = await models.salePerformance.findAll({ + //todo 待考虑加入年份比对 + where: { saleName: { $in: imporNames } } + }); + if (oldData.length) { + for (let old of oldData) { + if (importData.find(d => d.month == old.month && d.saleName == old.saleName)) { + delDataIds.push(old.id); + } + } + } + await models.salePerformance.destroy({ where: { id: { $in: delDataIds } }, transaction }); + + } + if (importData.length) + await models.salePerformance.bulkCreate(importData, { transaction }); + + await transaction.commit(); + ctx.status = 204; + } catch (error) { + await transaction.rollback(); + ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); + ctx.status = 400; + ctx.body = errorMsg; + } +} + module.exports = { getSalePerformance, + importSalePerformance, } \ No newline at end of file diff --git a/api/app/lib/routes/salePerformance/index.js b/api/app/lib/routes/salePerformance/index.js index a8889b0..eb9c00c 100644 --- a/api/app/lib/routes/salePerformance/index.js +++ b/api/app/lib/routes/salePerformance/index.js @@ -5,4 +5,9 @@ const report = require('../../controllers/salePerformance'); module.exports = function (app, router, opts) { app.fs.api.logAttr['GET/salePerformance'] = { content: '业绩汇总表', visible: false }; router.get('/salePerformance', report.getSalePerformance); -}; \ No newline at end of file + + app.fs.api.logAttr['POST/importSalePerformance'] = { content: '业绩汇总表', visible: true }; + router.post('/importSalePerformance', report.importSalePerformance); +}; + + diff --git a/web/client/src/sections/business/actions/performanceSummary.js b/web/client/src/sections/business/actions/performanceSummary.js index 7d2e6fb..40833ec 100644 --- a/web/client/src/sections/business/actions/performanceSummary.js +++ b/web/client/src/sections/business/actions/performanceSummary.js @@ -13,4 +13,15 @@ export function getPerformanceSummary() {//查询 }); } +export function importSalePerformance(values) { + return dispatch => basicAction({ + type: 'post', + dispatch: dispatch, + actionType: 'IMPORT_PERFORMANCE_SUMMARY', + url: ApiTable.importSalePerformance, + data: values, + msg: { option: '导入业绩汇总' }, + }); +} + diff --git a/web/client/src/sections/business/constants/index.js b/web/client/src/sections/business/constants/index.js index 0a8e0dd..d6de706 100644 --- a/web/client/src/sections/business/constants/index.js +++ b/web/client/src/sections/business/constants/index.js @@ -122,17 +122,53 @@ export const achievementColumnKeys = { } export const performanceSummaryKeys = { + oneAmount:'一月合同金额', + oneActualPerformance:'一月实际业绩', + oneAssessmentPerformance:'一月考核业绩', oneTask:'一月销售任务', + twoAmount:'二月合同金额', + twoActualPerformance:'二月实际业绩', + twoAssessmentPerformance:'二月考核业绩', twoTask:'二月销售任务', + threeAmount:'三月合同金额', + threeActualPerformance:'三月实际业绩', + threeAssessmentPerformance:'三月考核业绩', threeTask:'三月销售任务', + fourAmount:'四月合同金额', + fourActualPerformance:'四月实际业绩', + fourAssessmentPerformance:'四月考核业绩', fourTask:'四月销售任务', + fiveActualPerformance:'五月实际业绩', + fiveAssessmentPerformance:'五月考核业绩', fiveTask:'五月销售任务', + fiveAmount:'五月合同金额', + sixAmount:'六月合同金额', + sixActualPerformance:'六月实际业绩', + sixAssessmentPerformance:'六月考核业绩', sixTask:'六月销售任务', + sevenAmount:'七月合同金额', + sevenActualPerformance:'七月实际业绩', + sevenAssessmentPerformance:'七月考核业绩', sevenTask:'七月销售任务', + eightAmount:'八月合同金额', + eightActualPerformance:'八月实际业绩', + eightAssessmentPerformance:'八月考核业绩', eightTask:'八月销售任务', + nineAmount:'九月合同金额', + nineActualPerformance:'九月实际业绩', + nineAssessmentPerformance:'九月考核业绩', nineTask:'九月销售任务', + tenAmount:'十月合同金额', + tenActualPerformance:'十月实际业绩', + tenAssessmentPerformance:'十月考核业绩', tenTask:'十月销售任务', + elevenActualPerformance:'十一月实际业绩', + elevenAssessmentPerformance:'十一月考核业绩', elevenTask:'十一月销售任务', + elevenAmount:'十一月合同金额', + twelveAmount:'十二月合同金额', + twelveActualPerformance:'十二月实际业绩', + twelveAssessmentPerformance:'十二月考核业绩', twelveTask:'十二月销售任务', name:'销售人员' } \ No newline at end of file diff --git a/web/client/src/sections/business/containers/performanceReport/importPerformanceSummaryModal.jsx b/web/client/src/sections/business/containers/performanceReport/importPerformanceSummaryModal.jsx index d6482f7..9dafaf2 100644 --- a/web/client/src/sections/business/containers/performanceReport/importPerformanceSummaryModal.jsx +++ b/web/client/src/sections/business/containers/performanceReport/importPerformanceSummaryModal.jsx @@ -4,7 +4,7 @@ import { connect } from 'react-redux'; import moment from 'moment'; import { Modal, Form, Button, Notification } from '@douyinfe/semi-ui'; import { IconUpload } from '@douyinfe/semi-icons'; -import * as XLSX from 'xlsx' +import XLSX from 'xlsx' import { performanceSummaryKeys } from '../../constants/index'; //下载模板和上传文件读取 const ImportPerformanceSummaryModal = props => { @@ -16,11 +16,10 @@ const ImportPerformanceSummaryModal = props => { //初始化 useEffect(() => { }, []); - const confirm = () => { if (postData.length) { setLoading(true) - dispatch(businessManagement.importAchieveDetails(postData)).then(res => { + dispatch(businessManagement.importSalePerformance(postData)).then(res => { if (res.success) { onCancel() } @@ -68,7 +67,6 @@ const ImportPerformanceSummaryModal = props => { reader.readAsBinaryString(request.response); reader.onload = event => { try { - debugger const { result } = event.target; // 以二进制流方式读取得到整份excel表格对象 const workbook = XLSX.read(result, { diff --git a/web/client/src/utils/webapi.js b/web/client/src/utils/webapi.js index 3c87750..ef720d0 100644 --- a/web/client/src/utils/webapi.js +++ b/web/client/src/utils/webapi.js @@ -27,6 +27,7 @@ export const ApiTable = { getReceivedNumbers: 'detail/received/numbers', importBackDetails: 'add/received/back/bulk', importAchieveDetails: 'add/achievement/bulk', + importSalePerformance:'importSalePerformance', getContractDetail: 'contract/detail', getInvoicingDetail: 'invoicing/detail', diff --git a/web/package.json b/web/package.json index 5ef2a30..5c435ac 100644 --- a/web/package.json +++ b/web/package.json @@ -80,6 +80,6 @@ "webpack-dev-middleware": "^4.0.2", "webpack-dev-server": "^3.11.2", "webpack-hot-middleware": "^2.25.0", - "xlsx": "^0.18.5" + "xlsx": "^0.16.3" } }