Commit 1b084492 by kangxiaoshan

修改提示

parent 174f5525
...@@ -47,8 +47,7 @@ public class DmpIncomeController { ...@@ -47,8 +47,7 @@ public class DmpIncomeController {
@PostMapping("/upload") @PostMapping("/upload")
public ResultModel uploadList(@RequestParam("file") MultipartFile file, @CurrentAccount User loginAccount) { public ResultModel uploadList(@RequestParam("file") MultipartFile file, @CurrentAccount User loginAccount) {
//上传收入数据 //上传收入数据
dmpIncomeService.uploadFile(file, "dmp", loginAccount); return dmpIncomeService.uploadFile(file, "dmp", loginAccount);
return ResultModel.OK();
} }
......
...@@ -201,30 +201,37 @@ public class DmpIncomeServiceImpl implements DmpIncomeService { ...@@ -201,30 +201,37 @@ public class DmpIncomeServiceImpl implements DmpIncomeService {
Sheet sheet = workbook.getSheetAt(0); Sheet sheet = workbook.getSheetAt(0);
DecimalFormat df = new DecimalFormat("##,##0.00"); DecimalFormat df = new DecimalFormat("##,##0.00");
CompletableFuture.runAsync(() -> { StringBuffer erroMessage = new StringBuffer();
StopWatch stopWatch = new StopWatch(); StopWatch stopWatch = new StopWatch();
stopWatch.start(); stopWatch.start();
ExecutorService executorService = Executors.newFixedThreadPool(30); ExecutorService executorService = Executors.newFixedThreadPool(30);
CompletableFuture[] futures = Stream.iterate(1, n -> n + 1).limit(rowNumber - 1).map(index -> CompletableFuture[] futures = Stream.iterate(1, n -> n + 1).limit(rowNumber - 1).map(index ->
CompletableFuture.runAsync( CompletableFuture.runAsync(
() -> { () -> {
DmpIncome income = saveDmpIncomeItem(sheet, index, loginAccount); DmpIncome income = saveDmpIncomeItem(sheet, index, loginAccount);
if (income != null) {
if (income != null) {
if ("erro".equals(income.getIncomeMonth())) {
erroMessage.append(index).append(" 行 收入月份错误").append(";\n");
} else {
income.setConfirmSettlement(new BigDecimal(income.getConfirmSettlement()).setScale(2, BigDecimal.ROUND_HALF_UP).toString()); income.setConfirmSettlement(new BigDecimal(income.getConfirmSettlement()).setScale(2, BigDecimal.ROUND_HALF_UP).toString());
dmpIncomeRepository.save(income); dmpIncomeRepository.save(income);
} }
}, executorService) }
.exceptionally((t) -> { }, executorService)
logger.error("the line " + index, t); .exceptionally((t) -> {
return null; erroMessage.append(index).append(" 行 错误").append(t.getMessage()).append(";\n");
}) logger.error("the line " + index, t);
).toArray(size -> new CompletableFuture[size]); return null;
CompletableFuture.allOf(futures).join(); })
executorService.shutdownNow(); ).toArray(size -> new CompletableFuture[size]);
stopWatch.stop(); CompletableFuture.allOf(futures).join();
logger.info("dmp income upload {} line data use all {}s ", rowNumber - 1, stopWatch.getTotalTimeSeconds()); executorService.shutdownNow();
}); stopWatch.stop();
logger.info("dmp income upload {} line data use all {}s ", rowNumber - 1, stopWatch.getTotalTimeSeconds());
if (erroMessage.length() > 0) {
return ResultModel.ERROR(erroMessage.toString());
}
return ResultModel.OK(); return ResultModel.OK();
} }
...@@ -488,13 +495,11 @@ public class DmpIncomeServiceImpl implements DmpIncomeService { ...@@ -488,13 +495,11 @@ public class DmpIncomeServiceImpl implements DmpIncomeService {
private String getCellDateValue(Row row, int index, String fm) { private String getCellDateValue(Row row, int index, String fm) {
Cell cell = row.getCell(index); Cell cell = row.getCell(index);
if (cell == null) { if (cell == null) {
return "erro"; return "erro";
} }
String dfmate = cell.getCellStyle().getDataFormatString(); String dfmate = cell.getCellStyle().getDataFormatString();
if (!"yyyy/mm;@".equals(dfmate) && !"m/d/yy".equals(dfmate) && !"yy/m/d".equals(dfmate) && !"mm/dd/yy".equals(dfmate) && !"dd-mmm-yy".equals(dfmate) && !"yyyy/m/d".equals(dfmate) && !"yyyy/m/d;@".equals(dfmate) && !"yyyy\"年\"m\"月\";@".equals(dfmate)) { if (!"yyyy/mm;@".equals(dfmate) && !"m/d/yy".equals(dfmate) && !"yy/m/d".equals(dfmate) && !"mm/dd/yy".equals(dfmate) && !"dd-mmm-yy".equals(dfmate) && !"yyyy/m/d".equals(dfmate) && !"yyyy/m/d;@".equals(dfmate) && !"yyyy\"年\"m\"月\";@".equals(dfmate)) {
return "erro"; return "erro";
} }
...@@ -506,7 +511,6 @@ public class DmpIncomeServiceImpl implements DmpIncomeService { ...@@ -506,7 +511,6 @@ public class DmpIncomeServiceImpl implements DmpIncomeService {
if (org.apache.poi.ss.usermodel.DateUtil.isCellDateFormatted(cell)) { if (org.apache.poi.ss.usermodel.DateUtil.isCellDateFormatted(cell)) {
// 用于转化为日期格式 // 用于转化为日期格式
Date d = cell.getDateCellValue(); Date d = cell.getDateCellValue();
DateFormat formater = new SimpleDateFormat(fm); DateFormat formater = new SimpleDateFormat(fm);
return formater.format(d); return formater.format(d);
} }
......
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