From a7d5e6c4a45ca1f7bb1560ef4e76f4c1680c41db Mon Sep 17 00:00:00 2001
From: Junjie <xjj@123>
Date: 星期六, 18 五月 2024 10:43:29 +0800
Subject: [PATCH] #

---
 zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/action/ShuttleAction.java |  111 +++++++++++++++++++++++++++++--------------------------
 1 files changed, 58 insertions(+), 53 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 0d9accf..9ca36f9 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
@@ -4,12 +4,14 @@
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.ObjectMapper;
+import com.zy.asrs.wcs.common.ExecuteSupport;
 import com.zy.asrs.wcs.core.entity.Loc;
 import com.zy.asrs.wcs.core.entity.Task;
 import com.zy.asrs.wcs.core.model.NavigateNode;
 import com.zy.asrs.wcs.core.model.command.ShuttleAssignCommand;
 import com.zy.asrs.wcs.core.model.command.ShuttleCommand;
 import com.zy.asrs.wcs.core.model.command.ShuttleRedisCommand;
+import com.zy.asrs.wcs.core.model.enums.MotionCtgType;
 import com.zy.asrs.wcs.core.model.enums.ShuttleCommandModeType;
 import com.zy.asrs.wcs.core.model.enums.ShuttleTaskModeType;
 import com.zy.asrs.wcs.core.service.BasShuttleService;
@@ -26,12 +28,12 @@
 import com.zy.asrs.wcs.rcs.model.enums.SlaveType;
 import com.zy.asrs.wcs.rcs.model.protocol.ShuttleProtocol;
 import com.zy.asrs.wcs.rcs.thread.ShuttleThread;
-import org.aspectj.apache.bcel.generic.RET;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Objects;
 
 @Component
 public class ShuttleAction {
@@ -63,7 +65,7 @@
         ShuttleRedisCommand redisCommand = new ShuttleRedisCommand();
 
         redisCommand.setShuttleNo(assignCommand.getShuttleNo());//鍥涘悜绌挎杞﹀彿
-        redisCommand.setWrkNo(assignCommand.getTaskNo());//宸ヤ綔鍙�
+        redisCommand.setTaskNo(assignCommand.getTaskNo());//宸ヤ綔鍙�
         redisCommand.setCommandStep(0);//鍛戒护鎵ц姝ュ簭
         redisCommand.setAssignCommand(assignCommand);//鍛戒护
         //浠诲姟鏁版嵁淇濆瓨鍒皉edis
@@ -73,7 +75,7 @@
                     || assignCommand.getTaskMode() == ShuttleTaskModeType.MOVE_LOC_NO.id
                     || assignCommand.getTaskMode() == ShuttleTaskModeType.SHUTTLE_MOVE_LOC_NO.id) {
                 //涓嬪彂琛岄┒璺緞
-                boolean result = shuttleThread.movePath(assignCommand.getNodes(), assignCommand.getTaskNo());
+                boolean result = shuttleThread.movePath(assignCommand.getNodes(), assignCommand.getDeviceTaskNo());
                 if (!result) {
                     return false;
                 }
@@ -110,16 +112,6 @@
         if (shuttleProtocol == null) {
             return false;
         }
-
-        //鍒ゆ柇璁惧鏄惁绌洪棽
-        if (!shuttleThread.isDeviceIdle()) {
-            return false;
-        }
-//        if (!shuttleThread.isIdle(() -> {
-//            return shuttleProtocol.getTaskNo().equals(taskNo);
-//        })) {
-//            return false;
-//        }
 
         //鍒ゆ柇宸ヤ綔鍙锋槸鍚︾浉鍚�
         if (!shuttleProtocol.getTaskNo().equals(taskNo)) {
@@ -182,7 +174,7 @@
             }
 
             // 鏇存柊redis鏁版嵁
-            redisUtil.set(DeviceRedisConstant.SHUTTLE_WORK_FLAG + redisCommand.getWrkNo(), JSON.toJSONString(redisCommand));
+            redisUtil.set(DeviceRedisConstant.SHUTTLE_WORK_FLAG + redisCommand.getTaskNo(), JSON.toJSONString(redisCommand));
 
             if (!command.getComplete()) {
                 return false;
@@ -197,25 +189,25 @@
                 if (assignCommand.getAuto()) {
                     if (!assignCommand.getCharge()) {
                         //瀵逛富绾跨▼鎶涘嚭绛夊緟纭鐘舵�亀aiting
-                        shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.WAITING);
+                        shuttleThread.setProtocolStatus(ShuttleProtocolStatusType.WAITING);
                     }else {
-                        shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.CHARGING_WAITING);
+                        shuttleThread.setProtocolStatus(ShuttleProtocolStatusType.CHARGING_WAITING);
                     }
                     News.info("鍥涘悜绌挎杞︿换鍔℃墽琛屼笅鍙戝畬鎴愮瓑寰呮墽琛岀粨鏉燂紝绌挎杞﹀彿={}锛屼换鍔℃暟鎹�={}", shuttleProtocol.getShuttleNo(), JSON.toJSON(command));
 
                     // 鎵嬪姩浠诲姟
                 } else {
                     //鎵嬪姩妯″紡涓嶆姏鍑虹瓑寰呯姸鎬侊紝鐩存帴澶嶄綅绌洪棽鐘舵��
-                    shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.IDLE);
+                    shuttleThread.setProtocolStatus(ShuttleProtocolStatusType.IDLE);
                     //浠诲姟鍙锋竻闆�
-                    shuttleProtocol.setSyncTaskNo(0);
+                    shuttleThread.setSyncTaskNo(0);
                     //鏍囪澶嶄綅
-                    shuttleProtocol.setPakMk(true);
+                    shuttleThread.setPakMk(true);
                     News.info("鍥涘悜绌挎杞︽墜鍔ㄤ换鍔℃墽琛屽畬鎴愶紝绌挎杞﹀彿={}锛屼换鍔℃暟鎹�={}", shuttleProtocol.getShuttleNo(), JSON.toJSON(command));
                 }
 
                 //鍒犻櫎redis
-                redisUtil.del(DeviceRedisConstant.SHUTTLE_WORK_FLAG + redisCommand.getWrkNo());
+                redisUtil.del(DeviceRedisConstant.SHUTTLE_WORK_FLAG + redisCommand.getTaskNo());
                 return false;//绂佹鍐嶄笅鍙戝懡浠�
             }
         }
@@ -223,18 +215,32 @@
         //鍙栧嚭鍛戒护
         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)) {
             News.error("鍥涘悜绌挎杞﹀懡浠や笅鍙戝け璐ワ紝绌挎杞﹀彿={}锛屼换鍔℃暟鎹�={}", shuttleProtocol.getShuttleNo(), JSON.toJSON(command));
             return false;
         }
 
-        shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.WORKING);
+        shuttleThread.setProtocolStatus(ShuttleProtocolStatusType.WORKING);
         commandStep++;
         //鏇存柊redis鏁版嵁
         redisCommand.setCommandStep(commandStep);
         //浠诲姟鏁版嵁淇濆瓨鍒皉edis
-        redisUtil.set(DeviceRedisConstant.SHUTTLE_WORK_FLAG + redisCommand.getWrkNo(), JSON.toJSONString(redisCommand));
+        redisUtil.set(DeviceRedisConstant.SHUTTLE_WORK_FLAG + redisCommand.getTaskNo(), JSON.toJSONString(redisCommand));
         return true;
     }
 
@@ -244,8 +250,7 @@
         if (shuttleThread == null) {
             return;
         }
-
-        ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
+        ShuttleProtocol shuttleProtocol = shuttleThread.getStatus(false);
         if (shuttleProtocol == null) {
             return;
         }
@@ -275,35 +280,6 @@
         }
 
         if (shuttleProtocol.getMoveType() == 0) {//璺戣建閬�
-            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);
-                }
-            }
-        } else if (shuttleProtocol.getMoveType() == 1) {//璺戝簱浣�
             Integer xCurrent = shuttleProtocol.getXCurrent();
             if (xCurrent > shuttleProtocol.getXTarget()) {//褰揦鍊煎ぇ浜嶺鐩爣鍊硷紝杩涜褰掗浂涓擸鏂瑰悜+1
                 shuttleProtocol.setXCurrent(shuttleProtocol.getXStart());
@@ -333,6 +309,35 @@
                 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);
+                }
+            }
         } else if (shuttleProtocol.getMoveType() == 2) {//姣嶈建閬撳惊鐜窇
             Integer xCurrent = shuttleProtocol.getXCurrent();
             Integer yCurrent = shuttleProtocol.getYCurrent();

--
Gitblit v1.9.1