|
@@ -0,0 +1,146 @@
|
|
|
+package com.sd.wln.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.convert.Convert;
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
+import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
|
+import com.ruoyi.common.core.domain.BaseIdPo;
|
|
|
+import com.sd.business.entity.order.enums.OrderStatusEnum;
|
|
|
+import com.sd.business.entity.order.po.OrderInfo;
|
|
|
+import com.sd.business.entity.outbound.po.OutboundOrder;
|
|
|
+import com.sd.business.entity.statement.po.StatementOfAccount;
|
|
|
+import com.sd.business.service.inventory.InventoryFinishedService;
|
|
|
+import com.sd.business.service.order.OrderInfoService;
|
|
|
+import com.sd.business.service.outbound.OutboundOrderService;
|
|
|
+import com.sd.business.service.statement.StatementOfAccountService;
|
|
|
+import com.sd.wln.service.WlnOutboundOrderService;
|
|
|
+import com.sd.wln.service.WlnStatementOfAccount;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Objects;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class WlnStatementOfAccountImpl implements WlnStatementOfAccount {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private StatementOfAccountService statementOfAccountService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private OutboundOrderService outboundOrderService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private OrderInfoService orderInfoService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private InventoryFinishedService inventoryFinishedService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private WlnOutboundOrderService wlnOutboundOrderService;
|
|
|
+
|
|
|
+ @DSTransactional
|
|
|
+ @Override
|
|
|
+ public synchronized void createStatementOfAccount() {
|
|
|
+
|
|
|
+ // 获取没绑定对账单的订单
|
|
|
+ List<OrderInfo> orderList = orderInfoService.list(q -> q
|
|
|
+ .in(OrderInfo::getStatus, OrderStatusEnum.IN_PRODUCTION.getKey(), OrderStatusEnum.COMPLETION_PRODUCTION.getKey())
|
|
|
+ .isNotNull(OrderInfo::getWlnCode)
|
|
|
+ .isNull(OrderInfo::getStatementOfAccountId));
|
|
|
+ if (orderList.isEmpty()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 订单万里牛编号集合
|
|
|
+ List<String> wlnCodeList = orderList.stream().map(OrderInfo::getWlnCode).collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 根据万里牛编号查询出库记录
|
|
|
+ List<OutboundOrder> outboundOrderList = outboundOrderService.list(q -> q.in(OutboundOrder::getOrderWlnCode, wlnCodeList));
|
|
|
+ if (outboundOrderList.isEmpty()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 订单编号以及出库时间
|
|
|
+ Map<String, Date> map = outboundOrderList.stream().collect(
|
|
|
+ Collectors.toMap(OutboundOrder::getOrderWlnCode, OutboundOrder::getOutboundTime, (t1, t2) -> t1));
|
|
|
+
|
|
|
+ // 生成对账单
|
|
|
+ Map<String, List<StatementOfAccount>> statementOfAccountMap = new HashMap<>();
|
|
|
+
|
|
|
+ List<StatementOfAccount> saveStatementOfAccountList = new ArrayList<>();
|
|
|
+ List<OrderInfo> editOrderList = new ArrayList<>();
|
|
|
+ List<Long> orderIdList = new ArrayList<>();
|
|
|
+
|
|
|
+ for (OrderInfo order : orderList) {
|
|
|
+
|
|
|
+ Date date = map.get(order.getWlnCode());
|
|
|
+ if (date == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ String outDate = DateUtil.format(date, "yyMMdd");
|
|
|
+ Date timePeriod = DateUtil.parse(DateUtil.format(date, "yyyy-MM-dd 19:00:00"));
|
|
|
+ Date beginDate = DateUtil.beginOfDay(date);
|
|
|
+ Date endDate = DateUtil.endOfDay(date);
|
|
|
+
|
|
|
+ List<StatementOfAccount> statementOfAccountList = statementOfAccountMap.computeIfAbsent(outDate, item ->
|
|
|
+ statementOfAccountService.list(q -> q.between(StatementOfAccount::getTimePeriod, beginDate, endDate)));
|
|
|
+
|
|
|
+ StatementOfAccount statementOfAccount = statementOfAccountList.stream()
|
|
|
+ .filter(item -> Objects.equals(item.getType(), 2))
|
|
|
+ .filter(item -> Objects.equals(item.getDepartmentId(), order.getDepartmentId()))
|
|
|
+ .findFirst().orElse(null);
|
|
|
+
|
|
|
+ if (statementOfAccount == null) {
|
|
|
+ int codeNumber = statementOfAccountList.stream()
|
|
|
+ .mapToInt(item -> Convert.toInt(item.getCode().split("-")[2]))
|
|
|
+ .max().orElse(0);
|
|
|
+
|
|
|
+ statementOfAccount = new StatementOfAccount();
|
|
|
+ statementOfAccount.setId(IdWorker.getId());
|
|
|
+ statementOfAccount.setCode("SOA-" + outDate + "-" + String.format("%06d", codeNumber + 1));
|
|
|
+ statementOfAccount.setDepartmentId(order.getDepartmentId());
|
|
|
+ statementOfAccount.setTimePeriod(timePeriod);
|
|
|
+ statementOfAccount.setType(2);
|
|
|
+ statementOfAccountList.add(statementOfAccount);
|
|
|
+ saveStatementOfAccountList.add(statementOfAccount);
|
|
|
+ }
|
|
|
+
|
|
|
+ OrderInfo editOrderInfo = new OrderInfo();
|
|
|
+ editOrderInfo.setId(order.getId());
|
|
|
+ editOrderInfo.setStatementOfAccountId(statementOfAccount.getId());
|
|
|
+ editOrderInfo.setShippingTime(map.get(order.getWlnCode()));
|
|
|
+
|
|
|
+ // 生产中的任务变为生产完成,生产成品入库,生成生产任务
|
|
|
+ if (order.getStatus().equals(OrderStatusEnum.IN_PRODUCTION.getKey())) {
|
|
|
+ editOrderInfo.setStatus(OrderStatusEnum.COMPLETION_PRODUCTION.getKey());
|
|
|
+ orderIdList.add(order.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ editOrderList.add(editOrderInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新订单信息
|
|
|
+ orderInfoService.updateBatchById(editOrderList);
|
|
|
+
|
|
|
+ // 保存对账单
|
|
|
+ if (!saveStatementOfAccountList.isEmpty()) {
|
|
|
+ statementOfAccountService.saveBatch(saveStatementOfAccountList);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 生产入库
|
|
|
+ inventoryFinishedService.productionWarehousing(orderIdList);
|
|
|
+
|
|
|
+ // 库存销售出库
|
|
|
+ List<Long> editOrderIdList = editOrderList.stream().map(BaseIdPo::getId).collect(Collectors.toList());
|
|
|
+ inventoryFinishedService.saleOutOfWarehouse(editOrderIdList);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+}
|