From 08c96e4b797573fd64b42a52a2f9b9805d59d3e3 Mon Sep 17 00:00:00 2001
From: Junjie <xjj@123>
Date: 星期日, 07 四月 2024 14:03:54 +0800
Subject: [PATCH] #

---
 zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/utils/ShuttleDispatcher.java |   63 +++++++++++++++++++++++++++++++
 1 files changed, 63 insertions(+), 0 deletions(-)

diff --git a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/utils/ShuttleDispatcher.java b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/utils/ShuttleDispatcher.java
index 778a328..cac25e6 100644
--- a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/utils/ShuttleDispatcher.java
+++ b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/utils/ShuttleDispatcher.java
@@ -1,13 +1,18 @@
 package com.zy.asrs.wcs.core.utils;
 
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.zy.asrs.framework.common.Cools;
 import com.zy.asrs.framework.common.SnowflakeIdWorker;
 import com.zy.asrs.framework.exception.CoolException;
+import com.zy.asrs.wcs.core.entity.BasShuttle;
 import com.zy.asrs.wcs.core.entity.Task;
 import com.zy.asrs.wcs.core.kernel.AnalyzeService;
 import com.zy.asrs.wcs.core.model.NavigateNode;
 import com.zy.asrs.wcs.core.model.enums.LiftCodeType;
 import com.zy.asrs.wcs.core.model.enums.NavigationMapType;
+import com.zy.asrs.wcs.core.service.BasShuttleService;
 import com.zy.asrs.wcs.core.service.TaskService;
 import com.zy.asrs.wcs.rcs.cache.SlaveConnection;
 import com.zy.asrs.wcs.rcs.entity.Device;
@@ -48,6 +53,8 @@
     private DeviceService deviceService;
     @Autowired
     private DeviceTypeService deviceTypeService;
+    @Autowired
+    private BasShuttleService basShuttleService;
 
     public ShuttleThread queryShuttleWhichConvenient(Task task, Integer liftNo) {
         String locNo = taskService.judgeInbound(task) ? task.getDestLoc() : task.getOriginLoc();
@@ -169,5 +176,61 @@
 //        return wrkCharge;
 //    }
 
+    /**
+     * 鎼滅储閬胯搴撲綅锛岄�氳繃灏忚溅鍙峰拰鐩爣搴撲綅
+     */
+    public String searchStandByLocNo(Integer shuttleNo, Long hostId, String locNo) {
+        BasShuttle basShuttle = basShuttleService.getOne(new LambdaQueryWrapper<BasShuttle>()
+                .eq(BasShuttle::getShuttleNo, shuttleNo)
+                .eq(BasShuttle::getHostId, hostId));
+        if (basShuttle == null) {
+            throw new CoolException("灏忚溅鍩虹鏁版嵁涓嶅瓨鍦�");
+        }
+
+        String idleLoc = basShuttle.getIdleLoc();
+        if (Cools.isEmpty(idleLoc)) {
+            throw new CoolException("灏忚溅閬胯鏁版嵁涓嶅瓨鍦�");
+        }
+
+        int lev = Utils.getLev(locNo);//褰撳墠妤煎眰
+        JSONArray standbyLoc = JSON.parseArray(idleLoc);
+        if (lev > standbyLoc.size()) {
+            throw new CoolException("閬胯鏁版嵁寮傚父");
+        }
+
+        Object object = standbyLoc.get(lev - 1);
+        List<String> locs = JSON.parseArray(object.toString(), String.class);
+        if (locs.isEmpty()) {
+            throw new CoolException("閬胯鏁版嵁涓虹┖");
+        }
+
+        Integer finalDistance = ShuttleDispatcher.INF;
+        String recentLoc = null;
+        for (String loc : locs) {
+            //褰撳墠绌挎杞﹀埌閬胯浣嶈绠�
+            List<NavigateNode> currentShuttlePath = NavigateUtils.calc(
+                    locNo
+                    , loc
+                    , NavigationMapType.NORMAL.id
+                    , Utils.getShuttlePoints(shuttleNo, lev)
+            );//浣跨敤姝e父閫氶亾鍦板浘
+            if (currentShuttlePath == null) {
+                continue;
+            }
+
+            Integer currDistance = NavigateUtils.getOriginPathAllDistance(currentShuttlePath);//璁$畻褰撳墠璺緞琛岃蛋鎬昏窛绂�
+            if (currDistance < finalDistance) {
+                finalDistance = currDistance;
+                recentLoc = loc;
+            }
+        }
+
+        if (recentLoc == null) {
+            throw new CoolException("鎼滅储閬胯浣嶇疆澶辫触");
+        }
+
+        return recentLoc;
+    }
+
 
 }

--
Gitblit v1.9.1