Commit 97c5627c80cc5647d399daaaab2786ad80b5df8b

Authored by 房远帅
2 parents 6dfc579c 94a0b1fe

Merge remote-tracking branch 'origin/master_cj_zq' into master_cj_zq

@@ -16,6 +16,7 @@ import com.lframework.starter.web.core.annotations.oplog.OpLog; @@ -16,6 +16,7 @@ import com.lframework.starter.web.core.annotations.oplog.OpLog;
16 import com.lframework.starter.web.core.utils.PageHelperUtil; 16 import com.lframework.starter.web.core.utils.PageHelperUtil;
17 import com.lframework.starter.common.utils.Assert; 17 import com.lframework.starter.common.utils.Assert;
18 import com.lframework.starter.web.inner.components.oplog.OtherOpLogType; 18 import com.lframework.starter.web.inner.components.oplog.OtherOpLogType;
  19 +import org.apache.commons.collections4.CollectionUtils;
19 import org.apache.commons.lang3.StringUtils; 20 import org.apache.commons.lang3.StringUtils;
20 import org.springframework.transaction.annotation.Transactional; 21 import org.springframework.transaction.annotation.Transactional;
21 import com.lframework.xingyun.basedata.mappers.CustomerShortMapper; 22 import com.lframework.xingyun.basedata.mappers.CustomerShortMapper;
@@ -25,6 +26,7 @@ import com.lframework.xingyun.basedata.vo.customer.QueryCustomerShortVo; @@ -25,6 +26,7 @@ import com.lframework.xingyun.basedata.vo.customer.QueryCustomerShortVo;
25 import com.lframework.xingyun.basedata.vo.customer.UpdateCustomerShortVo; 26 import com.lframework.xingyun.basedata.vo.customer.UpdateCustomerShortVo;
26 import org.springframework.stereotype.Service; 27 import org.springframework.stereotype.Service;
27 28
  29 +import java.util.Collections;
28 import java.util.List; 30 import java.util.List;
29 31
30 @Service 32 @Service
@@ -122,4 +124,15 @@ public class CustomerShortServiceImpl extends BaseMpServiceImpl<CustomerShortMap @@ -122,4 +124,15 @@ public class CustomerShortServiceImpl extends BaseMpServiceImpl<CustomerShortMap
122 124
123 return getBaseMapper().selectOne(queryWrapper); 125 return getBaseMapper().selectOne(queryWrapper);
124 } 126 }
  127 +
  128 + @Override
  129 + public List<CustomerShort> listByCustomerId(List<String> customerIds) {
  130 + if (CollectionUtils.isEmpty(customerIds)) {
  131 + return Collections.emptyList();
  132 + }
  133 + LambdaQueryWrapper<CustomerShort> queryWrapper = Wrappers.lambdaQuery(CustomerShort.class);
  134 + queryWrapper.in(CustomerShort::getCustomerId, customerIds);
  135 +
  136 + return getBaseMapper().selectList(queryWrapper);
  137 + }
125 } 138 }
@@ -65,4 +65,12 @@ public interface CustomerShortService extends BaseMpService<CustomerShort> { @@ -65,4 +65,12 @@ public interface CustomerShortService extends BaseMpService<CustomerShort> {
65 * @return CustomerShort 65 * @return CustomerShort
66 */ 66 */
67 CustomerShort getByCustomerId(String customerId); 67 CustomerShort getByCustomerId(String customerId);
  68 +
  69 + /**
  70 + * 根据客户ID获取客户简称
  71 + *
  72 + * @param customerIds 客户ID集合
  73 + * @return List<CustomerShort>
  74 + */
  75 + List<CustomerShort> listByCustomerId(List<String> customerIds);
68 } 76 }
@@ -158,12 +158,6 @@ public class GetReceiptLedgerInfoBo extends BaseBo<ReceiptLedgerInfo> { @@ -158,12 +158,6 @@ public class GetReceiptLedgerInfoBo extends BaseBo<ReceiptLedgerInfo> {
158 private BigDecimal returnedAmount; 158 private BigDecimal returnedAmount;
159 159
160 /** 160 /**
161 - * 实际回笼金额  
162 - */  
163 - @ApiModelProperty("实际回笼金额")  
164 - private BigDecimal actualReturnedAmount;  
165 -  
166 - /**  
167 * 期末应收账款 161 * 期末应收账款
168 */ 162 */
169 @ApiModelProperty("期末应收账款") 163 @ApiModelProperty("期末应收账款")
@@ -7,6 +7,8 @@ import com.lframework.starter.common.constants.StringPool; @@ -7,6 +7,8 @@ import com.lframework.starter.common.constants.StringPool;
7 import com.lframework.starter.web.core.bo.BaseBo; 7 import com.lframework.starter.web.core.bo.BaseBo;
8 import java.time.LocalDate; 8 import java.time.LocalDate;
9 import java.time.LocalDateTime; 9 import java.time.LocalDateTime;
  10 +import java.time.temporal.ChronoUnit;
  11 +
10 import io.swagger.annotations.ApiModelProperty; 12 import io.swagger.annotations.ApiModelProperty;
11 13
12 import lombok.Data; 14 import lombok.Data;
@@ -155,12 +157,6 @@ public class QueryReceiptLedgerInfoBo extends BaseBo<ReceiptLedgerInfo> { @@ -155,12 +157,6 @@ public class QueryReceiptLedgerInfoBo extends BaseBo<ReceiptLedgerInfo> {
155 private BigDecimal returnedAmount; 157 private BigDecimal returnedAmount;
156 158
157 /** 159 /**
158 - * 实际回笼金额  
159 - */  
160 - @ApiModelProperty("实际回笼金额")  
161 - private BigDecimal actualReturnedAmount;  
162 -  
163 - /**  
164 * 期末应收账款 160 * 期末应收账款
165 */ 161 */
166 @ApiModelProperty("期末应收账款") 162 @ApiModelProperty("期末应收账款")
@@ -226,6 +222,18 @@ public class QueryReceiptLedgerInfoBo extends BaseBo<ReceiptLedgerInfo> { @@ -226,6 +222,18 @@ public class QueryReceiptLedgerInfoBo extends BaseBo<ReceiptLedgerInfo> {
226 private boolean spilt; 222 private boolean spilt;
227 223
228 /** 224 /**
  225 + * 占用天数
  226 + */
  227 + @ApiModelProperty("占用天数")
  228 + private Long occupiedDays;
  229 +
  230 + /**
  231 + * 到货天数
  232 + */
  233 + @ApiModelProperty("到货天数")
  234 + private Long deliveryDays;
  235 +
  236 + /**
229 * 创建人ID 237 * 创建人ID
230 */ 238 */
231 @ApiModelProperty("创建人ID") 239 @ApiModelProperty("创建人ID")
@@ -275,5 +283,14 @@ public class QueryReceiptLedgerInfoBo extends BaseBo<ReceiptLedgerInfo> { @@ -275,5 +283,14 @@ public class QueryReceiptLedgerInfoBo extends BaseBo<ReceiptLedgerInfo> {
275 } else if ("GJ".equals(dto.getFactoryType())) { 283 } else if ("GJ".equals(dto.getFactoryType())) {
276 this.factoryType = "安徽楚江高精铜带有限公司"; 284 this.factoryType = "安徽楚江高精铜带有限公司";
277 } 285 }
  286 + LocalDate now = LocalDate.now();
  287 + LocalDate dtoShipmentDate = dto.getShipmentDate();
  288 + if (dtoShipmentDate != null) {
  289 + this.occupiedDays = ChronoUnit.DAYS.between(dtoShipmentDate, now) + 1;
  290 + }
  291 + LocalDate dtoArrivalDate = dto.getArrivalDate();
  292 + if (dtoArrivalDate != null) {
  293 + this.deliveryDays = ChronoUnit.DAYS.between(dtoArrivalDate, now) + 1;
  294 + }
278 } 295 }
279 } 296 }
@@ -141,11 +141,6 @@ public class ReceiptLedgerInfo extends BaseEntity implements BaseDto { @@ -141,11 +141,6 @@ public class ReceiptLedgerInfo extends BaseEntity implements BaseDto {
141 private BigDecimal returnedAmount; 141 private BigDecimal returnedAmount;
142 142
143 /** 143 /**
144 - * 实际回笼金额  
145 - */  
146 - private BigDecimal actualReturnedAmount;  
147 -  
148 - /**  
149 * 期末应收账款 144 * 期末应收账款
150 */ 145 */
151 private BigDecimal endAccountReceivable; 146 private BigDecimal endAccountReceivable;
@@ -110,6 +110,11 @@ public class ShipmentsOrderInfo extends BaseEntity implements BaseDto { @@ -110,6 +110,11 @@ public class ShipmentsOrderInfo extends BaseEntity implements BaseDto {
110 private String receiptsName; 110 private String receiptsName;
111 111
112 /** 112 /**
  113 + * 签收时间
  114 + */
  115 + private LocalDateTime deliveryTime;
  116 +
  117 + /**
113 * 状态 118 * 状态
114 */ 119 */
115 private String status; 120 private String status;
@@ -2064,6 +2064,18 @@ public class CustomerCreditServiceImpl extends BaseMpServiceImpl<CustomerCreditM @@ -2064,6 +2064,18 @@ public class CustomerCreditServiceImpl extends BaseMpServiceImpl<CustomerCreditM
2064 OpLogUtil.setExtra(vo); 2064 OpLogUtil.setExtra(vo);
2065 } 2065 }
2066 2066
  2067 + @Override
  2068 + public List<CustomerCredit> listByCustomerId(List<String> customerIds) {
  2069 + if (CollectionUtils.isEmpty(customerIds)) {
  2070 + return Collections.emptyList();
  2071 + }
  2072 + LambdaQueryWrapper<CustomerCredit> queryWrapper = Wrappers.lambdaQuery(CustomerCredit.class);
  2073 + queryWrapper.eq(CustomerCredit::getFrozenStatus, "NORMAL")
  2074 + .in(CustomerCredit::getCompanyId, customerIds);
  2075 +
  2076 + return getBaseMapper().selectList(queryWrapper);
  2077 + }
  2078 +
2067 2079
2068 @Override 2080 @Override
2069 public void cleanCacheByKey(Serializable key) { 2081 public void cleanCacheByKey(Serializable key) {
@@ -9,7 +9,11 @@ import com.lframework.starter.common.utils.StringUtil; @@ -9,7 +9,11 @@ import com.lframework.starter.common.utils.StringUtil;
9 import com.lframework.starter.web.core.components.security.SecurityUtil; 9 import com.lframework.starter.web.core.components.security.SecurityUtil;
10 import com.lframework.starter.web.inner.entity.SysDataDicItem; 10 import com.lframework.starter.web.inner.entity.SysDataDicItem;
11 import com.lframework.starter.web.inner.service.system.SysDataDicItemService; 11 import com.lframework.starter.web.inner.service.system.SysDataDicItemService;
12 -import com.lframework.xingyun.sc.entity.ReceiptLedgerInfo; 12 +import com.lframework.xingyun.basedata.entity.Customer;
  13 +import com.lframework.xingyun.basedata.entity.CustomerShort;
  14 +import com.lframework.xingyun.basedata.service.customer.CustomerService;
  15 +import com.lframework.xingyun.basedata.service.customer.CustomerShortService;
  16 +import com.lframework.xingyun.sc.entity.*;
13 import com.lframework.starter.web.core.impl.BaseMpServiceImpl; 17 import com.lframework.starter.web.core.impl.BaseMpServiceImpl;
14 import com.lframework.starter.web.core.utils.PageResultUtil; 18 import com.lframework.starter.web.core.utils.PageResultUtil;
15 import com.lframework.starter.web.core.utils.OpLogUtil; 19 import com.lframework.starter.web.core.utils.OpLogUtil;
@@ -19,6 +23,9 @@ import com.lframework.starter.web.core.utils.PageHelperUtil; @@ -19,6 +23,9 @@ import com.lframework.starter.web.core.utils.PageHelperUtil;
19 import com.lframework.starter.web.inner.components.oplog.OtherOpLogType; 23 import com.lframework.starter.web.inner.components.oplog.OtherOpLogType;
20 import com.lframework.starter.web.core.components.resp.PageResult; 24 import com.lframework.starter.web.core.components.resp.PageResult;
21 import com.lframework.starter.common.utils.Assert; 25 import com.lframework.starter.common.utils.Assert;
  26 +import com.lframework.xingyun.sc.service.customer.CustomerCreditService;
  27 +import com.lframework.xingyun.sc.service.order.PurchaseOrderInfoService;
  28 +import com.lframework.xingyun.sc.service.order.PurchaseOrderLineService;
22 import com.lframework.xingyun.sc.utils.CommonUtil; 29 import com.lframework.xingyun.sc.utils.CommonUtil;
23 import com.lframework.xingyun.sc.vo.ledger.receipt.ReceiptLedgerInfoSplitVo; 30 import com.lframework.xingyun.sc.vo.ledger.receipt.ReceiptLedgerInfoSplitVo;
24 import com.lframework.xingyun.sc.vo.ledger.receipt.UpdateReceiptLedgerInfoVo; 31 import com.lframework.xingyun.sc.vo.ledger.receipt.UpdateReceiptLedgerInfoVo;
@@ -32,10 +39,10 @@ import org.springframework.stereotype.Service; @@ -32,10 +39,10 @@ import org.springframework.stereotype.Service;
32 39
33 import javax.annotation.Resource; 40 import javax.annotation.Resource;
34 import java.math.BigDecimal; 41 import java.math.BigDecimal;
35 -import java.util.ArrayList;  
36 -import java.util.Collections;  
37 -import java.util.List;  
38 -import java.util.Map; 42 +import java.time.LocalDate;
  43 +import java.time.temporal.ChronoUnit;
  44 +import java.util.*;
  45 +import java.util.function.Function;
39 import java.util.stream.Collectors; 46 import java.util.stream.Collectors;
40 47
41 @Service 48 @Service
@@ -44,6 +51,16 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge @@ -44,6 +51,16 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge
44 51
45 @Resource 52 @Resource
46 private SysDataDicItemService sysDataDicItemService; 53 private SysDataDicItemService sysDataDicItemService;
  54 + @Resource
  55 + private CustomerService customerService;
  56 + @Resource
  57 + private CustomerCreditService customerCreditService;
  58 + @Resource
  59 + private CustomerShortService customerShortService;
  60 + @Resource
  61 + private PurchaseOrderInfoService purchaseOrderInfoService;
  62 + @Resource
  63 + private PurchaseOrderLineService purchaseOrderLineService;
47 64
48 65
49 66
@@ -81,7 +98,8 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge @@ -81,7 +98,8 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge
81 public ReceiptLedgerInfo findById(String id) { 98 public ReceiptLedgerInfo findById(String id) {
82 QueryReceiptLedgerInfoVo ledgerInfoVo = new QueryReceiptLedgerInfoVo(); 99 QueryReceiptLedgerInfoVo ledgerInfoVo = new QueryReceiptLedgerInfoVo();
83 ledgerInfoVo.setId(id); 100 ledgerInfoVo.setId(id);
84 - return getBaseMapper().query(ledgerInfoVo).get(0); 101 + List<ReceiptLedgerInfo> infoList = getBaseMapper().query(ledgerInfoVo);
  102 + return CollectionUtils.isEmpty(infoList) ? null : infoList.get(0);
85 } 103 }
86 104
87 @OpLog(type = OtherOpLogType.class, name = "新增应收款台账明细,ID:{}", params = {"#id"}) 105 @OpLog(type = OtherOpLogType.class, name = "新增应收款台账明细,ID:{}", params = {"#id"})
@@ -105,7 +123,6 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge @@ -105,7 +123,6 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge
105 data.setProcessedDate(vo.getProcessedDate()); 123 data.setProcessedDate(vo.getProcessedDate());
106 data.setActualReturnedDate(vo.getActualReturnedDate()); 124 data.setActualReturnedDate(vo.getActualReturnedDate());
107 data.setReturnedAmount(vo.getReturnedAmount()); 125 data.setReturnedAmount(vo.getReturnedAmount());
108 - data.setActualReturnedAmount(vo.getActualReturnedAmount());  
109 data.setEndAccountReceivable(vo.getEndAccountReceivable()); 126 data.setEndAccountReceivable(vo.getEndAccountReceivable());
110 data.setApplyStatus(vo.getApplyStatus()); 127 data.setApplyStatus(vo.getApplyStatus());
111 data.setCoordinateDate(vo.getCoordinateDate()); 128 data.setCoordinateDate(vo.getCoordinateDate());
@@ -131,10 +148,13 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge @@ -131,10 +148,13 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge
131 if (ObjectUtil.isNull(data)) { 148 if (ObjectUtil.isNull(data)) {
132 throw new DefaultClientException("应收款台账明细不存在!"); 149 throw new DefaultClientException("应收款台账明细不存在!");
133 } 150 }
  151 + // 获取欠款状态
  152 + String settlementStatus = getSettlementStatus(data.getEndAccountReceivable(), data.getProcessedDate());
134 LambdaUpdateWrapper<ReceiptLedgerInfo> updateWrapper = Wrappers.lambdaUpdate(ReceiptLedgerInfo.class) 153 LambdaUpdateWrapper<ReceiptLedgerInfo> updateWrapper = Wrappers.lambdaUpdate(ReceiptLedgerInfo.class)
135 .set(ReceiptLedgerInfo::getDescription, StringUtil.isBlank(vo.getDescription()) ? null : vo.getDescription()) 154 .set(ReceiptLedgerInfo::getDescription, StringUtil.isBlank(vo.getDescription()) ? null : vo.getDescription())
136 .set(ReceiptLedgerInfo::getProcessedDate, vo.getProcessedDate() == null ? null : vo.getProcessedDate()) 155 .set(ReceiptLedgerInfo::getProcessedDate, vo.getProcessedDate() == null ? null : vo.getProcessedDate())
137 .set(ReceiptLedgerInfo::getRemark, StringUtil.isBlank(vo.getRemark()) ? null : vo.getRemark()) 156 .set(ReceiptLedgerInfo::getRemark, StringUtil.isBlank(vo.getRemark()) ? null : vo.getRemark())
  157 + .set(ReceiptLedgerInfo::getDebtStatus, settlementStatus)
138 .eq(ReceiptLedgerInfo::getId, vo.getId()); 158 .eq(ReceiptLedgerInfo::getId, vo.getId());
139 159
140 getBaseMapper().update(updateWrapper); 160 getBaseMapper().update(updateWrapper);
@@ -214,7 +234,6 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge @@ -214,7 +234,6 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge
214 data.setProcessedDate(vo.getProcessedDate()); 234 data.setProcessedDate(vo.getProcessedDate());
215 data.setActualReturnedDate(vo.getActualReturnedDate()); 235 data.setActualReturnedDate(vo.getActualReturnedDate());
216 data.setReturnedAmount(vo.getReturnedAmount()); 236 data.setReturnedAmount(vo.getReturnedAmount());
217 - data.setActualReturnedAmount(vo.getActualReturnedAmount());  
218 //拆分的时候期末应收账款=期初-回笼资金(这时候为0) 237 //拆分的时候期末应收账款=期初-回笼资金(这时候为0)
219 data.setEndAccountReceivable(quantity); 238 data.setEndAccountReceivable(quantity);
220 data.setApplyStatus(vo.getApplyStatus()); 239 data.setApplyStatus(vo.getApplyStatus());
@@ -236,4 +255,152 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge @@ -236,4 +255,152 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge
236 public void deleteById(String id) { 255 public void deleteById(String id) {
237 getBaseMapper().deleteById(id); 256 getBaseMapper().deleteById(id);
238 } 257 }
  258 +
  259 + @Override
  260 + @Transactional(rollbackFor = Exception.class)
  261 + public void generateLedgerInfo(List<ShipmentsOrderInfo> shipmentsOrderInfoList) {
  262 + if (CollectionUtils.isEmpty(shipmentsOrderInfoList)) {
  263 + log.error("generateLedgerInfo invoke failed: orderInfoList is empty!");
  264 + return;
  265 + }
  266 + List<String> customerIds = new ArrayList<>();
  267 + List<String> orderIds = new ArrayList<>();
  268 + List<String> orderSpecIds = new ArrayList<>();
  269 + for (ShipmentsOrderInfo orderInfo : shipmentsOrderInfoList) {
  270 + String customerId = orderInfo.getCustomerId();
  271 + if (!customerIds.contains(customerId)) {
  272 + customerIds.add(customerId);
  273 + }
  274 + List<ShipmentsPlanDetail> detailList = orderInfo.getDetailList();
  275 + for (ShipmentsPlanDetail detail : detailList) {
  276 + String orderId = detail.getOrderId();
  277 + String orderSpecId = detail.getOrderSpecId();
  278 + if (!orderIds.contains(orderId)) {
  279 + orderIds.add(orderId);
  280 + }
  281 + if (!orderSpecIds.contains(orderSpecId)) {
  282 + orderSpecIds.add(orderSpecId);
  283 + }
  284 + }
  285 + }
  286 + // 客户基本信息
  287 + Map<String, Customer> customerMap = new HashMap<>();
  288 + List<Customer> customers = customerService.listByIds(customerIds);
  289 + if (CollectionUtils.isNotEmpty(customers)) {
  290 + customerMap = customers.stream().collect(Collectors.toMap(Customer::getId, Function.identity()));
  291 + }
  292 + // 客户资信数据
  293 + Map<String, CustomerCredit> customerCreditMap = new HashMap<>();
  294 + List<CustomerCredit> customerCreditList = customerCreditService.listByCustomerId(customerIds);
  295 + if (CollectionUtils.isNotEmpty(customerCreditList)) {
  296 + customerCreditMap = customerCreditList.stream().collect(Collectors.toMap(CustomerCredit::getCompanyId, Function.identity()
  297 + , (v1, v2) -> v1));
  298 + }
  299 + // 客户简称数据
  300 + Map<String, String> customerShortNameMap = new HashMap<>();
  301 + List<CustomerShort> customerShortList = customerShortService.listByCustomerId(customerIds);
  302 + if (CollectionUtils.isNotEmpty(customerShortList)) {
  303 + customerShortNameMap = customerShortList.stream().collect(Collectors.toMap(CustomerShort::getCustomerId, CustomerShort::getId
  304 + , (v1, v2) -> v1));
  305 + }
  306 + // 订货单信息
  307 + Map<String, PurchaseOrderInfo> orderInfoMap = new HashMap<>();
  308 + List<PurchaseOrderInfo> orderInfoList = purchaseOrderInfoService.listByIds(orderIds);
  309 + if (CollectionUtils.isNotEmpty(orderInfoList)) {
  310 + orderInfoMap = orderInfoList.stream().collect(Collectors.toMap(PurchaseOrderInfo::getId, Function.identity()));
  311 + }
  312 + // 订货单规格信息
  313 + Map<String, PurchaseOrderLine> orderSpecMap = new HashMap<>();
  314 + List<PurchaseOrderLine> orderSpecList = purchaseOrderLineService.listByIds(orderIds);
  315 + if (CollectionUtils.isNotEmpty(orderSpecList)) {
  316 + orderSpecMap = orderSpecList.stream().collect(Collectors.toMap(PurchaseOrderLine::getId, Function.identity()));
  317 + }
  318 + List<ReceiptLedgerInfo> dataList = new ArrayList<>();
  319 + for (ShipmentsOrderInfo shipmentsOrderInfo : shipmentsOrderInfoList) {
  320 + String customerId = shipmentsOrderInfo.getCustomerId();
  321 + ReceiptLedgerInfo data = new ReceiptLedgerInfo();
  322 + data.setId(IdUtil.getId());
  323 + String shortNameId = customerShortNameMap.get(customerId);
  324 + data.setCustomerShortId(shortNameId);
  325 + CustomerCredit credit = customerCreditMap.get(customerId);
  326 + if (credit != null) {
  327 + String companyCreditLimit = credit.getCompanyCreditLimit();
  328 + if (companyCreditLimit != null) {
  329 + data.setQuota(new BigDecimal(credit.getCompanyCreditLimit()));
  330 + } else {
  331 + data.setQuota(BigDecimal.ZERO);
  332 + }
  333 + data.setSettleTerm(credit.getCompanySettlementPeriod());
  334 + }
  335 + data.setDeptId(shipmentsOrderInfo.getDeptId());
  336 + data.setRegion(shipmentsOrderInfo.getRegion());
  337 + data.setCustomerId(shipmentsOrderInfo.getCustomerId());
  338 + data.setShipmentDate(shipmentsOrderInfo.getShipmentsDate());
  339 + List<String> supplyUnitList = new ArrayList<>();
  340 + // 计算期初应收款
  341 + BigDecimal startAccountReceivable = BigDecimal.ZERO;
  342 + List<ShipmentsPlanDetail> detailList = shipmentsOrderInfo.getDetailList();
  343 + for (ShipmentsPlanDetail detail : detailList) {
  344 + String orderSpecId = detail.getOrderSpecId();
  345 + PurchaseOrderLine orderLine = orderSpecMap.get(orderSpecId);
  346 + BigDecimal salesPrice = BigDecimal.ZERO;
  347 + if (orderLine != null && orderLine.getSalesPrice() != null) {
  348 + salesPrice = orderLine.getSalesPrice();
  349 + }
  350 + Double actualShipmentQuantity = detail.getActualShipmentQuantity();
  351 + startAccountReceivable = salesPrice.multiply(new BigDecimal(actualShipmentQuantity));
  352 + // 厂别数据处理
  353 + PurchaseOrderInfo orderInfo = orderInfoMap.get(detail.getOrderId());
  354 + String supplyUnit = orderInfo.getSupplyUnit();
  355 + if (!supplyUnitList.contains(supplyUnit)) {
  356 + supplyUnitList.add(supplyUnit);
  357 + }
  358 + }
  359 + String factoryType = String.join(",", supplyUnitList);
  360 + data.setFactoryType(factoryType);
  361 + data.setStartAccountReceivable(startAccountReceivable);
  362 + if (shipmentsOrderInfo.getDeliveryTime() != null) {
  363 + data.setArrivalDate(shipmentsOrderInfo.getDeliveryTime().toLocalDate());
  364 + }
  365 + data.setEndAccountReceivable(startAccountReceivable);
  366 +
  367 + dataList.add(data);
  368 + }
  369 + getBaseMapper().batchAdd(dataList);
  370 + }
  371 +
  372 +
  373 +
  374 + /**
  375 + * 获取结算状态
  376 + * @return 状态字符串
  377 + */
  378 + public String getSettlementStatus(BigDecimal endAccountReceivable, LocalDate settleTerm) {
  379 + // 检查期末应收账款是否为0
  380 + if (endAccountReceivable.compareTo(BigDecimal.ZERO) == 0) {
  381 + return "SETTLE_UP";
  382 + }
  383 + // 检查期末应收账款是否为负数
  384 + if (endAccountReceivable.compareTo(BigDecimal.ZERO) < 0) {
  385 + return "DEPOSIT";
  386 + }
  387 + // 正数情况下,检查是否超期
  388 + try {
  389 + LocalDate currentDate = LocalDate.now();
  390 + // 计算超期天数
  391 + long overdueDays = ChronoUnit.DAYS.between(settleTerm, currentDate);
  392 + if (overdueDays <= 0) {
  393 + return "AGREEMENT";
  394 + } else if (overdueDays <= 5) {
  395 + return "FIRST_COORDINATE";
  396 + } else if (overdueDays <= 10) {
  397 + return "SECOND";
  398 + } else {
  399 + return "CLEAR_DEBTS";
  400 + }
  401 + } catch (Exception e) {
  402 + // 日期解析错误或空值处理
  403 + throw new DefaultClientException("日期数据异常!");
  404 + }
  405 + }
239 } 406 }
@@ -26,6 +26,7 @@ import com.lframework.starter.web.core.annotations.oplog.OpLog; @@ -26,6 +26,7 @@ import com.lframework.starter.web.core.annotations.oplog.OpLog;
26 import com.lframework.starter.common.utils.Assert; 26 import com.lframework.starter.common.utils.Assert;
27 import com.lframework.starter.web.inner.components.oplog.OtherOpLogType; 27 import com.lframework.starter.web.inner.components.oplog.OtherOpLogType;
28 import com.lframework.xingyun.sc.handlers.MessageHandler; 28 import com.lframework.xingyun.sc.handlers.MessageHandler;
  29 +import com.lframework.xingyun.sc.service.ledger.ReceiptLedgerInfoService;
29 import com.lframework.xingyun.sc.service.order.PurchaseOrderInfoService; 30 import com.lframework.xingyun.sc.service.order.PurchaseOrderInfoService;
30 import com.lframework.xingyun.sc.service.order.PurchaseOrderLineService; 31 import com.lframework.xingyun.sc.service.order.PurchaseOrderLineService;
31 import com.lframework.xingyun.sc.service.shipments.ShipmentsPlanDetailService; 32 import com.lframework.xingyun.sc.service.shipments.ShipmentsPlanDetailService;
@@ -51,6 +52,7 @@ import org.springframework.stereotype.Service; @@ -51,6 +52,7 @@ import org.springframework.stereotype.Service;
51 import javax.annotation.Resource; 52 import javax.annotation.Resource;
52 import java.math.BigDecimal; 53 import java.math.BigDecimal;
53 import java.time.LocalDate; 54 import java.time.LocalDate;
  55 +import java.time.LocalDateTime;
54 import java.time.LocalTime; 56 import java.time.LocalTime;
55 import java.time.format.DateTimeFormatter; 57 import java.time.format.DateTimeFormatter;
56 import java.util.*; 58 import java.util.*;
@@ -87,6 +89,8 @@ public class ShipmentsOrderInfoServiceImpl extends BaseMpServiceImpl<ShipmentsOr @@ -87,6 +89,8 @@ public class ShipmentsOrderInfoServiceImpl extends BaseMpServiceImpl<ShipmentsOr
87 private MqProducerService mqProducerService; 89 private MqProducerService mqProducerService;
88 @Resource 90 @Resource
89 private PurchaseOrderLineService purchaseOrderLineService; 91 private PurchaseOrderLineService purchaseOrderLineService;
  92 + @Resource
  93 + private ReceiptLedgerInfoService receiptLedgerInfoService;
90 94
91 95
92 @Override 96 @Override
@@ -383,6 +387,7 @@ public class ShipmentsOrderInfoServiceImpl extends BaseMpServiceImpl<ShipmentsOr @@ -383,6 +387,7 @@ public class ShipmentsOrderInfoServiceImpl extends BaseMpServiceImpl<ShipmentsOr
383 if (detailVo == null) { 387 if (detailVo == null) {
384 continue; 388 continue;
385 } 389 }
  390 + info.setActualShipmentQuantity(detailVo.getActualShipmentQuantity());
386 detail.setActualShipmentQuantity(detailVo.getActualShipmentQuantity()); 391 detail.setActualShipmentQuantity(detailVo.getActualShipmentQuantity());
387 detail.setNum(detailVo.getNum()); 392 detail.setNum(detailVo.getNum());
388 detail.setYieldBatchNo(detailVo.getYieldBatchNo()); 393 detail.setYieldBatchNo(detailVo.getYieldBatchNo());
@@ -396,6 +401,7 @@ public class ShipmentsOrderInfoServiceImpl extends BaseMpServiceImpl<ShipmentsOr @@ -396,6 +401,7 @@ public class ShipmentsOrderInfoServiceImpl extends BaseMpServiceImpl<ShipmentsOr
396 orderIds.add(info.getOrderId()); 401 orderIds.add(info.getOrderId());
397 } 402 }
398 } 403 }
  404 + orderInfo.setDetailList(shipmentsOrderDetailList);
399 // 更新发货明细 405 // 更新发货明细
400 shipmentsPlanDetailService.updateBatchById(dataList); 406 shipmentsPlanDetailService.updateBatchById(dataList);
401 // 更新发货单状态 407 // 更新发货单状态
@@ -425,6 +431,13 @@ public class ShipmentsOrderInfoServiceImpl extends BaseMpServiceImpl<ShipmentsOr @@ -425,6 +431,13 @@ public class ShipmentsOrderInfoServiceImpl extends BaseMpServiceImpl<ShipmentsOr
425 } 431 }
426 messageHandler.sendMsg(userIds, title, title, shipmentsOrderId, null); 432 messageHandler.sendMsg(userIds, title, title, shipmentsOrderId, null);
427 } 433 }
  434 + // 判断当前日期是否大于等于发货日期
  435 + LocalDate now = LocalDate.now();
  436 + LocalDate shipmentsDate = orderInfo.getShipmentsDate();
  437 + if (!now.isBefore(shipmentsDate)) {
  438 + // 生成应收款台账明细数据
  439 + receiptLedgerInfoService.generateLedgerInfo(Collections.singletonList(orderInfo));
  440 + }
428 } 441 }
429 442
430 @Override 443 @Override
@@ -434,6 +447,7 @@ public class ShipmentsOrderInfoServiceImpl extends BaseMpServiceImpl<ShipmentsOr @@ -434,6 +447,7 @@ public class ShipmentsOrderInfoServiceImpl extends BaseMpServiceImpl<ShipmentsOr
434 updateWrapper.set(ShipmentsOrderInfo::getReceiptsId, vo.getFileId()) 447 updateWrapper.set(ShipmentsOrderInfo::getReceiptsId, vo.getFileId())
435 .set(ShipmentsOrderInfo::getReceiptsName, vo.getFileName()) 448 .set(ShipmentsOrderInfo::getReceiptsName, vo.getFileName())
436 .set(ShipmentsOrderInfo::getStatus, "DELIVERED") 449 .set(ShipmentsOrderInfo::getStatus, "DELIVERED")
  450 + .set(ShipmentsOrderInfo::getDeliveryTime, LocalDateTime.now())
437 .eq(ShipmentsOrderInfo::getId, vo.getShipmentsOrderId()); 451 .eq(ShipmentsOrderInfo::getId, vo.getShipmentsOrderId());
438 getBaseMapper().update(updateWrapper); 452 getBaseMapper().update(updateWrapper);
439 // 更新订货单状态 453 // 更新订货单状态
@@ -157,4 +157,12 @@ public interface CustomerCreditService extends BaseMpService<CustomerCredit> { @@ -157,4 +157,12 @@ public interface CustomerCreditService extends BaseMpService<CustomerCredit> {
157 * @param vo 157 * @param vo
158 */ 158 */
159 void updateChange(UpdateCustomerCreditVo vo); 159 void updateChange(UpdateCustomerCreditVo vo);
  160 +
  161 + /**
  162 + * 根据客户ID获取资信数据
  163 + *
  164 + * @param customerIds 客户ID
  165 + * @return List<CustomerCredit>
  166 + */
  167 + List<CustomerCredit> listByCustomerId(List<String> customerIds);
160 } 168 }
1 package com.lframework.xingyun.sc.service.ledger; 1 package com.lframework.xingyun.sc.service.ledger;
2 2
  3 +import com.lframework.xingyun.sc.entity.ShipmentsOrderInfo;
3 import com.lframework.xingyun.sc.vo.ledger.receipt.CreateReceiptLedgerInfoVo; 4 import com.lframework.xingyun.sc.vo.ledger.receipt.CreateReceiptLedgerInfoVo;
4 import com.lframework.xingyun.sc.vo.ledger.receipt.QueryReceiptLedgerInfoVo; 5 import com.lframework.xingyun.sc.vo.ledger.receipt.QueryReceiptLedgerInfoVo;
5 import com.lframework.xingyun.sc.entity.ReceiptLedgerInfo; 6 import com.lframework.xingyun.sc.entity.ReceiptLedgerInfo;
@@ -72,4 +73,11 @@ public interface ReceiptLedgerInfoService extends BaseMpService<ReceiptLedgerInf @@ -72,4 +73,11 @@ public interface ReceiptLedgerInfoService extends BaseMpService<ReceiptLedgerInf
72 * @param id 主键ID 73 * @param id 主键ID
73 */ 74 */
74 void deleteById(String id); 75 void deleteById(String id);
  76 +
  77 + /**
  78 + * 生成台账明细
  79 + *
  80 + * @param orderInfoList 发货单数据
  81 + */
  82 + void generateLedgerInfo(List<ShipmentsOrderInfo> orderInfoList);
75 } 83 }
@@ -137,15 +137,6 @@ public class CreateReceiptLedgerInfoVo implements BaseVo, Serializable { @@ -137,15 +137,6 @@ public class CreateReceiptLedgerInfoVo implements BaseVo, Serializable {
137 private BigDecimal returnedAmount; 137 private BigDecimal returnedAmount;
138 138
139 /** 139 /**
140 - * 实际回笼金额  
141 - */  
142 - @ApiModelProperty(value = "实际回笼金额", required = true)  
143 - @NotNull(message = "请输入实际回笼金额!")  
144 - @TypeMismatch(message = "实际回笼金额格式有误!")  
145 - @IsNumberPrecision(message = "实际回笼金额最多允许4位小数!", value = 4)  
146 - private BigDecimal actualReturnedAmount;  
147 -  
148 - /**  
149 * 期末应收账款 140 * 期末应收账款
150 */ 141 */
151 @ApiModelProperty(value = "期末应收账款", required = true) 142 @ApiModelProperty(value = "期末应收账款", required = true)
@@ -25,7 +25,6 @@ @@ -25,7 +25,6 @@
25 <result column="processed_date" property="processedDate"/> 25 <result column="processed_date" property="processedDate"/>
26 <result column="actual_returned_date" property="actualReturnedDate"/> 26 <result column="actual_returned_date" property="actualReturnedDate"/>
27 <result column="returned_amount" property="returnedAmount"/> 27 <result column="returned_amount" property="returnedAmount"/>
28 - <result column="actual_returned_amount" property="actualReturnedAmount"/>  
29 <result column="end_account_receivable" property="endAccountReceivable"/> 28 <result column="end_account_receivable" property="endAccountReceivable"/>
30 <result column="apply_status" property="applyStatus"/> 29 <result column="apply_status" property="applyStatus"/>
31 <result column="coordinate_date" property="coordinateDate"/> 30 <result column="coordinate_date" property="coordinateDate"/>
@@ -66,7 +65,6 @@ @@ -66,7 +65,6 @@
66 tb.processed_date, 65 tb.processed_date,
67 tb.actual_returned_date, 66 tb.actual_returned_date,
68 tb.returned_amount, 67 tb.returned_amount,
69 - tb.actual_returned_amount,  
70 tb.end_account_receivable, 68 tb.end_account_receivable,
71 tb.apply_status, 69 tb.apply_status,
72 tb.coordinate_date, 70 tb.coordinate_date,
@@ -144,7 +142,6 @@ @@ -144,7 +142,6 @@
144 processed_date, 142 processed_date,
145 actual_returned_date, 143 actual_returned_date,
146 returned_amount, 144 returned_amount,
147 - actual_returned_amount,  
148 end_account_receivable, 145 end_account_receivable,
149 apply_status, 146 apply_status,
150 coordinate_date, 147 coordinate_date,
@@ -177,7 +174,6 @@ @@ -177,7 +174,6 @@
177 #{item.processedDate}, 174 #{item.processedDate},
178 #{item.actualReturnedDate}, 175 #{item.actualReturnedDate},
179 #{item.returnedAmount}, 176 #{item.returnedAmount},
180 - #{item.actualReturnedAmount},  
181 #{item.endAccountReceivable}, 177 #{item.endAccountReceivable},
182 #{item.applyStatus}, 178 #{item.applyStatus},
183 #{item.coordinateDate}, 179 #{item.coordinateDate},