瀏覽代碼

分账管理优化

liuj 6 月之前
父節點
當前提交
f83fafa48e
共有 1 個文件被更改,包括 35 次插入47 次删除
  1. 35 47
      src/main/java/com/sunxung/factoring/service/ledger/impl/LedgerManagementServiceImpl.java

+ 35 - 47
src/main/java/com/sunxung/factoring/service/ledger/impl/LedgerManagementServiceImpl.java

@@ -1127,6 +1127,14 @@ public class LedgerManagementServiceImpl implements LedgerManagementService {
                             List<PaymentCollectionPlanFactoring> principalFactoringList = getFactoringByAmountType(allPlanFactoringList, principalDict);
                             //检验本金是否存在
                             validatePlanFactoring(principalFactoringList);
+                            Boolean assignOverdueInterest = hasAssignOverdueInterest(allPlanFactoringList, goodsAssignVo.getHasAssignOverdueInterest());
+
+                            Date actualDate;
+                            if (assignOverdueInterest) {
+                                actualDate = new Date();
+                            } else {
+                                actualDate = ledgerDate;
+                            }
 
                             //1.查看计划是否有逾期利息未分完的,存在先分逾期利息
                             if (goodsAssignVo.getHasAssignOverdueInterest()) {
@@ -1138,7 +1146,7 @@ public class LedgerManagementServiceImpl implements LedgerManagementService {
                                         BigDecimal currentAssignAmount = assignAmount(assignAmount, factoring);
                                         financingOverdueInterest = financingOverdueInterest.add(currentAssignAmount);
                                         assignAmount = assignAmount.subtract(currentAssignAmount);
-                                        ledgerPlanFactoringAssignList.add(addPlanFactoringUpdateAssign(ledgerDate, currentAssignAmount, factoring, goodsAssignVo, 0));
+                                        ledgerPlanFactoringAssignList.add(addPlanFactoringUpdateAssign(actualDate, currentAssignAmount, factoring, goodsAssignVo, 0));
                                         if (assignAmount.compareTo(BigDecimal.ZERO) == 0) {
                                             //说明钱已经分完了,结束分配
                                             break;
@@ -1155,7 +1163,7 @@ public class LedgerManagementServiceImpl implements LedgerManagementService {
                                         BigDecimal currentAssignAmount = assignAmount(assignAmount, factoring);
                                         financeInterest = financeInterest.add(currentAssignAmount);
                                         assignAmount = assignAmount.subtract(currentAssignAmount);
-                                        ledgerPlanFactoringAssignList.add(addPlanFactoringUpdateAssign(ledgerDate, currentAssignAmount, factoring, goodsAssignVo, 0));
+                                        ledgerPlanFactoringAssignList.add(addPlanFactoringUpdateAssign(actualDate, currentAssignAmount, factoring, goodsAssignVo, 0));
                                         if (assignAmount.compareTo(BigDecimal.ZERO) == 0) {
                                             //说明钱已经分完了,结束分配
                                             break;
@@ -1168,29 +1176,15 @@ public class LedgerManagementServiceImpl implements LedgerManagementService {
                             //4.获取所有的已经收款的利息之和
                             BigDecimal actualInterestTotal = getActualAmountTotal(allPlanFactoringList, interestDict);
 
-                            Boolean assignOverdueInterest = hasAssignOverdueInterest(allPlanFactoringList, goodsAssignVo.getHasAssignOverdueInterest());
                             //5.获取截至到分账日期的新的本金计划
-                            List<PaymentCollectionPlanFactoring> newPrincipalFactoringList;
-                            BigDecimal planManagementTotal;
-                            BigDecimal planInterestTotal;
-                            if (assignOverdueInterest) {
-                                //判断是否存在逾期利息不豁免且需要分逾期利息的场景,如果存在分账日期取系统当前日期
-                                newPrincipalFactoringList = getPrincipalFactoringByLedgerDate(principalFactoringList, new Date(), returnedAmount);
-                                //6.计算截至到分账日期计划应收管理费总和
-                                planManagementTotal = getAllocatedAmountByPlanFactoring(newPrincipalFactoringList, managementFeeDict,
-                                        goodsAssignVo, paymentCalculateVo, new Date());
-                                //7.计算截至到分账日期计划应收利息总和
-                                planInterestTotal = getAllocatedAmountByPlanFactoring(newPrincipalFactoringList, interestDict,
-                                        goodsAssignVo, paymentCalculateVo, new Date());
-                            } else {
-                                newPrincipalFactoringList = getPrincipalFactoringByLedgerDate(principalFactoringList, ledgerDate, returnedAmount);
-                                //6.计算截至到分账日期计划应收管理费总和
-                                planManagementTotal = getAllocatedAmountByPlanFactoring(newPrincipalFactoringList, managementFeeDict,
-                                        goodsAssignVo, paymentCalculateVo, ledgerDate);
-                                //7.计算截至到分账日期计划应收利息总和
-                                planInterestTotal = getAllocatedAmountByPlanFactoring(newPrincipalFactoringList, interestDict,
-                                        goodsAssignVo, paymentCalculateVo, ledgerDate);
-                            }
+                            List<PaymentCollectionPlanFactoring> newPrincipalFactoringList = getPrincipalFactoringByLedgerDate(principalFactoringList, actualDate, returnedAmount);
+                            //6.计算截至到分账日期计划应收管理费总和
+                            BigDecimal planManagementTotal = getAllocatedAmountByPlanFactoring(newPrincipalFactoringList, managementFeeDict,
+                                    goodsAssignVo, paymentCalculateVo, actualDate);
+                            //7.计算截至到分账日期计划应收利息总和
+                            BigDecimal planInterestTotal = getAllocatedAmountByPlanFactoring(newPrincipalFactoringList, interestDict,
+                                    goodsAssignVo, paymentCalculateVo, actualDate);
+
                             //剩余未分配管理费
                             BigDecimal unAssignManagement = BigDecimal.ZERO;
                             //剩余未分配利息
@@ -1218,16 +1212,16 @@ public class LedgerManagementServiceImpl implements LedgerManagementService {
                                 BigDecimal toAssignManagement = refundManagement.negate();
                                 if (assignAmount.compareTo(BigDecimal.ZERO) > 0) {
                                     //这种场景可能存在未分配的管理费,要删除分账日期之前的状态为计划中的数据
-                                    deleteUnAssignList(managementFeeFactoringList, ledgerPlanFactoringAssignList, goodsAssignVo, ledgerDate);
+                                    deleteUnAssignList(managementFeeFactoringList, ledgerPlanFactoringAssignList, goodsAssignVo, actualDate);
                                     //判断是否需要分配
                                     if (goodsAssignVo.getHasAssignInterest()) {
                                         if (assignAmount.compareTo(toAssignManagement) >= 0) {
-                                            ledgerPlanFactoringAssignList.add(addPlanFactoringInsertAssign(ledgerDate, toAssignManagement, toAssignManagement,
+                                            ledgerPlanFactoringAssignList.add(addPlanFactoringInsertAssign(actualDate, toAssignManagement, toAssignManagement,
                                                     IncomeExpenditureTypeDict.ChildEnum.MANAGEMENT_FEE.getCode(), goodsAssignVo, 0));
                                             financingManagementFee = financingManagementFee.add(toAssignManagement);
                                             assignAmount = assignAmount.subtract(toAssignManagement);
                                         } else if (assignAmount.compareTo(toAssignManagement) < 0) {
-                                            ledgerPlanFactoringAssignList.add(addPlanFactoringInsertAssign(ledgerDate, assignAmount, assignAmount,
+                                            ledgerPlanFactoringAssignList.add(addPlanFactoringInsertAssign(actualDate, assignAmount, assignAmount,
                                                     IncomeExpenditureTypeDict.ChildEnum.MANAGEMENT_FEE.getCode(), goodsAssignVo, 0));
                                             financingManagementFee = financingManagementFee.add(assignAmount);
                                             //剩余未分配管理费
@@ -1236,7 +1230,7 @@ public class LedgerManagementServiceImpl implements LedgerManagementService {
                                         }
                                     } else {
                                         //如果本次选择不分管理费
-                                        ledgerPlanFactoringAssignList.add(addPlanFactoringInsertAssign(ledgerDate, toAssignManagement, BigDecimal.ZERO,
+                                        ledgerPlanFactoringAssignList.add(addPlanFactoringInsertAssign(actualDate, toAssignManagement, BigDecimal.ZERO,
                                                 IncomeExpenditureTypeDict.ChildEnum.MANAGEMENT_FEE.getCode(), goodsAssignVo, 0));
                                     }
                                 }
@@ -1263,17 +1257,17 @@ public class LedgerManagementServiceImpl implements LedgerManagementService {
                                 BigDecimal toAssignInterest = refundInterest.negate();
                                 if (assignAmount.compareTo(BigDecimal.ZERO) > 0) {
                                     //这种场景可能存在未分配的管理费,要删除分账日期之前的状态为计划中的数据
-                                    deleteUnAssignList(interestFactoringList, ledgerPlanFactoringAssignList, goodsAssignVo, ledgerDate);
+                                    deleteUnAssignList(interestFactoringList, ledgerPlanFactoringAssignList, goodsAssignVo, actualDate);
                                     //判断是否需要分配
                                     if (goodsAssignVo.getHasAssignInterest()) {
                                         //如果需要分配利息
                                         if (assignAmount.compareTo(toAssignInterest) >= 0) {
-                                            ledgerPlanFactoringAssignList.add(addPlanFactoringInsertAssign(ledgerDate, toAssignInterest, toAssignInterest,
+                                            ledgerPlanFactoringAssignList.add(addPlanFactoringInsertAssign(actualDate, toAssignInterest, toAssignInterest,
                                                     IncomeExpenditureTypeDict.ChildEnum.INTEREST.getCode(), goodsAssignVo, 0));
                                             financeInterest = financeInterest.add(toAssignInterest);
                                             assignAmount = assignAmount.subtract(toAssignInterest);
                                         } else if (assignAmount.compareTo(toAssignInterest) < 0) {
-                                            ledgerPlanFactoringAssignList.add(addPlanFactoringInsertAssign(ledgerDate, assignAmount, assignAmount,
+                                            ledgerPlanFactoringAssignList.add(addPlanFactoringInsertAssign(actualDate, assignAmount, assignAmount,
                                                     IncomeExpenditureTypeDict.ChildEnum.INTEREST.getCode(), goodsAssignVo, 0));
                                             financeInterest = financeInterest.add(assignAmount);
                                             //剩余未分配利息
@@ -1282,7 +1276,7 @@ public class LedgerManagementServiceImpl implements LedgerManagementService {
                                         }
                                     } else {
                                         //如果不分配利息
-                                        ledgerPlanFactoringAssignList.add(addPlanFactoringInsertAssign(ledgerDate, toAssignInterest, BigDecimal.ZERO,
+                                        ledgerPlanFactoringAssignList.add(addPlanFactoringInsertAssign(actualDate, toAssignInterest, BigDecimal.ZERO,
                                                 IncomeExpenditureTypeDict.ChildEnum.INTEREST.getCode(), goodsAssignVo, 0));
                                     }
                                 }
@@ -1304,11 +1298,11 @@ public class LedgerManagementServiceImpl implements LedgerManagementService {
                                             if (assignAmount.compareTo(planFactoring.getAmount()) >= 0) {
                                                 //本金分配金额>计划金额、说明本金够分
                                                 //修改一笔本金收款记录
-                                                if (ledgerDate.before(planFactoring.getPlanDate())) {
+                                                if (actualDate.before(planFactoring.getPlanDate())) {
                                                     //分账日期早于计划日期
-                                                    planFactoring.setPlanDate(ledgerDate);
+                                                    planFactoring.setPlanDate(actualDate);
                                                 }
-                                                ledgerPlanFactoringAssignList.add(addPlanFactoringUpdateAssign(ledgerDate, planFactoring.getAmount(),
+                                                ledgerPlanFactoringAssignList.add(addPlanFactoringUpdateAssign(actualDate, planFactoring.getAmount(),
                                                         planFactoring, goodsAssignVo, 1));
                                                 assignAmount = assignAmount.subtract(planFactoring.getAmount());
                                                 returnedAmount = returnedAmount.subtract(planFactoring.getAmount());
@@ -1319,17 +1313,17 @@ public class LedgerManagementServiceImpl implements LedgerManagementService {
                                                     //判断本金状态是否逾期,如果逾期,本金不能拆分
                                                     if (PaymentCollectionPlanStatusDict.ChildEnum.OVERDUE.getCode().equals(planFactoring.getStatus().getCode())) {
                                                         //计划已逾期
-                                                        ledgerPlanFactoringAssignList.add(addPlanFactoringUpdateAssign(ledgerDate, assignAmount,
+                                                        ledgerPlanFactoringAssignList.add(addPlanFactoringUpdateAssign(actualDate, assignAmount,
                                                                 planFactoring, goodsAssignVo, 1));
                                                     } else {
-                                                        if (ledgerDate.before(planFactoring.getPlanDate())) {
+                                                        if (actualDate.before(planFactoring.getPlanDate())) {
                                                             //分账日期早于计划日期
-                                                            planFactoring.setPlanDate(ledgerDate);
+                                                            planFactoring.setPlanDate(actualDate);
                                                         }
                                                         planFactoring.setAmount(assignAmount);
                                                         planFactoring.setActualCashFlow(assignAmount);
                                                         //修改一笔本金收款记录
-                                                        ledgerPlanFactoringAssignList.add(addPlanFactoringUpdateAssign(ledgerDate, assignAmount,
+                                                        ledgerPlanFactoringAssignList.add(addPlanFactoringUpdateAssign(actualDate, assignAmount,
                                                                 planFactoring, goodsAssignVo, 1));
                                                         Date lastPlanDate = goodsAssignVo.getLastPlanDate();
                                                         //增加一笔剩余本金收款记录
@@ -1350,12 +1344,12 @@ public class LedgerManagementServiceImpl implements LedgerManagementService {
                                 //说明此分配本金已经分完了
                                 if (unAssignInterest.compareTo(BigDecimal.ZERO) < 0) {
                                     //将之前未分配的利息分完
-                                    ledgerPlanFactoringAssignList.add(addPlanFactoringInsertAssign(ledgerDate, unAssignInterest, BigDecimal.ZERO,
+                                    ledgerPlanFactoringAssignList.add(addPlanFactoringInsertAssign(actualDate, unAssignInterest, BigDecimal.ZERO,
                                             IncomeExpenditureTypeDict.ChildEnum.INTEREST.getCode(), goodsAssignVo, 0));
                                 }
                                 if (unAssignManagement.compareTo(BigDecimal.ZERO) < 0) {
                                     //将之前未分配的管理费分完
-                                    ledgerPlanFactoringAssignList.add(addPlanFactoringInsertAssign(ledgerDate, unAssignManagement, BigDecimal.ZERO,
+                                    ledgerPlanFactoringAssignList.add(addPlanFactoringInsertAssign(actualDate, unAssignManagement, BigDecimal.ZERO,
                                             IncomeExpenditureTypeDict.ChildEnum.MANAGEMENT_FEE.getCode(), goodsAssignVo, 0));
                                 }
                             } else if (returnedAmount.compareTo(BigDecimal.ZERO) > 0) {
@@ -1368,12 +1362,6 @@ public class LedgerManagementServiceImpl implements LedgerManagementService {
                                 }
                                 //增加一笔剩余利息计划
                                 //计算剩余应收利息
-                                Date actualDate;
-                                if (assignOverdueInterest) {
-                                    actualDate = new Date();
-                                }else {
-                                    actualDate = ledgerDate;
-                                }
                                 BigDecimal calculateInterest = calculateAssignInterest(returnedAmount, actualDate, lastPlanDate,
                                         !hasPrincipalAssign, paymentCalculateVo, IncomeExpenditureTypeDict.ChildEnum.INTEREST.getCode());
                                 BigDecimal surplusInterest = calculateInterest.add(unAssignInterest);