From ddeaa535350db85a54a041da6a4d74e50877d637 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期二, 04 四月 2023 14:34:02 +0800
Subject: [PATCH] 修复寻路算法路线数据4(站点)无法移动问题

---
 src/main/java/com/zy/core/thread/ShuttleThread.java |  427 ++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 356 insertions(+), 71 deletions(-)

diff --git a/src/main/java/com/zy/core/thread/ShuttleThread.java b/src/main/java/com/zy/core/thread/ShuttleThread.java
index 1e3d471..73613c9 100644
--- a/src/main/java/com/zy/core/thread/ShuttleThread.java
+++ b/src/main/java/com/zy/core/thread/ShuttleThread.java
@@ -4,32 +4,37 @@
 import HslCommunication.Core.Types.OperateResult;
 import HslCommunication.Core.Types.OperateResultExOne;
 import HslCommunication.ModBus.ModbusTcpNet;
-import HslCommunication.Profinet.Siemens.SiemensPLCS;
-import HslCommunication.Profinet.Siemens.SiemensS7Net;
 import com.alibaba.fastjson.JSON;
 import com.core.common.DateUtils;
-import com.core.common.RadixTools;
+import com.core.common.SpringUtils;
 import com.core.exception.CoolException;
+import com.zy.asrs.entity.BasShuttle;
+import com.zy.asrs.entity.BasShuttleOpt;
+import com.zy.asrs.service.BasShuttleOptService;
+import com.zy.asrs.service.BasShuttleService;
+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.core.News;
 import com.zy.core.ThreadHandler;
 import com.zy.core.cache.MessageQueue;
 import com.zy.core.cache.OutputQueue;
-import com.zy.core.cache.SlaveConnection;
-import com.zy.core.enums.ShuttleStatusType;
-import com.zy.core.enums.SlaveType;
+import com.zy.core.enums.*;
 import com.zy.core.model.ShuttleSlave;
-import com.zy.core.model.SteSlave;
 import com.zy.core.model.Task;
+import com.zy.core.model.command.ShuttleAssignCommand;
 import com.zy.core.model.command.ShuttleCommand;
-import com.zy.core.model.command.SteCommand;
 import com.zy.core.model.protocol.ShuttleProtocol;
 import lombok.Data;
 import lombok.extern.slf4j.Slf4j;
 
 import java.text.MessageFormat;
+import java.util.ArrayList;
 import java.util.Date;
-import java.util.Random;
+import java.util.HashMap;
+import java.util.List;
 
 /**
  * 鍥涘悜绌挎杞︾嚎绋�
@@ -41,10 +46,11 @@
     private ModbusTcpNet modbusTcpNet;
     private ShuttleSlave slave;
     private ShuttleProtocol shuttleProtocol;
-    private SiemensS7Net siemensS7Net;
+    private RedisUtil redisUtil;
 
-    public ShuttleThread(ShuttleSlave slave) {
+    public ShuttleThread(ShuttleSlave slave,RedisUtil redisUtil) {
         this.slave = slave;
+        this.redisUtil = redisUtil;
     }
 
     @Override
@@ -65,6 +71,10 @@
                     // 鍐欏叆鏁版嵁
                     case 2:
                         write((ShuttleCommand) task.getData());
+                        break;
+                    //涓嬪彂浠诲姟
+                    case 3:
+                        assignWork((ShuttleAssignCommand) task.getData());
                         break;
                     default:
                         break;
@@ -99,7 +109,7 @@
 
     @Override
     public void close() {
-
+        modbusTcpNet.ConnectClose();
     }
 
     private void readStatus() {
@@ -109,6 +119,7 @@
                 if (null == shuttleProtocol) {
                     shuttleProtocol = new ShuttleProtocol();
                     shuttleProtocol.setShuttleNo(slave.getId().shortValue());
+                    shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.IDLE);
                 }
 
                 //----------璇诲彇鍥涘悜绌挎杞︾姸鎬�-----------
@@ -151,17 +162,82 @@
 
                 ///璇诲彇鍥涘悜绌挎杞︾姸鎬�-end
 
-                OutputQueue.SHUTTLE.offer(MessageFormat.format("銆恵0}銆慬id:{1}] <<<<< 瀹炴椂鏁版嵁鏇存柊鎴愬姛",DateUtils.convert(new Date()), slave.getId()));
-                log.info(MessageFormat.format("銆恵0}銆慬id:{1}] <<<<< 瀹炴椂鏁版嵁鏇存柊鎴愬姛",DateUtils.convert(new Date()), slave.getId()));
+                //灏忚溅澶勪簬蹇欑鐘舵�侊紝灏嗘爣璁扮疆涓簍rue
+                if (shuttleProtocol.getBusyStatusType() == ShuttleStatusType.BUSY) {
+                    shuttleProtocol.setPakMk(true);
+                }
 
-                // 鏍规嵁瀹炴椂淇℃伅鏇存柊鏁版嵁搴�
-                //.....
+                //鍥涘悜绌挎杞︾┖闂层�佹湁浠诲姟銆佹爣璁颁负true銆佸瓨鍦ㄤ换鍔℃寚浠わ紝闇�瑕佹墽琛屼换鍔$殑涓嬩竴鏉℃寚浠�
+                if (shuttleProtocol.getBusyStatusType() == ShuttleStatusType.IDLE
+                        && shuttleProtocol.getTaskNo() != 0
+                        && shuttleProtocol.getPakMk()
+                        && shuttleProtocol.getAssignCommand() != null) {
+                    //鎵ц涓嬩竴姝ユ寚浠�
+                    executeWork(shuttleProtocol.getAssignCommand());
+                }
+
+                //灏嗗洓鍚戠┛姊溅鐘舵�佷繚瀛樿嚦鏁版嵁搴�
+                BasShuttleService shuttleService = SpringUtils.getBean(BasShuttleService.class);
+                BasShuttle basShuttle = shuttleService.selectById(shuttleProtocol.getShuttleNo());
+                if (basShuttle == null) {
+                    basShuttle = new BasShuttle();
+                    //鍥涘悜绌挎杞﹀彿
+                    basShuttle.setShuttleNo(slave.getId());
+                    shuttleService.insert(basShuttle);
+                }
+                //灏忚溅蹇欑姸鎬佷綅
+                basShuttle.setBusyStatus(shuttleProtocol.getBusyStatus().intValue());
+                //褰撳墠浜岀淮鐮�
+                basShuttle.setCurrentCode(shuttleProtocol.getCurrentCode().intValue());
+                //鐢垫睜鐢甸噺鐧惧垎姣�
+                basShuttle.setBatteryPower(shuttleProtocol.getBatteryPower().intValue());
+                //鐢垫睜娓╁害
+                basShuttle.setBatteryTemp(shuttleProtocol.getBatteryTemp().intValue());
+                //閿欒缂栧彿
+                basShuttle.setErrorCode(shuttleProtocol.getErrorCode().intValue());
+                //Plc杈撳嚭鐘舵�両O
+                basShuttle.setPlcOutputStatusIo(shuttleProtocol.getPlcOutputStatusIO().intValue());
+                //閿欒淇℃伅鐮�
+                basShuttle.setStatusErrorCode(shuttleProtocol.getStatusErrorCode().intValue());
+                //PLC杈撳叆鐘舵��
+                basShuttle.setPlcInputStatus(shuttleProtocol.getPlcInputStatus().intValue());
+                //褰撳墠鎴栬�呬箣鍓嶈鍒扮殑浜岀淮鐮佸��
+                basShuttle.setCurrentOrBeforeCode(shuttleProtocol.getCurrentOrBeforeCode().intValue());
+                //璇诲埌鐨勪簩缁寸爜X鏂瑰悜鍋忕Щ閲�
+                basShuttle.setCodeOffsetX(shuttleProtocol.getCodeOffsetX().intValue());
+                //璇诲埌鐨勪簩缁寸爜Y鏂瑰悜鍋忕Щ閲�
+                basShuttle.setCodeOffsetY(shuttleProtocol.getCodeOffsetY().intValue());
+                //褰撳墠鐨勭數鍘嬪��
+                basShuttle.setCurrentVoltage(shuttleProtocol.getCurrentVoltage().intValue());
+                //褰撳墠鐨勬ā鎷熼噺鍊�
+                basShuttle.setCurrentAnalogValue(shuttleProtocol.getCurrentAnalogValue().intValue());
+                //褰撳墠鐨勫崌闄嶄己鏈嶉�熷害
+                basShuttle.setCurrentLiftServoSpeed(shuttleProtocol.getCurrentLiftServoSpeed().intValue());
+                //褰撳墠鐨勮璧颁己鏈嶉�熷害
+                basShuttle.setCurrentMoveServoSpeed(shuttleProtocol.getCurrentMoveServoSpeed().intValue());
+                //褰撳墠鐨勫崌闄嶄己鏈嶈礋杞界巼
+                basShuttle.setCurrentLiftServoLoad(shuttleProtocol.getCurrentLiftServoLoad().intValue());
+                //褰撳墠鐨勮璧颁己鏈嶈礋杞界巼
+                basShuttle.setCurrentMoveServoLoad(shuttleProtocol.getCurrentMoveServoLoad().intValue());
+                //褰撳墠灏忚溅鐘舵�侊紙鍐呴儴鑷垜缁存姢锛�
+                basShuttle.setShuttleStatus(shuttleProtocol.getProtocolStatus());
+                //浠诲姟鍙�
+                basShuttle.setWrkNo(shuttleProtocol.getTaskNo().intValue());
+                //淇敼鏃堕棿
+                basShuttle.setUpdateTime(new Date());
+                //浣滀笟鏍囪
+                basShuttle.setPakMk(shuttleProtocol.getPakMk());
+                if (shuttleService.updateById(basShuttle)) {
+                    OutputQueue.SHUTTLE.offer(MessageFormat.format("銆恵0}銆慬id:{1}] <<<<< 瀹炴椂鏁版嵁鏇存柊鎴愬姛",DateUtils.convert(new Date()), slave.getId()));
+//                    log.info(MessageFormat.format("銆恵0}銆慬id:{1}] <<<<< 瀹炴椂鏁版嵁鏇存柊鎴愬姛",DateUtils.convert(new Date()), slave.getId()));
+                }
 
             }else {
                 OutputQueue.SHUTTLE.offer(MessageFormat.format("銆恵0}銆憑1}鍥涘悜绌挎杞lc鐘舵�佷俊鎭け璐�", DateUtils.convert(new Date()), slave.getId()));
                 throw new CoolException(MessageFormat.format( "鍥涘悜绌挎杞lc鐘舵�佷俊鎭け璐� ===>> [id:{0}] [ip:{1}] [port:{2}]", slave.getId(), slave.getIp(), slave.getPort()));
             }
         } catch (Exception e) {
+            e.printStackTrace();
             OutputQueue.SHUTTLE.offer(MessageFormat.format("銆恵0}銆戝洓鍚戠┛姊溅plc鐘舵�佷俊鎭け璐� ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort()));
             initShuttle();
         }
@@ -173,47 +249,77 @@
             return false;
         }
 
-        command.setShuttleNo(slave.getId());
+        command.setShuttleNo(slave.getId().shortValue());
         // 寮�濮嬩换鍔�
-        //...
         short[] array = new short[17];
         //鎺у埗鎸囦护瀛�
         array[0] = command.getCommandWord();
-        //鍚浜岀淮缂栧彿
-        array[1] = command.getStartCodeNum();
-        //涓棿浜岀淮缂栧彿
-        array[2] = command.getMiddleCodeNum();
-        //鐩爣浜岀淮缂栧彿
-        array[3] = command.getDistCodeNum();
+        if (command.getStartCodeNum() != null) {
+            //鍚浜岀淮缂栧彿
+            array[1] = command.getStartCodeNum();
+        }
 
-        //璧风偣鍒扮洰鏍囩偣鐨勮窛绂婚暱搴︼紝鍏堝皢int杞负byte鏁扮粍锛屽啀灏哹yte鏁扮粍杞垚涓や釜short锛屽垎鍒崰鐢�4鍜�5绌洪棿
-        short[] startToDistDistances = CommonUtils.intToShorts(command.getStartToDistDistance());
-        array[4] = startToDistDistances[0];
-        array[5] = startToDistDistances[1];
+        if (command.getMiddleCodeNum() != null) {
+            //涓棿浜岀淮缂栧彿
+            array[2] = command.getMiddleCodeNum();
+        }
 
-        //涓棿鐐瑰埌鐩爣鐐圭殑璺濈闀垮害锛屽厛灏唅nt杞负byte鏁扮粍锛屽啀灏哹yte鏁扮粍杞垚涓や釜short锛屽垎鍒崰鐢�4鍜�5绌洪棿
-        short[] middleToDistDistances = CommonUtils.intToShorts(command.getMiddleToDistDistance());
-        array[6] = middleToDistDistances[0];
-        array[7] = middleToDistDistances[1];
+        if (command.getDistCodeNum() != null) {
+            //鐩爣浜岀淮缂栧彿
+            array[3] = command.getDistCodeNum();
+        }
 
-        //灏忚溅杩愯鏂瑰悜
-        array[8] = command.getRunDirection();
-        //鎵樼洏椤跺崌
-        array[9] = command.getPalletLift();
+        if (command.getStartToDistDistance() != null) {
+            //璧风偣鍒扮洰鏍囩偣鐨勮窛绂婚暱搴︼紝鍏堝皢int杞负byte鏁扮粍锛屽啀灏哹yte鏁扮粍杞垚涓や釜short锛屽垎鍒崰鐢�4鍜�5绌洪棿
+            short[] startToDistDistances = CommonUtils.intToShorts(command.getStartToDistDistance());
+            array[4] = startToDistDistances[0];
+            array[5] = startToDistDistances[1];
+        }
 
-        //灏忚溅寮哄埗绉诲姩璺濈锛屽厛灏唅nt杞负byte鏁扮粍锛屽啀灏哹yte鏁扮粍杞垚涓や釜short锛屽垎鍒崰鐢�4鍜�5绌洪棿
-        short[] forceMoveDistances = CommonUtils.intToShorts(command.getForceMoveDistance());
-        array[10] = forceMoveDistances[0];
-        array[11] = forceMoveDistances[1];
+        if (command.getMiddleToDistDistance() != null) {
+            //涓棿鐐瑰埌鐩爣鐐圭殑璺濈闀垮害锛屽厛灏唅nt杞负byte鏁扮粍锛屽啀灏哹yte鏁扮粍杞垚涓や釜short锛屽垎鍒崰鐢�4鍜�5绌洪棿
+            short[] middleToDistDistances = CommonUtils.intToShorts(command.getMiddleToDistDistance());
+            array[6] = middleToDistDistances[0];
+            array[7] = middleToDistDistances[1];
+        }
 
-        //鍏呯數寮�鍏�
-        array[12] = command.getChargeSwitch();
-        //灏忚溅IO鎺у埗
-        array[13] = command.getIOControl();
-        //灏忚溅杩愯閫熷害
-        array[14] = command.getRunSpeed();
-        //灏忚溅闆疯揪澶囩敤
-        array[15] = command.getRadarTmp();
+        if (command.getRunDirection() != null) {
+            //灏忚溅杩愯鏂瑰悜
+            array[8] = command.getRunDirection();
+        }
+
+        if (command.getPalletLift() != null) {
+            //鎵樼洏椤跺崌
+            array[9] = command.getPalletLift();
+        }
+
+        if (command.getForceMoveDistance() != null) {
+            //灏忚溅寮哄埗绉诲姩璺濈锛屽厛灏唅nt杞负byte鏁扮粍锛屽啀灏哹yte鏁扮粍杞垚涓や釜short锛屽垎鍒崰鐢�4鍜�5绌洪棿
+            short[] forceMoveDistances = CommonUtils.intToShorts(command.getForceMoveDistance());
+            array[10] = forceMoveDistances[0];
+            array[11] = forceMoveDistances[1];
+        }
+
+        if (command.getChargeSwitch() != null) {
+            //鍏呯數寮�鍏�
+            array[12] = command.getChargeSwitch();
+        }
+
+        if (command.getIOControl() != null) {
+            //灏忚溅IO鎺у埗
+            array[13] = command.getIOControl();
+        }
+
+        if (command.getRunSpeed() != null) {
+            //灏忚溅杩愯閫熷害
+            array[14] = command.getRunSpeed();
+        }
+
+        if (command.getRadarTmp() != null) {
+            //灏忚溅闆疯揪澶囩敤
+            array[15] = command.getRadarTmp();
+        }
+
         //鎸囦护缁撴潫浣�
         array[16] = command.getCommandEnd();
 
@@ -236,9 +342,188 @@
         if (null == shuttleProtocol) {
             shuttleProtocol = new ShuttleProtocol();
         }
-//        shuttleProtocol.setShuttleNo(slave.getId().shortValue());
-//        shuttleProtocol.setBusyStatus(ShuttleStatusType.BUSY);
-//        shuttleProtocol.setCurrentCode("0");
+    }
+
+    //鍒嗛厤浠诲姟
+    private void assignWork(ShuttleAssignCommand assignCommand) throws Exception {
+        //灏嗘map瀛樺叆redis涓�
+        HashMap<String, Object> map = new HashMap<>();
+
+        if (assignCommand.getTaskMode() == ShuttleTaskModeType.PAK_IN.id.shortValue()
+                || assignCommand.getTaskMode() == ShuttleTaskModeType.PAK_OUT.id.shortValue()) {
+            //鍏ュ簱鎴栧嚭搴撴ā寮忥紝璁$畻璺緞
+            //璁$畻璺緞
+            List<NavigateNode> calc = NavigateUtils.calc(assignCommand.getSourceLocNo(), assignCommand.getLocNo(), assignCommand.getTaskMode().intValue());
+            if (calc != null) {
+                //鑾峰彇鍒嗘璺緞
+                ArrayList<ArrayList<NavigateNode>> data = NavigateUtils.getSectionPath(calc);
+                //璺緞鏁版嵁
+                map.put("path", data);
+                //璺緞娆℃暟
+                map.put("pathSize", data.size());
+            }else {
+                if (assignCommand.getTaskMode() == ShuttleTaskModeType.PAK_IN.id.shortValue() || assignCommand.getTaskMode() == ShuttleTaskModeType.PAK_OUT.id.shortValue()) {
+                    //灞炰簬鍏ュ簱鍑哄簱锛屽繀椤昏璁$畻璺緞锛屽垯鎶涘嚭寮傚父
+                    throw new Exception("鏈兘鎵惧埌杩愯璺緞");
+                }
+            }
+        }
+
+        //鍥涘悜绌挎杞﹀彿
+        map.put("shuttle_no", assignCommand.getShuttleNo());
+        //宸ヤ綔鍙�
+        map.put("wrk_no", assignCommand.getTaskNo());
+        //鍛戒护鎵ц姝ュ簭
+        map.put("commandStep", 0);
+        //鍛戒护
+        map.put("assignCommand", assignCommand);
+        shuttleProtocol.setTaskNo(assignCommand.getTaskNo());
+        shuttleProtocol.setAssignCommand(assignCommand);
+        shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.WORKING);
+        //浠诲姟鏁版嵁淇濆瓨鍒皉edis
+        redisUtil.set("wrk_no_" + assignCommand.getTaskNo(), JSON.toJSONString(map));
+        //鎵ц涓嬪彂浠诲姟
+        executeWork(assignCommand);
+    }
+
+    //鎵ц涓嬪彂鐨勬寚浠�
+    private boolean executeWork(ShuttleAssignCommand assignCommand) {
+        //璇诲彇redis鏁版嵁
+        if (assignCommand == null) {
+            return false;
+        }
+
+        //灏嗘爣璁扮疆涓篺alse(闃叉閲嶅彂)
+        shuttleProtocol.setPakMk(false);
+
+        Object o = redisUtil.get("wrk_no_" + assignCommand.getTaskNo());
+        if (o == null) {
+            return false;
+        }
+        HashMap map = JSON.parseObject(o.toString(), HashMap.class);
+        //褰撳墠姝ュ簭
+        int commandStep = Integer.parseInt(map.get("commandStep").toString());
+        //path璺緞鏁扮洰
+        int size = 0;
+        //涓嬪彂鍛戒护
+        ShuttleCommand command = new ShuttleCommand();
+        switch (assignCommand.getTaskMode()) {
+            case 1://鍏ュ簱
+            case 2://鍑哄簱
+                //褰撳墠璺緞鏁版嵁
+                Object data = map.get("path");
+                ArrayList pathList = JSON.parseObject(data.toString(), ArrayList.class);
+                //鍙栫涓�鏉¤矾寰�
+                Object o1 = pathList.get(commandStep);
+                ArrayList objectPath = JSON.parseObject(o1.toString(), ArrayList.class);
+                ArrayList<NavigateNode> path = new ArrayList<>();
+                for (Object o2 : objectPath) {
+                    NavigateNode navigateNode = JSON.parseObject(o2.toString(), NavigateNode.class);
+                    path.add(navigateNode);
+                }
+                Integer allDistance = NavigateUtils.getCurrentPathAllDistance(path);//璁$畻褰撳墠璺緞琛岃蛋鎬昏窛绂�
+
+                size = Integer.parseInt(map.get("pathSize").toString());
+                //寮�濮嬭矾寰�
+                NavigateNode startPath = path.get(0);
+                //鐩爣璺緞
+                NavigateNode endPath = path.get(path.size() - 1);
+
+                command.setCommandWord((short) 1);
+                command.setStartCodeNum(NavigatePositionConvert.xyToPosition(startPath.getX(), startPath.getY()));
+                command.setMiddleCodeNum((short) 0);
+                command.setDistCodeNum(NavigatePositionConvert.xyToPosition(endPath.getX(), endPath.getY()));
+                command.setStartToDistDistance(allDistance);
+                command.setMiddleToDistDistance(1000);
+                command.setRunDirection(ShuttleRunDirection.get(startPath.getDirection()).id);
+                command.setPalletLift((short) 1);
+                command.setForceMoveDistance(1000);
+                command.setChargeSwitch((short) 2);
+                command.setIOControl((short) 0);
+                command.setRunSpeed((short) 1000);
+                command.setRadarTmp((short) 0);
+
+                break;
+            case 3://鎵樼洏椤跺崌
+            case 4://鎵樼洏涓嬮檷
+                command.setCommandWord((short) 2);
+                command.setPalletLift(assignCommand.getTaskMode() == 3 ? (short)1 : (short)2);
+                command.setCommandEnd((short) 1);
+                break;
+            case 5://寮哄埗宸︾Щ
+            case 6://寮哄埗鍙崇Щ
+            case 7://寮哄埗涓婄Щ
+            case 8://寮哄埗涓嬬Щ
+                command.setCommandWord((short) 3);
+                command.setForceMoveDistance(1000);
+                command.setRunDirection((short) (assignCommand.getTaskMode() - 4));
+                command.setCommandEnd((short) 1);
+                break;
+            case 9://鐘舵�佸浣�
+                command.setCommandWord((short) 0);
+                //璁剧疆鍥涘悜绌挎杞︿负绌洪棽鐘舵��
+                shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.IDLE);
+                //浠诲姟鍙锋竻闆�
+                shuttleProtocol.setTaskNo((short) 0);
+                //鏍囪澶嶄綅
+                shuttleProtocol.setPakMk(true);
+                //浠诲姟鎸囦护娓呴浂
+                shuttleProtocol.setAssignCommand(null);
+                break;
+            default:
+        }
+
+        command.setCommandEnd((short) 1);
+        //涓嬪彂鍛戒护
+        if (!write(command)) {
+            News.error("鍥涘悜绌挎杞﹀懡浠や笅鍙戝け璐ワ紝绌挎杞﹀彿={}锛屼换鍔℃暟鎹�={}", shuttleProtocol.getShuttleNo(), JSON.toJSON(command));
+            return false;
+        } else {
+            News.info("鍥涘悜绌挎杞﹀懡浠や笅鍙戞垚鍔燂紝绌挎杞﹀彿={}锛屼换鍔℃暟鎹�={}", shuttleProtocol.getShuttleNo(), JSON.toJSON(command));
+
+            //鍒ゆ柇鏁版嵁鏄惁鎵ц瀹屾垚
+            if (commandStep < size - 1) {
+                //鏇存柊redis鏁版嵁
+                //姝ュ簭澧炲姞
+                commandStep++;
+                map.put("commandStep", commandStep);
+                //浠诲姟鏁版嵁淇濆瓨鍒皉edis
+                redisUtil.set("wrk_no_" + map.get("wrk_no").toString(), JSON.toJSONString(map));
+            }else {
+                //宸叉墽琛屽畬鎴�
+                //淇濆瓨鏁版嵁鍒版暟鎹簱鍋氭祦姘�
+                BasShuttleOptService shuttleOptService = SpringUtils.getBean(BasShuttleOptService.class);
+                if (shuttleOptService != null) {
+                    BasShuttleOpt opt = new BasShuttleOpt(
+                            assignCommand.getTaskNo().intValue(),
+                            assignCommand.getShuttleNo().intValue(),
+                            new Date(),
+                            ShuttleTaskModeType.get(assignCommand.getTaskMode()).desc,
+                            assignCommand.getSourceLocNo(),
+                            assignCommand.getLocNo(),
+                            null,
+                            null,
+                            null,
+                            JSON.toJSONString(assignCommand)
+                    );
+                    shuttleOptService.insert(opt);
+                }
+                //鍒犻櫎redis
+                redisUtil.del("wrk_no_" + map.get("wrk_no").toString());
+
+                if (!assignCommand.getAuto()) {
+                    //鎵嬪姩妯″紡涓嶆姏鍑虹瓑寰呯姸鎬侊紝鐩存帴澶嶄綅
+                    News.info("鍥涘悜绌挎杞︽墜鍔ㄤ换鍔℃墽琛屽畬鎴愶紝绌挎杞﹀彿={}锛屼换鍔℃暟鎹�={}", shuttleProtocol.getShuttleNo(), JSON.toJSON(command));
+                }else {
+                    //瀵逛富绾跨▼鎶涘嚭绛夊緟纭鐘舵�亀aiting
+                    shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.WAITING);
+                    News.info("鍥涘悜绌挎杞︿换鍔℃墽琛屽畬鎴愮瓑寰呯‘璁や腑锛岀┛姊溅鍙�={}锛屼换鍔℃暟鎹�={}", shuttleProtocol.getShuttleNo(), JSON.toJSON(command));
+                }
+
+            }
+
+        }
+        return true;
     }
 
     /******************************************************************************************/
@@ -249,26 +534,26 @@
         slave.setId(1);
         slave.setIp("192.168.4.24");
         slave.setPort(502);
-        ShuttleThread thread = new ShuttleThread(slave);
-        thread.connect();
-        thread.readStatus();
-
-        ShuttleCommand command = new ShuttleCommand();
-        command.setCommandWord((short) 0);
-        command.setStartCodeNum((short) 12323);
-        command.setMiddleCodeNum((short) 22323);
-        command.setDistCodeNum((short) 29999);
-        command.setStartToDistDistance(109999);
-        command.setMiddleToDistDistance(5000);
-        command.setRunDirection((short) 1);
-        command.setPalletLift((short) 2);
-        command.setForceMoveDistance(3000);
-        command.setChargeSwitch((short) 2);
-        command.setIOControl((short) 0);
-        command.setRunSpeed((short) 0);
-        command.setRadarTmp((short) 0);
-        command.setCommandEnd((short) 1);
-        thread.write(command);
+//        ShuttleThread thread = new ShuttleThread(slave);
+//        thread.connect();
+//        thread.readStatus();
+//
+//        ShuttleCommand command = new ShuttleCommand();
+//        command.setCommandWord((short) 0);
+//        command.setStartCodeNum((short) 12323);
+//        command.setMiddleCodeNum((short) 22323);
+//        command.setDistCodeNum((short) 29999);
+//        command.setStartToDistDistance(109999);
+//        command.setMiddleToDistDistance(5000);
+//        command.setRunDirection((short) 1);
+//        command.setPalletLift((short) 2);
+//        command.setForceMoveDistance(3000);
+//        command.setChargeSwitch((short) 2);
+//        command.setIOControl((short) 0);
+//        command.setRunSpeed((short) 0);
+//        command.setRadarTmp((short) 0);
+//        command.setCommandEnd((short) 1);
+//        thread.write(command);
 
     }
 }

--
Gitblit v1.9.1