From d835d1b51f832889929cdf69010034a30ef44d02 Mon Sep 17 00:00:00 2001
From: Junjie <xjj@123>
Date: 星期四, 17 十月 2024 13:57:29 +0800
Subject: [PATCH] #

---
 zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/action/ShuttleAction.java |  426 ++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 326 insertions(+), 100 deletions(-)

diff --git a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/action/ShuttleAction.java b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/action/ShuttleAction.java
index 1f1c557..6bcfefc 100644
--- a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/action/ShuttleAction.java
+++ b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/action/ShuttleAction.java
@@ -1,8 +1,10 @@
 package com.zy.asrs.wcs.core.action;
 
 import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.serializer.SerializerFeature;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.core.type.TypeReference;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.zy.asrs.wcs.common.ExecuteSupport;
 import com.zy.asrs.wcs.core.entity.Loc;
@@ -17,24 +19,24 @@
 import com.zy.asrs.wcs.core.model.enums.ShuttleTaskModeType;
 import com.zy.asrs.wcs.core.service.BasShuttleService;
 import com.zy.asrs.wcs.core.service.LocService;
-import com.zy.asrs.wcs.core.utils.NavigateMapUtils;
-import com.zy.asrs.wcs.core.utils.RedisUtil;
-import com.zy.asrs.wcs.core.utils.ShuttleDispatcher;
-import com.zy.asrs.wcs.core.utils.Utils;
+import com.zy.asrs.wcs.core.utils.*;
 import com.zy.asrs.wcs.rcs.News;
 import com.zy.asrs.wcs.rcs.cache.SlaveConnection;
 import com.zy.asrs.wcs.rcs.constant.DeviceRedisConstant;
+import com.zy.asrs.wcs.rcs.entity.BasShuttleOpt;
 import com.zy.asrs.wcs.rcs.entity.Device;
+import com.zy.asrs.wcs.rcs.model.CommandResponse;
 import com.zy.asrs.wcs.rcs.model.enums.ShuttleProtocolStatusType;
 import com.zy.asrs.wcs.rcs.model.enums.SlaveType;
 import com.zy.asrs.wcs.rcs.model.protocol.ShuttleProtocol;
+import com.zy.asrs.wcs.rcs.service.BasShuttleOptService;
 import com.zy.asrs.wcs.rcs.thread.ShuttleThread;
+import com.zy.asrs.wcs.system.entity.Dict;
+import com.zy.asrs.wcs.system.service.DictService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Objects;
+import java.util.*;
 
 @Component
 public class ShuttleAction {
@@ -51,6 +53,12 @@
     private ShuttleDispatcher shuttleDispatcher;
     @Autowired
     private ObjectMapper objectMapper;
+    @Autowired
+    private DictService dictService;
+    @Autowired
+    private ConveyorDispatcher conveyorDispatcher;
+    @Autowired
+    private BasShuttleOptService basShuttleOptService;
 
     public synchronized boolean assignWork(Device device, ShuttleAssignCommand assignCommand) {
         ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, device.getId().intValue());
@@ -70,13 +78,14 @@
         redisCommand.setCommandStep(0);//鍛戒护鎵ц姝ュ簭
         redisCommand.setAssignCommand(assignCommand);//鍛戒护
         //浠诲姟鏁版嵁淇濆瓨鍒皉edis
-        if (redisUtil.set(DeviceRedisConstant.SHUTTLE_WORK_FLAG + assignCommand.getTaskNo(), JSON.toJSONString(redisCommand))) {
+        if (redisUtil.set(DeviceRedisConstant.SHUTTLE_WORK_FLAG + assignCommand.getTaskNo(), JSON.toJSONString(redisCommand, SerializerFeature.DisableCircularReferenceDetect))) {
             if (assignCommand.getTaskMode() == ShuttleTaskModeType.PAK_IN.id
                     || assignCommand.getTaskMode() == ShuttleTaskModeType.PAK_OUT.id
                     || assignCommand.getTaskMode() == ShuttleTaskModeType.MOVE_LOC_NO.id
                     || assignCommand.getTaskMode() == ShuttleTaskModeType.SHUTTLE_MOVE_LOC_NO.id) {
                 //涓嬪彂琛岄┒璺緞
-                boolean result = shuttleThread.movePath(assignCommand.getNodes(), assignCommand.getDeviceTaskNo());
+                CommandResponse response = shuttleThread.movePath(assignCommand.getNodes(), assignCommand.getDeviceTaskNo());
+                Boolean result = response.getResult();
                 if (!result) {
                     return false;
                 }
@@ -127,15 +136,46 @@
         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)) {//鍏抽棴鍏呯數motion
+                    return false;//涓嶉渶瑕佸垽鏂姸鎬�
+                }
+                return true;//闇�瑕佸垽鏂姸鎬�
+            }
+        })) {
+            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 = JSON.parseArray(JSON.toJSONString(command.getNodes()), NavigateNode.class);//杩涜娣卞害copy
+                    List<NavigateNode> nodes = null;
+                    try {
+                        String nodesStr = objectMapper.writeValueAsString(command.getNodes());
+                        nodes = objectMapper.readValue(nodesStr, new TypeReference<List<NavigateNode>>() {
+                        });
+                    } catch (JsonProcessingException e) {
+                        throw new RuntimeException(e);
+                    }
+
                     if (nodes != null) {
                         NavigateNode targetNode = assignCommand.getNodes().get(assignCommand.getNodes().size() - 1);//鏈�缁堣妭鐐�
                         NavigateNode node = nodes.get(nodes.size() - 1);
@@ -153,6 +193,7 @@
                 //鍒ゆ柇鏄惁椤跺崌鍒颁綅
                 if (shuttleProtocol.getHasLift()) {
                     command.setComplete(true);
+                    updateCommand = true;
 //                    //鍒ゆ柇鏄惁鏈夌墿
 //                    if (shuttleProtocol.getHasPallet()) {
 //                        command.setComplete(true);
@@ -163,19 +204,24 @@
                 // 鍒ゆ柇鏄惁涓嬮檷鍒颁綅
                 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;
             }
 
-            // 鏇存柊redis鏁版嵁
-            redisUtil.set(DeviceRedisConstant.SHUTTLE_WORK_FLAG + redisCommand.getTaskNo(), JSON.toJSONString(redisCommand));
+            if(updateCommand) {
+                // 鏇存柊redis鏁版嵁
+                redisUtil.set(DeviceRedisConstant.SHUTTLE_WORK_FLAG + redisCommand.getTaskNo(), JSON.toJSONString(redisCommand, SerializerFeature.DisableCircularReferenceDetect));
+            }
 
             if (!command.getComplete()) {
                 return false;
@@ -216,22 +262,29 @@
         //鍙栧嚭鍛戒护
         ShuttleCommand command = commands.get(commandStep);
 
-        Integer mode = command.getMode();
-        //鍒ゆ柇璁惧鏄惁绌洪棽
-        if (!shuttleThread.isDeviceIdle(new ExecuteSupport() {
-            @Override
-            public Boolean judgement() {
-                if (ShuttleCommandModeType.CHARGE_CLOSE.id.equals(mode)) {//鍏抽棴鍏呯數motion
-                    return false;//涓嶉渶瑕佸垽鏂姸鎬�
-                }
-                return true;//闇�瑕佸垽鏂姸鎬�
-            }
-        })) {
-            return false;
-        }
-
         // 涓嬪彂鍛戒护
-        if (!write(command, device)) {
+        CommandResponse response = write(command, device);
+
+        //淇濆瓨鍛戒护鏃ュ織
+        BasShuttleOpt basShuttleOpt = new BasShuttleOpt();
+        basShuttleOpt.setTaskNo(redisCommand.getTaskNo());
+        basShuttleOpt.setShuttleNo(Integer.parseInt(device.getDeviceNo()));
+
+        basShuttleOpt.setMode(ShuttleCommandModeType.get(command.getMode()).desc);
+        basShuttleOpt.setSourceLocNo(assignCommand.getSourceLocNo());
+        basShuttleOpt.setDistLocNo(assignCommand.getLocNo());
+        basShuttleOpt.setCommand(JSON.toJSONString(command));
+        basShuttleOpt.setSystemStatus(JSON.toJSONString(shuttleProtocol));
+        basShuttleOpt.setDeviceId(device.getId());
+        basShuttleOpt.setDeviceWrk(String.valueOf(command.getTaskNo()));
+        basShuttleOpt.setResponse(response.getMessage());//鑾峰彇鍝嶅簲
+        basShuttleOpt.setSendTime(new Date());//鎸囦护涓嬪彂鏃堕棿
+        basShuttleOpt.setSend(response.getResult() ? 1 : 0);
+        basShuttleOpt.setHostId(device.getHostId());
+        //淇濆瓨鍛戒护娴佹按
+        basShuttleOptService.save(basShuttleOpt);
+
+        if (!response.getResult()) {
             News.error("鍥涘悜绌挎杞﹀懡浠や笅鍙戝け璐ワ紝绌挎杞﹀彿={}锛屼换鍔℃暟鎹�={}", shuttleProtocol.getShuttleNo(), JSON.toJSON(command));
             return false;
         }
@@ -267,77 +320,245 @@
         }
 
         int lev = Utils.getLev(shuttleProtocol.getCurrentLocNo());//灏忚溅褰撳墠妤煎眰
-        if (shuttleProtocol.getYCurrent() > shuttleProtocol.getYTarget()) {
-            //璺戝簱缁撴潫
-            shuttleProtocol.setMoveLoc(false);
-            shuttleProtocol.setMoveType(0);
-            shuttleProtocol.setXStart(0);
-            shuttleProtocol.setXTarget(0);
-            shuttleProtocol.setXCurrent(0);
-            shuttleProtocol.setYStart(0);
-            shuttleProtocol.setYTarget(0);
-            shuttleProtocol.setYCurrent(0);
-            return;
-        }
 
         if (shuttleProtocol.getMoveType() == 0) {//璺戣建閬�
-            Integer xCurrent = shuttleProtocol.getXCurrent();
-            if (xCurrent > shuttleProtocol.getXTarget()) {//褰揦鍊煎ぇ浜嶺鐩爣鍊硷紝杩涜褰掗浂涓擸鏂瑰悜+1
-                shuttleProtocol.setXCurrent(shuttleProtocol.getXStart());
-                shuttleProtocol.setYCurrent(shuttleProtocol.getYCurrent() + 1);
+            //鏍规嵁鍦板浘鏂瑰悜鍐冲畾璺憍鎴杫
+            Dict dict = dictService.getOne(new LambdaQueryWrapper<Dict>()
+                    .eq(Dict::getFlag, "direction_map")
+                    .eq(Dict::getStatus, 1));
+            if (dict == null) {
+                //璺戝簱缁撴潫
+                shuttleProtocol.setMoveLoc(false);
+                shuttleProtocol.setMoveType(0);
+                shuttleProtocol.setXStart(0);
+                shuttleProtocol.setXTarget(0);
+                shuttleProtocol.setXCurrent(0);
+                shuttleProtocol.setYStart(0);
+                shuttleProtocol.setYTarget(0);
+                shuttleProtocol.setYCurrent(0);
                 return;
             }
+            String direction = dict.getValue();
 
-            Integer yCurrent = shuttleProtocol.getYCurrent();
-            String locNo = Utils.getLocNo(xCurrent, yCurrent, lev);
-            Loc target = locService.getOne(new LambdaQueryWrapper<Loc>()
-                    .eq(Loc::getLocNo, locNo)
-                    .eq(Loc::getHostId, device.getHostId()));
-            if (target == null) {
-                shuttleProtocol.setXCurrent(shuttleProtocol.getXCurrent() + 1);
-                return;
-            }
-
-//            if (!target.getLocSts().equals("O")) {
-//                shuttleProtocol.setXCurrent(shuttleProtocol.getXCurrent() + 1);
-//                return;
-//            }
-
-            //璋冨害鍘荤洰鏍囦綅缃�
-            if (shuttleProtocol.getCurrentLocNo().equals(target.getLocNo())) {
-                shuttleProtocol.setXCurrent(shuttleProtocol.getXCurrent() + 1);//灏忚溅鍜岀洰鏍囦綅缃竴鑷达紝璺宠繃
-            } else {
-                shuttleDispatcher.generateMoveTask(device, target.getLocNo());
-                shuttleProtocol.setXCurrent(shuttleProtocol.getXCurrent() + 1);
-            }
-        } else if (shuttleProtocol.getMoveType() == 1) {//璺戝簱浣�
-            ArrayList<String> locs = new ArrayList<>();
-            for (int i = shuttleProtocol.getXCurrent(); i <= shuttleProtocol.getXTarget(); i++) {
-                String locNo = Utils.getLocNo(i, shuttleProtocol.getYCurrent(), lev);
-                locs.add(locNo);
-            }
-
-            List<Loc> locList = locService.list(new LambdaQueryWrapper<Loc>()
-                    .in(Loc::getLocNo, locs));
-            if (locList.isEmpty()) {
-                //绌哄簱浣�
-                shuttleProtocol.setYCurrent(shuttleProtocol.getYCurrent() + 1);
-                return;
-            }
-
-            Loc start = locList.get(0);
-            Loc target = locList.get(locList.size() - 1);
-            //鍒ゆ柇灏忚溅鏄惁鍦ㄨ捣鐐逛綅缃�
-            if (!shuttleProtocol.getCurrentLocNo().equals(start.getLocNo())) {//涓嶅湪璧风偣浣嶇疆锛岃皟搴﹀幓璧风偣浣嶇疆
-                shuttleDispatcher.generateMoveTask(device, start.getLocNo());
-            }else {
-                //鍦ㄨ捣鐐逛綅缃紝璋冨害鍘荤洰鏍囦綅缃�
-                if (shuttleProtocol.getCurrentLocNo().equals(target.getLocNo())) {
-                    shuttleProtocol.setYCurrent(shuttleProtocol.getYCurrent() + 1);//灏忚溅鍜岀洰鏍囦綅缃竴鑷达紝璺宠繃
-                }else {
-                    shuttleDispatcher.generateMoveTask(device, start.getLocNo());
-                    shuttleProtocol.setYCurrent(shuttleProtocol.getYCurrent() + 1);
+            if (direction.equals("y")) {//璺憍杞存柟鍚戯紝璺戝畬x杞村啀鍒囨崲y杞�
+                ArrayList<String> locs = new ArrayList<>();
+                for (int i = shuttleProtocol.getXCurrent(); i <= shuttleProtocol.getXTarget(); i++) {
+                    String locNo = Utils.getLocNo(i, shuttleProtocol.getYCurrent(), lev);
+                    locs.add(locNo);
                 }
+
+                List<Loc> locList = locService.list(new LambdaQueryWrapper<Loc>()
+                        .eq(Loc::getLocSts, LocStsType.O.val())
+                        .in(Loc::getLocNo, locs));
+                if (locList.isEmpty()) {
+                    //绌哄簱浣�
+                    shuttleProtocol.setYCurrent(shuttleProtocol.getYCurrent() + 1);
+                    return;
+                }
+
+                Loc start = locList.get(0);
+                Loc target = locList.get(locList.size() - 1);
+                //鍒ゆ柇灏忚溅鏄惁鍦ㄨ捣鐐逛綅缃�
+                if (!shuttleProtocol.getCurrentLocNo().equals(start.getLocNo())) {//涓嶅湪璧风偣浣嶇疆锛岃皟搴﹀幓璧风偣浣嶇疆
+                    shuttleDispatcher.generateMoveTask(device, start.getLocNo());
+                }else {
+                    //鍦ㄨ捣鐐逛綅缃紝璋冨害鍘荤洰鏍囦綅缃�
+                    Task task = shuttleDispatcher.generateMoveTask(device, target.getLocNo());
+                    if (task != null) {
+                        shuttleProtocol.setYCurrent(shuttleProtocol.getYCurrent() + 1);//鍒囨崲y杞�
+                    }
+
+                    if(shuttleProtocol.getYCurrent() > shuttleProtocol.getYTarget()) {
+                        //y杞翠篃璺戝畬浜嗭紝缁撴潫璺戝簱
+                        shuttleProtocol.setMoveLoc(false);
+                        shuttleProtocol.setMoveType(0);
+                        shuttleProtocol.setXStart(0);
+                        shuttleProtocol.setXTarget(0);
+                        shuttleProtocol.setXCurrent(0);
+                        shuttleProtocol.setYStart(0);
+                        shuttleProtocol.setYTarget(0);
+                        shuttleProtocol.setYCurrent(0);
+                        return;
+                    }
+                }
+            }else {//璺憏杞存柟鍚戯紝璺戝畬y杞村啀鍒囨崲x杞�
+                ArrayList<String> locs = new ArrayList<>();
+                for (int i = shuttleProtocol.getYCurrent(); i <= shuttleProtocol.getYTarget(); i++) {
+                    String locNo = Utils.getLocNo(shuttleProtocol.getXCurrent(), i, lev);
+                    locs.add(locNo);
+                }
+
+                List<Loc> locList = locService.list(new LambdaQueryWrapper<Loc>()
+                        .eq(Loc::getLocSts, LocStsType.O.val())
+                        .in(Loc::getLocNo, locs));
+                if (locList.isEmpty()) {
+                    //绌哄簱浣�
+                    shuttleProtocol.setXCurrent(shuttleProtocol.getXCurrent() + 1);
+                    return;
+                }
+
+                Loc start = locList.get(0);
+                Loc target = locList.get(locList.size() - 1);
+                //鍒ゆ柇灏忚溅鏄惁鍦ㄨ捣鐐逛綅缃�
+                if (!shuttleProtocol.getCurrentLocNo().equals(start.getLocNo())) {//涓嶅湪璧风偣浣嶇疆锛岃皟搴﹀幓璧风偣浣嶇疆
+                    shuttleDispatcher.generateMoveTask(device, start.getLocNo());
+                }else {
+                    //鍦ㄨ捣鐐逛綅缃紝璋冨害鍘荤洰鏍囦綅缃�
+                    Task task = shuttleDispatcher.generateMoveTask(device, target.getLocNo());
+                    if (task != null) {
+                        shuttleProtocol.setXCurrent(shuttleProtocol.getXCurrent() + 1);//鍒囨崲x杞�
+                    }
+
+                    if(shuttleProtocol.getXCurrent() > shuttleProtocol.getXTarget()) {
+                        //y杞翠篃璺戝畬浜嗭紝缁撴潫璺戝簱
+                        shuttleProtocol.setMoveLoc(false);
+                        shuttleProtocol.setMoveType(0);
+                        shuttleProtocol.setXStart(0);
+                        shuttleProtocol.setXTarget(0);
+                        shuttleProtocol.setXCurrent(0);
+                        shuttleProtocol.setYStart(0);
+                        shuttleProtocol.setYTarget(0);
+                        shuttleProtocol.setYCurrent(0);
+                        return;
+                    }
+                }
+            }
+
+        } else if (shuttleProtocol.getMoveType() == 1) {//璺戝簱浣�
+            //鏍规嵁鍦板浘鏂瑰悜鍐冲畾璺憍鎴杫
+            Dict dict = dictService.getOne(new LambdaQueryWrapper<Dict>()
+                    .eq(Dict::getFlag, "direction_map")
+                    .eq(Dict::getStatus, 1));
+            if (dict == null) {
+                //璺戝簱缁撴潫
+                shuttleProtocol.setMoveLoc(false);
+                shuttleProtocol.setMoveType(0);
+                shuttleProtocol.setXStart(0);
+                shuttleProtocol.setXTarget(0);
+                shuttleProtocol.setXCurrent(0);
+                shuttleProtocol.setYStart(0);
+                shuttleProtocol.setYTarget(0);
+                shuttleProtocol.setYCurrent(0);
+                return;
+            }
+            String direction = dict.getValue();
+
+            if (direction.equals("y")) {//璺憍杞存柟鍚戯紝璺戝畬x杞村啀鍒囨崲y杞�
+                Integer xCurrent = shuttleProtocol.getXCurrent();
+
+                //鑾峰彇寰呰窇搴撲綅鍙�
+                String locNo = Utils.getLocNo(xCurrent, shuttleProtocol.getYCurrent(), lev);
+                Loc target = locService.getOne(new LambdaQueryWrapper<Loc>()
+                        .eq(Loc::getLocNo, locNo)
+                        .eq(Loc::getLocSts, LocStsType.O.val())
+                        .eq(Loc::getHostId, device.getHostId()));
+                if (target == null || shuttleProtocol.getCurrentLocNo().equals(locNo)) {//搴撲綅涓嶅瓨鍦ㄦ垨灏忚溅宸插湪褰撳墠浣嶇疆
+                    shuttleProtocol.setXCurrent(xCurrent + 1);
+                    if (shuttleProtocol.getXCurrent() > shuttleProtocol.getXTarget()) {
+                        //x杞磋窇瀹岋紝鍒囨崲y杞�
+                        shuttleProtocol.setXCurrent(shuttleProtocol.getXStart());
+                        shuttleProtocol.setYCurrent(shuttleProtocol.getYCurrent() + 1);
+
+                        if(shuttleProtocol.getYCurrent() > shuttleProtocol.getYTarget()) {
+                            //y杞翠篃璺戝畬浜嗭紝缁撴潫璺戝簱
+                            shuttleProtocol.setMoveLoc(false);
+                            shuttleProtocol.setMoveType(0);
+                            shuttleProtocol.setXStart(0);
+                            shuttleProtocol.setXTarget(0);
+                            shuttleProtocol.setXCurrent(0);
+                            shuttleProtocol.setYStart(0);
+                            shuttleProtocol.setYTarget(0);
+                            shuttleProtocol.setYCurrent(0);
+                            return;
+                        }
+                    }
+                    return;
+                }
+
+                //璋冨害鍘诲簱浣�
+                Task task = shuttleDispatcher.generateMoveTask(device, locNo);
+                if (task == null) {
+                    return;//璋冨害澶辫触
+                }
+
+                shuttleProtocol.setXCurrent(xCurrent + 1);
+                if (shuttleProtocol.getXCurrent() > shuttleProtocol.getXTarget()) {
+                    //x杞磋窇瀹岋紝鍒囨崲y杞�
+                    shuttleProtocol.setXCurrent(shuttleProtocol.getXStart());
+                    shuttleProtocol.setYCurrent(shuttleProtocol.getYCurrent() + 1);
+
+                    if(shuttleProtocol.getYCurrent() > shuttleProtocol.getYTarget()) {
+                        //y杞翠篃璺戝畬浜嗭紝缁撴潫璺戝簱
+                        shuttleProtocol.setMoveLoc(false);
+                        shuttleProtocol.setMoveType(0);
+                        shuttleProtocol.setXStart(0);
+                        shuttleProtocol.setXTarget(0);
+                        shuttleProtocol.setXCurrent(0);
+                        shuttleProtocol.setYStart(0);
+                        shuttleProtocol.setYTarget(0);
+                        shuttleProtocol.setYCurrent(0);
+                        return;
+                    }
+                }
+
+            }else {//璺憏杞存柟鍚戯紝璺戝畬y杞村啀鍒囨崲x杞�
+                Integer yCurrent = shuttleProtocol.getYCurrent();
+
+                //鑾峰彇寰呰窇搴撲綅鍙�
+                String locNo = Utils.getLocNo(shuttleProtocol.getXCurrent(), yCurrent, lev);
+                Loc target = locService.getOne(new LambdaQueryWrapper<Loc>()
+                        .eq(Loc::getLocNo, locNo)
+                        .eq(Loc::getLocSts, LocStsType.O.val())
+                        .eq(Loc::getHostId, device.getHostId()));
+                if (target == null || shuttleProtocol.getCurrentLocNo().equals(locNo)) {//搴撲綅涓嶅瓨鍦ㄦ垨灏忚溅宸插湪褰撳墠浣嶇疆
+                    shuttleProtocol.setYCurrent(yCurrent + 1);
+                    if (shuttleProtocol.getYCurrent() > shuttleProtocol.getYTarget()) {
+                        //y杞磋窇瀹岋紝鍒囨崲x杞�
+                        shuttleProtocol.setYCurrent(shuttleProtocol.getYStart());
+                        shuttleProtocol.setXCurrent(shuttleProtocol.getXCurrent() + 1);
+
+                        if(shuttleProtocol.getXCurrent() > shuttleProtocol.getXTarget()) {
+                            //x杞翠篃璺戝畬浜嗭紝缁撴潫璺戝簱
+                            shuttleProtocol.setMoveLoc(false);
+                            shuttleProtocol.setMoveType(0);
+                            shuttleProtocol.setXStart(0);
+                            shuttleProtocol.setXTarget(0);
+                            shuttleProtocol.setXCurrent(0);
+                            shuttleProtocol.setYStart(0);
+                            shuttleProtocol.setYTarget(0);
+                            shuttleProtocol.setYCurrent(0);
+                            return;
+                        }
+                    }
+                    return;
+                }
+
+                //璋冨害鍘诲簱浣�
+                Task task = shuttleDispatcher.generateMoveTask(device, locNo);
+                if (task == null) {
+                    return;//璋冨害澶辫触
+                }
+
+                shuttleProtocol.setYCurrent(yCurrent + 1);
+                if (shuttleProtocol.getYCurrent() > shuttleProtocol.getYTarget()) {
+                    //y杞磋窇瀹岋紝鍒囨崲x杞�
+                    shuttleProtocol.setYCurrent(shuttleProtocol.getYStart());
+                    shuttleProtocol.setXCurrent(shuttleProtocol.getXCurrent() + 1);
+
+                    if(shuttleProtocol.getXCurrent() > shuttleProtocol.getXTarget()) {
+                        //x杞翠篃璺戝畬浜嗭紝缁撴潫璺戝簱
+                        shuttleProtocol.setMoveLoc(false);
+                        shuttleProtocol.setMoveType(0);
+                        shuttleProtocol.setXStart(0);
+                        shuttleProtocol.setXTarget(0);
+                        shuttleProtocol.setXCurrent(0);
+                        shuttleProtocol.setYStart(0);
+                        shuttleProtocol.setYTarget(0);
+                        shuttleProtocol.setYCurrent(0);
+                        return;
+                    }
+                }
+
             }
         } else if (shuttleProtocol.getMoveType() == 2) {//姣嶈建閬撳惊鐜窇
             Integer xCurrent = shuttleProtocol.getXCurrent();
@@ -446,27 +667,32 @@
         }
     }
 
-    private synchronized boolean write(ShuttleCommand command, Device device) {
+    private synchronized CommandResponse write(ShuttleCommand command, Device device) {
+        CommandResponse response = new CommandResponse(false);
         if (null == command) {
             News.error("鍥涘悜绌挎杞﹀啓鍏ュ懡浠や负绌�");
-            return false;
+            response.setMessage("鍥涘悜绌挎杞﹀啓鍏ュ懡浠や负绌�");
+            return response;
         }
         ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, device.getId().intValue());
-        boolean result = false;
         if (command.getMode() == ShuttleCommandModeType.MOVE.id
                 || command.getMode() == ShuttleCommandModeType.IN_LIFT.id
                 || command.getMode() == ShuttleCommandModeType.OUT_LIFT.id) {//绉诲姩
-            result = shuttleThread.move(command);
+            response = shuttleThread.move(command);
         } else if (command.getMode() == ShuttleCommandModeType.PALLET_LIFT.id
                 || command.getMode() == ShuttleCommandModeType.PALLET_DOWN.id) {//椤跺崌
-            result = shuttleThread.lift(command);
+            response = shuttleThread.lift(command);
         } else if (command.getMode() == ShuttleCommandModeType.CHARGE_OPEN.id
                 || command.getMode() == ShuttleCommandModeType.CHARGE_CLOSE.id) {//鍏呯數
-            result = shuttleThread.charge(command);
+            response = shuttleThread.charge(command);
         } else if (command.getMode() == ShuttleCommandModeType.RESET.id) {//澶嶄綅
-            result = shuttleThread.reset(command);
+            response = shuttleThread.reset(command);
+        } else if (command.getMode() == ShuttleCommandModeType.UPDATE_LOCATION.id) {//鏇存柊鍧愭爣
+            response = shuttleThread.updateLocation(command);
         }
-        return result;
+
+//        News.info("鍥涘悜绌挎杞﹀懡浠や笅鍙戯紝绌挎杞﹀彿={}锛屼换鍔℃暟鎹�={}", device.getDeviceNo(), JSON.toJSON(command));
+        return response;
     }
 
 }

--
Gitblit v1.9.1