From b176072388747abb438990157bfa305b215b4b90 Mon Sep 17 00:00:00 2001
From: zwl <1051256694@qq.com>
Date: 星期二, 14 四月 2026 21:59:39 +0800
Subject: [PATCH] 我们现在讨论一下系统找库位方案, 如何实现,对现有找库位规则进行整改,数据库也要整改 1、要能方便的填写单伸堆垛机或双伸堆垛机的深浅库位配置 2、根据设备状态分配库位,离线设备不分配 3、库位分配要均衡到每一个设备  4、库位高度需要匹配到对应库位信息,低库位能向上兼容  5、空托盘优先放在locType2库位=1的库位,没有这种库位了,允许放到其他库位 6、给入库站点设置有限去那些堆垛机,其次去那些堆垛机,弄成页面可以配置入库站点 7、在系统配置新增优先放前几列的配置,当入库的货物是高频货物时放在前几列 8、组托中会标识该托盘是高频还是低频,如果是高频则从前往后找库位,如果是低频则从后往前找库位 9、找库位时locMast中whsType字段无用

---
 src/main/java/com/zy/asrs/utils/Utils.java |  217 ++++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 169 insertions(+), 48 deletions(-)

diff --git a/src/main/java/com/zy/asrs/utils/Utils.java b/src/main/java/com/zy/asrs/utils/Utils.java
index 91537d3..a95300b 100644
--- a/src/main/java/com/zy/asrs/utils/Utils.java
+++ b/src/main/java/com/zy/asrs/utils/Utils.java
@@ -29,6 +29,7 @@
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 import java.util.Locale;
 
 /**
@@ -131,98 +132,220 @@
     }
 
 
-    public static Integer getStationStorageArea(Integer stationId) {
+    public static List<Integer> getStationStorageAreas(Integer stationId) {
         if (stationId == null || stationId <= 0) {
-            return null;
+            return new ArrayList<>();
         }
         BasDevpService basDevpService = SpringUtils.getBean(BasDevpService.class);
         BasDevp station = basDevpService.selectById(stationId);
         if (station == null) {
+            return new ArrayList<>();
+        }
+        return parseStorageAreas(station.getArea());
+    }
+
+    public static Integer getStationStorageArea(Integer stationId) {
+        List<Integer> storageAreas = getStationStorageAreas(stationId);
+        if (Cools.isEmpty(storageAreas)) {
             return null;
         }
-        return parseStorageArea(station.getArea());
+        return storageAreas.get(0);
     }
 
     /**
      * 鐢熸垚鍏ュ簱鎵惧簱浣嶆椂鐨勫爢鍨涙満浼樺厛椤哄簭銆�
      *
-     * <p>澶勭悊瑙勫垯锛�
-     * 1. 鍏堟牴鎹叆搴撶珯鐐规煡璇㈡墍灞炲簱鍖恒��
-     * 2. 鍏堟彁鍙栬搴撳尯鍐呯殑鍫嗗灈鏈猴紝骞舵寜鍙敤绌哄簱浣嶈繃婊や笉鍙敤鍫嗗灈鏈恒��
-     * 3. 褰� {@code locType1 = 1} 鏃讹紝鍏堣繑鍥炰綆搴撲綅鍫嗗灈鏈猴紝鍐嶆妸鍚屾壒鍫嗗灈鏈虹殑楂樺簱浣嶈拷鍔犲埌鍚庨潰銆�
-     * 4. 瀵逛笉瀛樺湪銆佹晠闅溿�佷笉鍙叆浠ュ強鏃犵┖搴撲綅鐨勫爢鍨涙満鐩存帴鍓旈櫎銆�
-     *
-     * <p>杩欓噷鏄彧璇绘帓搴忓伐鍏凤紝涓嶅啀鍐欏洖 {@code asr_row_lastno.crn_qty}銆�
-     * {@code crn_qty} 鍦ㄤ富鏁版嵁閲岃〃绀衡�滃爢鍨涙満鏁伴噺鈥濓紝涓嶈兘鍐嶈鎷挎潵褰撹疆璇㈡父鏍囷紝鍚﹀垯浼氭妸鏁翠粨閰嶇疆鍐欏潖銆�
+     * <p>褰撳墠璇箟宸茬粡鍒囨崲涓衡�滅珯鐐圭涓�浼樺厛姹� + 绗簩浼樺厛姹犫�濈殑閰嶇疆棰勮锛�
+     * 涓嶅啀娌跨敤鏃х殑 area 椤哄簭銆�
      *
      * <p>杩斿洖缁撴灉涓殑姣忎竴椤规牸寮忎负锛�
-     * {@code {crnNo: 鍫嗗灈鏈哄彿, locType1: 搴撲綅楂樹綆绫诲瀷}}
+     * {@code {pool: 浼樺厛姹犵紪鍙�, seq: 姹犲唴椤哄簭, crnNo: 鍫嗗灈鏈哄彿}}
      *
      * @param stationId 鍏ュ簱绔欑偣
-     * @param locType1  鐩爣搴撲綅楂樹綆绫诲瀷锛�1=浣庡簱浣嶏紝2=楂樺簱浣�
-     * @param matnr     鐗╂枡缂栫爜锛屼紶鍏� {@code emptyPallet} 鏃朵娇鐢ㄧ┖鏉挎帓搴忚鍒�
-     * @return 鎸変紭鍏堢骇鎺掑ソ搴忕殑鍫嗗灈鏈哄垪琛�
+     * @param locType1  淇濈暀鍏煎鍙傛暟锛屽綋鍓嶄笉鍙備笌鎺掑簭
+     * @param matnr     淇濈暀鍏煎鍙傛暟锛屽綋鍓嶄笉鍙備笌鎺掑簭
+     * @return 鎸変紭鍏堟睜椤哄簭鎺掑ソ鐨勫爢鍨涙満鍒楄〃
      */
     public static List<Map<String, Integer>> getStationStorageAreaName(Integer stationId, Integer locType1, String matnr) {
         List<Map<String, Integer>> result = new ArrayList<>();
-        // 鍏堝畾浣嶅叆搴撶珯鐐规墍灞炲簱鍖恒��
-        Integer storageArea = getStationStorageArea(stationId);
-        Integer whsType = GetWhsType(stationId);
-        if (storageArea == null || whsType == null || whsType <= 0) {
+        BasDevpService basDevpService = SpringUtils.getBean(BasDevpService.class);
+        BasDevp station = basDevpService.selectById(stationId);
+        if (station == null) {
             return result;
         }
-        RowLastnoService rowLastnoService = SpringUtils.getBean(RowLastnoService.class);
-        RowLastno rowLastno = rowLastnoService.selectById(whsType);
-        if (rowLastno == null) {
-            return result;
-        }
-
-        BasCrnpService basCrnpService = SpringUtils.getBean(BasCrnpService.class);
-        LocMastService locMastService = SpringUtils.getBean(LocMastService.class);
-        boolean emptyPallet = "emptyPallet".equalsIgnoreCase(matnr);
-
-        // 鍏堝彇褰撳墠搴撳尯瀵瑰簲鐨勫爢鍨涙満銆�
-        List<Integer> preferredCrnNos = getAreaCrnNos(storageArea, rowLastno);
-        List<Integer> preferredAvailableCrnNos = getAvailableCrnNos(preferredCrnNos, locType1, emptyPallet, basCrnpService, locMastService);
-        appendCrnLocTypeEntries(result, preferredAvailableCrnNos, locType1, emptyPallet, locMastService);
-
+        appendCrnPoolEntries(result, 1, distinctCrnNos(station.getInFirstCrnCsv()));
+        appendCrnPoolEntries(result, 2, distinctCrnNos(station.getInSecondCrnCsv()));
         return result;
     }
 
-    private static void appendCrnLocTypeEntries(List<Map<String, Integer>> result, List<Integer> crnNos, Integer locType1, boolean emptyPallet, LocMastService locMastService) {
-        Short normalizedLocType1 = normalizeLocType1(locType1);
-        if (normalizedLocType1 == null) {
-            appendCrnLocTypeEntries(result, crnNos, (short) 1, emptyPallet, locMastService);
-            appendCrnLocTypeEntries(result, crnNos, (short) 2, emptyPallet, locMastService);
+    public static List<Integer> parseCrnNos(String csv) {
+        List<Integer> crnNos = new ArrayList<>();
+        if (Cools.isEmpty(csv)) {
+            return crnNos;
+        }
+        String normalized = csv.replace("锛�", ",")
+                .replace("锛�", ",")
+                .replace("銆�", ",")
+                .replaceAll("\\s+", "");
+        if (normalized.isEmpty()) {
+            return crnNos;
+        }
+        for (String segment : normalized.split("[,;]")) {
+            if (segment == null || segment.isEmpty()) {
+                continue;
+            }
+            Integer crnNo = safeParseInt(segment);
+            if (crnNo == null || crnNo <= 0) {
+                throw new CoolException("鍫嗗灈鏈哄彿鏍煎紡閿欒锛�" + segment);
+            }
+            crnNos.add(crnNo);
+        }
+        return crnNos;
+    }
+
+    public static List<Integer> distinctCrnNos(String csv) {
+        return distinctCrnNos(parseCrnNos(csv));
+    }
+
+    public static List<Integer> distinctCrnNos(List<Integer> crnNos) {
+        List<Integer> result = new ArrayList<>();
+        if (Cools.isEmpty(crnNos)) {
+            return result;
+        }
+        LinkedHashSet<Integer> orderedCrnNos = new LinkedHashSet<>();
+        for (Integer crnNo : crnNos) {
+            if (crnNo == null || crnNo <= 0) {
+                continue;
+            }
+            orderedCrnNos.add(crnNo);
+        }
+        result.addAll(orderedCrnNos);
+        return result;
+    }
+
+    public static String normalizeCrnCsv(String csv) {
+        return normalizeCrnCsv(parseCrnNos(csv));
+    }
+
+    public static String normalizeCrnCsv(List<Integer> crnNos) {
+        return joinCrnNos(distinctCrnNos(crnNos));
+    }
+
+    public static String joinCrnNos(List<Integer> crnNos) {
+        if (Cools.isEmpty(crnNos)) {
+            return "";
+        }
+        StringBuilder builder = new StringBuilder();
+        for (Integer crnNo : crnNos) {
+            if (crnNo == null || crnNo <= 0) {
+                continue;
+            }
+            if (builder.length() > 0) {
+                builder.append(",");
+            }
+            builder.append(crnNo);
+        }
+        return builder.toString();
+    }
+
+    private static void appendCrnPoolEntries(List<Map<String, Integer>> result, int pool, List<Integer> crnNos) {
+        if (result == null || Cools.isEmpty(crnNos)) {
             return;
         }
-        appendCrnLocTypeEntries(result, crnNos, normalizedLocType1, emptyPallet, locMastService);
-        if (normalizedLocType1 == 1) {
-            appendCrnLocTypeEntries(result, crnNos, (short) 2, emptyPallet, locMastService);
+        int seq = 1;
+        for (Integer crnNo : crnNos) {
+            if (crnNo == null || crnNo <= 0) {
+                continue;
+            }
+            Map<String, Integer> item = new LinkedHashMap<>();
+            item.put("pool", pool);
+            item.put("seq", seq++);
+            item.put("crnNo", crnNo);
+            result.add(item);
         }
     }
 
-    private static void appendCrnLocTypeEntries(List<Map<String, Integer>> result, List<Integer> crnNos, Short targetLocType1, boolean emptyPallet, LocMastService locMastService) {
+    public static List<Integer> parseStorageAreas(String area) {
+        List<Integer> areas = new ArrayList<>();
+        if (Cools.isEmpty(area)) {
+            return areas;
+        }
+        LinkedHashSet<Integer> orderedAreas = new LinkedHashSet<>();
+        String normalized = area.replace("锛�", ",")
+                .replace("锛�", ";")
+                .replace("銆�", ",")
+                .replaceAll("\\s+", "");
+        if (normalized.isEmpty()) {
+            return areas;
+        }
+        for (String segment : normalized.split("[,;]")) {
+            if (segment == null || segment.isEmpty()) {
+                continue;
+            }
+            Integer areaNo = parseStorageArea(segment);
+            if (areaNo != null) {
+                orderedAreas.add(areaNo);
+            }
+        }
+        areas.addAll(orderedAreas);
+        return areas;
+    }
+
+    public static String formatStorageArea(Integer area) {
+        if (area == null) {
+            return "";
+        }
+        switch (area) {
+            case 1:
+                return "A搴撳尯";
+            case 2:
+                return "B搴撳尯";
+            case 3:
+                return "C搴撳尯";
+            default:
+                return String.valueOf(area);
+        }
+    }
+
+    private static void appendCrnLocTypeEntries(List<Map<String, Integer>> result, List<Integer> crnNos, Integer locType1,
+                                                boolean emptyPallet, LocMastService locMastService, Integer area) {
+        Short normalizedLocType1 = normalizeLocType1(locType1);
+        if (normalizedLocType1 == null) {
+            appendCrnLocTypeEntries(result, crnNos, (short) 1, emptyPallet, locMastService, area);
+            appendCrnLocTypeEntries(result, crnNos, (short) 2, emptyPallet, locMastService, area);
+            return;
+        }
+        appendCrnLocTypeEntries(result, crnNos, normalizedLocType1, emptyPallet, locMastService, area);
+        if (normalizedLocType1 == 1) {
+            appendCrnLocTypeEntries(result, crnNos, (short) 2, emptyPallet, locMastService, area);
+        }
+    }
+
+    private static void appendCrnLocTypeEntries(List<Map<String, Integer>> result, List<Integer> crnNos, Short targetLocType1,
+                                                boolean emptyPallet, LocMastService locMastService, Integer area) {
         if (targetLocType1 == null || Cools.isEmpty(crnNos)) {
             return;
         }
         for (Integer crnNo : crnNos) {
-            if (!hasAvailableLoc(crnNo, targetLocType1, emptyPallet, locMastService) || containsCrnLocType(result, crnNo, targetLocType1)) {
+            if (!hasAvailableLoc(crnNo, targetLocType1, emptyPallet, locMastService) || containsCrnLocType(result, area, crnNo, targetLocType1)) {
                 continue;
             }
             Map<String, Integer> item = new LinkedHashMap<>();
+            item.put("area", area);
             item.put("crnNo", crnNo);
             item.put("locType1", targetLocType1.intValue());
             result.add(item);
         }
     }
 
-    private static boolean containsCrnLocType(List<Map<String, Integer>> result, Integer crnNo, Short locType1) {
+    private static boolean containsCrnLocType(List<Map<String, Integer>> result, Integer area, Integer crnNo, Short locType1) {
         for (Map<String, Integer> item : result) {
             if (item == null) {
                 continue;
             }
-            if (crnNo.equals(item.get("crnNo")) && locType1.intValue() == item.get("locType1")) {
+            if (crnNo.equals(item.get("crnNo"))
+                    && locType1.intValue() == item.get("locType1")
+                    && Objects.equals(area, item.get("area"))) {
                 return true;
             }
         }
@@ -297,8 +420,6 @@
     private static Short normalizeLocType1(Integer locType1) {
         if (locType1 == null || (locType1 != 1 && locType1 != 2)) {
             return null;
-        } else {
-            locType1 = 2;
         }
         return locType1.shortValue();
     }

--
Gitblit v1.9.1