From aaea873695cd27a28ca9fec7e79a34db31e7527c Mon Sep 17 00:00:00 2001
From: Junjie <540245094@qq.com>
Date: 星期三, 10 九月 2025 15:20:44 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/core/action/ShuttleAction.java |  203 ++++++++++++++++++--------------------------------
 1 files changed, 73 insertions(+), 130 deletions(-)

diff --git a/src/main/java/com/zy/core/action/ShuttleAction.java b/src/main/java/com/zy/core/action/ShuttleAction.java
index a0a88b1..d3e961f 100644
--- a/src/main/java/com/zy/core/action/ShuttleAction.java
+++ b/src/main/java/com/zy/core/action/ShuttleAction.java
@@ -119,9 +119,11 @@
             return false;
         }
 
+        News.info("[RCS Debug] Execute check command {},{}", shuttleNo, taskNo);
         //妫�娴嬪懡浠�
-        int checked = checkCommand(redisCommand, shuttleNo);
-        if (checked == 0) {
+        ShuttleCheckCommandResultType checked = checkCommand(redisCommand, shuttleNo);
+        News.info("[RCS Debug] Execute check command complete {},{}", shuttleNo, taskNo);
+        if (checked.equals(ShuttleCheckCommandResultType.FAIL)) {
             return false;
         }
 
@@ -138,7 +140,7 @@
 
         //鍙栧嚭鍛戒护
         ShuttleCommand command = null;
-        if (checked == 1) {
+        if (checked.equals(ShuttleCheckCommandResultType.SUCCESS)) {
             //闈炶繛缁寚浠わ紝闇�瑕佹娴嬩笂涓�鏉℃寚浠ゆ槸鍚﹀畬鎴�
             if (commandStep > 0) {
                 ShuttleCommand lastCommand = commands.get(commandStep - 1);
@@ -148,7 +150,7 @@
             }
 
             command = commands.get(commandStep);
-        } else if (checked == 2) {
+        } else if (checked.equals(ShuttleCheckCommandResultType.SUCCESS_GO)) {
             //杩炵画鎸囦护鐩存帴鍙栨暟鎹�
             command = commands.get(commandStep);
         }
@@ -165,20 +167,25 @@
             }
 
             List<NavigateNode> nodes = JSON.parseArray(JSON.toJSONString(command.getNodes()), NavigateNode.class);
-            //鐢宠绠″埗
-            applyTrafficControl(commands, nodes, shuttleNo, taskNo);
+
+            Object object = redisUtil.get(RedisKeyType.TRAFFIC_CONTROL_LOCK_APPLY.key + shuttleNo);
+            if (object == null) {
+                //鐢宠绠″埗
+                News.info("[RCS Debug] Execute apply control {},{}", shuttleNo, taskNo);
+                redisUtil.set(RedisKeyType.TRAFFIC_CONTROL_LOCK_APPLY.key + shuttleNo, "lock", 10);
+                applyTrafficControl(commands, nodes, shuttleNo, taskNo);
+                News.info("[RCS Debug] Execute apply control complete {},{}", shuttleNo, taskNo);
+            }
+
+            News.info("[RCS Debug] Execute query control {},{}", shuttleNo, taskNo);
             //鏌ヨ绠″埗
             boolean apply = queryTrafficControl(shuttleNo, taskNo);
+            News.info("[RCS Debug] Execute query control complete {},{}", shuttleNo, taskNo);
             if(!apply){
                 return false;//鐢宠澶辫触
             }
-//            //妫�娴嬭矾寰勬槸鍚﹀啿绐�
-//            int conflict = searchShuttlePathConflict(nodes, shuttleNo);
-//            if(conflict == 2){
-//                return false;//妫�娴嬪悗鏈夊啿绐�
-//            }
 
-            if (checked == 2) {
+            if (checked.equals(ShuttleCheckCommandResultType.SUCCESS_GO)) {
                 nodes.remove(0);
             }
 
@@ -191,8 +198,10 @@
             }
         }
 
+        News.info("[RCS Debug] Execute send command {},{}", shuttleNo, taskNo);
         // 涓嬪彂鍛戒护
         CommandResponse response = write(command, shuttleNo);
+        News.info("[RCS Debug] Execute send command complete {},{}", shuttleNo, taskNo);
 
         //淇濆瓨鍛戒护鏃ュ織
         BasShuttleOpt basShuttleOpt = new BasShuttleOpt();
@@ -231,38 +240,40 @@
      * 妫�娴嬪懡浠�
      * 0:鏈�氳繃 1:閫氳繃 2:閫氳繃涓斿彲鎻愬墠涓嬪彂鎸囦护
      */
-    private int checkCommand(ShuttleRedisCommand redisCommand, Integer shuttleNo) {
+    private ShuttleCheckCommandResultType checkCommand(ShuttleRedisCommand redisCommand, Integer shuttleNo) {
         TrafficControlThread trafficControlThread = (TrafficControlThread) SlaveConnection.get(SlaveType.TrafficControl, 1);
         if(trafficControlThread == null){
-            return 0;
+            return ShuttleCheckCommandResultType.FAIL;
         }
 
         ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleNo);
         if (shuttleThread == null) {
-            return 0;
+            return ShuttleCheckCommandResultType.FAIL;
         }
 
         ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
         if (shuttleProtocol == null) {
-            return 0;
+            return ShuttleCheckCommandResultType.FAIL;
         }
 
         int commandStep = redisCommand.getCommandStep();
         if (commandStep == 0) {
-            return 1;//绗竴鏉″懡浠ゆ棤闇�妫�娴�
+            return ShuttleCheckCommandResultType.SUCCESS;//绗竴鏉″懡浠ゆ棤闇�妫�娴�
         }
 
         ShuttleAssignCommand assignCommand = redisCommand.getAssignCommand();
         List<ShuttleCommand> commands = assignCommand.getCommands();
         if (commands.isEmpty()) {
-            return 0;
+            return ShuttleCheckCommandResultType.FAIL;
         }
 
         boolean supportContinuously = false;
         int checkIdx = commandStep - 2;
         if (checkIdx < 0) {
+            supportContinuously = true;
             checkIdx = commandStep - 1;
         }
+
         ShuttleCommand last2Command = commands.get(checkIdx);
         if(last2Command.getComplete()){
             supportContinuously = true;
@@ -280,18 +291,18 @@
                 //灏忚溅绉诲姩杩炵画涓嬪彂鎸囦护
                 if (assignCommand.getShuttleMoveCommandsContinuously()) {
                     if (!supportContinuously) {
-                        return 0;
+                        return ShuttleCheckCommandResultType.FAIL;
                     }
 
                     //绉诲姩鎸囦护
                     if(lastCommand.getMode() != ShuttleCommandModeType.MOVE.id) {
-                        return 0;
+                        return ShuttleCheckCommandResultType.FAIL;
                     }
 
                     List<NavigateNode> nodes = lastCommand.getNodes();
                     NavigateNode startNode = nodes.get(0);
                     if (!startNode.getLinePartAllowGo()) {//鐩寸嚎娈甸儴鍒嗭紝鍏佽鐩存帴琛岃蛋
-                        return 0;
+                        return ShuttleCheckCommandResultType.FAIL;
                     }
 
                     //鐩寸嚎娈垫暟鎹爣璇�
@@ -301,23 +312,23 @@
                         //鍙栨寚浠�
                         ShuttleCommand currentCommand = commands.get(commandStep);
                         if(currentCommand.getMode() != ShuttleCommandModeType.MOVE.id) {
-                            return 0;
+                            return ShuttleCheckCommandResultType.FAIL;
                         }
 
                         List<NavigateNode> currentNodes = currentCommand.getNodes();
                         NavigateNode currentStartNode = currentNodes.get(0);
                         if(!currentStartNode.getLinePartAllowGo()) {//鐩寸嚎娈甸儴鍒嗭紝鍏佽鐩存帴琛岃蛋
-                            return 0;
+                            return ShuttleCheckCommandResultType.FAIL;
                         }
 
                         if(currentStartNode.getLinePartFlag().equals(linePartFlag)) {
                             //鏁版嵁鏍囪瘑涓�鑷�
-                            return 2;//鍏佽灏忚溅绉诲姩杩炵画涓嬪彂鎸囦护
+                            return ShuttleCheckCommandResultType.SUCCESS_GO;//鍏佽灏忚溅绉诲姩杩炵画涓嬪彂鎸囦护
                         }
                     }
                 }
 
-                return 0;
+                return ShuttleCheckCommandResultType.FAIL;
             }
         }
 
@@ -328,16 +339,24 @@
 
             // 绯荤粺浠诲姟
             if (assignCommand.getAuto()) {
-                if (!assignCommand.getCharge()) {
-                    //瀵逛富绾跨▼鎶涘嚭绛夊緟纭鐘舵�亀aiting
-                    shuttleThread.setProtocolStatus(ShuttleProtocolStatusType.WAITING);
-                } else {
-                    shuttleThread.setProtocolStatus(ShuttleProtocolStatusType.CHARGING_WAITING);
+                if (assignCommand.getTaskMode() == ShuttleTaskModeType.UPDATE_LOCATION.id) {//鏇存柊鍧愭爣鏃犻渶绛夊緟纭
+                    //鐩存帴澶嶄綅绌洪棽鐘舵��
+                    shuttleThread.setProtocolStatus(ShuttleProtocolStatusType.IDLE);
+                    //浠诲姟鍙锋竻闆�
+                    shuttleThread.setSyncTaskNo(0);
+                    //鏍囪澶嶄綅
+                    shuttleThread.setPakMk(true);
+                    News.info("鍥涘悜绌挎杞︽洿鏂板潗鏍囦换鍔℃墽琛屽畬鎴愶紝绌挎杞﹀彿={}锛屼换鍔℃暟鎹�={}", shuttleProtocol.getShuttleNo(), JSON.toJSON(endCommand));
+                }else {
+                    if (!assignCommand.getCharge()) {
+                        //瀵逛富绾跨▼鎶涘嚭绛夊緟纭鐘舵�亀aiting
+                        shuttleThread.setProtocolStatus(ShuttleProtocolStatusType.WAITING);
+                    } else {
+                        shuttleThread.setProtocolStatus(ShuttleProtocolStatusType.CHARGING_WAITING);
+                    }
+                    News.info("鍥涘悜绌挎杞︿换鍔℃墽琛屼笅鍙戝畬鎴愮瓑寰呮墽琛岀粨鏉燂紝绌挎杞﹀彿={}锛屼换鍔℃暟鎹�={}", shuttleProtocol.getShuttleNo(), JSON.toJSON(endCommand));
                 }
-                News.info("鍥涘悜绌挎杞︿换鍔℃墽琛屼笅鍙戝畬鎴愮瓑寰呮墽琛岀粨鏉燂紝绌挎杞﹀彿={}锛屼换鍔℃暟鎹�={}", shuttleProtocol.getShuttleNo(), JSON.toJSON(endCommand));
-
-                // 鎵嬪姩浠诲姟
-            } else {
+            } else {// 鎵嬪姩浠诲姟
                 //鎵嬪姩妯″紡涓嶆姏鍑虹瓑寰呯姸鎬侊紝鐩存帴澶嶄綅绌洪棽鐘舵��
                 shuttleThread.setProtocolStatus(ShuttleProtocolStatusType.IDLE);
                 //浠诲姟鍙锋竻闆�
@@ -348,13 +367,14 @@
             }
 
             //鐢宠鍙栨秷绠″埗
-            trafficControlThread.cancelTrafficControl(shuttleNo, shuttleProtocol.getTaskNo());
+            cancelTrafficControl(shuttleNo, shuttleProtocol.getTaskNo());
+
             //鍒犻櫎redis
             redisUtil.del(RedisKeyType.SHUTTLE_WORK_FLAG.key + redisCommand.getWrkNo());
-            return 0;//绂佹鍐嶄笅鍙戝懡浠�
+            return ShuttleCheckCommandResultType.FAIL;//绂佹鍐嶄笅鍙戝懡浠�
         }
 
-        return 1;
+        return ShuttleCheckCommandResultType.SUCCESS;
     }
 
     //妫�娴嬫洿鏂板懡浠ゅ畬鎴�
@@ -415,7 +435,9 @@
                 return false;
             }
             //涓婃姤浜ょ
+            News.info("[RCS Debug] Execute check command report traffic {},{}", shuttleNo, shuttleProtocol.getTaskNo());
             trafficControlThread.trafficReport(command.getNodesDeepCopy(), shuttleNo, shuttleProtocol.getTaskNo());
+            News.info("[RCS Debug] Execute check command report traffic complete {},{}", shuttleNo, shuttleProtocol.getTaskNo());
 
             String currentLocNo = shuttleProtocol.getCurrentLocNo();
             if (currentLocNo == null) {
@@ -497,103 +519,20 @@
 
     //鏌ヨ鏄惁鐢宠绠″埗鎴愬姛
     public boolean queryTrafficControl(Integer shuttleNo, Integer taskNo) {
-        TrafficControlThread trafficControlThread = (TrafficControlThread) SlaveConnection.get(SlaveType.TrafficControl, 1);
-        if (trafficControlThread == null) {
+        Object object = redisUtil.get(RedisKeyType.TRAFFIC_CONTROL_SUCCESS_APPLY.key + shuttleNo + "_" + taskNo);
+        if (object == null) {
             return false;
         }
-
-        TrafficControlDataModel trafficControlDataModel = trafficControlThread.queryTrafficControl(shuttleNo, taskNo);
-        if (trafficControlDataModel == null) {
-            return false;
-        }
-
         return true;
     }
 
-//    /**
-//     * 鎼滅储灏忚溅璺緞鏄惁瀛樺湪鍐茬獊
-//     * 0:鏈娴� 1:妫�娴嬫棤鍐茬獊 2:妫�娴嬫湁鍐茬獊
-//     */
-//    public int searchShuttlePathConflict(List<NavigateNode> nodeList, Integer shuttleNo) {
-//        ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleNo);
-//        if (shuttleThread == null) {
-//            return 0;
-//        }
-//
-//        ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
-//        if (shuttleProtocol == null) {
-//            return 0;
-//        }
-//
-//        int lev = Utils.getLev(shuttleProtocol.getCurrentLocNo());
-//
-//        TrafficControlThread trafficControlThread = (TrafficControlThread) SlaveConnection.get(SlaveType.TrafficControl, 1);
-//        if (trafficControlThread == null) {
-//            return 2;
-//        }
-//        HashMap<String, List<Integer>> nodeMap = trafficControlThread.getNodesMapByLev(lev);
-//        if (nodeMap == null || nodeMap.isEmpty()) {
-//            return 2;
-//        }
-//
-//        List<String> conflictLocList = new ArrayList<>();
-//        for (NavigateNode node : nodeList) {
-//            String locNo = Utils.getLocNo(node.getX(), node.getY(), lev);
-//            if(!nodeMap.containsKey(locNo)) {
-//                return 2;
-//            }
-//
-//            List<Integer> shuttleNos = nodeMap.get(locNo);
-//            if (shuttleNos.size() > 1) {
-//                //璺緞瀛樺湪澶氳溅锛屽啿绐�
-//                conflictLocList.add(locNo);
-//            }
-//        }
-//
-//        if (conflictLocList.isEmpty()) {
-//            //鏃犲啿绐侊紝瑙i櫎浜ら�氱鍒�
-//            shuttleThread.setTrafficControl(false, null);
-//            return 1;//妫�娴嬪悗鏃犲啿绐�
-//        }
-//
-//        //璺緞瀛樺湪鍐茬獊锛屾娴嬪彲鎵ц杞﹁締鏄惁涓哄綋鍓嶅皬杞�
-//        //涓婃姤灏忚溅鐘舵��-浜ら�氱鍒朵腑
-//        shuttleThread.setTrafficControl(true, nodeList);
-//
-//        HashMap<String, Integer> deviceMap = trafficControlThread.getDeviceMap();
-//        if(deviceMap == null) {
-//            return 2;
-//        }
-//
-//        boolean detected = false;
-////            for (Map.Entry<String, Integer> entry : deviceMap.entrySet()) {
-////                List<String> mainList = JSON.parseArray(entry.getKey(), String.class);
-////                Integer device = entry.getValue();
-////                if(result) {
-////                    //鍒ゆ柇绠″埗杞﹁締鏄惁鍖归厤
-////                    if(shuttleNo.equals(device)) {
-////                        detected = true;
-////                        break;
-////                    }
-////                }
-////            }
-//
-//        for (Map.Entry<String, Integer> entry : deviceMap.entrySet()) {
-//            String key = entry.getKey();
-//            Integer value = entry.getValue();
-//            if(shuttleNo.equals(value)) {
-//                //鍒ゆ柇绠″埗杞﹁締鏄惁鍖归厤
-//                detected = true;
-//                break;
-//            }
-//        }
-//
-//        if (detected) {
-//            return 1;//妫�娴嬪悗鏃犲啿绐侊紝浜ら�氱鍒跺凡鍏佽姝ゅ皬杞﹁繍琛�
-//        }
-//
-//        return 2;//妫�娴嬪悗鏈夊啿绐�
-//    }
+    public boolean cancelTrafficControl(Integer shuttleNo, Integer taskNo) {
+        TrafficControlDataModel model = new TrafficControlDataModel();
+        model.setShuttleNo(shuttleNo);
+        model.setTaskNo(taskNo);
+        redisUtil.set(RedisKeyType.TRAFFIC_CONTROL_CANCEL_LIST.key + shuttleNo + "_" + taskNo, model);
+        return true;
+    }
 
     //婕旂ず妯″紡
     public synchronized void demo(Integer shuttleNo) {
@@ -766,6 +705,10 @@
         } catch (Exception e) {
             e.printStackTrace();
         }
+    }
+
+    public synchronized boolean clearPath(Integer shuttleNo) {
+        return navigateMapUtils.clearPath(shuttleNo);
     }
 
 //    //璺戝簱绋嬪簭
@@ -1137,7 +1080,7 @@
 //        }
 //    }
 
-    private synchronized CommandResponse write(ShuttleCommand command, Integer shuttleNo) {
+    private CommandResponse write(ShuttleCommand command, Integer shuttleNo) {
         CommandResponse response = new CommandResponse(false);
         if (null == command) {
             News.error("鍥涘悜绌挎杞﹀啓鍏ュ懡浠や负绌�");

--
Gitblit v1.9.1