From 1b7eb0d86d61af13789d3615524e4c46e2c191ae Mon Sep 17 00:00:00 2001
From: yiwenpeng <ywp303@163.com>
Date: Thu, 28 Sep 2023 11:14:29 +0800
Subject: [PATCH] fix: 优化库位分配

---
 src/main/java/com/huaheng/api/wcs/service/warecellAllocation/LocationAllocationServiceImpl.java | 17 +++++++++--------
 src/main/java/com/huaheng/api/wcs/service/warecellAllocation/WarecellAllocationServiceImpl.java | 14 +++++++-------
 2 files changed, 16 insertions(+), 15 deletions(-)

diff --git a/src/main/java/com/huaheng/api/wcs/service/warecellAllocation/LocationAllocationServiceImpl.java b/src/main/java/com/huaheng/api/wcs/service/warecellAllocation/LocationAllocationServiceImpl.java
index a3fd19a..e39562a 100644
--- a/src/main/java/com/huaheng/api/wcs/service/warecellAllocation/LocationAllocationServiceImpl.java
+++ b/src/main/java/com/huaheng/api/wcs/service/warecellAllocation/LocationAllocationServiceImpl.java
@@ -99,17 +99,16 @@ public class LocationAllocationServiceImpl implements LocationAllocationService 
      * 双伸位库位入库分配库位
      */
     private String doubleRk(String area, List<String> roadWays, int high, String warehouseCode, List<String> locationTypeCodeList, String materialAreaCode, Integer frequencyLocation, Integer onlyEmptyContainer) {
-        //巷道为空的话
+        // 如果巷道为空,获取所有巷道
         if (roadWays == null || roadWays.isEmpty()) {
             List<Location> locationList = locationService.list(new LambdaQueryWrapper<Location>().eq(Location::getArea, area));
             roadWays = locationList.stream().map(Location::getRoadway).distinct().collect(toList());
         }
-        //双伸位预留库位数
+        // 获取双伸位预留库位数
         String value = configService.getKey(QuantityConstant.DOUBLE_FORK_RESERVE_LOCATION);
-        int reserveNumber = 0;
-        if (StringUtils.isNotEmpty(value)) {
-            reserveNumber = Integer.parseInt(value);
-        }
+        int reserveNumber = StringUtils.isNotEmpty(value) ? Integer.parseInt(value) : 0;
+
+        // 移除不符合条件的巷道
         List<String> removeRoadWays = new ArrayList<>();
         for (String roadWay : roadWays) {
             LambdaQueryWrapper<Location> wrapper = Wrappers.lambdaQuery();
@@ -139,11 +138,12 @@ public class LocationAllocationServiceImpl implements LocationAllocationService 
         }
         roadWays.removeAll(removeRoadWays);
         Collections.shuffle(roadWays);
+        // 如果没有符合条件的巷道,返回提示信息
         if (roadWays.isEmpty()) {
             return "可能是双伸位巷道保留库位数不够了";
         }
 
-        //查外侧的库位
+        // 查找外侧的库位
         String roadWay = roadWays.get(0);
         LambdaQueryWrapper<Location> locationLambda = Wrappers.lambdaQuery();
         locationLambda.eq(Location::getArea, area).
@@ -188,7 +188,7 @@ public class LocationAllocationServiceImpl implements LocationAllocationService 
         if (locationList != null) {
             locationList.removeAll(removeLocaationList);
         }
-        //如果没有外侧库位可分配了,再查内侧的库位
+        // 如果没有外侧库位可分配了,再查内侧的库位
         if (locationList == null || locationList.isEmpty()) {
             locationLambda = Wrappers.lambdaQuery();
             locationLambda.eq(Location::getArea, area).
@@ -233,6 +233,7 @@ public class LocationAllocationServiceImpl implements LocationAllocationService 
                 locationList.removeAll(removeLocaationList);
             }
         }
+        // 如果没有符合条件的库位可分配,返回null
         if (locationList == null || locationList.isEmpty()) {
             return null;
         }
diff --git a/src/main/java/com/huaheng/api/wcs/service/warecellAllocation/WarecellAllocationServiceImpl.java b/src/main/java/com/huaheng/api/wcs/service/warecellAllocation/WarecellAllocationServiceImpl.java
index 0edba7d..c8b98ec 100644
--- a/src/main/java/com/huaheng/api/wcs/service/warecellAllocation/WarecellAllocationServiceImpl.java
+++ b/src/main/java/com/huaheng/api/wcs/service/warecellAllocation/WarecellAllocationServiceImpl.java
@@ -130,7 +130,7 @@ public class WarecellAllocationServiceImpl implements WarecellAllocationService 
             return AjaxResult.error("宽为空");
         }
         if (StringUtils.isNull(warecellDomain.getHeight()) || "0".equals(warecellDomain.getHeight())) {
-            return AjaxResult.error("高为空");
+            return AjaxResult.error("高为空或0");
         }
         return warecellAllocationService.verticalWarehouseAllocation(warecellDomain);
     }
@@ -140,7 +140,7 @@ public class WarecellAllocationServiceImpl implements WarecellAllocationService 
     public AjaxResult<?> verticalWarehouseAllocation(WarecellDomain warecellDomain) {
         String warehouseCode = warecellDomain.getWarehouseCode();
         String area = warecellDomain.getArea();
-        String locationCode = null;
+        String locationCode;
         String height = warecellDomain.getHeight();
         String taskNo = warecellDomain.getTaskNo();
         List<String> roadWays = warecellDomain.getRoadWays();
@@ -474,10 +474,10 @@ public class WarecellAllocationServiceImpl implements WarecellAllocationService 
         if (locationTypeList.isEmpty()) {
             return AjaxResult.error("没有区域可分配");
         }
-        List<String> codeList = new ArrayList<>();
-        for (LocationType locationType : locationTypeList) {
-            codeList.add(locationType.getCode());
-        }
+        //List<String> codeList = new ArrayList<>();
+        //for (LocationType locationType : locationTypeList) {
+        //    codeList.add(locationType.getCode());
+        //}
 
         //定位库位List
         List<String> positioningLocationCodeList = null;
@@ -507,7 +507,7 @@ public class WarecellAllocationServiceImpl implements WarecellAllocationService 
             LambdaQueryWrapper<Location> locationLambda = Wrappers.lambdaQuery();
             locationLambda.last(locatingRules[0]);
             List<Location> locationList = locationService.list(locationLambda);
-            List<String> locationCodeList = locationTypeList.stream().map(t -> t.getCode()).collect(Collectors.toList());
+            List<String> locationCodeList = locationTypeList.stream().map(LocationType::getCode).collect(Collectors.toList());
             List<Location> newLocation = locationList.stream().filter(t -> locationCodeList.contains(t.getLocationType())).collect(Collectors.toList());
             if (!newLocation.isEmpty()) {
                 positioningLocationCodeList.add(newLocation.get(0).getCode());
--
libgit2 0.22.2