Commit 31d567a3 authored by wujipeng's avatar wujipeng
Browse files

解析excel优化

parent 258d646a
...@@ -24,4 +24,6 @@ public interface ExcelTemplateMapper extends BaseMapper<ExcelTemplateEntity> { ...@@ -24,4 +24,6 @@ public interface ExcelTemplateMapper extends BaseMapper<ExcelTemplateEntity> {
* @return List<ExcelTemplateVO> * @return List<ExcelTemplateVO>
*/ */
List<ExcelTemplateVO> pageExcelTemplate(ExcelTemplateDTO excelTemplateDTO); List<ExcelTemplateVO> pageExcelTemplate(ExcelTemplateDTO excelTemplateDTO);
ExcelTemplateEntity getMaxId();
} }
...@@ -12,4 +12,6 @@ import java.util.List; ...@@ -12,4 +12,6 @@ import java.util.List;
public interface UserMapper extends BaseMapper<UserEntity> { public interface UserMapper extends BaseMapper<UserEntity> {
List<ExcelDataVO> queryUserLabel(@Param("userNameList") List<String> userNameList, List<ExcelDataVO> queryUserLabel(@Param("userNameList") List<String> userNameList,
@Param("caseId") Integer id); @Param("caseId") Integer id);
void saveUserBatch(@Param("userList") List<UserEntity> userList);
} }
...@@ -46,4 +46,10 @@ public interface ExcelTemplateService extends IService<ExcelTemplateEntity> { ...@@ -46,4 +46,10 @@ public interface ExcelTemplateService extends IService<ExcelTemplateEntity> {
* @return Boolean * @return Boolean
*/ */
Boolean importExcel(MultipartFile file); Boolean importExcel(MultipartFile file);
/**
* 获取最大id
* @return ExcelTemplateEntity
*/
ExcelTemplateEntity getMaxId();
} }
...@@ -40,4 +40,6 @@ public interface UserService extends IService<UserEntity> { ...@@ -40,4 +40,6 @@ public interface UserService extends IService<UserEntity> {
Boolean relationSaveOrUpdate(List<UserRelationEntity> userRelationList); Boolean relationSaveOrUpdate(List<UserRelationEntity> userRelationList);
List<ExcelDataVO> queryUserLabel(List<String> userNameList, Integer id); List<ExcelDataVO> queryUserLabel(List<String> userNameList, Integer id);
void saveUserBatch(List<UserEntity> userList);
} }
package com.platform.service.impl; package com.platform.service.impl;
import com.alibaba.fastjson.JSON;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.platform.exception.BusinessException; import com.platform.exception.BusinessException;
import com.platform.model.entity.ExcelDataEntity; import com.platform.model.entity.ExcelDataEntity;
import com.platform.model.entity.ExcelTemplateEntity;
import com.platform.model.entity.UserAccountEntity; import com.platform.model.entity.UserAccountEntity;
import com.platform.model.entity.UserEntity; import com.platform.model.entity.UserEntity;
import com.platform.model.resp.Result; import com.platform.model.resp.Result;
...@@ -56,8 +58,6 @@ public class AnalysisServiceImpl implements AnalysisService { ...@@ -56,8 +58,6 @@ public class AnalysisServiceImpl implements AnalysisService {
private UserService userService; private UserService userService;
@Resource @Resource
private UserAccountService userAccountService; private UserAccountService userAccountService;
@Resource
private CasesService caseService;
private static final String[] EXCEL_EXTENSIONS = {".xlsx", ".xls"}; private static final String[] EXCEL_EXTENSIONS = {".xlsx", ".xls"};
...@@ -65,37 +65,32 @@ public class AnalysisServiceImpl implements AnalysisService { ...@@ -65,37 +65,32 @@ public class AnalysisServiceImpl implements AnalysisService {
@Transactional @Transactional
public Result<?> canvas(List<MultipartFile> files, int caseId, String folderName) { public Result<?> canvas(List<MultipartFile> files, int caseId, String folderName) {
//查询模板 //查询模板
// CasesEntity caseEntity = caseService.getById(caseId); ExcelTemplateEntity ExcelTemplate = excelTemplateService.getMaxId();
// String templateId = caseEntity.getTemplateId(); List<TableHeaderVO> tableHeaderList;
// if(StringUtils.isEmpty(templateId)){ if (ObjectUtils.isEmpty(ExcelTemplate)) {
// throw new BusinessException("案件未绑定模板"); //默认模板
// } tableHeaderList = Lists.newArrayList();
// ExcelTemplateEntity ExcelTemplate = excelTemplateService.getById(templateId); tableHeaderList.add(TableHeaderVO.builder().name("交易类型").index(2).filter(false).build());
// String json = ExcelTemplate.getJson(); tableHeaderList.add(TableHeaderVO.builder().name("交易主体的出入账标识").index(4).filter(false).build());
// List<TableHeaderVO> tableHeaderList = JSON.parseArray(json, TableHeaderVO.class); tableHeaderList.add(TableHeaderVO.builder().name("交易时间").index(5).filter(false).build());
// if (ObjectUtils.isEmpty(ExcelTemplate)) { tableHeaderList.add(TableHeaderVO.builder().name("交易金额").index(7).filter(false).build());
// return Result.fail("模板不存在"); tableHeaderList.add(TableHeaderVO.builder().name("交易流水号").index(8).filter(false).build());
// } tableHeaderList.add(TableHeaderVO.builder().name("收款方银行卡所属银行卡号").index(12).filter(false).build());
boolean flag = false; tableHeaderList.add(TableHeaderVO.builder().name("收款方的支付帐号").index(13).filter(false).build());
//默认模板 tableHeaderList.add(TableHeaderVO.builder().name("收款方的商户号").index(15).filter(false).build());
List<TableHeaderVO> tableHeaderList = Lists.newArrayList(); tableHeaderList.add(TableHeaderVO.builder().name("收款方的商户名称").index(16).filter(false).build());
tableHeaderList.add(TableHeaderVO.builder().name("交易类型").index(2).filter(false).build()); tableHeaderList.add(TableHeaderVO.builder().name("付款方银行卡所属银行名称").index(18).filter(false).build());
tableHeaderList.add(TableHeaderVO.builder().name("交易主体的出入账标识").index(4).filter(false).build()); tableHeaderList.add(TableHeaderVO.builder().name("付款方银行卡所属银行卡号").index(19).filter(false).build());
tableHeaderList.add(TableHeaderVO.builder().name("交易时间").index(5).filter(false).build()); tableHeaderList.add(TableHeaderVO.builder().name("付款方的支付帐号").index(20).filter(false).build());
tableHeaderList.add(TableHeaderVO.builder().name("交易金额").index(7).filter(false).build()); tableHeaderList.add(TableHeaderVO.builder().name("交易支付设备ip").index(22).filter(false).build());
tableHeaderList.add(TableHeaderVO.builder().name("交易流水号").index(8).filter(false).build()); tableHeaderList.add(TableHeaderVO.builder().name("mac地址").index(23).filter(false).build());
tableHeaderList.add(TableHeaderVO.builder().name("收款方银行卡所属银行卡号").index(12).filter(false).build()); tableHeaderList.add(TableHeaderVO.builder().name("银行外部渠道交易流水号").index(27).filter(false).build());
tableHeaderList.add(TableHeaderVO.builder().name("收款方的支付帐号").index(13).filter(false).build()); tableHeaderList.add(TableHeaderVO.builder().name("支付帐号").index(29).filter(false).build());
tableHeaderList.add(TableHeaderVO.builder().name("收款方的商户号").index(15).filter(false).build()); tableHeaderList.add(TableHeaderVO.builder().name("备注").index(30).filter(false).build());
tableHeaderList.add(TableHeaderVO.builder().name("收款方的商户名称").index(16).filter(false).build()); } else {
tableHeaderList.add(TableHeaderVO.builder().name("付款方银行卡所属银行名称").index(18).filter(false).build()); String json = ExcelTemplate.getJson();
tableHeaderList.add(TableHeaderVO.builder().name("付款方银行卡所属银行卡号").index(19).filter(false).build()); tableHeaderList = JSON.parseArray(json, TableHeaderVO.class);
tableHeaderList.add(TableHeaderVO.builder().name("付款方的支付帐号").index(20).filter(false).build()); }
tableHeaderList.add(TableHeaderVO.builder().name("交易支付设备ip").index(22).filter(false).build());
tableHeaderList.add(TableHeaderVO.builder().name("mac地址").index(23).filter(false).build());
tableHeaderList.add(TableHeaderVO.builder().name("银行外部渠道交易流水号").index(27).filter(false).build());
tableHeaderList.add(TableHeaderVO.builder().name("支付帐号").index(29).filter(false).build());
tableHeaderList.add(TableHeaderVO.builder().name("备注").index(30).filter(false).build());
if (files.isEmpty()) { if (files.isEmpty()) {
return Result.fail("上传的文件为空"); return Result.fail("上传的文件为空");
...@@ -135,8 +130,9 @@ public class AnalysisServiceImpl implements AnalysisService { ...@@ -135,8 +130,9 @@ public class AnalysisServiceImpl implements AnalysisService {
//把tableHeaderList中filter为true索引组成一个数字类型的集合 //把tableHeaderList中filter为true索引组成一个数字类型的集合
List<Integer> filterIndex = tableHeaderList.stream().filter(TableHeaderVO::getFilter).map(TableHeaderVO::getIndex).collect(Collectors.toList()); List<Integer> filterIndex = tableHeaderList.stream().filter(TableHeaderVO::getFilter).map(TableHeaderVO::getIndex).collect(Collectors.toList());
Map<String, ExcelDataEntity> excelDataMap = Maps.newHashMap(); Map<String, ExcelDataEntity> excelDataMap = Maps.newHashMap();
List<UserEntity> userList = Lists.newArrayList();
//保存excel数据,判断是否使用默认模板 //保存excel数据,判断是否使用默认模板
if (flag) { if (ObjectUtils.isEmpty(ExcelTemplate)) {
List<ExcelDataEntity> afterDeduplication = Lists.newArrayList(); List<ExcelDataEntity> afterDeduplication = Lists.newArrayList();
for (ExcelDataEntity excelDatum : excelData) { for (ExcelDataEntity excelDatum : excelData) {
StringBuilder key = new StringBuilder(); StringBuilder key = new StringBuilder();
...@@ -161,6 +157,17 @@ public class AnalysisServiceImpl implements AnalysisService { ...@@ -161,6 +157,17 @@ public class AnalysisServiceImpl implements AnalysisService {
(key, excelDatum) -> afterDeduplication.add(excelDatum) (key, excelDatum) -> afterDeduplication.add(excelDatum)
); );
excelDataService.saveBatch(afterDeduplication); excelDataService.saveBatch(afterDeduplication);
//保存无主用户
//afterDeduplication转换成payeeName的字符串集合并去重
List<String> payeeNameList = afterDeduplication.stream().map(ExcelDataEntity::getPayeeName).distinct().collect(Collectors.toList());
for (String s : payeeNameList) {
userList.add(UserEntity.builder()
.userName(s)
.caseId(caseId)
.type("2")
.build());
}
userService.saveUserBatch(userList);
} else { } else {
excelDataService.saveBatch(excelData); excelDataService.saveBatch(excelData);
} }
...@@ -168,10 +175,18 @@ public class AnalysisServiceImpl implements AnalysisService { ...@@ -168,10 +175,18 @@ public class AnalysisServiceImpl implements AnalysisService {
String userName = trimChineseNameFromFilename(folderName); String userName = trimChineseNameFromFilename(folderName);
groupedMap.forEach((paymentAccount, paymentBankName) -> userAccountList.add(UserAccountEntity.builder().userName(userName).account(paymentBankName).caseId(caseId).code(paymentAccount).build())); groupedMap.forEach((paymentAccount, paymentBankName) -> userAccountList.add(UserAccountEntity.builder().userName(userName).account(paymentBankName).caseId(caseId).code(paymentAccount).build()));
userAccountService.saveUserBatch(userAccountList); userAccountService.saveUserBatch(userAccountList);
//保存用户
if (StringUtils.isNotEmpty(folderName)) { if (StringUtils.isNotEmpty(folderName)) {
Map<String, String> idCardInfo = IdCardUtils.parseIdCardInfo(folderName); Map<String, String> idCardInfo = IdCardUtils.parseIdCardInfo(folderName);
if (!ObjectUtils.isEmpty(idCardInfo)) { if (!ObjectUtils.isEmpty(idCardInfo)) {
userService.save(UserEntity.builder().userName(userName).age(Integer.parseInt(idCardInfo.get("age"))).idCard(idCardInfo.get("idCard")).sex(idCardInfo.get("sex")).idType("身份证").caseId(caseId).build()); userService.save(UserEntity.builder()
.userName(userName + idCardInfo.get("idCard"))
.age(Integer.parseInt(idCardInfo.get("age")))
.idCard(idCardInfo.get("idCard"))
.sex(idCardInfo.get("sex"))
.idType("身份证")
.type("1")
.caseId(caseId).build());
} }
} }
if (errorCount == 0) { if (errorCount == 0) {
...@@ -207,8 +222,11 @@ public class AnalysisServiceImpl implements AnalysisService { ...@@ -207,8 +222,11 @@ public class AnalysisServiceImpl implements AnalysisService {
trySetValue(() -> excelDataEntity.setPayAccount(getCellValueAsString(row.getCell(tableHeaderList.get(15).getIndex())))); trySetValue(() -> excelDataEntity.setPayAccount(getCellValueAsString(row.getCell(tableHeaderList.get(15).getIndex()))));
trySetValue(() -> excelDataEntity.setRemark(getCellValueAsString(row.getCell(tableHeaderList.get(16).getIndex())))); trySetValue(() -> excelDataEntity.setRemark(getCellValueAsString(row.getCell(tableHeaderList.get(16).getIndex()))));
if (StringUtils.isNotEmpty(folderName)) { if (StringUtils.isNotEmpty(folderName)) {
//切割文件名前面是中文的人名,使用正则表达式 Map<String, String> idCardInfo = IdCardUtils.parseIdCardInfo(folderName);
trySetValue(() -> excelDataEntity.setPayUserName(trimChineseNameFromFilename(folderName))); if (!ObjectUtils.isEmpty(idCardInfo)) {
//切割文件名前面是中文的人名,使用正则表达式
trySetValue(() -> excelDataEntity.setPayUserName(trimChineseNameFromFilename(folderName) + idCardInfo.get("idCard")));
}
} }
excelDataEntity.setFileId(fileId); excelDataEntity.setFileId(fileId);
excelDataEntity.setUseFlag(true); excelDataEntity.setUseFlag(true);
......
...@@ -275,4 +275,9 @@ public class ExcelTemplateServiceImpl extends ServiceImpl<ExcelTemplateMapper, E ...@@ -275,4 +275,9 @@ public class ExcelTemplateServiceImpl extends ServiceImpl<ExcelTemplateMapper, E
return defaultValue; return defaultValue;
} }
} }
@Override
public ExcelTemplateEntity getMaxId() {
return baseMapper.getMaxId();
}
} }
...@@ -296,4 +296,9 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserEntity> impleme ...@@ -296,4 +296,9 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserEntity> impleme
} }
return baseMapper.queryUserLabel(userNameList, id); return baseMapper.queryUserLabel(userNameList, id);
} }
@Override
public void saveUserBatch(List<UserEntity> userList) {
baseMapper.saveUserBatch(userList);
}
} }
...@@ -17,4 +17,15 @@ ...@@ -17,4 +17,15 @@
</if> </if>
</where> </where>
</select> </select>
<select id="getMaxId" resultType="com.platform.model.entity.ExcelTemplateEntity">
select
id,
name,
json,
all_header
from
excel_template
order by id desc
limit 1
</select>
</mapper> </mapper>
...@@ -2,6 +2,13 @@ ...@@ -2,6 +2,13 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.platform.mapper.UserMapper"> <mapper namespace="com.platform.mapper.UserMapper">
<insert id="saveUserBatch">
INSERT IGNORE INTO user (case_id, user_name, type)
VALUES
<foreach collection="userList" item="user" separator=",">
(#{user.caseId}, #{user.userName}, #{user.type})
</foreach>
</insert>
<select id="queryUserLabel" resultType="com.platform.model.vo.ExcelDataVO"> <select id="queryUserLabel" resultType="com.platform.model.vo.ExcelDataVO">
SELECT SELECT
......
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