|
1
|
package com.lframework.xingyun.sc.impl.ledger;
|
1
|
package com.lframework.xingyun.sc.impl.ledger;
|
|
2
|
|
2
|
|
|
|
|
3
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
3
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
4
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
4
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
5
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
5
|
import com.github.pagehelper.PageInfo;
|
6
|
import com.github.pagehelper.PageInfo;
|
|
@@ -25,13 +26,17 @@ import com.lframework.starter.web.core.utils.PageHelperUtil; |
|
@@ -25,13 +26,17 @@ import com.lframework.starter.web.core.utils.PageHelperUtil; |
|
25
|
import com.lframework.starter.web.inner.components.oplog.OtherOpLogType;
|
26
|
import com.lframework.starter.web.inner.components.oplog.OtherOpLogType;
|
|
26
|
import com.lframework.starter.web.core.components.resp.PageResult;
|
27
|
import com.lframework.starter.web.core.components.resp.PageResult;
|
|
27
|
import com.lframework.starter.common.utils.Assert;
|
28
|
import com.lframework.starter.common.utils.Assert;
|
|
|
|
29
|
+import com.lframework.xingyun.sc.service.contract.ContractDistributorStandardService;
|
|
28
|
import com.lframework.xingyun.sc.service.customer.CustomerCreditService;
|
30
|
import com.lframework.xingyun.sc.service.customer.CustomerCreditService;
|
|
29
|
import com.lframework.xingyun.sc.service.order.PurchaseOrderInfoService;
|
31
|
import com.lframework.xingyun.sc.service.order.PurchaseOrderInfoService;
|
|
30
|
import com.lframework.xingyun.sc.service.order.PurchaseOrderLineService;
|
32
|
import com.lframework.xingyun.sc.service.order.PurchaseOrderLineService;
|
|
31
|
import com.lframework.xingyun.sc.service.shipments.ShipmentsOrderInfoService;
|
33
|
import com.lframework.xingyun.sc.service.shipments.ShipmentsOrderInfoService;
|
|
|
|
34
|
+import com.lframework.xingyun.sc.service.shipments.ShipmentsPlanDetailService;
|
|
32
|
import com.lframework.xingyun.sc.utils.CommonUtil;
|
35
|
import com.lframework.xingyun.sc.utils.CommonUtil;
|
|
33
|
import com.lframework.xingyun.sc.vo.ledger.receipt.*;
|
36
|
import com.lframework.xingyun.sc.vo.ledger.receipt.*;
|
|
|
|
37
|
+import lombok.extern.slf4j.Slf4j;
|
|
34
|
import org.apache.commons.collections4.CollectionUtils;
|
38
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
|
39
|
+import org.apache.commons.lang3.StringUtils;
|
|
35
|
import org.springframework.transaction.annotation.Transactional;
|
40
|
import org.springframework.transaction.annotation.Transactional;
|
|
36
|
import com.lframework.xingyun.sc.mappers.ReceiptLedgerInfoMapper;
|
41
|
import com.lframework.xingyun.sc.mappers.ReceiptLedgerInfoMapper;
|
|
37
|
import com.lframework.xingyun.sc.service.ledger.ReceiptLedgerInfoService;
|
42
|
import com.lframework.xingyun.sc.service.ledger.ReceiptLedgerInfoService;
|
|
@@ -41,11 +46,15 @@ import javax.annotation.Resource; |
|
@@ -41,11 +46,15 @@ import javax.annotation.Resource; |
|
41
|
import java.math.BigDecimal;
|
46
|
import java.math.BigDecimal;
|
|
42
|
import java.math.RoundingMode;
|
47
|
import java.math.RoundingMode;
|
|
43
|
import java.time.LocalDate;
|
48
|
import java.time.LocalDate;
|
|
|
|
49
|
+import java.time.LocalDateTime;
|
|
44
|
import java.time.temporal.ChronoUnit;
|
50
|
import java.time.temporal.ChronoUnit;
|
|
|
|
51
|
+import java.time.temporal.TemporalAdjusters;
|
|
45
|
import java.util.*;
|
52
|
import java.util.*;
|
|
46
|
import java.util.function.Function;
|
53
|
import java.util.function.Function;
|
|
47
|
import java.util.stream.Collectors;
|
54
|
import java.util.stream.Collectors;
|
|
48
|
|
55
|
|
|
|
|
56
|
+
|
|
|
|
57
|
+@Slf4j
|
|
49
|
@Service
|
58
|
@Service
|
|
50
|
public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedgerInfoMapper, ReceiptLedgerInfo> implements ReceiptLedgerInfoService {
|
59
|
public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedgerInfoMapper, ReceiptLedgerInfo> implements ReceiptLedgerInfoService {
|
|
51
|
|
60
|
|
|
@@ -64,6 +73,10 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge |
|
@@ -64,6 +73,10 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge |
|
64
|
private PurchaseOrderLineService purchaseOrderLineService;
|
73
|
private PurchaseOrderLineService purchaseOrderLineService;
|
|
65
|
@Resource
|
74
|
@Resource
|
|
66
|
private ShipmentsOrderInfoService shipmentsOrderInfoService;
|
75
|
private ShipmentsOrderInfoService shipmentsOrderInfoService;
|
|
|
|
76
|
+ @Resource
|
|
|
|
77
|
+ private ShipmentsPlanDetailService shipmentsPlanDetailService;
|
|
|
|
78
|
+ @Resource
|
|
|
|
79
|
+ private ContractDistributorStandardService contractDistributorStandardService;
|
|
67
|
|
80
|
|
|
68
|
|
81
|
|
|
69
|
// 定义状态优先级顺序(从高到低)
|
82
|
// 定义状态优先级顺序(从高到低)
|
|
@@ -336,10 +349,17 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge |
|
@@ -336,10 +349,17 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge |
|
336
|
customerShortNameMap = customerShortList.stream().collect(Collectors.toMap(CustomerShort::getCustomerId, CustomerShort::getId
|
349
|
customerShortNameMap = customerShortList.stream().collect(Collectors.toMap(CustomerShort::getCustomerId, CustomerShort::getId
|
|
337
|
, (v1, v2) -> v1));
|
350
|
, (v1, v2) -> v1));
|
|
338
|
}
|
351
|
}
|
|
|
|
352
|
+ List<String> contractIds = new ArrayList<>();
|
|
339
|
// 订货单信息
|
353
|
// 订货单信息
|
|
340
|
Map<String, PurchaseOrderInfo> orderInfoMap = new HashMap<>();
|
354
|
Map<String, PurchaseOrderInfo> orderInfoMap = new HashMap<>();
|
|
341
|
List<PurchaseOrderInfo> orderInfoList = purchaseOrderInfoService.listByIds(orderIds);
|
355
|
List<PurchaseOrderInfo> orderInfoList = purchaseOrderInfoService.listByIds(orderIds);
|
|
342
|
if (CollectionUtils.isNotEmpty(orderInfoList)) {
|
356
|
if (CollectionUtils.isNotEmpty(orderInfoList)) {
|
|
|
|
357
|
+ for (PurchaseOrderInfo orderInfo : orderInfoList) {
|
|
|
|
358
|
+ if (!contractIds.contains(orderInfo.getContractId())) {
|
|
|
|
359
|
+ contractIds.add(orderInfo.getContractId());
|
|
|
|
360
|
+ }
|
|
|
|
361
|
+ orderInfoMap.put(orderInfo.getId(), orderInfo);
|
|
|
|
362
|
+ }
|
|
343
|
orderInfoMap = orderInfoList.stream().collect(Collectors.toMap(PurchaseOrderInfo::getId, Function.identity()));
|
363
|
orderInfoMap = orderInfoList.stream().collect(Collectors.toMap(PurchaseOrderInfo::getId, Function.identity()));
|
|
344
|
}
|
364
|
}
|
|
345
|
// 订货单规格信息
|
365
|
// 订货单规格信息
|
|
@@ -348,11 +368,18 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge |
|
@@ -348,11 +368,18 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge |
|
348
|
if (CollectionUtils.isNotEmpty(orderSpecList)) {
|
368
|
if (CollectionUtils.isNotEmpty(orderSpecList)) {
|
|
349
|
orderSpecMap = orderSpecList.stream().collect(Collectors.toMap(PurchaseOrderLine::getId, Function.identity()));
|
369
|
orderSpecMap = orderSpecList.stream().collect(Collectors.toMap(PurchaseOrderLine::getId, Function.identity()));
|
|
350
|
}
|
370
|
}
|
|
|
|
371
|
+ // 合同信息
|
|
|
|
372
|
+ Map<String, ContractDistributorStandard> contractMap = new HashMap<>();
|
|
|
|
373
|
+ List<ContractDistributorStandard> contractList = contractDistributorStandardService.listByIds(contractIds);
|
|
|
|
374
|
+ if (CollectionUtils.isNotEmpty(contractList)) {
|
|
|
|
375
|
+ contractMap = contractList.stream().collect(Collectors.toMap(ContractDistributorStandard::getId, Function.identity()));
|
|
|
|
376
|
+ }
|
|
351
|
List<ReceiptLedgerInfo> dataList = new ArrayList<>();
|
377
|
List<ReceiptLedgerInfo> dataList = new ArrayList<>();
|
|
352
|
for (ShipmentsOrderInfo shipmentsOrderInfo : shipmentsOrderInfoList) {
|
378
|
for (ShipmentsOrderInfo shipmentsOrderInfo : shipmentsOrderInfoList) {
|
|
353
|
String customerId = shipmentsOrderInfo.getCustomerId();
|
379
|
String customerId = shipmentsOrderInfo.getCustomerId();
|
|
354
|
ReceiptLedgerInfo data = new ReceiptLedgerInfo();
|
380
|
ReceiptLedgerInfo data = new ReceiptLedgerInfo();
|
|
355
|
data.setId(IdUtil.getId());
|
381
|
data.setId(IdUtil.getId());
|
|
|
|
382
|
+ data.setShipmentOrderId(shipmentsOrderInfo.getId());
|
|
356
|
String shortNameId = customerShortNameMap.get(customerId);
|
383
|
String shortNameId = customerShortNameMap.get(customerId);
|
|
357
|
data.setCustomerShortId(shortNameId);
|
384
|
data.setCustomerShortId(shortNameId);
|
|
358
|
CustomerCredit credit = customerCreditMap.get(customerId);
|
385
|
CustomerCredit credit = customerCreditMap.get(customerId);
|
|
@@ -369,6 +396,8 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge |
|
@@ -369,6 +396,8 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge |
|
369
|
data.setRegion(shipmentsOrderInfo.getRegion());
|
396
|
data.setRegion(shipmentsOrderInfo.getRegion());
|
|
370
|
data.setCustomerId(shipmentsOrderInfo.getCustomerId());
|
397
|
data.setCustomerId(shipmentsOrderInfo.getCustomerId());
|
|
371
|
data.setShipmentDate(shipmentsOrderInfo.getShipmentsDate());
|
398
|
data.setShipmentDate(shipmentsOrderInfo.getShipmentsDate());
|
|
|
|
399
|
+
|
|
|
|
400
|
+ String contractType = null;
|
|
372
|
List<String> supplyUnitList = new ArrayList<>();
|
401
|
List<String> supplyUnitList = new ArrayList<>();
|
|
373
|
// 计算期初应收款
|
402
|
// 计算期初应收款
|
|
374
|
BigDecimal startAccountReceivable = BigDecimal.ZERO;
|
403
|
BigDecimal startAccountReceivable = BigDecimal.ZERO;
|
|
@@ -388,6 +417,11 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge |
|
@@ -388,6 +417,11 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge |
|
388
|
if (!supplyUnitList.contains(supplyUnit)) {
|
417
|
if (!supplyUnitList.contains(supplyUnit)) {
|
|
389
|
supplyUnitList.add(supplyUnit);
|
418
|
supplyUnitList.add(supplyUnit);
|
|
390
|
}
|
419
|
}
|
|
|
|
420
|
+ // 获取合同类型
|
|
|
|
421
|
+ ContractDistributorStandard contract = contractMap.get(orderInfo.getContractId());
|
|
|
|
422
|
+ if (contract != null && StringUtils.isBlank(contractType)) {
|
|
|
|
423
|
+ contractType = contract.getType();
|
|
|
|
424
|
+ }
|
|
391
|
}
|
425
|
}
|
|
392
|
String factoryType = String.join(",", supplyUnitList);
|
426
|
String factoryType = String.join(",", supplyUnitList);
|
|
393
|
data.setFactoryType(factoryType);
|
427
|
data.setFactoryType(factoryType);
|
|
@@ -396,6 +430,13 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge |
|
@@ -396,6 +430,13 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge |
|
396
|
data.setArrivalDate(shipmentsOrderInfo.getDeliveryTime().toLocalDate());
|
430
|
data.setArrivalDate(shipmentsOrderInfo.getDeliveryTime().toLocalDate());
|
|
397
|
}
|
431
|
}
|
|
398
|
data.setEndAccountReceivable(startAccountReceivable);
|
432
|
data.setEndAccountReceivable(startAccountReceivable);
|
|
|
|
433
|
+ // 内外贸区分
|
|
|
|
434
|
+ if ("INTL_STD_CONTRACT".equals(contractType) || "INTL_INVENTORY_AGMT".equals(contractType) || "INTL_OPEN_SPEC_AGMT".equals(contractType)) {
|
|
|
|
435
|
+ // 外贸
|
|
|
|
436
|
+ data.setType("OUTSIDE");
|
|
|
|
437
|
+ } else {
|
|
|
|
438
|
+ data.setType("INSIDE");
|
|
|
|
439
|
+ }
|
|
399
|
|
440
|
|
|
400
|
dataList.add(data);
|
441
|
dataList.add(data);
|
|
401
|
}
|
442
|
}
|
|
@@ -642,6 +683,70 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge |
|
@@ -642,6 +683,70 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge |
|
642
|
OpLogUtil.setExtra(vo);
|
683
|
OpLogUtil.setExtra(vo);
|
|
643
|
}
|
684
|
}
|
|
644
|
|
685
|
|
|
|
|
686
|
+ @Override
|
|
|
|
687
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
688
|
+ public void autoGenerate() {
|
|
|
|
689
|
+ List<String> statusList = new ArrayList<>();
|
|
|
|
690
|
+ statusList.add("SHIPMENTS");
|
|
|
|
691
|
+ statusList.add("DELIVERED");
|
|
|
|
692
|
+ LambdaQueryWrapper<ShipmentsOrderInfo> queryWrapper = Wrappers.lambdaQuery(ShipmentsOrderInfo.class);
|
|
|
|
693
|
+ queryWrapper.eq(ShipmentsOrderInfo::getShipmentsDate, LocalDate.now())
|
|
|
|
694
|
+ .in(ShipmentsOrderInfo::getStatus, statusList);
|
|
|
|
695
|
+ List<ShipmentsOrderInfo> shipmentsOrderInfos = shipmentsOrderInfoService.getBaseMapper().selectList(queryWrapper);
|
|
|
|
696
|
+ if (CollectionUtils.isEmpty(shipmentsOrderInfos)) {
|
|
|
|
697
|
+ log.info("========================== 没有需要生成台账数据的发货单!");
|
|
|
|
698
|
+ return;
|
|
|
|
699
|
+ }
|
|
|
|
700
|
+ List<String> shipmentOrderIds = shipmentsOrderInfos.stream().map(ShipmentsOrderInfo::getId).collect(Collectors.toList());
|
|
|
|
701
|
+ Map<String, List<ShipmentsPlanDetail>> shipmentDetailMap = new HashMap<>();
|
|
|
|
702
|
+ // 获取发货明细数据
|
|
|
|
703
|
+ List<ShipmentsPlanDetail> detailList = shipmentsPlanDetailService.listByShipmentOrderId(shipmentOrderIds);
|
|
|
|
704
|
+ for (ShipmentsPlanDetail detail : detailList) {
|
|
|
|
705
|
+ String shipmentOrderId = detail.getShipmentOrderId();
|
|
|
|
706
|
+ List<ShipmentsPlanDetail> list = shipmentDetailMap.computeIfAbsent(shipmentOrderId, k -> new ArrayList<>());
|
|
|
|
707
|
+ list.add(detail);
|
|
|
|
708
|
+ }
|
|
|
|
709
|
+ // 数据组装
|
|
|
|
710
|
+ for (ShipmentsOrderInfo orderInfo : shipmentsOrderInfos) {
|
|
|
|
711
|
+ String id = orderInfo.getId();
|
|
|
|
712
|
+ List<ShipmentsPlanDetail> shipmentDetails = shipmentDetailMap.get(id);
|
|
|
|
713
|
+ orderInfo.setDetailList(shipmentDetails);
|
|
|
|
714
|
+ }
|
|
|
|
715
|
+ generateLedgerInfo(shipmentsOrderInfos);
|
|
|
|
716
|
+ }
|
|
|
|
717
|
+
|
|
|
|
718
|
+ @Override
|
|
|
|
719
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
720
|
+ public void againGenerate() {
|
|
|
|
721
|
+ // 获取当前日期
|
|
|
|
722
|
+ LocalDate now = LocalDate.now();
|
|
|
|
723
|
+ // 获取上个月的第一天
|
|
|
|
724
|
+ LocalDateTime startDateTime = now.minusMonths(1).withDayOfMonth(1).atStartOfDay();
|
|
|
|
725
|
+ // 获取上个月的最后一天
|
|
|
|
726
|
+ LocalDateTime endDateTime = now.minusMonths(1).with(TemporalAdjusters.lastDayOfMonth())
|
|
|
|
727
|
+ .atTime(23, 59, 59);
|
|
|
|
728
|
+ LambdaQueryWrapper<ReceiptLedgerInfo> queryWrapper = Wrappers.lambdaQuery(ReceiptLedgerInfo.class);
|
|
|
|
729
|
+ queryWrapper.eq(ReceiptLedgerInfo::getDelFlag, Boolean.FALSE)
|
|
|
|
730
|
+ .ge(ReceiptLedgerInfo::getCreateTime, startDateTime)
|
|
|
|
731
|
+ .le(ReceiptLedgerInfo::getCreateTime, endDateTime)
|
|
|
|
732
|
+ .gt(ReceiptLedgerInfo::getEndAccountReceivable, BigDecimal.ZERO);
|
|
|
|
733
|
+ List<ReceiptLedgerInfo> ledgerInfoList = getBaseMapper().selectList(queryWrapper);
|
|
|
|
734
|
+ if (CollectionUtils.isEmpty(ledgerInfoList)) {
|
|
|
|
735
|
+ log.info("======================== 上个月没有应收款台账数据!");
|
|
|
|
736
|
+ return;
|
|
|
|
737
|
+ }
|
|
|
|
738
|
+ LocalDateTime nowTime = LocalDateTime.now();
|
|
|
|
739
|
+ for (ReceiptLedgerInfo ledgerInfo : ledgerInfoList) {
|
|
|
|
740
|
+ ledgerInfo.setId(IdUtil.getId());
|
|
|
|
741
|
+ ledgerInfo.setStartAccountReceivable(ledgerInfo.getEndAccountReceivable());
|
|
|
|
742
|
+ ledgerInfo.setActualReturnedDate(null);
|
|
|
|
743
|
+ ledgerInfo.setReturnedAmount(null);
|
|
|
|
744
|
+ ledgerInfo.setCreateTime(nowTime);
|
|
|
|
745
|
+ ledgerInfo.setUpdateTime(null);
|
|
|
|
746
|
+ }
|
|
|
|
747
|
+ baseMapper.batchAdd(ledgerInfoList);
|
|
|
|
748
|
+ }
|
|
|
|
749
|
+
|
|
645
|
|
750
|
|
|
646
|
/**
|
751
|
/**
|
|
647
|
* 从多个状态中获取最高优先级的状态
|
752
|
* 从多个状态中获取最高优先级的状态
|