From 73ce8bebcc5d14f3fb62a19ee677abfcdfc776b4 Mon Sep 17 00:00:00 2001
From: Junjie <540245094@qq.com>
Date: 星期六, 19 七月 2025 16:17:51 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/common/utils/ShuttleOperaUtils.java |  166 ++++++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 132 insertions(+), 34 deletions(-)

diff --git a/src/main/java/com/zy/common/utils/ShuttleOperaUtils.java b/src/main/java/com/zy/common/utils/ShuttleOperaUtils.java
index 9292a44..6869199 100644
--- a/src/main/java/com/zy/common/utils/ShuttleOperaUtils.java
+++ b/src/main/java/com/zy/common/utils/ShuttleOperaUtils.java
@@ -4,8 +4,11 @@
 import com.core.common.SpringUtils;
 import com.core.exception.CoolException;
 import com.zy.asrs.entity.BasShuttle;
+import com.zy.asrs.entity.DeviceConfig;
 import com.zy.asrs.service.BasShuttleService;
+import com.zy.asrs.service.DeviceConfigService;
 import com.zy.asrs.utils.Utils;
+import com.zy.common.model.MapNode;
 import com.zy.common.model.NavigateNode;
 import com.zy.common.model.enums.NavigationMapType;
 import com.zy.core.News;
@@ -18,7 +21,6 @@
 import com.zy.core.model.command.ShuttleAssignCommand;
 import com.zy.core.model.command.ShuttleCommand;
 import com.zy.core.model.protocol.ShuttleProtocol;
-import com.zy.core.properties.SlaveProperties;
 import com.zy.core.thread.ShuttleThread;
 import com.zy.system.entity.Config;
 import com.zy.system.service.ConfigService;
@@ -45,15 +47,15 @@
     @Autowired
     private ConfigService configService;
     @Autowired
-    private SlaveProperties slaveProperties;
-    @Autowired
     private ShuttleDispatchUtils shuttleDispatchUtils;
+    @Autowired
+    private DeviceConfigService deviceConfigService;
 
-    public synchronized List<ShuttleCommand> getStartToTargetCommands(String startLocNo, String endLocNo, Integer mapType, ShuttleAssignCommand assignCommand, ShuttleThread shuttleThread) {
-        return getStartToTargetCommands(startLocNo, endLocNo, mapType, null, assignCommand, shuttleThread);
+    public synchronized List<ShuttleCommand> getStartToTargetCommands(String startLocNo, String endLocNo, List<NavigationMapType> mapTypes, ShuttleAssignCommand assignCommand, ShuttleThread shuttleThread) {
+        return getStartToTargetCommands(startLocNo, endLocNo, mapTypes, null, assignCommand, shuttleThread);
     }
 
-    public synchronized List<ShuttleCommand> getStartToTargetCommands(String startLocNo, String endLocNo, Integer mapType, List<int[]> whites, ShuttleAssignCommand assignCommand, ShuttleThread shuttleThread) {
+    public synchronized List<ShuttleCommand> getStartToTargetCommands(String startLocNo, String endLocNo, List<NavigationMapType> mapTypes, List<int[]> whites, ShuttleAssignCommand assignCommand, ShuttleThread shuttleThread) {
         ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
         if (shuttleProtocol == null) {
             return null;
@@ -61,7 +63,7 @@
         Integer shuttleNo = shuttleProtocol.getShuttleNo();
         //鑾峰彇灏忚溅绉诲姩閫熷害
         Integer runSpeed = Optional.ofNullable(basShuttleService.selectOne(new EntityWrapper<BasShuttle>().eq("shuttle_no", shuttleNo)).getRunSpeed()).orElse(1000);
-        List<NavigateNode> nodeList = navigateUtils.calc(startLocNo, endLocNo, mapType, Utils.getShuttlePoints(shuttleNo, Utils.getLev(startLocNo)), whites);
+        List<NavigateNode> nodeList = navigateUtils.calc(startLocNo, endLocNo, mapTypes, Utils.getShuttlePoints(shuttleNo, Utils.getLev(startLocNo)), whites);
         if (nodeList == null) {
             News.error("{} dash {} can't find navigate path!", startLocNo, endLocNo);
             shuttleThread.offerSystemMsg("{} dash {} can't find navigate path!", startLocNo, endLocNo);
@@ -121,7 +123,7 @@
         return commands;
     }
 
-    public synchronized List<ShuttleCommand> shuttleInOutLiftCommand(String startLocNo, String endLocNo, Integer mapType, ShuttleAssignCommand assignCommand, ShuttleThread shuttleThread) {
+    public synchronized List<ShuttleCommand> shuttleInOutLiftCommand(String startLocNo, String endLocNo, List<NavigationMapType> mapTypes, ShuttleAssignCommand assignCommand, ShuttleThread shuttleThread) {
         NavigateNode startNode = NavigatePositionConvert.locNoToNode(startLocNo);
         NavigateNode endNode = NavigatePositionConvert.locNoToNode(endLocNo);
         List<NavigateNode> unlockPath = new ArrayList<>();
@@ -144,7 +146,7 @@
 
         //鑾峰彇灏忚溅绉诲姩閫熷害
         Integer runSpeed = Optional.ofNullable(basShuttleService.selectOne(new EntityWrapper<BasShuttle>().eq("shuttle_no", shuttleNo)).getRunSpeed()).orElse(1000);
-        List<NavigateNode> nodeList = navigateUtils.calc(startLocNo, endLocNo, mapType, Utils.getShuttlePoints(shuttleNo, Utils.getLev(startLocNo)), null);
+        List<NavigateNode> nodeList = navigateUtils.calc(startLocNo, endLocNo, mapTypes, Utils.getShuttlePoints(shuttleNo, Utils.getLev(startLocNo)), null);
         if (nodeList == null) {
             News.error("{} dash {} can't find navigate path!", startLocNo, endLocNo);
             shuttleThread.offerSystemMsg("{} dash {} can't find navigate path!", startLocNo, endLocNo);
@@ -260,22 +262,36 @@
                 continue;
             }
 
-            int nextInt = new Random().nextInt(outerNodes.size());
-            NavigateNode randomNode = outerNodes.get(nextInt);
-            String randomLocNo = NavigatePositionConvert.nodeToLocNo(randomNode);
-            shuttleDispatchUtils.dispatchShuttle(null, randomLocNo, shuttleNo);
+            String targetLocNo = null;
+            for (NavigateNode node : outerNodes) {
+                String dispatchLocNo = NavigatePositionConvert.nodeToLocNo(node);
+                //鑾峰彇鍐呭湀鑺傜偣
+                List<NavigateNode> avoidInnerNodes = getInnerNodes(dispatchLocNo, innerCircle, new ArrayList<>());
+                //璁$畻鍐呭湀鏄惁鏈夊皬杞�
+                List<Integer> avoidNodesCar = findNodesCar(avoidInnerNodes);
+                if(!avoidNodesCar.isEmpty()) {
+                   continue;
+                }
+                targetLocNo = dispatchLocNo;
+                break;
+            }
+
+            if(targetLocNo == null) {
+                continue;
+            }
+            shuttleDispatchUtils.dispatchShuttle(null, targetLocNo, shuttleNo);
         }
 
         return true;//鍐呭湀涓湁杞�
     }
 
-    //鎼滅储鑺傜偣鍐呯殑灏忚溅缂栧彿
-    private List<Integer> findNodesCar(List<NavigateNode> nodes) {
-        List<Integer> list = new ArrayList<>();
-
+    private HashMap<String, Integer> findCarMap() {
         HashMap<String, Integer> carMap = new HashMap<>();
-        for (ShuttleSlave slave : slaveProperties.getShuttle()) {
-            ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, slave.getId());
+
+        List<DeviceConfig> shuttleList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>()
+                .eq("device_type", String.valueOf(SlaveType.Shuttle)));
+        for (DeviceConfig device : shuttleList) {
+            ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, device.getDeviceNo());
             if (shuttleThread == null) {
                 continue;
             }
@@ -288,9 +304,15 @@
                 continue;
             }
 
-            carMap.put(currentLocNo, slave.getId());
+            carMap.put(currentLocNo, device.getDeviceNo());
         }
+        return carMap;
+    }
 
+    //鎼滅储鑺傜偣鍐呯殑灏忚溅缂栧彿
+    private List<Integer> findNodesCar(List<NavigateNode> nodes) {
+        List<Integer> list = new ArrayList<>();
+        HashMap<String, Integer> carMap = findCarMap();
         for (NavigateNode node : nodes) {
             String locNo = NavigatePositionConvert.nodeToLocNo(node);
             if (carMap.containsKey(locNo)) {
@@ -307,14 +329,16 @@
         int lev = Utils.getLev(locNo);
         int[] pointArr = NavigatePositionConvert.positionToXY(locNo);
         NavigateNode currentNode = new NavigateNode(pointArr[0], pointArr[1]);
+        currentNode.setZ(lev);
 
-        int[][] map = navigateMapData.getDataFromRedis(lev, NavigationMapType.NORMAL.id, null, whiteShuttlePointList);
+        List<List<MapNode>> lists = navigateMapData.getJsonData(lev, -1, null, null);//鑾峰彇瀹屾暣鍦板浘
+        int[][] map = navigateMapData.parseJsonDataArr(lists);
         int nodeValue = map[pointArr[0]][pointArr[1]];
         currentNode.setNodeValue(nodeValue);
 
         for (int i = 0; i < outerCircle; i++) {
             int idx = i + 1;
-            List<NavigateNode> list = extend_nodes(map, currentNode, idx);
+            List<NavigateNode> list = extend_outer_nodes(map, currentNode, idx);
             if (list.isEmpty()) {
                 continue;
             }
@@ -348,23 +372,37 @@
         currentNode.setZ(lev);
         innerNodes.add(currentNode);
 
-        int[][] map = navigateMapData.getDataFromRedis(lev, NavigationMapType.NORMAL.id, null, whiteShuttlePointList);
+        List<List<MapNode>> lists = navigateMapData.getJsonData(lev, -1, null, null);//鑾峰彇瀹屾暣鍦板浘
+        int[][] map = navigateMapData.parseJsonDataArr(lists);
         int nodeValue = map[pointArr[0]][pointArr[1]];
         currentNode.setNodeValue(nodeValue);
 
         for (int i = 0; i < innerCircle; i++) {
             int idx = i + 1;
-            List<NavigateNode> list = extend_nodes(map, currentNode, idx);
+            List<NavigateNode> list = extend_inner_nodes(map, currentNode, idx);
             if (list.isEmpty()) {
                 continue;
             }
-            innerNodes.addAll(list);
+
+            for (NavigateNode node : list) {
+                boolean flag = false;
+                for (int[] shuttlePoint : whiteShuttlePointList) {
+                    if(node.getX() == shuttlePoint[0] && node.getY() == shuttlePoint[1]) {
+                        flag = true;
+                        break;
+                    }
+                }
+                if(flag) {
+                    continue;
+                }
+                innerNodes.add(node);
+            }
         }
 
         return innerNodes;
     }
 
-    private List<NavigateNode> extend_nodes(int[][] map, NavigateNode startNode, int innerCircleIdx) {
+    private List<NavigateNode> extend_inner_nodes(int[][] map, NavigateNode startNode, int innerCircleIdx) {
         //榛樿鍦板浘姣嶈建鏂瑰悜x
         String mapDirection = "x";
         ConfigService configService = SpringUtils.getBean(ConfigService.class);
@@ -389,13 +427,17 @@
                     NavigateNode node = new NavigateNode(x + innerCircleIdx, y);
                     node.setNodeValue(map[x + innerCircleIdx][y]);
                     node.setZ(z);
-                    nodes.add(node);
+                    if (node.getNodeValue().equals(startNode.getNodeValue())) {
+                        nodes.add(node);
+                    }
                 }
                 if (is_valid(map, x - innerCircleIdx, y)) {
                     NavigateNode node = new NavigateNode(x - innerCircleIdx, y);
                     node.setNodeValue(map[x - innerCircleIdx][y]);
                     node.setZ(z);
-                    nodes.add(node);
+                    if (node.getNodeValue().equals(startNode.getNodeValue())) {
+                        nodes.add(node);
+                    }
                 }
             }
 
@@ -405,14 +447,18 @@
                     NavigateNode node = new NavigateNode(x, y + innerCircleIdx);
                     node.setNodeValue(map[x][y + innerCircleIdx]);
                     node.setZ(z);
-                    nodes.add(node);
+                    if (node.getNodeValue().equals(startNode.getNodeValue())) {
+                        nodes.add(node);
+                    }
                 }
 
                 if (is_valid(map, x, y - innerCircleIdx)) {
                     NavigateNode node = new NavigateNode(x, y - innerCircleIdx);
                     node.setNodeValue(map[x][y - innerCircleIdx]);
                     node.setZ(z);
-                    nodes.add(node);
+                    if (node.getNodeValue().equals(startNode.getNodeValue())) {
+                        nodes.add(node);
+                    }
                 }
             }
         }else if (mapDirection.equals("y")) {//姣嶈建y鏂瑰悜
@@ -422,14 +468,18 @@
                     NavigateNode node = new NavigateNode(x, y + innerCircleIdx);
                     node.setNodeValue(map[x][y + innerCircleIdx]);
                     node.setZ(z);
-                    nodes.add(node);
+                    if (node.getNodeValue().equals(startNode.getNodeValue())) {
+                        nodes.add(node);
+                    }
                 }
 
                 if (is_valid(map, x, y - innerCircleIdx)) {
                     NavigateNode node = new NavigateNode(x, y - innerCircleIdx);
                     node.setNodeValue(map[x][y - innerCircleIdx]);
                     node.setZ(z);
-                    nodes.add(node);
+                    if (node.getNodeValue().equals(startNode.getNodeValue())) {
+                        nodes.add(node);
+                    }
                 }
             }
 
@@ -439,13 +489,17 @@
                     NavigateNode node = new NavigateNode(x + innerCircleIdx, y);
                     node.setNodeValue(map[x + innerCircleIdx][y]);
                     node.setZ(z);
-                    nodes.add(node);
+                    if (node.getNodeValue().equals(startNode.getNodeValue())) {
+                        nodes.add(node);
+                    }
                 }
                 if (is_valid(map, x - innerCircleIdx, y)) {
                     NavigateNode node = new NavigateNode(x - innerCircleIdx, y);
                     node.setNodeValue(map[x - innerCircleIdx][y]);
                     node.setZ(z);
-                    nodes.add(node);
+                    if (node.getNodeValue().equals(startNode.getNodeValue())) {
+                        nodes.add(node);
+                    }
                 }
             }
         }else {
@@ -455,6 +509,50 @@
         return nodes;
     }
 
+    private List<NavigateNode> extend_outer_nodes(int[][] map, NavigateNode startNode, int innerCircleIdx) {
+        ArrayList<NavigateNode> nodes = new ArrayList<>();
+        int x = startNode.getX();
+        int y = startNode.getY();
+        int z = startNode.getZ();
+
+        if (is_valid(map, x + innerCircleIdx, y)) {
+            NavigateNode node = new NavigateNode(x + innerCircleIdx, y);
+            node.setNodeValue(map[x + innerCircleIdx][y]);
+            node.setZ(z);
+            if (node.getNodeValue().equals(startNode.getNodeValue())) {
+                nodes.add(node);
+            }
+        }
+
+        if (is_valid(map, x - innerCircleIdx, y)) {
+            NavigateNode node = new NavigateNode(x - innerCircleIdx, y);
+            node.setNodeValue(map[x - innerCircleIdx][y]);
+            node.setZ(z);
+            if (node.getNodeValue().equals(startNode.getNodeValue())) {
+                nodes.add(node);
+            }
+        }
+
+        if (is_valid(map, x, y + innerCircleIdx)) {
+            NavigateNode node = new NavigateNode(x, y + innerCircleIdx);
+            node.setNodeValue(map[x][y + innerCircleIdx]);
+            node.setZ(z);
+            if (node.getNodeValue().equals(startNode.getNodeValue())) {
+                nodes.add(node);
+            }
+        }
+
+        if (is_valid(map, x, y - innerCircleIdx)) {
+            NavigateNode node = new NavigateNode(x, y - innerCircleIdx);
+            node.setNodeValue(map[x][y - innerCircleIdx]);
+            node.setZ(z);
+            if (node.getNodeValue().equals(startNode.getNodeValue())) {
+                nodes.add(node);
+            }
+        }
+        return nodes;
+    }
+
     private boolean is_valid(int[][] map, int x, int y) {
         if (x < 0 || x >= map.length
                 || y < 0 || y >= map[0].length) {

--
Gitblit v1.9.1