From 10eb04d2444f383a647270ef05e32b59d6b1c125 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期六, 03 六月 2023 14:50:27 +0800
Subject: [PATCH] yml

---
 src/main/java/com/zy/core/thread/ShuttleThread.java |  496 +++++++++++++++++++++++++++---------------------------
 1 files changed, 250 insertions(+), 246 deletions(-)

diff --git a/src/main/java/com/zy/core/thread/ShuttleThread.java b/src/main/java/com/zy/core/thread/ShuttleThread.java
index 871654e..e6eac50 100644
--- a/src/main/java/com/zy/core/thread/ShuttleThread.java
+++ b/src/main/java/com/zy/core/thread/ShuttleThread.java
@@ -16,11 +16,9 @@
 import com.zy.asrs.service.BasShuttleOptService;
 import com.zy.asrs.service.BasShuttleService;
 import com.zy.asrs.service.LocMastService;
+import com.zy.asrs.utils.Utils;
 import com.zy.common.model.NavigateNode;
-import com.zy.common.utils.CommonUtils;
-import com.zy.common.utils.NavigatePositionConvert;
-import com.zy.common.utils.NavigateUtils;
-import com.zy.common.utils.RedisUtil;
+import com.zy.common.utils.*;
 import com.zy.core.News;
 import com.zy.core.ThreadHandler;
 import com.zy.core.cache.MessageQueue;
@@ -29,10 +27,7 @@
 import com.zy.core.enums.*;
 import com.zy.core.model.ShuttleSlave;
 import com.zy.core.model.Task;
-import com.zy.core.model.command.LiftAssignCommand;
-import com.zy.core.model.command.LiftCommand;
-import com.zy.core.model.command.ShuttleAssignCommand;
-import com.zy.core.model.command.ShuttleCommand;
+import com.zy.core.model.command.*;
 import com.zy.core.model.protocol.LiftProtocol;
 import com.zy.core.model.protocol.ShuttleProtocol;
 import lombok.Data;
@@ -41,7 +36,6 @@
 import java.text.MessageFormat;
 import java.util.ArrayList;
 import java.util.Date;
-import java.util.HashMap;
 import java.util.List;
 
 /**
@@ -182,37 +176,34 @@
 
                 if (shuttleProtocol.getErrorCode() != 0 && shuttleProtocol.getProtocolStatusType() == ShuttleProtocolStatusType.WORKING) {
                     //鍑虹幇閿欒
-                    reset(shuttleProtocol.getAssignCommand());
+                    resetAndTryFix(shuttleProtocol.getTaskNo());
                 }
 
                 if(shuttleProtocol.getProtocolStatusType() == ShuttleProtocolStatusType.FIXING
                         && shuttleProtocol.getTaskNo() != 0
-                        && shuttleProtocol.getBusyStatusType() == ShuttleStatusType.IDLE
-                        && shuttleProtocol.getAssignCommand() != null){
+                        && shuttleProtocol.getBusyStatusType() == ShuttleStatusType.IDLE){
                     //澶勪簬鏁呴殰淇鐘舵��
                     //鎵ц涓嬩竴姝ユ寚浠�
-                    executeWork(shuttleProtocol.getAssignCommand());
+                    executeWork(shuttleProtocol.getTaskNo());
                 }
 
                 //鍥涘悜绌挎杞︾┖闂层�佹湁浠诲姟銆佹爣璁颁负true銆佸瓨鍦ㄤ换鍔℃寚浠わ紝闇�瑕佹墽琛屼换鍔$殑涓嬩竴鏉℃寚浠�
                 if (shuttleProtocol.getBusyStatusType() == ShuttleStatusType.IDLE
                         && shuttleProtocol.getTaskNo() != 0
-                        && shuttleProtocol.getPakMk()
-                        && shuttleProtocol.getAssignCommand() != null) {
+                        && shuttleProtocol.getPakMk()) {
                     //鎵ц涓嬩竴姝ユ寚浠�
-                    executeWork(shuttleProtocol.getAssignCommand());
+                    executeWork(shuttleProtocol.getTaskNo());
                 }
 
                 //妫�娴嬫槸鍚︽湁鎻愬崌鏈洪攣瀹氭爣璁帮紝鏈夊垯妫�娴嬫彁鍗囨満鏄惁鍒颁綅锛屾槸鍚﹁兘璧颁笅涓�姝ュ懡浠�
                 if (shuttleProtocol.getBusyStatusType() == ShuttleStatusType.IDLE
-                        && shuttleProtocol.getTaskNo() != 0
-                        && shuttleProtocol.getAssignCommand() != null) {
-                    Object o = redisUtil.get("wrk_no_" + shuttleProtocol.getAssignCommand().getTaskNo());
+                        && shuttleProtocol.getTaskNo() != 0) {
+                    Object o = redisUtil.get("shuttle_wrk_no_" + shuttleProtocol.getTaskNo());
                     if (o != null) {
-                        HashMap map = JSON.parseObject(o.toString(), HashMap.class);
-                        if (map.containsKey("liftSecurityMk") && Boolean.parseBoolean(map.get("liftSecurityMk").toString())) {
+                        ShuttleRedisCommand redisCommand = JSON.parseObject(o.toString(), ShuttleRedisCommand.class);
+                        if (redisCommand.getLiftSecurityMk()) {
                             //鎵ц涓嬩竴姝ユ寚浠�
-                            executeWork(shuttleProtocol.getAssignCommand());
+                            executeWork(shuttleProtocol.getTaskNo());
                         }
                     }
                 }
@@ -290,6 +281,18 @@
             return false;
         }
 
+        BasShuttleService shuttleService = SpringUtils.getBean(BasShuttleService.class);
+        if (shuttleService == null) {
+            News.error("绯荤粺閿欒");
+            return false;
+        }
+
+        BasShuttle basShuttle = shuttleService.selectById(slave.getId().shortValue());
+        if (basShuttle == null) {
+            News.error("鍥涘悜绌挎杞︿笉瀛樺湪");
+            return false;
+        }
+
         command.setShuttleNo(slave.getId().shortValue());
         // 寮�濮嬩换鍔�
         short[] array = new short[17];
@@ -324,6 +327,7 @@
             array[7] = middleToDistDistances[1];
         }
 
+        array[8] = basShuttle.getRunSpeed().shortValue();//鍥涘悜绌挎杞﹁繍琛岄�熷害锛屼粠绯荤粺鏁版嵁搴撹鍑�
         if (command.getRunDirection() != null) {
             //灏忚溅杩愯鏂瑰悜
             array[8] = command.getRunDirection();
@@ -387,12 +391,11 @@
 
     //鍒嗛厤浠诲姟
     private void assignWork(ShuttleAssignCommand assignCommand) {
-        //灏嗘map瀛樺叆redis涓�
-        HashMap<String, Object> map = new HashMap<>();
         if (!assignCommand.getAuto()) {
+            List<NavigateNode> allNode = new ArrayList<>();
             List<ShuttleCommand> commands = new ArrayList<>();
-            ShuttleCommand command = new ShuttleCommand();
             LocMastService locMastService = SpringUtils.getBean(LocMastService.class);
+            NavigateMapData navigateMapData;
             switch (assignCommand.getTaskMode()) {
                 case 1://鍏ュ簱
                 case 2://鍑哄簱
@@ -400,7 +403,12 @@
                     //璁$畻灏忚溅璧风偣鍒颁腑鐐规墍闇�鍛戒护
                     LocMast currentLocMast = locMastService.queryByQrCode(shuttleProtocol.getCurrentCode().toString());
                     List<NavigateNode> firstMastResult = NavigateUtils.calc(currentLocMast.getLocNo(), assignCommand.getSourceLocNo(), ShuttleTaskModeType.PAK_IN.id);
+                    //鎵�浣跨敤鐨勮矾寰勮繘琛岄攣瀹氱鐢�
+                    navigateMapData = new NavigateMapData(Utils.getLev(currentLocMast.getLocNo()));
+                    navigateMapData.writeNavigateNodeToRedisMap(firstMastResult, true);////鎵�浣跨敤鐨勮矾寰勮繘琛岄攣瀹氱鐢�
+
                     if (firstMastResult != null) {
+                        allNode.addAll(firstMastResult);//灏嗚妭鐐硅繘琛屼繚瀛�
                         //鑾峰彇鍒嗘璺緞
                         ArrayList<ArrayList<NavigateNode>> data = NavigateUtils.getSectionPath(firstMastResult);
                         //灏嗘瘡涓�娈佃矾寰勫垎鎴恈ommand鎸囦护
@@ -411,58 +419,29 @@
                             NavigateNode endPath = nodes.get(nodes.size() - 1);
                             Integer allDistance = NavigateUtils.getCurrentPathAllDistance(nodes);//璁$畻褰撳墠璺緞琛岃蛋鎬昏窛绂�
 
-                            ShuttleCommand command1 = new ShuttleCommand();
-                            command1.setCommandWord((short) 1);
-                            command1.setStartCodeNum(NavigatePositionConvert.xyToPosition(startPath.getX(), startPath.getY(), 1));
-                            command1.setMiddleCodeNum((short) 1);
-                            command1.setDistCodeNum(NavigatePositionConvert.xyToPosition(endPath.getX(), endPath.getY(), 1));
-                            command1.setStartToDistDistance(allDistance);
-                            command1.setRunDirection(ShuttleRunDirection.get(startPath.getDirection()).id);
-                            command1.setForceMoveDistance(0);
-                            command1.setIOControl((short) 0);
-                            command1.setRunSpeed((short) 1000);
-                            command1.setCommandEnd((short) 1);
-                            commands.add(command1);
+                            //姝e父绉诲姩鍛戒护
+                            Short startCode = NavigatePositionConvert.xyToPosition(startPath.getX(), startPath.getY(), 1);//寮�濮嬩簩缁寸爜
+                            Short distCode = NavigatePositionConvert.xyToPosition(endPath.getX(), endPath.getY(), 1);//鐩爣浜岀淮鐮�
+                            commands.add(getMoveCommand(startCode,distCode,allDistance,ShuttleRunDirection.get(startPath.getDirection()).id));
                         }
 
                         //鎵樼洏椤跺崌
-                        ShuttleCommand command2 = new ShuttleCommand();
-                        command2.setCommandWord((short) 2);
-                        command2.setStartCodeNum((short) 0);
-                        command2.setMiddleCodeNum((short) 0);
-                        command2.setDistCodeNum((short) 0);
-                        command2.setStartToDistDistance(0);
-                        command2.setMiddleToDistDistance(0);
-                        command2.setRunDirection((short) 0);
-                        command2.setForceMoveDistance(0);
-                        command2.setPalletLift((short) 1);
-                        command2.setRunSpeed((short) 0);
-                        command2.setCommandEnd((short) 1);
-                        commands.add(command2);
+                        commands.add(getPalletCommand((short) 1));
                     }else {
                         //娌℃湁璁$畻鍒拌矾寰勶紝鍙兘瀛樺湪灏忚溅浣嶇疆灏辨槸璧风偣浣嶇疆
                         if (currentLocMast.getLocNo().equals(assignCommand.getSourceLocNo())) {
                             //灏忚溅浣嶇疆灏辨槸璧风偣浣嶇疆锛屾棤闇�绉诲姩锛岀洿鎺ラ《鍗�
                             //鎵樼洏椤跺崌
-                            ShuttleCommand command2 = new ShuttleCommand();
-                            command2.setCommandWord((short) 2);
-                            command2.setStartCodeNum((short) 0);
-                            command2.setMiddleCodeNum((short) 0);
-                            command2.setDistCodeNum((short) 0);
-                            command2.setStartToDistDistance(0);
-                            command2.setMiddleToDistDistance(0);
-                            command2.setRunDirection((short) 0);
-                            command2.setForceMoveDistance(0);
-                            command2.setPalletLift((short) 1);
-                            command2.setRunSpeed((short) 0);
-                            command2.setCommandEnd((short) 1);
-                            commands.add(command2);
+                            commands.add(getPalletCommand((short) 1));
                         }
                     }
 
                     //璁$畻涓偣鍒扮粓鐐硅矾寰�
                     List<NavigateNode> secMastResult = NavigateUtils.calc(assignCommand.getSourceLocNo(), assignCommand.getLocNo(), ShuttleTaskModeType.PAK_IN.id);
+                    navigateMapData.writeNavigateNodeToRedisMap(firstMastResult, true);////鎵�浣跨敤鐨勮矾寰勮繘琛岄攣瀹氱鐢�
+
                     if (secMastResult != null) {
+                        allNode.addAll(secMastResult);//灏嗚妭鐐硅繘琛屼繚瀛�
                         //鑾峰彇鍒嗘璺緞
                         ArrayList<ArrayList<NavigateNode>> data = NavigateUtils.getSectionPath(secMastResult);
                         //灏嗘瘡涓�娈佃矾寰勫垎鎴恈ommand鎸囦护
@@ -473,120 +452,51 @@
                             NavigateNode endPath = nodes.get(nodes.size() - 1);
                             Integer allDistance = NavigateUtils.getCurrentPathAllDistance(nodes);//璁$畻褰撳墠璺緞琛岃蛋鎬昏窛绂�
 
-                            ShuttleCommand command1 = new ShuttleCommand();
-                            command1.setCommandWord((short) 1);
-                            command1.setStartCodeNum(NavigatePositionConvert.xyToPosition(startPath.getX(), startPath.getY(), 1));
-                            command1.setMiddleCodeNum((short) 1);
-                            command1.setDistCodeNum(NavigatePositionConvert.xyToPosition(endPath.getX(), endPath.getY(), 1));
-                            command1.setStartToDistDistance(allDistance);
-                            command1.setRunDirection(ShuttleRunDirection.get(startPath.getDirection()).id);
-                            command1.setForceMoveDistance(0);
-                            command1.setIOControl((short) 0);
-                            command1.setRunSpeed((short) 1000);
-                            command1.setCommandEnd((short) 1);
-                            commands.add(command1);
+                            //姝e父绉诲姩鍛戒护
+                            Short startCode = NavigatePositionConvert.xyToPosition(startPath.getX(), startPath.getY(), 1);//寮�濮嬩簩缁寸爜
+                            Short distCode = NavigatePositionConvert.xyToPosition(endPath.getX(), endPath.getY(), 1);//鐩爣浜岀淮鐮�
+                            commands.add(getMoveCommand(startCode, distCode, allDistance, ShuttleRunDirection.get(startPath.getDirection()).id));
                         }
 
                         //鎵樼洏涓嬮檷
-                        ShuttleCommand command2 = new ShuttleCommand();
-                        command2.setCommandWord((short) 2);
-                        command2.setStartCodeNum((short) 0);
-                        command2.setMiddleCodeNum((short) 0);
-                        command2.setDistCodeNum((short) 0);
-                        command2.setStartToDistDistance(0);
-                        command2.setMiddleToDistDistance(0);
-                        command2.setRunDirection((short) 0);
-                        command2.setForceMoveDistance(0);
-                        command2.setPalletLift((short) 2);
-                        command2.setRunSpeed((short) 0);
-                        command2.setCommandEnd((short) 1);
-                        commands.add(command2);
+                        commands.add(getPalletCommand((short) 2));
                     }
                     break;
                 case 3://鎵樼洏椤跺崌
                 case 4://鎵樼洏涓嬮檷
-                    command.setCommandWord((short) 2);
-                    command.setStartCodeNum((short) 0);
-                    command.setMiddleCodeNum((short) 0);
-                    command.setDistCodeNum((short) 0);
-                    command.setStartToDistDistance(0);
-                    command.setMiddleToDistDistance(0);
-                    command.setRunDirection((short) 0);
-                    command.setForceMoveDistance(0);
-                    command.setPalletLift(assignCommand.getTaskMode() == 3 ? (short)1 : (short)2);
-                    command.setRunSpeed((short) 0);
-                    command.setCommandEnd((short) 1);
-                    commands.add(command);
+                    commands.add(getPalletCommand(assignCommand.getTaskMode() == 3 ? (short) 1 : (short) 2));
                     break;
                 case 5://寮哄埗宸︾Щ
                 case 6://寮哄埗鍙崇Щ
                 case 7://寮哄埗涓婄Щ
                 case 8://寮哄埗涓嬬Щ
-                    command.setCommandWord((short) 3);
-                    command.setStartCodeNum((short) 0);
-                    command.setMiddleCodeNum((short) 0);
-                    command.setDistCodeNum((short) 0);
-                    command.setStartToDistDistance(600);
-                    command.setRunDirection((short) (assignCommand.getTaskMode() - 4));
-                    command.setForceMoveDistance(600);
-                    command.setIOControl((short) 0);
-                    command.setCommandEnd((short) 1);
-                    command.setRunSpeed((short) 1000);
-                    commands.add(command);
+                    commands.add(getForceMoveCommand((short) (assignCommand.getTaskMode() - 4)));
                     break;
                 case 9://鐘舵�佸浣�
-                    command.setCommandWord((short) 6);
-                    command.setStartCodeNum((short) 0);
-                    command.setMiddleCodeNum((short) 0);
-                    command.setDistCodeNum((short) 0);
-                    command.setStartToDistDistance(0);
-                    command.setMiddleToDistDistance(0);
-                    command.setRunDirection((short) 0);
-                    command.setPalletLift((short) 0);
-                    command.setPalletLift((short) 0);
-                    command.setForceMoveDistance(0);
-                    command.setChargeSwitch((short) 0);
-                    command.setIOControl((short) 0);
-                    command.setRunSpeed((short) 0);
-                    command.setCommandEnd((short) 1);
-                    commands.add(command);
+                    ShuttleCommand reset = getResetCommand();
+                    commands.add(reset);
                     break;
                 case 10://鍚戞鏂瑰悜(宸�)瀵诲簱浣�
-                    command.setCommandWord((short) 4);
-                    command.setRunDirection((short) 1);
-                    command.setStartToDistDistance(3000);
-                    command.setRunSpeed((short) 1000);
-                    command.setCommandEnd((short) 1);
-                    commands.add(command);
+                    commands.add(getFindLocCommand((short) 1));
                     break;
                 case 11://鍚戣礋鏂瑰悜(鍙�)瀵诲簱浣�
-                    command.setCommandWord((short) 4);
-                    command.setRunDirection((short) 2);
-                    command.setStartToDistDistance(3000);
-                    command.setRunSpeed((short) 1000);
-                    command.setCommandEnd((short) 1);
-                    commands.add(command);
+                    commands.add(getFindLocCommand((short) 2));
                     break;
                 case 12://鍚戞鏂瑰悜(鍓�)瀵诲簱浣�
-                    command.setCommandWord((short) 4);
-                    command.setRunDirection((short) 4);
-                    command.setStartToDistDistance(3000);
-                    command.setRunSpeed((short) 1000);
-                    command.setCommandEnd((short) 1);
-                    commands.add(command);
+                    commands.add(getFindLocCommand((short) 4));
                     break;
                 case 13://鍚戣礋鏂瑰悜(鍚�)瀵诲簱浣�
-                    command.setCommandWord((short) 4);
-                    command.setRunDirection((short) 3);
-                    command.setStartToDistDistance(3000);
-                    command.setRunSpeed((short) 1000);
-                    command.setCommandEnd((short) 1);
-                    commands.add(command);
+                    commands.add(getFindLocCommand((short) 3));
                     break;
                 case 14://绉诲姩鍒扮洰鏍囧簱浣�
                     LocMast locMast = locMastService.queryByQrCode(shuttleProtocol.getCurrentCode().toString());
                     List<NavigateNode> result = NavigateUtils.calc(locMast.getLocNo(), assignCommand.getLocNo(), ShuttleTaskModeType.PAK_IN.id);
+                    //鎵�浣跨敤鐨勮矾寰勮繘琛岄攣瀹氱鐢�
+                    navigateMapData = new NavigateMapData(Utils.getLev(locMast.getLocNo()));
+                    navigateMapData.writeNavigateNodeToRedisMap(result, true);////鎵�浣跨敤鐨勮矾寰勮繘琛岄攣瀹氱鐢�
+
                     if (result != null) {
+                        allNode.addAll(result);//灏嗚妭鐐硅繘琛屼繚瀛�
                         //鑾峰彇鍒嗘璺緞
                         ArrayList<ArrayList<NavigateNode>> data = NavigateUtils.getSectionPath(result);
                         //灏嗘瘡涓�娈佃矾寰勫垎鎴恈ommand鎸囦护
@@ -599,71 +509,57 @@
 
                             LocMast distLocMast = locMastService.queryByLoc(assignCommand.getLocNo());
                             String qrCodeValue = distLocMast.getQrCodeValue();
-                            command.setCommandWord((short) 1);
-                            command.setStartCodeNum(shuttleProtocol.getCurrentCode());
-                            command.setMiddleCodeNum((short) 1);
-                            command.setDistCodeNum((short) Integer.parseInt(qrCodeValue));
-                            command.setStartToDistDistance(allDistance);
-                            command.setRunSpeed((short) 1000);
-                            command.setRunDirection(ShuttleRunDirection.get(startPath.getDirection()).id);
-                            command.setForceMoveDistance(0);
-                            command.setIOControl((short) 0);
-                            command.setCommandEnd((short) 1);
-                            commands.add(command);
+
+                            //姝e父绉诲姩鍛戒护
+                            commands.add(getMoveCommand(shuttleProtocol.getCurrentCode(),(short) Integer.parseInt(qrCodeValue),allDistance,ShuttleRunDirection.get(startPath.getDirection()).id));
                         }
                     }
                     break;
                 case 15://鍏呯數寮�鍏�
-                    command.setCommandWord((short) 8);
-                    command.setIOControl((short) 4);
-                    command.setCommandEnd((short) 1);
-                    commands.add(command);
+                    commands.add(getChargeSwitchCommand());
                     break;
                 default:
             }
             assignCommand.setCommands(commands);
+            assignCommand.setNodes(allNode);//褰撳墠浠诲姟鎵�鍗犵敤鐨勮妭鐐筶ist
         }
 
-        //鍥涘悜绌挎杞﹀彿
-        map.put("shuttle_no", assignCommand.getShuttleNo());
-        //宸ヤ綔鍙�
-        map.put("wrk_no", assignCommand.getTaskNo());
-        //鍛戒护鎵ц姝ュ簭
-        map.put("commandStep", 0);
-        //鍛戒护
-        map.put("assignCommand", assignCommand);
-        //鍙戠敓閿欒鏃跺皾璇曟墽琛岀殑鎸囦护锛屼紭鍏堢骇鏈�楂�
-        map.put("errorCommands", new ArrayList<ShuttleCommand>());
+        ShuttleRedisCommand redisCommand = new ShuttleRedisCommand();
+        redisCommand.setShuttleNo(assignCommand.getShuttleNo());//鍥涘悜绌挎杞﹀彿
+        redisCommand.setWrkNo(assignCommand.getTaskNo());//宸ヤ綔鍙�
+        redisCommand.setCommandStep(0);//鍛戒护鎵ц姝ュ簭
+        redisCommand.setAssignCommand(assignCommand);//鍛戒护
+        redisCommand.setErrorCommands(new ArrayList<ShuttleCommand>());//鍙戠敓閿欒鏃跺皾璇曟墽琛岀殑鎸囦护锛屼紭鍏堢骇鏈�楂�
         shuttleProtocol.setTaskNo(assignCommand.getTaskNo());
         shuttleProtocol.setAssignCommand(assignCommand);
         shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.WORKING);
         //浠诲姟鏁版嵁淇濆瓨鍒皉edis
-        redisUtil.set("wrk_no_" + assignCommand.getTaskNo(), JSON.toJSONString(map));
+        redisUtil.set("shuttle_wrk_no_" + assignCommand.getTaskNo(), JSON.toJSONString(redisCommand));
         //鎵ц涓嬪彂浠诲姟
-        executeWork(assignCommand);
+        executeWork(assignCommand.getTaskNo());
     }
 
     //鎵ц涓嬪彂鐨勬寚浠�
-    private boolean executeWork(ShuttleAssignCommand assignCommand) {
+    private boolean executeWork(Short wrkNo) {
         //璇诲彇redis鏁版嵁
-        if (assignCommand == null) {
+        if (wrkNo == null) {
             return false;
         }
 
-        Object o = redisUtil.get("wrk_no_" + assignCommand.getTaskNo());
+        Object o = redisUtil.get("shuttle_wrk_no_" + wrkNo);
         if (o == null) {
             return false;
         }
-        HashMap map = JSON.parseObject(o.toString(), HashMap.class);
+        ShuttleRedisCommand redisCommand = JSON.parseObject(o.toString(), ShuttleRedisCommand.class);
 
-        if (!checkLiftStation(assignCommand)) {//妫�娴嬫槸鍚︽湁鎻愬崌鏈虹珯鐐癸紝鏈夊垯璋冨害鎻愬崌鏈�
+        if (!checkLiftStation(wrkNo)) {//妫�娴嬫槸鍚︽湁鎻愬崌鏈虹珯鐐癸紝鏈夊垯璋冨害鎻愬崌鏈�
             return false;
         }
 
         //灏嗘爣璁扮疆涓篺alse(闃叉閲嶅彂)
         shuttleProtocol.setPakMk(false);
 
-        List<ShuttleCommand> errorCommands =  JSON.parseArray(map.get("errorCommands").toString(),ShuttleCommand.class);
+        List<ShuttleCommand> errorCommands = redisCommand.getErrorCommands();
         if (errorCommands.size() > 0) {
             //浼樺厛鎵ц璇ユ寚浠�
             ShuttleCommand errorCommand = errorCommands.get(0);//鍙栧嚭鎸囦护
@@ -675,15 +571,15 @@
                 if (shuttleProtocol.getCurrentCode().equals(errorCommand.getStartCodeNum())) {
                     //璧风偣鍜岀粓鐐瑰睘浜庡悓涓�搴撲綅锛屾棤闇�鍐嶆墽琛岀Щ鍔ㄦ搷浣�
                     errorCommands.remove(0);//绉婚櫎璇ュ懡浠�
-                    map.put("errorCommands", new ArrayList<ShuttleCommand>());
+                    redisCommand.setErrorCommands(new ArrayList<ShuttleCommand>());
                     shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.WORKING);
                     //褰撳墠姝ュ簭
-                    int commandStep = Integer.parseInt(map.get("commandStep").toString());
+                    int commandStep = redisCommand.getCommandStep();
                     //姝ュ簭鍥為��
                     commandStep--;
-                    map.put("commandStep", commandStep);
+                    redisCommand.setCommandStep(commandStep);
                     //浠诲姟鏁版嵁淇濆瓨鍒皉edis
-                    redisUtil.set("wrk_no_" + assignCommand.getTaskNo(), JSON.toJSONString(map));
+                    redisUtil.set("shuttle_wrk_no_" + wrkNo, JSON.toJSONString(redisCommand));
                     shuttleProtocol.setPakMk(true);
                     return true;
                 }else {
@@ -717,10 +613,10 @@
 
                 shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.WORKING);
                 //褰撳墠姝ュ簭
-                int commandStep = Integer.parseInt(map.get("commandStep").toString());
+                int commandStep = redisCommand.getCommandStep();
                 //姝ュ簭鍥為��
                 commandStep--;
-                map.put("commandStep", commandStep);
+                redisCommand.setCommandStep(commandStep);
             }
 
             if (!write(errorCommand)) {
@@ -729,18 +625,19 @@
             } else {
                 News.info("鍥涘悜绌挎杞﹀懡浠や笅鍙戞垚鍔燂紝绌挎杞﹀彿={}锛屼换鍔℃暟鎹�={}", shuttleProtocol.getShuttleNo(), JSON.toJSON(errorCommand));
                 errorCommands.remove(0);
-                map.put("errorCommands", errorCommands);
+                redisCommand.setErrorCommands(errorCommands);
                 //浠诲姟鏁版嵁淇濆瓨鍒皉edis
-                redisUtil.set("wrk_no_" + assignCommand.getTaskNo(), JSON.toJSONString(map));
+                redisUtil.set("shuttle_wrk_no_" + wrkNo, JSON.toJSONString(redisCommand));
                 return true;
             }
         }
 
-        List<ShuttleCommand> commands = assignCommand.getCommands();
+        List<ShuttleCommand> commands = redisCommand.getAssignCommand().getCommands();
         //褰撳墠姝ュ簭
-        int commandStep = Integer.parseInt(map.get("commandStep").toString());
+        int commandStep = redisCommand.getCommandStep();
         //path璺緞鏁扮洰
         int size = commands.size();
+        ShuttleAssignCommand assignCommand = redisCommand.getAssignCommand();
 
         //鍙栧嚭鍛戒护
         ShuttleCommand command = commands.get(commandStep);
@@ -766,9 +663,9 @@
                 //鏇存柊redis鏁版嵁
                 //姝ュ簭澧炲姞
                 commandStep++;
-                map.put("commandStep", commandStep);
+                redisCommand.setCommandStep(commandStep);
                 //浠诲姟鏁版嵁淇濆瓨鍒皉edis
-                redisUtil.set("wrk_no_" + map.get("wrk_no").toString(), JSON.toJSONString(map));
+                redisUtil.set("shuttle_wrk_no_" + redisCommand.getWrkNo(), JSON.toJSONString(redisCommand));
             }else {
                 //宸叉墽琛屽畬鎴�
                 //淇濆瓨鏁版嵁鍒版暟鎹簱鍋氭祦姘�
@@ -789,7 +686,7 @@
                     shuttleOptService.insert(opt);
                 }
 
-                if (map.containsKey("liftSecurityMk") && Boolean.parseBoolean(map.get("liftSecurityMk").toString())) {
+                if (redisCommand.getLiftSecurityMk()) {
                     //鏇鹃攣瀹氳繃鎻愬崌鏈猴紝闇�瑕佽繘琛岃В閿�
                     LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, 1);
                     LiftProtocol liftProtocol = liftThread.getLiftProtocol();
@@ -798,21 +695,22 @@
                     }
                 }
 
+                String locNo = shuttleProtocol.getLocNo() == null ? shuttleProtocol.getSourceLocNo() : shuttleProtocol.getLocNo();
+                //瑙i櫎閿佸畾鐨勫簱浣嶈矾寰�
+                NavigateMapData navigateMapData = new NavigateMapData(Utils.getLev(locNo));
+                navigateMapData.writeNavigateNodeToRedisMap(redisCommand.getAssignCommand().getNodes(), false);
+
                 //鍒犻櫎redis
-                redisUtil.del("wrk_no_" + map.get("wrk_no").toString());
+                redisUtil.del("shuttle_wrk_no_" + redisCommand.getWrkNo());
 
                 if (!assignCommand.getAuto()) {
                     //鎵嬪姩妯″紡涓嶆姏鍑虹瓑寰呯姸鎬侊紝鐩存帴澶嶄綅
-                    if (assignCommand.getTaskMode() == 9) {
-                        //璁剧疆鍥涘悜绌挎杞︿负绌洪棽鐘舵��
-                        shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.IDLE);
-                        //浠诲姟鍙锋竻闆�
-                        shuttleProtocol.setTaskNo((short) 0);
-                        //鏍囪澶嶄綅
-                        shuttleProtocol.setPakMk(true);
-                        //浠诲姟鎸囦护娓呴浂
-                        shuttleProtocol.setAssignCommand(null);
-                    }
+                    //璁剧疆鍥涘悜绌挎杞︿负绌洪棽鐘舵��
+                    shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.IDLE);
+                    //浠诲姟鍙锋竻闆�
+                    shuttleProtocol.setTaskNo((short) 0);
+                    //鏍囪澶嶄綅
+                    shuttleProtocol.setPakMk(true);
                     News.info("鍥涘悜绌挎杞︽墜鍔ㄤ换鍔℃墽琛屽畬鎴愶紝绌挎杞﹀彿={}锛屼换鍔℃暟鎹�={}", shuttleProtocol.getShuttleNo(), JSON.toJSON(command));
                 }else {
                     if (!assignCommand.getCharge()) {
@@ -833,22 +731,22 @@
     /**
      * 妫�娴嬫槸鍚︽湁鎻愬崌鏈虹珯鐐癸紝鏈夊垯璋冨害鎻愬崌鏈�
      */
-    private boolean checkLiftStation(ShuttleAssignCommand assignCommand) {
+    private boolean checkLiftStation(Short wrkNo) {
         //璇诲彇redis鏁版嵁
-        if (assignCommand == null) {
+        if (wrkNo == null) {
             return false;
         }
 
-        Object o = redisUtil.get("wrk_no_" + assignCommand.getTaskNo());
+        Object o = redisUtil.get("shuttle_wrk_no_" + wrkNo);
         if (o == null) {
             return false;
         }
-        HashMap map = JSON.parseObject(o.toString(), HashMap.class);
+        ShuttleRedisCommand redisCommand = JSON.parseObject(o.toString(), ShuttleRedisCommand.class);
         //褰撳墠姝ュ簭
-        int commandStep = Integer.parseInt(map.get("commandStep").toString());
+        int commandStep = redisCommand.getCommandStep();
 
         //妫�娴嬫槸鍚﹀瓨鍦ㄦ彁鍗囨満鍙g殑鎸囦护
-        List<ShuttleCommand> commands = assignCommand.getCommands();
+        List<ShuttleCommand> commands = redisCommand.getAssignCommand().getCommands();
         BasDevpService basDevpService = SpringUtils.getBean(BasDevpService.class);
         ArrayList<Short> qrCodeValues = new ArrayList<>();
         for (BasDevp basDevp : basDevpService.selectList(null)) {
@@ -926,9 +824,9 @@
         liftProtocol.setShuttleNo(shuttleProtocol.getShuttleNo());//璁剧疆鍥涘悜绌挎杞﹀彿
         liftProtocol.setProtocolStatus(LiftProtocolStatusType.WORKING);//璁剧疆鎻愬崌鏈虹姸鎬佷负宸ヤ綔涓�
         liftProtocol.setSecurityMk(true);//鏍囪缃负true锛岄槻姝㈠叾浠栦换鍔″崰鐢ㄥ綋鍓嶆彁鍗囨満
-        map.put("liftSecurityMk", true);//鏍囪缃负true锛岄槻姝㈠叾浠栦换鍔″崰鐢ㄥ綋鍓嶆彁鍗囨満
+        redisCommand.setLiftSecurityMk(true);//鏍囪缃负true锛岄槻姝㈠叾浠栦换鍔″崰鐢ㄥ綋鍓嶆彁鍗囨満
         //浠诲姟鏁版嵁淇濆瓨鍒皉edis
-        redisUtil.set("wrk_no_" + assignCommand.getTaskNo(), JSON.toJSONString(map));
+        redisUtil.set("shuttle_wrk_no_" + wrkNo, JSON.toJSONString(redisCommand));
 
         //鍛戒护list
         ArrayList<LiftCommand> liftCommands = new ArrayList<>();
@@ -953,21 +851,21 @@
     /**
      * 澶嶄綅骞跺皾璇曚慨澶嶉敊璇�
      */
-    private boolean reset(ShuttleAssignCommand assignCommand) {
+    private boolean resetAndTryFix(Short wrkNo) {
         //璇诲彇redis鏁版嵁
-        if (assignCommand == null) {
+        if (wrkNo == null) {
             return false;
         }
 
-        Object o = redisUtil.get("wrk_no_" + assignCommand.getTaskNo());
+        Object o = redisUtil.get("shuttle_wrk_no_" + wrkNo);
         if (o == null) {
             return false;
         }
 
-        HashMap map = JSON.parseObject(o.toString(), HashMap.class);
-        List<ShuttleCommand> commands = assignCommand.getCommands();
+        ShuttleRedisCommand redisCommand = JSON.parseObject(o.toString(), ShuttleRedisCommand.class);
+        List<ShuttleCommand> commands = redisCommand.getAssignCommand().getCommands();
         //褰撳墠姝ュ簭
-        int commandStep = Integer.parseInt(map.get("commandStep").toString());
+        int commandStep = redisCommand.getCommandStep();
         //path璺緞鏁扮洰
         int size = commands.size();
 
@@ -977,29 +875,13 @@
         ShuttleCommand command = commands.get(commandStep - 1);
 
         //澶嶄綅鍛戒护
-        ShuttleCommand resetCommand = new ShuttleCommand();
-        resetCommand.setCommandWord((short) 6);
-        resetCommand.setStartCodeNum((short) 0);
-        resetCommand.setMiddleCodeNum((short) 0);
-        resetCommand.setDistCodeNum((short) 0);
-        resetCommand.setStartToDistDistance(0);
-        resetCommand.setMiddleToDistDistance(0);
-        resetCommand.setRunDirection((short) 0);
-        resetCommand.setPalletLift((short) 0);
-        resetCommand.setPalletLift((short) 0);
-        resetCommand.setForceMoveDistance(0);
-        resetCommand.setChargeSwitch((short) 0);
-        resetCommand.setIOControl((short) 0);
-        resetCommand.setRunSpeed((short) 0);
-        resetCommand.setCommandEnd((short) 1);
+        ShuttleCommand resetCommand = getResetCommand();
         list.add(resetCommand);
 
         //杞﹁締绌洪棽锛岀瓑寰呭啓鍏ユ壘搴撲綅鍛戒护
         //鎵惧簱浣嶅懡浠�
-        ShuttleCommand searchCommand = new ShuttleCommand();
-        searchCommand.setCommandWord((short) 4);
         short direction = 1;
-        switch (command.getRunDirection()) {
+        switch (command.getRunDirection()) {//杞崲杩愯鏂瑰悜
             case 1:
                 direction = 2;
                 break;
@@ -1015,11 +897,8 @@
             default:
                 direction = 1;
         }
-
-        searchCommand.setRunDirection(direction);//杩愯鏂瑰悜
-        searchCommand.setStartToDistDistance(1200);
-        searchCommand.setRunSpeed((short) 1000);
-        searchCommand.setCommandEnd((short) 1);
+        //鎵惧簱浣嶅懡浠�
+        ShuttleCommand searchCommand = getFindLocCommand(direction, 1200, (short) 1000);
         list.add(searchCommand);
 
         //绉诲姩杞﹁締锛岄渶瑕佸湪鎵ц瀹屽鎵惧畾浣嶇偣鍚庡啀鎵ц
@@ -1028,13 +907,138 @@
         moveCommand.setStartCodeNum(command.getStartCodeNum());//瀛樺叆鐩爣搴撲綅鍙�
         list.add(moveCommand);
 
-        map.put("errorCommands", list);
+        redisCommand.setErrorCommands(list);
         //浠诲姟鏁版嵁淇濆瓨鍒皉edis
-        redisUtil.set("wrk_no_" + assignCommand.getTaskNo(), JSON.toJSONString(map));
+        redisUtil.set("shuttle_wrk_no_" + wrkNo, JSON.toJSONString(redisCommand));
         shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.FIXING);
         return true;
     }
 
+    /**
+     * 鑾峰彇鎵樼洏椤跺崌鍛戒护
+     * @param lift 1椤跺崌锛�2涓嬮檷
+     */
+    public ShuttleCommand getPalletCommand(Short lift) {
+        ShuttleCommand command = new ShuttleCommand();
+        command.setCommandWord((short) 2);
+        command.setStartCodeNum((short) 0);
+        command.setMiddleCodeNum((short) 0);
+        command.setDistCodeNum((short) 0);
+        command.setStartToDistDistance(0);
+        command.setMiddleToDistDistance(0);
+        command.setRunDirection((short) 0);
+        command.setForceMoveDistance(0);
+        command.setPalletLift(lift);
+        command.setRunSpeed((short) 0);
+        command.setCommandEnd((short) 1);
+        return command;
+    }
+
+    /**
+     * 姝e父绉诲姩鍛戒护
+     * @return
+     */
+    public ShuttleCommand getMoveCommand(Short startCodeNum, Short distCodeNum, Integer startToDistDistance, Short runDirection) {
+        ShuttleCommand command = new ShuttleCommand();
+        command.setCommandWord((short) 1);
+        command.setStartCodeNum(startCodeNum);
+        command.setMiddleCodeNum((short) 1);
+        command.setDistCodeNum(distCodeNum);
+        command.setStartToDistDistance(startToDistDistance);
+        command.setRunDirection(runDirection);
+        command.setForceMoveDistance(0);
+        command.setIOControl((short) 0);
+        command.setRunSpeed((short) 1000);
+        command.setCommandEnd((short) 1);
+        return command;
+    }
+
+    /**
+     * 寮哄埗绉诲姩鍛戒护
+     * @param direction 绉诲姩鏂瑰悜 1宸︾Щ锛�2鍙崇Щ锛�3鍓嶇Щ锛�4鍚庣Щ
+     */
+    public ShuttleCommand getForceMoveCommand(Short direction) {
+        ShuttleCommand command = new ShuttleCommand();
+        command.setCommandWord((short) 3);
+        command.setStartCodeNum((short) 0);
+        command.setMiddleCodeNum((short) 0);
+        command.setDistCodeNum((short) 0);
+        command.setStartToDistDistance(600);
+        command.setRunDirection(direction);
+        command.setForceMoveDistance(600);
+        command.setIOControl((short) 0);
+        command.setCommandEnd((short) 1);
+        command.setRunSpeed((short) 1000);
+        return command;
+    }
+
+    /**
+     * 鐘舵�佸浣嶅懡浠�
+     */
+    public ShuttleCommand getResetCommand() {
+        ShuttleCommand command = new ShuttleCommand();
+        command.setCommandWord((short) 6);
+        command.setStartCodeNum((short) 0);
+        command.setMiddleCodeNum((short) 0);
+        command.setDistCodeNum((short) 0);
+        command.setStartToDistDistance(0);
+        command.setMiddleToDistDistance(0);
+        command.setRunDirection((short) 0);
+        command.setPalletLift((short) 0);
+        command.setPalletLift((short) 0);
+        command.setForceMoveDistance(0);
+        command.setChargeSwitch((short) 0);
+        command.setIOControl((short) 0);
+        command.setRunSpeed((short) 0);
+        command.setCommandEnd((short) 1);
+        return command;
+    }
+
+    /**
+     * 鑾峰彇瀵诲簱浣嶅懡浠�
+     * @param direction 1:鍚戞鏂瑰悜(宸�)瀵诲簱浣�,2:鍚戣礋鏂瑰悜(鍙�)瀵诲簱浣�,3:鍚戣礋鏂瑰悜(鍚�)瀵诲簱浣�,4:鍚戞鏂瑰悜(鍓�)瀵诲簱浣�
+     */
+    public ShuttleCommand getFindLocCommand(Short direction, Integer startToDistance, Short runSpeed) {
+        ShuttleCommand command = new ShuttleCommand();
+        command.setCommandWord((short) 4);
+        command.setRunDirection(direction);
+        command.setStartToDistDistance(startToDistance);
+        command.setRunSpeed((short) runSpeed);
+        command.setCommandEnd((short) 1);
+        return command;
+    }
+
+    /**
+     * 鑾峰彇瀵诲簱浣嶅懡浠わ紝榛樿绉诲姩璺濈3000锛岃繍琛岄�熷害1000
+     * @param direction 1:鍚戞鏂瑰悜(宸�)瀵诲簱浣�,2:鍚戣礋鏂瑰悜(鍙�)瀵诲簱浣�,3:鍚戣礋鏂瑰悜(鍚�)瀵诲簱浣�,4:鍚戞鏂瑰悜(鍓�)瀵诲簱浣�
+     */
+    public ShuttleCommand getFindLocCommand(Short direction) {
+        return getFindLocCommand(direction, 3000, (short) 1000);
+    }
+
+    /**
+     * 鑾峰彇鍏呯數寮�鍏冲懡浠�
+     */
+    public ShuttleCommand getChargeSwitchCommand() {
+        ShuttleCommand command = new ShuttleCommand();
+        command.setCommandWord((short) 8);
+        command.setIOControl((short) 4);
+        command.setCommandEnd((short) 1);
+        return command;
+    }
+
+    /**
+     * charge锛�1=>寮�濮嬪厖鐢碉紝2=>鏂紑鍏呯數
+     */
+    public ShuttleCommand getChargeSwitchCommand(Short charge) {
+        ShuttleCommand command = new ShuttleCommand();
+        command.setCommandWord((short) 5);//鍏呯數
+        command.setShuttleNo(shuttleProtocol.getShuttleNo());
+        command.setChargeSwitch(charge);//寮�濮嬪厖鐢�
+        command.setCommandEnd((short) 1);
+        return command;
+    }
+
     /******************************************************************************************/
     /**************************************** 娴嬭瘯涓撶敤 *****************************************/
     /*****************************************************************************************/

--
Gitblit v1.9.1