From f84448a10d99a0fa82e71088051e3517637edaa7 Mon Sep 17 00:00:00 2001
From: Junjie <540245094@qq.com>
Date: 星期二, 09 四月 2024 15:11:52 +0800
Subject: [PATCH] #

---
 zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/kernel/AnalyzeService.java |  251 +++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 208 insertions(+), 43 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 ae54ee7..9e0b818 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
@@ -1,9 +1,10 @@
 package com.zy.asrs.wcs.core.kernel;
 
+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.Task;
-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.MotionCtgType;
 import com.zy.asrs.wcs.core.model.enums.TaskStsType;
 import com.zy.asrs.wcs.core.model.enums.WorkZoneType;
@@ -11,11 +12,15 @@
 import com.zy.asrs.wcs.core.utils.LiftDispatcher;
 import com.zy.asrs.wcs.core.utils.ShuttleDispatcher;
 import com.zy.asrs.wcs.core.utils.Utils;
-import com.zy.asrs.wcs.rcs.entity.Motion;
-import com.zy.asrs.wcs.rcs.model.protocol.LiftProtocol;
+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.ShuttleProtocol;
-import com.zy.asrs.wcs.rcs.service.MotionService;
-import com.zy.asrs.wcs.rcs.thread.LiftThread;
+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.ShuttleThread;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -41,8 +46,12 @@
     private ShuttleDispatcher shuttleDispatcher;
     @Autowired
     private LiftDispatcher liftDispatcher;
-//    @Autowired
+    //    @Autowired
 //    private ConveyorDispatcher conveyorDispatcher;
+    @Autowired
+    private DeviceService deviceService;
+    @Autowired
+    private DeviceTypeService deviceTypeService;
 
     public List<Motion> generateMotion(Task task) {
         List<Motion> motionList = new ArrayList<>();
@@ -70,18 +79,21 @@
          * 5.绌挎杞﹀叆搴撹嚦鐩爣搴撲綅
          */
         if (task.getTaskSts() == TaskStsType.NEW_INBOUND.sts) {
-            // lift
-            LiftThread liftThread = liftDispatcher.queryLiftForTransport(task.getOriginSite());
-            LiftProtocol liftProtocol = liftThread.getStatus();
-            if (liftProtocol == null) {
-                return motionList;
-            }
+//            // lift
+//            LiftThread liftThread = liftDispatcher.queryLiftForTransport(task.getOriginSite());
+//            LiftProtocol liftProtocol = liftThread.getStatus();
+//            if (liftProtocol == null) {
+//                return motionList;
+//            }
 
             // shuttle
-            ShuttleThread shuttleThread = shuttleDispatcher.queryShuttleWhichConvenient(task, Integer.parseInt(liftThread.getStatus().getLiftNo()));
+//            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 = shuttleProtocol.getCurrentLocNo();
+            String shuttleLocNo = "0100201";
 
 //            // conveyor
 //            DevpSlave devpSlave = conveyorDispatcher.queryByInBound(task.getSourceStaNo());
@@ -101,20 +113,20 @@
 //                return motionList;
 //            }
 
-            //绌挎杞﹀埌鎻愬崌鏈哄簱浣嶅彿
-            String liftLocNoTo = LiftCodeType.getLocNo(Integer.parseInt(liftNo), Utils.getLev(shuttleLocNo), task.getHostId());
-
-            //绌挎杞﹀嚭鎻愬崌鏈哄簱浣嶅彿
-            String liftLocNoFrom = LiftCodeType.getLocNo(Integer.parseInt(liftNo), Utils.getLev(task.getDestLoc()), task.getHostId());
-
-            //绌挎杞﹀埌鎻愬崌鏈哄緟鏈轰綅搴撲綅鍙�
-            String standbyLocNoTo = LiftCodeType.getStandbyLocNo(Integer.parseInt(liftNo), Utils.getLev(shuttleLocNo));
-
-            //绌挎杞﹀嚭鎻愬崌鏈哄緟鏈轰綅搴撲綅鍙�
-            String standbyLocNoFrom = LiftCodeType.getStandbyLocNo(Integer.parseInt(liftNo), Utils.getLev(task.getDestLoc()));
+//            //绌挎杞﹀埌鎻愬崌鏈哄簱浣嶅彿
+//            String liftLocNoTo = LiftCodeType.getLocNo(Integer.parseInt(liftNo), Utils.getLev(shuttleLocNo), task.getHostId());
+//
+//            //绌挎杞﹀嚭鎻愬崌鏈哄簱浣嶅彿
+//            String liftLocNoFrom = LiftCodeType.getLocNo(Integer.parseInt(liftNo), Utils.getLev(task.getDestLoc()), task.getHostId());
+//
+//            //绌挎杞﹀埌鎻愬崌鏈哄緟鏈轰綅搴撲綅鍙�
+//            String standbyLocNoTo = LiftCodeType.getStandbyLocNo(Integer.parseInt(liftNo), Utils.getLev(shuttleLocNo));
+//
+//            //绌挎杞﹀嚭鎻愬崌鏈哄緟鏈轰綅搴撲綅鍙�
+//            String standbyLocNoFrom = LiftCodeType.getStandbyLocNo(Integer.parseInt(liftNo), Utils.getLev(task.getDestLoc()));
 
             // 鍏ュ簱鐩爣灞傛湁绌挎杞�
-            if (Utils.getLev(shuttleLocNo) == Utils.getLev(task.getOriginLoc())) {
+            if (Utils.getLev(shuttleLocNo) == Utils.getLev(task.getDestLoc())) {
 
                 // 绌挎杞﹁蛋琛岃嚦搴撲綅
                 motionList.addAll(kernelService.shuttleMove(
@@ -353,7 +365,7 @@
             }
 
             shuttleNo = String.valueOf(shuttleProtocol.getShuttleNo());
-            liftNo = String.valueOf(liftProtocol.getLiftNo());
+//            liftNo = String.valueOf(liftProtocol.getLiftNo());
         }
 
         /**
@@ -701,11 +713,11 @@
     }
 
 
-//    /**
-//     * 鐢熸垚鍏呯數鍔ㄤ綔
-//     */
-//    public List<Motion> generateChargeMotion(WrkCharge wrkCharge) {
-//        List<Motion> motionList = new ArrayList<>();
+    /**
+     * 鐢熸垚鍏呯數鍔ㄤ綔
+     */
+    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;
 //        }
@@ -864,15 +876,15 @@
 //                    dto.setShuttleNo(shuttleProtocol.getShuttleNo().intValue());
 //                }))
 //        ));
-//
-//        return motionList;
-//    }
-//
-//    /**
-//     * 鐢熸垚鍏呯數瀹屾垚鍔ㄤ綔
-//     */
-//    public List<Motion> generateShuttleChargeWrkComplete(WrkCharge wrkCharge) {
-//        List<Motion> motionList = new ArrayList<>();
+
+        return motionList;
+    }
+
+    /**
+     * 鐢熸垚鍏呯數瀹屾垚鍔ㄤ綔
+     */
+    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;
 //        }
@@ -907,9 +919,162 @@
 //            ));
 //
 //        }
-//        return motionList;
-//    }
+        return motionList;
+    }
 
+    /**
+     * 鐢熸垚灏忚溅杩佺Щ鍔ㄤ綔
+     */
+    public List<Motion> generateShuttleMoveMotion(Task task) {
+        List<Motion> motionList = new ArrayList<>();
+        if (task.getTaskSts() != TaskStsType.NEW_MOVE.sts) {
+            return motionList;
+        }
 
+        // 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::getHostId, task.getHostId())
+                .eq(Device::getStatus, 1));
+        if (device == null) {
+            return motionList;
+        }
+
+        ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, device.getId().intValue());
+        if (shuttleThread == null) {
+            return motionList;
+        }
+
+        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(shuttleProtocol.getShuttleNo().intValue());
+                        dto.setLocNo(shuttleLocNo);
+                    })),
+                    MotionDto.build((dto -> {
+                        dto.setShuttleNo(shuttleProtocol.getShuttleNo().intValue());
+                        dto.setLocNo(locNo);
+                    })),
+                    MotionCtgType.SHUTTLE_MOVE
+            ));
+
+        }
+        return motionList;
+    }
+
+    /**
+     * 鐢熸垚灏忚溅鎵嬪姩鍔ㄤ綔
+     */
+    public List<Motion> generateShuttleManualMotion(Task task) {
+        List<Motion> motionList = new ArrayList<>();
+        if (task.getTaskSts() != TaskStsType.NEW_MANUAL.sts) {
+            return motionList;
+        }
+
+        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::getHostId, task.getHostId())
+                .eq(Device::getStatus, 1));
+        if (device == null) {
+            return motionList;
+        }
+
+        ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, device.getId().intValue());
+        if (shuttleThread == null) {
+            return motionList;
+        }
+
+        ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
+        if (shuttleProtocol == null || shuttleProtocol.getShuttleNo() == null) {
+            return motionList;
+        }
+
+        if (targetSite.equals("moveLoc")) {//绉诲姩
+            String shuttleLocNo = shuttleProtocol.getCurrentLocNo();
+
+            // 鍒ゆ柇绌挎杞︽槸鍚﹀湪鐩爣灞�
+            if (Utils.getLev(shuttleLocNo) == Utils.getLev(targetLoc)) {
+
+                // 绌挎杞﹁蛋琛岃嚦鐩爣搴撲綅
+                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(targetLoc);
+                        })),
+                        MotionCtgType.SHUTTLE_MOVE
+                ));
+
+            }
+        } else if (targetSite.equals("palletLift")) {
+            //鎵樼洏椤跺崌
+            motionList.add(Motion.build(motion -> {
+                motion.setDeviceCtg(DeviceCtgType.SHUTTLE.val());
+                motion.setDevice(String.valueOf(task.getShuttleNo()));
+                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.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.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.setMotionCtg(MotionCtgType.SHUTTLE_CHARGE_OFF.val());
+            }));
+        } else if (targetSite.equals("reset")) {
+            //澶嶄綅
+        }
+
+        return motionList;
+    }
 
 }

--
Gitblit v1.9.1