|
|
@@ -1,5 +1,6 @@
|
|
|
package com.jzg.organization.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.collection.ListUtil;
|
|
|
import cn.hutool.core.date.DateTime;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
@@ -639,8 +640,8 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public ImportExcelResultVo importPlatFormReceivable(MultipartFile file) {
|
|
|
- ImportExcelResultVo importExcelResultVo = new ImportExcelResultVo();
|
|
|
+ public ImportUpdateExcelResultVo importPlatFormReceivable(MultipartFile file) {
|
|
|
+ ImportUpdateExcelResultVo importExcelResultVo = new ImportUpdateExcelResultVo();
|
|
|
|
|
|
List<ReceivableExportExcelVo> receivableExportExcelVos = importReceivableExcel(file);
|
|
|
AssertionUtils.isEmpty(receivableExportExcelVos, "数据处理失败,导入失败");
|
|
|
@@ -650,11 +651,26 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
|
|
|
AssertionUtils.isFail(listHttpResult.getCode() != 200, listHttpResult.getMsg());
|
|
|
|
|
|
int failedNumber = 0;
|
|
|
- List<Object> failedExcel = new ArrayList<>();
|
|
|
- List<InsPlyIncome> successExcel = new ArrayList<>();
|
|
|
+ List<ReceivableExportExcelVo> failedExcel = new ArrayList<>();
|
|
|
+ // 只存储需要【修改】的数据
|
|
|
+ List<InsPlyIncome> updateExcel = new ArrayList<>();
|
|
|
+
|
|
|
+ // ===================== 第一步:校验Excel内部保单号重复 =====================
|
|
|
+ Set<String> existPolicyNoSet = new HashSet<>();
|
|
|
+ Set<String> repeatPolicyNoSet = new HashSet<>();
|
|
|
+
|
|
|
+ for (ReceivableExportExcelVo vo : receivableExportExcelVos) {
|
|
|
+ String policyNo = vo.getJqPolicyNo();
|
|
|
+ if (existPolicyNoSet.contains(policyNo)) {
|
|
|
+ repeatPolicyNoSet.add(policyNo);
|
|
|
+ } else {
|
|
|
+ existPolicyNoSet.add(policyNo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// 处理数据
|
|
|
for (ReceivableExportExcelVo vo : receivableExportExcelVos) {
|
|
|
- // 出现空数据则失败
|
|
|
+ // 1. 空数据校验
|
|
|
ImportResultVo resultVo = vo.checkEmpty();
|
|
|
if (!resultVo.isSuccess()) {
|
|
|
failedNumber++;
|
|
|
@@ -663,35 +679,39 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
- // 检测是否有重复的保单号
|
|
|
- InsPlyIncome checkInsPlyIncome = baseMapper.selectOne(new LambdaQueryWrapper<InsPlyIncome>()
|
|
|
- .eq(InsPlyIncome::getJqPolicyNo, vo.getJqPolicyNo()));
|
|
|
- if (!Objects.isNull(checkInsPlyIncome)) {
|
|
|
+ // 2. Excel内部保单号重复
|
|
|
+ if (repeatPolicyNoSet.contains(vo.getJqPolicyNo())) {
|
|
|
failedNumber++;
|
|
|
- vo.setErrorMessage("车险保单号重复");
|
|
|
+ vo.setErrorMessage("保单号重复");
|
|
|
failedExcel.add(vo);
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
- // 判断应收数据是否已开票 / 已结算
|
|
|
- InsPlyIncome checkInsPlyIncomeByOrderNo = baseMapper.selectOne(new LambdaQueryWrapper<InsPlyIncome>()
|
|
|
- .eq(InsPlyIncome::getOrderNo, vo.getOrderNo()));
|
|
|
- if (ObjectUtil.isNotNull(checkInsPlyIncomeByOrderNo)){
|
|
|
- if ("1".equals(checkInsPlyIncomeByOrderNo.getSuperviseSettlement()) || "1".equals(checkInsPlyIncomeByOrderNo.getOtherSettlement())
|
|
|
- || "1".equals(checkInsPlyIncomeByOrderNo.getJySuperviseSettlement()) || "1".equals(checkInsPlyIncomeByOrderNo.getJyOtherSettlement())){
|
|
|
- failedNumber++;
|
|
|
- vo.setErrorMessage("应收数据已结算");
|
|
|
- failedExcel.add(vo);
|
|
|
- continue;
|
|
|
- }
|
|
|
- }
|
|
|
+ // 3. 查询数据库中是否已存在该保单号
|
|
|
+ InsPlyIncome existIncome = baseMapper.selectOne(new LambdaQueryWrapper<InsPlyIncome>()
|
|
|
+ .eq(InsPlyIncome::getJqPolicyNo, vo.getJqPolicyNo()));
|
|
|
|
|
|
- // 判断应收数据是否已锁定,暂无逻辑
|
|
|
+ // ===================== 【关键修改】数据库不存在 → 直接失败 =====================
|
|
|
+ if (Objects.isNull(existIncome)) {
|
|
|
+ failedNumber++;
|
|
|
+ vo.setErrorMessage("保单号不存在,不允许新增");
|
|
|
+ failedExcel.add(vo);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
|
|
|
+ // ===================== 数据库已存在 → 继续后续校验(需求3顺序) =====================
|
|
|
+ // 判断已开票 / 已结算
|
|
|
+ if ("1".equals(existIncome.getSuperviseSettlement()) || "1".equals(existIncome.getOtherSettlement())
|
|
|
+ || "1".equals(existIncome.getJySuperviseSettlement()) || "1".equals(existIncome.getJyOtherSettlement())) {
|
|
|
+ failedNumber++;
|
|
|
+ vo.setErrorMessage("应收数据已结算");
|
|
|
+ failedExcel.add(vo);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
|
|
|
- // 处理数据
|
|
|
+ // 封装修改数据
|
|
|
InsPlyIncome insPlyIncome = new InsPlyIncome();
|
|
|
- insPlyIncome.setId(IdGenerate.nextId());
|
|
|
+ insPlyIncome.setId(existIncome.getId()); // 必须带ID才能修改
|
|
|
insPlyIncome.setLicenseNo(vo.getLicenseNo());
|
|
|
insPlyIncome.setJqPolicyNo(vo.getJqPolicyNo());
|
|
|
insPlyIncome.setJqSuperviseCostsProportion(vo.getJqSuperviseCostsProportion());
|
|
|
@@ -703,16 +723,32 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
|
|
|
insPlyIncome.setJySuperviseCostsProportion(vo.getJySuperviseCostsProportion());
|
|
|
insPlyIncome.setJyOtherCostsProportion(vo.getJyOtherCostsProportion());
|
|
|
insPlyIncome.setContactPerson(vo.getDockingPerson());
|
|
|
- successExcel.add(insPlyIncome);
|
|
|
+
|
|
|
+ // 加入修改列表
|
|
|
+ updateExcel.add(insPlyIncome);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 执行批量更新(只更新,不新增)
|
|
|
+ if (CollUtil.isNotEmpty(updateExcel)) {
|
|
|
+ baseMapper.updateById(updateExcel);
|
|
|
+ }
|
|
|
+
|
|
|
+ // ===================== 生成失败数据下载链接 =====================
|
|
|
+ String failFileUrl = "";
|
|
|
+ if (CollUtil.isNotEmpty(failedExcel)) {
|
|
|
+ failFileUrl = exportBaseService.upLoadFile(
|
|
|
+ ReceivableExportExcelVo.class,
|
|
|
+ failedExcel,
|
|
|
+ "平台协议应收-导入失败-" + Instant.now()
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
+ // 返回结果
|
|
|
importExcelResultVo.setFailedData(failedExcel);
|
|
|
- importExcelResultVo.setSuccessNumber(successExcel.size());
|
|
|
+ importExcelResultVo.setFailFileUrl(failFileUrl);
|
|
|
+ importExcelResultVo.setSuccessNumber(updateExcel.size());
|
|
|
importExcelResultVo.setFailedNumber(failedNumber);
|
|
|
|
|
|
- // 批量插入数据
|
|
|
- baseMapper.insert(successExcel);
|
|
|
-
|
|
|
return importExcelResultVo;
|
|
|
}
|
|
|
|