Commit 596cf8ccb3a85b41d9860b5cb8c237ee917cedb5

Authored by yeqianyong
1 parent 70b10676

楚江erp:应收款台账报表统计数据补充

@@ -121,5 +121,5 @@ public class ReceiptLedgerReportBo { @@ -121,5 +121,5 @@ public class ReceiptLedgerReportBo {
121 * 待交付订单总数 121 * 待交付订单总数
122 */ 122 */
123 @ApiModelProperty("待交付订单总数") 123 @ApiModelProperty("待交付订单总数")
124 - private Integer waitDeliveredOrderTotal; 124 + private Long waitDeliveredOrderTotal;
125 } 125 }
@@ -71,6 +71,6 @@ public class ReceiptLedgerReportDetail { @@ -71,6 +71,6 @@ public class ReceiptLedgerReportDetail {
71 /** 71 /**
72 * 待交付订单数量 72 * 待交付订单数量
73 */ 73 */
74 - @ApiModelProperty("授时状态")  
75 - private Integer waitDeliveredOrder; 74 + @ApiModelProperty("待交付订单数量")
  75 + private Long waitDeliveredOrder;
76 } 76 }
@@ -28,6 +28,7 @@ import com.lframework.starter.common.utils.Assert; @@ -28,6 +28,7 @@ import com.lframework.starter.common.utils.Assert;
28 import com.lframework.xingyun.sc.service.customer.CustomerCreditService; 28 import com.lframework.xingyun.sc.service.customer.CustomerCreditService;
29 import com.lframework.xingyun.sc.service.order.PurchaseOrderInfoService; 29 import com.lframework.xingyun.sc.service.order.PurchaseOrderInfoService;
30 import com.lframework.xingyun.sc.service.order.PurchaseOrderLineService; 30 import com.lframework.xingyun.sc.service.order.PurchaseOrderLineService;
  31 +import com.lframework.xingyun.sc.service.shipments.ShipmentsOrderInfoService;
31 import com.lframework.xingyun.sc.utils.CommonUtil; 32 import com.lframework.xingyun.sc.utils.CommonUtil;
32 import com.lframework.xingyun.sc.vo.ledger.receipt.*; 33 import com.lframework.xingyun.sc.vo.ledger.receipt.*;
33 import org.apache.commons.collections4.CollectionUtils; 34 import org.apache.commons.collections4.CollectionUtils;
@@ -61,6 +62,17 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge @@ -61,6 +62,17 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge
61 private PurchaseOrderInfoService purchaseOrderInfoService; 62 private PurchaseOrderInfoService purchaseOrderInfoService;
62 @Resource 63 @Resource
63 private PurchaseOrderLineService purchaseOrderLineService; 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,10 +428,16 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge
416 // 根据简称分组 428 // 根据简称分组
417 Map<String, List<Map<String, Object>>> debtMap = new HashMap<>(); 429 Map<String, List<Map<String, Object>>> debtMap = new HashMap<>();
418 for (Map<String, Object> map : debtAmountList) { 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 String shortName = (String) map.get("short_name"); 435 String shortName = (String) map.get("short_name");
420 List<Map<String, Object>> list = debtMap.computeIfAbsent(shortName, k -> new ArrayList<>()); 436 List<Map<String, Object>> list = debtMap.computeIfAbsent(shortName, k -> new ArrayList<>());
421 list.add(map); 437 list.add(map);
422 } 438 }
  439 + // 获取待交付订货单数
  440 + Map<String, Long> orderCountMap = shipmentsOrderInfoService.countWaitDeliveredOrder(customerNameList);
423 for (ReceiptLedgerReportBo report : dataList) { 441 for (ReceiptLedgerReportBo report : dataList) {
424 String customerShortName = report.getCustomerShortName(); 442 String customerShortName = report.getCustomerShortName();
425 List<Map<String, Object>> list = debtMap.get(customerShortName); 443 List<Map<String, Object>> list = debtMap.get(customerShortName);
@@ -431,11 +449,13 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge @@ -431,11 +449,13 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge
431 BigDecimal firstCoordinateTotal = BigDecimal.ZERO; 449 BigDecimal firstCoordinateTotal = BigDecimal.ZERO;
432 BigDecimal secondCoordinateTotal = BigDecimal.ZERO; 450 BigDecimal secondCoordinateTotal = BigDecimal.ZERO;
433 BigDecimal clearDebtTotal = BigDecimal.ZERO; 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 for (Map<String, Object> map : list) { 455 for (Map<String, Object> map : list) {
437 String customerName = (String) map.get("name"); 456 String customerName = (String) map.get("name");
438 String debtStatus = (String) map.get("debt_status"); 457 String debtStatus = (String) map.get("debt_status");
  458 + debtStates.add(debtStatus);
439 BigDecimal debtAmount = (BigDecimal) map.get("debt_amount"); 459 BigDecimal debtAmount = (BigDecimal) map.get("debt_amount");
440 460
441 ReceiptLedgerReportDetail reportDetail = reportDetailMap.get(customerName); 461 ReceiptLedgerReportDetail reportDetail = reportDetailMap.get(customerName);
@@ -443,20 +463,31 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge @@ -443,20 +463,31 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge
443 reportDetail = new ReceiptLedgerReportDetail(); 463 reportDetail = new ReceiptLedgerReportDetail();
444 } 464 }
445 reportDetail.setCustomerName(customerName); 465 reportDetail.setCustomerName(customerName);
  466 + reportDetail.setCreditStatus(debtStatus);
446 if ("AGREEMENT".equals(debtStatus)) { 467 if ("AGREEMENT".equals(debtStatus)) {
447 reportDetail.setAgreement(valueConvert(debtAmount)); 468 reportDetail.setAgreement(valueConvert(debtAmount));
448 agreementTotal = agreementTotal.add(debtAmount); 469 agreementTotal = agreementTotal.add(debtAmount);
  470 + reportDetail.setCreditStatus("约定内");
449 } else if ("FIRST_COORDINATE".equals(debtStatus)) { 471 } else if ("FIRST_COORDINATE".equals(debtStatus)) {
450 reportDetail.setFirstCoordinate(valueConvert(debtAmount)); 472 reportDetail.setFirstCoordinate(valueConvert(debtAmount));
451 firstCoordinateTotal = firstCoordinateTotal.add(debtAmount); 473 firstCoordinateTotal = firstCoordinateTotal.add(debtAmount);
  474 + reportDetail.setCreditStatus("超期1");
452 } else if ("SECOND_COORDINATE".equals(debtStatus)) { 475 } else if ("SECOND_COORDINATE".equals(debtStatus)) {
453 reportDetail.setSecondCoordinate(valueConvert(debtAmount)); 476 reportDetail.setSecondCoordinate(valueConvert(debtAmount));
454 secondCoordinateTotal = secondCoordinateTotal.add(debtAmount); 477 secondCoordinateTotal = secondCoordinateTotal.add(debtAmount);
  478 + reportDetail.setCreditStatus("超期2");
455 } else if ("CLEAR_DEBTS".equals(debtStatus)) { 479 } else if ("CLEAR_DEBTS".equals(debtStatus)) {
456 reportDetail.setClearDebt(valueConvert(debtAmount)); 480 reportDetail.setClearDebt(valueConvert(debtAmount));
457 clearDebtTotal = clearDebtTotal.add(debtAmount); 481 clearDebtTotal = clearDebtTotal.add(debtAmount);
  482 + reportDetail.setCreditStatus("超期3");
458 } 483 }
459 debtTotal = debtTotal.add(debtAmount); 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 reportDetailMap.put(reportDetail.getCustomerName(), reportDetail); 492 reportDetailMap.put(reportDetail.getCustomerName(), reportDetail);
462 } 493 }
@@ -468,6 +499,8 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge @@ -468,6 +499,8 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge
468 report.setFirstCoordinateTotal(valueConvert(firstCoordinateTotal)); 499 report.setFirstCoordinateTotal(valueConvert(firstCoordinateTotal));
469 report.setSecondCoordinateTotal(valueConvert(secondCoordinateTotal)); 500 report.setSecondCoordinateTotal(valueConvert(secondCoordinateTotal));
470 report.setClearDebtTotal(valueConvert(clearDebtTotal)); 501 report.setClearDebtTotal(valueConvert(clearDebtTotal));
  502 + report.setCreditStatus(getHighestPriorityStatus(debtStates));
  503 + // 处理超额逻辑
471 report.setWaitDeliveredOrderTotal(waitDeliveredOrderTotal); 504 report.setWaitDeliveredOrderTotal(waitDeliveredOrderTotal);
472 } 505 }
473 return result; 506 return result;
@@ -608,4 +641,46 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge @@ -608,4 +641,46 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge
608 OpLogUtil.setVariable("id", data.getId()); 641 OpLogUtil.setVariable("id", data.getId());
609 OpLogUtil.setExtra(vo); 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 }
@@ -513,6 +513,25 @@ public class ShipmentsOrderInfoServiceImpl extends BaseMpServiceImpl<ShipmentsOr @@ -513,6 +513,25 @@ public class ShipmentsOrderInfoServiceImpl extends BaseMpServiceImpl<ShipmentsOr
513 return result; 513 return result;
514 } 514 }
515 515
  516 + @Override
  517 + public Map<String, Long> countWaitDeliveredOrder(List<String> customerNames) {
  518 + if (CollectionUtils.isEmpty(customerNames)) {
  519 + return Collections.emptyMap();
  520 + }
  521 + List<Map<String, Object>> mapList = getBaseMapper().countWaitDeliveredOrder(customerNames);
  522 + if (CollectionUtils.isEmpty(mapList)) {
  523 + return Collections.emptyMap();
  524 + }
  525 + Map<String, Long> result = new HashMap<>();
  526 + for (Map<String, Object> map : mapList) {
  527 + String key = (String) map.get("name");
  528 + Long value = (Long) map.get("orderCount");
  529 +
  530 + result.put(key, value);
  531 + }
  532 + return result;
  533 + }
  534 +
516 535
517 /** 536 /**
518 * 处理批次数据 537 * 处理批次数据
@@ -47,4 +47,12 @@ public interface ShipmentsOrderInfoMapper extends BaseMapper<ShipmentsOrderInfo> @@ -47,4 +47,12 @@ public interface ShipmentsOrderInfoMapper extends BaseMapper<ShipmentsOrderInfo>
47 * @return List<Map<String, Double>> 47 * @return List<Map<String, Double>>
48 */ 48 */
49 List<Map<String, Object>> statisticsActualNum(@Param("customerIds") List<String> customerIds); 49 List<Map<String, Object>> statisticsActualNum(@Param("customerIds") List<String> customerIds);
  50 +
  51 + /**
  52 + * 统计待交付订单数
  53 + *
  54 + * @param customerNames 客户名称
  55 + * @return Map<Integer, Integer>
  56 + */
  57 + List<Map<String, Object>> countWaitDeliveredOrder(@Param("customerNames") List<String> customerNames);
50 } 58 }
@@ -108,4 +108,12 @@ public interface ShipmentsOrderInfoService extends BaseMpService<ShipmentsOrderI @@ -108,4 +108,12 @@ public interface ShipmentsOrderInfoService extends BaseMpService<ShipmentsOrderI
108 * @return List<ShipmentsPlanDetail> 108 * @return List<ShipmentsPlanDetail>
109 */ 109 */
110 Map<String, Double> statisticsActualNum(List<String> customerIds); 110 Map<String, Double> statisticsActualNum(List<String> customerIds);
  111 +
  112 + /**
  113 + * 统计待交付订单数
  114 + *
  115 + * @param customerNames 客户名称
  116 + * @return Map<Integer, Long>
  117 + */
  118 + Map<String, Long> countWaitDeliveredOrder(List<String> customerNames);
111 } 119 }
@@ -128,4 +128,19 @@ @@ -128,4 +128,19 @@
128 </foreach> 128 </foreach>
129 group by o.customer_id 129 group by o.customer_id
130 </select> 130 </select>
  131 +
  132 + <select id="countWaitDeliveredOrder" resultType="java.util.Map">
  133 + select c.name,count(distinct sd.order_id) as orderCount
  134 + from shipments_order_info tb
  135 + inner join shipments_plan_detail sd on tb.id = sd.shipment_order_id
  136 + inner join base_data_customer c on tb.customer_id = c.id
  137 + where tb.status = 'SHIPMENTS'
  138 + <if test="customerNames != null and customerNames.size() > 0">
  139 + and c.name in
  140 + <foreach collection="customerNames" open="(" separator="," close=")" item="name">
  141 + #{name}
  142 + </foreach>
  143 + </if>
  144 + group by c.name
  145 + </select>
131 </mapper> 146 </mapper>