From 7df5cbaf14469067ffc23732ac4d7c16936d2529 Mon Sep 17 00:00:00 2001
From: yiwenpeng <ywp303@163.com>
Date: Mon, 15 Jan 2024 11:58:02 +0800
Subject: [PATCH] feat: 更新出库组盘逻辑:①通知单号匹配               ②主体颜色加喷漆状态、喷漆状态、主体颜色、底漆(状态)、无颜色               ③先进先出

---
 src/main/java/com/huaheng/pc/receipt/receiptContainerHeader/service/ReceiptContainerHeaderServiceImpl.java |   6 +-----
 src/main/java/com/huaheng/pc/shipment/shipmentHeader/domain/ShipmentHeader.java                            |  10 +++++-----
 src/main/java/com/huaheng/pc/shipment/shippingCombination/controller/ShippingCombinationController.java    |  20 ++++++++++++--------
 src/main/java/com/huaheng/pc/shipment/shippingCombination/service/ShippingCombinationService.java          | 128 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------------------------------------------
 4 files changed, 84 insertions(+), 80 deletions(-)

diff --git a/src/main/java/com/huaheng/pc/receipt/receiptContainerHeader/service/ReceiptContainerHeaderServiceImpl.java b/src/main/java/com/huaheng/pc/receipt/receiptContainerHeader/service/ReceiptContainerHeaderServiceImpl.java
index 7209962..d5e3b4d 100644
--- a/src/main/java/com/huaheng/pc/receipt/receiptContainerHeader/service/ReceiptContainerHeaderServiceImpl.java
+++ b/src/main/java/com/huaheng/pc/receipt/receiptContainerHeader/service/ReceiptContainerHeaderServiceImpl.java
@@ -936,11 +936,7 @@ public class ReceiptContainerHeaderServiceImpl extends ServiceImpl<ReceiptContai
 
     @Override
     public List<ReceiptContainerHeader> getUnCompleteCombineList() {
-        LambdaQueryWrapper<ReceiptContainerHeader> receiptContainerHeaderLambdaQueryWrapper = Wrappers.lambdaQuery();
-        receiptContainerHeaderLambdaQueryWrapper
-                .lt(ReceiptContainerHeader::getStatus, QuantityConstant.RECEIPT_CONTAINER_FINISHED);
-        List<ReceiptContainerHeader> receiptContainerHeaderList = list(receiptContainerHeaderLambdaQueryWrapper);
-        return receiptContainerHeaderList;
+        return list(new LambdaQueryWrapper<ReceiptContainerHeader>().lt(ReceiptContainerHeader::getStatus, QuantityConstant.RECEIPT_CONTAINER_FINISHED));
     }
 
 
diff --git a/src/main/java/com/huaheng/pc/shipment/shipmentHeader/domain/ShipmentHeader.java b/src/main/java/com/huaheng/pc/shipment/shipmentHeader/domain/ShipmentHeader.java
index 5dcc520..b154521 100644
--- a/src/main/java/com/huaheng/pc/shipment/shipmentHeader/domain/ShipmentHeader.java
+++ b/src/main/java/com/huaheng/pc/shipment/shipmentHeader/domain/ShipmentHeader.java
@@ -509,6 +509,11 @@ public class ShipmentHeader implements Serializable {
     @TableField(value = "materialColor")
     @ApiModelProperty(value = "物料颜色")
     public String materialColor;
+    /**
+     * 喷漆状态
+     */
+    @TableField(value = "paintStatus")
+    public String paintStatus;
 
     /**
      * 任务完成时间
@@ -536,9 +541,4 @@ public class ShipmentHeader implements Serializable {
     @ApiModelProperty(value = "物料编码")
     private String materialCode;
 
-    /**
-     * 喷漆状态
-     */
-    @TableField(value = "paintStatus")
-    public String paintStatus;
 }
diff --git a/src/main/java/com/huaheng/pc/shipment/shippingCombination/controller/ShippingCombinationController.java b/src/main/java/com/huaheng/pc/shipment/shippingCombination/controller/ShippingCombinationController.java
index 77e34d9..c88f1b1 100644
--- a/src/main/java/com/huaheng/pc/shipment/shippingCombination/controller/ShippingCombinationController.java
+++ b/src/main/java/com/huaheng/pc/shipment/shippingCombination/controller/ShippingCombinationController.java
@@ -160,19 +160,23 @@ public class ShippingCombinationController extends BaseController {
         if (list.isEmpty()) {
             // 处理库存为0的明细
             //handleDetail(shipmentHeader, shipmentDetail);
-            throw new ServiceException("该物料没有库存可能是原仓库不同");
+            throw new ServiceException("该物料WMS系统没有库存,无法出库,或者是原仓库不同");
         }
         List<InventoryDetail> removeList = new ArrayList<>();
         for (InventoryDetail item : list) {
             item.setQty(item.getQty().subtract(item.getTaskQty()));
             String containerCode = item.getContainerCode();
-            Container container = containerService.getContainerByCode(containerCode);
+            //Container container = containerService.getContainerByCode(containerCode);
             //平库不统计有任务的托盘
-            if (container.getFlat() == null || container.getFlat() != 1) {
-                Integer number = taskHeaderService.UncompleteCount(containerCode);
-                if (number >= 1) {
-                    removeList.add(item);
-                }
+            //if (container.getFlat() == null || container.getFlat() != 1) {
+            //    Integer number = taskHeaderService.UncompleteCount(containerCode);
+            //    if (number >= 1) {
+            //        removeList.add(item);
+            //    }
+            //}
+            Integer number = taskHeaderService.UncompleteCount(containerCode);
+            if (number >= 1) {
+                removeList.add(item);
             }
         }
         List<ReceiptContainerHeader> unCompleteCombineList = receiptContainerHeaderService.getUnCompleteCombineList();
@@ -190,7 +194,7 @@ public class ShippingCombinationController extends BaseController {
             }
         }
         StringBuilder builder = new StringBuilder();
-        builder.append("库存不足,剩余库存 ");
+        builder.append("库存不足,剩余库存");
         list.removeAll(removeList);
         for (InventoryDetail inventoryDetail : removeList) {
             builder.append(inventoryDetail.getContainerCode() + "-");
diff --git a/src/main/java/com/huaheng/pc/shipment/shippingCombination/service/ShippingCombinationService.java b/src/main/java/com/huaheng/pc/shipment/shippingCombination/service/ShippingCombinationService.java
index 128979f..6056a97 100644
--- a/src/main/java/com/huaheng/pc/shipment/shippingCombination/service/ShippingCombinationService.java
+++ b/src/main/java/com/huaheng/pc/shipment/shippingCombination/service/ShippingCombinationService.java
@@ -26,8 +26,10 @@ import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
 import java.util.ArrayList;
+import java.util.Comparator;
 import java.util.List;
 import java.util.Optional;
+import java.util.stream.Collectors;
 
 
 @Service
@@ -53,84 +55,86 @@ public class ShippingCombinationService {
 
     //根据分配规则查找库存
     public List<InventoryDetail> getInventorys(ShipmentDetail shipmentDetail, boolean isAuto, boolean isFlatWarehouse) {
-        String warehouseCode = shipmentDetail.getWarehouseCode();
-        String companyCode = shipmentDetail.getCompanyCode();
         String materialCode = shipmentDetail.getMaterialCode();
-        String inventorySts = shipmentDetail.getInventorySts();
         String noticeNo = shipmentDetail.getNoticeNo();
-        String batch = shipmentDetail.getBatch();
+        //noticeNo = Optional.ofNullable(noticeNo).orElse("");
         String containerCode = shipmentDetail.getContainerCode();
         String receiptCode = shipmentDetail.getReceiptCode();
-        checkNotEmpty(warehouseCode, "出库详情没有仓库编码");
-        checkNotEmpty(companyCode, "出库详情没有货主编码");
-        checkNotEmpty(materialCode, "出库详情没有物料编码");
-        checkNotEmpty(inventorySts, "出库详情没有物料品质");
-        Material material = getMaterialByCode(materialCode);
-        String policy = Optional.ofNullable(material.getPolicy()).orElse("");
-        noticeNo = Optional.ofNullable(noticeNo).orElse("");
-
-        String isBatchMaterial = Optional.ofNullable(material.getIsBatch()).orElse("");
+        checkNotEmpty(materialCode, "出库明细没有物料编码");
+        //Material material = getMaterialByCode(materialCode);
+        //String policy = Optional.ofNullable(material.getPolicy()).orElse("");
+        //String isBatchMaterial = Optional.ofNullable(material.getIsBatch()).orElse("");
         ShipmentHeader shipmentHeader = shipmentHeaderService.getById(shipmentDetail.getShipmentId());
         String warehouse = shipmentHeader.getWarehouse();
+        String color = shipmentHeader.getMaterialColor();
+        String paintStatus = shipmentHeader.getPaintStatus();
 
         LambdaQueryWrapper<InventoryDetail> wrapper = Wrappers.lambdaQuery();
-        wrapper.eq(InventoryDetail::getWarehouseCode, warehouseCode)
-                .eq(InventoryDetail::getCompanyCode, companyCode)
-                .eq(InventoryDetail::getMaterialCode, materialCode)
-                .eq(InventoryDetail::getInventorySts, inventorySts)
-                .eq(StringUtils.isNotEmpty(receiptCode), InventoryDetail::getReceiptCode, receiptCode)
-                .eq(StringUtils.isNotEmpty(warehouse), InventoryDetail::getWarehouse, warehouse)
-                .eq(StringUtils.isNotEmpty(containerCode), InventoryDetail::getContainerCode, containerCode);
-
-        if (isAuto && StringUtils.isNotEmpty(noticeNo)) {
-            wrapper.eq(InventoryDetail::getNoticeCode, noticeNo);
-        }
-        if (isFlatWarehouse) {
-            wrapper.ne(InventoryDetail::getZoneCode, "L");
+        wrapper.eq(InventoryDetail::getMaterialCode, materialCode)
+                .eq(StringUtils.isNotEmpty(warehouse), InventoryDetail::getWarehouse, warehouse)//原仓库
+                .eq(StringUtils.isNotEmpty(containerCode), InventoryDetail::getContainerCode, containerCode) //托盘号
+                .eq(StringUtils.isNotEmpty(receiptCode), InventoryDetail::getReceiptCode, receiptCode)//入库单号
+                .eq(StringUtils.isNotEmpty(noticeNo), InventoryDetail::getNoticeCode, noticeNo)//通知单号
+                .ne(isFlatWarehouse, InventoryDetail::getZoneCode, "L");//如果用平库组盘功能,只能出平库的库存
+        List<InventoryDetail> list = inventoryDetailService.list(wrapper);
+        if (list.isEmpty()) {
+            return list;
         }
-
+        //排序:主体颜色加喷漆状态、喷漆状态、主体颜色、喷漆状态(底漆)、无颜色、先进先出
+
+        return list.stream()
+                .sorted(Comparator.comparing((InventoryDetail detail) -> {
+                    if (StringUtils.isNotEmpty(color) && StringUtils.isNotEmpty(paintStatus) && color.equals(detail.getMaterialColor()) && paintStatus.equals(detail.getPaintStatus())) {
+                        return 1;
+                    } else if (StringUtils.isNotEmpty(paintStatus) && paintStatus.equals(detail.getPaintStatus())) {
+                        return 2;
+                    } else if (StringUtils.isNotEmpty(color) && color.equals(detail.getMaterialColor())) {
+                        return 3;
+                    } else if ("底漆".equals(detail.getPaintStatus())) {
+                        return 4;
+                    } else if (StringUtils.isEmpty(detail.getPaintStatus())) {
+                        return 5;
+                    } else {
+                        return 6;
+                    }
+                }))
+                .collect(Collectors.toList());
         //批次管控的物料,出库时优先按,生产日期,先进先出
-        if (StringUtils.isNotEmpty(isBatchMaterial) && isBatchMaterial.equals("是")) {
-            //是批次批次管控的物料走这里
-            wrapper.orderByAsc(InventoryDetail::getProductionDate);
-        }
-        wrapper.orderByDesc(InventoryDetail::getQty);
-        wrapper.orderByAsc(InventoryDetail::getCreated);
-        List<InventoryDetail> list = inventoryDetailService.list(wrapper);
+        //if (StringUtils.isNotEmpty(isBatchMaterial) && isBatchMaterial.equals("是")) {
+        //    //是批次批次管控的物料走这里
+        //    wrapper.orderByAsc(InventoryDetail::getProductionDate);
+        //}
 
-        //优先匹配通知单号,没有数据就去掉通知单号再匹配
-        if (list.isEmpty() && isAuto) {
-            //如果物料的供需政策为LP的,或者通知单号包含展会字样的,必须匹配通知单号才可以出库,所以下面的代码不能走了,直接返回空集合
-            if (policy.equals("PL") || noticeNo.contains("展会")) {
-                return list;
-            }
-            return getInventoryWithoutNotice(companyCode, materialCode, inventorySts, receiptCode, containerCode, batch, isFlatWarehouse, isBatchMaterial);
-        }
-        return list;
-    }
 
+        ////优先匹配通知单号,没有数据就去掉通知单号再匹配
+        //if (list.isEmpty() && isAuto) {
+        //    //如果物料的供需政策为LP的,或者通知单号包含展会字样的,必须匹配通知单号才可以出库,所以下面的代码不能走了,直接返回空集合
+        //    if (policy.equals("PL") || noticeNo.contains("展会")) {
+        //        return list;
+        //    }
+        //    return getInventoryWithoutNotice(materialCode, receiptCode, containerCode, isFlatWarehouse, isBatchMaterial);
+        //}
 
-    // 提取方法,用于构建没有通知单号的查询条件
-    private List<InventoryDetail> getInventoryWithoutNotice(String companyCode, String materialCode, String inventorySts, String receiptCode, String containerCode, String batch, boolean isFlatWarehouse, String isBatchMaterial) {
-        LambdaQueryWrapper<InventoryDetail> wrapper = Wrappers.lambdaQuery();
-        wrapper.eq(InventoryDetail::getMaterialCode, materialCode)
-                .eq(InventoryDetail::getCompanyCode, companyCode)
-                .eq(InventoryDetail::getInventorySts, inventorySts)
-                .eq(StringUtils.isNotEmpty(receiptCode), InventoryDetail::getReceiptCode, receiptCode)
-                .eq(StringUtils.isNotEmpty(containerCode), InventoryDetail::getContainerCode, containerCode)
-                .eq(StringUtils.isNotEmpty(batch), InventoryDetail::getBatch, batch);
-
-        if (isFlatWarehouse) {
-            wrapper.ne(InventoryDetail::getZoneCode, "L");
-        }
-        if (StringUtils.isEmpty(isBatchMaterial) || !isBatchMaterial.equals("是")) {
-            wrapper.orderByDesc(InventoryDetail::getQty);
-        }
-        wrapper.orderByAsc(InventoryDetail::getCreated);
-        return inventoryDetailService.list(wrapper);
     }
 
 
+    // 没有通知单号
+    //private List<InventoryDetail> getInventoryWithoutNotice(String materialCode, String receiptCode, String containerCode, boolean isFlatWarehouse, String isBatchMaterial) {
+    //    LambdaQueryWrapper<InventoryDetail> wrapper = Wrappers.lambdaQuery();
+    //    wrapper.eq(InventoryDetail::getMaterialCode, materialCode)
+    //            .eq(StringUtils.isNotEmpty(receiptCode), InventoryDetail::getReceiptCode, receiptCode)
+    //            .eq(StringUtils.isNotEmpty(containerCode), InventoryDetail::getContainerCode, containerCode);
+    //    if (isFlatWarehouse) {
+    //        wrapper.ne(InventoryDetail::getZoneCode, "L");
+    //    }
+    //    if (StringUtils.isEmpty(isBatchMaterial) || !isBatchMaterial.equals("是")) {
+    //        wrapper.orderByDesc(InventoryDetail::getQty);
+    //    }
+    //    wrapper.orderByAsc(InventoryDetail::getCreated);
+    //    return inventoryDetailService.list(wrapper);
+    //}
+
+
     // 封装判断方法,检查字符串是否为空,如果为空则抛出 ServiceException 异常
     private void checkNotEmpty(String value, String errorMessage) {
         if (StringUtils.isEmpty(value)) {
--
libgit2 0.22.2