From 2db722e23d7e5d1d2e719174938f354d804644af Mon Sep 17 00:00:00 2001
From: Junjie <xjj@123>
Date: 星期二, 23 四月 2024 08:13:52 +0800
Subject: [PATCH] #

---
 zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/constant/DeviceRedisConstant.java          |    2 
 zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/thread/impl/NyLiftThread.java              |   14 ++
 zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/thread/impl/SurayLiftThread.java           |    6 +
 zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/kernel/command/ShuttleCommandService.java |  228 ++++++++++++++++++++++++++++++++++++++-------
 zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/thread/LiftThread.java                     |    2 
 5 files changed, 210 insertions(+), 42 deletions(-)

diff --git a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/kernel/command/ShuttleCommandService.java b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/kernel/command/ShuttleCommandService.java
index e799b7b..2669988 100644
--- a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/kernel/command/ShuttleCommandService.java
+++ b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/kernel/command/ShuttleCommandService.java
@@ -4,11 +4,14 @@
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.zy.asrs.framework.common.Cools;
 import com.zy.asrs.framework.exception.CoolException;
+import com.zy.asrs.wcs.common.ExecuteSupport;
 import com.zy.asrs.wcs.core.action.LiftAction;
 import com.zy.asrs.wcs.core.action.ShuttleAction;
 import com.zy.asrs.wcs.core.entity.BasShuttle;
 import com.zy.asrs.wcs.core.entity.Loc;
 import com.zy.asrs.wcs.core.model.NavigateNode;
+import com.zy.asrs.wcs.core.model.command.LiftAssignCommand;
+import com.zy.asrs.wcs.core.model.command.LiftCommand;
 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.enums.*;
@@ -19,6 +22,7 @@
 import com.zy.asrs.wcs.rcs.News;
 import com.zy.asrs.wcs.rcs.cache.SlaveConnection;
 import com.zy.asrs.wcs.core.entity.Motion;
+import com.zy.asrs.wcs.rcs.constant.DeviceRedisConstant;
 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.LiftProtocol;
@@ -135,21 +139,26 @@
                     return false;
                 }
 
-//                //鍒ゆ柇鎻愬崌鏈烘槸鍚﹁閿佸畾
-//                if (!liftProtocol.getLock()) {
-//                    //閿佸畾鎻愬崌鏈�
-//                    LiftCommand lockCommand = liftThread.getLockCommand(motion.getWrkNo(), true);//鑾峰彇鎻愬崌鏈洪攣瀹氬懡浠�
-//
-//                    LiftAssignCommand liftAssignCommand = new LiftAssignCommand();
-//                    liftAssignCommand.setLiftNo(liftThread.getStatus().getLiftNo());
-//                    liftAssignCommand.setTaskNo(motion.getWrkNo());
-//                    ArrayList<LiftCommand> list = new ArrayList<>();
-//                    list.add(lockCommand);
-//                    liftAssignCommand.setCommands(list);
-//
-//                    liftAction.assignWork(liftThread.getDevice(), liftAssignCommand);
-//                    return false;//绛夊緟涓嬩竴娆¤疆璇�
-//                }
+                //鍒ゆ柇鎻愬崌鏈烘槸鍚﹁閿佸畾
+                if (!liftThread.isLock(new ExecuteSupport() {
+                    @Override
+                    public Boolean judgement() {
+                        return true;
+                    }
+                })) {
+                    //閿佸畾鎻愬崌鏈�
+                    LiftCommand lockCommand = liftThread.getLockCommand(motion.getTaskNo(), true);//鑾峰彇鎻愬崌鏈洪攣瀹氬懡浠�
+
+                    LiftAssignCommand liftAssignCommand = new LiftAssignCommand();
+                    liftAssignCommand.setLiftNo(liftThread.getStatus().getLiftNo());
+                    liftAssignCommand.setTaskNo(motion.getTaskNo());
+                    ArrayList<LiftCommand> list = new ArrayList<>();
+                    list.add(lockCommand);
+                    liftAssignCommand.setCommands(list);
+
+                    liftAction.assignWork(liftThread.getDevice(), liftAssignCommand);
+                    return false;//绛夊緟涓嬩竴娆¤疆璇�
+                }
 
                 //鍒ゆ柇鎻愬崌鏈哄伐浣滃彿鏄惁鍜屽綋鍓嶄换鍔$浉鍚�
                 if (liftProtocol.getTaskNo().intValue() != motion.getTaskNo()) {
@@ -178,15 +187,29 @@
                     return false;
                 }
 
-//                //鍒ゆ柇鎻愬崌鏈烘槸鍚﹁閿佸畾
-//                if (!liftProtocol.getLiftLock()) {
-//                    //閿佸畾鎻愬崌鏈�
-//                    LiftCommand lockCommand = liftThread.getLockCommand(true);//鑾峰彇鎻愬崌鏈洪攣瀹氬懡浠�
-//                    lockCommand.setLiftNo(liftProtocol.getLiftNo());
-//                    lockCommand.setTaskNo(motion.getWrkNo().shortValue());//鑾峰彇浠诲姟鍙�
-//                    liftThread.assignWork(lockCommand);
-//                    return false;//绛夊緟涓嬩竴娆¤疆璇�
-//                }
+                //鍒ゆ柇鎻愬崌鏈烘槸鍚﹁閿佸畾
+                if (!liftThread.isLock(new ExecuteSupport() {
+                    @Override
+                    public Boolean judgement() {
+                        return true;
+                    }
+                })) {
+                    //閿佸畾鎻愬崌鏈�
+                    LiftCommand lockCommand = liftThread.getLockCommand(motion.getTaskNo(), true);//鑾峰彇鎻愬崌鏈洪攣瀹氬懡浠�
+                    if (lockCommand == null) {
+                        return false;
+                    }
+
+                    LiftAssignCommand liftAssignCommand = new LiftAssignCommand();
+                    liftAssignCommand.setLiftNo(liftThread.getStatus().getLiftNo());
+                    liftAssignCommand.setTaskNo(motion.getTaskNo());
+                    ArrayList<LiftCommand> list = new ArrayList<>();
+                    list.add(lockCommand);
+                    liftAssignCommand.setCommands(list);
+
+                    liftAction.assignWork(liftThread.getDevice(), liftAssignCommand);
+                    return false;//绛夊緟涓嬩竴娆¤疆璇�
+                }
 
                 //鍒ゆ柇鎻愬崌鏈哄伐浣滃彿鏄惁鍜屽綋鍓嶄换鍔$浉鍚�
                 if (liftProtocol.getTaskNo().intValue() != motion.getTaskNo()) {
@@ -284,7 +307,126 @@
                 }
                 break;
             case SHUTTLE_MOVE_TO_LIFT:
+                liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, Integer.parseInt(motion.getTemp()));
+                if (liftThread == null) {
+                    return false;
+                }
+                liftProtocol = liftThread.getStatus();
+
+                if (!shuttleProtocol.getCurrentLocNo().equals(motion.getTarget())) {
+                    return false;
+                }
+
+                //鍒ゆ柇鎻愬崌鏈烘槸鍚﹁閿佸畾
+                if (liftThread.isLock(new ExecuteSupport() {
+                    @Override
+                    public Boolean judgement() {
+                        return false;
+                    }
+                })) {
+                    //瑙i攣鎻愬崌鏈�
+                    LiftCommand lockCommand = liftThread.getLockCommand(motion.getTaskNo(), false);//鑾峰彇鎻愬崌鏈鸿В閿佸懡浠�
+
+                    LiftAssignCommand liftAssignCommand = new LiftAssignCommand();
+                    liftAssignCommand.setLiftNo(liftThread.getStatus().getLiftNo());
+                    liftAssignCommand.setTaskNo(motion.getTaskNo());
+                    ArrayList<LiftCommand> list = new ArrayList<>();
+                    list.add(lockCommand);
+                    liftAssignCommand.setCommands(list);
+
+                    liftAction.assignWork(liftThread.getDevice(), liftAssignCommand);
+                    return false;//绛夊緟涓嬩竴娆¤疆璇�
+                }
+
+                //鍒ゆ柇灏忚溅鏄惁宸插埌浣�
+                if (liftProtocol.getHasCar()) {
+                    LiftCommand signalCommand = liftThread.getShuttleSignalCommand(motion.getTaskNo(), true);//鑾峰彇灏忚溅宸插埌浣嶅懡浠�
+                    if(signalCommand != null) {
+                        boolean hasKey = redisUtil.hasKey(DeviceRedisConstant.COMMAND_TMP + motion.getTaskNo());
+                        if (!hasKey) {
+                            LiftAssignCommand liftAssignCommand = new LiftAssignCommand();
+                            liftAssignCommand.setLiftNo(liftThread.getStatus().getLiftNo());
+                            liftAssignCommand.setTaskNo(motion.getTaskNo());
+                            ArrayList<LiftCommand> list = new ArrayList<>();
+                            list.add(signalCommand);
+                            liftAssignCommand.setCommands(list);
+                            liftAction.assignWork(liftThread.getDevice(), liftAssignCommand);
+                            return false;
+                        }
+                    }
+                }
+
+                //鍒ゆ柇鎻愬崌鏈哄伐浣滃彿鏄惁鍜屽綋鍓嶄换鍔$浉鍚�
+                if (liftProtocol.getTaskNo().intValue() != motion.getTaskNo()) {
+                    return false;
+                }
+
+                if (liftProtocol.getTaskNo() != 0) {
+                    //娓呯┖鎻愬崌鏈哄彿
+                    liftThread.setSyncTaskNo(0);
+                }
+                break;
             case SHUTTLE_MOVE_FROM_LIFT:
+                liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, Integer.parseInt(motion.getTemp()));
+                if (liftThread == null) {
+                    return false;
+                }
+                liftProtocol = liftThread.getStatus();
+
+                if (!shuttleProtocol.getCurrentLocNo().equals(motion.getTarget())) {
+                    return false;
+                }
+
+                //鍒ゆ柇鎻愬崌鏈烘槸鍚﹁閿佸畾
+                if (liftThread.isLock(new ExecuteSupport() {
+                    @Override
+                    public Boolean judgement() {
+                        return false;
+                    }
+                })) {
+                    //瑙i攣鎻愬崌鏈�
+                    LiftCommand lockCommand = liftThread.getLockCommand(motion.getTaskNo(), false);//鑾峰彇鎻愬崌鏈鸿В閿佸懡浠�
+
+                    LiftAssignCommand liftAssignCommand = new LiftAssignCommand();
+                    liftAssignCommand.setLiftNo(liftThread.getStatus().getLiftNo());
+                    liftAssignCommand.setTaskNo(motion.getTaskNo());
+                    ArrayList<LiftCommand> list = new ArrayList<>();
+                    list.add(lockCommand);
+                    liftAssignCommand.setCommands(list);
+
+                    liftAction.assignWork(liftThread.getDevice(), liftAssignCommand);
+                    return false;//绛夊緟涓嬩竴娆¤疆璇�
+                }
+
+                //鍒ゆ柇灏忚溅鏄惁宸茬寮�
+                if (!liftProtocol.getHasCar()) {
+                    LiftCommand signalCommand = liftThread.getShuttleSignalCommand(motion.getTaskNo(), false);//鑾峰彇灏忚溅宸查┚绂诲懡浠�
+                    if(signalCommand != null) {
+                        boolean hasKey = redisUtil.hasKey(DeviceRedisConstant.COMMAND_TMP + motion.getTaskNo());
+                        if (!hasKey) {
+                            redisUtil.set(DeviceRedisConstant.COMMAND_TMP + motion.getTaskNo(), JSON.toJSONString(signalCommand), 120);
+                            LiftAssignCommand liftAssignCommand = new LiftAssignCommand();
+                            liftAssignCommand.setLiftNo(liftThread.getStatus().getLiftNo());
+                            liftAssignCommand.setTaskNo(motion.getTaskNo());
+                            ArrayList<LiftCommand> list = new ArrayList<>();
+                            list.add(signalCommand);
+                            liftAssignCommand.setCommands(list);
+                            liftAction.assignWork(liftThread.getDevice(), liftAssignCommand);
+                            return false;
+                        }
+                    }
+                }
+
+                //鍒ゆ柇鎻愬崌鏈哄伐浣滃彿鏄惁鍜屽綋鍓嶄换鍔$浉鍚�
+                if (liftProtocol.getTaskNo().intValue() != motion.getTaskNo()) {
+                    return false;
+                }
+
+                if (liftProtocol.getTaskNo() != 0) {
+                    //娓呯┖鎻愬崌鏈哄彿
+                    liftThread.setSyncTaskNo(0);
+                }
+                break;
             case SHUTTLE_TRANSPORT_FROM_LIFT:
             case SHUTTLE_TRANSPORT_TO_LIFT:
             case SHUTTLE_MOVE_FROM_LIFT_TO_CONVEYOR:
@@ -298,26 +440,36 @@
                     return false;
                 }
 
-//                //鍒ゆ柇鎻愬崌鏈烘槸鍚﹁閿佸畾
-//                if (liftProtocol.getLiftLock()) {
-//                    //瑙i攣鎻愬崌鏈�
-//                    LiftCommand lockCommand = liftThread.getLockCommand(false);//鑾峰彇鎻愬崌鏈鸿В閿佸懡浠�
-//                    lockCommand.setLiftNo(liftProtocol.getLiftNo());
-//                    lockCommand.setTaskNo(motion.getWrkNo().shortValue());//鑾峰彇浠诲姟鍙�
-//                    liftThread.assignWork(lockCommand);
-//                    return false;
-//                }
+                //鍒ゆ柇鎻愬崌鏈烘槸鍚﹁閿佸畾
+                if (liftThread.isLock(new ExecuteSupport() {
+                    @Override
+                    public Boolean judgement() {
+                        return false;
+                    }
+                })) {
+                    //瑙i攣鎻愬崌鏈�
+                    LiftCommand lockCommand = liftThread.getLockCommand(motion.getTaskNo(), false);//鑾峰彇鎻愬崌鏈鸿В閿佸懡浠�
+
+                    LiftAssignCommand liftAssignCommand = new LiftAssignCommand();
+                    liftAssignCommand.setLiftNo(liftThread.getStatus().getLiftNo());
+                    liftAssignCommand.setTaskNo(motion.getTaskNo());
+                    ArrayList<LiftCommand> list = new ArrayList<>();
+                    list.add(lockCommand);
+                    liftAssignCommand.setCommands(list);
+
+                    liftAction.assignWork(liftThread.getDevice(), liftAssignCommand);
+                    return false;//绛夊緟涓嬩竴娆¤疆璇�
+                }
 
                 //鍒ゆ柇鎻愬崌鏈哄伐浣滃彿鏄惁鍜屽綋鍓嶄换鍔$浉鍚�
                 if (liftProtocol.getTaskNo().intValue() != motion.getTaskNo()) {
                     return false;
                 }
 
-//                if (liftProtocol.getTaskNo() != 0) {
-//                    //娓呯┖鎻愬崌鏈哄彿
-//                    liftThread.setTaskNo(0);
-//                }
-
+                if (liftProtocol.getTaskNo() != 0) {
+                    //娓呯┖鎻愬崌鏈哄彿
+                    liftThread.setSyncTaskNo(0);
+                }
                 break;
             default:
                 break;
diff --git a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/constant/DeviceRedisConstant.java b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/constant/DeviceRedisConstant.java
index 52dd32b..a4ab4df 100644
--- a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/constant/DeviceRedisConstant.java
+++ b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/constant/DeviceRedisConstant.java
@@ -15,4 +15,6 @@
 
     public static final String MAP = "realtimeBasMap_";
 
+    public static final String COMMAND_TMP = "command_tmp_";
+
 }
diff --git a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/thread/LiftThread.java b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/thread/LiftThread.java
index 72e48c4..ae280fb 100644
--- a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/thread/LiftThread.java
+++ b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/thread/LiftThread.java
@@ -30,6 +30,8 @@
 
     boolean setSyncTaskNo(Integer taskNo);//璁剧疆宸ヤ綔鍙�
 
+    boolean isLock(ExecuteSupport support);
+
     //***************鑾峰彇鍛戒护*****************
     LiftCommand getMoveCommand(Integer taskNo, Integer sourceLev, Integer targetLev, Integer mode);//鎻愬崌鏈虹Щ鍔�
 
diff --git a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/thread/impl/NyLiftThread.java b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/thread/impl/NyLiftThread.java
index 90ddd55..cc8ad97 100644
--- a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/thread/impl/NyLiftThread.java
+++ b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/thread/impl/NyLiftThread.java
@@ -312,6 +312,14 @@
     }
 
     @Override
+    public boolean isLock(ExecuteSupport support) {
+        if (support != null) {
+            return support.judgement();
+        }
+        return true;
+    }
+
+    @Override
     public LiftCommand getMoveCommand(Integer taskNo, Integer sourceLev, Integer targetLev, Integer mode) {
         /**
          * 浠诲姟绫诲瀷
@@ -355,14 +363,12 @@
 
     @Override
     public LiftCommand getLockCommand(Integer taskNo, Boolean lock) {
-        LiftCommand command = new LiftCommand();
-        return command;
+        return null;
     }
 
     @Override
     public LiftCommand getShuttleSignalCommand(Integer taskNo, Boolean signal) {
-        LiftCommand command = new LiftCommand();
-        return command;
+        return null;
     }
 
     @Override
diff --git a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/thread/impl/SurayLiftThread.java b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/thread/impl/SurayLiftThread.java
index fcdf4fd..ee1b8ba 100644
--- a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/thread/impl/SurayLiftThread.java
+++ b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/thread/impl/SurayLiftThread.java
@@ -339,6 +339,12 @@
         return true;
     }
 
+    @Override
+    public boolean isLock(ExecuteSupport support) {
+        InnerLiftExtend extend = (InnerLiftExtend) this.liftProtocol.getExtend();
+        return extend.getLock();
+    }
+
     //***************璁惧灞傞�氳-涓嶅悓鍘傚晢璁惧閫氳鏂规涓嶄竴鑷�***************
 
     //璇锋眰鐧诲綍

--
Gitblit v1.9.1