From 877b2519157cea762b1e63e9c57c09614216d684 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期四, 24 七月 2025 19:27:46 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/core/action/ShuttleAction.java |  584 +++++++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 455 insertions(+), 129 deletions(-)

diff --git a/src/main/java/com/zy/core/action/ShuttleAction.java b/src/main/java/com/zy/core/action/ShuttleAction.java
index 1bfe527..393d2cb 100644
--- a/src/main/java/com/zy/core/action/ShuttleAction.java
+++ b/src/main/java/com/zy/core/action/ShuttleAction.java
@@ -13,31 +13,30 @@
 import com.zy.asrs.service.LocMastService;
 import com.zy.asrs.service.WrkMastService;
 import com.zy.asrs.utils.Utils;
-import com.zy.common.ExecuteSupport;
 import com.zy.common.model.NavigateNode;
 import com.zy.common.service.CommonService;
 import com.zy.common.utils.NavigateMapUtils;
+import com.zy.common.utils.NavigatePositionConvert;
 import com.zy.common.utils.RedisUtil;
 import com.zy.core.News;
 import com.zy.core.cache.SlaveConnection;
 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;
 import com.zy.core.model.protocol.ShuttleProtocol;
 import com.zy.core.thread.ShuttleThread;
+import com.zy.core.thread.TrafficControlThread;
 import com.zy.system.entity.Config;
 import com.zy.system.service.ConfigService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
 import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.Random;
+import java.util.*;
 
 @Component
 public class ShuttleAction {
@@ -65,6 +64,17 @@
         ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleNo);
         if (shuttleThread == null) {
             return false;
+        }
+
+        TrafficControlThread trafficControlThread = (TrafficControlThread) SlaveConnection.get(SlaveType.TrafficControl, 1);
+        if(trafficControlThread == null){
+            return false;
+        }
+
+        //娓呯┖涓嬪彂绱㈠紩
+        Set<String> keys = redisUtil.searchKeys(RedisKeyType.SHUTTLE_SEND_COMMAND_INDEX.key + shuttleNo);
+        for (String key : keys) {
+            redisUtil.del(key);
         }
 
         ShuttleRedisCommand redisCommand = new ShuttleRedisCommand();
@@ -113,139 +123,69 @@
             return false;
         }
 
-        List<ShuttleCommand> commands = redisCommand.getAssignCommand().getCommands();
-        if (commands.isEmpty()) {
+        //妫�娴嬪懡浠�
+        int checked = checkCommand(redisCommand, shuttleNo);
+        if (checked == 0) {
             return false;
         }
 
         ShuttleAssignCommand assignCommand = redisCommand.getAssignCommand();
-        int commandStep = redisCommand.getCommandStep();
-
-        Integer mode = -1;
-        if(commandStep < commands.size()) {
-            //鍙栧嚭鍛戒护
-            ShuttleCommand currentCommand = commands.get(commandStep);
-            mode = currentCommand.getMode();
-        }
-
-        //鍒ゆ柇璁惧鏄惁绌洪棽
-        Integer finalMode = mode;
-        if (!shuttleThread.isDeviceIdle(new ExecuteSupport() {
-            @Override
-            public Boolean judgement() {
-                if (ShuttleCommandModeType.CHARGE_CLOSE.id.equals(finalMode)) {//鍏抽棴鍏呯數
-                    return false;//涓嶉渶瑕佸垽鏂姸鎬�
-                }
-                return true;//闇�瑕佸垽鏂姸鎬�
-            }
-        })) {
+        List<ShuttleCommand> commands = assignCommand.getCommands();
+        if (commands.isEmpty()) {
             return false;
         }
 
-        // 瀹岀粨涓婁竴鏉″懡浠�
-        boolean updateCommand = false;
-        if (commandStep != 0) {
-            ShuttleCommand command = commands.get(commandStep - 1);
-            if (command.getMode() == ShuttleCommandModeType.MOVE.id) {
-                // 姝e父绉诲姩
-                if (command.getTargetLocNo().equals(shuttleProtocol.getCurrentLocNo())) {
-                    command.setComplete(true);
-                    updateCommand = true;
-                    //瑙i攣閿佸畾璺緞锛屼笂涓�鏉¤矾寰�
-                    List<NavigateNode> nodes = null;
-                    try {
-                        String nodesStr = objectMapper.writeValueAsString(command.getNodes());
-                        nodes = objectMapper.readValue(nodesStr, new TypeReference<List<NavigateNode>>() {
-                        });
-                    } catch (IOException e) {
-                        throw new RuntimeException(e);
-                    }
-
-                    if (nodes != null) {
-                        NavigateNode targetNode = assignCommand.getNodes().get(assignCommand.getNodes().size() - 1);//鏈�缁堣妭鐐�
-                        NavigateNode node = nodes.get(nodes.size() - 1);
-                        if (!(targetNode.getX() == node.getX() && targetNode.getY() == node.getY())) {
-                            nodes.remove(nodes.size() - 1);//鍓旈櫎灏捐妭鐐�
-                        }
-                        boolean result = navigateMapUtils.writeNavigateNodeToRedisMap(Utils.getLev(shuttleProtocol.getCurrentLocNo()), shuttleProtocol.getShuttleNo(), nodes, false);//瑙i攣璺緞
-                        if (!result) {
-                            return false;//瑙i攣澶辫触
-                        }
-                    }
-                }
-            } else if (command.getMode() == ShuttleCommandModeType.PALLET_LIFT.id) {
-                // 鎵樼洏椤跺崌
-                //鍒ゆ柇鏄惁椤跺崌鍒颁綅
-                if (shuttleProtocol.getHasLift()) {
-                    command.setComplete(true);
-                    updateCommand = true;
-//                    //鍒ゆ柇鏄惁鏈夌墿
-//                    if (shuttleProtocol.getHasPallet()) {
-//                        command.setComplete(true);
-//                    }
-                }
-            } else if (command.getMode() == ShuttleCommandModeType.PALLET_DOWN.id) {
-                // 鎵樼洏涓嬮檷鍛戒护
-                // 鍒ゆ柇鏄惁涓嬮檷鍒颁綅
-                if (!shuttleProtocol.getHasLift()) {
-                    command.setComplete(true);
-                    updateCommand = true;
-                }
-            } else if (command.getMode() == ShuttleCommandModeType.CHARGE_OPEN.id) {
-                // 鍏呯數寮�
-                //鍒ゆ柇灏忚溅鍏呯數鐘舵��
-                if (shuttleProtocol.getHasCharge()) {
-                    command.setComplete(true);
-                    updateCommand = true;
-                }
-            }else {
-                command.setComplete(true);//鍏朵粬鍛戒护榛樿璁や负瀹屾垚
-                updateCommand = true;
-            }
-
-            if(updateCommand) {
-                // 鏇存柊redis鏁版嵁
-                redisUtil.set(RedisKeyType.SHUTTLE_WORK_FLAG.key + redisCommand.getWrkNo(), JSON.toJSONString(redisCommand, SerializerFeature.DisableCircularReferenceDetect));
-            }
-
-            if (!command.getComplete()) {
-                return false;
-            }
-
-            //鍒ゆ柇鏄惁涓烘渶鍚庝竴鏉″懡浠や笖鍛戒护鎵ц瀹屾垚锛屾姏鍑虹瓑寰呯‘璁ょ姸鎬�
-            ShuttleCommand endCommand = commands.get(commands.size() - 1);
-            if (endCommand.getComplete()) {
-                News.info("鍥涘悜绌挎杞︿换鍔℃墽琛屼笅鍙戝畬鎴愮瓑寰呮墽琛岀粨鏉燂紝绌挎杞﹀彿={}锛屼换鍔℃暟鎹�={}", shuttleProtocol.getShuttleNo(), JSON.toJSON(commands));
-
-                // 绯荤粺浠诲姟
-                if (assignCommand.getAuto()) {
-                    if (!assignCommand.getCharge()) {
-                        //瀵逛富绾跨▼鎶涘嚭绛夊緟纭鐘舵�亀aiting
-                        shuttleThread.setProtocolStatus(ShuttleProtocolStatusType.WAITING);
-                    }else {
-                        shuttleThread.setProtocolStatus(ShuttleProtocolStatusType.CHARGING_WAITING);
-                    }
-                    News.info("鍥涘悜绌挎杞︿换鍔℃墽琛屼笅鍙戝畬鎴愮瓑寰呮墽琛岀粨鏉燂紝绌挎杞﹀彿={}锛屼换鍔℃暟鎹�={}", shuttleProtocol.getShuttleNo(), JSON.toJSON(command));
-
-                    // 鎵嬪姩浠诲姟
-                } else {
-                    //鎵嬪姩妯″紡涓嶆姏鍑虹瓑寰呯姸鎬侊紝鐩存帴澶嶄綅绌洪棽鐘舵��
-                    shuttleThread.setProtocolStatus(ShuttleProtocolStatusType.IDLE);
-                    //浠诲姟鍙锋竻闆�
-                    shuttleThread.setSyncTaskNo(0);
-                    //鏍囪澶嶄綅
-                    shuttleThread.setPakMk(true);
-                    News.info("鍥涘悜绌挎杞︽墜鍔ㄤ换鍔℃墽琛屽畬鎴愶紝绌挎杞﹀彿={}锛屼换鍔℃暟鎹�={}", shuttleProtocol.getShuttleNo(), JSON.toJSON(command));
-                }
-
-                //鍒犻櫎redis
-                redisUtil.del(RedisKeyType.SHUTTLE_WORK_FLAG.key + redisCommand.getWrkNo());
-                return false;//绂佹鍐嶄笅鍙戝懡浠�
-            }
+        int commandStep = redisCommand.getCommandStep();
+        if(commandStep >= commands.size()){
+            return false;
         }
 
         //鍙栧嚭鍛戒护
-        ShuttleCommand command = commands.get(commandStep);
+        ShuttleCommand command = null;
+        if (checked == 1) {
+            //闈炶繛缁寚浠わ紝闇�瑕佹娴嬩笂涓�鏉℃寚浠ゆ槸鍚﹀畬鎴�
+            if (commandStep > 0) {
+                ShuttleCommand lastCommand = commands.get(commandStep - 1);
+                if (!lastCommand.getComplete()) {
+                    return false;//鎸囦护鏈畬鎴�
+                }
+            }
+
+            command = commands.get(commandStep);
+        } else if (checked == 2) {
+            //杩炵画鎸囦护鐩存帴鍙栨暟鎹�
+            command = commands.get(commandStep);
+        }
+
+        if(command == null){
+            return false;
+        }
+
+        //绉诲姩鍛戒护锛岄攣瀹氳矾寰�
+        if (command.getMode() == ShuttleCommandModeType.MOVE.id) {
+            List<NavigateNode> nodes = JSON.parseArray(JSON.toJSONString(command.getNodes()), NavigateNode.class);
+            //鐢宠绠″埗
+            boolean apply = applyTrafficControl(commands, nodes, shuttleNo, taskNo);
+            if(!apply){
+                return false;//鐢宠澶辫触
+            }
+//            //妫�娴嬭矾寰勬槸鍚﹀啿绐�
+//            int conflict = searchShuttlePathConflict(nodes, shuttleNo);
+//            if(conflict == 2){
+//                return false;//妫�娴嬪悗鏈夊啿绐�
+//            }
+
+            if (checked == 2) {
+                nodes.remove(0);
+            }
+
+            boolean result = navigateMapUtils.writeNavigateNodeToRedisMap(Utils.getLev(command.getTargetLocNo()), shuttleNo, nodes, true);//閿佸畾璺緞
+            if (!result) {
+                News.error("{} device can't lock path!", shuttleNo);
+                shuttleThread.offerSystemMsg("{} device can't lock path!", shuttleNo);
+                return false;//璺緞閿佸畾澶辫触
+            }
+        }
 
         // 涓嬪彂鍛戒护
         CommandResponse response = write(command, shuttleNo);
@@ -273,14 +213,400 @@
         }
 
         shuttleThread.setProtocolStatus(ShuttleProtocolStatusType.WORKING);
-        commandStep++;
+
+        //瀛樺偍涓嬪彂鎸囦护绱㈠紩
+        redisUtil.set(RedisKeyType.SHUTTLE_SEND_COMMAND_INDEX.key + shuttleNo + "_" + taskNo + "_" + commandStep, commandStep);
+
+        commandStep += 1;
         //鏇存柊redis鏁版嵁
         redisCommand.setCommandStep(commandStep);
+
         //浠诲姟鏁版嵁淇濆瓨鍒皉edis
         redisUtil.set(RedisKeyType.SHUTTLE_WORK_FLAG.key + redisCommand.getWrkNo(), JSON.toJSONString(redisCommand));
         return true;
     }
 
+    /**
+     * 妫�娴嬪懡浠�
+     * 0:鏈�氳繃 1:閫氳繃 2:閫氳繃涓斿彲鎻愬墠涓嬪彂鎸囦护
+     */
+    private int checkCommand(ShuttleRedisCommand redisCommand, Integer shuttleNo) {
+        TrafficControlThread trafficControlThread = (TrafficControlThread) SlaveConnection.get(SlaveType.TrafficControl, 1);
+        if(trafficControlThread == null){
+            return 0;
+        }
+
+        ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleNo);
+        if (shuttleThread == null) {
+            return 0;
+        }
+
+        ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
+        if (shuttleProtocol == null) {
+            return 0;
+        }
+
+        int commandStep = redisCommand.getCommandStep();
+        if (commandStep == 0) {
+            return 1;//绗竴鏉″懡浠ゆ棤闇�妫�娴�
+        }
+
+        ShuttleAssignCommand assignCommand = redisCommand.getAssignCommand();
+        List<ShuttleCommand> commands = assignCommand.getCommands();
+        if (commands.isEmpty()) {
+            return 0;
+        }
+
+        //涓婁竴鏉℃寚浠�
+        String searchKey = RedisKeyType.SHUTTLE_SEND_COMMAND_INDEX.key + shuttleNo + "_" + redisCommand.getWrkNo() + "_";
+        Set<String> keys = redisUtil.searchKeys(searchKey);
+        TreeSet<Integer> treeSet = new TreeSet<>();
+        for (String key : keys) {
+            String[] split = key.split(searchKey);
+            treeSet.add(Integer.parseInt(split[1]));
+        }
+        if (treeSet.isEmpty()) {
+            return 1;
+        }
+
+        String firstKey = searchKey + treeSet.first();
+        Integer lastCommandIdx = (Integer) redisUtil.get(firstKey);
+        ShuttleCommand lastCommand = commands.get(lastCommandIdx);
+        if (!lastCommand.getComplete()) {
+            //妫�娴嬫洿鏂板懡浠ゅ畬鎴�
+            boolean checked = updateCommandComplete(lastCommandIdx, commands, shuttleNo);
+            if (checked) {
+                //鍒犻櫎绱㈠紩
+                redisUtil.del(firstKey);
+
+                // 鏇存柊redis鏁版嵁
+                redisUtil.set(RedisKeyType.SHUTTLE_WORK_FLAG.key + redisCommand.getWrkNo(), JSON.toJSONString(redisCommand, SerializerFeature.DisableCircularReferenceDetect));
+            }else {
+                //灏忚溅绉诲姩杩炵画涓嬪彂鎸囦护
+                if (assignCommand.getShuttleMoveCommandsContinuously()) {
+                    if (treeSet.size() <= 1) {
+                        if(commandStep >= commands.size()) {
+                            return 0;
+                        }
+
+                        //绉诲姩鎸囦护
+                        if(lastCommand.getMode() != ShuttleCommandModeType.MOVE.id) {
+                            return 0;
+                        }
+
+                        List<NavigateNode> nodes = lastCommand.getNodes();
+                        NavigateNode startNode = nodes.get(0);
+                        if (!startNode.getLinePartAllowGo()) {//鐩寸嚎娈甸儴鍒嗭紝鍏佽鐩存帴琛岃蛋
+                            return 0;
+                        }
+
+                        //鐩寸嚎娈垫暟鎹爣璇�
+                        Long linePartFlag = startNode.getLinePartFlag();
+
+                        //鍙栨寚浠�
+                        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;
+                        }
+
+                        if(currentStartNode.getLinePartFlag().equals(linePartFlag)) {
+                            //鏁版嵁鏍囪瘑涓�鑷�
+                            return 2;//鍏佽灏忚溅绉诲姩杩炵画涓嬪彂鎸囦护
+                        }
+
+                    }
+                }
+
+                return 0;
+            }
+        }
+
+        //鍒ゆ柇鏄惁涓烘渶鍚庝竴鏉″懡浠や笖鍛戒护鎵ц瀹屾垚锛屾姏鍑虹瓑寰呯‘璁ょ姸鎬�
+        ShuttleCommand endCommand = commands.get(commands.size() - 1);
+        if (endCommand.getComplete()) {
+            News.info("鍥涘悜绌挎杞︿换鍔℃墽琛屼笅鍙戝畬鎴愮瓑寰呮墽琛岀粨鏉燂紝绌挎杞﹀彿={}锛屼换鍔℃暟鎹�={}", shuttleProtocol.getShuttleNo(), JSON.toJSON(commands));
+
+            // 绯荤粺浠诲姟
+            if (assignCommand.getAuto()) {
+                if (!assignCommand.getCharge()) {
+                    //瀵逛富绾跨▼鎶涘嚭绛夊緟纭鐘舵�亀aiting
+                    shuttleThread.setProtocolStatus(ShuttleProtocolStatusType.WAITING);
+                } else {
+                    shuttleThread.setProtocolStatus(ShuttleProtocolStatusType.CHARGING_WAITING);
+                }
+                News.info("鍥涘悜绌挎杞︿换鍔℃墽琛屼笅鍙戝畬鎴愮瓑寰呮墽琛岀粨鏉燂紝绌挎杞﹀彿={}锛屼换鍔℃暟鎹�={}", shuttleProtocol.getShuttleNo(), JSON.toJSON(endCommand));
+
+                // 鎵嬪姩浠诲姟
+            } else {
+                //鎵嬪姩妯″紡涓嶆姏鍑虹瓑寰呯姸鎬侊紝鐩存帴澶嶄綅绌洪棽鐘舵��
+                shuttleThread.setProtocolStatus(ShuttleProtocolStatusType.IDLE);
+                //浠诲姟鍙锋竻闆�
+                shuttleThread.setSyncTaskNo(0);
+                //鏍囪澶嶄綅
+                shuttleThread.setPakMk(true);
+                News.info("鍥涘悜绌挎杞︽墜鍔ㄤ换鍔℃墽琛屽畬鎴愶紝绌挎杞﹀彿={}锛屼换鍔℃暟鎹�={}", shuttleProtocol.getShuttleNo(), JSON.toJSON(endCommand));
+            }
+
+            //鐢宠鍙栨秷绠″埗
+            trafficControlThread.cancelTrafficControl(shuttleNo, shuttleProtocol.getTaskNo());
+            //鍒犻櫎redis
+            redisUtil.del(RedisKeyType.SHUTTLE_WORK_FLAG.key + redisCommand.getWrkNo());
+            return 0;//绂佹鍐嶄笅鍙戝懡浠�
+        }
+
+        return 1;
+    }
+
+    //妫�娴嬫洿鏂板懡浠ゅ畬鎴�
+    private boolean updateCommandComplete(Integer commandIdx, List<ShuttleCommand> commands, Integer shuttleNo) {
+        ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleNo);
+        if (shuttleThread == null) {
+            return false;
+        }
+
+        ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
+        if (shuttleProtocol == null) {
+            return false;
+        }
+
+        //鍒ゆ柇璁惧鏄惁绌洪棽
+        boolean deviceIdle = shuttleThread.isDeviceIdle();
+
+        ShuttleCommand command = commands.get(commandIdx);
+        if (command.getMode() == ShuttleCommandModeType.MOVE.id) {
+            // 姝e父绉诲姩
+            List<String> targetPoints = new ArrayList<>();
+
+            //瑙i攣閿佸畾璺緞锛屼笂涓�鏉¤矾寰�
+            List<NavigateNode> nodes = null;
+            try {
+                String nodesStr = objectMapper.writeValueAsString(command.getNodes());
+                nodes = objectMapper.readValue(nodesStr, new TypeReference<List<NavigateNode>>() {
+                });
+            } catch (IOException e) {
+                throw new RuntimeException(e);
+            }
+
+            NavigateNode startNode = nodes.get(0);
+            Long linePartFlag = startNode.getLinePartFlag();
+
+            NavigateNode targetNode = nodes.get(nodes.size() - 1);
+            targetPoints.add(targetNode.getX() + "-" + targetNode.getY());
+
+            for (int i = commandIdx + 1; i < commands.size(); i++) {
+                ShuttleCommand nextCommand = commands.get(i);
+                if (nextCommand.getMode() == ShuttleCommandModeType.MOVE.id) {
+                    List<NavigateNode> nextCommandNodes = nextCommand.getNodes();
+                    NavigateNode nextStartNode = nextCommandNodes.get(0);
+                    Long nextLinePartFlag = nextStartNode.getLinePartFlag();
+                    if(nextLinePartFlag.equals(linePartFlag)) {
+                        for (NavigateNode node : nextCommandNodes) {
+                            String key = node.getX() + "-" + node.getY();
+                            if(!targetPoints.contains(key)) {
+                                targetPoints.add(key);
+                            }
+                        }
+                    }
+                }
+            }
+
+            TrafficControlThread trafficControlThread = (TrafficControlThread) SlaveConnection.get(SlaveType.TrafficControl, 1);
+            if (trafficControlThread == null) {
+                return false;
+            }
+
+            TrafficControlDataModel trafficControlDataModel = trafficControlThread.queryTrafficControl(shuttleNo);
+            if (trafficControlDataModel != null) {
+                //鏈夌鍒朵俊鎭紝杩涜妫�娴�
+                if (!trafficControlDataModel.getTaskNo().equals(shuttleProtocol.getTaskNo())) {
+                    return false;//浠诲姟涓嶄竴鑷�
+                }
+
+                //妫�娴嬫槸鍚﹀埌缁堢偣
+                List<NavigateNode> totalNodeList = trafficControlDataModel.getTotalNodeList();
+                NavigateNode trafficTargetNode = totalNodeList.get(totalNodeList.size() - 1);
+                String trafficTargetLoc = Utils.getLocNo(trafficTargetNode.getX(), trafficTargetNode.getY(), trafficTargetNode.getZ());
+
+                //鍒ゆ柇灏忚溅鏄惁鍒扮粓鐐�
+                if(shuttleProtocol.getCurrentLocNo().equals(trafficTargetLoc)) {
+                    //涓婃姤浜ょ
+                    trafficControlThread.trafficReport(command.getNodesDeepCopy(), shuttleNo, shuttleProtocol.getTaskNo());
+                }
+            }
+
+            String currentLocNo = shuttleProtocol.getCurrentLocNo();
+            if (targetPoints.contains(Utils.getRow(currentLocNo) + "-" + Utils.getBay(currentLocNo))) {
+                command.setComplete(true);
+                boolean result = navigateMapUtils.writeNavigateNodeToRedisMap(Utils.getLev(shuttleProtocol.getCurrentLocNo()), shuttleProtocol.getShuttleNo(), nodes, false);//瑙i攣璺緞
+                if (!result) {
+                    return false;//瑙i攣澶辫触
+                }
+            }else {
+                return false;
+            }
+        } else if (command.getMode() == ShuttleCommandModeType.PALLET_LIFT.id) {
+            // 鎵樼洏椤跺崌
+            if (!deviceIdle) {
+                return false;//璁惧涓嶇┖闂�
+            }
+
+            //鍒ゆ柇鏄惁椤跺崌鍒颁綅
+            if (shuttleProtocol.getHasLift()) {
+                command.setComplete(true);
+//                    //鍒ゆ柇鏄惁鏈夌墿
+//                    if (shuttleProtocol.getHasPallet()) {
+//                        command.setComplete(true);
+//                    }
+            }else {
+                return false;
+            }
+        } else if (command.getMode() == ShuttleCommandModeType.PALLET_DOWN.id) {
+            // 鎵樼洏涓嬮檷鍛戒护
+            if (!deviceIdle) {
+                return false;//璁惧涓嶇┖闂�
+            }
+
+            // 鍒ゆ柇鏄惁涓嬮檷鍒颁綅
+            if (!shuttleProtocol.getHasLift()) {
+                command.setComplete(true);
+            }else {
+                return false;
+            }
+        } else if (command.getMode() == ShuttleCommandModeType.CHARGE_OPEN.id) {
+            // 鍏呯數寮�
+            //鍒ゆ柇灏忚溅鍏呯數鐘舵��
+            if (shuttleProtocol.getHasCharge()) {
+                command.setComplete(true);
+            }else {
+                return false;
+            }
+        } else if (command.getMode() == ShuttleCommandModeType.CHARGE_CLOSE.id) {
+            //鍏抽棴鍏呯數
+            command.setComplete(true);
+        } else {
+            command.setComplete(true);//鍏朵粬鍛戒护榛樿璁や负瀹屾垚
+        }
+
+        return true;
+    }
+
+    //鐢宠绠″埗
+    public boolean applyTrafficControl(List<ShuttleCommand> commands, List<NavigateNode> nodeList, Integer shuttleNo, Integer taskNo) {
+        TrafficControlThread trafficControlThread = (TrafficControlThread) SlaveConnection.get(SlaveType.TrafficControl, 1);
+        if (trafficControlThread == null) {
+            return false;
+        }
+
+        NavigateNode startNode = nodeList.get(0);
+        Long linePartFlag = startNode.getLinePartFlag();
+
+        List<NavigateNode> totalNodeList = new ArrayList<>();
+        for (ShuttleCommand command : commands) {
+            if (command.getMode() == ShuttleCommandModeType.MOVE.id) {
+                NavigateNode node = command.getNodes().get(0);
+                Long nodeLinePartFlag = node.getLinePartFlag();
+                if (nodeLinePartFlag.equals(linePartFlag)) {
+                    List<NavigateNode> deepCopy = command.getNodesDeepCopy();
+                    if (deepCopy != null) {
+                        totalNodeList.addAll(deepCopy);
+                    }
+                }
+            }
+        }
+        return trafficControlThread.applyTrafficControl(totalNodeList, nodeList, shuttleNo, taskNo);
+    }
+
+//    /**
+//     * 鎼滅储灏忚溅璺緞鏄惁瀛樺湪鍐茬獊
+//     * 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 synchronized void demo(Integer shuttleNo) {
         ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleNo);

--
Gitblit v1.9.1