From 5937598bb5ff67de64bcdda560e9bef4e54f4541 Mon Sep 17 00:00:00 2001
From: yiwenpeng <ywp303@163.com>
Date: Thu, 22 Aug 2024 00:02:45 +0800
Subject: [PATCH] feat:出库组盘限制增加二期5号巷道大小托盘逻辑,排除执行中的任务后,可用的(大托盘库位/小托盘库位)空闲库位数,小于指定的值就不允许继续组盘,避免分拣任务无法回库

---
 src/main/java/com/huaheng/common/constant/QuantityConstant.java                                               |  2 ++
 src/main/java/com/huaheng/pc/shipment/shipmentContainerHeader/service/ShipmentContainerHeaderServiceImpl.java | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
 2 files changed, 84 insertions(+), 3 deletions(-)

diff --git a/src/main/java/com/huaheng/common/constant/QuantityConstant.java b/src/main/java/com/huaheng/common/constant/QuantityConstant.java
index ff7b2a3..38f6d76 100644
--- a/src/main/java/com/huaheng/common/constant/QuantityConstant.java
+++ b/src/main/java/com/huaheng/common/constant/QuantityConstant.java
@@ -490,6 +490,8 @@ public class QuantityConstant {
     public static final String DOUBLE_FORK_RESERVE_LOCATION = "doubleForkReserveLocation";
     public static final String DYNAMIC_DOUBLE_FORK_RESERVE_LOCATION = "dynamicDoubleForkReserveLocation";
 
+    //组盘限制预留库位数
+    public static final String LIMIT_COMBINATION_COUNT = "limitCombinationCount";
 
     // 自动出库状态
     public static final String AUTO_SHIPMENT_STATUS = "autoShipmentStatus";
diff --git a/src/main/java/com/huaheng/pc/shipment/shipmentContainerHeader/service/ShipmentContainerHeaderServiceImpl.java b/src/main/java/com/huaheng/pc/shipment/shipmentContainerHeader/service/ShipmentContainerHeaderServiceImpl.java
index 1d1ed2a..d73e149 100644
--- a/src/main/java/com/huaheng/pc/shipment/shipmentContainerHeader/service/ShipmentContainerHeaderServiceImpl.java
+++ b/src/main/java/com/huaheng/pc/shipment/shipmentContainerHeader/service/ShipmentContainerHeaderServiceImpl.java
@@ -673,6 +673,19 @@ public class ShipmentContainerHeaderServiceImpl extends ServiceImpl<ShipmentCont
         Location location = locationService.getLocationByCode(inventory.getLocationCode());
         // 获取巷道信息
         String roadway = location.getRoadway();
+        if (roadway.equals("9") || roadway.equals("10")) {//9、10号巷道是单伸位
+            return AjaxResult.success();
+        }
+        int count = Integer.parseInt(configService.getKey(LIMIT_COMBINATION_COUNT));
+
+        //5号巷道
+        if (roadway.equals(DYNAMIC_ROADWAY)) {
+            AjaxResult ajaxResult = fiveStacker(location, count, inventory.getContainerCode());
+            if (ajaxResult.hasErr()) {
+                AjaxResult.error(ajaxResult.getMsg());
+            }
+        }
+
 
         LambdaQueryWrapper<Location> wrapper = Wrappers.lambdaQuery();
         wrapper.eq(Location::getRoadway, roadway)
@@ -683,7 +696,7 @@ public class ShipmentContainerHeaderServiceImpl extends ServiceImpl<ShipmentCont
                 .eq(Location::getOnlyEmptyContainer, NO_EMPTY_CONTAINER_LOCATION);
         List<Location> locationList = locationService.list(wrapper);
 
-        if (locationList.size() < 3) {
+        if (locationList.size() <= count) {
             return AjaxResult.error("该库存出库可能无法回库了");
         }
 
@@ -693,8 +706,8 @@ public class ShipmentContainerHeaderServiceImpl extends ServiceImpl<ShipmentCont
             if (taskHeaderService.getUncompleteTaskInNear(location1) == 0) {
                 availableLocations.add(location1);
             }
-            // 如果已经找到了 3 个可用库位,则直接返回成功
-            if (availableLocations.size() >= 3) {
+            // 如果已经找到了 2 个可用库位,则直接返回成功
+            if (availableLocations.size() >= count) {
                 return AjaxResult.success();
             }
         }
@@ -722,6 +735,72 @@ public class ShipmentContainerHeaderServiceImpl extends ServiceImpl<ShipmentCont
         //}
     }
 
+    private AjaxResult fiveStacker(Location location, int count, String containerCode) {
+        LambdaQueryWrapper<Location> wrapper = Wrappers.lambdaQuery();
+        wrapper
+                .eq(Location::getRoadway, DYNAMIC_ROADWAY)
+                .eq(Location::getStatus, STATUS_LOCATION_EMPTY)
+                .eq(Location::getHigh, location.getHigh())
+                .eq(Location::getContainerCode, EMPTY_STRING)
+                .ne(Location::getIColumn, "26");
+        List<Location> list = locationService.list(wrapper);
+        String containerType = countContainerType(containerCode);
+        //大托盘
+        if (containerType.equals(BIG_CONTAINER_TYPE)) {
+            List<Location> bigContainerLocations = countBigContainer(list);
+            if (bigContainerLocations.size() <= count) {
+                return AjaxResult.error("大托盘库位不够了");
+            }
+            //小托盘
+        } else {
+            List<Location> smallContainerLocations = list.stream().filter(smallLocation -> smallLocation.getIColumn() != 25
+                    && !String.valueOf(smallLocation.getTemporaryType()).startsWith(BIG_CONTAINER_TYPE)).collect(Collectors.toList());
+            if (smallContainerLocations.size() <= count) {
+                return AjaxResult.error("小托盘库位不够了");
+            }
+
+            List<Location> availableLocations = new ArrayList<>();
+            for (Location location1 : smallContainerLocations) {
+                // 如果库位内侧没有未完成的任务,则将其添加到可用库位列表中
+                if (taskHeaderService.getUncompleteTaskInNear(location1) == 0) {
+                    availableLocations.add(location1);
+                }
+                // 如果已经找到了 2 个可用库位,则直接返回成功
+                if (availableLocations.size() >= count) {
+                    return AjaxResult.success();
+                }
+            }
+            return AjaxResult.error("小托盘库位不够了");
+        }
+        return AjaxResult.success("");
+    }
+
+    private List<Location> countBigContainer(List<Location> list) {
+        List<Location> bigContainerLocations = new ArrayList<>();
+
+        //大托盘占两个库位,只放奇数列,且右侧有空库位,且当前库位类型不是小托盘
+        List<Location> filteredLocations = list.stream().filter(location -> location.getIColumn() % 2 != 0 && !location.getTemporaryType()
+                .startsWith(SMALL_CONTAINER_TYPE)).collect(Collectors.toList());
+
+        for (Location filteredLocation : filteredLocations) {
+            Location rightLocation = locationService.getRightEmptyLocation(filteredLocation);
+            if (rightLocation != null) {
+                bigContainerLocations.add(filteredLocation);
+            }
+        }
+        return bigContainerLocations;
+    }
+
+    private String countContainerType(String containerCode) {
+        Container container = containerService.getOne(new LambdaQueryWrapper<Container>().eq(Container::getCode, containerCode));
+        String containerType = container.getContainerType();
+        if (containerType.equals(CONTAINER_TYPE_X) || containerType.equals(CONTAINER_TYPE_W)) {
+            return BIG_CONTAINER_TYPE;
+        } else {
+            return SMALL_CONTAINER_TYPE;
+        }
+    }
+
     /**
      * 检查是否可以进行取消配盘
      *
--
libgit2 0.22.2