From 5c0622d48c825ca4b75f63dda78d51ed75bc7a2f Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@163.com>
Date: 星期五, 12 四月 2024 11:04:19 +0800
Subject: [PATCH] #

---
 zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/thread/impl/SurayShuttleThread.java |  136 +++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 131 insertions(+), 5 deletions(-)

diff --git a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/thread/impl/SurayShuttleThread.java b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/thread/impl/SurayShuttleThread.java
index 75dd1fd..d9930f0 100644
--- a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/thread/impl/SurayShuttleThread.java
+++ b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/thread/impl/SurayShuttleThread.java
@@ -7,15 +7,20 @@
 import com.zy.asrs.framework.common.DateUtils;
 import com.zy.asrs.framework.common.SpringUtils;
 import com.zy.asrs.framework.exception.CoolException;
+import com.zy.asrs.wcs.common.ExecuteSupport;
+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.ShuttleCommand;
+import com.zy.asrs.wcs.core.model.command.ShuttleRedisCommand;
 import com.zy.asrs.wcs.core.model.enums.ShuttleCommandModeType;
 import com.zy.asrs.wcs.core.model.enums.ShuttleRunDirection;
+import com.zy.asrs.wcs.core.service.BasShuttleService;
 import com.zy.asrs.wcs.core.service.LocService;
 import com.zy.asrs.wcs.core.utils.NavigateUtils;
 import com.zy.asrs.wcs.rcs.News;
 import com.zy.asrs.wcs.rcs.cache.OutputQueue;
+import com.zy.asrs.wcs.rcs.constant.DeviceRedisConstant;
 import com.zy.asrs.wcs.rcs.entity.DeviceDataLog;
 import com.zy.asrs.wcs.rcs.model.enums.ShuttleProtocolStatusType;
 import com.zy.asrs.wcs.rcs.model.enums.SlaveType;
@@ -99,12 +104,17 @@
                 //----------璇诲彇鍥涘悜绌挎杞︾姸鎬�-----------
                 //灏忚溅璁惧鐘舵��
                 Integer deviceStatus = data.getInteger("deviceStatus");
+                if (deviceStatus == 255) {
+                    //绂荤嚎
+                    shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.OFFLINE);
+                }
                 shuttleProtocol.setDeviceStatus(deviceStatus);
                 //褰撳墠浜岀淮鐮�
                 shuttleProtocol.setCurrentCode(data.getString("groundCode") == null ? "0" : data.getString("groundCode"));
                 //鐢垫睜鐢甸噺
                 shuttleProtocol.setBatteryPower(data.getString("battery") == null ? "0%" : data.getString("battery"));
-
+                //鏁呴殰
+                shuttleProtocol.setErrorCode(deviceStatus == 6 ? "1" : "0");
 
                 //鏄惁椤跺崌
                 shuttleProtocol.setHasLift(data.getInteger("palletStatus") == 1 ? true : false);
@@ -128,10 +138,10 @@
                     shuttleProtocol.setPakMk(true);
                 }
 
-//                if (shuttleProtocol.getProtocolStatusType() == null && shuttleProtocol.getDeviceStatus().intValue() == ShuttleDeviceStatusType.IDLE.id) {
-//                    //灏忚溅绌洪棽鐘舵�併�佸皬杞︿换鍔$姸鎬佷负鏈煡锛岃瀹氭浘绂荤嚎杩囷紝闇�瑕佸浣嶆垚绌洪棽
-//                    shuttleProtocol.setProtocolStatusType(ShuttleProtocolStatusType.IDLE);
-//                }
+                if (shuttleProtocol.getProtocolStatusType() == null && shuttleProtocol.getDeviceStatus().intValue() == 3) {
+                    //灏忚溅绌洪棽鐘舵�併�佸皬杞︿换鍔$姸鎬佷负鏈煡锛岃瀹氭浘绂荤嚎杩囷紝闇�瑕佸浣嶆垚绌洪棽
+                    shuttleProtocol.setProtocolStatusType(ShuttleProtocolStatusType.IDLE);
+                }
 
                 if (System.currentTimeMillis() - shuttleProtocol.getDeviceDataLog() > 1000 * 5) {
                     //閲囬泦鏃堕棿瓒呰繃5s锛屼繚瀛樹竴娆℃暟鎹褰�
@@ -148,6 +158,30 @@
 
                     //鏇存柊閲囬泦鏃堕棿
                     shuttleProtocol.setDeviceDataLog(System.currentTimeMillis());
+                }
+
+                //灏嗗洓鍚戠┛姊溅鐘舵�佷繚瀛樿嚦鏁版嵁搴�
+                BasShuttleService shuttleService = SpringUtils.getBean(BasShuttleService.class);
+                BasShuttle basShuttle = shuttleService.getOne(new LambdaQueryWrapper<BasShuttle>()
+                        .eq(BasShuttle::getShuttleNo, device.getDeviceNo())
+                        .eq(BasShuttle::getHostId, device.getHostId()));
+                if (basShuttle == null) {
+                    basShuttle = new BasShuttle();
+                    //鍥涘悜绌挎杞﹀彿
+                    basShuttle.setShuttleNo(Integer.valueOf(device.getDeviceNo()));
+                    basShuttle.setStatus(1);
+                    basShuttle.setDeleted(0);
+                    basShuttle.setHostId(device.getHostId());
+                    shuttleService.save(basShuttle);
+                }
+                //浠诲姟鍙�
+                basShuttle.setTaskNo(shuttleProtocol.getTaskNo().intValue());
+                //淇敼鏃堕棿
+                basShuttle.setUpdateTime(new Date());
+                //璁惧鐘舵��
+                basShuttle.setProtocol(JSON.toJSONString(shuttleProtocol));
+                if (shuttleService.updateById(basShuttle)) {
+                    OutputQueue.SHUTTLE.offer(MessageFormat.format("銆恵0}銆慬id:{1}] <<<<< 瀹炴椂鏁版嵁鏇存柊鎴愬姛",DateUtils.convert(new Date()), device.getDeviceNo()));
                 }
             } else {
                 OutputQueue.SHUTTLE.offer(MessageFormat.format("銆恵0}銆憑1}璇诲彇鍥涘悜绌挎杞︾姸鎬佷俊鎭け璐�", DateUtils.convert(new Date()), device.getDeviceNo()));
@@ -340,6 +374,16 @@
 
     @Override
     public boolean isIdle() {
+        return this.isIdle(null);
+    }
+
+    @Override
+    public boolean isIdle(ExecuteSupport support) {
+        if (null != support) {
+            if (!support.judgement()) {
+                return false;
+            }
+        }
         if (this.shuttleProtocol.getIdle() == null
                 || this.shuttleProtocol.getPakMk() == null
                 || this.shuttleProtocol.getErrorCode() == null
@@ -357,6 +401,88 @@
     }
 
     @Override
+    public boolean isRequireCharge() {
+        if (this.shuttleProtocol.getIdle() == null
+                || this.shuttleProtocol.getPakMk() == null
+                || this.shuttleProtocol.getErrorCode() == null
+                || this.shuttleProtocol.getProtocolStatus() == null
+        ) {
+            return false;
+        }
+
+        boolean res = this.shuttleProtocol.getIdle()
+                && this.shuttleProtocol.getPakMk()
+                && this.shuttleProtocol.getErrorCode().equals("0")
+                && this.shuttleProtocol.getProtocolStatus() == ShuttleProtocolStatusType.IDLE.id
+                ;
+        if (!res) {
+            return res;
+        } else {
+            // 鐢甸噺灏忎簬闃堝�奸渶瑕佽繘琛屽厖鐢�
+            try {
+                BasShuttleService shuttleService = SpringUtils.getBean(BasShuttleService.class);
+                if (shuttleService == null) {
+                    return false;
+                }
+                BasShuttle basShuttle = shuttleService.getById(this.device.getDeviceNo());
+                if (basShuttle == null) {
+                    return false;
+                }
+                Integer chargeLine = basShuttle.getChargeLine();
+                if (chargeLine == null) {
+                    return false;
+                }
+                return Integer.valueOf(this.shuttleProtocol.getBatteryPower()) < chargeLine;
+            } catch (Exception e) {
+                News.error("fail", e);
+                return false;
+            }
+        }
+    }
+
+    @Override
+    public boolean isCharging() {
+        if (this.shuttleProtocol.getDeviceStatus() == null) {
+            return false;
+        }
+
+        if (this.shuttleProtocol.getDeviceStatus() == 5 || this.shuttleProtocol.getDeviceStatus() == 13) {
+            //鍏呯數涓拰鐢垫睜鍧囪  =銆� 鍏呯數
+            return true;
+        }
+        return false;
+    }
+
+    @Override
+    public boolean isChargingCompleted() {
+        if (this.shuttleProtocol.getBatteryPower() == null) {
+            return false;
+        }
+
+        if (Integer.valueOf(this.shuttleProtocol.getBatteryPower()) >= 100) {
+            return true;
+        }
+        return false;
+    }
+
+    @Override
+    public List<NavigateNode> getMoveAdvancePath() {
+        ArrayList<NavigateNode> path = new ArrayList<>();
+        if (shuttleProtocol.getTaskNo() != 0) {
+            //瀛樺湪浠诲姟锛岃幏鍙栨寚浠�
+            Object object = redisUtil.get(DeviceRedisConstant.SHUTTLE_FLAG + shuttleProtocol.getTaskNo());
+            if (object != null) {
+                ShuttleRedisCommand redisCommand = JSON.parseObject(object.toString(), ShuttleRedisCommand.class);
+                List<NavigateNode> nodes = redisCommand.getAssignCommand().getNodes();//绌挎杞﹂璁¤矾寰�
+                if (!nodes.isEmpty()) {
+                    path.addAll(nodes);
+                }
+            }
+        }
+        return path;
+    }
+
+    @Override
     public ShuttleCommand getMoveCommand(Integer taskNo, String startCodeNum, String distCodeNum, Integer allDistance, Integer runDirection, Integer runSpeed) {
         HashMap<String, Object> body = new HashMap<>();
         body.put("messageName", "runOrder");

--
Gitblit v1.9.1