From 25b1f6699b46bb9413b8c6b98f32c20aa60394fd Mon Sep 17 00:00:00 2001
From: Junjie <xjj@123>
Date: 星期二, 03 十二月 2024 16:01:13 +0800
Subject: [PATCH] #算法优化

---
 zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/kernel/command/ShuttleCommandService.java |   77 ++++++++++++++++++++++++++++++--------
 1 files changed, 60 insertions(+), 17 deletions(-)

diff --git a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/kernel/command/ShuttleCommandService.java b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/kernel/command/ShuttleCommandService.java
index 5390f51..b58abda 100644
--- a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/kernel/command/ShuttleCommandService.java
+++ b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/kernel/command/ShuttleCommandService.java
@@ -15,6 +15,7 @@
 import com.zy.asrs.wcs.core.utils.*;
 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.model.enums.ShuttleProtocolStatusType;
 import com.zy.asrs.wcs.rcs.model.enums.SlaveType;
 import com.zy.asrs.wcs.rcs.model.protocol.LiftProtocol;
@@ -60,6 +61,10 @@
     private BasConveyorService basConveyorService;
     @Autowired
     private BasConveyorStaService basConveyorStaService;
+    @Autowired
+    private ShuttleDispatcher shuttleDispatcher;
+    @Autowired
+    private NavigateUtils navigateUtils;
 
     // 璁$畻
     public Boolean accept(Motion motion) {
@@ -68,6 +73,8 @@
         if (shuttleThread == null) {
             return false;
         }
+        Device shuttleDevice = shuttleThread.getDevice();
+
         ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
         if (null == shuttleProtocol) {
             return false;
@@ -120,7 +127,7 @@
                     return true;
                 }
                 shuttleCommands = this.shuttleAssignCommand(motion.getOrigin(), motion.getTarget(), NavigationMapType.NORMAL.id, assignCommand, shuttleThread);
-                shuttleTaskModeType = ShuttleTaskModeType.SHUTTLE_MOVE_LOC_NO;
+                shuttleTaskModeType = ShuttleTaskModeType.SHUTTLE_MOVE;
                 break;
             case SHUTTLE_TRANSPORT://绌挎杞﹁浇璐ц璧�
                 // 濡傛灉宸茬粡鍦ㄥ綋鍓嶆潯鐮佸垯杩囨护
@@ -131,6 +138,15 @@
                 }
                 shuttleCommands = this.shuttleAssignCommand(motion.getOrigin(), motion.getTarget(), NavigationMapType.DFX.id, assignCommand, shuttleThread);
                 shuttleTaskModeType = ShuttleTaskModeType.TRANSPORT;
+
+                if (motion.getReleaseLift() == 2) {//鎵ц涓噴鏀炬彁鍗囨満
+                    task.setLiftNo(0);
+                    task.setUpdateTime(new Date());
+                    if (!taskService.updateById(task)) {
+                        return false;
+                    }
+                }
+
                 break;
             case SHUTTLE_TRANSPORT_TO_CONVEYOR://绌挎杞﹁浇璐ц繘杈撻�佺嚎
                 BasConveyorSta originStaObj = basConveyorStaService.selectBySiteNo(motion.getDockNo());//鑾峰彇杈撻�佺珯鐐�
@@ -161,17 +177,17 @@
                         .eq(Loc::getHostId, motion.getHostId())).getCode())) {
                     return true;
                 }
-                shuttleCommands = this.shuttleAssignCommand(motion.getOrigin(), motion.getTarget(), NavigationMapType.NORMAL.id, assignCommand, shuttleThread);
-                shuttleTaskModeType = ShuttleTaskModeType.SHUTTLE_MOVE_LOC_NO;
+                shuttleCommands = this.shuttleAssignCommand(motion.getOrigin(), motion.getTarget(), NavigationMapType.DFX.id, assignCommand, shuttleThread);
+                shuttleTaskModeType = ShuttleTaskModeType.TRANSPORT_TO_CONVEYOR;
                 break;
             case SHUTTLE_MOVE_LIFT_PALLET://绌挎杞﹂《鍗囧苟绉诲姩
                 shuttleCommands = this.shuttleAssignCommand(motion.getOrigin(), motion.getTarget(), NavigationMapType.DFX.id, assignCommand, shuttleThread);
-                shuttleTaskModeType = ShuttleTaskModeType.PAK_IN;
+                shuttleTaskModeType = ShuttleTaskModeType.MOVE_PALLET_LIFT;
                 shuttleCommands.add(0, shuttleThread.getLiftCommand(motion.getTaskNo(), true));
                 break;
             case SHUTTLE_MOVE_DOWN_PALLET://绌挎杞︾Щ鍔ㄥ苟鎵樼洏涓嬮檷
                 shuttleCommands = this.shuttleAssignCommand(motion.getOrigin(), motion.getTarget(), NavigationMapType.DFX.id, assignCommand, shuttleThread);
-                shuttleTaskModeType = ShuttleTaskModeType.PAK_IN;
+                shuttleTaskModeType = ShuttleTaskModeType.MOVE_PALLET_DOWN;
                 shuttleCommands.add(shuttleCommands.size(), shuttleThread.getLiftCommand(motion.getTaskNo(), false));
                 break;
             case SHUTTLE_MOVE_FROM_LIFT://鍑烘彁鍗囨満
@@ -211,7 +227,7 @@
 //                }
 
                 shuttleCommands = this.shuttleInOutLiftCommand(motion.getOrigin(), motion.getTarget(), NavigationMapType.NORMAL.id, assignCommand, shuttleThread);
-                shuttleTaskModeType = ShuttleTaskModeType.SHUTTLE_MOVE_LOC_NO;
+                shuttleTaskModeType = ShuttleTaskModeType.MOVE_OUT_LIFT;
                 break;
             case SHUTTLE_MOVE_TO_LIFT://杩涙彁鍗囨満
                 // 鍒ゆ柇鎻愬崌鏈虹姸鎬�
@@ -247,16 +263,16 @@
 //                    return false;
 //                }
 
-                shuttleCommands = this.shuttleAssignCommand(motion.getOrigin(), motion.getTarget(), NavigationMapType.NORMAL.id, assignCommand, shuttleThread);
-                shuttleTaskModeType = ShuttleTaskModeType.SHUTTLE_MOVE_LOC_NO;
+                shuttleCommands = this.shuttleInOutLiftCommand(motion.getOrigin(), motion.getTarget(), NavigationMapType.NORMAL.id, assignCommand, shuttleThread);
+                shuttleTaskModeType = ShuttleTaskModeType.MOVE_TO_LIFT;
                 break;
             case SHUTTLE_CHARGE_ON://鍏呯數寮�
-                shuttleTaskModeType = ShuttleTaskModeType.CHARGE;
+                shuttleTaskModeType = ShuttleTaskModeType.CHARGE_ON;
                 shuttleCommands.add(shuttleThread.getChargeCommand(motion.getTaskNo(), true));
                 assignCommand.setCharge(Boolean.TRUE);
                 break;
             case SHUTTLE_CHARGE_OFF://鍏呯數鍏�
-                shuttleTaskModeType = ShuttleTaskModeType.CHARGE;
+                shuttleTaskModeType = ShuttleTaskModeType.CHARGE_OFF;
                 shuttleCommands.add(shuttleThread.getChargeCommand(motion.getTaskNo(), false));
                 assignCommand.setCharge(Boolean.TRUE);
                 break;
@@ -271,6 +287,21 @@
             case SHUTTLE_UPDATE_LOCATION://灏忚溅鍧愭爣鏇存柊
                 shuttleTaskModeType = ShuttleTaskModeType.SHUTTLE_UPDATE_LOCATION;
                 shuttleCommands.add(shuttleThread.getUpdateLocationCommand(motion.getTaskNo(), motion.getTarget()));
+                break;
+            case SHUTTLE_MOVE_STANDBY://绌挎杞︾Щ鍔ㄥ埌寰呮満浣�
+                shuttleTaskModeType = ShuttleTaskModeType.SHUTTLE_MOVE;
+
+                //鑾峰彇鍏ㄩ儴寰呮満浣�
+                List<String> standbyLocs = JSON.parseArray(motion.getTemp(), String.class);
+                //鑾峰彇鍙敤寰呮満浣�
+                String shuttleFromLiftStandbyLoc = shuttleDispatcher.searchAvailableLocNo(Integer.valueOf(shuttleDevice.getDeviceNo()), shuttleDevice.getHostId(), shuttleThread.getStatus().getCurrentLocNo(), standbyLocs);
+                shuttleCommands = this.shuttleAssignCommand(motion.getOrigin(), shuttleFromLiftStandbyLoc, NavigationMapType.NORMAL.id, assignCommand, shuttleThread);
+
+                //鏇存柊鍔ㄤ綔鍙敤寰呮満浣�
+                motion.setTarget(shuttleFromLiftStandbyLoc);
+                motion.setUpdateTime(new Date());
+                motionService.updateById(motion);
+
                 break;
             default:
                 throw new CoolException(motion.getMotionCtgEl() + "娌℃湁鎸囧畾浠诲姟浣滀笟娴佺▼锛侊紒锛�");
@@ -461,6 +492,19 @@
                     return false;
                 }
                 break;
+            case SHUTTLE_MOVE_STANDBY://绌挎杞︾Щ鍔ㄥ埌寰呮満浣�
+                if (!shuttleProtocol.getCurrentLocNo().equals(motion.getTarget())) {
+                    return false;
+                }
+
+                if (Optional.ofNullable(motion.getReleaseShuttle()).orElse(0) == 1) {//閲婃斁绌挎杞�
+                    task.setShuttleNo(0);
+                    task.setUpdateTime(new Date());
+                    if (!taskService.updateById(task)) {
+                        return false;
+                    }
+                }
+                break;
             default:
                 break;
         }
@@ -477,7 +521,7 @@
         //鑾峰彇灏忚溅绉诲姩閫熷害
         Integer runSpeed = Optional.ofNullable(basShuttleService.getOne(new LambdaQueryWrapper<BasShuttle>().eq(BasShuttle::getDeviceId, assignCommand.getDeviceId())).getRunSpeed()).orElse(1000);
         Long hostId = shuttleThread.getDevice().getHostId();
-        List<NavigateNode> nodeList = NavigateUtils.calc(startLocNo, endLocNo, mapType, Utils.getShuttlePoints(Integer.parseInt(shuttleThread.getDevice().getDeviceNo()), Utils.getLev(startLocNo)));
+        List<NavigateNode> nodeList = navigateUtils.calc(startLocNo, endLocNo, mapType, Utils.getShuttlePoints(Integer.parseInt(shuttleThread.getDevice().getDeviceNo()), Utils.getLev(startLocNo)));
         if (nodeList == null) {
             News.error("{} dash {} can't find navigate path!", startLocNo, endLocNo);
             return null;
@@ -490,7 +534,7 @@
 
         List<ShuttleCommand> commands = new ArrayList<>();
         //鑾峰彇鍒嗘璺緞
-        ArrayList<ArrayList<NavigateNode>> data = NavigateUtils.getSectionPath(nodeList);
+        ArrayList<ArrayList<NavigateNode>> data = navigateUtils.getSectionPath(nodeList);
         //灏嗘瘡涓�娈佃矾寰勫垎鎴恈ommand鎸囦护
         for (ArrayList<NavigateNode> nodes : data) {
             //寮�濮嬭矾寰�
@@ -498,7 +542,7 @@
 
             //鐩爣璺緞
             NavigateNode endPath = nodes.get(nodes.size() - 1);
-            Integer allDistance = NavigateUtils.getCurrentPathAllDistance(nodes);//璁$畻褰撳墠璺緞琛岃蛋鎬昏窛绂�
+            Integer allDistance = navigateUtils.getCurrentPathAllDistance(nodes);//璁$畻褰撳墠璺緞琛岃蛋鎬昏窛绂�
             //閫氳繃xy鍧愭爣灏忚溅浜岀淮鐮�
             String startCodeNum = NavigatePositionConvert.xyToPosition(startPath.getX(), startPath.getY(), startPath.getZ(), hostId);
             //閫氳繃xy鍧愭爣灏忚溅浜岀淮鐮�
@@ -530,11 +574,10 @@
             return null;//瑙i攣澶辫触
         }
 
-
         //鑾峰彇灏忚溅绉诲姩閫熷害
         Integer runSpeed = Optional.ofNullable(basShuttleService.getOne(new LambdaQueryWrapper<BasShuttle>().eq(BasShuttle::getDeviceId, assignCommand.getDeviceId())).getRunSpeed()).orElse(1000);
         Long hostId = shuttleThread.getDevice().getHostId();
-        List<NavigateNode> nodeList = NavigateUtils.calc(startLocNo, endLocNo, mapType, Utils.getShuttlePoints(Integer.parseInt(shuttleThread.getDevice().getDeviceNo()), Utils.getLev(startLocNo)));
+        List<NavigateNode> nodeList = navigateUtils.calc(startLocNo, endLocNo, mapType, Utils.getShuttlePoints(Integer.parseInt(shuttleThread.getDevice().getDeviceNo()), Utils.getLev(startLocNo)));
         if (nodeList == null) {
             News.error("{} dash {} can't find navigate path!", startLocNo, endLocNo);
             return null;
@@ -547,7 +590,7 @@
 
         List<ShuttleCommand> commands = new ArrayList<>();
         //鑾峰彇鍒嗘璺緞
-        ArrayList<ArrayList<NavigateNode>> data = NavigateUtils.getSectionPath(nodeList);
+        ArrayList<ArrayList<NavigateNode>> data = navigateUtils.getSectionPath(nodeList);
         //灏嗘瘡涓�娈佃矾寰勫垎鎴恈ommand鎸囦护
         for (ArrayList<NavigateNode> nodes : data) {
             //寮�濮嬭矾寰�
@@ -555,7 +598,7 @@
 
             //鐩爣璺緞
             NavigateNode endPath = nodes.get(nodes.size() - 1);
-            Integer allDistance = NavigateUtils.getCurrentPathAllDistance(nodes);//璁$畻褰撳墠璺緞琛岃蛋鎬昏窛绂�
+            Integer allDistance = navigateUtils.getCurrentPathAllDistance(nodes);//璁$畻褰撳墠璺緞琛岃蛋鎬昏窛绂�
             //閫氳繃xy鍧愭爣灏忚溅浜岀淮鐮�
             String startCodeNum = NavigatePositionConvert.xyToPosition(startPath.getX(), startPath.getY(), startPath.getZ(), hostId);
             //閫氳繃xy鍧愭爣灏忚溅浜岀淮鐮�

--
Gitblit v1.9.1