From 88a1fbd68cfb38c921fbf83c92d17b38a4a5975a Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期三, 02 八月 2023 09:14:00 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/core/thread/NyShuttleThread.java |  134 ++++++++++++++++++++++++++++++++++----------
 1 files changed, 104 insertions(+), 30 deletions(-)

diff --git a/src/main/java/com/zy/core/thread/NyShuttleThread.java b/src/main/java/com/zy/core/thread/NyShuttleThread.java
index ddd71bb..648e456 100644
--- a/src/main/java/com/zy/core/thread/NyShuttleThread.java
+++ b/src/main/java/com/zy/core/thread/NyShuttleThread.java
@@ -5,6 +5,7 @@
 import com.core.common.DateUtils;
 import com.core.common.SpringUtils;
 import com.zy.asrs.entity.*;
+import com.zy.asrs.mapper.WrkMastMapper;
 import com.zy.asrs.service.*;
 
 import com.zy.asrs.utils.Utils;
@@ -16,14 +17,13 @@
 import com.zy.core.cache.OutputQueue;
 import com.zy.core.cache.SlaveConnection;
 import com.zy.core.enums.*;
+import com.zy.core.model.LiftSlave;
 import com.zy.core.model.ShuttleSlave;
 import com.zy.core.model.Task;
-import com.zy.core.model.command.NyShuttleHttpCommand;
-import com.zy.core.model.command.ShuttleAssignCommand;
-import com.zy.core.model.command.ShuttleCommand;
-import com.zy.core.model.command.ShuttleRedisCommand;
+import com.zy.core.model.command.*;
 import com.zy.core.model.protocol.LiftProtocol;
 import com.zy.core.model.protocol.NyShuttleProtocol;
+import com.zy.core.properties.SlaveProperties;
 import lombok.Data;
 import lombok.extern.slf4j.Slf4j;
 
@@ -358,6 +358,11 @@
             return false;
         }
 
+        //妫�娴嬬┛姊溅鏄惁鍦ㄦ彁鍗囨満鍐�
+        if (!checkShuttleInTheLift(wrkNo)) {
+            return false;
+        }
+
         //妫�鏌ヨ矾寰勬槸鍚﹀彲琛岃蛋(妫�鏌ヨ矾寰勯攣瀹氱姸鎬侊紝妫�娴嬭矾寰勬槸鍚︽湁鍏朵粬灏忚溅)
         //妫�娴嬪綋鍓嶈璧拌矾寰勶紝鍜屼笅涓�姝ヨ矾寰�
         boolean checkPathIsAvailable = NavigateUtils.checkPathIsAvailable(command.getNodes(), shuttleProtocol.getShuttleNo().intValue(), Utils.getLev(shuttleProtocol.getCurrentLocNo()));
@@ -410,20 +415,6 @@
         }else {
             //宸叉墽琛屽畬鎴�
 
-//            if (redisCommand.getLiftSecurityMk()) {
-//                //鏇鹃攣瀹氳繃鎻愬崌鏈猴紝闇�瑕佽繘琛岃В閿�
-//                if (liftProtocol != null) {
-//                    liftProtocol.setSecurityMk(false);
-//                }
-//            }
-
-//            String locNo = shuttleProtocol.getLocNo() == null ? shuttleProtocol.getSourceLocNo() : shuttleProtocol.getLocNo();
-//            if (locNo != null) {
-//                //瑙i櫎閿佸畾鐨勫簱浣嶈矾寰�
-//                NavigateMapData navigateMapData = new NavigateMapData(Utils.getLev(locNo));
-//                navigateMapData.writeNavigateNodeToRedisMap(redisCommand.getAssignCommand().getNodes(), false);
-//            }
-
             //鍒犻櫎redis
             redisUtil.del("shuttle_wrk_no_" + redisCommand.getWrkNo());
 
@@ -451,15 +442,7 @@
             return false;
         }
 
-        //鎷垮埌鎻愬崌鏈虹嚎绋�
-        LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, 1);
-        if (liftThread == null) {
-            return false;
-        }
-        LiftProtocol liftProtocol = liftThread.getLiftProtocol();
-        if (liftProtocol == null) {
-            return false;
-        }
+        WrkMastMapper wrkMastMapper = SpringUtils.getBean(WrkMastMapper.class);
 
         ShuttleRedisCommand redisCommand = JSON.parseObject(o.toString(), ShuttleRedisCommand.class);
         //褰撳墠姝ュ簭
@@ -467,15 +450,106 @@
 
         //妫�娴嬫槸鍚﹀瓨鍦ㄦ彁鍗囨満鍙g殑鎸囦护
         List<NyShuttleHttpCommand> commands = redisCommand.getAssignCommand().getCommands();
-        if (commands.size() == 0) {
+        if (commands.isEmpty()) {
+            return false;
+        }
+        NyShuttleHttpCommand command = commands.get(commandStep);//褰撳墠鍛戒护
+        if (!command.getMsgType().equals("intoLift")) {
+            return true;//涓嶆槸鍏ユ彁鍗囨満鍛戒护锛岀洿鎺ユ斁琛�
+        }
+
+        //鑾峰彇璧风偣(杈撻�佺珯鐐�)
+        NyShuttleProtocol.NyShuttlePointClass start = JSON.parseObject(command.getRequest().getBody().get("start").toString(), NyShuttleProtocol.NyShuttlePointClass.class);
+        //灏嗙墰鐪煎潗鏍囪浆鎹㈡垚WCS搴撲綅鍙�
+        String startLocNo = NavigatePositionConvert.nyXyzToLocNo(start.getX(), start.getY(), start.getZ());
+
+        BasDevpService basDevpService = SpringUtils.getBean(BasDevpService.class);
+        BasDevp basDevp = basDevpService.queryByLocNo(startLocNo);
+        if (basDevp == null) {
+            return false;//鏌ヤ笉鍒扮珯鐐癸紝绂佹涓嬪彂
+        }
+
+        //鎷垮埌鎻愬崌鏈虹嚎绋�
+        LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, basDevp.getLiftNo());
+        if (liftThread == null) {
+            return false;
+        }
+        LiftProtocol liftProtocol = liftThread.getLiftProtocol();
+        if (liftProtocol == null) {
+            return false;
+        }
+        if (!liftProtocol.isIdle()) {
             return false;
         }
 
-        if (!commands.get(commandStep).getMsgType().equals("move")) {
-            return true;//涓嶆槸琛岃蛋鍛戒护锛岀洿鎺ユ斁琛�
+        if (liftProtocol.getLev().intValue() == Utils.getLev(shuttleProtocol.getCurrentLocNo())) {
+            return true;//鎻愬崌鏈鸿揪鍒板皬杞︽ゼ灞傦紝鏀捐
         }
 
+        //鎼滅储鏄惁鏈夊叾浠栦换鍔″崰鐢ㄤ簡鎻愬崌鏈猴紝濡傛灉鍗犵敤鎻愬崌鏈虹殑浠诲姟鍜屽綋鍓嶄换鍔$浉鍚岋紝鍒欒繍琛屾墽琛�
+        WrkMast wrkMast1 = wrkMastMapper.selectLiftWrkMast(liftProtocol.getLiftNo().intValue());
+        if (wrkMast1 != null && wrkMast1.getWrkNo() != wrkNo.intValue()) {
+            return false;
+        }
 
+        //鎻愬崌鏈烘湭鍒拌揪灏忚溅妤煎眰锛屽懠鍙彁鍗囨満
+        //鑾峰彇鎻愬崌鏈哄懡浠�
+        NyLiftCommand liftCommand = NyLiftUtils.getLiftCommand(liftProtocol.getLiftNo().intValue(), NyLiftTaskModelType.MOVE_CAR.id, null, basDevp.getDevNo(), wrkNo.intValue());
+        ArrayList<NyLiftCommand> liftCommands = new ArrayList<>();
+        liftCommands.add(liftCommand);
+
+        //鎻愪氦鍒扮嚎绋嬪幓宸ヤ綔
+        LiftAssignCommand assignCommand = new LiftAssignCommand();
+        assignCommand.setCommands(liftCommands);
+        assignCommand.setLiftNo(liftProtocol.getLiftNo());
+        assignCommand.setTaskNo(wrkNo);
+        assignCommand.setTaskMode(NyLiftTaskModelType.MOVE_CAR.id.shortValue());
+
+        //涓嬪彂浠诲姟
+        MessageQueue.offer(SlaveType.Lift, liftProtocol.getLiftNo().intValue(), new Task(3, assignCommand));
+
+        return false;//榛樿涓嶆斁琛�
+    }
+
+    /**
+     * 妫�娴嬬┛姊溅鏄惁鍦ㄦ彁鍗囨満鍐�
+     * 濡傜┛姊溅鍦ㄦ彁鍗囨満鍐咃紝蹇呴』绛夊緟鎻愬崌鏈虹┖闂叉墠鍙墽琛岀┛姊溅鍛戒护
+     */
+    private boolean checkShuttleInTheLift(Short wrkNo) {
+        //璇诲彇redis鏁版嵁
+        if (wrkNo == null) {
+            return false;
+        }
+
+        Object o = redisUtil.get("shuttle_wrk_no_" + wrkNo);
+        if (o == null) {
+            return false;
+        }
+
+        SlaveProperties slaveProperties = SpringUtils.getBean(SlaveProperties.class);
+        BasLiftService liftService = SpringUtils.getBean(BasLiftService.class);
+        for (LiftSlave liftSlave : slaveProperties.getLift()) {
+            BasLift basLift = liftService.selectById(liftSlave.getId());
+            if (basLift == null) {
+                continue;
+            }
+            if (basLift.getPoint().equals(shuttleProtocol.getPoint())) {
+                //灏忚溅鍦ㄦ彁鍗囨満鍐�
+                //鍒ゆ柇鎻愬崌鏈烘槸鍚︾┖闂�
+                LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, liftSlave.getId());
+                if (liftThread == null) {
+                    return false;
+                }
+                LiftProtocol liftProtocol = liftThread.getLiftProtocol();
+                if (liftProtocol == null) {
+                    return false;
+                }
+                if (liftProtocol.isIdle()) {
+                    //鎻愬崌鏈哄浜庣┖闂诧紝鏀捐
+                    return true;
+                }
+            }
+        }
         return false;//榛樿涓嶆斁琛�
     }
 

--
Gitblit v1.9.1