|
...
|
...
|
@@ -28,6 +28,7 @@ import com.lframework.starter.common.utils.Assert; |
|
28
|
28
|
import com.lframework.xingyun.sc.service.customer.CustomerCreditService;
|
|
29
|
29
|
import com.lframework.xingyun.sc.service.order.PurchaseOrderInfoService;
|
|
30
|
30
|
import com.lframework.xingyun.sc.service.order.PurchaseOrderLineService;
|
|
|
31
|
+import com.lframework.xingyun.sc.service.shipments.ShipmentsOrderInfoService;
|
|
31
|
32
|
import com.lframework.xingyun.sc.utils.CommonUtil;
|
|
32
|
33
|
import com.lframework.xingyun.sc.vo.ledger.receipt.*;
|
|
33
|
34
|
import org.apache.commons.collections4.CollectionUtils;
|
|
...
|
...
|
@@ -61,6 +62,17 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge |
|
61
|
62
|
private PurchaseOrderInfoService purchaseOrderInfoService;
|
|
62
|
63
|
@Resource
|
|
63
|
64
|
private PurchaseOrderLineService purchaseOrderLineService;
|
|
|
65
|
+ @Resource
|
|
|
66
|
+ private ShipmentsOrderInfoService shipmentsOrderInfoService;
|
|
|
67
|
+
|
|
|
68
|
+
|
|
|
69
|
+ // 定义状态优先级顺序(从高到低)
|
|
|
70
|
+ private static final List<String> STATUS_PRIORITY = Arrays.asList(
|
|
|
71
|
+ "CLEAR_DEBTS",
|
|
|
72
|
+ "SECOND_COORDINATE",
|
|
|
73
|
+ "FIRST_COORDINATE",
|
|
|
74
|
+ "AGREEMENT"
|
|
|
75
|
+ );
|
|
64
|
76
|
|
|
65
|
77
|
|
|
66
|
78
|
|
|
...
|
...
|
@@ -416,10 +428,16 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge |
|
416
|
428
|
// 根据简称分组
|
|
417
|
429
|
Map<String, List<Map<String, Object>>> debtMap = new HashMap<>();
|
|
418
|
430
|
for (Map<String, Object> map : debtAmountList) {
|
|
|
431
|
+ String name = (String) map.get("name");
|
|
|
432
|
+ if (!customerNameList.contains(name)) {
|
|
|
433
|
+ customerNameList.add(name);
|
|
|
434
|
+ }
|
|
419
|
435
|
String shortName = (String) map.get("short_name");
|
|
420
|
436
|
List<Map<String, Object>> list = debtMap.computeIfAbsent(shortName, k -> new ArrayList<>());
|
|
421
|
437
|
list.add(map);
|
|
422
|
438
|
}
|
|
|
439
|
+ // 获取待交付订货单数
|
|
|
440
|
+ Map<String, Long> orderCountMap = shipmentsOrderInfoService.countWaitDeliveredOrder(customerNameList);
|
|
423
|
441
|
for (ReceiptLedgerReportBo report : dataList) {
|
|
424
|
442
|
String customerShortName = report.getCustomerShortName();
|
|
425
|
443
|
List<Map<String, Object>> list = debtMap.get(customerShortName);
|
|
...
|
...
|
@@ -431,11 +449,13 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge |
|
431
|
449
|
BigDecimal firstCoordinateTotal = BigDecimal.ZERO;
|
|
432
|
450
|
BigDecimal secondCoordinateTotal = BigDecimal.ZERO;
|
|
433
|
451
|
BigDecimal clearDebtTotal = BigDecimal.ZERO;
|
|
434
|
|
- Integer waitDeliveredOrderTotal = 0;
|
|
435
|
|
- Map<String, ReceiptLedgerReportDetail> reportDetailMap = new HashMap<>();
|
|
|
452
|
+ long waitDeliveredOrderTotal = 0;
|
|
|
453
|
+ List<String> debtStates = new ArrayList<>();
|
|
|
454
|
+ Map<String, ReceiptLedgerReportDetail> reportDetailMap = new LinkedHashMap<>();
|
|
436
|
455
|
for (Map<String, Object> map : list) {
|
|
437
|
456
|
String customerName = (String) map.get("name");
|
|
438
|
457
|
String debtStatus = (String) map.get("debt_status");
|
|
|
458
|
+ debtStates.add(debtStatus);
|
|
439
|
459
|
BigDecimal debtAmount = (BigDecimal) map.get("debt_amount");
|
|
440
|
460
|
|
|
441
|
461
|
ReceiptLedgerReportDetail reportDetail = reportDetailMap.get(customerName);
|
|
...
|
...
|
@@ -443,20 +463,31 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge |
|
443
|
463
|
reportDetail = new ReceiptLedgerReportDetail();
|
|
444
|
464
|
}
|
|
445
|
465
|
reportDetail.setCustomerName(customerName);
|
|
|
466
|
+ reportDetail.setCreditStatus(debtStatus);
|
|
446
|
467
|
if ("AGREEMENT".equals(debtStatus)) {
|
|
447
|
468
|
reportDetail.setAgreement(valueConvert(debtAmount));
|
|
448
|
469
|
agreementTotal = agreementTotal.add(debtAmount);
|
|
|
470
|
+ reportDetail.setCreditStatus("约定内");
|
|
449
|
471
|
} else if ("FIRST_COORDINATE".equals(debtStatus)) {
|
|
450
|
472
|
reportDetail.setFirstCoordinate(valueConvert(debtAmount));
|
|
451
|
473
|
firstCoordinateTotal = firstCoordinateTotal.add(debtAmount);
|
|
|
474
|
+ reportDetail.setCreditStatus("超期1");
|
|
452
|
475
|
} else if ("SECOND_COORDINATE".equals(debtStatus)) {
|
|
453
|
476
|
reportDetail.setSecondCoordinate(valueConvert(debtAmount));
|
|
454
|
477
|
secondCoordinateTotal = secondCoordinateTotal.add(debtAmount);
|
|
|
478
|
+ reportDetail.setCreditStatus("超期2");
|
|
455
|
479
|
} else if ("CLEAR_DEBTS".equals(debtStatus)) {
|
|
456
|
480
|
reportDetail.setClearDebt(valueConvert(debtAmount));
|
|
457
|
481
|
clearDebtTotal = clearDebtTotal.add(debtAmount);
|
|
|
482
|
+ reportDetail.setCreditStatus("超期3");
|
|
458
|
483
|
}
|
|
459
|
484
|
debtTotal = debtTotal.add(debtAmount);
|
|
|
485
|
+ // 统计待交付订单数
|
|
|
486
|
+ Long count = orderCountMap.get(customerName);
|
|
|
487
|
+ if (count != null) {
|
|
|
488
|
+ waitDeliveredOrderTotal += count;
|
|
|
489
|
+ reportDetail.setWaitDeliveredOrder(count);
|
|
|
490
|
+ }
|
|
460
|
491
|
|
|
461
|
492
|
reportDetailMap.put(reportDetail.getCustomerName(), reportDetail);
|
|
462
|
493
|
}
|
|
...
|
...
|
@@ -468,6 +499,8 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge |
|
468
|
499
|
report.setFirstCoordinateTotal(valueConvert(firstCoordinateTotal));
|
|
469
|
500
|
report.setSecondCoordinateTotal(valueConvert(secondCoordinateTotal));
|
|
470
|
501
|
report.setClearDebtTotal(valueConvert(clearDebtTotal));
|
|
|
502
|
+ report.setCreditStatus(getHighestPriorityStatus(debtStates));
|
|
|
503
|
+ // 处理超额逻辑
|
|
471
|
504
|
report.setWaitDeliveredOrderTotal(waitDeliveredOrderTotal);
|
|
472
|
505
|
}
|
|
473
|
506
|
return result;
|
|
...
|
...
|
@@ -608,4 +641,46 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge |
|
608
|
641
|
OpLogUtil.setVariable("id", data.getId());
|
|
609
|
642
|
OpLogUtil.setExtra(vo);
|
|
610
|
643
|
}
|
|
|
644
|
+
|
|
|
645
|
+
|
|
|
646
|
+ /**
|
|
|
647
|
+ * 从多个状态中获取最高优先级的状态
|
|
|
648
|
+ *
|
|
|
649
|
+ * @param statusList 当前存在的状态列表
|
|
|
650
|
+ * @return 最高优先级的状态,如果没有匹配则返回null
|
|
|
651
|
+ */
|
|
|
652
|
+ public static String getHighestPriorityStatus(List<String> statusList) {
|
|
|
653
|
+ if (statusList == null || statusList.isEmpty()) {
|
|
|
654
|
+ return null;
|
|
|
655
|
+ }
|
|
|
656
|
+ String result = null;
|
|
|
657
|
+ Set<String> statusSet = new HashSet<>(statusList);
|
|
|
658
|
+ // 按照优先级顺序查找第一个匹配的状态
|
|
|
659
|
+ for (String status : STATUS_PRIORITY) {
|
|
|
660
|
+ if (statusSet.contains(status)) {
|
|
|
661
|
+ result = status;
|
|
|
662
|
+ break;
|
|
|
663
|
+ }
|
|
|
664
|
+ }
|
|
|
665
|
+ if (result == null) {
|
|
|
666
|
+ return null;
|
|
|
667
|
+ }
|
|
|
668
|
+ switch (result) {
|
|
|
669
|
+ case "AGREEMENT":
|
|
|
670
|
+ result = "约定内";
|
|
|
671
|
+ break;
|
|
|
672
|
+ case "FIRST_COORDINATE":
|
|
|
673
|
+ result = "超期1";
|
|
|
674
|
+ break;
|
|
|
675
|
+ case "SECOND_COORDINATE":
|
|
|
676
|
+ result = "超期2";
|
|
|
677
|
+ break;
|
|
|
678
|
+ case "CLEAR_DEBTS":
|
|
|
679
|
+ result = "超期3";
|
|
|
680
|
+ break;
|
|
|
681
|
+ default:
|
|
|
682
|
+ break;
|
|
|
683
|
+ }
|
|
|
684
|
+ return result;
|
|
|
685
|
+ }
|
|
611
|
686
|
} |
...
|
...
|
|