Commit 4d4e558a43897471292f34efee813ac8359fa01e

Authored by yeqianyong
1 parent 02dc099b

楚江erp:定时任务生成应收款台账数据

... ... @@ -4,7 +4,6 @@ import com.lframework.starter.mq.core.utils.ExportTaskUtil;
4 4 import com.lframework.xingyun.sc.bo.ledger.receipt.GetReceiptLedgerInfoBo;
5 5 import com.lframework.xingyun.sc.bo.ledger.receipt.QueryReceiptLedgerInfoBo;
6 6 import com.lframework.xingyun.sc.bo.ledger.receipt.ReceiptLedgerReportBo;
7   -import com.lframework.xingyun.sc.enums.ExportType;
8 7 import com.lframework.xingyun.sc.excel.ledger.LedgerReportExportTaskWorker;
9 8 import com.lframework.xingyun.sc.utils.CommonUtil;
10 9 import com.lframework.xingyun.sc.vo.ledger.receipt.*;
... ... @@ -19,6 +18,7 @@ import io.swagger.annotations.ApiOperation;
19 18 import com.lframework.starter.common.utils.CollectionUtil;
20 19 import io.swagger.annotations.Api;
21 20 import org.apache.commons.lang3.StringUtils;
  21 +import org.springframework.scheduling.annotation.Scheduled;
22 22 import org.springframework.web.bind.annotation.DeleteMapping;
23 23 import com.lframework.starter.web.core.components.resp.PageResult;
24 24 import com.lframework.starter.web.core.components.resp.InvokeResult;
... ... @@ -42,6 +42,8 @@ import java.util.stream.Collectors;
42 42 @RestController
43 43 @RequestMapping("/ledger/receipt")
44 44 public class ReceiptLedgerInfoController extends DefaultBaseController {
  45 +
  46 +
45 47 @Resource
46 48 private ReceiptLedgerInfoService receiptLedgerInfoService;
47 49
... ... @@ -157,4 +159,27 @@ public class ReceiptLedgerInfoController extends DefaultBaseController {
157 159 ExportTaskUtil.exportTask("应收款台账报表信息", LedgerReportExportTaskWorker.class, vo);
158 160 return InvokeResultBuilder.success();
159 161 }
  162 +
  163 +
  164 + /**
  165 + * 自动生成台账明细数据
  166 + */
  167 + @ApiOperation("自动生成台账明细数据")
  168 + @GetMapping("/autoGenerate")
  169 + @Scheduled(cron = "0 10 2 * * ?")
  170 + public InvokeResult<Void> autoGenerate() {
  171 + receiptLedgerInfoService.autoGenerate();
  172 + return InvokeResultBuilder.success();
  173 + }
  174 +
  175 + /**
  176 + * 重新生成新的台账数据
  177 + */
  178 + @ApiOperation("自动生成台账明细数据")
  179 + @GetMapping("/againGenerate")
  180 + @Scheduled(cron = "0 30 2 1 * ?")
  181 + public InvokeResult<Void> againGenerate() {
  182 + receiptLedgerInfoService.againGenerate();
  183 + return InvokeResultBuilder.success();
  184 + }
160 185 }
... ...
... ... @@ -203,6 +203,11 @@ public class ReceiptLedgerInfo extends BaseEntity implements BaseDto {
203 203 private Integer delFlag;
204 204
205 205 /**
  206 + * 发货单ID
  207 + */
  208 + private String shipmentOrderId;
  209 +
  210 + /**
206 211 * 创建人ID
207 212 */
208 213 @TableField(fill = FieldFill.INSERT)
... ...
... ... @@ -138,7 +138,7 @@ public class LedgerReportExportHandler implements ExportHandler {
138 138 builder.deleteCharAt(builder.length() - 1);
139 139 }
140 140 }
141   - dataMap.put("titleSuffix", "——" + builder.toString());
  141 + dataMap.put("titleSuffix", "——" + builder);
142 142 ExcelUtil.processTemplate(workbook, dataMap);
143 143 // 将workbook写入文件
144 144 try (FileOutputStream outputStream = new FileOutputStream(xlsxFile)) {
... ...
1 1 package com.lframework.xingyun.sc.impl.ledger;
2 2
  3 +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
3 4 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
4 5 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
5 6 import com.github.pagehelper.PageInfo;
... ... @@ -25,13 +26,17 @@ import com.lframework.starter.web.core.utils.PageHelperUtil;
25 26 import com.lframework.starter.web.inner.components.oplog.OtherOpLogType;
26 27 import com.lframework.starter.web.core.components.resp.PageResult;
27 28 import com.lframework.starter.common.utils.Assert;
  29 +import com.lframework.xingyun.sc.service.contract.ContractDistributorStandardService;
28 30 import com.lframework.xingyun.sc.service.customer.CustomerCreditService;
29 31 import com.lframework.xingyun.sc.service.order.PurchaseOrderInfoService;
30 32 import com.lframework.xingyun.sc.service.order.PurchaseOrderLineService;
31 33 import com.lframework.xingyun.sc.service.shipments.ShipmentsOrderInfoService;
  34 +import com.lframework.xingyun.sc.service.shipments.ShipmentsPlanDetailService;
32 35 import com.lframework.xingyun.sc.utils.CommonUtil;
33 36 import com.lframework.xingyun.sc.vo.ledger.receipt.*;
  37 +import lombok.extern.slf4j.Slf4j;
34 38 import org.apache.commons.collections4.CollectionUtils;
  39 +import org.apache.commons.lang3.StringUtils;
35 40 import org.springframework.transaction.annotation.Transactional;
36 41 import com.lframework.xingyun.sc.mappers.ReceiptLedgerInfoMapper;
37 42 import com.lframework.xingyun.sc.service.ledger.ReceiptLedgerInfoService;
... ... @@ -41,11 +46,15 @@ import javax.annotation.Resource;
41 46 import java.math.BigDecimal;
42 47 import java.math.RoundingMode;
43 48 import java.time.LocalDate;
  49 +import java.time.LocalDateTime;
44 50 import java.time.temporal.ChronoUnit;
  51 +import java.time.temporal.TemporalAdjusters;
45 52 import java.util.*;
46 53 import java.util.function.Function;
47 54 import java.util.stream.Collectors;
48 55
  56 +
  57 +@Slf4j
49 58 @Service
50 59 public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedgerInfoMapper, ReceiptLedgerInfo> implements ReceiptLedgerInfoService {
51 60
... ... @@ -64,6 +73,10 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge
64 73 private PurchaseOrderLineService purchaseOrderLineService;
65 74 @Resource
66 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 349 customerShortNameMap = customerShortList.stream().collect(Collectors.toMap(CustomerShort::getCustomerId, CustomerShort::getId
337 350 , (v1, v2) -> v1));
338 351 }
  352 + List<String> contractIds = new ArrayList<>();
339 353 // 订货单信息
340 354 Map<String, PurchaseOrderInfo> orderInfoMap = new HashMap<>();
341 355 List<PurchaseOrderInfo> orderInfoList = purchaseOrderInfoService.listByIds(orderIds);
342 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 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 368 if (CollectionUtils.isNotEmpty(orderSpecList)) {
349 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 377 List<ReceiptLedgerInfo> dataList = new ArrayList<>();
352 378 for (ShipmentsOrderInfo shipmentsOrderInfo : shipmentsOrderInfoList) {
353 379 String customerId = shipmentsOrderInfo.getCustomerId();
354 380 ReceiptLedgerInfo data = new ReceiptLedgerInfo();
355 381 data.setId(IdUtil.getId());
  382 + data.setShipmentOrderId(shipmentsOrderInfo.getId());
356 383 String shortNameId = customerShortNameMap.get(customerId);
357 384 data.setCustomerShortId(shortNameId);
358 385 CustomerCredit credit = customerCreditMap.get(customerId);
... ... @@ -369,6 +396,8 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge
369 396 data.setRegion(shipmentsOrderInfo.getRegion());
370 397 data.setCustomerId(shipmentsOrderInfo.getCustomerId());
371 398 data.setShipmentDate(shipmentsOrderInfo.getShipmentsDate());
  399 +
  400 + String contractType = null;
372 401 List<String> supplyUnitList = new ArrayList<>();
373 402 // 计算期初应收款
374 403 BigDecimal startAccountReceivable = BigDecimal.ZERO;
... ... @@ -388,6 +417,11 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge
388 417 if (!supplyUnitList.contains(supplyUnit)) {
389 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 426 String factoryType = String.join(",", supplyUnitList);
393 427 data.setFactoryType(factoryType);
... ... @@ -396,6 +430,13 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge
396 430 data.setArrivalDate(shipmentsOrderInfo.getDeliveryTime().toLocalDate());
397 431 }
398 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 441 dataList.add(data);
401 442 }
... ... @@ -642,6 +683,70 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge
642 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 * 从多个状态中获取最高优先级的状态
... ...
... ... @@ -112,4 +112,15 @@ public interface ReceiptLedgerInfoService extends BaseMpService<ReceiptLedgerInf
112 112 * @param vo 数据
113 113 */
114 114 void reconciliation(UpdateReceiptLedgerInfoVo vo);
  115 +
  116 + /**
  117 + * 自动生成台账明细数据
  118 + * 今天要发货并且已填完实发数的数据
  119 + */
  120 + void autoGenerate();
  121 +
  122 + /**
  123 + * 重新生成新的台账数据
  124 + */
  125 + void againGenerate();
115 126 }
... ...
... ... @@ -170,6 +170,7 @@
170 170 fourth_coordinate_date,
171 171 fifth_coordinate_date,
172 172 description,
  173 + shipment_order_id,
173 174 create_by_id,
174 175 update_by_id,
175 176 create_time,
... ... @@ -203,6 +204,7 @@
203 204 #{item.fourthCoordinateDate},
204 205 #{item.fifthCoordinateDate},
205 206 #{item.description},
  207 + #{item.shipmentOrderId},
206 208 #{item.createById},
207 209 #{item.updateById},
208 210 #{item.createTime},
... ...