From 9372f61dcb41eeb2e09871caefce0f764d6ab021 Mon Sep 17 00:00:00 2001
From: zjj <3272660260@qq.com>
Date: 星期五, 21 六月 2024 15:17:04 +0800
Subject: [PATCH] #

---
 zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/kernel/AnalyzeService.java |  831 +++++++++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 612 insertions(+), 219 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 68d7a94..5791605 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,12 +3,14 @@
 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.ConveyorDispatcher;
 import com.zy.asrs.wcs.core.utils.LiftDispatcher;
 import com.zy.asrs.wcs.core.utils.ShuttleDispatcher;
 import com.zy.asrs.wcs.core.utils.Utils;
@@ -16,19 +18,20 @@
 import com.zy.asrs.wcs.core.entity.Motion;
 import com.zy.asrs.wcs.rcs.entity.Device;
 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.thread.LiftThread;
 import com.zy.asrs.wcs.rcs.thread.ShuttleThread;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import java.util.ArrayList;
 import java.util.List;
-import java.util.Objects;
 
 /**
- * todo:luxiaotao 1.鍏呯數浠诲姟锛�2.搴撲綅绉昏浆锛�3.灏忚溅杩佺Щ
+ * 1.鍏呯數浠诲姟锛�2.搴撲綅绉昏浆锛�3.灏忚溅杩佺Щ锛�4.鎵嬪姩浠诲姟
  * Created by vincent on 2023/10/11
  */
 @Service
@@ -44,19 +47,16 @@
     private ShuttleDispatcher shuttleDispatcher;
     @Autowired
     private LiftDispatcher liftDispatcher;
-//    @Autowired
-//    private ConveyorDispatcher conveyorDispatcher;
+    @Autowired
+    private ConveyorDispatcher conveyorDispatcher;
     @Autowired
     private DeviceService deviceService;
+    @Autowired
+    private ShuttleStandbyService shuttleStandbyService;
 
     public List<Motion> generateMotion(Task task) {
         List<Motion> motionList = new ArrayList<>();
-        switch (Objects.requireNonNull(WorkZoneType.query(task.getTaskSts() == TaskStsType.NEW_INBOUND.sts ? task.getOriginSite() : task.getDestSite()))) {
-            case FIRST_ZONE:
-                motionList = this.generateFirstZoneMotion(task);
-                break;
-            default:
-        }
+        motionList = this.generateFirstZoneMotion(task);
         return motionList;
     }
 
@@ -75,21 +75,86 @@
          * 5.绌挎杞﹀叆搴撹嚦鐩爣搴撲綅
          */
         if (task.getTaskSts() == TaskStsType.NEW_INBOUND.sts) {
-//            // lift
-//            LiftThread liftThread = liftDispatcher.queryLiftForTransport(task.getOriginSite());
-//            LiftProtocol liftProtocol = liftThread.getStatus();
-//            if (liftProtocol == null) {
-//                return motionList;
-//            }
+            // locNo
+            String destLoc = 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();
+
+            //鑾峰彇璺濈鐩爣浣嶇疆鏈�杩戠殑绌洪棽鍙崲灞傛彁鍗囨満
+            LiftThread liftThread = liftDispatcher.searchIdleLift(shuttleLocNo, task.getHostId(), true);
+            if (liftThread == null) {
+                return motionList;
+            }
+            Device transferLiftDevice = liftThread.getDevice();
+
+            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(destLoc))
+                    .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();
 
             // shuttle
 //            ShuttleThread shuttleThread = shuttleDispatcher.queryShuttleWhichConvenient(task, Integer.parseInt(liftThread.getStatus().getLiftNo()));
 //            ShuttleThread shuttleThread = shuttleDispatcher.queryShuttleWhichConvenient(task, 1);
-            ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, 6);
-            if (Cools.isEmpty(shuttleThread)) { return motionList; }
-            ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
 //            String shuttleLocNo = shuttleProtocol.getCurrentLocNo();
-            String shuttleLocNo = "0100201";
 
 //            // conveyor
 //            DevpSlave devpSlave = conveyorDispatcher.queryByInBound(task.getSourceStaNo());
@@ -714,164 +779,231 @@
      */
     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();
+
+        //鑾峰彇璺濈鐩爣浣嶇疆鏈�杩戠殑绌洪棽鍙崲灞傛彁鍗囨満
+        LiftThread liftThread = liftDispatcher.searchIdleLift(shuttleLocNo, task.getHostId(), true);
+        if (liftThread == null) {
+            return motionList;
+        }
+        Device transferLiftDevice = liftThread.getDevice();
+
+        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.liftLock(
+                    null
+                    , MotionDto.build((dto -> {
+                        dto.setLiftNo(transferLiftDevice.getId().intValue());
+                    }))
+            ));
+
+            // 绌挎杞︽彁鍗囨満寰呮満浣嶈嚦鎻愬崌鏈�
+            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
+            ));
+
+            // 瑙i攣鎻愬崌鏈�
+            motionList.addAll(kernelService.liftUnlock(
+                    null
+                    , MotionDto.build((dto -> {
+                        dto.setLiftNo(transferLiftDevice.getId().intValue());
+                    }))
+            ));
+
+            // 鎻愬崌鏈烘惉杞� 鑷� 鍏呯數灞�
+            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.liftLock(
+                    null
+                    , MotionDto.build((dto -> {
+                        dto.setLiftNo(transferLiftDevice.getId().intValue());
+                    }))
+            ));
+
+            // 鏇存柊灏忚溅鍧愭爣
+            motionList.addAll(kernelService.shuttleUpdateLocation(
+                    null
+                    , MotionDto.build((dto -> {
+                        dto.setShuttleNo(shuttleDevice.getId().intValue());
+                        dto.setLocNo(liftLocNoFrom);
+                    }))
+            ));
+
+            // 绌挎杞︽彁鍗囨満鑷虫彁鍗囨満寰呮満浣�
+            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
+            ));
+
+            // 瑙i攣鎻愬崌鏈�
+            motionList.addAll(kernelService.liftUnlock(
+                    null
+                    , MotionDto.build((dto -> {
+                        dto.setLiftNo(transferLiftDevice.getId().intValue());
+                    }))
+            ));
+
+            // 绌挎杞︽彁鍗囨満寰呮満浣嶈嚦鍏呯數浣�
+            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;
     }
@@ -881,40 +1013,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;
     }
 
@@ -930,16 +1069,16 @@
         // locNo
         String locNo = task.getDestLoc();
 
-        Device device = deviceService.getOne(new LambdaQueryWrapper<Device>()
+        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 (device == null) {
+        if (shuttleDevice == null) {
             return motionList;
         }
 
-        ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, device.getId().intValue());
+        ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleDevice.getId().intValue());
         if (shuttleThread == null) {
             return motionList;
         }
@@ -954,14 +1093,165 @@
         // 鍒ゆ柇绌挎杞︽槸鍚﹀湪鐩爣灞�
         if (Utils.getLev(shuttleLocNo) == Utils.getLev(locNo)) {
 
-            // 绌挎杞﹁蛋琛岃嚦鐩爣搴撲綅
+            if (!shuttleLocNo.equals(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
+                ));
+            }
+
+        } else {
+            //灏忚溅璺ㄥ眰
+
+            //鑾峰彇璺濈鐩爣浣嶇疆鏈�杩戠殑绌洪棽鍙崲灞傛彁鍗囨満
+            LiftThread liftThread = liftDispatcher.searchIdleLift(locNo, task.getHostId(), true);
+            if (liftThread == null) {
+                return motionList;
+            }
+            Device liftDevice = liftThread.getDevice();
+
+            //绌挎杞﹀埌鎻愬崌鏈哄簱浣嶅彿
+            String liftLocNoTo = liftDispatcher.getLiftLocNo(liftThread, Utils.getLev(shuttleLocNo));
+
+            //绌挎杞﹀嚭鎻愬崌鏈哄簱浣嶅彿
+            String liftLocNoFrom = liftDispatcher.getLiftLocNo(liftThread, Utils.getLev(task.getDestLoc()));
+
+            //绌挎杞﹀埌鎻愬崌鏈哄緟鏈轰綅搴撲綅鍙�
+            String standbyLocNoTo = liftDispatcher.getLiftStandByLocNo(liftThread, Utils.getLev(shuttleLocNo));
+
+            //绌挎杞﹀嚭鎻愬崌鏈哄緟鏈轰綅搴撲綅鍙�
+            String standbyLocNoFrom = liftDispatcher.getLiftStandByLocNo(liftThread, Utils.getLev(task.getDestLoc()));
+
+
+            // 绌挎杞﹁蛋琛岃嚦鎻愬崌鏈哄簱浣嶅緟鏈轰綅
             motionList.addAll(kernelService.shuttleMove(
                     MotionDto.build((dto -> {
-                        dto.setShuttleNo(shuttleProtocol.getShuttleNo().intValue());
+                        dto.setShuttleNo(shuttleDevice.getId().intValue());
                         dto.setLocNo(shuttleLocNo);
                     })),
                     MotionDto.build((dto -> {
-                        dto.setShuttleNo(shuttleProtocol.getShuttleNo().intValue());
+                        dto.setShuttleNo(shuttleDevice.getId().intValue());
+                        dto.setLiftNo(liftDevice.getId().intValue());
+                        dto.setLocNo(standbyLocNoTo);
+                    })),
+                    MotionCtgType.SHUTTLE_MOVE
+            ));
+
+            // 鎻愬崌鏈虹┖杞界Щ鍔ㄥ埌绌挎杞﹀眰
+            motionList.addAll(kernelService.liftMove(
+                    null
+                    , MotionDto.build((dto -> {
+                        dto.setLiftNo(liftDevice.getId().intValue());
+                        dto.setLev(Utils.getLev(shuttleLocNo));
+                    }))
+            ));
+
+            // 閿佸畾鎻愬崌鏈�
+            motionList.addAll(kernelService.liftLock(
+                    null
+                    , MotionDto.build((dto -> {
+                        dto.setLiftNo(liftDevice.getId().intValue());
+                    }))
+            ));
+
+            // 绌挎杞﹀緟鏈轰綅鑷虫彁鍗囨満
+            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(liftDevice.getId().intValue());
+                        dto.setLocNo(liftLocNoTo);
+                    })),
+                    MotionCtgType.SHUTTLE_MOVE_TO_LIFT
+            ));
+
+            // 鍚戞彁鍗囨満鍙戦�佸皬杞﹀凡鍒颁綅淇″彿
+            motionList.addAll(kernelService.liftShuttleArrival(
+                    null
+                    , MotionDto.build((dto -> {
+                        dto.setLiftNo(liftDevice.getId().intValue());
+                    }))
+            ));
+
+            // 瑙i攣鎻愬崌鏈�
+            motionList.addAll(kernelService.liftUnlock(
+                    null
+                    , MotionDto.build((dto -> {
+                        dto.setLiftNo(liftDevice.getId().intValue());
+                    }))
+            ));
+
+            // 鎻愬崌鏈烘惉杞� 鑷� 鐩爣浣嶇疆灞�
+            motionList.addAll(kernelService.liftMoveShuttle(
+                    MotionDto.build((dto -> {
+                        dto.setLiftNo(liftDevice.getId().intValue());
+                        dto.setLev(Utils.getLev(shuttleLocNo));
+                    })),
+                    MotionDto.build((dto -> {
+                        dto.setLiftNo(liftDevice.getId().intValue());
+                        dto.setLev(Utils.getLev(locNo));
+                    }))
+            ));
+
+            // 閿佸畾鎻愬崌鏈�
+            motionList.addAll(kernelService.liftLock(
+                    null
+                    , MotionDto.build((dto -> {
+                        dto.setLiftNo(liftDevice.getId().intValue());
+                    }))
+            ));
+
+            // 鏇存柊灏忚溅鍧愭爣
+            motionList.addAll(kernelService.shuttleUpdateLocation(
+                    null
+                    , MotionDto.build((dto -> {
+                        dto.setShuttleNo(shuttleDevice.getId().intValue());
+                        dto.setLocNo(liftLocNoFrom);
+                    }))
+            ));
+
+            // 绌挎杞﹁蛋琛岃嚦鎻愬崌鏈哄緟鏈轰綅
+            motionList.addAll(kernelService.shuttleMove(
+                    MotionDto.build((dto -> {
+                        dto.setShuttleNo(shuttleDevice.getId().intValue());
+                        dto.setLiftNo(liftDevice.getId().intValue());
+                        dto.setLocNo(liftLocNoFrom);
+                    })),
+                    MotionDto.build((dto -> {
+                        dto.setShuttleNo(shuttleDevice.getId().intValue());
+                        dto.setLocNo(standbyLocNoFrom);
+                    })),
+                    MotionCtgType.SHUTTLE_MOVE_FROM_LIFT
+            ));
+
+            // 瑙i攣鎻愬崌鏈�
+            motionList.addAll(kernelService.liftUnlock(
+                    null
+                    , MotionDto.build((dto -> {
+                        dto.setLiftNo(liftDevice.getId().intValue());
+                    }))
+            ));
+
+            // 绌挎杞︽彁鍗囨満寰呮満浣嶈嚦鐩爣浣嶇疆
+            motionList.addAll(kernelService.shuttleMove(
+                    MotionDto.build((dto -> {
+                        dto.setShuttleNo(shuttleDevice.getId().intValue());
+                        dto.setLiftNo(liftDevice.getId().intValue());
+                        dto.setLocNo(standbyLocNoFrom);
+                    })),
+                    MotionDto.build((dto -> {
+                        dto.setShuttleNo(shuttleDevice.getId().intValue());
                         dto.setLocNo(locNo);
                     })),
                     MotionCtgType.SHUTTLE_MOVE
@@ -980,6 +1270,7 @@
             return motionList;
         }
 
+        String sourceLoc = task.getOriginLoc();//婧愬簱浣�
         String targetLoc = task.getDestLoc();//浠诲姟鐩爣(鍊熺敤瀛楁)
         String targetSite = task.getDestSite();//浠诲姟绫诲瀷(鍊熺敤瀛楁)
 
@@ -1052,6 +1343,108 @@
             }));
         } else if (targetSite.equals("reset")) {
             //澶嶄綅
+        } else if (targetSite.equals("takeMove")) {
+            //鍙栨斁璐�
+            String shuttleLocNo = shuttleProtocol.getCurrentLocNo();
+
+            // 鍒ゆ柇绌挎杞︽槸鍚﹀湪鐩爣灞�
+            if (Utils.getLev(shuttleLocNo) == Utils.getLev(targetLoc)) {
+
+                if (!shuttleLocNo.equals(sourceLoc)) {//灏忚溅涓嶅湪鐩爣搴撲綅
+                    // 绌挎杞﹁蛋琛岃嚦婧愬簱浣�
+                    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;
+    }
+
+    /**
+     * 鐢熸垚鎻愬崌鏈烘墜鍔ㄥ姩浣�
+     */
+    public List<Motion> generateLiftManualMotion(Task task) {
+        List<Motion> motionList = new ArrayList<>();
+        if (task.getTaskSts() != TaskStsType.NEW_MANUAL.sts) {
+            return motionList;
+        }
+
+        Device device = deviceService.getOne(new LambdaQueryWrapper<Device>()
+                .eq(Device::getDeviceNo, task.getLiftNo())
+                .eq(Device::getDeviceType, DeviceCtgType.LIFT.val())
+                .eq(Device::getHostId, task.getHostId())
+                .eq(Device::getStatus, 1));
+        if (device == null) {
+            return motionList;
+        }
+
+        if (task.getDestSite().equals("move")) {
+            //鎻愬崌鏈哄崌闄嶆ゼ灞�
+
+            // 鎻愬崌鏈虹┖杞界Щ鍔ㄥ埌绌挎杞﹀眰
+            motionList.addAll(kernelService.liftMove(
+                    null
+                    , MotionDto.build((dto -> {
+                        dto.setLiftNo(device.getId().intValue());
+                        dto.setLev(Integer.parseInt(task.getDestLoc()));
+                    }))
+            ));
+
+        } else if (task.getDestSite().equals("movePallet")) {
+            //绉诲姩鎵樼洏
+
+            // 鎻愬崌鏈虹Щ鍔ㄦ墭鐩�
+            motionList.addAll(kernelService.liftMoveGoods(
+                    MotionDto.build((dto -> {
+                        dto.setLiftNo(device.getId().intValue());
+                        dto.setLev(Integer.parseInt(task.getOriginLoc()));
+                        dto.setStaNo(Integer.parseInt(task.getOriginSite()));
+                    }))
+                    , MotionDto.build((dto -> {
+                        dto.setLiftNo(device.getId().intValue());
+                        dto.setLev(Integer.parseInt(task.getDestLoc()));
+                        dto.setStaNo(Integer.parseInt(task.getDestSite()));
+                    }))
+            ));
+
         }
 
         return motionList;

--
Gitblit v1.9.1