Commit fcccdc70 by kangxiaoshan

修复dmp 收入上传

parent 1b084492
......@@ -38,9 +38,9 @@ public class DmpIncomeController {
}
@PostMapping("/delete")
public ResultModel deleteItem(Long id) {
public ResultModel deleteItem(@RequestBody DmpIncome dmpIncome) {
//删除数据
return ResultModel.OK(dmpIncomeService.delete(id));
return ResultModel.OK(dmpIncomeService.delete(dmpIncome));
}
......
......@@ -20,6 +20,7 @@ public class DmpIncome {
private Date createTime;
private Date modifyTime;
private String uploadUser;
private int index;
//contract_code, my_body_name, customer_body, customer_short, business_type, agreement_type
......@@ -164,4 +165,13 @@ public class DmpIncome {
public void setAgreementType(String agreementType) {
this.agreementType = agreementType;
}
@Transient
public int getIndex() {
return index;
}
public void setIndex(int index) {
this.index = index;
}
}
......@@ -16,4 +16,5 @@ public interface DmpIncomeRepository extends JpaRepository<DmpIncome, Long> {
@Query(value = "select * from dmp_income where contract_code = ?1 and income_month =?2 limit 1 ", nativeQuery = true)
DmpIncome findByCodeMonth(String contractCode, String incomeMonth);
}
......@@ -18,7 +18,7 @@ public interface DmpIncomeService {
DmpIncome update(DmpIncome dmpIncome);
Long delete(Long id);
Long delete(DmpIncome dmpIncome);
ResultModel uploadFile(MultipartFile file, String platform, User loginAccount);
......
......@@ -177,12 +177,12 @@ public class DmpIncomeServiceImpl implements DmpIncomeService {
}
@Override
public Long delete(Long id) {
if (id == null) {
public Long delete(DmpIncome dmpIncome) {
if (dmpIncome.getId() == null) {
return null;
}
dmpIncomeRepository.delete(id);
return id;
dmpIncomeRepository.delete(dmpIncome.getId());
return dmpIncome.getId();
}
@Override
......@@ -204,24 +204,42 @@ public class DmpIncomeServiceImpl implements DmpIncomeService {
StringBuffer erroMessage = new StringBuffer();
StopWatch stopWatch = new StopWatch();
stopWatch.start();
Map<String, String> incomeMap = new HashMap<>();
List<DmpIncome> dmpIncomeList = Stream.iterate(1, n -> n + 1).limit(rowNumber - 1).map(index -> {
DmpIncome income = saveDmpIncomeItem(sheet, index, loginAccount);
String key = income.getIncomeMonth() + income.getContractCode();
if (incomeMap.containsKey(key)) {
return null;
}
incomeMap.put(key, "1");
return income;
}).filter(in -> in != null).collect(Collectors.toList());
if (dmpIncomeList.isEmpty()) {
return ResultModel.OK();
}
ExecutorService executorService = Executors.newFixedThreadPool(30);
CompletableFuture[] futures = Stream.iterate(1, n -> n + 1).limit(rowNumber - 1).map(index ->
final int[] indexLine = {0};
CompletableFuture[] futures = dmpIncomeList.stream().map(income ->
CompletableFuture.runAsync(
() -> {
DmpIncome income = saveDmpIncomeItem(sheet, index, loginAccount);
if (income != null) {
DmpIncome one = dmpIncomeRepository.findByCodeMonth(income.getContractCode(), income.getIncomeMonth());
if (one != null) {
// 同一合同同一月份不重复保存
return;
}
indexLine[0] = income.getIndex();
if ("erro".equals(income.getIncomeMonth())) {
erroMessage.append(index).append(" 行 收入月份错误").append(";\n");
erroMessage.append(income.getIndex()).append(" 行 收入月份错误").append(";\n");
} else {
income.setConfirmSettlement(new BigDecimal(income.getConfirmSettlement()).setScale(2, BigDecimal.ROUND_HALF_UP).toString());
dmpIncomeRepository.save(income);
}
}
}, executorService)
.exceptionally((t) -> {
erroMessage.append(index).append(" 行 错误").append(t.getMessage()).append(";\n");
logger.error("the line " + index, t);
erroMessage.append(indexLine[0]).append(" 行 错误").append(t.getMessage()).append(";\n");
logger.error("the line " + indexLine[0], t);
return null;
})
).toArray(size -> new CompletableFuture[size]);
......@@ -461,6 +479,7 @@ public class DmpIncomeServiceImpl implements DmpIncomeService {
Row rowItem = sheet.getRow(index);
//合同编号 收入月份 结算周期 系统结算 按月结算 税率 确认收入
DmpIncome income = new DmpIncome();
income.setIndex(index);
income.setContractCode(getCellStringValue(rowItem, 0));
income.setIncomeMonth(getCellDateValue(rowItem, 1, "yyyy-MM"));
income.setPeriod(getCellStringValue(rowItem, 2));
......@@ -480,11 +499,7 @@ public class DmpIncomeServiceImpl implements DmpIncomeService {
if (StringUtils.isEmpty(income.getSysSettlement())) {
income.setSysSettlement("0");
}
DmpIncome one = dmpIncomeRepository.findByCodeMonth(income.getContractCode(), income.getIncomeMonth());
if (one != null) {
// 同一合同同一月份不重复保存
return null;
}
return income;
}
......
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