From e7ec0b5327724e06668160e00270edb75d59ef4b Mon Sep 17 00:00:00 2001
From: Junjie <xjj@123>
Date: 星期二, 16 四月 2024 15:23:08 +0800
Subject: [PATCH] #

---
 zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/kernel/AnalyzeService.java |  511 ++++++++++++++++++++++++++++++++------------------------
 1 files changed, 289 insertions(+), 222 deletions(-)

diff --git a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/kernel/AnalyzeService.java b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/kernel/AnalyzeService.java
index 9e0b818..0e3e5f2 100644
--- a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/kernel/AnalyzeService.java
+++ b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/kernel/AnalyzeService.java
@@ -3,11 +3,13 @@
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.zy.asrs.framework.common.Cools;
 import com.zy.asrs.wcs.core.domain.dto.MotionDto;
+import com.zy.asrs.wcs.core.entity.ShuttleStandby;
 import com.zy.asrs.wcs.core.entity.Task;
 import com.zy.asrs.wcs.core.model.enums.DeviceCtgType;
 import com.zy.asrs.wcs.core.model.enums.MotionCtgType;
 import com.zy.asrs.wcs.core.model.enums.TaskStsType;
 import com.zy.asrs.wcs.core.model.enums.WorkZoneType;
+import com.zy.asrs.wcs.core.service.ShuttleStandbyService;
 import com.zy.asrs.wcs.core.service.TaskService;
 import com.zy.asrs.wcs.core.utils.LiftDispatcher;
 import com.zy.asrs.wcs.core.utils.ShuttleDispatcher;
@@ -15,12 +17,12 @@
 import com.zy.asrs.wcs.rcs.cache.SlaveConnection;
 import com.zy.asrs.wcs.core.entity.Motion;
 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.LiftProtocol;
 import com.zy.asrs.wcs.rcs.model.protocol.ShuttleProtocol;
 import com.zy.asrs.wcs.core.service.MotionService;
 import com.zy.asrs.wcs.rcs.service.DeviceService;
-import com.zy.asrs.wcs.rcs.service.DeviceTypeService;
+import com.zy.asrs.wcs.rcs.thread.LiftThread;
 import com.zy.asrs.wcs.rcs.thread.ShuttleThread;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -46,12 +48,12 @@
     private ShuttleDispatcher shuttleDispatcher;
     @Autowired
     private LiftDispatcher liftDispatcher;
-    //    @Autowired
+//    @Autowired
 //    private ConveyorDispatcher conveyorDispatcher;
     @Autowired
     private DeviceService deviceService;
     @Autowired
-    private DeviceTypeService deviceTypeService;
+    private ShuttleStandbyService shuttleStandbyService;
 
     public List<Motion> generateMotion(Task task) {
         List<Motion> motionList = new ArrayList<>();
@@ -718,164 +720,189 @@
      */
     public List<Motion> generateChargeMotion(Task task) {
         List<Motion> motionList = new ArrayList<>();
-//        if (wrkCharge.getWrkSts() != WrkMastStsType.NEW_CHARGE.sts || wrkCharge.getIoType() != WrkIoTypeType.CHARGE.sts) {
-//            return motionList;
-//        }
-//
-//        // locNo
-//        String chargeLocNo = wrkCharge.getLocNo();
-//
-//        // lift
-//        Integer transferLiftNo = 2;
-//        SiemensLiftThread liftThread = (SiemensLiftThread) SlaveConnection.get(SlaveType.Lift, transferLiftNo);
-//        LiftProtocol liftProtocol = liftThread.getLiftProtocol();
-//        if (liftProtocol == null || liftProtocol.getLiftNo() == null) {
-//            return motionList;
-//        }
-//
-//        // shuttle
-//        Integer shuttleNo = wrkCharge.getShuttleNo();
-//        ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleNo);
-//        ShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol();
-//        if (shuttleProtocol == null || shuttleProtocol.getShuttleNo() == null) {
-//            return motionList;
-//        }
-//        if (!shuttleProtocol.isIdle()) {
-//            return motionList;
-//        }
-//
-//        //妫�娴嬬┛姊溅鏄惁鏈変换鍔$粦瀹�
-//        boolean shuttleResult = Utils.checkShuttleHasBinding(shuttleProtocol.getShuttleNo().intValue());
-//        if (shuttleResult) {
-//            //瀛樺湪浠诲姟锛岀姝㈣В鏋�
-//            return motionList;
-//        }
-//
-//        //妫�娴嬫彁鍗囨満鏄惁鏈変换鍔$粦瀹�
-//        boolean liftResult = Utils.checkLiftHasBinding(transferLiftNo);
-//        if (liftResult) {
-//            //瀛樺湪浠诲姟锛岀姝㈣В鏋�
-//            return motionList;
-//        }
-//
-//        String shuttleLocNo = shuttleProtocol.getCurrentLocNo();
-//
-//        //绌挎杞﹀埌鎻愬崌鏈哄簱浣嶅彿
-//        String liftLocNoTo = LiftCodeType.getLocNo(transferLiftNo, Utils.getLev(shuttleLocNo));
-//
-//        //绌挎杞﹀嚭鎻愬崌鏈哄簱浣嶅彿
-//        String liftLocNoFrom = LiftCodeType.getLocNo(transferLiftNo, Utils.getLev(wrkCharge.getLocNo()));
-//
-//        //绌挎杞﹀埌鎻愬崌鏈哄緟鏈轰綅搴撲綅鍙�
-//        String standbyLocNoTo = LiftCodeType.getStandbyLocNo(transferLiftNo, Utils.getLev(shuttleLocNo));
-//
-//        //绌挎杞﹀嚭鎻愬崌鏈哄緟鏈轰綅搴撲綅鍙�
-//        String standbyLocNoFrom = LiftCodeType.getStandbyLocNo(transferLiftNo, Utils.getLev(wrkCharge.getLocNo()));
-//
-//        // 鍒ゆ柇绌挎杞︽槸鍚﹀湪鍏呯數灞�
-//        if (Utils.getLev(shuttleLocNo) == Utils.getLev(chargeLocNo)) {
-//
-//            // 绌挎杞﹁蛋琛岃嚦鍏呯數妗╁簱浣�
-//            motionList.addAll(kernelService.shuttleMove(
-//                    MotionDto.build((dto -> {
-//                        dto.setShuttleNo(shuttleProtocol.getShuttleNo().intValue());
-//                        dto.setLocNo(shuttleLocNo);
-//                    })),
-//                    MotionDto.build((dto -> {
-//                        dto.setShuttleNo(shuttleProtocol.getShuttleNo().intValue());
-//                        dto.setLocNo(chargeLocNo);
-//                    })),
-//                    MotionCtgType.SHUTTLE_MOVE
-//            ));
-//
-//        } else {
-//
-//            // 绌挎杞﹁蛋琛岃嚦鎻愬崌鏈哄緟鏈轰綅
-//            motionList.addAll(kernelService.shuttleMove(
-//                    MotionDto.build((dto -> {
-//                        dto.setShuttleNo(shuttleProtocol.getShuttleNo().intValue());
-//                        dto.setLocNo(shuttleLocNo);
-//                    })),
-//                    MotionDto.build((dto -> {
-//                        dto.setShuttleNo(shuttleProtocol.getShuttleNo().intValue());
-//                        dto.setLocNo(standbyLocNoTo);
-//                    })),
-//                    MotionCtgType.SHUTTLE_MOVE
-//            ));
-//
-//            // 鎻愬崌鏈虹┖杞界Щ鍔ㄥ埌绌挎杞﹀眰
-//            motionList.addAll(kernelService.liftMove(
-//                    null
-//                    , MotionDto.build((dto -> {
-//                        dto.setLiftNo(transferLiftNo);
-//                        dto.setLev(Utils.getLev(shuttleLocNo));
-//                    }))
-//            ));
-//
-//            // 绌挎杞︽彁鍗囨満寰呮満浣嶈嚦鎻愬崌鏈哄簱浣�
-//            motionList.addAll(kernelService.shuttleMove(
-//                    MotionDto.build((dto -> {
-//                        dto.setShuttleNo(shuttleProtocol.getShuttleNo().intValue());
-//                        dto.setLocNo(standbyLocNoTo);
-//                    })),
-//                    MotionDto.build((dto -> {
-//                        dto.setShuttleNo(shuttleProtocol.getShuttleNo().intValue());
-//                        dto.setLiftNo(transferLiftNo);
-//                        dto.setLocNo(liftLocNoTo);
-//                    })),
-//                    MotionCtgType.SHUTTLE_MOVE_TO_LIFT
-//            ));
-//
-//            // 鎻愬崌鏈烘惉杞� 鑷� 杈撻�佺嚎灞�
-//            motionList.addAll(kernelService.liftMoveShuttle(
-//                    MotionDto.build((dto -> {
-//                        dto.setLiftNo(transferLiftNo);
-//                        dto.setLev(Utils.getLev(shuttleLocNo));
-//                    })),
-//                    MotionDto.build((dto -> {
-//                        dto.setLiftNo(transferLiftNo);
-//                        dto.setLev(Utils.getLev(chargeLocNo));
-//                    }))
-//            ));
-//
-//            // 绌挎杞︽彁鍗囨満鑷虫彁鍗囨満寰呮満浣�
-//            motionList.addAll(kernelService.shuttleMove(
-//                    MotionDto.build((dto -> {
-//                        dto.setShuttleNo(shuttleProtocol.getShuttleNo().intValue());
-//                        dto.setLiftNo(transferLiftNo);
-//                        dto.setLocNo(liftLocNoFrom);
-//                    })),
-//                    MotionDto.build((dto -> {
-//                        dto.setShuttleNo(shuttleProtocol.getShuttleNo().intValue());
-//                        dto.setLocNo(standbyLocNoFrom);
-//                    })),
-//                    MotionCtgType.SHUTTLE_MOVE_FROM_LIFT
-//            ));
-//
-//            // 绌挎杞︽彁鍗囨満寰呮満浣嶈嚦鍏呯數浣�
-//            motionList.addAll(kernelService.shuttleMove(
-//                    MotionDto.build((dto -> {
-//                        dto.setShuttleNo(shuttleProtocol.getShuttleNo().intValue());
-//                        dto.setLocNo(standbyLocNoFrom);
-//                    })),
-//                    MotionDto.build((dto -> {
-//                        dto.setShuttleNo(shuttleProtocol.getShuttleNo().intValue());
-//                        dto.setLocNo(chargeLocNo);
-//                    })),
-//                    MotionCtgType.SHUTTLE_MOVE
-//            ));
-//
-//            wrkCharge.setLiftNo(transferLiftNo);
-//            wrkChargeMapper.updateById(wrkCharge);
-//        }
-//
-//        // 绌挎杞﹀紑濮嬪厖鐢�
-//        motionList.addAll(kernelService.shuttleCharge(
-//                null,
-//                MotionDto.build((dto -> {
-//                    dto.setShuttleNo(shuttleProtocol.getShuttleNo().intValue());
-//                }))
-//        ));
+        if (task.getTaskSts() != TaskStsType.NEW_CHARGE.sts) {
+            return motionList;
+        }
+
+        // locNo
+        String chargeLocNo = task.getDestLoc();
+
+        // shuttle
+        Device shuttleDevice = deviceService.getOne(new LambdaQueryWrapper<Device>()
+                .eq(Device::getDeviceNo, task.getShuttleNo())
+                .eq(Device::getDeviceType, DeviceCtgType.SHUTTLE.val())
+                .eq(Device::getHostId, task.getHostId())
+                .eq(Device::getStatus, 1));
+        if (shuttleDevice == null) {
+            return motionList;
+        }
+        ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleDevice.getId().intValue());
+        ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
+        if (shuttleProtocol == null || shuttleProtocol.getShuttleNo() == null) {
+            return motionList;
+        }
+        if (!shuttleThread.isIdle()) {
+            return motionList;
+        }
+
+        String shuttleLocNo = shuttleProtocol.getCurrentLocNo();
+
+        // lift
+        Device transferLiftDevice = Utils.getRecentTransferLift(shuttleLocNo, shuttleProtocol.getShuttleNo());
+        if (transferLiftDevice == null) {
+            return motionList;
+        }
+        LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, transferLiftDevice.getId().intValue());
+        LiftProtocol liftProtocol = liftThread.getStatus();
+        if (liftProtocol == null || liftProtocol.getLiftNo() == null) {
+            return motionList;
+        }
+
+        //妫�娴嬬┛姊溅鏄惁鏈変换鍔$粦瀹�
+        boolean shuttleResult = Utils.checkShuttleHasBinding(shuttleDevice);
+        if (shuttleResult) {
+            //瀛樺湪浠诲姟锛岀姝㈣В鏋�
+            return motionList;
+        }
+
+        //妫�娴嬫彁鍗囨満鏄惁鏈変换鍔$粦瀹�
+        boolean liftResult = Utils.checkLiftHasBinding(Integer.parseInt(transferLiftDevice.getDeviceNo()));
+        if (liftResult) {
+            //瀛樺湪浠诲姟锛岀姝㈣В鏋�
+            return motionList;
+        }
+
+        //鑾峰彇灏忚溅寰呮満搴撲綅 ==> 杩涙彁鍗囨満
+        ShuttleStandby shuttleStandbyTo = shuttleStandbyService.getOne(new LambdaQueryWrapper<ShuttleStandby>()
+                .eq(ShuttleStandby::getDeviceId, transferLiftDevice.getId())
+                .eq(ShuttleStandby::getDeviceLev, Utils.getLev(shuttleLocNo))
+                .eq(ShuttleStandby::getStatus, 1));
+
+        //鑾峰彇灏忚溅寰呮満搴撲綅 ==> 鍑烘彁鍗囨満
+        ShuttleStandby shuttleStandbyFrom = shuttleStandbyService.getOne(new LambdaQueryWrapper<ShuttleStandby>()
+                .eq(ShuttleStandby::getDeviceId, transferLiftDevice.getId())
+                .eq(ShuttleStandby::getDeviceLev, Utils.getLev(chargeLocNo))
+                .eq(ShuttleStandby::getStatus, 1));
+        if (shuttleStandbyTo == null || shuttleStandbyFrom == null) {
+            return motionList;
+        }
+
+        //绌挎杞﹁繘鎻愬崌鏈哄簱浣嶅彿
+        String liftLocNoTo = shuttleStandbyTo.getDeviceLoc();
+
+        //绌挎杞﹀嚭鎻愬崌鏈哄簱浣嶅彿
+        String liftLocNoFrom = shuttleStandbyFrom.getDeviceLoc();
+
+        //绌挎杞﹁繘鎻愬崌鏈哄緟鏈轰綅搴撲綅鍙�
+        String standbyLocNoTo = shuttleStandbyTo.getDeviceStandbyLoc();
+
+        //绌挎杞﹀嚭鎻愬崌鏈哄緟鏈轰綅搴撲綅鍙�
+        String standbyLocNoFrom = shuttleStandbyFrom.getDeviceStandbyLoc();
+
+        // 鍒ゆ柇绌挎杞︽槸鍚﹀湪鍏呯數灞�
+        if (Utils.getLev(shuttleLocNo) == Utils.getLev(chargeLocNo)) {
+
+            // 绌挎杞﹁蛋琛岃嚦鍏呯數妗╁簱浣�
+            motionList.addAll(kernelService.shuttleMove(
+                    MotionDto.build((dto -> {
+                        dto.setShuttleNo(shuttleDevice.getId().intValue());
+                        dto.setLocNo(shuttleLocNo);
+                    })),
+                    MotionDto.build((dto -> {
+                        dto.setShuttleNo(shuttleDevice.getId().intValue());
+                        dto.setLocNo(chargeLocNo);
+                    })),
+                    MotionCtgType.SHUTTLE_MOVE
+            ));
+
+        } else {
+
+            // 绌挎杞﹁蛋琛岃嚦鎻愬崌鏈哄緟鏈轰綅
+            motionList.addAll(kernelService.shuttleMove(
+                    MotionDto.build((dto -> {
+                        dto.setShuttleNo(shuttleDevice.getId().intValue());
+                        dto.setLocNo(shuttleLocNo);
+                    })),
+                    MotionDto.build((dto -> {
+                        dto.setShuttleNo(shuttleDevice.getId().intValue());
+                        dto.setLocNo(standbyLocNoTo);
+                    })),
+                    MotionCtgType.SHUTTLE_MOVE
+            ));
+
+            // 鎻愬崌鏈虹┖杞界Щ鍔ㄥ埌绌挎杞﹀眰
+            motionList.addAll(kernelService.liftMove(
+                    null
+                    , MotionDto.build((dto -> {
+                        dto.setLiftNo(transferLiftDevice.getId().intValue());
+                        dto.setLev(Utils.getLev(shuttleLocNo));
+                    }))
+            ));
+
+            // 绌挎杞︽彁鍗囨満寰呮満浣嶈嚦鎻愬崌鏈哄簱浣�
+            motionList.addAll(kernelService.shuttleMove(
+                    MotionDto.build((dto -> {
+                        dto.setShuttleNo(shuttleDevice.getId().intValue());
+                        dto.setLocNo(standbyLocNoTo);
+                    })),
+                    MotionDto.build((dto -> {
+                        dto.setShuttleNo(shuttleDevice.getId().intValue());
+                        dto.setLiftNo(transferLiftDevice.getId().intValue());
+                        dto.setLocNo(liftLocNoTo);
+                    })),
+                    MotionCtgType.SHUTTLE_MOVE_TO_LIFT
+            ));
+
+            // 鎻愬崌鏈烘惉杞� 鑷� 杈撻�佺嚎灞�
+            motionList.addAll(kernelService.liftMoveShuttle(
+                    MotionDto.build((dto -> {
+                        dto.setLiftNo(transferLiftDevice.getId().intValue());
+                        dto.setLev(Utils.getLev(shuttleLocNo));
+                    })),
+                    MotionDto.build((dto -> {
+                        dto.setLiftNo(transferLiftDevice.getId().intValue());
+                        dto.setLev(Utils.getLev(chargeLocNo));
+                    }))
+            ));
+
+            // 绌挎杞︽彁鍗囨満鑷虫彁鍗囨満寰呮満浣�
+            motionList.addAll(kernelService.shuttleMove(
+                    MotionDto.build((dto -> {
+                        dto.setShuttleNo(shuttleDevice.getId().intValue());
+                        dto.setLiftNo(transferLiftDevice.getId().intValue());
+                        dto.setLocNo(liftLocNoFrom);
+                    })),
+                    MotionDto.build((dto -> {
+                        dto.setShuttleNo(shuttleDevice.getId().intValue());
+                        dto.setLocNo(standbyLocNoFrom);
+                    })),
+                    MotionCtgType.SHUTTLE_MOVE_FROM_LIFT
+            ));
+
+            // 绌挎杞︽彁鍗囨満寰呮満浣嶈嚦鍏呯數浣�
+            motionList.addAll(kernelService.shuttleMove(
+                    MotionDto.build((dto -> {
+                        dto.setShuttleNo(shuttleDevice.getId().intValue());
+                        dto.setLocNo(standbyLocNoFrom);
+                    })),
+                    MotionDto.build((dto -> {
+                        dto.setShuttleNo(shuttleDevice.getId().intValue());
+                        dto.setLocNo(chargeLocNo);
+                    })),
+                    MotionCtgType.SHUTTLE_MOVE
+            ));
+
+            task.setLiftNo(Integer.parseInt(transferLiftDevice.getDeviceNo()));
+            taskService.updateById(task);
+        }
+
+        // 绌挎杞﹀紑濮嬪厖鐢�
+        motionList.addAll(kernelService.shuttleCharge(
+                null,
+                MotionDto.build((dto -> {
+                    dto.setShuttleNo(shuttleDevice.getId().intValue());
+                }))
+        ));
 
         return motionList;
     }
@@ -885,40 +912,47 @@
      */
     public List<Motion> generateShuttleChargeWrkComplete(Task task) {
         List<Motion> motionList = new ArrayList<>();
-//        if (wrkCharge.getWrkSts() != WrkMastStsType.NEW_MOVE.sts || wrkCharge.getIoType() != WrkIoTypeType.MOVE.sts) {
-//            return motionList;
-//        }
-//
-//        // locNo
-//        String locNo = wrkCharge.getLocNo();
-//
-//        // shuttle
-//        Integer shuttleNo = wrkCharge.getShuttleNo();
-//        ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleNo);
-//        ShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol();
-//        if (shuttleProtocol == null || shuttleProtocol.getShuttleNo() == null) {
-//            return motionList;
-//        }
-//
-//        String shuttleLocNo = shuttleProtocol.getCurrentLocNo();
-//
-//        // 鍒ゆ柇绌挎杞︽槸鍚﹀湪鐩爣灞�
-//        if (Utils.getLev(shuttleLocNo) == Utils.getLev(locNo)) {
-//
-//            // 绌挎杞﹁蛋琛岃嚦鐩爣搴撲綅
-//            motionList.addAll(kernelService.shuttleMove(
-//                    MotionDto.build((dto -> {
-//                        dto.setShuttleNo(shuttleProtocol.getShuttleNo().intValue());
-//                        dto.setLocNo(shuttleLocNo);
-//                    })),
-//                    MotionDto.build((dto -> {
-//                        dto.setShuttleNo(shuttleProtocol.getShuttleNo().intValue());
-//                        dto.setLocNo(locNo);
-//                    })),
-//                    MotionCtgType.SHUTTLE_MOVE
-//            ));
-//
-//        }
+        if (task.getTaskSts() != TaskStsType.NEW_MOVE.sts) {
+            return motionList;
+        }
+
+        // locNo
+        String locNo = task.getDestLoc();
+
+        // shuttle
+        Device shuttleDevice = deviceService.getOne(new LambdaQueryWrapper<Device>()
+                .eq(Device::getDeviceNo, task.getShuttleNo())
+                .eq(Device::getDeviceType, DeviceCtgType.SHUTTLE.val())
+                .eq(Device::getHostId, task.getHostId())
+                .eq(Device::getStatus, 1));
+        if (shuttleDevice == null) {
+            return motionList;
+        }
+        ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleDevice.getId().intValue());
+        ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
+        if (shuttleProtocol == null || shuttleProtocol.getShuttleNo() == null) {
+            return motionList;
+        }
+
+        String shuttleLocNo = shuttleProtocol.getCurrentLocNo();
+
+        // 鍒ゆ柇绌挎杞︽槸鍚﹀湪鐩爣灞�
+        if (Utils.getLev(shuttleLocNo) == Utils.getLev(locNo)) {
+
+            // 绌挎杞﹁蛋琛岃嚦鐩爣搴撲綅
+            motionList.addAll(kernelService.shuttleMove(
+                    MotionDto.build((dto -> {
+                        dto.setShuttleNo(shuttleDevice.getId().intValue());
+                        dto.setLocNo(shuttleLocNo);
+                    })),
+                    MotionDto.build((dto -> {
+                        dto.setShuttleNo(shuttleDevice.getId().intValue());
+                        dto.setLocNo(locNo);
+                    })),
+                    MotionCtgType.SHUTTLE_MOVE
+            ));
+
+        }
         return motionList;
     }
 
@@ -934,17 +968,9 @@
         // locNo
         String locNo = task.getDestLoc();
 
-        //鑾峰彇绌挎杞︾被鍨�
-        DeviceType deviceType = deviceTypeService.getOne(new LambdaQueryWrapper<DeviceType>()
-                .eq(DeviceType::getFlag, String.valueOf(SlaveType.Shuttle))
-                .eq(DeviceType::getStatus, 1));
-        if (deviceType == null) {
-            return motionList;
-        }
-
         Device device = deviceService.getOne(new LambdaQueryWrapper<Device>()
                 .eq(Device::getDeviceNo, task.getShuttleNo())
-                .eq(Device::getDeviceType, deviceType.getId())
+                .eq(Device::getDeviceType, DeviceCtgType.SHUTTLE.val())
                 .eq(Device::getHostId, task.getHostId())
                 .eq(Device::getStatus, 1));
         if (device == null) {
@@ -969,11 +995,11 @@
             // 绌挎杞﹁蛋琛岃嚦鐩爣搴撲綅
             motionList.addAll(kernelService.shuttleMove(
                     MotionDto.build((dto -> {
-                        dto.setShuttleNo(shuttleProtocol.getShuttleNo().intValue());
+                        dto.setShuttleNo(device.getId().intValue());
                         dto.setLocNo(shuttleLocNo);
                     })),
                     MotionDto.build((dto -> {
-                        dto.setShuttleNo(shuttleProtocol.getShuttleNo().intValue());
+                        dto.setShuttleNo(device.getId().intValue());
                         dto.setLocNo(locNo);
                     })),
                     MotionCtgType.SHUTTLE_MOVE
@@ -992,20 +1018,13 @@
             return motionList;
         }
 
+        String sourceLoc = task.getOriginLoc();//婧愬簱浣�
         String targetLoc = task.getDestLoc();//浠诲姟鐩爣(鍊熺敤瀛楁)
         String targetSite = task.getDestSite();//浠诲姟绫诲瀷(鍊熺敤瀛楁)
 
-        //鑾峰彇绌挎杞︾被鍨�
-        DeviceType deviceType = deviceTypeService.getOne(new LambdaQueryWrapper<DeviceType>()
-                .eq(DeviceType::getFlag, String.valueOf(SlaveType.Shuttle))
-                .eq(DeviceType::getStatus, 1));
-        if (deviceType == null) {
-            return motionList;
-        }
-
         Device device = deviceService.getOne(new LambdaQueryWrapper<Device>()
                 .eq(Device::getDeviceNo, task.getShuttleNo())
-                .eq(Device::getDeviceType, deviceType.getId())
+                .eq(Device::getDeviceType, DeviceCtgType.SHUTTLE.val())
                 .eq(Device::getHostId, task.getHostId())
                 .eq(Device::getStatus, 1));
         if (device == null) {
@@ -1031,11 +1050,11 @@
                 // 绌挎杞﹁蛋琛岃嚦鐩爣搴撲綅
                 motionList.addAll(kernelService.shuttleMove(
                         MotionDto.build((dto -> {
-                            dto.setShuttleNo(shuttleProtocol.getShuttleNo().intValue());
+                            dto.setShuttleNo(device.getId().intValue());
                             dto.setLocNo(shuttleLocNo);
                         })),
                         MotionDto.build((dto -> {
-                            dto.setShuttleNo(shuttleProtocol.getShuttleNo().intValue());
+                            dto.setShuttleNo(device.getId().intValue());
                             dto.setLocNo(targetLoc);
                         })),
                         MotionCtgType.SHUTTLE_MOVE
@@ -1046,32 +1065,80 @@
             //鎵樼洏椤跺崌
             motionList.add(Motion.build(motion -> {
                 motion.setDeviceCtg(DeviceCtgType.SHUTTLE.val());
-                motion.setDevice(String.valueOf(task.getShuttleNo()));
+                motion.setDevice(String.valueOf(device.getId()));
                 motion.setMotionCtg(MotionCtgType.SHUTTLE_PALLET_LIFT.val());
             }));
         } else if (targetSite.equals("palletDown")) {
             //鎵樼洏涓嬮檷
             motionList.add(Motion.build(motion -> {
                 motion.setDeviceCtg(DeviceCtgType.SHUTTLE.val());
-                motion.setDevice(String.valueOf(task.getShuttleNo()));
+                motion.setDevice(String.valueOf(device.getId()));
                 motion.setMotionCtg(MotionCtgType.SHUTTLE_PALLET_DOWN.val());
             }));
         } else if (targetSite.equals("chargeOpen")) {
             //鍏呯數寮�
             motionList.add(Motion.build(motion -> {
                 motion.setDeviceCtg(DeviceCtgType.SHUTTLE.val());
-                motion.setDevice(String.valueOf(task.getShuttleNo()));
+                motion.setDevice(String.valueOf(device.getId()));
                 motion.setMotionCtg(MotionCtgType.SHUTTLE_CHARGE_ON.val());
             }));
         } else if (targetSite.equals("chargeClose")) {
             //鍏呯數鍏�
             motionList.add(Motion.build(motion -> {
                 motion.setDeviceCtg(DeviceCtgType.SHUTTLE.val());
-                motion.setDevice(String.valueOf(task.getShuttleNo()));
+                motion.setDevice(String.valueOf(device.getId()));
                 motion.setMotionCtg(MotionCtgType.SHUTTLE_CHARGE_OFF.val());
             }));
         } else if (targetSite.equals("reset")) {
             //澶嶄綅
+        } else if (targetSite.equals("takeMove")) {
+            //鍙栨斁璐�
+            String shuttleLocNo = shuttleProtocol.getCurrentLocNo();
+
+            // 鍒ゆ柇绌挎杞︽槸鍚﹀湪鐩爣灞�
+            if (Utils.getLev(shuttleLocNo) == Utils.getLev(targetLoc)) {
+
+                // 绌挎杞﹁蛋琛岃嚦婧愬簱浣�
+                motionList.addAll(kernelService.shuttleMove(
+                        MotionDto.build((dto -> {
+                            dto.setShuttleNo(device.getId().intValue());
+                            dto.setLocNo(shuttleLocNo);
+                        })),
+                        MotionDto.build((dto -> {
+                            dto.setShuttleNo(device.getId().intValue());
+                            dto.setLocNo(sourceLoc);
+                        })),
+                        MotionCtgType.SHUTTLE_MOVE
+                ));
+
+                //鎵樼洏椤跺崌
+                motionList.add(Motion.build(motion -> {
+                    motion.setDeviceCtg(DeviceCtgType.SHUTTLE.val());
+                    motion.setDevice(String.valueOf(device.getId()));
+                    motion.setMotionCtg(MotionCtgType.SHUTTLE_PALLET_LIFT.val());
+                }));
+
+                // 绌挎杞﹁蛋琛岃嚦鐩爣搴撲綅
+                motionList.addAll(kernelService.shuttleMove(
+                        MotionDto.build((dto -> {
+                            dto.setShuttleNo(device.getId().intValue());
+                            dto.setLocNo(sourceLoc);
+                        })),
+                        MotionDto.build((dto -> {
+                            dto.setShuttleNo(device.getId().intValue());
+                            dto.setLocNo(targetLoc);
+                        })),
+                        MotionCtgType.SHUTTLE_MOVE
+                ));
+
+                //鎵樼洏涓嬮檷
+                motionList.add(Motion.build(motion -> {
+                    motion.setDeviceCtg(DeviceCtgType.SHUTTLE.val());
+                    motion.setDevice(String.valueOf(device.getId()));
+                    motion.setMotionCtg(MotionCtgType.SHUTTLE_PALLET_DOWN.val());
+                }));
+
+            }
         }
 
         return motionList;

--
Gitblit v1.9.1