Commit f766d49d authored by wujipeng's avatar wujipeng
Browse files

解析excel优化

parent dec1e42a
...@@ -128,24 +128,31 @@ public class AnalysisServiceImpl implements AnalysisService { ...@@ -128,24 +128,31 @@ 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 = Lists.newArrayList();
for (TableHeaderVO tableHeaderVO : tableHeaderList) {
if (!ObjectUtils.isEmpty(tableHeaderVO) && !ObjectUtils.isEmpty(tableHeaderVO.getFilter()) && tableHeaderVO.getFilter()) {
filterIndex.add(tableHeaderVO.getIndex());
}
}
Map<String, ExcelDataEntity> excelDataMap = Maps.newHashMap(); Map<String, ExcelDataEntity> excelDataMap = Maps.newHashMap();
List<UserEntity> userList = Lists.newArrayList(); List<UserEntity> userList = Lists.newArrayList();
//保存excel数据,判断是否使用默认模板 //保存excel数据,判断是否使用默认模板
if (ObjectUtils.isEmpty(ExcelTemplate)) { 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();
for (Integer index : filterIndex) { for (Integer index : filterIndex) {
Field field = AnnotationUtils.findFieldByNumericValue(excelDatum, index); Field field = AnnotationUtils.findFieldByNumericValue(excelDatum, index);
if (field != null) { if (field != null) {
// 获取getter方法
Method getter = AnnotationUtils.findGetterMethod(field, excelDatum.getClass()); Method getter = AnnotationUtils.findGetterMethod(field, excelDatum.getClass());
if (getter != null) { if (getter != null) {
// 调用getter方法获取值
try { try {
key.append((String) getter.invoke(excelDatum)); Object value = getter.invoke(excelDatum);
if (value != null) {
key.append(value);
}
} catch (IllegalAccessException | InvocationTargetException ignored) { } catch (IllegalAccessException | InvocationTargetException ignored) {
// 异常处理(建议至少记录日志)
} }
} }
} }
...@@ -170,6 +177,17 @@ public class AnalysisServiceImpl implements AnalysisService { ...@@ -170,6 +177,17 @@ public class AnalysisServiceImpl implements AnalysisService {
userService.saveUserBatch(userList); userService.saveUserBatch(userList);
} else { } else {
excelDataService.saveBatch(excelData); excelDataService.saveBatch(excelData);
//保存无主用户
//afterDeduplication转换成payeeName的字符串集合并去重
List<String> payeeNameList = excelData.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);
} }
//保存账户 //保存账户
String userName = trimChineseNameFromFilename(folderName); String userName = trimChineseNameFromFilename(folderName);
......
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