From a7d5e6c4a45ca1f7bb1560ef4e76f4c1680c41db Mon Sep 17 00:00:00 2001
From: Junjie <xjj@123>
Date: 星期六, 18 五月 2024 10:43:29 +0800
Subject: [PATCH] #

---
 zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/utils/ShuttleDispatcher.java |   56 +++++++++++++++++++++++---------------------------------
 1 files changed, 23 insertions(+), 33 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 58d0e4b..19b2732 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
@@ -6,33 +6,24 @@
 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.Motion;
-import com.zy.asrs.wcs.core.entity.Task;
-import com.zy.asrs.wcs.core.entity.TaskCtg;
+import com.zy.asrs.wcs.core.entity.*;
 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.DeviceCtgType;
 import com.zy.asrs.wcs.core.model.enums.NavigationMapType;
 import com.zy.asrs.wcs.core.model.enums.TaskStsType;
-import com.zy.asrs.wcs.core.service.BasShuttleService;
-import com.zy.asrs.wcs.core.service.TaskCtgService;
-import com.zy.asrs.wcs.core.service.TaskService;
+import com.zy.asrs.wcs.core.service.*;
 import com.zy.asrs.wcs.rcs.News;
 import com.zy.asrs.wcs.rcs.cache.SlaveConnection;
 import com.zy.asrs.wcs.rcs.entity.Device;
-import com.zy.asrs.wcs.rcs.entity.DeviceType;
 import com.zy.asrs.wcs.rcs.model.enums.SlaveType;
 import com.zy.asrs.wcs.rcs.model.protocol.ShuttleProtocol;
 import com.zy.asrs.wcs.rcs.service.DeviceService;
-import com.zy.asrs.wcs.rcs.service.DeviceTypeService;
-import com.zy.asrs.wcs.core.service.MotionService;
 import com.zy.asrs.wcs.rcs.thread.ShuttleThread;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
-import java.util.Date;
-import java.util.List;
+import java.util.*;
 
 /**
  * Created by vincent on 2023/10/12
@@ -49,8 +40,6 @@
     private LiftDispatcher liftDispatcher;
     @Autowired
     private SnowflakeIdWorker snowflakeIdWorker;
-//    @Autowired
-//    private CommonService commonService;
     @Autowired
     private AnalyzeService analyzeService;
     @Autowired
@@ -58,27 +47,19 @@
     @Autowired
     private DeviceService deviceService;
     @Autowired
-    private DeviceTypeService deviceTypeService;
-    @Autowired
     private BasShuttleService basShuttleService;
     @Autowired
     private TaskCtgService taskCtgService;
+    @Autowired
+    private ShuttleStandbyService shuttleStandbyService;
 
-    public ShuttleThread queryShuttleWhichConvenient(Task task, Integer liftNo) {
+    public synchronized ShuttleThread searchIdleShuttle(Task task) {
         String locNo = taskService.judgeInbound(task) ? task.getDestLoc() : task.getOriginLoc();
         ShuttleThread resThread = null;
         Integer finalDistance = ShuttleDispatcher.INF;
 
-        DeviceType deviceType = deviceTypeService.getOne(new LambdaQueryWrapper<DeviceType>()
-                .eq(DeviceType::getHostId, task.getHostId())
-                .eq(DeviceType::getStatus, 1)
-                .eq(DeviceType::getFlag, String.valueOf(SlaveType.Shuttle)));
-        if (deviceType == null) {
-            throw new CoolException("璁惧绫诲瀷涓嶅瓨鍦�");
-        }
-
         List<Device> list = deviceService.list(new LambdaQueryWrapper<Device>()
-                .eq(Device::getDeviceType, deviceType.getId())
+                .eq(Device::getDeviceType, DeviceCtgType.SHUTTLE.val())
                 .eq(Device::getHostId, task.getHostId())
                 .eq(Device::getStatus, 1));
 
@@ -112,10 +93,22 @@
                 break;
             }
 
-            String targetLocNo = LiftCodeType.getStandbyLocNo(liftNo, currentLev);//榛樿鍒版彁鍗囨満寰呮満浣�
+            String targetLocNo = null;//榛樿鍒版彁鍗囨満寰呮満浣�
             // 鍚屾ゼ灞傜洿鎺ヨ绠楀埌鐩爣搴撲綅
             if (currentLev == Utils.getLev(locNo)) {
                 targetLocNo = locNo;
+            }else {
+                Device recentTransferLift = Utils.getRecentTransferLift(locNo, Integer.parseInt(device.getDeviceNo()));
+                if (recentTransferLift == null) {
+                    continue;
+                }
+
+                //鑾峰彇灏忚溅妤煎眰鎻愬崌鏈哄緟鏈轰綅
+                ShuttleStandby shuttleStandby = shuttleStandbyService.getOne(new LambdaQueryWrapper<ShuttleStandby>()
+                        .eq(ShuttleStandby::getDeviceId, recentTransferLift.getId())
+                        .eq(ShuttleStandby::getDeviceLev, currentLev)
+                        .eq(ShuttleStandby::getStatus, 1));
+                targetLocNo = shuttleStandby.getDeviceLoc();
             }
 
             //褰撳墠绌挎杞︾嚎绋嬪埌褰撳墠杞﹀瓙鎵�鍦ㄦゼ灞傜殑鎻愬崌鏈哄彛璺濈
@@ -171,9 +164,6 @@
             return null;
         }
 
-        //鑾峰彇閬胯浣嶇疆
-        String standByLocNo = this.searchStandByLocNo(Integer.valueOf(device.getDeviceNo()), device.getHostId(), shuttleThread.getStatus().getCurrentLocNo());
-
         Task task = new Task();
         task.setUuid(String.valueOf(snowflakeIdWorker.nextId()));
         task.setTaskNo(String.valueOf(Utils.getTaskNo("MOVE")));
@@ -183,7 +173,7 @@
         task.setOriginSite(null);
         task.setOriginLoc(null);
         task.setDestSite(null);
-        task.setDestLoc(standByLocNo); // 閬胯浣嶇疆
+        task.setDestLoc(locNo); // 杩佺Щ浣嶇疆
         task.setIoTime(new Date());
         task.setStartTime(new Date());
         task.setHostId(device.getHostId());
@@ -196,7 +186,7 @@
             News.error("淇濆瓨{}鍙峰洓鍚戠┛姊溅杩佺Щ浠诲姟澶辫触!!!", device.getDeviceNo());
             return null;
         }
-        motionService.batchInsert(motionList, task.getUuid(), Integer.valueOf(task.getTaskNo()));
+        motionService.batchInsert(motionList, task.getUuid(), Integer.valueOf(task.getTaskNo()), device.getHostId());
 
         task.setTaskSts(TaskStsType.ANALYZE_MOVE.sts);
 

--
Gitblit v1.9.1