Commit 5e265dfc917bd44d17ed2a7c24cdab18ee9e67a2

Authored by yeqianyong
2 parents dfb0293c 6e21cdf9

Merge branch 'master_cj_zq' into master_sample_order

@@ -164,6 +164,12 @@ public class GetReceiptLedgerInfoBo extends BaseBo<ReceiptLedgerInfo> { @@ -164,6 +164,12 @@ public class GetReceiptLedgerInfoBo extends BaseBo<ReceiptLedgerInfo> {
164 private BigDecimal endAccountReceivable; 164 private BigDecimal endAccountReceivable;
165 165
166 /** 166 /**
  167 + * 欠款状态
  168 + */
  169 + @ApiModelProperty("欠款状态")
  170 + private String debtStatus;
  171 +
  172 + /**
167 * 申请状态 173 * 申请状态
168 */ 174 */
169 @ApiModelProperty("申请状态") 175 @ApiModelProperty("申请状态")
@@ -278,5 +284,13 @@ public class GetReceiptLedgerInfoBo extends BaseBo<ReceiptLedgerInfo> { @@ -278,5 +284,13 @@ public class GetReceiptLedgerInfoBo extends BaseBo<ReceiptLedgerInfo> {
278 this.customerType = dicItem.getName(); 284 this.customerType = dicItem.getName();
279 } 285 }
280 } 286 }
  287 + if (StringUtils.isNotBlank(dto.getDebtStatus())) {
  288 + // 获取欠款状态(数据字典)
  289 + SysDataDicItemService sysDataDicItemService = ApplicationUtil.getBean(SysDataDicItemService.class);
  290 + SysDataDicItem dicItem = sysDataDicItemService.findByCode("DEBT_STATUS", dto.getDebtStatus());
  291 + if (dicItem != null) {
  292 + this.debtStatus = dicItem.getName();
  293 + }
  294 + }
281 } 295 }
282 } 296 }
@@ -171,6 +171,12 @@ public class QueryReceiptLedgerInfoBo extends BaseBo<ReceiptLedgerInfo> { @@ -171,6 +171,12 @@ public class QueryReceiptLedgerInfoBo extends BaseBo<ReceiptLedgerInfo> {
171 private BigDecimal endAccountReceivable; 171 private BigDecimal endAccountReceivable;
172 172
173 /** 173 /**
  174 + * 欠款状态
  175 + */
  176 + @ApiModelProperty("欠款状态")
  177 + private String debtStatus;
  178 +
  179 + /**
174 * 申请状态 180 * 申请状态
175 */ 181 */
176 @ApiModelProperty("申请状态") 182 @ApiModelProperty("申请状态")
@@ -117,11 +117,18 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge @@ -117,11 +117,18 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge
117 List<SysDataDicItem> enterpriseTypeList = sysDataDicItemService.findByDicCode("ENTERPRISE_TYPE"); 117 List<SysDataDicItem> enterpriseTypeList = sysDataDicItemService.findByDicCode("ENTERPRISE_TYPE");
118 Map<String, String> enterpriseTypeMap = enterpriseTypeList.stream() 118 Map<String, String> enterpriseTypeMap = enterpriseTypeList.stream()
119 .collect(Collectors.toMap(SysDataDicItem::getCode, SysDataDicItem::getName, (v1, v2) -> v1)); 119 .collect(Collectors.toMap(SysDataDicItem::getCode, SysDataDicItem::getName, (v1, v2) -> v1));
  120 + // 获取欠款状态(数据字典)
  121 + List<SysDataDicItem> debtStatusList = sysDataDicItemService.findByDicCode("DEBT_STATUS");
  122 + Map<String, String> debtStatusMap = debtStatusList.stream()
  123 + .collect(Collectors.toMap(SysDataDicItem::getCode, SysDataDicItem::getName, (v1, v2) -> v1));
120 for (ReceiptLedgerInfo info : infoList) { 124 for (ReceiptLedgerInfo info : infoList) {
121 String customerType = info.getCustomerType(); 125 String customerType = info.getCustomerType();
122 String enterpriseType = enterpriseTypeMap.get(customerType); 126 String enterpriseType = enterpriseTypeMap.get(customerType);
  127 + String debtStatus = info.getDebtStatus();
  128 + String debtStatusName = debtStatusMap.get(debtStatus);
123 129
124 info.setCustomerType(enterpriseType); 130 info.setCustomerType(enterpriseType);
  131 + info.setDebtStatus(debtStatusName);
125 } 132 }
126 return infoList; 133 return infoList;
127 } 134 }
@@ -420,69 +427,28 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge @@ -420,69 +427,28 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge
420 } 427 }
421 List<ReceiptLedgerInfo> dataList = new ArrayList<>(); 428 List<ReceiptLedgerInfo> dataList = new ArrayList<>();
422 for (ShipmentsOrderInfo shipmentsOrderInfo : shipmentsOrderInfoList) { 429 for (ShipmentsOrderInfo shipmentsOrderInfo : shipmentsOrderInfoList) {
423 - String customerId = shipmentsOrderInfo.getCustomerId();  
424 - ReceiptLedgerInfo data = new ReceiptLedgerInfo();  
425 - data.setId(IdUtil.getId());  
426 - data.setShipmentOrderId(shipmentsOrderInfo.getId());  
427 - String shortNameId = customerShortNameMap.get(customerId);  
428 - data.setCustomerShortId(shortNameId);  
429 - CustomerCredit credit = customerCreditMap.get(customerId);  
430 - if (credit != null) {  
431 - String companyCreditLimit = credit.getCompanyCreditLimit();  
432 - if (companyCreditLimit != null) {  
433 - data.setQuota(new BigDecimal(credit.getCompanyCreditLimit()));  
434 - } else {  
435 - data.setQuota(BigDecimal.ZERO);  
436 - }  
437 - data.setSettleTerm(credit.getCompanySettlementPeriod());  
438 - }  
439 - data.setDeptId(shipmentsOrderInfo.getDeptId());  
440 - data.setRegion(shipmentsOrderInfo.getRegion());  
441 - data.setCustomerId(shipmentsOrderInfo.getCustomerId());  
442 - data.setShipmentDate(shipmentsOrderInfo.getShipmentsDate());  
443 -  
444 - String contractType = null;  
445 - List<String> supplyUnitList = new ArrayList<>();  
446 - // 计算期初应收款  
447 - BigDecimal startAccountReceivable = BigDecimal.ZERO;  
448 - List<ShipmentsPlanDetail> detailList = shipmentsOrderInfo.getDetailList();  
449 - for (ShipmentsPlanDetail detail : detailList) {  
450 - String orderSpecId = detail.getOrderSpecId();  
451 - PurchaseOrderLine orderLine = orderSpecMap.get(orderSpecId);  
452 - BigDecimal salesPrice = BigDecimal.ZERO;  
453 - if (orderLine != null && orderLine.getSalesPrice() != null) {  
454 - salesPrice = orderLine.getSalesPrice();  
455 - }  
456 - Double actualShipmentQuantity = detail.getActualShipmentQuantity();  
457 - startAccountReceivable = salesPrice.multiply(new BigDecimal(actualShipmentQuantity));  
458 - // 厂别数据处理  
459 - PurchaseOrderInfo orderInfo = orderInfoMap.get(detail.getOrderId());  
460 - String supplyUnit = orderInfo.getSupplyUnit();  
461 - if (!supplyUnitList.contains(supplyUnit)) {  
462 - supplyUnitList.add(supplyUnit);  
463 - }  
464 - // 获取合同类型  
465 - ContractDistributorStandard contract = contractMap.get(orderInfo.getContractId());  
466 - if (contract != null && StringUtils.isBlank(contractType)) {  
467 - contractType = contract.getType();  
468 - }  
469 - }  
470 - String factoryType = String.join(",", supplyUnitList);  
471 - data.setFactoryType(factoryType);  
472 - data.setStartAccountReceivable(startAccountReceivable);  
473 - if (shipmentsOrderInfo.getDeliveryTime() != null) {  
474 - data.setArrivalDate(shipmentsOrderInfo.getDeliveryTime().toLocalDate());  
475 - }  
476 - data.setEndAccountReceivable(startAccountReceivable);  
477 - // 内外贸区分  
478 - if ("INTL_STD_CONTRACT".equals(contractType) || "INTL_INVENTORY_AGMT".equals(contractType) || "INTL_OPEN_SPEC_AGMT".equals(contractType)) {  
479 - // 外贸  
480 - data.setType("OUTSIDE"); 430 + // 如果存在多个办事处或区域,则分别进行计算
  431 + String[] deptIdArr = StringUtils.isBlank(shipmentsOrderInfo.getDeptId()) ? new String[0] : shipmentsOrderInfo.getDeptId().split(",");
  432 + String[] regionArr = StringUtils.isBlank(shipmentsOrderInfo.getRegion()) ? new String[0] : shipmentsOrderInfo.getRegion().split(",");
  433 + // 使用Set来确保组合不重复
  434 + Set<String> usedCombinations = new HashSet<>();
  435 + // 如果两个都为空,至少生成一条默认记录
  436 + if (deptIdArr.length == 0 && regionArr.length == 0) {
  437 + packReceiptLedgerInfo(shipmentsOrderInfo, customerShortNameMap, customerCreditMap, orderInfoMap, orderSpecMap, contractMap
  438 + , null, null, dataList);
481 } else { 439 } else {
482 - data.setType("INSIDE"); 440 + // 遍历所有组合
  441 + for (String deptId : deptIdArr.length > 0 ? deptIdArr : new String[]{null}) {
  442 + for (String region : regionArr.length > 0 ? regionArr : new String[]{null}) {
  443 + String combination = (deptId == null ? "null" : deptId) + "_" + (region == null ? "null" : region);
  444 + if (!usedCombinations.contains(combination)) {
  445 + packReceiptLedgerInfo(shipmentsOrderInfo, customerShortNameMap, customerCreditMap, orderInfoMap, orderSpecMap, contractMap
  446 + , deptId, region, dataList);
  447 + usedCombinations.add(combination);
  448 + }
  449 + }
  450 + }
483 } 451 }
484 -  
485 - dataList.add(data);  
486 } 452 }
487 getBaseMapper().batchAdd(dataList); 453 getBaseMapper().batchAdd(dataList);
488 } 454 }
@@ -542,7 +508,6 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge @@ -542,7 +508,6 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge
542 reportDetail = new ReceiptLedgerReportDetail(); 508 reportDetail = new ReceiptLedgerReportDetail();
543 } 509 }
544 reportDetail.setCustomerName(customerName); 510 reportDetail.setCustomerName(customerName);
545 - reportDetail.setCreditStatus(debtStatus);  
546 if ("AGREEMENT".equals(debtStatus) || "DEPOSIT".equals(debtStatus)) { 511 if ("AGREEMENT".equals(debtStatus) || "DEPOSIT".equals(debtStatus)) {
547 BigDecimal agreement = reportDetail.getAgreement(); 512 BigDecimal agreement = reportDetail.getAgreement();
548 if (agreement == null) { 513 if (agreement == null) {
@@ -810,7 +775,7 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge @@ -810,7 +775,7 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge
810 @Override 775 @Override
811 public Map<String, Boolean> checkIsDebt(String customerId) { 776 public Map<String, Boolean> checkIsDebt(String customerId) {
812 LocalDateTime endTime = LocalDateTime.now(); 777 LocalDateTime endTime = LocalDateTime.now();
813 - LocalDateTime startTime = LocalDate.now().atStartOfDay(); 778 + LocalDateTime startTime = LocalDate.now().withDayOfMonth(1).atStartOfDay();
814 779
815 LambdaQueryWrapper<ReceiptLedgerInfo> queryWrapper = Wrappers.lambdaQuery(ReceiptLedgerInfo.class); 780 LambdaQueryWrapper<ReceiptLedgerInfo> queryWrapper = Wrappers.lambdaQuery(ReceiptLedgerInfo.class);
816 queryWrapper.eq(ReceiptLedgerInfo::getDelFlag, Boolean.FALSE) 781 queryWrapper.eq(ReceiptLedgerInfo::getDelFlag, Boolean.FALSE)
@@ -823,13 +788,36 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge @@ -823,13 +788,36 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge
823 if (CollectionUtils.isEmpty(ledgerInfoList)) { 788 if (CollectionUtils.isEmpty(ledgerInfoList)) {
824 return Collections.emptyMap(); 789 return Collections.emptyMap();
825 } 790 }
  791 + // 获取资信数据
  792 + Map<String, CustomerCredit> customerCreditMap = new HashMap<>();
  793 + LambdaQueryWrapper<CustomerCredit> customerCreditQueryWrapper = Wrappers.lambdaQuery(CustomerCredit.class);
  794 + customerCreditQueryWrapper.eq(CustomerCredit::getStatus, "PASS")
  795 + .eq(CustomerCredit::getFrozenStatus, "NORMAL");
  796 + if (StringUtils.isNotBlank(customerId)) {
  797 + customerCreditQueryWrapper.eq(CustomerCredit::getCompanyId, customerId);
  798 + }
  799 + List<CustomerCredit> customerCreditList = customerCreditService.getBaseMapper().selectList(customerCreditQueryWrapper);
  800 + if (CollectionUtils.isNotEmpty(customerCreditList)) {
  801 + customerCreditMap = customerCreditList.stream().collect(Collectors.toMap(CustomerCredit::getCompanyId, Function.identity(), (v1, v2) -> v1));
  802 + }
826 Map<String, Boolean> result = new HashMap<>(); 803 Map<String, Boolean> result = new HashMap<>();
827 for (ReceiptLedgerInfo ledgerInfo : ledgerInfoList) { 804 for (ReceiptLedgerInfo ledgerInfo : ledgerInfoList) {
  805 + String debtStatus = ledgerInfo.getDebtStatus();
828 BigDecimal endAccountReceivable = ledgerInfo.getEndAccountReceivable(); 806 BigDecimal endAccountReceivable = ledgerInfo.getEndAccountReceivable();
829 - if (endAccountReceivable.compareTo(BigDecimal.ZERO) > 0) {  
830 - result.put(ledgerInfo.getCustomerId(), Boolean.TRUE);  
831 - } else { 807 + if (StringUtils.isBlank(debtStatus) || endAccountReceivable.compareTo(BigDecimal.ZERO) <= 0) {
832 result.put(ledgerInfo.getCustomerId(), Boolean.FALSE); 808 result.put(ledgerInfo.getCustomerId(), Boolean.FALSE);
  809 + } else {
  810 + CustomerCredit customerCredit = customerCreditMap.get(ledgerInfo.getCustomerId());
  811 + if ("AGREEMENT".equals(debtStatus) && customerCredit != null) {
  812 + String companyCreditLimit = customerCredit.getCompanyCreditLimit();
  813 + // 转化成万元
  814 + endAccountReceivable = valueConvert(endAccountReceivable);
  815 +
  816 + boolean isDebt = StringUtils.isBlank(companyCreditLimit) || endAccountReceivable.compareTo(new BigDecimal(companyCreditLimit)) > 0;
  817 + result.put(ledgerInfo.getCustomerId(), isDebt);
  818 + } else {
  819 + result.put(ledgerInfo.getCustomerId(), Boolean.TRUE);
  820 + }
833 } 821 }
834 } 822 }
835 return result; 823 return result;
@@ -1053,4 +1041,93 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge @@ -1053,4 +1041,93 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge
1053 } 1041 }
1054 return ledgerInfoMap; 1042 return ledgerInfoMap;
1055 } 1043 }
  1044 +
  1045 +
  1046 + /**
  1047 + * 封装台账明细数据
  1048 + *
  1049 + * @param shipmentsOrderInfo 发货单数据
  1050 + * @param customerShortNameMap 客户简称数据
  1051 + * @param customerCreditMap 客户资信数据
  1052 + * @param orderInfoMap 订货单数据
  1053 + * @param orderSpecMap 订货单规格数据
  1054 + * @param contractMap 合同数据
  1055 + * @param dataList 台账明细集合
  1056 + */
  1057 + private void packReceiptLedgerInfo(ShipmentsOrderInfo shipmentsOrderInfo, Map<String, String> customerShortNameMap, Map<String, CustomerCredit> customerCreditMap
  1058 + , Map<String, PurchaseOrderInfo> orderInfoMap, Map<String, PurchaseOrderLine> orderSpecMap, Map<String, ContractDistributorStandard> contractMap
  1059 + , String deptId, String region, List<ReceiptLedgerInfo> dataList) {
  1060 + String customerId = shipmentsOrderInfo.getCustomerId();
  1061 + ReceiptLedgerInfo data = new ReceiptLedgerInfo();
  1062 + data.setId(IdUtil.getId());
  1063 + data.setShipmentOrderId(shipmentsOrderInfo.getId());
  1064 + String shortNameId = customerShortNameMap.get(customerId);
  1065 + data.setCustomerShortId(shortNameId);
  1066 + CustomerCredit credit = customerCreditMap.get(customerId);
  1067 + if (credit != null) {
  1068 + String companyCreditLimit = credit.getCompanyCreditLimit();
  1069 + if (companyCreditLimit != null) {
  1070 + data.setQuota(new BigDecimal(credit.getCompanyCreditLimit()));
  1071 + } else {
  1072 + data.setQuota(BigDecimal.ZERO);
  1073 + }
  1074 + data.setSettleTerm(credit.getCompanySettlementPeriod());
  1075 + }
  1076 + data.setDeptId(deptId);
  1077 + data.setRegion(region);
  1078 + data.setCustomerId(shipmentsOrderInfo.getCustomerId());
  1079 + data.setShipmentDate(shipmentsOrderInfo.getShipmentsDate());
  1080 +
  1081 + String contractType = null;
  1082 + List<String> supplyUnitList = new ArrayList<>();
  1083 + // 计算期初应收款
  1084 + BigDecimal startAccountReceivable = BigDecimal.ZERO;
  1085 + List<ShipmentsPlanDetail> detailList = shipmentsOrderInfo.getDetailList();
  1086 + for (ShipmentsPlanDetail detail : detailList) {
  1087 + PurchaseOrderInfo orderInfo = orderInfoMap.get(detail.getOrderId());
  1088 + // 厂别数据处理
  1089 + String supplyUnit = orderInfo.getSupplyUnit();
  1090 + if (!supplyUnitList.contains(supplyUnit)) {
  1091 + supplyUnitList.add(supplyUnit);
  1092 + }
  1093 + // 获取合同类型
  1094 + ContractDistributorStandard contract = contractMap.get(orderInfo.getContractId());
  1095 + if (contract != null && StringUtils.isBlank(contractType)) {
  1096 + contractType = contract.getType();
  1097 + }
  1098 + // 根据办事处、区域分别计算
  1099 + String orderDeptId = orderInfo.getDeptId();
  1100 + if (StringUtils.isNotBlank(deptId) && !deptId.equals("null") && !deptId.equals(orderDeptId)) {
  1101 + continue;
  1102 + }
  1103 + String orderRegion = orderInfo.getRegion();
  1104 + if (StringUtils.isNotBlank(region) && !region.equals("null") && !region.equals(orderRegion)) {
  1105 + continue;
  1106 + }
  1107 + String orderSpecId = detail.getOrderSpecId();
  1108 + PurchaseOrderLine orderLine = orderSpecMap.get(orderSpecId);
  1109 + BigDecimal salesPrice = BigDecimal.ZERO;
  1110 + if (orderLine != null && orderLine.getSalesPrice() != null) {
  1111 + salesPrice = orderLine.getSalesPrice();
  1112 + }
  1113 + Double actualShipmentQuantity = detail.getActualShipmentQuantity();
  1114 + BigDecimal multiply = salesPrice.multiply(new BigDecimal(actualShipmentQuantity));
  1115 + startAccountReceivable = startAccountReceivable.add(multiply);
  1116 + }
  1117 + String factoryType = String.join(",", supplyUnitList);
  1118 + data.setFactoryType(factoryType);
  1119 + data.setStartAccountReceivable(startAccountReceivable);
  1120 + if (shipmentsOrderInfo.getDeliveryTime() != null) {
  1121 + data.setArrivalDate(shipmentsOrderInfo.getDeliveryTime().toLocalDate());
  1122 + }
  1123 + data.setEndAccountReceivable(startAccountReceivable);
  1124 + // 内外贸区分
  1125 + if ("INTL_STD_CONTRACT".equals(contractType) || "INTL_INVENTORY_AGMT".equals(contractType) || "INTL_OPEN_SPEC_AGMT".equals(contractType)) {
  1126 + // 外贸
  1127 + data.setType("OUTSIDE");
  1128 + } else {
  1129 + data.setType("INSIDE");
  1130 + }
  1131 + dataList.add(data);
  1132 + }
1056 } 1133 }
@@ -282,15 +282,14 @@ public class DraftRequestCarTicketServiceImpl extends BaseMpServiceImpl<DraftReq @@ -282,15 +282,14 @@ public class DraftRequestCarTicketServiceImpl extends BaseMpServiceImpl<DraftReq
282 } 282 }
283 LambdaUpdateWrapper<DraftRequestCarTicket> updateWrapper = Wrappers.lambdaUpdate(DraftRequestCarTicket.class); 283 LambdaUpdateWrapper<DraftRequestCarTicket> updateWrapper = Wrappers.lambdaUpdate(DraftRequestCarTicket.class);
284 if (flag) { 284 if (flag) {
285 - updateWrapper.set(DraftRequestCarTicket::isFreeze, flag) 285 + updateWrapper.set(DraftRequestCarTicket::isFreeze, true)
286 .setSql("freeze_count = freeze_count + 1") 286 .setSql("freeze_count = freeze_count + 1")
287 .in(DraftRequestCarTicket::getPurchaseOrderId, orderIds); 287 .in(DraftRequestCarTicket::getPurchaseOrderId, orderIds);
288 - getBaseMapper().update(updateWrapper);  
289 } else { 288 } else {
290 - updateWrapper.set(DraftRequestCarTicket::isFreeze, flag) 289 + updateWrapper.set(DraftRequestCarTicket::isFreeze, false)
291 .in(DraftRequestCarTicket::getPurchaseOrderId, orderIds); 290 .in(DraftRequestCarTicket::getPurchaseOrderId, orderIds);
292 - getBaseMapper().update(updateWrapper);  
293 } 291 }
  292 + getBaseMapper().update(updateWrapper);
294 } 293 }
295 294
296 @Override 295 @Override
@@ -134,6 +134,7 @@ public interface ReceiptLedgerInfoService extends BaseMpService<ReceiptLedgerInf @@ -134,6 +134,7 @@ public interface ReceiptLedgerInfoService extends BaseMpService<ReceiptLedgerInf
134 134
135 /** 135 /**
136 * 检查客户是否欠款 136 * 检查客户是否欠款
  137 + * 超额或超期
137 * 138 *
138 * @param customerId 客户ID 139 * @param customerId 客户ID
139 */ 140 */
@@ -135,7 +135,7 @@ @@ -135,7 +135,7 @@
135 from shipments_order_info tb 135 from shipments_order_info tb
136 inner join shipments_plan_detail sd on tb.id = sd.shipment_order_id 136 inner join shipments_plan_detail sd on tb.id = sd.shipment_order_id
137 inner join base_data_customer c on tb.customer_id = c.id 137 inner join base_data_customer c on tb.customer_id = c.id
138 - where tb.status = 'SHIPMENTS' 138 + where tb.status = 'UN_SHIPMENTS'
139 <if test="customerNames != null and customerNames.size() > 0"> 139 <if test="customerNames != null and customerNames.size() > 0">
140 and c.name in 140 and c.name in
141 <foreach collection="customerNames" open="(" separator="," close=")" item="name"> 141 <foreach collection="customerNames" open="(" separator="," close=")" item="name">