From 728ad81fa10d2879654c5f9ae4314db94eafb865 Mon Sep 17 00:00:00 2001
From: Junjie <540245094@qq.com>
Date: 星期五, 01 八月 2025 08:08:18 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/core/task/ShuttleExecuteScheduler.java         |   48 ++--
 src/main/java/com/zy/core/thread/impl/NyShuttleThread.java          |   76 +++---
 src/main/java/com/zy/core/action/ShuttleAction.java                 |   50 ++-
 src/main/webapp/views/console.html                                  |   25 +
 src/main/java/com/zy/core/thread/impl/TrafficControlImplThread.java |  460 +++++---------------------------------
 src/main/java/com/zy/core/thread/TrafficControlThread.java          |   11 
 src/main/webapp/views/shuttleNew.html                               |   28 +
 7 files changed, 196 insertions(+), 502 deletions(-)

diff --git a/src/main/java/com/zy/core/action/ShuttleAction.java b/src/main/java/com/zy/core/action/ShuttleAction.java
index d25b6cb..a0a88b1 100644
--- a/src/main/java/com/zy/core/action/ShuttleAction.java
+++ b/src/main/java/com/zy/core/action/ShuttleAction.java
@@ -22,6 +22,7 @@
 import com.zy.core.dispatcher.ShuttleDispatchUtils;
 import com.zy.core.enums.*;
 import com.zy.core.model.CommandResponse;
+import com.zy.core.model.TrafficControlDataModel;
 import com.zy.core.model.command.ShuttleAssignCommand;
 import com.zy.core.model.command.ShuttleCommand;
 import com.zy.core.model.command.ShuttleRedisCommand;
@@ -86,7 +87,7 @@
         return false;
     }
 
-    public synchronized boolean executeWork(Integer shuttleNo, Integer taskNo) {
+    public boolean executeWork(Integer shuttleNo, Integer taskNo) {
         Object obj = redisUtil.get(RedisKeyType.SHUTTLE_WORK_FLAG.key + taskNo);
         if (obj == null) {
             return false;
@@ -165,7 +166,9 @@
 
             List<NavigateNode> nodes = JSON.parseArray(JSON.toJSONString(command.getNodes()), NavigateNode.class);
             //鐢宠绠″埗
-            boolean apply = applyTrafficControl(commands, nodes, shuttleNo, taskNo);
+            applyTrafficControl(commands, nodes, shuttleNo, taskNo);
+            //鏌ヨ绠″埗
+            boolean apply = queryTrafficControl(shuttleNo, taskNo);
             if(!apply){
                 return false;//鐢宠澶辫触
             }
@@ -294,21 +297,23 @@
                     //鐩寸嚎娈垫暟鎹爣璇�
                     Long linePartFlag = startNode.getLinePartFlag();
 
-                    //鍙栨寚浠�
-                    ShuttleCommand currentCommand = commands.get(commandStep);
-                    if(currentCommand.getMode() != ShuttleCommandModeType.MOVE.id) {
-                        return 0;
-                    }
+                    if(commandStep < commands.size()){
+                        //鍙栨寚浠�
+                        ShuttleCommand currentCommand = commands.get(commandStep);
+                        if(currentCommand.getMode() != ShuttleCommandModeType.MOVE.id) {
+                            return 0;
+                        }
 
-                    List<NavigateNode> currentNodes = currentCommand.getNodes();
-                    NavigateNode currentStartNode = currentNodes.get(0);
-                    if(!currentStartNode.getLinePartAllowGo()) {//鐩寸嚎娈甸儴鍒嗭紝鍏佽鐩存帴琛岃蛋
-                        return 0;
-                    }
+                        List<NavigateNode> currentNodes = currentCommand.getNodes();
+                        NavigateNode currentStartNode = currentNodes.get(0);
+                        if(!currentStartNode.getLinePartAllowGo()) {//鐩寸嚎娈甸儴鍒嗭紝鍏佽鐩存帴琛岃蛋
+                            return 0;
+                        }
 
-                    if(currentStartNode.getLinePartFlag().equals(linePartFlag)) {
-                        //鏁版嵁鏍囪瘑涓�鑷�
-                        return 2;//鍏佽灏忚溅绉诲姩杩炵画涓嬪彂鎸囦护
+                        if(currentStartNode.getLinePartFlag().equals(linePartFlag)) {
+                            //鏁版嵁鏍囪瘑涓�鑷�
+                            return 2;//鍏佽灏忚溅绉诲姩杩炵画涓嬪彂鎸囦护
+                        }
                     }
                 }
 
@@ -490,6 +495,21 @@
         return trafficControlThread.applyTrafficControl(totalNodeList, nodeList, shuttleNo, taskNo);
     }
 
+    //鏌ヨ鏄惁鐢宠绠″埗鎴愬姛
+    public boolean queryTrafficControl(Integer shuttleNo, Integer taskNo) {
+        TrafficControlThread trafficControlThread = (TrafficControlThread) SlaveConnection.get(SlaveType.TrafficControl, 1);
+        if (trafficControlThread == null) {
+            return false;
+        }
+
+        TrafficControlDataModel trafficControlDataModel = trafficControlThread.queryTrafficControl(shuttleNo, taskNo);
+        if (trafficControlDataModel == null) {
+            return false;
+        }
+
+        return true;
+    }
+
 //    /**
 //     * 鎼滅储灏忚溅璺緞鏄惁瀛樺湪鍐茬獊
 //     * 0:鏈娴� 1:妫�娴嬫棤鍐茬獊 2:妫�娴嬫湁鍐茬獊
diff --git a/src/main/java/com/zy/core/task/ShuttleExecuteScheduler.java b/src/main/java/com/zy/core/task/ShuttleExecuteScheduler.java
index 5b16027..9020af6 100644
--- a/src/main/java/com/zy/core/task/ShuttleExecuteScheduler.java
+++ b/src/main/java/com/zy/core/task/ShuttleExecuteScheduler.java
@@ -18,29 +18,29 @@
 @Component
 public class ShuttleExecuteScheduler {
 
-    @Autowired
-    private ShuttleAction shuttleAction;
-    @Autowired
-    private DeviceConfigService deviceConfigService;
-    @Autowired
-    private RedisUtil redisUtil;
-
-    @Scheduled(cron = "0/1 * * * * ? ")
-    public void execute() {
-        List<DeviceConfig> shuttleList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>()
-                .eq("device_type", String.valueOf(SlaveType.Shuttle)));
-        for (DeviceConfig deviceConfig : shuttleList) {
-            Object object = redisUtil.get(RedisKeyType.SHUTTLE_FLAG.key + deviceConfig.getDeviceNo());
-            if (object == null) {
-                continue;
-            }
-
-            int taskNo = Integer.parseInt(String.valueOf(object));
-            if (taskNo != 0) {
-                //瀛樺湪浠诲姟闇�瑕佹墽琛�
-                boolean result = shuttleAction.executeWork(deviceConfig.getDeviceNo(), taskNo);
-            }
-        }
-    }
+//    @Autowired
+//    private ShuttleAction shuttleAction;
+//    @Autowired
+//    private DeviceConfigService deviceConfigService;
+//    @Autowired
+//    private RedisUtil redisUtil;
+//
+//    @Scheduled(cron = "0/1 * * * * ? ")
+//    public void execute() {
+//        List<DeviceConfig> shuttleList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>()
+//                .eq("device_type", String.valueOf(SlaveType.Shuttle)));
+//        for (DeviceConfig deviceConfig : shuttleList) {
+//            Object object = redisUtil.get(RedisKeyType.SHUTTLE_FLAG.key + deviceConfig.getDeviceNo());
+//            if (object == null) {
+//                continue;
+//            }
+//
+//            int taskNo = Integer.parseInt(String.valueOf(object));
+//            if (taskNo != 0) {
+//                //瀛樺湪浠诲姟闇�瑕佹墽琛�
+//                boolean result = shuttleAction.executeWork(deviceConfig.getDeviceNo(), taskNo);
+//            }
+//        }
+//    }
 
 }
diff --git a/src/main/java/com/zy/core/thread/TrafficControlThread.java b/src/main/java/com/zy/core/thread/TrafficControlThread.java
index 3314b13..a12dd26 100644
--- a/src/main/java/com/zy/core/thread/TrafficControlThread.java
+++ b/src/main/java/com/zy/core/thread/TrafficControlThread.java
@@ -5,18 +5,9 @@
 import com.zy.core.ThreadHandler;
 import com.zy.core.model.TrafficControlDataModel;
 
-import java.util.HashMap;
 import java.util.List;
 
 public interface TrafficControlThread extends ThreadHandler {
-
-//    boolean getDetecting();
-//
-//    void updateDetect();
-//
-//    boolean addNodes(Integer shuttleNo, Integer taskNo, List<NavigateNode> nodeList);
-//
-//    boolean removeNodes(Integer shuttleNo, Integer taskNo);
 
     boolean applyTrafficControl(List<NavigateNode> totalNodeList, List<NavigateNode> nodeList, Integer shuttleNo, Integer taskNo);
 
@@ -28,6 +19,8 @@
 
     boolean forceCancelTrafficControl(Integer shuttleNo);
 
+    TrafficControlDataModel queryTrafficControl(Integer shuttleNo, Integer taskNo);
+
     TrafficControlDataModel queryTrafficControl(Integer shuttleNo);
 
     List<TrafficControlDataModel> getAllTrafficControl();
diff --git a/src/main/java/com/zy/core/thread/impl/NyShuttleThread.java b/src/main/java/com/zy/core/thread/impl/NyShuttleThread.java
index 19af9d7..312b527 100644
--- a/src/main/java/com/zy/core/thread/impl/NyShuttleThread.java
+++ b/src/main/java/com/zy/core/thread/impl/NyShuttleThread.java
@@ -52,6 +52,7 @@
     private DeviceConfig deviceConfig;
     private RedisUtil redisUtil;
     private ShuttleProtocol shuttleProtocol;
+    private ShuttleAction shuttleAction = null;
 
     private static final boolean DEBUG = false;//璋冭瘯妯″紡
 
@@ -88,38 +89,35 @@
         });
         readThread.start();
 
-//        //璁惧鎵ц
-//        Thread executeThread = new Thread(() -> {
-//            while (true) {
-//                try {
-//                    ShuttleAction shuttleAction = null;
-//                    try {
-//                        shuttleAction = SpringUtils.getBean(ShuttleAction.class);
-//                    }catch (Exception e){
-//                        continue;
-//                    }
-//
-//                    if (shuttleAction == null) {
-//                        continue;
-//                    }
-//
-//                    Object object = redisUtil.get(RedisKeyType.SHUTTLE_FLAG.key + deviceConfig.getDeviceNo());
-//                    if (object == null) {
-//                        continue;
-//                    }
-//
-//                    Integer taskNo = Integer.valueOf(String.valueOf(object));
-//                    if (taskNo != 0) {
-//                        //瀛樺湪浠诲姟闇�瑕佹墽琛�
-//                        boolean result = shuttleAction.executeWork(deviceConfig.getDeviceNo(), taskNo);
-//                    }
-//                    Thread.sleep(100);
-//                } catch (Exception e) {
-//                    e.printStackTrace();
-//                }
-//            }
-//        });
-//        executeThread.start();
+        //璁惧鎵ц
+        Thread executeThread = new Thread(() -> {
+            while (true) {
+                try {
+                    if (shuttleAction == null) {
+                        try {
+                            shuttleAction = SpringUtils.getBean(ShuttleAction.class);
+                        }catch (Exception e){
+                        }
+                        continue;
+                    }
+
+                    Object object = redisUtil.get(RedisKeyType.SHUTTLE_FLAG.key + deviceConfig.getDeviceNo());
+                    if (object == null) {
+                        continue;
+                    }
+
+                    Integer taskNo = Integer.valueOf(String.valueOf(object));
+                    if (taskNo != 0) {
+                        //瀛樺湪浠诲姟闇�瑕佹墽琛�
+                        boolean result = shuttleAction.executeWork(deviceConfig.getDeviceNo(), taskNo);
+                    }
+                    Thread.sleep(100);
+                } catch (Exception e) {
+                    e.printStackTrace();
+                }
+            }
+        });
+        executeThread.start();
     }
 
     private void listenMessageFromRedis() {
@@ -1214,16 +1212,16 @@
 
     private JSONObject queryCommandStatus(String resultKey) {
         // 鑾峰彇鏈嶅姟鍣ㄥ搷搴�
-        // 灏濊瘯50娆�
         JSONObject result = null;
-        for (int i = 0; i < 50; i++) {
+        long startTime = System.currentTimeMillis();
+        while (true) {
+            if((System.currentTimeMillis() - startTime) > 1000 * 10) {
+                break;
+            }
+
             result = getRequestBody(resultKey);
             if (result == null) {
-                try {
-                    Thread.sleep(500);
-                } catch (Exception e) {
-                    e.printStackTrace();
-                }
+                continue;
             }else {
                 break;
             }
diff --git a/src/main/java/com/zy/core/thread/impl/TrafficControlImplThread.java b/src/main/java/com/zy/core/thread/impl/TrafficControlImplThread.java
index 9a3a6de..7fccedc 100644
--- a/src/main/java/com/zy/core/thread/impl/TrafficControlImplThread.java
+++ b/src/main/java/com/zy/core/thread/impl/TrafficControlImplThread.java
@@ -29,13 +29,8 @@
 public class TrafficControlImplThread implements TrafficControlThread {
 
     private RedisUtil redisUtil;
-    private boolean detecting = false;
-    private boolean updateDetect = false;
-    private Long detectTime = System.currentTimeMillis();
-    private HashMap<String, Integer> deviceMap = null;
-    private HashMap<Integer, HashMap<String, List<Integer>>> levNodesMap = null;
 
-
+    private List<TrafficControlDataModel> applyList = new ArrayList<>();
     private HashMap<Integer,Long> shuttleReportErrorMap = new HashMap<>();
     private HashMap<Integer,Long> pathIdleShuttleMap = new HashMap<>();
     private HashMap<Integer,Long> applyRecordsMap = new HashMap<>();
@@ -54,402 +49,40 @@
             trafficControlDataList = (List<TrafficControlDataModel>) object;
         }
 
-//        List<Integer> shuttleNoList = new ArrayList<>();
-//        while (true) {
-//            try {
-//                DeviceConfigService deviceConfigService = null;
-//                try {
-//                    deviceConfigService = SpringUtils.getBean(DeviceConfigService.class);
-//                }catch (Exception e){}
-//
-//                if(deviceConfigService == null){
-//                    continue;
-//                }
-//
-//                if(shuttleNoList.isEmpty()){
-//                    List<DeviceConfig> shuttleList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>()
-//                            .eq("device_type", String.valueOf(SlaveType.Shuttle)));
-//                    for (DeviceConfig deviceConfig : shuttleList) {
-//                        shuttleNoList.add(deviceConfig.getDeviceNo());
-//                    }
-//                }
-//
-//                if((updateDetect) || ((System.currentTimeMillis() - detectTime) > 1000 * 2)) {
-//                    detect(shuttleNoList);
-//                }
-//            }catch (Exception e){
-//                e.printStackTrace();
-//            }
-//        }
-
-    }
-
-    public synchronized void detect(List<Integer> shuttleNoList) {
-        detecting = true;
-        updateDetect = false;
-        ObjectMapper objectMapper = null;
-        try {
-            objectMapper = SpringUtils.getBean(ObjectMapper.class);
-        }catch (Exception e){}
-
-        if(objectMapper == null){
-            return;
-        }
-
-        HashMap<String, List<NavigateNode>> tmpTaskNodesMap = new HashMap<>();
-        for (Integer shuttleNo : shuttleNoList) {
-            ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleNo);
-            if (shuttleThread == null) {
-                continue;
-            }
-
-            ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
-            if (shuttleProtocol == null) {
-                continue;
-            }
-
-            if (shuttleProtocol.getTaskNo() == 0) {
-                continue;
-            }
-
-            if (shuttleProtocol.getCurrentLocNo() == null) {
-                continue;
-            }
-
-            int lev = Utils.getLev(shuttleProtocol.getCurrentLocNo());
-
-            Object obj = redisUtil.get(RedisKeyType.SHUTTLE_WORK_FLAG.key + shuttleProtocol.getTaskNo());
-            if (obj == null) {
-                continue;
-            }
-
-            ShuttleRedisCommand redisCommand = null;
+        while (true) {
             try {
-                redisCommand = objectMapper.readValue(String.valueOf(obj), ShuttleRedisCommand.class);
-            } catch (IOException e) {
-                throw new RuntimeException(e);
-            }
-
-            if (redisCommand == null) {
-                continue;
-            }
-
-            ShuttleAssignCommand assignCommand = redisCommand.getAssignCommand();
-            if (assignCommand == null) {
-                continue;
-            }
-
-            List<NavigateNode> nodeList = assignCommand.getNodesDeepCopy();
-            if (nodeList == null || nodeList.isEmpty()) {
-                continue;
-            }
-
-            tmpTaskNodesMap.put(shuttleProtocol.getTaskNo() + "-" + shuttleNo, nodeList);
-        }
-        this.taskNodesMap = tmpTaskNodesMap;
-        HashMap<Integer, HashMap<String, List<Integer>>> levNodesMap = calcNodeList();
-
-        HashMap<Integer, HashMap<String, List<Integer>>> levBlockMap = new HashMap<>();
-        //杩囨护涓嶉渶瑕佺鍒惰妭鐐�
-        for (Map.Entry<Integer, HashMap<String, List<Integer>>> entry : levNodesMap.entrySet()) {
-            Integer lev = entry.getKey();
-            HashMap<String, List<Integer>> value = entry.getValue();
-
-            HashMap<String, List<Integer>> blockMap = new HashMap<>();
-            for (Map.Entry<String, List<Integer>> listEntry : value.entrySet()) {
-                String locNo = listEntry.getKey();
-                List<Integer> shuttleNos = listEntry.getValue();
-                if (shuttleNos.size() <= 1) {
+                if (applyList.isEmpty()) {
                     continue;
                 }
-                blockMap.put(locNo, shuttleNos);
-            }
 
-            levBlockMap.put(lev, blockMap);
+                TrafficControlDataModel dataModel = applyList.get(0);
+                processApply(dataModel);
+                applyList.remove(0);
+            }catch (Exception e){
+                e.printStackTrace();
+            }
         }
 
-        //璁$畻鍫靛鑼冨洿
-        List<List<String>> allLocList = new ArrayList<>();
-        List<List<Integer>> allDeviceNodes = new ArrayList<>();
-        for (Map.Entry<Integer, HashMap<String, List<Integer>>> entry : levBlockMap.entrySet()) {
-            Integer lev = entry.getKey();
-            HashMap<String, List<Integer>> nodes = entry.getValue();
-
-            Set<String> sets = new HashSet<>();
-            for (Map.Entry<String, List<Integer>> val : nodes.entrySet()) {
-                String locNo = val.getKey();
-                sets.add(locNo);
-            }
-
-            List<List<String>> locList = TrafficControlUtils.groupNodes(sets);
-            List<List<Integer>> deviceNodes = new ArrayList<>();
-
-            //get devices
-            for (List<String> list : locList) {
-                List<List<Integer>> tmpDeviceNodes = new ArrayList<>();
-                for (String loc : list) {
-                    List<Integer> shuttleNos = nodes.get(loc);
-                    if(!tmpDeviceNodes.contains(shuttleNos)) {
-                        tmpDeviceNodes.add(shuttleNos);
-                    }
-                }
-                //鑺傜偣骞堕泦-鑾峰彇鍫靛璁惧缂栧彿
-                List<List<Integer>> deviceList = mergeConnectedComponents(tmpDeviceNodes);
-                deviceNodes.addAll(deviceList);
-            }
-
-            allLocList.addAll(locList);
-            allDeviceNodes.addAll(deviceNodes);
-        }
-
-        System.out.println(JSON.toJSONString(allLocList));
-        System.out.println(JSON.toJSONString(allDeviceNodes));
-//        //鍒嗛厤鍫靛鑺傜偣鍙墽琛岃澶�
-//        findDeviceByBlockList(allLocList, allDeviceNodes);
-
-        detecting = false;
-        detectTime = System.currentTimeMillis();
-
-//        //鍙戝竷鍫靛鑺傜偣鍙敤璁惧缂栧彿
-//        redisUtil.set(RedisKeyType.TASK_BLOCK_ENABLE_DEVICE_MAP.key, trafficControlDataList);
     }
 
-//    //鍒嗛厤鍫靛鑺傜偣鍙墽琛岃澶�
-//    public void findDeviceByBlockList(List<List<String>> allLocList, List<List<Integer>> blockNodes) {
-//        HashMap<String, Integer> map = new HashMap<>();
-//        if (deviceMap == null) {
-//            Object object = redisUtil.get(RedisKeyType.TASK_BLOCK_ENABLE_DEVICE_MAP.key);
-//            if (object != null) {
-//                map = (HashMap<String, Integer>) object;
-//            }
-//        } else {
-//            map = deviceMap;
-//        }
-//
-//        HashMap<String, Integer> newMap = new HashMap<>();
-//
-//        for (int i = 0; i < blockNodes.size(); i++) {
-//            List<Integer> blockNode = blockNodes.get(i);
-//            List<String> locs = allLocList.get(i);
-//
-//            String key = JSON.toJSONString(locs);
-//
-//            Integer value = -1;
-//            if (map.containsKey(key)) {
-//                value = map.get(key);
-//                map.remove(key);
-//
-//                if (value > 0) {
-//                    ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, value);
-//                    if (shuttleThread == null) {
-//                        continue;
-//                    }
-//
-//                    ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
-//                    if (shuttleProtocol == null) {
-//                        continue;
-//                    }
-//
-//                    if (shuttleProtocol.getTaskNo() == 0) {
-//                        value = searchDevice(locs, blockNode, newMap);
-//                    }
-//
-//                    if (!shuttleProtocol.getTrafficControl()) {
-//                        value = searchDevice(locs, blockNode, newMap);
-//                    }
-//                }else {
-//                    value = searchDevice(locs, blockNode, newMap);
-//                }
-//            } else {
-//                value = searchDevice(locs, blockNode, newMap);
-//            }
-//            newMap.put(key, value);
-//        }
-//
-//        deviceMap = newMap;
-//        //鍙戝竷鍫靛鑺傜偣鍙敤璁惧缂栧彿
-//        redisUtil.set(RedisKeyType.TASK_BLOCK_ENABLE_DEVICE_MAP.key, newMap);
-//    }
-
-    public Integer searchDevice(List<String> locs, List<Integer> blockNode, HashMap<String, Integer> deviceMap) {
-        NavigateUtils navigateUtils = null;
-        try {
-            navigateUtils = SpringUtils.getBean(NavigateUtils.class);
-        }catch (Exception e){}
-
-        if(navigateUtils == null){
-            return -1;
-        }
-
-        Integer value = -1;
-        for (Integer shuttleNo : blockNode) {
-            ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleNo);
-            if (shuttleThread == null) {
-                continue;
-            }
-
-            ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
-            if (shuttleProtocol == null) {
-                continue;
-            }
-
-            if (!shuttleThread.isDeviceIdle()) {
-                continue;
-            }
-
-            if (shuttleProtocol.getTaskNo() == 0) {
-                continue;
-            }
-
-            if (!shuttleProtocol.getTrafficControl()) {
-                continue;//灏忚溅鏈敵璇蜂氦閫氱鍒�
-            }
-
-            //妫�娴嬪皬杞︽槸鍚﹀凡缁忓垎閰�
-            if (deviceMap.containsValue(shuttleNo)) {
-                continue;
-            }
-
-            List<NavigateNode> trafficControlNodes = shuttleProtocol.getTrafficControlNodes();
-            List<String> trafficControlLocs = new ArrayList<>();
-            for (NavigateNode node : trafficControlNodes) {
-                trafficControlLocs.add(Utils.getLocNo(node.getX(), node.getY(), node.getZ()));
-            }
-
-            //妫�娴嬪綋鍓嶅皬杞﹁妭鐐规槸鍚﹀尮閰嶄氦閫氱鍒惰妭鐐�
-            boolean result = false;
-            for (String loc : locs) {
-                if (trafficControlLocs.contains(loc)) {
-                    result = true;
-                    break;
-                }
-            }
-
-            if (!result) {
-                continue;
-            }
-
-            //check path
-            String currentLocNo = shuttleProtocol.getCurrentLocNo();
-            for (String loc : locs) {
-                if (loc.equals(currentLocNo)) {
-                    continue;
-                }
-                List<NavigateNode> nodeList = navigateUtils.calc(currentLocNo, loc, NavigationMapType.getNormalWithDevice(), Utils.getShuttlePoints(shuttleNo, Utils.getLev(loc)), null);
-                if (nodeList == null) {
-                    break;
-                }
-            }
-
-            value = shuttleNo;
-            break;
-        }
-
-        return value;
-    }
-
-    //鑺傜偣骞堕泦
-    public List<List<Integer>> mergeConnectedComponents(List<List<Integer>> lists) {
-        // 1. 鏀堕泦鎵�鏈夊敮涓�鍏冪礌
-        Set<Integer> allElements = new HashSet<>();
-        for (List<Integer> list : lists) {
-            allElements.addAll(list);
-        }
-
-        // 2. 鍒濆鍖栧苟鏌ラ泦
-        Map<Integer, Integer> parent = new HashMap<>();
-        for (Integer element : allElements) {
-            parent.put(element, element);
-        }
-
-        // 3. 瀹氫箟鏌ユ壘鏍硅妭鐐圭殑鍑芥暟锛堝甫璺緞鍘嬬缉锛�
-        Function<Integer, Integer> find = x -> {
-            int root = x;
-            while (parent.get(root) != root) {
-                root = parent.get(root);
-            }
-            // 璺緞鍘嬬缉
-            int current = x;
-            while (parent.get(current) != root) {
-                int next = parent.get(current);
-                parent.put(current, root);
-                current = next;
-            }
-            return root;
-        };
-
-        // 4. 閬嶅巻姣忎釜鍒楄〃骞跺悎骞跺厓绱�
-        for (List<Integer> list : lists) {
-            if (list.isEmpty()) continue;
-            int first = list.get(0);
-            for (int i = 1; i < list.size(); i++) {
-                int a = first;
-                int b = list.get(i);
-                int rootA = find.apply(a);
-                int rootB = find.apply(b);
-                if (rootA != rootB) {
-                    parent.put(rootB, rootA); // 鍚堝苟闆嗗悎
-                }
-            }
-        }
-
-        // 5. 鎸夋牴鑺傜偣鍒嗙粍
-        Map<Integer, Set<Integer>> components = new HashMap<>();
-        for (Integer element : allElements) {
-            int root = find.apply(element);
-            components.computeIfAbsent(root, k -> new TreeSet<>()).add(element);
-        }
-
-        // 6. 杞崲涓烘湁搴忓垪琛�
-        List<List<Integer>> result = new ArrayList<>();
-        for (Set<Integer> set : components.values()) {
-            result.add(new ArrayList<>(set));
-        }
-
-        return result;
-    }
-
-    private HashMap<Integer, HashMap<String, List<Integer>>> calcNodeList() {
-        HashMap<Integer, HashMap<String, List<Integer>>> levNodesMap = new HashMap<>();
-        for (Map.Entry<String, List<NavigateNode>> entry : taskNodesMap.entrySet()) {
-            String key = entry.getKey();
-            String[] split = key.split("-");
-            Integer taskNo = Integer.parseInt(split[0]);
-            Integer shuttleNo = Integer.parseInt(split[1]);
-
-            List<NavigateNode> nodeList = entry.getValue();
-            NavigateNode node1 = nodeList.get(0);
-            int lev = node1.getZ();
-
-            HashMap<String, List<Integer>> nodeMap = new HashMap<>();
-            if(levNodesMap.containsKey(lev)) {
-                nodeMap = levNodesMap.get(lev);
-            }
-
-            for (NavigateNode node : nodeList) {
-                String locNo = Utils.getLocNo(node.getX(), node.getY(), lev);
-                List<Integer> shuttleNos = new ArrayList<>();
-                if (nodeMap.containsKey(locNo)) {
-                    shuttleNos = nodeMap.get(locNo);
-                }
-
-                if (!shuttleNos.contains(shuttleNo)) {
-                    shuttleNos.add(shuttleNo);
-                }
-                nodeMap.put(locNo, shuttleNos);
-            }
-            levNodesMap.put(lev, nodeMap);
-        }
-        this.levNodesMap = levNodesMap;
-        return levNodesMap;
-    }
-
-    @Override
-    public synchronized boolean applyTrafficControl(List<NavigateNode> totalNodeList, List<NavigateNode> nodeList, Integer shuttleNo, Integer taskNo) {
+    public synchronized boolean processApply(TrafficControlDataModel applyData) {
         ShuttleOperaUtils shuttleOperaUtils = SpringUtils.getBean(ShuttleOperaUtils.class);
         if (shuttleOperaUtils == null) {
             return false;
         }
+
+        if (applyData == null) {
+            return false;
+        }
+
+        if (applyData.getShuttleNo() == null || applyData.getTaskNo() == null || applyData.getNodeList() == null || applyData.getTotalNodeList() == null) {
+            return false;
+        }
+
+        Integer shuttleNo = applyData.getShuttleNo();
+        Integer taskNo = applyData.getTaskNo();
+        List<NavigateNode> nodeList = applyData.getNodeList();
+        List<NavigateNode> totalNodeList = applyData.getTotalNodeList();
 
         //鏇存柊浜ょ淇℃伅
         redisUtil.set(RedisKeyType.TRAFFIC_CONTROL_MAP.key, trafficControlDataList);
@@ -488,7 +121,7 @@
                     }
                 }
 
-                News.info("traffic running {},{}", shuttleNo, taskNo);
+//                News.info("traffic running {},{}", shuttleNo, taskNo);
                 return true;//宸茬粡绠″埗鍏佽鎵ц
             }
         }
@@ -561,15 +194,34 @@
         }
 
         //浜ょ鎺ユ敹
-        TrafficControlDataModel model = new TrafficControlDataModel();
-        model.setShuttleNo(shuttleNo);
-        model.setTaskNo(taskNo);
-        model.setNodeList(nodeList);
-        model.setTotalNodeList(totalNodeList);
-        trafficControlDataList.add(model);
+        trafficControlDataList.add(applyData);
 
         applyRecordsMap.remove(shuttleNo);
         News.info("receipt traffic {},{}", shuttleNo, taskNo);
+        return true;
+    }
+
+    @Override
+    public synchronized boolean applyTrafficControl(List<NavigateNode> totalNodeList, List<NavigateNode> nodeList, Integer shuttleNo, Integer taskNo) {
+        boolean add = true;
+        for (TrafficControlDataModel controlDataModel : applyList) {
+            if(controlDataModel.getShuttleNo().equals(shuttleNo)) {
+                add = false;
+                break;
+            }
+        }
+
+        if (add) {
+            TrafficControlDataModel model = new TrafficControlDataModel();
+            model.setShuttleNo(shuttleNo);
+            model.setTaskNo(taskNo);
+            model.setNodeList(nodeList);
+            model.setTotalNodeList(totalNodeList);
+            applyList.add(model);
+        }else {
+            return false;
+        }
+
         return true;
     }
 
@@ -654,6 +306,20 @@
     }
 
     @Override
+    public TrafficControlDataModel queryTrafficControl(Integer shuttleNo, Integer taskNo) {
+        //妫�娴嬭溅瀛愭槸鍚﹀瓨鍦ㄧ鍒�
+        for (int i = 0; i < trafficControlDataList.size(); i++) {
+            TrafficControlDataModel controlDataModel = trafficControlDataList.get(i);
+            if(shuttleNo.equals(controlDataModel.getShuttleNo())) {
+                if(controlDataModel.getTaskNo().equals(taskNo)) {
+                    return controlDataModel;
+                }
+            }
+        }
+        return null;
+    }
+
+    @Override
     public TrafficControlDataModel queryTrafficControl(Integer shuttleNo) {
         //妫�娴嬭溅瀛愭槸鍚﹀瓨鍦ㄧ鍒�
         for (int i = 0; i < trafficControlDataList.size(); i++) {
diff --git a/src/main/webapp/views/console.html b/src/main/webapp/views/console.html
index 93c1aa3..538a39d 100644
--- a/src/main/webapp/views/console.html
+++ b/src/main/webapp/views/console.html
@@ -358,17 +358,13 @@
 				},
 				methods: {
 					init() {
-						this.ws = new WebSocket("ws://" + window.location.host + baseUrl + "/console/websocket");
-						this.ws.onopen = this.webSocketOnOpen
-						this.ws.onerror = this.webSocketOnError
-						this.ws.onmessage = this.webSocketOnMessage
-						this.ws.onclose = this.webSocketClose
-
 						this.getMap(this.currentLev)
 						this.getSystemRunningStatus() //鑾峰彇绯荤粺杩愯鐘舵��
 						this.initLev()//鍒濆鍖栨ゼ灞備俊鎭�
 
 						this.consoleInterval = setInterval(() => {
+							this.websocketConnect()
+
 							this.getShuttleStateInfo() //鑾峰彇鍥涘悜绌挎杞︿俊鎭�
 							this.getLiftStateInfo() //鑾峰彇鎻愬崌鏈轰俊鎭�
 							this.getSiteInfo() //鑾峰彇杈撻�佺珯鐐规暟鎹�
@@ -709,10 +705,20 @@
 							}
 						}
 					},
+					websocketConnect() {
+						if (this.ws == null) {
+							this.ws = new WebSocket("ws://" + window.location.host + baseUrl + "/console/websocket");
+							this.ws.onopen = this.webSocketOnOpen
+							this.ws.onerror = this.webSocketOnError
+							this.ws.onmessage = this.webSocketOnMessage
+							this.ws.onclose = this.webSocketClose
+						}
+					},
 					webSocketOnOpen(e) {
 						console.log("open");
 					},
 					webSocketOnError(e) {
+						this.ws = null;
 						console.log(e);
 					},
 					webSocketOnMessage(e) {
@@ -730,11 +736,16 @@
 						}
 					},
 					webSocketClose(e) {
+						this.ws = null;
 						console.log("close");
 					},
 					sendWs(message) {
+						if (this.ws == null) {
+							return;
+						}
+
 						if (this.ws.readyState == WebSocket.OPEN) {
-							this.ws.send(message)
+							this.ws.send(message);
 						}
 					}
 				}
diff --git a/src/main/webapp/views/shuttleNew.html b/src/main/webapp/views/shuttleNew.html
index a1362ac..ef80807 100644
--- a/src/main/webapp/views/shuttleNew.html
+++ b/src/main/webapp/views/shuttleNew.html
@@ -202,7 +202,7 @@
                         </div>
                     </div>
                     <div class="bg-slate-700 p-4 rounded-lg">
-                        <h3 class="text-lg font-medium mb-2">璁惧缁存姢</h3>
+                        <h3 class="text-lg font-medium mb-2">璁惧鎸囦护</h3>
                         <div class="flex flex-wrap gap-2" style="display: flex;justify-content: center;">
                             <button class="btn bg-slate-600 hover:bg-slate-500" @click="shuttleOperator('palletLift')">
                                 <i class="fas fa-level-up mr-1"></i>鎵樼洏椤跺崌
@@ -406,9 +406,9 @@
         },
         methods: {
             init() {
-                this.websocketConnect();
-
                 this.consoleInterval = setInterval(() => {
+                    this.websocketConnect();
+
                     this.getShuttleStateInfo() //鑾峰彇鍥涘悜绌挎杞︿俊鎭�
                 }, 1000)
             },
@@ -594,18 +594,20 @@
                 });
             },
             websocketConnect() {
-                this.ws = new WebSocket("ws://" + window.location.host + baseUrl + "/console/websocket");
-                this.ws.onopen = this.webSocketOnOpen
-                this.ws.onerror = this.webSocketOnError
-                this.ws.onmessage = this.webSocketOnMessage
-                this.ws.onclose = this.webSocketClose
+                if (this.ws == null) {
+                    this.ws = new WebSocket("ws://" + window.location.host + baseUrl + "/console/websocket");
+                    this.ws.onopen = this.webSocketOnOpen
+                    this.ws.onerror = this.webSocketOnError
+                    this.ws.onmessage = this.webSocketOnMessage
+                    this.ws.onclose = this.webSocketClose
+                }
             },
             webSocketOnOpen(e) {
                 console.log("open");
             },
             webSocketOnError(e) {
+                this.ws = null;
                 console.log(e);
-                this.websocketConnect();
             },
             webSocketOnMessage(e) {
                 const result = JSON.parse(e.data);
@@ -614,12 +616,16 @@
                 }
             },
             webSocketClose(e) {
+                this.ws = null;
                 console.log("close");
-                this.websocketConnect();
             },
             sendWs(message) {
+                if (this.ws == null) {
+                    return;
+                }
+
                 if (this.ws.readyState == WebSocket.OPEN) {
-                    this.ws.send(message)
+                    this.ws.send(message);
                 }
             }
         }

--
Gitblit v1.9.1