Commit 45bd2ad2 authored by zhuxiang's avatar zhuxiang
Browse files

Merge remote-tracking branch 'origin/dev' into dev

parents 75c9f5e7 837109a0
......@@ -53,7 +53,7 @@ public class ExcelDataEntity {
@TableField("payee_bank_card")
private String payeeBankCard;
@ApiModelProperty("'收款方支付账号'")
@ApiModelProperty("收款方支付账号")
@TableField("payee_account")
private String payeeAccount;
......
package com.platform.service.impl;
import com.alibaba.fastjson.JSON;
import com.google.common.collect.Maps;
import com.platform.exception.BusinessException;
import com.platform.model.entity.*;
import com.platform.model.resp.Result;
......@@ -91,7 +92,7 @@ public class AnalysisServiceImpl implements AnalysisService {
tableHeaderList.add(TableHeaderVO.builder().name("支付帐号").index(29).build());
tableHeaderList.add(TableHeaderVO.builder().name("备注").index(30).build());
try {
if (files.size() == 0) {
return Result.fail("上传的文件为空");
}
......@@ -101,16 +102,27 @@ public class AnalysisServiceImpl implements AnalysisService {
List<AnalysisVO> detail = Lists.newArrayList();
int errorCount = 0;
int totalCount = 0;
Map<String, String> groupedMap = Maps.newHashMap();
List<UserAccountEntity> userAccountList = Lists.newArrayList();
for (MultipartFile file : files) {
// 检查是否是Excel文件
if (isExcelFile(file.getOriginalFilename())) {
FileUploadVO fileUploadVO = fileUploadService.uploadFile(file);
File tempFile = convertMultipartFileToFile(file);
processSingleExcelFile(tempFile, tableHeaderList, folderName, fileUploadVO.getId(), caseId);
File tempFile = null;
try {
tempFile = convertMultipartFileToFile(file);
} catch (IOException e) {
throw new BusinessException("文件转换错误");
}
try {
processSingleExcelFile(tempFile, tableHeaderList, folderName, fileUploadVO.getId(), caseId, userAccountList, groupedMap);
} catch (IOException e) {
throw new BusinessException("文件解析错误");
}
//文件上传
fileUploadList.add(fileUploadVO);
totalCount++;
}else {
} else {
errorCount++;
totalCount++;
detail.add(AnalysisVO.builder()
......@@ -120,8 +132,17 @@ public class AnalysisServiceImpl implements AnalysisService {
.build());
}
}
if (StringUtils.isNotEmpty(folderName)) {
//保存账户
String userName = trimChineseNameFromFilename(folderName);
groupedMap.forEach((paymentAccount, paymentBankName) ->
userAccountList.add(UserAccountEntity.builder()
.userName(userName)
.account(paymentBankName)
.caseId(caseId)
.code(paymentAccount)
.build()));
userAccountService.saveUserBatch(userAccountList);
if (StringUtils.isNotEmpty(folderName)) {
Map<String, String> idCardInfo = IdCardUtils.parseIdCardInfo(folderName);
if (!ObjectUtils.isEmpty(idCardInfo)) {
userService.save(UserEntity.builder().userName(userName)
......@@ -133,9 +154,9 @@ public class AnalysisServiceImpl implements AnalysisService {
.build());
}
}
if (errorCount == 0){
if (errorCount == 0) {
return Result.data(fileUploadList);
}else {
} else {
return Result.data(AnalysisVO.builder()
.folderCount(1)
.totalCount(totalCount)
......@@ -143,9 +164,6 @@ public class AnalysisServiceImpl implements AnalysisService {
.detail(detail)
.build());
}
} catch (Exception e) {
throw new BusinessException(e.getMessage());
}
}
private ExcelDataEntity handleExcelData(List<TableHeaderVO> tableHeaderList, Row row, String folderName, String fileId, String caseId) {
......@@ -250,7 +268,7 @@ public class AnalysisServiceImpl implements AnalysisService {
return false;
}
private void processSingleExcelFile(File excelFile, List<TableHeaderVO> tableHeaderList, String folderName, String fileId, String caseId) throws IOException {
private void processSingleExcelFile(File excelFile, List<TableHeaderVO> tableHeaderList, String folderName, String fileId, String caseId, List<UserAccountEntity> userAccountList, Map<String, String> groupedMap) throws IOException {
//读取第一个sheet
Sheet sheet = getWorkbook(excelFile).getSheetAt(0);
//获取sheet长度
......@@ -266,30 +284,18 @@ public class AnalysisServiceImpl implements AnalysisService {
}
if (StringUtils.isNotEmpty(folderName)) {
String userName = trimChineseNameFromFilename(folderName);
if (!excelData.isEmpty()) {
//excelData转化成以paymentAccount为键paymentBankName为值的map
Map<String, String> groupedMap = excelData.stream().collect(Collectors.toMap(ExcelDataEntity::getPaymentAccount, ExcelDataEntity::getPaymentBankName));
// List<String> paymentBankNames = excelData.stream().map(ExcelDataEntity::getPaymentBankName).distinct().collect(Collectors.toList());
List<UserAccountEntity> userAccountList = Lists.newArrayList();
// for (String paymentBankName : paymentBankNames) {
// userAccountList.add(UserAccountEntity.builder()
// .userName(userName)
// .account(paymentBankName)
// .caseId(caseId)
// .build());
// }
groupedMap.forEach((paymentAccount, paymentBankName) ->
userAccountList.add(UserAccountEntity.builder()
.userName(userName)
.account(paymentBankName)
.caseId(caseId)
.code(paymentAccount)
.build()));
userAccountService.saveUserBatch(userAccountList);
for (ExcelDataEntity excelDatum : excelData) {
if("出账".equals(excelDatum.getDirection())){
groupedMap.put(excelDatum.getPaymentAccount(), excelDatum.getPaymentBankName());
}else if("入账".equals(excelDatum.getDirection())){
groupedMap.put(excelDatum.getPayeeAccount(), excelDatum.getPayeeBankCard());
}
}
}
}
//保存excel数据
excelDataService.saveBatch(excelData);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment