From 32cf315c6ac0cbbac6cc75a5e4e083d5e72bbe04 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期三, 12 四月 2023 16:52:00 +0800
Subject: [PATCH] 穿梭车到达提升机口前,优先调度提升机。寻路节点增加层高等

---
 src/main/java/com/zy/core/thread/ShuttleThread.java |  159 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 156 insertions(+), 3 deletions(-)

diff --git a/src/main/java/com/zy/core/thread/ShuttleThread.java b/src/main/java/com/zy/core/thread/ShuttleThread.java
index a970778..871654e 100644
--- a/src/main/java/com/zy/core/thread/ShuttleThread.java
+++ b/src/main/java/com/zy/core/thread/ShuttleThread.java
@@ -8,9 +8,11 @@
 import com.core.common.DateUtils;
 import com.core.common.SpringUtils;
 import com.core.exception.CoolException;
+import com.zy.asrs.entity.BasDevp;
 import com.zy.asrs.entity.BasShuttle;
 import com.zy.asrs.entity.BasShuttleOpt;
 import com.zy.asrs.entity.LocMast;
+import com.zy.asrs.service.BasDevpService;
 import com.zy.asrs.service.BasShuttleOptService;
 import com.zy.asrs.service.BasShuttleService;
 import com.zy.asrs.service.LocMastService;
@@ -27,8 +29,11 @@
 import com.zy.core.enums.*;
 import com.zy.core.model.ShuttleSlave;
 import com.zy.core.model.Task;
+import com.zy.core.model.command.LiftAssignCommand;
+import com.zy.core.model.command.LiftCommand;
 import com.zy.core.model.command.ShuttleAssignCommand;
 import com.zy.core.model.command.ShuttleCommand;
+import com.zy.core.model.protocol.LiftProtocol;
 import com.zy.core.model.protocol.ShuttleProtocol;
 import lombok.Data;
 import lombok.extern.slf4j.Slf4j;
@@ -196,6 +201,20 @@
                         && shuttleProtocol.getAssignCommand() != null) {
                     //鎵ц涓嬩竴姝ユ寚浠�
                     executeWork(shuttleProtocol.getAssignCommand());
+                }
+
+                //妫�娴嬫槸鍚︽湁鎻愬崌鏈洪攣瀹氭爣璁帮紝鏈夊垯妫�娴嬫彁鍗囨満鏄惁鍒颁綅锛屾槸鍚﹁兘璧颁笅涓�姝ュ懡浠�
+                if (shuttleProtocol.getBusyStatusType() == ShuttleStatusType.IDLE
+                        && shuttleProtocol.getTaskNo() != 0
+                        && shuttleProtocol.getAssignCommand() != null) {
+                    Object o = redisUtil.get("wrk_no_" + shuttleProtocol.getAssignCommand().getTaskNo());
+                    if (o != null) {
+                        HashMap map = JSON.parseObject(o.toString(), HashMap.class);
+                        if (map.containsKey("liftSecurityMk") && Boolean.parseBoolean(map.get("liftSecurityMk").toString())) {
+                            //鎵ц涓嬩竴姝ユ寚浠�
+                            executeWork(shuttleProtocol.getAssignCommand());
+                        }
+                    }
                 }
 
                 //灏嗗洓鍚戠┛姊溅鐘舵�佷繚瀛樿嚦鏁版嵁搴�
@@ -631,14 +650,18 @@
             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);
+
+        if (!checkLiftStation(assignCommand)) {//妫�娴嬫槸鍚︽湁鎻愬崌鏈虹珯鐐癸紝鏈夊垯璋冨害鎻愬崌鏈�
+            return false;
+        }
+
+        //灏嗘爣璁扮疆涓篺alse(闃叉閲嶅彂)
+        shuttleProtocol.setPakMk(false);
 
         List<ShuttleCommand> errorCommands =  JSON.parseArray(map.get("errorCommands").toString(),ShuttleCommand.class);
         if (errorCommands.size() > 0) {
@@ -765,6 +788,16 @@
                     );
                     shuttleOptService.insert(opt);
                 }
+
+                if (map.containsKey("liftSecurityMk") && Boolean.parseBoolean(map.get("liftSecurityMk").toString())) {
+                    //鏇鹃攣瀹氳繃鎻愬崌鏈猴紝闇�瑕佽繘琛岃В閿�
+                    LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, 1);
+                    LiftProtocol liftProtocol = liftThread.getLiftProtocol();
+                    if (liftProtocol != null) {
+                        liftProtocol.setSecurityMk(false);
+                    }
+                }
+
                 //鍒犻櫎redis
                 redisUtil.del("wrk_no_" + map.get("wrk_no").toString());
 
@@ -798,6 +831,126 @@
     }
 
     /**
+     * 妫�娴嬫槸鍚︽湁鎻愬崌鏈虹珯鐐癸紝鏈夊垯璋冨害鎻愬崌鏈�
+     */
+    private boolean checkLiftStation(ShuttleAssignCommand assignCommand) {
+        //璇诲彇redis鏁版嵁
+        if (assignCommand == null) {
+            return 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());
+
+        //妫�娴嬫槸鍚﹀瓨鍦ㄦ彁鍗囨満鍙g殑鎸囦护
+        List<ShuttleCommand> commands = assignCommand.getCommands();
+        BasDevpService basDevpService = SpringUtils.getBean(BasDevpService.class);
+        ArrayList<Short> qrCodeValues = new ArrayList<>();
+        for (BasDevp basDevp : basDevpService.selectList(null)) {
+            //灏嗘墍鏈夋彁鍗囨満鍙d簩缁寸爜瀛樺叆list
+            qrCodeValues.add(Short.parseShort(basDevp.getQrCodeValue()));
+        }
+
+        //閬嶅巻鎵�鏈夋寚浠わ紝鍒ゆ柇鏄惁鏈夊埌鎻愬崌鏈哄彛鐨勬寚浠わ紝骞惰幏鍙栧埌杈捐鎻愬崌鏈哄彛鎵�闇�姝ュ簭
+        int step = 0;
+        ShuttleCommand command = null;
+        for (int i = 1; i < commands.size(); i++) {
+            command = commands.get(i);
+            if (qrCodeValues.contains(command.getDistCodeNum())) {
+                //瀛樺湪
+                step = i + 1;
+                break;
+            }
+        }
+
+        if (step == 0) {
+            //鏃犻渶鍚庣画妫�娴嬶紝鐩存帴鏀捐
+            return true;
+        }
+
+        //鍒ゆ柇涓嬩竴姝ユ槸鍚︿负鎻愬崌鏈哄彛
+        if (commandStep + 1 != step) {
+            //涓嬩竴姝ヤ笉鏄彁鍗囨満鍙o紝璺宠繃鍚庣画娴佺▼
+            return true;
+        }
+
+        //鎷垮埌鎻愬崌鏈虹嚎绋�
+        LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, 1);
+        if (liftThread == null) {
+            return false;
+        }
+        LiftProtocol liftProtocol = liftThread.getLiftProtocol();
+        if (liftProtocol == null) {
+            return false;
+        }
+
+        //鑾峰彇鍥涘悜绌挎杞﹀綋鍓嶆ゼ灞�
+        String shuttleLocNo = shuttleProtocol.getCurrentLocNo();//浜岀淮鐮佸搴斿簱浣嶅彿
+        Integer shuttleLocNoLev = Integer.parseInt(shuttleLocNo.substring(shuttleLocNo.length() - 2, shuttleLocNo.length()));//搴撲綅鍙峰搴斿眰楂�
+
+        //绋嬪簭璧板埌杩欙紝琛ㄧず鎻愬崌鏈哄彲鑳戒竴鐩村氨鍦ㄥ綋鍓嶅眰锛屽彲鑳界粡杩囦簡绉诲姩鍒拌揪浜嗚灞�
+        if (liftProtocol.getProtocolStatusType() == LiftProtocolStatusType.WAITING) {
+            //鎻愬崌鏈虹瓑寰呯‘璁�
+            //璁剧疆鎻愬崌鏈轰负绌洪棽鐘舵��
+            liftProtocol.setProtocolStatus(LiftProtocolStatusType.IDLE);
+            //浠诲姟鍙锋竻闆�
+            liftProtocol.setTaskNo((short) 0);
+            //鏍囪澶嶄綅
+            liftProtocol.setPakMk(true);
+            //浠诲姟鎸囦护娓呴浂
+            liftProtocol.setAssignCommand(null);
+            //鎻愬崌鏈鸿В閿�
+            liftProtocol.setLiftLock(false);
+        }
+
+        //鍒ゆ柇鎻愬崌鏈烘槸鍚﹀湪鐩爣妤煎眰
+        if (liftProtocol.getLev().intValue() == shuttleLocNoLev) {
+            //鍚屼竴灞傦紝鐩存帴鏀捐
+            return true;
+        }
+
+        //鎻愬崌鏈哄拰绌挎杞﹀浜庝笉鍚屾ゼ灞傦紝闇�瑕佽繘琛岃皟搴�
+        if (!liftProtocol.isIdle()) {
+            //鎻愬崌鏈轰笉鏄┖闂�
+            return false;
+        }
+
+        //缁欐彁鍗囨満鍒嗛厤浠诲姟
+        liftProtocol.setLiftLock(true);//閿佸畾鎻愬崌鏈�
+        liftProtocol.setTaskNo(shuttleProtocol.getTaskNo());//璁剧疆浠诲姟鍙�
+        liftProtocol.setShuttleNo(shuttleProtocol.getShuttleNo());//璁剧疆鍥涘悜绌挎杞﹀彿
+        liftProtocol.setProtocolStatus(LiftProtocolStatusType.WORKING);//璁剧疆鎻愬崌鏈虹姸鎬佷负宸ヤ綔涓�
+        liftProtocol.setSecurityMk(true);//鏍囪缃负true锛岄槻姝㈠叾浠栦换鍔″崰鐢ㄥ綋鍓嶆彁鍗囨満
+        map.put("liftSecurityMk", true);//鏍囪缃负true锛岄槻姝㈠叾浠栦换鍔″崰鐢ㄥ綋鍓嶆彁鍗囨満
+        //浠诲姟鏁版嵁淇濆瓨鍒皉edis
+        redisUtil.set("wrk_no_" + assignCommand.getTaskNo(), JSON.toJSONString(map));
+
+        //鍛戒护list
+        ArrayList<LiftCommand> liftCommands = new ArrayList<>();
+        LiftCommand liftCommand = new LiftCommand();
+        liftCommand.setLiftNo(liftProtocol.getLiftNo());//鎻愬崌鏈哄彿
+        liftCommand.setTaskNo(liftProtocol.getTaskNo());//浠诲姟鍙�
+        liftCommand.setRun((short) 1);//鍗囬檷
+        liftCommand.setDistPosition(shuttleLocNoLev.shortValue());//鐩爣妤煎眰(绌挎杞︽墍鍦ㄦゼ灞�)
+        liftCommand.setLiftLock(true);//閿佸畾鎻愬崌鏈�
+        liftCommands.add(liftCommand);//灏嗗懡浠ゆ坊鍔犺繘list
+
+        LiftAssignCommand liftAssignCommand = new LiftAssignCommand();
+        liftAssignCommand.setCommands(liftCommands);
+        liftAssignCommand.setLiftNo(liftProtocol.getLiftNo());
+        liftAssignCommand.setTaskNo(liftProtocol.getTaskNo());
+        //涓嬪彂浠诲姟
+        MessageQueue.offer(SlaveType.Lift, liftProtocol.getLiftNo().intValue(), new Task(3, liftAssignCommand));
+
+        return false;
+    }
+
+    /**
      * 澶嶄綅骞跺皾璇曚慨澶嶉敊璇�
      */
     private boolean reset(ShuttleAssignCommand assignCommand) {

--
Gitblit v1.9.1