From f033da325dd16825bbca0d1ac71cc76420dfc8a2 Mon Sep 17 00:00:00 2001
From: Junjie <DELL@qq.com>
Date: 星期五, 09 一月 2026 11:14:36 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/asrs/utils/Utils.java |  241 ++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 230 insertions(+), 11 deletions(-)

diff --git a/src/main/java/com/zy/asrs/utils/Utils.java b/src/main/java/com/zy/asrs/utils/Utils.java
index bb645ef..cb1ee8b 100644
--- a/src/main/java/com/zy/asrs/utils/Utils.java
+++ b/src/main/java/com/zy/asrs/utils/Utils.java
@@ -11,9 +11,11 @@
 import com.core.exception.CoolException;
 import com.zy.asrs.entity.BasCrnp;
 import com.zy.asrs.entity.BasDualCrnp;
+import com.zy.asrs.entity.BasStationDevice;
 import com.zy.asrs.entity.WrkMast;
 import com.zy.asrs.service.BasCrnpService;
 import com.zy.asrs.service.BasDualCrnpService;
+import com.zy.asrs.service.BasStationDeviceService;
 import com.zy.asrs.service.WrkMastService;
 import com.zy.common.model.NavigateNode;
 import com.zy.common.utils.NavigateUtils;
@@ -168,6 +170,18 @@
             NavigateUtils navigateUtils = SpringUtils.getBean(NavigateUtils.class);
             WrkMastService wrkMastService = SpringUtils.getBean(WrkMastService.class);
             BasCrnpService basCrnpService = SpringUtils.getBean(BasCrnpService.class);
+            BasStationDeviceService basStationDeviceService = SpringUtils.getBean(BasStationDeviceService.class);
+
+            List<BasStationDevice> stationDevices = basStationDeviceService.selectList(new EntityWrapper<BasStationDevice>().eq("station_id", stationId));
+            boolean hasConfig = !stationDevices.isEmpty();
+            List<Integer> allowedCrnNos = new ArrayList<>();
+            if (hasConfig) {
+                for (BasStationDevice sd : stationDevices) {
+                    if (SlaveType.Crn.toString().equals(sd.getDeviceType())) {
+                        allowedCrnNos.add(sd.getDeviceNo());
+                    }
+                }
+            }
 
             Integer currentCircleTaskCrnNo = null;
             Object object = redisUtil.get(RedisKeyType.CURRENT_CIRCLE_TASK_CRN_NO.key);
@@ -179,10 +193,20 @@
                     .eq("in_enable", "Y")
                     .eq("status", 1);
 
+            if (hasConfig) {
+                wrapper.in("crn_no", allowedCrnNos);
+            }
+
             if (currentCircleTaskCrnNo != null) {
                 currentCircleTaskCrnNo = currentCircleTaskCrnNo + 1;
-                BasCrnp basCrnp = basCrnpService.selectOne(new EntityWrapper<BasCrnp>().eq("crn_no", currentCircleTaskCrnNo));
-                List<WrkMast> currentCrnTask = wrkMastService.selectList(new EntityWrapper<WrkMast>().eq("crn_no", currentCircleTaskCrnNo));
+                BasCrnp basCrnp = basCrnpService.selectOne(new EntityWrapper<BasCrnp>()
+                        .eq("crn_no", currentCircleTaskCrnNo)
+                        .eq("in_enable", "Y")
+                        .eq("status", 1)
+                );
+                List<WrkMast> currentCrnTask = wrkMastService.selectList(new EntityWrapper<WrkMast>()
+                        .eq("crn_no", currentCircleTaskCrnNo)
+                );
                 if (currentCrnTask.size() <= 1) {
                     if (basCrnp != null) {
                         List<List<Integer>> rowList = basCrnp.getControlRows$();
@@ -198,13 +222,24 @@
             List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<>());
             List<BasCrnp> basCrnps = basCrnpService.selectList(wrapper);
 
+            List<BasCrnp> baseList = new ArrayList<>();
+            List<BasCrnp> extraList = new ArrayList<>();
+            for (BasCrnp basCrnp : basCrnps) {
+                if (excludeCrnList.contains(basCrnp.getCrnNo())) {
+                    extraList.add(basCrnp);
+                }else {
+                    baseList.add(basCrnp);
+                }
+            }
+            baseList.addAll(extraList);
+
             for (WrkMast wrkMast : wrkMasts) {
                 Integer crnNo = wrkMast.getCrnNo();
                 map.put(crnNo, map.getOrDefault(crnNo, 0) + 1);
             }
 
             List<BasCrnp> enabledCrnps = new ArrayList<>();
-            for (BasCrnp basCrnp : basCrnps) {
+            for (BasCrnp basCrnp : baseList) {
                 CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, basCrnp.getCrnNo());
                 if (crnThread == null) {
                     continue;
@@ -221,9 +256,6 @@
                 // 妫�鏌ユ槸鍚﹁秴杩囨渶澶у叆搴撲换鍔℃暟
                 if (maxInTaskControl && inWrkMasts.size() >= basCrnp.getMaxInTask()) {
                     News.info("鍫嗗灈鏈�:{} 宸茶揪鏈�澶у叆搴撲换鍔℃暟锛屽綋鍓嶄换鍔℃暟:{}", basCrnp.getCrnNo(), inWrkMasts.size());
-                    continue;
-                }
-                if (excludeCrnList.contains(basCrnp.getCrnNo())) {
                     continue;
                 }
 
@@ -269,14 +301,41 @@
             NavigateUtils navigateUtils = SpringUtils.getBean(NavigateUtils.class);
             WrkMastService wrkMastService = SpringUtils.getBean(WrkMastService.class);
             BasDualCrnpService basDualCrnpService = SpringUtils.getBean(BasDualCrnpService.class);
+            BasStationDeviceService basStationDeviceService = SpringUtils.getBean(BasStationDeviceService.class);
+
+            List<BasStationDevice> stationDevices = basStationDeviceService.selectList(new EntityWrapper<BasStationDevice>().eq("station_id", stationId));
+            boolean hasConfig = !stationDevices.isEmpty();
+            List<Integer> allowedCrnNos = new ArrayList<>();
+            if (hasConfig) {
+                for (BasStationDevice sd : stationDevices) {
+                    if (SlaveType.Crn.toString().equals(sd.getDeviceType())) {
+                        allowedCrnNos.add(sd.getDeviceNo());
+                    }
+                }
+            }
 
             Wrapper<BasDualCrnp> wrapper = new EntityWrapper<BasDualCrnp>()
                     .eq("in_enable", "Y")
                     .eq("status", 1);
 
+            if (hasConfig) {
+                wrapper.in("crn_no", allowedCrnNos);
+            }
+
             HashMap<Integer, Integer> map = new HashMap<>();
             List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<>());
             List<BasDualCrnp> basDualCrnps = basDualCrnpService.selectList(wrapper);
+
+            List<BasDualCrnp> baseList = new ArrayList<>();
+            List<BasDualCrnp> extraList = new ArrayList<>();
+            for (BasDualCrnp basDualCrnp : basDualCrnps) {
+                if (excludeCrnList.contains(basDualCrnp.getCrnNo())) {
+                    extraList.add(basDualCrnp);
+                }else {
+                    baseList.add(basDualCrnp);
+                }
+            }
+            baseList.addAll(extraList);
 
             for (WrkMast wrkMast : wrkMasts) {
                 Integer dualCrnNo = wrkMast.getDualCrnNo();
@@ -284,7 +343,7 @@
             }
 
             List<BasDualCrnp> enabledCrnps = new ArrayList<>();
-            for (BasDualCrnp basDualCrnp : basDualCrnps) {
+            for (BasDualCrnp basDualCrnp : baseList) {
                 DualCrnThread dualCrnThread = (DualCrnThread) SlaveConnection.get(SlaveType.DualCrn, basDualCrnp.getCrnNo());
                 if (dualCrnThread == null) {
                     continue;
@@ -300,10 +359,7 @@
                 );
                 // 妫�鏌ユ槸鍚﹁秴杩囨渶澶у叆搴撲换鍔℃暟
                 if (maxInTaskControl && inWrkMasts.size() >= basDualCrnp.getMaxInTask()) {
-                    News.info("鍫嗗灈鏈�:{} 宸茶揪鏈�澶у叆搴撲换鍔℃暟锛屽綋鍓嶄换鍔℃暟:{}", basDualCrnp.getCrnNo(), inWrkMasts.size());
-                    continue;
-                }
-                if (excludeCrnList.contains(basDualCrnp.getCrnNo())) {
+                    News.info("鍙屽伐浣嶅爢鍨涙満:{} 宸茶揪鏈�澶у叆搴撲换鍔℃暟锛屽綋鍓嶄换鍔℃暟:{}", basDualCrnp.getCrnNo(), inWrkMasts.size());
                     continue;
                 }
 
@@ -364,9 +420,23 @@
             return rowList;
         }
 
+        BasDualCrnpService basDualCrnpService = SpringUtils.getBean(BasDualCrnpService.class);
+        if (basDualCrnpService == null) {
+            return rowList;
+        }
+
         List<BasCrnp> basCrnps = basCrnpService.selectList(new EntityWrapper<BasCrnp>());
         for (BasCrnp basCrnp : basCrnps) {
             String deepRowsStr = basCrnp.getDeepRows();
+            if(!Cools.isEmpty(deepRowsStr)){
+                List<Integer> rows = JSON.parseArray(deepRowsStr, Integer.class);
+                rowList.addAll(rows);
+            }
+        }
+
+        List<BasDualCrnp> basDualCrnps = basDualCrnpService.selectList(new EntityWrapper<BasDualCrnp>());
+        for (BasDualCrnp basDualCrnp : basDualCrnps) {
+            String deepRowsStr = basDualCrnp.getDeepRows();
             if(!Cools.isEmpty(deepRowsStr)){
                 List<Integer> rows = JSON.parseArray(deepRowsStr, Integer.class);
                 rowList.addAll(rows);
@@ -377,6 +447,22 @@
 
     //鑾峰彇娴呭簱浣嶆帓鍙�
     public static Integer getShallowRowByDeepRow(Integer deepRow) {
+        SlaveType slaveType = checkRowDeviceType(deepRow);
+        if (slaveType == null) {
+            return null;
+        }
+
+        if (slaveType.equals(SlaveType.Crn)) {
+            return getShallowRowByCrnDeepRow(deepRow);
+        } else if (slaveType.equals(SlaveType.DualCrn)) {
+            return getShallowRowByDualCrnDeepRow(deepRow);
+        }
+
+        return null;
+    }
+
+    //鑾峰彇鍫嗗灈鏈烘祬搴撲綅鎺掑彿
+    public static Integer getShallowRowByCrnDeepRow(Integer deepRow) {
         BasCrnpService basCrnpService = SpringUtils.getBean(BasCrnpService.class);
         if (basCrnpService == null) {
             return null;
@@ -403,6 +489,52 @@
             }
         }
 
+        if (controlRowList == null) {
+            return null;
+        }
+
+        for (Integer row : controlRowList) {
+            if (deepRow.equals(row)) {
+                continue;
+            }
+
+            return row;
+        }
+        return null;
+    }
+
+    //鑾峰彇鍙屽伐浣嶅爢鍨涙満娴呭簱浣嶆帓鍙�
+    public static Integer getShallowRowByDualCrnDeepRow(Integer deepRow) {
+        BasDualCrnpService basDualCrnpService = SpringUtils.getBean(BasDualCrnpService.class);
+        if (basDualCrnpService == null) {
+            return null;
+        }
+
+        List<Integer> deepRowList = getDeepRowList();
+        if (!deepRowList.contains(deepRow)) {
+            return null;
+        }
+
+        List<Integer> controlRowList = null;
+        List<BasDualCrnp> basDualCrnps = basDualCrnpService.selectList(new EntityWrapper<>());
+        for (BasDualCrnp basDualCrnp : basDualCrnps) {
+            List<List<Integer>> rowList = basDualCrnp.getControlRows$();
+            for (List<Integer> rows : rowList) {
+                if (rows.contains(deepRow)) {
+                    controlRowList = rows;
+                    break;
+                }
+            }
+
+            if (controlRowList != null) {
+                break;
+            }
+        }
+
+        if (controlRowList == null) {
+            return null;
+        }
+
         for (Integer row : controlRowList) {
             if (deepRow.equals(row)) {
                 continue;
@@ -415,6 +547,19 @@
 
     //鑾峰彇娣卞簱浣嶆帓鍙�
     public static Integer getDeepRowByShallowRow(Integer shallowRow) {
+        SlaveType slaveType = checkRowDeviceType(shallowRow);
+
+        if (slaveType.equals(SlaveType.Crn)) {
+            return getDeepRowByCrnShallowRow(shallowRow);
+        } else if (slaveType.equals(SlaveType.DualCrn)) {
+            return getDeepRowByDualCrnShallowRow(shallowRow);
+        }
+
+        return null;
+    }
+
+    //鑾峰彇鍫嗗灈鏈烘繁搴撲綅鎺掑彿
+    public static Integer getDeepRowByCrnShallowRow(Integer shallowRow) {
         BasCrnpService basCrnpService = SpringUtils.getBean(BasCrnpService.class);
         if (basCrnpService == null) {
             return null;
@@ -451,4 +596,78 @@
         }
         return null;
     }
+
+    //鑾峰彇鍙屽伐浣嶅爢鍨涙満娣卞簱浣嶆帓鍙�
+    public static Integer getDeepRowByDualCrnShallowRow(Integer shallowRow) {
+        BasDualCrnpService basDualCrnpService = SpringUtils.getBean(BasDualCrnpService.class);
+        if (basDualCrnpService == null) {
+            return null;
+        }
+
+        List<Integer> controlRowList = null;
+        List<Integer> deepRowList = null;
+        List<BasDualCrnp> basDualCrnps = basDualCrnpService.selectList(new EntityWrapper<>());
+        for (BasDualCrnp basDualCrnp : basDualCrnps) {
+            List<List<Integer>> rowList = basDualCrnp.getControlRows$();
+            for (List<Integer> rows : rowList) {
+                if (rows.contains(shallowRow)) {
+                    controlRowList = rows;
+                    deepRowList = JSON.parseArray(basDualCrnp.getDeepRows(), Integer.class);
+                    break;
+                }
+            }
+
+            if (controlRowList != null) {
+                break;
+            }
+        }
+
+        if (deepRowList == null) {
+            return null;
+        }
+
+        for (Integer row : controlRowList) {
+            if (!deepRowList.contains(row)) {
+                continue;
+            }
+
+            return row;
+        }
+        return null;
+    }
+
+    //妫�娴嬫帓鍙疯澶囩被鍨�
+    public static SlaveType checkRowDeviceType(Integer row) {
+        BasCrnpService basCrnpService = SpringUtils.getBean(BasCrnpService.class);
+        if (basCrnpService == null) {
+            return null;
+        }
+
+        BasDualCrnpService basDualCrnpService = SpringUtils.getBean(BasDualCrnpService.class);
+        if (basDualCrnpService == null) {
+            return null;
+        }
+
+        List<BasCrnp> basCrnps = basCrnpService.selectList(new EntityWrapper<>());
+        for (BasCrnp basCrnp : basCrnps) {
+            List<List<Integer>> controlRows = basCrnp.getControlRows$();
+            for (List<Integer> list : controlRows) {
+                if (list.contains(row)) {
+                    return SlaveType.Crn;
+                }
+            }
+        }
+
+        List<BasDualCrnp> basDualCrnps = basDualCrnpService.selectList(new EntityWrapper<>());
+        for (BasDualCrnp basDualCrnp : basDualCrnps) {
+            List<List<Integer>> controlRows = basDualCrnp.getControlRows$();
+            for (List<Integer> list : controlRows) {
+                if (list.contains(row)) {
+                    return SlaveType.DualCrn;
+                }
+            }
+        }
+
+        return null;
+    }
 }

--
Gitblit v1.9.1