Ver código fonte

分账bug处理

liuj 7 meses atrás
pai
commit
85b48058fa

+ 27 - 6
src/main/java/com/sunxung/factoring/service/ledger/impl/LedgerManagementServiceImpl.java

@@ -1378,9 +1378,19 @@ public class LedgerManagementServiceImpl implements LedgerManagementService {
                                         ledgerPlanFactoringAssignList.add(addPlanFactoringInsertAssign(ledgerDate, surplusInterest, BigDecimal.ZERO,
                                                 IncomeExpenditureTypeDict.ChildEnum.INTEREST.getCode(), goodsAssignVo, 0));
                                     } else {
-                                        lastInterestFactoring.setAmount(surplusInterest);
-                                        ledgerPlanFactoringAssignList.add(addPlanFactoringUpdateAssign(lastInterestFactoring.getPlanDate(), BigDecimal.ZERO,
-                                                lastInterestFactoring, goodsAssignVo, 0));
+                                        //可能存在计划已经在之前的判断中被删除的情况,所以需要再判断一次
+                                        boolean exist = ledgerPlanFactoringAssignList.stream().anyMatch(planFactoringAssign ->
+                                                planFactoringAssign.getDeleteFlag() != null && planFactoringAssign.getDeleteFlag()
+                                                        && planFactoringAssign.getPlanFactoringId() != null && lastInterestFactoring.getId().equals(planFactoringAssign.getPlanFactoringId()));
+                                        if (exist) {
+                                            //说明最后一期计划被删了
+                                            ledgerPlanFactoringAssignList.add(addPlanFactoringInsertAssign(ledgerDate, surplusInterest, BigDecimal.ZERO,
+                                                    IncomeExpenditureTypeDict.ChildEnum.INTEREST.getCode(), goodsAssignVo, 0));
+                                        } else {
+                                            lastInterestFactoring.setAmount(surplusInterest);
+                                            ledgerPlanFactoringAssignList.add(addPlanFactoringUpdateAssign(lastInterestFactoring.getPlanDate(), BigDecimal.ZERO,
+                                                    lastInterestFactoring, goodsAssignVo, 0));
+                                        }
                                     }
                                     refundInterest = BigDecimal.ZERO;
                                 }
@@ -1402,13 +1412,24 @@ public class LedgerManagementServiceImpl implements LedgerManagementService {
                                 }
                                 if (surplusManagement.compareTo(BigDecimal.ZERO) > 0) {
                                     PaymentCollectionPlanFactoring lastManagementFactoring = getLastPrincipalFactoring(allPlanFactoringList, managementFeeDict, lastPlanDate);
+                                    //可能存在计划已经在之前的判断中被删除的情况,所以需要再判断一次
                                     if (lastManagementFactoring == null) {
                                         ledgerPlanFactoringAssignList.add(addPlanFactoringInsertAssign(ledgerDate, surplusManagement, BigDecimal.ZERO,
                                                 IncomeExpenditureTypeDict.ChildEnum.MANAGEMENT_FEE.getCode(), goodsAssignVo, 0));
                                     } else {
-                                        lastManagementFactoring.setAmount(surplusManagement);
-                                        ledgerPlanFactoringAssignList.add(addPlanFactoringUpdateAssign(lastManagementFactoring.getPlanDate(), BigDecimal.ZERO,
-                                                lastManagementFactoring, goodsAssignVo, 0));
+                                        //可能存在计划已经在之前的判断中被删除的情况,所以需要再判断一次
+                                        boolean exist = ledgerPlanFactoringAssignList.stream().anyMatch(planFactoringAssign ->
+                                                planFactoringAssign.getDeleteFlag() != null && planFactoringAssign.getDeleteFlag()
+                                                        && planFactoringAssign.getPlanFactoringId() != null && lastManagementFactoring.getId().equals(planFactoringAssign.getPlanFactoringId()));
+                                        if (exist) {
+                                            //说明最后一期计划被删了
+                                            ledgerPlanFactoringAssignList.add(addPlanFactoringInsertAssign(ledgerDate, surplusManagement, BigDecimal.ZERO,
+                                                    IncomeExpenditureTypeDict.ChildEnum.MANAGEMENT_FEE.getCode(), goodsAssignVo, 0));
+                                        } else {
+                                            lastManagementFactoring.setAmount(surplusManagement);
+                                            ledgerPlanFactoringAssignList.add(addPlanFactoringUpdateAssign(lastManagementFactoring.getPlanDate(), BigDecimal.ZERO,
+                                                    lastManagementFactoring, goodsAssignVo, 0));
+                                        }
                                     }
                                     refundManagement = BigDecimal.ZERO;
                                 }