From c036b0582e39b53516d88f26df587b5a61c4b2f2 Mon Sep 17 00:00:00 2001
From: Junjie <xjj@123>
Date: 星期三, 17 四月 2024 10:32:47 +0800
Subject: [PATCH] #

---
 zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/kernel/command/ShuttleCommandService.java |   74 +++++++++++++++----------------------
 1 files changed, 30 insertions(+), 44 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 1ef90fd..e799b7b 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
@@ -1,10 +1,12 @@
 package com.zy.asrs.wcs.core.kernel.command;
 
+import com.alibaba.fastjson.JSON;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.zy.asrs.framework.common.Cools;
 import com.zy.asrs.framework.exception.CoolException;
 import com.zy.asrs.wcs.core.action.LiftAction;
 import com.zy.asrs.wcs.core.action.ShuttleAction;
+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.ShuttleAssignCommand;
@@ -28,10 +30,7 @@
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Objects;
-import java.util.Optional;
+import java.util.*;
 
 /**
  * Created by vincent on 2023/10/23
@@ -82,9 +81,11 @@
 
         ShuttleAssignCommand assignCommand = new ShuttleAssignCommand();
         assignCommand.setShuttleNo(deviceNo);
-        assignCommand.setTaskNo(motion.getWrkNo());
+        assignCommand.setTaskNo(motion.getTaskNo());
+        assignCommand.setDeviceTaskNo(shuttleThread.generateDeviceTaskNo(motion.getTaskNo(), MotionCtgType.get(motion.getMotionCtgEl())));
         assignCommand.setSourceLocNo(motion.getOrigin());
         assignCommand.setLocNo(motion.getTarget());
+        assignCommand.setDeviceId(Integer.parseInt(motion.getDevice()));
 
         List<ShuttleCommand> shuttleCommands = new ArrayList<>();
         ShuttleTaskModeType shuttleTaskModeType = null;
@@ -97,7 +98,7 @@
                 // 濡傛灉宸茬粡鍦ㄥ綋鍓嶆潯鐮佸垯杩囨护
                 if (String.valueOf(shuttleProtocol.getCurrentCode()).equals(locService.getOne(new LambdaQueryWrapper<Loc>()
                         .eq(Loc::getLocNo, motion.getTarget())
-                        .eq(Loc::getHostId, motion.getHostId())).getCode())) {
+                            .eq(Loc::getHostId, motion.getHostId())).getCode())) {
                     return true;
                 }
                 shuttleCommands = this.shuttleAssignCommand(motion.getOrigin(), motion.getTarget(), NavigationMapType.NORMAL.id, assignCommand, shuttleThread);
@@ -106,12 +107,12 @@
             case SHUTTLE_MOVE_LIFT_PALLET://绌挎杞﹂《鍗囧苟绉诲姩
                 shuttleCommands = this.shuttleAssignCommand(motion.getOrigin(), motion.getTarget(), NavigationMapType.DFX.id, assignCommand, shuttleThread);
                 shuttleTaskModeType = ShuttleTaskModeType.PAK_IN;
-                shuttleCommands.add(0, shuttleThread.getLiftCommand(motion.getWrkNo(), true));
+                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;
-                shuttleCommands.add(shuttleCommands.size(), shuttleThread.getLiftCommand(motion.getWrkNo(), false));
+                shuttleCommands.add(shuttleCommands.size(), shuttleThread.getLiftCommand(motion.getTaskNo(), false));
                 break;
             case SHUTTLE_MOVE_FROM_LIFT://鍑烘彁鍗囨満
                 // 鍒ゆ柇鎻愬崌鏈虹姸鎬�
@@ -151,7 +152,7 @@
 //                }
 
                 //鍒ゆ柇鎻愬崌鏈哄伐浣滃彿鏄惁鍜屽綋鍓嶄换鍔$浉鍚�
-                if (liftProtocol.getTaskNo().intValue() != motion.getWrkNo()) {
+                if (liftProtocol.getTaskNo().intValue() != motion.getTaskNo()) {
                     return false;
                 }
 
@@ -188,7 +189,7 @@
 //                }
 
                 //鍒ゆ柇鎻愬崌鏈哄伐浣滃彿鏄惁鍜屽綋鍓嶄换鍔$浉鍚�
-                if (liftProtocol.getTaskNo().intValue() != motion.getWrkNo()) {
+                if (liftProtocol.getTaskNo().intValue() != motion.getTaskNo()) {
                     return false;
                 }
 
@@ -197,21 +198,21 @@
                 break;
             case SHUTTLE_CHARGE_ON://鍏呯數寮�
                 shuttleTaskModeType = ShuttleTaskModeType.CHARGE;
-                shuttleCommands.add(shuttleThread.getChargeCommand(motion.getWrkNo(), true));
+                shuttleCommands.add(shuttleThread.getChargeCommand(motion.getTaskNo(), true));
                 assignCommand.setCharge(Boolean.TRUE);
                 break;
             case SHUTTLE_CHARGE_OFF://鍏呯數鍏�
                 shuttleTaskModeType = ShuttleTaskModeType.CHARGE;
-                shuttleCommands.add(shuttleThread.getChargeCommand(motion.getWrkNo(), false));
+                shuttleCommands.add(shuttleThread.getChargeCommand(motion.getTaskNo(), false));
                 assignCommand.setCharge(Boolean.TRUE);
                 break;
             case SHUTTLE_PALLET_LIFT://鎵樼洏椤跺崌
                 shuttleTaskModeType = ShuttleTaskModeType.PALLET_LIFT;
-                shuttleCommands.add(shuttleThread.getLiftCommand(motion.getWrkNo(), true));
+                shuttleCommands.add(shuttleThread.getLiftCommand(motion.getTaskNo(), true));
                 break;
             case SHUTTLE_PALLET_DOWN://鎵樼洏涓嬮檷
                 shuttleTaskModeType = ShuttleTaskModeType.PALLET_DOWN;
-                shuttleCommands.add(shuttleThread.getLiftCommand(motion.getWrkNo(), false));
+                shuttleCommands.add(shuttleThread.getLiftCommand(motion.getTaskNo(), false));
                 break;
             default:
                 throw new CoolException(motion.getMotionCtgEl() + "娌℃湁鎸囧畾浠诲姟浣滀笟娴佺▼锛侊紒锛�");
@@ -245,16 +246,16 @@
             return false;
         }
 
-        if (shuttleProtocol.getTaskNo() != 0 && shuttleProtocol.getTaskNo().intValue() != motion.getWrkNo()) {
+        if (shuttleProtocol.getTaskNo() != 0 && shuttleProtocol.getTaskNo().intValue() != motion.getTaskNo()) {
             return false;
         }
 
         //鍏呯數浠诲姟
         if (Objects.requireNonNull(MotionCtgType.get(motion.getMotionCtgEl())).equals(MotionCtgType.SHUTTLE_CHARGE_ON)) {
             // 澶嶄綅绌挎杞�
-            shuttleProtocol.setTaskNo(0);
-            shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.IDLE);
-            shuttleProtocol.setPakMk(true);
+            shuttleThread.setSyncTaskNo(0);
+            shuttleThread.setProtocolStatus(ShuttleProtocolStatusType.IDLE);
+            shuttleThread.setPakMk(true);
             return true;
         }
 
@@ -308,7 +309,7 @@
 //                }
 
                 //鍒ゆ柇鎻愬崌鏈哄伐浣滃彿鏄惁鍜屽綋鍓嶄换鍔$浉鍚�
-                if (liftProtocol.getTaskNo().intValue() != motion.getWrkNo()) {
+                if (liftProtocol.getTaskNo().intValue() != motion.getTaskNo()) {
                     return false;
                 }
 
@@ -323,23 +324,27 @@
         }
 
         // 澶嶄綅绌挎杞�
-        shuttleProtocol.setTaskNo(0);
-        shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.IDLE);
-        shuttleProtocol.setPakMk(true);
+        shuttleThread.setSyncTaskNo(0);
+        shuttleThread.setProtocolStatus(ShuttleProtocolStatusType.IDLE);
+        shuttleThread.setPakMk(true);
 
         return true;
     }
 
     public synchronized List<ShuttleCommand> shuttleAssignCommand(String startLocNo, String endLocNo, Integer mapType, ShuttleAssignCommand assignCommand, ShuttleThread shuttleThread) {
         //鑾峰彇灏忚溅绉诲姩閫熷害
-        Integer runSpeed = Optional.ofNullable(basShuttleService.getById(assignCommand.getShuttleNo()).getRunSpeed()).orElse(1000);
+        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)));
         if (nodeList == null) {
             News.error("{} dash {} can't find navigate path!", startLocNo, endLocNo);
             return null;
         }
-        List<NavigateNode> allNode = new ArrayList<>(nodeList);
+
+        List<NavigateNode> allNode = new ArrayList<>();
+        for (NavigateNode node : nodeList) {
+            allNode.add(node.clone());
+        }
 
         List<ShuttleCommand> commands = new ArrayList<>();
         //鑾峰彇鍒嗘璺緞
@@ -349,25 +354,6 @@
             //寮�濮嬭矾寰�
             NavigateNode startPath = nodes.get(0);
 
-            //涓棿璺緞
-            NavigateNode middlePath = null;
-            //閫氳繃xy鍧愭爣灏忚溅浜岀淮鐮�
-            String middleCodeNum = null;
-            Integer middleToDistDistance = null;//璁$畻涓棿鐐瑰埌鐩爣鐐硅璧拌窛绂�
-            if (nodes.size() > 10) {//涓鐮佷紶鍊掓暟绗笁涓�
-                //涓棿璺緞
-                middlePath = nodes.get(nodes.size() - 3);
-                //閫氳繃xy鍧愭爣灏忚溅浜岀淮鐮�
-                middleCodeNum = NavigatePositionConvert.xyToPosition(middlePath.getX(), middlePath.getY(), middlePath.getZ(), hostId);
-                middleToDistDistance = NavigateUtils.getMiddleToDistDistance(nodes, middlePath);//璁$畻涓棿鐐瑰埌鐩爣鐐硅璧拌窛绂�
-            } else if (nodes.size() > 5) {//涓鐮佷紶鍊掓暟绗簩涓�
-                //涓棿璺緞
-                middlePath = nodes.get(nodes.size() - 2);
-                //閫氳繃xy鍧愭爣灏忚溅浜岀淮鐮�
-                middleCodeNum = NavigatePositionConvert.xyToPosition(middlePath.getX(), middlePath.getY(), middlePath.getZ(), hostId);
-                middleToDistDistance = NavigateUtils.getMiddleToDistDistance(nodes, middlePath);//璁$畻涓棿鐐瑰埌鐩爣鐐硅璧拌窛绂�
-            }
-
             //鐩爣璺緞
             NavigateNode endPath = nodes.get(nodes.size() - 1);
             Integer allDistance = NavigateUtils.getCurrentPathAllDistance(nodes);//璁$畻褰撳墠璺緞琛岃蛋鎬昏窛绂�
@@ -376,7 +362,7 @@
             //閫氳繃xy鍧愭爣灏忚溅浜岀淮鐮�
             String distCodeNum = NavigatePositionConvert.xyToPosition(endPath.getX(), endPath.getY(), endPath.getZ(), hostId);
             //鑾峰彇绉诲姩鍛戒护
-            ShuttleCommand command = shuttleThread.getMoveCommand(assignCommand.getTaskNo().intValue(), startCodeNum, distCodeNum, allDistance, ShuttleRunDirection.get(startPath.getDirection()).id.intValue(), runSpeed);
+            ShuttleCommand command = shuttleThread.getMoveCommand(assignCommand.getDeviceTaskNo(), startCodeNum, distCodeNum, allDistance, ShuttleRunDirection.get(startPath.getDirection()).id.intValue(), runSpeed);
             command.setNodes(nodes);//灏嗚璧拌妭鐐规坊鍔犲埌姣忎竴姝ュ懡浠や腑
             commands.add(command);
         }

--
Gitblit v1.9.1