Browse Source

(*)业绩汇总表导入

master
ww664853070 2 years ago
parent
commit
a7f20acb8e
  1. 125
      api/app/lib/controllers/salePerformance/index.js
  2. 7
      api/app/lib/routes/salePerformance/index.js
  3. 11
      web/client/src/sections/business/actions/performanceSummary.js
  4. 36
      web/client/src/sections/business/constants/index.js
  5. 6
      web/client/src/sections/business/containers/performanceReport/importPerformanceSummaryModal.jsx
  6. 1
      web/client/src/utils/webapi.js
  7. 2
      web/package.json

125
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,
}

7
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);
};
app.fs.api.logAttr['POST/importSalePerformance'] = { content: '业绩汇总表', visible: true };
router.post('/importSalePerformance', report.importSalePerformance);
};

11
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: '导入业绩汇总' },
});
}

36
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:'销售人员'
}

6
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, {

1
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',

2
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"
}
}

Loading…
Cancel
Save