Commit 52127ac03b66aa7e2b2ba2159d1b3c4f74243bbc

Authored by yeqianyong
1 parent cce1bef5

楚江erp:超期或超额客户冻结逻辑调整

@@ -154,4 +154,15 @@ public class CustomerShortServiceImpl extends BaseMpServiceImpl<CustomerShortMap @@ -154,4 +154,15 @@ public class CustomerShortServiceImpl extends BaseMpServiceImpl<CustomerShortMap
154 154
155 return getBaseMapper().getByShortName(shortName); 155 return getBaseMapper().getByShortName(shortName);
156 } 156 }
  157 +
  158 + @Override
  159 + public List<CustomerShort> getByShortName(List<String> shortNames) {
  160 + if (CollectionUtils.isEmpty(shortNames)) {
  161 + return Collections.emptyList();
  162 + }
  163 + LambdaQueryWrapper<CustomerShort> queryWrapper = Wrappers.lambdaQuery(CustomerShort.class);
  164 + queryWrapper.in(CustomerShort::getShortName, shortNames);
  165 +
  166 + return getBaseMapper().selectList(queryWrapper);
  167 + }
157 } 168 }
@@ -89,4 +89,5 @@ public interface CustomerShortService extends BaseMpService<CustomerShort> { @@ -89,4 +89,5 @@ public interface CustomerShortService extends BaseMpService<CustomerShort> {
89 * @return CustomerShortList 89 * @return CustomerShortList
90 */ 90 */
91 List<CustomerShort> getByShortName(String shortName); 91 List<CustomerShort> getByShortName(String shortName);
  92 + List<CustomerShort> getByShortName(List<String> shortNames);
92 } 93 }
@@ -827,7 +827,17 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge @@ -827,7 +827,17 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge
827 } 827 }
828 828
829 @Override 829 @Override
830 - public Map<String, Boolean> checkIsDebt(String customerId) { 830 + public List<String> getExcessOrOverdue(String customerId) {
  831 + Set<String> customerIds = new HashSet<>();
  832 + if (StringUtils.isNotBlank(customerId)) {
  833 + CustomerShort customerShort = customerShortService.getByCustomerId(customerId);
  834 + if (customerShort != null) {
  835 + List<CustomerShort> shortList = customerShortService.getByShortName(customerShort.getShortName());
  836 + customerIds.addAll(shortList.stream().map(CustomerShort::getCustomerId).collect(Collectors.toList()));
  837 + } else {
  838 + customerIds.add(customerId);
  839 + }
  840 + }
831 LocalDateTime endTime = LocalDateTime.now(); 841 LocalDateTime endTime = LocalDateTime.now();
832 LocalDateTime startTime = LocalDate.now().withDayOfMonth(1).atStartOfDay(); 842 LocalDateTime startTime = LocalDate.now().withDayOfMonth(1).atStartOfDay();
833 843
@@ -835,35 +845,34 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge @@ -835,35 +845,34 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge
835 queryWrapper.eq(ReceiptLedgerInfo::getDelFlag, Boolean.FALSE) 845 queryWrapper.eq(ReceiptLedgerInfo::getDelFlag, Boolean.FALSE)
836 .ge(ReceiptLedgerInfo::getCreateTime, startTime) 846 .ge(ReceiptLedgerInfo::getCreateTime, startTime)
837 .le(ReceiptLedgerInfo::getCreateTime, endTime); 847 .le(ReceiptLedgerInfo::getCreateTime, endTime);
838 - if (StringUtils.isNotBlank(customerId)) {  
839 - queryWrapper.eq(ReceiptLedgerInfo::getCustomerId, customerId); 848 + if (CollectionUtils.isNotEmpty(customerIds)) {
  849 + queryWrapper.in(ReceiptLedgerInfo::getCustomerId, customerIds);
840 } 850 }
841 List<ReceiptLedgerInfo> ledgerInfoList = getBaseMapper().selectList(queryWrapper); 851 List<ReceiptLedgerInfo> ledgerInfoList = getBaseMapper().selectList(queryWrapper);
842 if (CollectionUtils.isEmpty(ledgerInfoList)) { 852 if (CollectionUtils.isEmpty(ledgerInfoList)) {
843 - return Collections.emptyMap(); 853 + return Collections.emptyList();
844 } 854 }
845 // 获取资信数据 855 // 获取资信数据
846 Map<String, CustomerCredit> customerCreditMap = new HashMap<>(); 856 Map<String, CustomerCredit> customerCreditMap = new HashMap<>();
847 LambdaQueryWrapper<CustomerCredit> customerCreditQueryWrapper = Wrappers.lambdaQuery(CustomerCredit.class); 857 LambdaQueryWrapper<CustomerCredit> customerCreditQueryWrapper = Wrappers.lambdaQuery(CustomerCredit.class);
848 customerCreditQueryWrapper.eq(CustomerCredit::getStatus, "PASS") 858 customerCreditQueryWrapper.eq(CustomerCredit::getStatus, "PASS")
849 .eq(CustomerCredit::getFrozenStatus, "NORMAL"); 859 .eq(CustomerCredit::getFrozenStatus, "NORMAL");
850 - if (StringUtils.isNotBlank(customerId)) {  
851 - customerCreditQueryWrapper.eq(CustomerCredit::getCompanyId, customerId); 860 + if (CollectionUtils.isNotEmpty(customerIds)) {
  861 + customerCreditQueryWrapper.in(CustomerCredit::getCompanyId, customerIds);
852 } 862 }
853 List<CustomerCredit> customerCreditList = customerCreditService.getBaseMapper().selectList(customerCreditQueryWrapper); 863 List<CustomerCredit> customerCreditList = customerCreditService.getBaseMapper().selectList(customerCreditQueryWrapper);
854 if (CollectionUtils.isNotEmpty(customerCreditList)) { 864 if (CollectionUtils.isNotEmpty(customerCreditList)) {
855 customerCreditMap = customerCreditList.stream().collect(Collectors.toMap(CustomerCredit::getCompanyId, Function.identity(), (v1, v2) -> v1)); 865 customerCreditMap = customerCreditList.stream().collect(Collectors.toMap(CustomerCredit::getCompanyId, Function.identity(), (v1, v2) -> v1));
856 } 866 }
857 - Map<String, Boolean> result = new HashMap<>(); 867 + List<String> result = new ArrayList<>();
858 for (ReceiptLedgerInfo ledgerInfo : ledgerInfoList) { 868 for (ReceiptLedgerInfo ledgerInfo : ledgerInfoList) {
859 - Boolean excessOrOverdue = result.get(ledgerInfo.getCustomerId()); 869 + String shortId = ledgerInfo.getCustomerShortId();
  870 + if (StringUtils.isBlank(shortId)) {
  871 + shortId = ledgerInfo.getCustomerId();
  872 + }
860 String debtStatus = ledgerInfo.getDebtStatus(); 873 String debtStatus = ledgerInfo.getDebtStatus();
861 BigDecimal endAccountReceivable = ledgerInfo.getEndAccountReceivable(); 874 BigDecimal endAccountReceivable = ledgerInfo.getEndAccountReceivable();
862 - if (StringUtils.isBlank(debtStatus) || endAccountReceivable.compareTo(BigDecimal.ZERO) <= 0) {  
863 - if (excessOrOverdue == null) {  
864 - result.put(ledgerInfo.getCustomerId(), Boolean.FALSE);  
865 - }  
866 - } else { 875 + if (StringUtils.isNotBlank(debtStatus) && endAccountReceivable.compareTo(BigDecimal.ZERO) > 0) {
867 CustomerCredit customerCredit = customerCreditMap.get(ledgerInfo.getCustomerId()); 876 CustomerCredit customerCredit = customerCreditMap.get(ledgerInfo.getCustomerId());
868 if ("AGREEMENT".equals(debtStatus) && customerCredit != null) { 877 if ("AGREEMENT".equals(debtStatus) && customerCredit != null) {
869 String companyCreditLimit = customerCredit.getCompanyCreditLimit(); 878 String companyCreditLimit = customerCredit.getCompanyCreditLimit();
@@ -871,11 +880,11 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge @@ -871,11 +880,11 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge
871 endAccountReceivable = valueConvert(endAccountReceivable); 880 endAccountReceivable = valueConvert(endAccountReceivable);
872 881
873 boolean isDebt = StringUtils.isBlank(companyCreditLimit) || endAccountReceivable.compareTo(new BigDecimal(companyCreditLimit)) > 0; 882 boolean isDebt = StringUtils.isBlank(companyCreditLimit) || endAccountReceivable.compareTo(new BigDecimal(companyCreditLimit)) > 0;
874 - if (!BooleanUtils.isTrue(excessOrOverdue)) {  
875 - result.put(ledgerInfo.getCustomerId(), isDebt); 883 + if (BooleanUtils.isTrue(isDebt) && !result.contains(shortId)) {
  884 + result.add(shortId);
876 } 885 }
877 - } else if (!BooleanUtils.isTrue(excessOrOverdue)) {  
878 - result.put(ledgerInfo.getCustomerId(), Boolean.TRUE); 886 + } else if (!result.contains(shortId)) {
  887 + result.add(shortId);
879 } 888 }
880 } 889 }
881 } 890 }
@@ -885,11 +894,19 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge @@ -885,11 +894,19 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge
885 @Override 894 @Override
886 @Transactional(rollbackFor = Exception.class) 895 @Transactional(rollbackFor = Exception.class)
887 public void autoFreeze(String customerId) { 896 public void autoFreeze(String customerId) {
888 - Map<String, Boolean> debtCustomerMap = checkIsDebt(customerId);  
889 - Set<String> customerIds = debtCustomerMap.keySet();  
890 - if (CollectionUtils.isEmpty(customerIds)) { 897 + List<String> shortIds = getExcessOrOverdue(customerId);
  898 + if (CollectionUtils.isEmpty(shortIds)) {
891 return; 899 return;
892 } 900 }
  901 + Set<String> customerIds = new HashSet<>(shortIds);
  902 + List<CustomerShort> shortList = customerShortService.listByIds(shortIds);
  903 + if (CollectionUtils.isNotEmpty(shortList)) {
  904 + List<String> shotNames = shortList.stream().map(CustomerShort::getShortName).distinct().collect(Collectors.toList());
  905 + shortList = customerShortService.getByShortName(shotNames);
  906 + if (CollectionUtils.isNotEmpty(shortList)) {
  907 + customerIds.addAll(shortList.stream().map(CustomerShort::getCustomerId).collect(Collectors.toList()));
  908 + }
  909 + }
893 List<PurchaseOrderInfo> orderInfoList = purchaseOrderInfoService.listByCustomerIds(new ArrayList<>(customerIds)); 910 List<PurchaseOrderInfo> orderInfoList = purchaseOrderInfoService.listByCustomerIds(new ArrayList<>(customerIds));
894 if (CollectionUtils.isEmpty(orderInfoList)) { 911 if (CollectionUtils.isEmpty(orderInfoList)) {
895 return; 912 return;
@@ -905,9 +922,8 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge @@ -905,9 +922,8 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge
905 } 922 }
906 List<String> needFreezeOrderIds = new ArrayList<>(); 923 List<String> needFreezeOrderIds = new ArrayList<>();
907 for (String id : customerIds) { 924 for (String id : customerIds) {
908 - Boolean debt = debtCustomerMap.get(id);  
909 List<String> orderIds = orderInfoMap.get(id); 925 List<String> orderIds = orderInfoMap.get(id);
910 - if (BooleanUtils.isTrue(debt) && CollectionUtils.isNotEmpty(orderIds)) { 926 + if (CollectionUtils.isNotEmpty(orderIds)) {
911 needFreezeOrderIds.addAll(orderIds); 927 needFreezeOrderIds.addAll(orderIds);
912 } 928 }
913 } 929 }
@@ -137,8 +137,9 @@ public interface ReceiptLedgerInfoService extends BaseMpService<ReceiptLedgerInf @@ -137,8 +137,9 @@ public interface ReceiptLedgerInfoService extends BaseMpService<ReceiptLedgerInf
137 * 超额或超期 137 * 超额或超期
138 * 138 *
139 * @param customerId 客户ID 139 * @param customerId 客户ID
  140 + * @return List<String> 简称ID或客户ID
140 */ 141 */
141 - Map<String, Boolean> checkIsDebt(String customerId); 142 + List<String> getExcessOrOverdue(String customerId);
142 143
143 /** 144 /**
144 * 冻结欠款客户,管控发货 145 * 冻结欠款客户,管控发货