|
...
|
...
|
@@ -51,6 +51,7 @@ import java.math.RoundingMode; |
|
51
|
51
|
import java.time.LocalDate;
|
|
52
|
52
|
import java.time.LocalDateTime;
|
|
53
|
53
|
import java.time.YearMonth;
|
|
|
54
|
+import java.time.format.DateTimeFormatter;
|
|
54
|
55
|
import java.time.temporal.ChronoUnit;
|
|
55
|
56
|
import java.time.temporal.TemporalAdjusters;
|
|
56
|
57
|
import java.util.*;
|
|
...
|
...
|
@@ -483,6 +484,16 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge |
|
483
|
484
|
public PageResult<ReceiptLedgerReportBo> report(Integer pageIndex, Integer pageSize, ReceiptLedgerReportVo vo) {
|
|
484
|
485
|
Assert.greaterThanZero(pageIndex);
|
|
485
|
486
|
Assert.greaterThanZero(pageSize);
|
|
|
487
|
+ // 获取当月1号和当前时间
|
|
|
488
|
+ LocalDateTime endTime = LocalDateTime.now();
|
|
|
489
|
+ LocalDateTime startTime = LocalDate.now().withDayOfMonth(1).atStartOfDay();
|
|
|
490
|
+ if (vo.getStartTime() == null) {
|
|
|
491
|
+ vo.setStartTime(startTime);
|
|
|
492
|
+ }
|
|
|
493
|
+ if (vo.getEndTime() == null) {
|
|
|
494
|
+ vo.setEndTime(endTime);
|
|
|
495
|
+ }
|
|
|
496
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
486
|
497
|
// 开启分页
|
|
487
|
498
|
PageHelperUtil.startPage(pageIndex, pageSize);
|
|
488
|
499
|
List<ReceiptLedgerReportBo> dataList = getBaseMapper().report(vo);
|
|
...
|
...
|
@@ -491,11 +502,15 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge |
|
491
|
502
|
return result;
|
|
492
|
503
|
}
|
|
493
|
504
|
List<String> shortNames = dataList.stream().map(ReceiptLedgerReportBo::getCustomerShortName).distinct().collect(Collectors.toList());
|
|
494
|
|
- // 根据简称获取台账明细数据
|
|
495
|
|
- Map<String, List<ReceiptLedgerInfo>> agreementDataMap = getLedgerInfoByShortName(shortNames, Boolean.FALSE);
|
|
496
|
|
- Map<String, List<ReceiptLedgerInfo>> overdueDataMap = getLedgerInfoByShortName(shortNames, Boolean.TRUE);
|
|
|
505
|
+ // 获取当月所有台账明细数据(内贸)
|
|
|
506
|
+ QueryReceiptLedgerInfoVo ledgerInfoVo = new QueryReceiptLedgerInfoVo();
|
|
|
507
|
+ ledgerInfoVo.setType("INSIDE");
|
|
|
508
|
+ ledgerInfoVo.setCreateTimeStart(startTime.format(formatter));
|
|
|
509
|
+ ledgerInfoVo.setCreateTimeEnd(endTime.format(formatter));
|
|
|
510
|
+ List<ReceiptLedgerInfo> ledgerInfoList = getBaseMapper().query(ledgerInfoVo);
|
|
497
|
511
|
// 统计各个阶段欠款金额数据
|
|
498
|
|
- List<Map<String, Object>> debtAmountList = getBaseMapper().statisticsDebtByShortName(shortNames, null, "INSIDE");
|
|
|
512
|
+ List<Map<String, Object>> debtAmountList = getBaseMapper().statisticsDebtByShortName(shortNames, null, "INSIDE"
|
|
|
513
|
+ , vo.getStartTime(), vo.getEndTime());
|
|
499
|
514
|
if (CollectionUtils.isEmpty(debtAmountList)) {
|
|
500
|
515
|
return result;
|
|
501
|
516
|
}
|
|
...
|
...
|
@@ -511,6 +526,7 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge |
|
511
|
526
|
List<Map<String, Object>> list = debtMap.computeIfAbsent(shortName, k -> new ArrayList<>());
|
|
512
|
527
|
list.add(map);
|
|
513
|
528
|
}
|
|
|
529
|
+ Set<String> customerNames = new HashSet<>();
|
|
514
|
530
|
// 获取待交付订货单数
|
|
515
|
531
|
Map<String, Long> orderCountMap = shipmentsOrderInfoService.countWaitDeliveredOrder(customerNameList);
|
|
516
|
532
|
for (ReceiptLedgerReportBo report : dataList) {
|
|
...
|
...
|
@@ -520,28 +536,19 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge |
|
520
|
536
|
continue;
|
|
521
|
537
|
}
|
|
522
|
538
|
long waitDeliveredOrderTotal = 0;
|
|
523
|
|
- List<String> creditStatusList = new ArrayList<>();
|
|
524
|
|
- List<String> debtStates = new ArrayList<>();
|
|
525
|
539
|
Map<String, ReceiptLedgerReportDetail> reportDetailMap = new LinkedHashMap<>();
|
|
526
|
540
|
for (Map<String, Object> map : list) {
|
|
527
|
541
|
String customerName = (String) map.get("name");
|
|
528
|
542
|
String debtStatus = (String) map.get("debt_status");
|
|
529
|
|
- debtStates.add(debtStatus);
|
|
530
|
543
|
BigDecimal debtAmount = (BigDecimal) map.get("debt_amount");
|
|
531
|
544
|
|
|
532
|
545
|
ReceiptLedgerReportDetail reportDetail = reportDetailMap.get(customerName);
|
|
533
|
546
|
if (reportDetail == null) {
|
|
534
|
547
|
reportDetail = new ReceiptLedgerReportDetail();
|
|
|
548
|
+ reportDetail.setCustomerName(customerName);
|
|
535
|
549
|
}
|
|
536
|
|
- reportDetail.setCustomerName(customerName);
|
|
537
|
|
- if ("AGREEMENT".equals(debtStatus) || "DEPOSIT".equals(debtStatus)) {
|
|
538
|
|
- BigDecimal agreement = reportDetail.getAgreement();
|
|
539
|
|
- if (agreement == null) {
|
|
540
|
|
- agreement = debtAmount;
|
|
541
|
|
- } else {
|
|
542
|
|
- agreement = agreement.add(debtAmount);
|
|
543
|
|
- }
|
|
544
|
|
- reportDetail.setAgreement(valueConvert(agreement));
|
|
|
550
|
+ if ("AGREEMENT".equals(debtStatus)) {
|
|
|
551
|
+ reportDetail.setAgreement(valueConvert(debtAmount));
|
|
545
|
552
|
reportDetail.setTimingStatus("约定内");
|
|
546
|
553
|
} else if ("FIRST_COORDINATE".equals(debtStatus)) {
|
|
547
|
554
|
reportDetail.setFirstCoordinate(valueConvert(debtAmount));
|
|
...
|
...
|
@@ -553,17 +560,13 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge |
|
553
|
560
|
reportDetail.setClearDebt(valueConvert(debtAmount));
|
|
554
|
561
|
reportDetail.setTimingStatus("超期3");
|
|
555
|
562
|
}
|
|
556
|
|
- // 计算超额数据(授信状态)
|
|
557
|
|
- String creditStatus = calculateExcess(debtAmount, report.getQuota());
|
|
558
|
|
- if (StringUtils.isNotBlank(creditStatus)) {
|
|
559
|
|
- report.setCreditStatus(creditStatus);
|
|
560
|
|
- creditStatusList.add(creditStatus);
|
|
561
|
|
- }
|
|
562
|
563
|
// 统计待交付订单数
|
|
563
|
564
|
Long count = orderCountMap.get(customerName);
|
|
564
|
|
- if (count != null) {
|
|
|
565
|
+ if (count != null && !customerNames.contains(customerName)) {
|
|
565
|
566
|
waitDeliveredOrderTotal += count;
|
|
566
|
567
|
reportDetail.setWaitDeliveredOrder(count);
|
|
|
568
|
+ // 防止重复相加
|
|
|
569
|
+ customerNames.add(customerName);
|
|
567
|
570
|
}
|
|
568
|
571
|
// 计算总欠款
|
|
569
|
572
|
BigDecimal debtTotal = reportDetail.getDebtTotal();
|
|
...
|
...
|
@@ -577,22 +580,28 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge |
|
577
|
580
|
}
|
|
578
|
581
|
List<ReceiptLedgerReportDetail> details = new ArrayList<>(reportDetailMap.values());
|
|
579
|
582
|
if (CollectionUtils.isNotEmpty(details)) {
|
|
580
|
|
- // 转换成万元
|
|
581
|
583
|
for (ReceiptLedgerReportDetail detail : details) {
|
|
|
584
|
+ // 转换成万元
|
|
582
|
585
|
BigDecimal debtTotal = detail.getDebtTotal();
|
|
583
|
586
|
detail.setDebtTotal(valueConvert(debtTotal));
|
|
|
587
|
+ // 计算超额数据(授信状态)
|
|
|
588
|
+ String creditStatus = calculateExcess(debtTotal, report.getQuota());
|
|
|
589
|
+ if (StringUtils.isNotBlank(creditStatus)) {
|
|
|
590
|
+ detail.setCreditStatus(creditStatus);
|
|
|
591
|
+ }
|
|
584
|
592
|
}
|
|
585
|
593
|
}
|
|
586
|
594
|
report.setDetailList(details);
|
|
587
|
595
|
|
|
588
|
596
|
// 处理约定内、一次协调、二次协调、清欠小计数据
|
|
589
|
|
- handleSubtotal(agreementDataMap, overdueDataMap, report);
|
|
590
|
|
- // 授时状态
|
|
591
|
|
- report.setTimingStatus(getHighestPriorityStatus(debtStates));
|
|
|
597
|
+ handleSubtotal(ledgerInfoList, report);
|
|
592
|
598
|
// 授信状态
|
|
593
|
|
- report.setCreditStatus(findMaxPercentageString(creditStatusList));
|
|
594
|
|
- report.setWaitDeliveredOrderTotal(waitDeliveredOrderTotal);
|
|
595
|
599
|
BigDecimal debtTotal = report.getDebtTotal();
|
|
|
600
|
+ String creditStatus = calculateExcess(debtTotal, report.getQuota());
|
|
|
601
|
+ if (StringUtils.isNotBlank(creditStatus)) {
|
|
|
602
|
+ report.setCreditStatus(creditStatus);
|
|
|
603
|
+ }
|
|
|
604
|
+ report.setWaitDeliveredOrderTotal(waitDeliveredOrderTotal);
|
|
596
|
605
|
report.setDebtTotal(valueConvert(debtTotal));
|
|
597
|
606
|
}
|
|
598
|
607
|
return result;
|
|
...
|
...
|
@@ -1032,13 +1041,111 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge |
|
1032
|
1041
|
/**
|
|
1033
|
1042
|
* 处理“小计”数据
|
|
1034
|
1043
|
*
|
|
1035
|
|
- * @param agreementDataMap 约定内数据集合
|
|
1036
|
|
- * @param overdueDataMap 逾期数据集合
|
|
1037
|
|
- * @param report 报表数据
|
|
|
1044
|
+ * @param ledgerInfoList 台账明细数据
|
|
|
1045
|
+ * @param report 报表数据
|
|
1038
|
1046
|
*/
|
|
1039
|
|
- private void handleSubtotal(Map<String, List<ReceiptLedgerInfo>> agreementDataMap, Map<String, List<ReceiptLedgerInfo>> overdueDataMap
|
|
1040
|
|
- , ReceiptLedgerReportBo report) {
|
|
1041
|
|
- String customerShortName = report.getCustomerShortName();
|
|
|
1047
|
+ private void handleSubtotal(List<ReceiptLedgerInfo> ledgerInfoList, ReceiptLedgerReportBo report) {
|
|
|
1048
|
+ if (CollectionUtils.isEmpty(ledgerInfoList) || report == null) {
|
|
|
1049
|
+ return;
|
|
|
1050
|
+ }
|
|
|
1051
|
+ BigDecimal debtTotal = report.getDebtTotal();
|
|
|
1052
|
+ // 约定内欠款
|
|
|
1053
|
+ BigDecimal agreement = getAgreementDebt(ledgerInfoList, report);
|
|
|
1054
|
+ if (agreement.compareTo(debtTotal) >= 0) {
|
|
|
1055
|
+ report.setAgreementTotal(valueConvert(debtTotal));
|
|
|
1056
|
+ report.setTimingStatus("约定内");
|
|
|
1057
|
+ return;
|
|
|
1058
|
+ }
|
|
|
1059
|
+ // 一次协调欠款
|
|
|
1060
|
+ BigDecimal firstCoordinate = BigDecimal.ZERO;
|
|
|
1061
|
+ for (ReceiptLedgerInfo ledgerInfo : ledgerInfoList) {
|
|
|
1062
|
+ String customerShortName = report.getCustomerShortName();
|
|
|
1063
|
+ if (!customerShortName.equals(ledgerInfo.getCustomerShortName())) {
|
|
|
1064
|
+ continue;
|
|
|
1065
|
+ }
|
|
|
1066
|
+ BigDecimal startAccountReceivable = ledgerInfo.getStartAccountReceivable();
|
|
|
1067
|
+ String debtStatus = ledgerInfo.getDebtStatus();
|
|
|
1068
|
+ if ("FIRST_COORDINATE".equals(debtStatus)) {
|
|
|
1069
|
+ firstCoordinate = firstCoordinate.add(startAccountReceivable);
|
|
|
1070
|
+ }
|
|
|
1071
|
+ }
|
|
|
1072
|
+ if (firstCoordinate.add(agreement).compareTo(debtTotal) >= 0) {
|
|
|
1073
|
+ BigDecimal difference = debtTotal.subtract(agreement);
|
|
|
1074
|
+ report.setAgreementTotal(valueConvert(agreement));
|
|
|
1075
|
+ report.setFirstCoordinateTotal(valueConvert(difference));
|
|
|
1076
|
+ report.setTimingStatus("超期1");
|
|
|
1077
|
+ return;
|
|
|
1078
|
+ }
|
|
|
1079
|
+ // 二次协调欠款
|
|
|
1080
|
+ BigDecimal secondCoordinate = BigDecimal.ZERO;
|
|
|
1081
|
+ for (ReceiptLedgerInfo ledgerInfo : ledgerInfoList) {
|
|
|
1082
|
+ String customerShortName = report.getCustomerShortName();
|
|
|
1083
|
+ if (!customerShortName.equals(ledgerInfo.getCustomerShortName())) {
|
|
|
1084
|
+ continue;
|
|
|
1085
|
+ }
|
|
|
1086
|
+ BigDecimal startAccountReceivable = ledgerInfo.getStartAccountReceivable();
|
|
|
1087
|
+ String debtStatus = ledgerInfo.getDebtStatus();
|
|
|
1088
|
+ if ("SECOND_COORDINATE".equals(debtStatus)) {
|
|
|
1089
|
+ secondCoordinate = secondCoordinate.add(startAccountReceivable);
|
|
|
1090
|
+ }
|
|
|
1091
|
+ }
|
|
|
1092
|
+ BigDecimal secondCoordinateDifference = debtTotal.subtract(agreement).subtract(firstCoordinate);
|
|
|
1093
|
+ if (secondCoordinate.add(firstCoordinate).add(agreement).compareTo(debtTotal) >= 0) {
|
|
|
1094
|
+ report.setAgreementTotal(valueConvert(agreement));
|
|
|
1095
|
+ report.setFirstCoordinateTotal(valueConvert(firstCoordinate));
|
|
|
1096
|
+ report.setSecondCoordinateTotal(valueConvert(secondCoordinateDifference));
|
|
|
1097
|
+ report.setTimingStatus("超期2");
|
|
|
1098
|
+ return;
|
|
|
1099
|
+ }
|
|
|
1100
|
+ // 清欠阶段欠款
|
|
|
1101
|
+ BigDecimal clearDebt = BigDecimal.ZERO;
|
|
|
1102
|
+ for (ReceiptLedgerInfo ledgerInfo : ledgerInfoList) {
|
|
|
1103
|
+ String customerShortName = report.getCustomerShortName();
|
|
|
1104
|
+ if (!customerShortName.equals(ledgerInfo.getCustomerShortName())) {
|
|
|
1105
|
+ continue;
|
|
|
1106
|
+ }
|
|
|
1107
|
+ BigDecimal startAccountReceivable = ledgerInfo.getStartAccountReceivable();
|
|
|
1108
|
+ String debtStatus = ledgerInfo.getDebtStatus();
|
|
|
1109
|
+ if ("CLEAR_DEBTS".equals(debtStatus)) {
|
|
|
1110
|
+ clearDebt = clearDebt.add(startAccountReceivable);
|
|
|
1111
|
+ }
|
|
|
1112
|
+ }
|
|
|
1113
|
+ report.setAgreementTotal(valueConvert(agreement));
|
|
|
1114
|
+ report.setFirstCoordinateTotal(valueConvert(firstCoordinate));
|
|
|
1115
|
+ report.setSecondCoordinateTotal(valueConvert(secondCoordinate));
|
|
|
1116
|
+ report.setTimingStatus("超期3");
|
|
|
1117
|
+ if (clearDebt.add(secondCoordinate).add(firstCoordinate).add(agreement).compareTo(debtTotal) >= 0) {
|
|
|
1118
|
+ BigDecimal difference = secondCoordinateDifference.subtract(secondCoordinate);
|
|
|
1119
|
+ report.setClearDebtTotal(valueConvert(difference));
|
|
|
1120
|
+ } else {
|
|
|
1121
|
+ report.setClearDebtTotal(valueConvert(clearDebt));
|
|
|
1122
|
+ }
|
|
|
1123
|
+ }
|
|
|
1124
|
+
|
|
|
1125
|
+ /**
|
|
|
1126
|
+ * 获取约定内欠款小计
|
|
|
1127
|
+ *
|
|
|
1128
|
+ * @param ledgerInfoList 应收款台账明细数据
|
|
|
1129
|
+ * @param report 报表数据
|
|
|
1130
|
+ * @return BigDecimal
|
|
|
1131
|
+ */
|
|
|
1132
|
+ private static BigDecimal getAgreementDebt(List<ReceiptLedgerInfo> ledgerInfoList, ReceiptLedgerReportBo report) {
|
|
|
1133
|
+ BigDecimal agreement = BigDecimal.ZERO;
|
|
|
1134
|
+ for (ReceiptLedgerInfo ledgerInfo : ledgerInfoList) {
|
|
|
1135
|
+ String customerShortName = report.getCustomerShortName();
|
|
|
1136
|
+ if (!customerShortName.equals(ledgerInfo.getCustomerShortName())) {
|
|
|
1137
|
+ continue;
|
|
|
1138
|
+ }
|
|
|
1139
|
+ BigDecimal startAccountReceivable = ledgerInfo.getStartAccountReceivable();
|
|
|
1140
|
+ String debtStatus = ledgerInfo.getDebtStatus();
|
|
|
1141
|
+ if ("AGREEMENT".equals(debtStatus) || "SETTLE_UP".equals(debtStatus)) {
|
|
|
1142
|
+ agreement = agreement.add(startAccountReceivable);
|
|
|
1143
|
+ } else if ("DEPOSIT".equals(debtStatus)) {
|
|
|
1144
|
+ BigDecimal endAccountReceivable = ledgerInfo.getEndAccountReceivable();
|
|
|
1145
|
+ agreement = agreement.add(endAccountReceivable.abs());
|
|
|
1146
|
+ }
|
|
|
1147
|
+ }
|
|
|
1148
|
+ return agreement;
|
|
1042
|
1149
|
}
|
|
1043
|
1150
|
|
|
1044
|
1151
|
|
|
...
|
...
|
@@ -1099,8 +1206,12 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge |
|
1099
|
1206
|
}
|
|
1100
|
1207
|
data.setSettleTerm(credit.getCompanySettlementPeriod());
|
|
1101
|
1208
|
}
|
|
1102
|
|
- data.setDeptId(deptId);
|
|
1103
|
|
- data.setRegion(region);
|
|
|
1209
|
+ if (StringUtils.isNotBlank(deptId) && !deptId.equals("null")) {
|
|
|
1210
|
+ data.setDeptId(deptId);
|
|
|
1211
|
+ }
|
|
|
1212
|
+ if (StringUtils.isNotBlank(region) && !region.equals("null")) {
|
|
|
1213
|
+ data.setRegion(region);
|
|
|
1214
|
+ }
|
|
1104
|
1215
|
data.setCustomerId(shipmentsOrderInfo.getCustomerId());
|
|
1105
|
1216
|
data.setShipmentDate(shipmentsOrderInfo.getShipmentsDate());
|
|
1106
|
1217
|
|
...
|
...
|
|