Răsfoiți Sursa

订单自动一键包装、自动生成对账单定时任务

24282 1 an în urmă
părinte
comite
94410e3dcb

+ 1 - 1
sd-business/src/main/java/com/sd/business/entity/statement/po/StatementOfAccount.java

@@ -39,7 +39,7 @@ public class StatementOfAccount extends BasePo {
     /**
      * 对账时间段开始时间
      */
-    private Date timePeriodStart;
+    private Date timePeriodBegin;
 
     /**
      * 对账时间段结束时间

+ 4 - 0
sd-business/src/main/java/com/sd/business/util/CodeEnum.java

@@ -10,6 +10,7 @@ import com.ruoyi.common.exception.ServiceException;
 import com.sd.business.service.apply.ApplyBuyService;
 import com.sd.business.service.in.InOutStorageService;
 import com.sd.business.service.lend.LendService;
+import com.sd.business.service.statement.StatementOfAccountService;
 import lombok.Getter;
 
 import java.util.Date;
@@ -26,6 +27,9 @@ public enum CodeEnum {
     IN_CODE("DTS", "-yyMMdd-", "code", 6, InOutStorageService.class),
     // 入库编号
     OUT_CODE("OS", "-yyMMdd-", "code", 6, InOutStorageService.class),
+    // 对账单号
+    STATEMENT_OF_ACCOUNT_CODE("SOA", "-yyMMdd-", "code", 6, StatementOfAccountService.class),
+
     ;
 
     // 编码前缀

+ 1 - 1
sd-business/src/main/resources/mapper/statement/StatementOfAccountMapper.xml

@@ -6,7 +6,7 @@
                soa.code,
                soa.department_id,
                soa.amount,
-               soa.time_period_start,
+               soa.time_period_begin,
                soa.time_period_end,
                soa.order_id_join,
                soa.create_user,

+ 95 - 9
sd-wln/src/main/java/com/sd/wln/service/impl/WlnStatementOfAccountImpl.java

@@ -1,18 +1,26 @@
 package com.sd.wln.service.impl;
 
+import cn.hutool.core.convert.Convert;
 import cn.hutool.core.date.DateUtil;
+import com.ruoyi.common.core.domain.BaseIdPo;
 import com.ruoyi.common.core.domain.BasePo;
+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.order.OrderService;
 import com.sd.business.service.outbound.OutboundOrderService;
 import com.sd.business.service.statement.StatementOfAccountService;
+import com.sd.business.util.CodeEnum;
 import com.sd.wln.service.WlnStatementOfAccount;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
+import java.math.BigDecimal;
+import java.util.*;
+import java.util.function.Function;
+import java.util.stream.Collectors;
 
 @Service
 public class WlnStatementOfAccountImpl implements WlnStatementOfAccount {
@@ -23,20 +31,98 @@ public class WlnStatementOfAccountImpl implements WlnStatementOfAccount {
     @Autowired
     private OutboundOrderService outboundOrderService;
 
+    @Autowired
+    private OrderService orderService;
+
+    @Transactional
     @Override
     public void createStatementOfAccount() {
         Date date = new Date();
 
-        Map<Long, StatementOfAccount> statementOfAccountMap = statementOfAccountService.mapKEntity(
-                StatementOfAccount::getDepartmentId,
-                q -> q
-                        .eq(StatementOfAccount::getType, 2)
-                        .between(BasePo::getCreateTime, DateUtil.beginOfDay(date), DateUtil.endOfDay(date))
-        );
+        List<OrderInfo> editOrderList = new ArrayList<>();
 
+        // 获取当天出库单
         List<OutboundOrder> list = outboundOrderService.list(q -> q
                 .between(BasePo::getCreateTime, DateUtil.beginOfDay(date), DateUtil.endOfDay(date)));
+        if (list.size() == 0) {
+            return;
+        }
+
+        // 根据出库单查询订单
+        Map<String, Date> map = list.stream().collect(
+                Collectors.toMap(OutboundOrder::getOrderWlnCode, OutboundOrder::getOutboundTime, (t1, t2) -> t1));
+
+        // 查询与出库单关联的订单
+        List<OrderInfo> orderList = orderService.list(q -> q
+                .in(OrderInfo::getWlnCode, map.keySet())
+                .ge(OrderInfo::getStatus, OrderStatusEnum.IN_PRODUCTION.getKey())
+                .notIn(OrderInfo::getStatus, OrderStatusEnum.DELETE.getKey(), OrderStatusEnum.EXCEPTION.getKey())
+        );
+
+        // 循环订单,把生产中的订单改为生产完成
+        for (OrderInfo orderInfo : orderList) {
+            Integer status = orderInfo.getStatus();
+            if (status.equals(OrderStatusEnum.IN_PRODUCTION.getKey())) {
+                OrderInfo tempOrderInfo = new OrderInfo();
+                tempOrderInfo.setStatus(OrderStatusEnum.COMPLETION_PRODUCTION.getKey());
+                tempOrderInfo.setShippingTime(map.get(orderInfo.getWlnCode()));
+                editOrderList.add(tempOrderInfo);
+            }
+        }
+
+        // 生成对账单
+        List<StatementOfAccount> statementOfAccountList = statementOfAccountService.list(q -> q
+                .eq(StatementOfAccount::getType, 2)
+                .between(BasePo::getCreateTime, DateUtil.beginOfDay(date), DateUtil.endOfDay(date))
+        );
+        Map<Long, StatementOfAccount> statementOfAccountMap = statementOfAccountList.stream()
+                .collect(Collectors.toMap(StatementOfAccount::getDepartmentId, Function.identity()));
+
+        Map<String, String> codeMap = new HashMap<>(1);
+
+        Map<Long, List<OrderInfo>> orderByDepartmentIdMap = orderList.stream().collect(Collectors.groupingBy(OrderInfo::getDepartmentId));
+
+        orderByDepartmentIdMap.forEach((departmentId, order) -> {
+            StatementOfAccount statementOfAccount = statementOfAccountMap.computeIfAbsent(departmentId, item -> {
+                String code = codeMap.get("code");
+                if (code == null) {
+                    codeMap.put("code", CodeEnum.STATEMENT_OF_ACCOUNT_CODE.getCode());
+                } else {
+                    int number = Convert.toInt(code.substring(code.length() - 6));
+                    codeMap.put("code", code.substring(0, code.length() - 6) + String.format("%06d", number + 1));
+                }
+
+                StatementOfAccount tempStatementOfAccount = new StatementOfAccount();
+                tempStatementOfAccount.setCode(codeMap.get("code"));
+                tempStatementOfAccount.setDepartmentId(departmentId);
+                tempStatementOfAccount.setTimePeriodBegin(DateUtil.beginOfDay(date));
+                tempStatementOfAccount.setTimePeriodEnd(DateUtil.endOfDay(date));
+                tempStatementOfAccount.setType(2);
+                return tempStatementOfAccount;
+            });
+
+            String orderIdJoin = order.stream()
+                    .map(BaseIdPo::getId)
+                    .distinct()
+                    .map(Convert::toStr)
+                    .collect(Collectors.joining(","));
+            statementOfAccount.setOrderIdJoin(orderIdJoin);
+
+            BigDecimal amount = order.stream()
+                    .map(OrderInfo::getTotalAmount)
+                    .reduce(BigDecimal.ZERO, BigDecimal::add);
+            statementOfAccount.setAmount(amount);
+
+        });
+
+        if (editOrderList.size() > 0) {
+            orderService.updateBatchById(editOrderList);
+        }
 
+        List<StatementOfAccount> editStatementOfAccountList = new ArrayList<>(statementOfAccountMap.values());
+        if (editStatementOfAccountList.size() > 0) {
+            statementOfAccountService.saveOrUpdateBatch(editStatementOfAccountList);
+        }
 
     }