|
|
@@ -2304,7 +2304,7 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
|
|
|
.eq(PtlAgreement::getId, data.getAgreementId()));
|
|
|
|
|
|
// 数据库不存在 → 直接失败
|
|
|
- if (Objects.isNull(ptlAgreement) || !ptlAgreement.getAgreementType().toString().equals(vo.getAgreementType())) {
|
|
|
+ if (Objects.isNull(ptlAgreement) || !"2".equals(ptlAgreement.getAgreementType().toString())) {
|
|
|
failedNumber++;
|
|
|
vo.setErrorMessage("协议编码在协议中不存在");
|
|
|
failedExcel.add(vo);
|
|
|
@@ -2312,72 +2312,27 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
|
|
|
}
|
|
|
|
|
|
// 查询数据库中是否已存在该保单号
|
|
|
- InsPlyIncome existIncome = baseMapper.selectOne(new LambdaQueryWrapper<InsPlyIncome>()
|
|
|
- .eq(InsPlyIncome::getJqPolicyNo, vo.getJqPolicyNo()));
|
|
|
-
|
|
|
- // 封装修改数据
|
|
|
- InsPlyIncome insPlyIncome = new InsPlyIncome();
|
|
|
- insPlyIncome.setId(IdGenerate.nextId());
|
|
|
- insPlyIncome.setLicenseNo(vo.getLicenseNo());
|
|
|
- insPlyIncome.setJqPolicyNo(vo.getJqPolicyNo());
|
|
|
- insPlyIncome.setJqSuperviseCostsProportion(vo.getJqSuperviseCostsProportion());
|
|
|
- insPlyIncome.setJqOtherCostsProportion(vo.getJqOtherCostsProportion());
|
|
|
- insPlyIncome.setSyPolicyNo(vo.getSyPolicyNo());
|
|
|
- insPlyIncome.setSySuperviseCostsProportion(vo.getSySuperviseCostsProportion());
|
|
|
- insPlyIncome.setSyOtherCostsProportion(vo.getSyOtherCostsProportion());
|
|
|
- insPlyIncome.setJyPolicyNo(vo.getJyPolicyNo());
|
|
|
- insPlyIncome.setJySuperviseCostsProportion(vo.getJySuperviseCostsProportion());
|
|
|
- insPlyIncome.setJyOtherCostsProportion(vo.getJyOtherCostsProportion());
|
|
|
- // 签单时间
|
|
|
- DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
- insPlyIncome.setSigningTime(LocalDateTime.parse(vo.getSigningTime(), formatter));
|
|
|
- // 协议编号
|
|
|
- insPlyIncome.setAgreementId(ptlAgreement.getId());
|
|
|
- insPlyIncome.setAgreementName(ptlAgreement.getAgreementName());
|
|
|
- insPlyIncome.setAgreementType(ptlAgreement.getAgreementType().toString());
|
|
|
- insPlyIncome.setSystemCode(ptlAgreement.getSystemCode());
|
|
|
- // 险种编号
|
|
|
- insPlyIncome.setProductId(ProductsType.getCodeByDesc(vo.getProductName()));
|
|
|
- // 险种名称
|
|
|
- insPlyIncome.setProductName(vo.getProductName());
|
|
|
- // 被保险人姓名
|
|
|
- insPlyIncome.setInsuredPerson(vo.getInsuredPerson());
|
|
|
- // 对接人信息
|
|
|
- insPlyIncome.setContactPerson(vo.getContactPerson());
|
|
|
- insPlyIncome.setContactPersonPhone(vo.getContactPersonPhone());
|
|
|
+ failedNumber = spliceData(vo, ptlAgreement, esmInsCompanyList, insertExcel, successOrderNoList, failedNumber, failedExcel, updateExcel);
|
|
|
+ }
|
|
|
|
|
|
- // 数据库不存在 → 直接失败
|
|
|
- if (Objects.isNull(existIncome)) {
|
|
|
- // 加入修改列表
|
|
|
- // 机构id
|
|
|
- insPlyIncome.setDeptId(baseController.getUserDeptId());
|
|
|
- EsmInsCompany esmInsCompany = esmInsCompanyList.stream().filter(company -> company.getName().equals(vo.getCompanyName())).findFirst().orElse(new EsmInsCompany());
|
|
|
- insPlyIncome.setCompanyId(esmInsCompany.getId());
|
|
|
- insPlyIncome.setOrderNo(vo.getOrderNo());
|
|
|
- insertExcel.add(insPlyIncome);
|
|
|
- // 新增成功,记录订单号
|
|
|
- successOrderNoList.add(vo.getOrderNo());
|
|
|
- }else{
|
|
|
- // 数据库已存在 → 继续后续校验
|
|
|
- // 判断已开票 / 已结算
|
|
|
- String settlementFlag = "1";
|
|
|
- if (settlementFlag.equals(existIncome.getSuperviseSettlement()) || settlementFlag.equals(existIncome.getOtherSettlement())
|
|
|
- || settlementFlag.equals(existIncome.getJySuperviseSettlement()) || settlementFlag.equals(existIncome.getJyOtherSettlement())
|
|
|
- || settlementFlag.equals(existIncome.getPlatformSuperviseSettlement()) || settlementFlag.equals(existIncome.getPlatformOtherSettlement())) {
|
|
|
- failedNumber++;
|
|
|
- vo.setErrorMessage("应收数据已结算");
|
|
|
- failedExcel.add(vo);
|
|
|
- continue;
|
|
|
- }
|
|
|
+ getDataManipulationResult(updateExcel, insertExcel, failedExcel, importExcelResultVo, failedNumber, successOrderNoList);
|
|
|
|
|
|
- insPlyIncome.setId(existIncome.getId());
|
|
|
- // 加入修改列表
|
|
|
- updateExcel.add(insPlyIncome);
|
|
|
- // 更新成功,记录订单号
|
|
|
- successOrderNoList.add(vo.getOrderNo());
|
|
|
- }
|
|
|
- }
|
|
|
+ return importExcelResultVo;
|
|
|
+ }
|
|
|
|
|
|
+ /**
|
|
|
+ * <p>
|
|
|
+ * 1. 获取保司名称
|
|
|
+ * 2. 校验Excel内部保单号重复
|
|
|
+ * 3. 处理数据
|
|
|
+ * 4. 执行批量更新
|
|
|
+ * 5. 生成失败数据下载链接
|
|
|
+ * 6. 返回结果
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @return List<InvoiceReceivableExportExcelVo> 处理后的数据列表
|
|
|
+ */
|
|
|
+ private void getDataManipulationResult(List<InsPlyIncome> updateExcel, List<InsPlyIncome> insertExcel, List<InvoiceReceivableExportExcelVo> failedExcel, ImportUpdateExcelResultVo importExcelResultVo, int failedNumber, List<String> successOrderNoList) {
|
|
|
// 执行批量更新
|
|
|
if (CollUtil.isNotEmpty(updateExcel)) {
|
|
|
baseMapper.updateById(updateExcel);
|
|
|
@@ -2402,10 +2357,184 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
|
|
|
importExcelResultVo.setFailedNumber(failedNumber);
|
|
|
// 导出成功的orderNos
|
|
|
importExcelResultVo.setOrderNos(successOrderNoList);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 导入平台的应收数据
|
|
|
+ * @param file
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ImportUpdateExcelResultVo importPlatformReceivableInvoice(MultipartFile file) {
|
|
|
+ String userName = baseController.getUserName();
|
|
|
+ log.info("用户[{}]导入平台协议文件",userName);
|
|
|
+ ImportUpdateExcelResultVo importExcelResultVo = new ImportUpdateExcelResultVo();
|
|
|
+ List<InvoiceReceivableExportExcelVo> receivableExportExcelVos = importInvoiceReceivableExcel(file);
|
|
|
+ if (CollUtil.isEmpty(receivableExportExcelVos)){
|
|
|
+ throw new SystemException("数据不能为空,导入失败");
|
|
|
+ }
|
|
|
+ AssertionUtils.isEmpty(receivableExportExcelVos, "数据处理失败,导入失败");
|
|
|
+ // 获取保司名称
|
|
|
+ HttpResult<List<EsmInsCompany>> listHttpResult = esmInsCompanyClient.liveCompanyList();
|
|
|
+ AssertionUtils.isFail(listHttpResult.getCode() != 200, listHttpResult.getMsg());
|
|
|
+ List<EsmInsCompany> esmInsCompanyList = CollUtil.isNotEmpty(listHttpResult.getData()) ? listHttpResult.getData() : CollUtil.newArrayList();
|
|
|
+
|
|
|
+ int failedNumber = 0;
|
|
|
+ List<InvoiceReceivableExportExcelVo> failedExcel = new ArrayList<>();
|
|
|
+ // 只存储需要【修改】的数据
|
|
|
+ List<InsPlyIncome> updateExcel = new ArrayList<>();
|
|
|
+ List<InsPlyIncome> insertExcel = new ArrayList<>();
|
|
|
+ // 存储导入成功的订单号
|
|
|
+ List<String> successOrderNoList = new ArrayList<>();
|
|
|
+
|
|
|
+ // 校验Excel内部保单号重复
|
|
|
+ Set<String> existPolicyNoSet = new HashSet<>();
|
|
|
+ Set<String> repeatPolicyNoSet = new HashSet<>();
|
|
|
+ Set<String> existCompanyIdSet = new HashSet<>();
|
|
|
+
|
|
|
+ for (InvoiceReceivableExportExcelVo vo : receivableExportExcelVos) {
|
|
|
+ String policyNo = vo.getJqPolicyNo();
|
|
|
+ if (existPolicyNoSet.contains(policyNo)) {
|
|
|
+ repeatPolicyNoSet.add(policyNo);
|
|
|
+ } else {
|
|
|
+ existPolicyNoSet.add(policyNo);
|
|
|
+ }
|
|
|
+ existCompanyIdSet.add(vo.getCompanyName());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 导入只能一个保司
|
|
|
+ if (existCompanyIdSet.size() > 1) {
|
|
|
+ throw new SystemException("导入数据不能包含多个保险公司");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理数据
|
|
|
+ for (InvoiceReceivableExportExcelVo vo : receivableExportExcelVos) {
|
|
|
+ // 1. 空数据校验
|
|
|
+ ImportResultVo resultVo = vo.checkEmpty();
|
|
|
+ if (!resultVo.isSuccess()) {
|
|
|
+ failedNumber++;
|
|
|
+ vo.setErrorMessage(resultVo.getMessage());
|
|
|
+ failedExcel.add(vo);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 2. Excel内部保单号重复
|
|
|
+ if (repeatPolicyNoSet.contains(vo.getJqPolicyNo())) {
|
|
|
+ failedNumber++;
|
|
|
+ vo.setErrorMessage("保单号重复");
|
|
|
+ failedExcel.add(vo);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询订单
|
|
|
+ HttpResult<InsOrdersVo> insOrdersVoHttpResult = insOrdersClient.selectById(vo.getOrderNo());
|
|
|
+ InsOrdersVo data = insOrdersVoHttpResult.getData();
|
|
|
+ if (null == data){
|
|
|
+ failedNumber++;
|
|
|
+ vo.setErrorMessage("订单号不存在");
|
|
|
+ failedExcel.add(vo);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询数据库中是否已存在该协议
|
|
|
+ PtlAgreement ptlAgreement = ptlAgreementMapper.selectOne(new LambdaQueryWrapper<PtlAgreement>()
|
|
|
+ .eq(PtlAgreement::getId, data.getAgreementId()));
|
|
|
+
|
|
|
+ // 数据库不存在 → 直接失败
|
|
|
+ if (Objects.isNull(ptlAgreement) || !"1".equals(ptlAgreement.getAgreementType().toString())) {
|
|
|
+ failedNumber++;
|
|
|
+ vo.setErrorMessage("协议编码在协议中不存在");
|
|
|
+ failedExcel.add(vo);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ failedNumber = spliceData(vo, ptlAgreement, esmInsCompanyList, insertExcel, successOrderNoList, failedNumber, failedExcel, updateExcel);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 执行批量更新
|
|
|
+ getDataManipulationResult(updateExcel, insertExcel, failedExcel, importExcelResultVo, failedNumber, successOrderNoList);
|
|
|
|
|
|
return importExcelResultVo;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 批量处理数据
|
|
|
+ * @param updateExcel
|
|
|
+ * @param insertExcel
|
|
|
+ * @param failedExcel
|
|
|
+ * @param failedNumber
|
|
|
+ * @param successOrderNoList
|
|
|
+ */
|
|
|
+ private int spliceData(InvoiceReceivableExportExcelVo vo, PtlAgreement ptlAgreement, List<EsmInsCompany> esmInsCompanyList, List<InsPlyIncome> insertExcel, List<String> successOrderNoList, int failedNumber, List<InvoiceReceivableExportExcelVo> failedExcel, List<InsPlyIncome> updateExcel) {
|
|
|
+ // 查询数据库中是否已存在该保单号
|
|
|
+ InsPlyIncome existIncome = baseMapper.selectOne(new LambdaQueryWrapper<InsPlyIncome>()
|
|
|
+ .eq(InsPlyIncome::getJqPolicyNo, vo.getJqPolicyNo()));
|
|
|
+
|
|
|
+ // 封装修改数据
|
|
|
+ InsPlyIncome insPlyIncome = new InsPlyIncome();
|
|
|
+ insPlyIncome.setId(IdGenerate.nextId());
|
|
|
+ insPlyIncome.setLicenseNo(vo.getLicenseNo());
|
|
|
+ insPlyIncome.setJqPolicyNo(vo.getJqPolicyNo());
|
|
|
+ insPlyIncome.setJqSuperviseCostsProportion(vo.getJqSuperviseCostsProportion());
|
|
|
+ insPlyIncome.setJqOtherCostsProportion(vo.getJqOtherCostsProportion());
|
|
|
+ insPlyIncome.setSyPolicyNo(vo.getSyPolicyNo());
|
|
|
+ insPlyIncome.setSySuperviseCostsProportion(vo.getSySuperviseCostsProportion());
|
|
|
+ insPlyIncome.setSyOtherCostsProportion(vo.getSyOtherCostsProportion());
|
|
|
+ insPlyIncome.setJyPolicyNo(vo.getJyPolicyNo());
|
|
|
+ insPlyIncome.setJySuperviseCostsProportion(vo.getJySuperviseCostsProportion());
|
|
|
+ insPlyIncome.setJyOtherCostsProportion(vo.getJyOtherCostsProportion());
|
|
|
+ // 签单时间
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
+ insPlyIncome.setSigningTime(LocalDateTime.parse(vo.getSigningTime(), formatter));
|
|
|
+ // 协议编号
|
|
|
+ insPlyIncome.setAgreementId(ptlAgreement.getId());
|
|
|
+ insPlyIncome.setAgreementName(ptlAgreement.getAgreementName());
|
|
|
+ insPlyIncome.setAgreementType(ptlAgreement.getAgreementType().toString());
|
|
|
+ insPlyIncome.setSystemCode(ptlAgreement.getSystemCode());
|
|
|
+ // 险种编号
|
|
|
+ insPlyIncome.setProductId(ProductsType.getCodeByDesc(vo.getProductName()));
|
|
|
+ // 险种名称
|
|
|
+ insPlyIncome.setProductName(vo.getProductName());
|
|
|
+ // 被保险人姓名
|
|
|
+ insPlyIncome.setInsuredPerson(vo.getInsuredPerson());
|
|
|
+ // 对接人信息
|
|
|
+ insPlyIncome.setContactPerson(vo.getContactPerson());
|
|
|
+ insPlyIncome.setContactPersonPhone(vo.getContactPersonPhone());
|
|
|
+
|
|
|
+ // 数据库不存在 → 直接失败
|
|
|
+ if (Objects.isNull(existIncome)) {
|
|
|
+ // 加入修改列表
|
|
|
+ // 机构id
|
|
|
+ insPlyIncome.setDeptId(baseController.getUserDeptId());
|
|
|
+ EsmInsCompany esmInsCompany = esmInsCompanyList.stream().filter(company -> company.getName().equals(vo.getCompanyName())).findFirst().orElse(new EsmInsCompany());
|
|
|
+ insPlyIncome.setCompanyId(esmInsCompany.getId());
|
|
|
+ insPlyIncome.setOrderNo(vo.getOrderNo());
|
|
|
+ insertExcel.add(insPlyIncome);
|
|
|
+ // 新增成功,记录订单号
|
|
|
+ successOrderNoList.add(vo.getOrderNo());
|
|
|
+ }else{
|
|
|
+ // 数据库已存在 → 继续后续校验
|
|
|
+ // 判断已开票 / 已结算
|
|
|
+ String settlementFlag = "1";
|
|
|
+ if (settlementFlag.equals(existIncome.getSuperviseSettlement()) || settlementFlag.equals(existIncome.getOtherSettlement())
|
|
|
+ || settlementFlag.equals(existIncome.getJySuperviseSettlement()) || settlementFlag.equals(existIncome.getJyOtherSettlement())
|
|
|
+ || settlementFlag.equals(existIncome.getPlatformSuperviseSettlement()) || settlementFlag.equals(existIncome.getPlatformOtherSettlement())) {
|
|
|
+ failedNumber++;
|
|
|
+ vo.setErrorMessage("应收数据已结算");
|
|
|
+ failedExcel.add(vo);
|
|
|
+ return failedNumber;
|
|
|
+ }
|
|
|
+
|
|
|
+ insPlyIncome.setId(existIncome.getId());
|
|
|
+ // 加入修改列表
|
|
|
+ updateExcel.add(insPlyIncome);
|
|
|
+ // 更新成功,记录订单号
|
|
|
+ successOrderNoList.add(vo.getOrderNo());
|
|
|
+ }
|
|
|
+ return failedNumber;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 平台协议结算-删除结算记录
|
|
|
@@ -3950,7 +4079,7 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
|
|
|
invoice.setPaymentReason(vo.getPaymentReason());
|
|
|
invoice.setReceivableSupervisePremium(vo.getReceivableSupervisePremium());
|
|
|
invoice.setTaxPoint(vo.getTaxPoint());
|
|
|
- invoice.setInvoiceTime(LocalDateTime.now());
|
|
|
+ invoice.setInvoiceTime(vo.getInvoiceTime());
|
|
|
// 初始状态:0-待处理
|
|
|
invoice.setStatus("0");
|
|
|
return invoice;
|
|
|
@@ -4601,7 +4730,7 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
|
|
|
// settlementPaymentDifference = BigDecimalUtil.subtract(settlementAmount,receivableSupervisePremium);
|
|
|
// }
|
|
|
// 待结算金额 = 开票金额 - 已收金额
|
|
|
- BigDecimal remainSettlementAmount = receivableSupervisePremium.subtract(BigDecimalUtil.add(settlementAmount, settlementPaymentDifference));
|
|
|
+ BigDecimal remainSettlementAmount = receivableSupervisePremium.subtract(BigDecimalUtil.subtract(settlementAmount, settlementPaymentDifference));
|
|
|
// 设置已结算的金额
|
|
|
action.setSettlementAmount(settlementAmount);
|
|
|
// 设置待结算金额
|