|
...
|
...
|
@@ -9,7 +9,11 @@ import com.lframework.starter.common.utils.StringUtil; |
|
9
|
9
|
import com.lframework.starter.web.core.components.security.SecurityUtil;
|
|
10
|
10
|
import com.lframework.starter.web.inner.entity.SysDataDicItem;
|
|
11
|
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
|
17
|
import com.lframework.starter.web.core.impl.BaseMpServiceImpl;
|
|
14
|
18
|
import com.lframework.starter.web.core.utils.PageResultUtil;
|
|
15
|
19
|
import com.lframework.starter.web.core.utils.OpLogUtil;
|
|
...
|
...
|
@@ -19,6 +23,9 @@ import com.lframework.starter.web.core.utils.PageHelperUtil; |
|
19
|
23
|
import com.lframework.starter.web.inner.components.oplog.OtherOpLogType;
|
|
20
|
24
|
import com.lframework.starter.web.core.components.resp.PageResult;
|
|
21
|
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
|
29
|
import com.lframework.xingyun.sc.utils.CommonUtil;
|
|
23
|
30
|
import com.lframework.xingyun.sc.vo.ledger.receipt.ReceiptLedgerInfoSplitVo;
|
|
24
|
31
|
import com.lframework.xingyun.sc.vo.ledger.receipt.UpdateReceiptLedgerInfoVo;
|
|
...
|
...
|
@@ -32,10 +39,10 @@ import org.springframework.stereotype.Service; |
|
32
|
39
|
|
|
33
|
40
|
import javax.annotation.Resource;
|
|
34
|
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
|
46
|
import java.util.stream.Collectors;
|
|
40
|
47
|
|
|
41
|
48
|
@Service
|
|
...
|
...
|
@@ -44,6 +51,16 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge |
|
44
|
51
|
|
|
45
|
52
|
@Resource
|
|
46
|
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
|
98
|
public ReceiptLedgerInfo findById(String id) {
|
|
82
|
99
|
QueryReceiptLedgerInfoVo ledgerInfoVo = new QueryReceiptLedgerInfoVo();
|
|
83
|
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
|
105
|
@OpLog(type = OtherOpLogType.class, name = "新增应收款台账明细,ID:{}", params = {"#id"})
|
|
...
|
...
|
@@ -105,7 +123,6 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge |
|
105
|
123
|
data.setProcessedDate(vo.getProcessedDate());
|
|
106
|
124
|
data.setActualReturnedDate(vo.getActualReturnedDate());
|
|
107
|
125
|
data.setReturnedAmount(vo.getReturnedAmount());
|
|
108
|
|
- data.setActualReturnedAmount(vo.getActualReturnedAmount());
|
|
109
|
126
|
data.setEndAccountReceivable(vo.getEndAccountReceivable());
|
|
110
|
127
|
data.setApplyStatus(vo.getApplyStatus());
|
|
111
|
128
|
data.setCoordinateDate(vo.getCoordinateDate());
|
|
...
|
...
|
@@ -131,10 +148,13 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge |
|
131
|
148
|
if (ObjectUtil.isNull(data)) {
|
|
132
|
149
|
throw new DefaultClientException("应收款台账明细不存在!");
|
|
133
|
150
|
}
|
|
|
151
|
+ // 获取欠款状态
|
|
|
152
|
+ String settlementStatus = getSettlementStatus(data.getEndAccountReceivable(), data.getProcessedDate());
|
|
134
|
153
|
LambdaUpdateWrapper<ReceiptLedgerInfo> updateWrapper = Wrappers.lambdaUpdate(ReceiptLedgerInfo.class)
|
|
135
|
154
|
.set(ReceiptLedgerInfo::getDescription, StringUtil.isBlank(vo.getDescription()) ? null : vo.getDescription())
|
|
136
|
155
|
.set(ReceiptLedgerInfo::getProcessedDate, vo.getProcessedDate() == null ? null : vo.getProcessedDate())
|
|
137
|
156
|
.set(ReceiptLedgerInfo::getRemark, StringUtil.isBlank(vo.getRemark()) ? null : vo.getRemark())
|
|
|
157
|
+ .set(ReceiptLedgerInfo::getDebtStatus, settlementStatus)
|
|
138
|
158
|
.eq(ReceiptLedgerInfo::getId, vo.getId());
|
|
139
|
159
|
|
|
140
|
160
|
getBaseMapper().update(updateWrapper);
|
|
...
|
...
|
@@ -214,7 +234,6 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge |
|
214
|
234
|
data.setProcessedDate(vo.getProcessedDate());
|
|
215
|
235
|
data.setActualReturnedDate(vo.getActualReturnedDate());
|
|
216
|
236
|
data.setReturnedAmount(vo.getReturnedAmount());
|
|
217
|
|
- data.setActualReturnedAmount(vo.getActualReturnedAmount());
|
|
218
|
237
|
//拆分的时候期末应收账款=期初-回笼资金(这时候为0)
|
|
219
|
238
|
data.setEndAccountReceivable(quantity);
|
|
220
|
239
|
data.setApplyStatus(vo.getApplyStatus());
|
|
...
|
...
|
@@ -236,4 +255,152 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge |
|
236
|
255
|
public void deleteById(String id) {
|
|
237
|
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
|
} |
...
|
...
|
|