24282 1 سال پیش
والد
کامیت
1e916574ff

+ 5 - 0
sd-business/src/main/java/com/sd/business/service/inventory/InventoryFinishedOrderService.java

@@ -59,4 +59,9 @@ public interface InventoryFinishedOrderService extends BaseService<InventoryFini
      */
     void excelErpExport(List<InventoryFinishedErpImportDataDto> list);
 
+    /**
+     * 产品库订单出库
+     */
+    void saleOutOfWarehouse(List<InventoryFinishedOrder> list);
+
 }

+ 5 - 0
sd-business/src/main/java/com/sd/business/service/inventory/InventoryFinishedService.java

@@ -55,4 +55,9 @@ public interface InventoryFinishedService extends BaseService<InventoryFinished>
      */
     void inOut(List<InventoryFinished> list, boolean isIn);
 
+    /**
+     * 销售出库
+     */
+    void saleOutOfWarehouse(List<Long> orderIdList);
+
 }

+ 23 - 0
sd-business/src/main/java/com/sd/business/service/inventory/impl/InventoryFinishedOrderServiceImpl.java

@@ -295,4 +295,27 @@ public class InventoryFinishedOrderServiceImpl extends ServiceImpl<InventoryFini
         TemplateExcelUtil.writeBrowserMultiSheet("inOutStorageDetails.xlsx", 2, fileName, response, inOutStorageErpExportVoList, inOutStorageBomErpExportVoList);
     }
 
+    @Override
+    public void saleOutOfWarehouse(List<InventoryFinishedOrder> list) {
+
+        List<Long> orderIdList = list.stream()
+                .map(InventoryFinishedOrder::getOrderInfoId)
+                .distinct()
+                .collect(Collectors.toList());
+
+        Map<Long, OrderInfo> orderMap = orderInfoService.mapKEntity(BaseIdPo::getId, q -> q.in(BaseIdPo::getId, orderIdList));
+
+        for (InventoryFinishedOrder item : list) {
+            item.setStatus(StatusConstant.NO);
+            item.setExistingQuantity(BigDecimal.ZERO);
+            OrderInfo orderInfo = orderMap.get(item.getOrderInfoId());
+            item.setDepartmentId(orderInfo.getDepartmentId());
+        }
+
+        updateBatchById(list);
+
+        // 添加流水记录
+        inventoryFinishedOrderDetailService.add(list, FinishedOperationTypeEnum.SALE_OUT_OF_WAREHOUSE);
+    }
+
 }

+ 42 - 0
sd-business/src/main/java/com/sd/business/service/inventory/impl/InventoryFinishedServiceImpl.java

@@ -2,9 +2,11 @@ package com.sd.business.service.inventory.impl;
 
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.common.constant.StatusConstant;
 import com.sd.business.entity.inventory.dto.InventoryFinishedDto;
 import com.sd.business.entity.inventory.dto.InventoryFinishedSelectDto;
 import com.sd.business.entity.inventory.po.InventoryFinished;
+import com.sd.business.entity.inventory.po.InventoryFinishedOrder;
 import com.sd.business.entity.inventory.vo.InventoryFinishedVo;
 import com.sd.business.entity.order.po.OrderSku;
 import com.sd.business.mapper.inventory.InventoryFinishedMapper;
@@ -152,4 +154,44 @@ public class InventoryFinishedServiceImpl extends ServiceImpl<InventoryFinishedM
 
     }
 
+    @Override
+    public void saleOutOfWarehouse(List<Long> orderIdList) {
+        if (orderIdList.isEmpty()) {
+            return;
+        }
+
+        // 查询成品仓库
+        List<InventoryFinishedOrder> list = inventoryFinishedOrderService.list(q -> q
+                .in(InventoryFinishedOrder::getOrderInfoId, orderIdList)
+                .eq(InventoryFinishedOrder::getStatus, StatusConstant.YES));
+
+        if (list.isEmpty()) {
+            return;
+        }
+
+        // 成品库存出库
+        outByFinishedOrder(list);
+
+        // 产品库订单出库
+        inventoryFinishedOrderService.saleOutOfWarehouse(list);
+    }
+
+    /**
+     * 成品库存出库
+     *
+     * @param list 成品仓库
+     */
+    private void outByFinishedOrder(List<InventoryFinishedOrder> list) {
+
+        List<InventoryFinished> inventoryFinishedList = list.stream().map(item -> {
+            InventoryFinished inventoryFinished = new InventoryFinished();
+            inventoryFinished.setQuantity(item.getQuantity());
+            inventoryFinished.setSkuSpecId(item.getSkuSpecId());
+            return inventoryFinished;
+        }).collect(Collectors.toList());
+
+        inOut(inventoryFinishedList, false);
+
+    }
+
 }

+ 5 - 0
sd-wln/src/main/java/com/sd/wln/scheduled/WlnSyncTask.java

@@ -3,6 +3,7 @@ package com.sd.wln.scheduled;
 import com.sd.wln.service.WlnOrderService;
 import com.sd.wln.service.WlnOutboundOrderService;
 import com.sd.wln.service.WlnSkuService;
+import com.sd.wln.service.WlnStatementOfAccount;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Profile;
 import org.springframework.scheduling.annotation.Scheduled;
@@ -24,6 +25,9 @@ public class WlnSyncTask {
     @Autowired
     private WlnOutboundOrderService wlnOutboundOrderService;
 
+    @Autowired
+    private WlnStatementOfAccount wlnStatementOfAccount;
+
     /**
      * 同步sku信息
      */
@@ -46,6 +50,7 @@ public class WlnSyncTask {
     @Scheduled(cron = "0 0 19-23 * * ?")
     private void createStatementOfAccount() {
         wlnOutboundOrderService.syncOutboundOrder();
+        wlnStatementOfAccount.createStatementOfAccount();
     }
 
 }

+ 10 - 0
sd-wln/src/main/java/com/sd/wln/service/WlnStatementOfAccount.java

@@ -0,0 +1,10 @@
+package com.sd.wln.service;
+
+public interface WlnStatementOfAccount {
+
+    /**
+     * 生成对账单
+     */
+    void createStatementOfAccount();
+
+}

+ 146 - 0
sd-wln/src/main/java/com/sd/wln/service/impl/WlnStatementOfAccountImpl.java

@@ -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);
+
+    }
+
+}