diff --git a/emis-biz/src/main/java/com/xdadan/erp/emis/domain/EmisSettlePayRecord.java b/emis-biz/src/main/java/com/xdadan/erp/emis/domain/EmisSettlePayRecord.java index 4df94bf88..cb8fca8dd 100644 --- a/emis-biz/src/main/java/com/xdadan/erp/emis/domain/EmisSettlePayRecord.java +++ b/emis-biz/src/main/java/com/xdadan/erp/emis/domain/EmisSettlePayRecord.java @@ -102,21 +102,21 @@ public class EmisSettlePayRecord extends BaseEntity private String refundRegisterSiteCode; /* 退款登记人 */ private String refundRegisterManCode; - /* 安全金额 */ + /* 理赔金额 */ private BigDecimal satisfyMoney; - /* 安全原因 */ + /* 理赔原因 */ private String satisfyReason; - /* allowance_money */ + /* 折让金额 */ private BigDecimal allowanceMoney; - /* allowance_reason */ + /* 折让原因 */ private String allowanceReason; - /* deduction_money */ + /* 抵扣金额 */ private BigDecimal deductionMoney; - /* deduction_reason */ + /* 抵扣原因 */ private String deductionReason; - /* other_money */ + /* 其他金额 */ private BigDecimal otherMoney; - /* other_reason */ + /* 其他原因 */ private String otherReason; /* 交易时间 */ @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8") diff --git a/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisSettleBillServiceImpl.java b/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisSettleBillServiceImpl.java index d1a07a79f..89a3b14d2 100644 --- a/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisSettleBillServiceImpl.java +++ b/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisSettleBillServiceImpl.java @@ -897,16 +897,81 @@ public class EmisSettleBillServiceImpl extends EmisBaseService implements IEmisS // refund_money BigDecimal refundMoney = BigDecimal.ZERO; + // 理赔/折让/抵扣/其他原因聚合(可能一个回款记录关联多个账单号) + StringBuilder satisfyReasonSb = new StringBuilder(); + StringBuilder allowanceReasonSb = new StringBuilder(); + StringBuilder deductionReasonSb = new StringBuilder(); + StringBuilder otherReasonSb = new StringBuilder(); + log.debug("reCalcSettleBillPayStatus===>应收:{}", oldBill.getRecMoney()); for (EmisSettlePayRecord item : payRecordList) { + // 一个收退款记录可能关联多个账单号,这里按账单号数量分摊理赔/折让/抵扣/其他金额 + int length = 1; + String itemSettleBillNo = item.getSettleBillNo(); + if (StringUtils.isNotBlank(itemSettleBillNo)) { + String[] billNoArr = itemSettleBillNo.split("[,,]"); + int cnt = 0; + for (String no : billNoArr) { + if (StringUtils.isNotBlank(no)) { + cnt++; + } + } + if (cnt > 0) { + length = cnt; + } + } + totalHasPayMoney = totalHasPayMoney.add(item.getPayMoney()); - satisfyMoney = satisfyMoney.add(item.getSatisfyMoney() == null ? BigDecimal.ZERO : item.getSatisfyMoney()); - allowanceMoney = allowanceMoney - .add(item.getAllowanceMoney() == null ? BigDecimal.ZERO : item.getAllowanceMoney()); - deductionMoney = deductionMoney - .add(item.getDeductionMoney() == null ? BigDecimal.ZERO : item.getDeductionMoney()); - otherMoney = otherMoney.add(item.getOtherMoney() == null ? BigDecimal.ZERO : item.getOtherMoney()); + BigDecimal curSatisfyMoney = item.getSatisfyMoney() == null ? BigDecimal.ZERO : item.getSatisfyMoney(); + if (length > 1) { + curSatisfyMoney = curSatisfyMoney.divide(BigDecimal.valueOf(length), 2, BigDecimal.ROUND_HALF_UP); + } + satisfyMoney = satisfyMoney.add(curSatisfyMoney); + + BigDecimal curAllowanceMoney = item.getAllowanceMoney() == null ? BigDecimal.ZERO : item.getAllowanceMoney(); + if (length > 1) { + curAllowanceMoney = curAllowanceMoney.divide(BigDecimal.valueOf(length), 2, BigDecimal.ROUND_HALF_UP); + } + allowanceMoney = allowanceMoney.add(curAllowanceMoney); + + BigDecimal curDeductionMoney = item.getDeductionMoney() == null ? BigDecimal.ZERO : item.getDeductionMoney(); + if (length > 1) { + curDeductionMoney = curDeductionMoney.divide(BigDecimal.valueOf(length), 2, BigDecimal.ROUND_HALF_UP); + } + deductionMoney = deductionMoney.add(curDeductionMoney); + + BigDecimal curOtherMoney = item.getOtherMoney() == null ? BigDecimal.ZERO : item.getOtherMoney(); + if (length > 1) { + curOtherMoney = curOtherMoney.divide(BigDecimal.valueOf(length), 2, BigDecimal.ROUND_HALF_UP); + } + otherMoney = otherMoney.add(curOtherMoney); + + // 原因字段从收退款明细聚合 + if (StringUtils.isNotBlank(item.getSatisfyReason())) { + if (satisfyReasonSb.length() > 0) { + satisfyReasonSb.append(","); + } + satisfyReasonSb.append(item.getSatisfyReason()); + } + if (StringUtils.isNotBlank(item.getAllowanceReason())) { + if (allowanceReasonSb.length() > 0) { + allowanceReasonSb.append(","); + } + allowanceReasonSb.append(item.getAllowanceReason()); + } + if (StringUtils.isNotBlank(item.getDeductionReason())) { + if (deductionReasonSb.length() > 0) { + deductionReasonSb.append(","); + } + deductionReasonSb.append(item.getDeductionReason()); + } + if (StringUtils.isNotBlank(item.getOtherReason())) { + if (otherReasonSb.length() > 0) { + otherReasonSb.append(","); + } + otherReasonSb.append(item.getOtherReason()); + } if ("2".equals(item.getRecType())) { refundMoney = refundMoney.add(item.getRefundMoney() == null ? BigDecimal.ZERO : item.getRefundMoney()); @@ -992,6 +1057,10 @@ public class EmisSettleBillServiceImpl extends EmisBaseService implements IEmisS newBill.setOtherMoney(otherMoney); // 退款金额 newBill.setRefundMoney(refundMoney); + newBill.setSatisfyReason(satisfyReasonSb.length() > 0 ? satisfyReasonSb.toString() : null); + newBill.setAllowanceReason(allowanceReasonSb.length() > 0 ? allowanceReasonSb.toString() : null); + newBill.setDeductionReason(deductionReasonSb.length() > 0 ? deductionReasonSb.toString() : null); + newBill.setOtherReason(otherReasonSb.length() > 0 ? otherReasonSb.toString() : null); // 更新账单收款状态 收款金额 log.debug("reCalcSettleBillPayStatus===>收款金额:{},应收:{}", totalMoney, oldBill.getRecMoney()); @@ -1036,6 +1105,10 @@ public class EmisSettleBillServiceImpl extends EmisBaseService implements IEmisS newBill.setOtherMoney(otherMoney); // 退款金额 newBill.setRefundMoney(refundMoney); + newBill.setSatisfyReason(satisfyReasonSb.length() > 0 ? satisfyReasonSb.toString() : null); + newBill.setAllowanceReason(allowanceReasonSb.length() > 0 ? allowanceReasonSb.toString() : null); + newBill.setDeductionReason(deductionReasonSb.length() > 0 ? deductionReasonSb.toString() : null); + newBill.setOtherReason(otherReasonSb.length() > 0 ? otherReasonSb.toString() : null); // 更新账单收款状态 收款金额 log.debug("reCalcSettleBillPayStatus===>收款金额:{},应收:{}", totalMoney, oldBill.getRecMoney()); @@ -1117,6 +1190,10 @@ public class EmisSettleBillServiceImpl extends EmisBaseService implements IEmisS newBill.setOtherMoney(otherMoney); // 退款金额 newBill.setRefundMoney(refundMoney); + newBill.setSatisfyReason(satisfyReasonSb.length() > 0 ? satisfyReasonSb.toString() : null); + newBill.setAllowanceReason(allowanceReasonSb.length() > 0 ? allowanceReasonSb.toString() : null); + newBill.setDeductionReason(deductionReasonSb.length() > 0 ? deductionReasonSb.toString() : null); + newBill.setOtherReason(otherReasonSb.length() > 0 ? otherReasonSb.toString() : null); // 更新账单收款状态 收款金额 log.debug("reCalcSettleBillPayStatus===>收款金额:{},应收:{}", totalMoney, oldBill.getRecMoney()); diff --git a/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisSettlePayRecordServiceImpl.java b/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisSettlePayRecordServiceImpl.java index bfe97910f..c2d66b058 100644 --- a/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisSettlePayRecordServiceImpl.java +++ b/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisSettlePayRecordServiceImpl.java @@ -34,8 +34,10 @@ import java.time.LocalDate; import java.time.ZoneId; import java.time.format.DateTimeFormatter; import java.util.Arrays; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -472,6 +474,9 @@ public class EmisSettlePayRecordServiceImpl extends EmisBaseService implements I List settleBillNoArr = Arrays.stream(emisSettlePayRecord.getSettleBillNo().split(",")).distinct() .collect(Collectors.toList()); + // 现金结算多账单合并收款时,校验每条运单的 moneyUserId 必须一致 + validateMoneyUserIdForMergeCashSettle(emisSettlePayRecord); + for (int i = 0; i < settleBillNoArr.size(); i++) { String settleBillNo = settleBillNoArr.get(i); if (!StringUtils.isEmpty(settleBillNo)) { @@ -573,6 +578,33 @@ public class EmisSettlePayRecordServiceImpl extends EmisBaseService implements I return 1; } + private void validateMoneyUserIdForMergeCashSettle(EmisSettlePayRecord emisSettlePayRecord) throws EmisBizError { + if (!"1".equals(emisSettlePayRecord.getSettleType()) + || StringUtils.isBlank(emisSettlePayRecord.getSettleBillNo()) + || !emisSettlePayRecord.getSettleBillNo().contains(",")) { + return; + } + + List payRelList = emisSettlePayRecord.getPayRelList(); + if (CollectionUtils.isEmpty(payRelList)) { + return; + } + + Set moneyUserIdSet = new HashSet<>(); + for (EmisSettlePayRel payRel : payRelList) { + Long moneyUserId = null; + if (payRel != null + && payRel.getWaybillDetail() != null + && payRel.getWaybillDetail().getWaybillOther() != null) { + moneyUserId = payRel.getWaybillDetail().getWaybillOther().getMoneyUserId(); + } + moneyUserIdSet.add(moneyUserId); + if (moneyUserIdSet.size() > 1) { + throw new EmisBizError(EmisBizErrorType.FAIL, "不同现金客户不允许合并收款"); + } + } + } + private static void checkParam(EmisSettlePayRecord emisSettlePayRecord) throws EmisBizError { if (StringUtils.isEmpty(emisSettlePayRecord.getSettleBillNo())) { throw new EmisBizError(EmisBizErrorType.FAIL, "账单编号不能为空"); diff --git a/emis-biz/src/main/resources/mapper/EmisSettleSubBillMapper.xml b/emis-biz/src/main/resources/mapper/EmisSettleSubBillMapper.xml index a6d7b309b..8023b64d8 100644 --- a/emis-biz/src/main/resources/mapper/EmisSettleSubBillMapper.xml +++ b/emis-biz/src/main/resources/mapper/EmisSettleSubBillMapper.xml @@ -54,7 +54,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"