From 15356da6eeca013fafc9bb6ed2d2a4a12422ce04 Mon Sep 17 00:00:00 2001
From: Junjie <xjj@123>
Date: 星期三, 02 四月 2025 16:41:52 +0800
Subject: [PATCH] #

---
 zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/service/impl/MainServiceImpl.java |    7 +
 zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/kernel/AnalyzeService.java        |  277 +++++++++++++++++++++++++++++++++++++++++++++
 zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/utils/ConveyorDispatcher.java     |   31 -----
 zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/model/protocol/StaProtocol.java    |    3 
 zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/thread/impl/FyxcDevpThread.java    |    7 +
 5 files changed, 288 insertions(+), 37 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 8542d54..8cf74c0 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
@@ -12,7 +12,9 @@
 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.rcs.model.protocol.StaProtocol;
 import com.zy.asrs.wcs.rcs.service.DeviceService;
+import com.zy.asrs.wcs.rcs.thread.DevpThread;
 import com.zy.asrs.wcs.rcs.thread.LiftThread;
 import com.zy.asrs.wcs.rcs.thread.ShuttleThread;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -65,7 +67,13 @@
 
     public List<Motion> generateMotion(Task task) {
         List<Motion> motionList = new ArrayList<>();
-        motionList = this.generateFirstZoneMotion(task);
+        int originSite = Integer.parseInt(task.getOriginSite());
+        int destSite = Integer.parseInt(task.getDestSite());
+        if (originSite == 1015 || originSite == 1026 || destSite == 1015 || destSite == 1026) {
+            motionList = generateSecondZoneMotion(task);
+        }else {
+            motionList = generateFirstZoneMotion(task);
+        }
         return motionList;
     }
 
@@ -260,10 +268,7 @@
                 return motionList;
             }
 
-            BasConveyorSta basConveyorStaOrigin = basConveyorStaService.selectBySiteNo(task.getOriginSite());
-            if (basConveyorStaOrigin == null) {
-                return motionList;
-            }
+
 
             //妫�娴嬬┛姊溅鏄惁鏈変换鍔$粦瀹�
             boolean shuttleResult = Utils.checkShuttleHasBinding(shuttleDevice, task.getTaskNo());
@@ -442,6 +447,268 @@
         return motionList;
     }
 
+    public List<Motion> generateSecondZoneMotion(Task task) {
+        List<Motion> motionList = new ArrayList<>();
+        int originSite = Integer.parseInt(task.getOriginSite());
+
+        String conveyLocNo;
+        if (originSite == 1015 || originSite == 1026) {
+            BasConveyorSta basConveyorStaOrigin = basConveyorStaService.selectBySiteNo(task.getOriginSite());
+            if (basConveyorStaOrigin == null) {
+                return motionList;
+            }
+
+            DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Conveyor, basConveyorStaOrigin.getConveyorId().intValue());
+            StaProtocol staProtocol = devpThread.getStation().get(originSite);
+            if (staProtocol == null) {
+                return motionList;
+            } else {
+                staProtocol = staProtocol.clone();
+            }
+            conveyLocNo = staProtocol.getLocNo();
+        }else {
+            conveyLocNo = null;
+        }
+
+        if(conveyLocNo == null) {
+            return motionList;
+        }
+
+        /**
+         * 鍏ュ簱
+         */
+        if (task.getTaskSts() == TaskStsType.NEW_INBOUND.sts) {
+            // 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();
+
+            BasConveyorSta basConveyorStaDest = basConveyorStaService.selectBySiteNo(task.getDestSite());
+            if (basConveyorStaDest == null) {
+                return motionList;
+            }
+
+            //妫�娴嬬┛姊溅鏄惁鏈変换鍔$粦瀹�
+            boolean shuttleResult = Utils.checkShuttleHasBinding(shuttleDevice, task.getTaskNo());
+            if (shuttleResult) {
+                //瀛樺湪浠诲姟锛岀姝㈣В鏋�
+                return motionList;
+            }
+
+            // 鍏ュ簱鐩爣灞傛湁绌挎杞�
+            if (Utils.getLev(shuttleLocNo) == Utils.getLev(task.getDestLoc())) {
+
+                // 绌挎杞﹁蛋琛岃嚦鍙栬揣搴撲綅
+                motionList.addAll(kernelService.shuttleMove(
+                        MotionDto.build((dto -> {
+                            dto.setShuttleNo(shuttleDevice.getId().intValue());
+                            dto.setLocNo(shuttleLocNo);
+                        })),
+                        MotionDto.build((dto -> {
+                            dto.setShuttleNo(shuttleDevice.getId().intValue());
+                            dto.setShuttleDevice(shuttleDevice);
+                            dto.setLocNo(conveyLocNo);
+                        })),
+                        MotionCtgType.SHUTTLE_MOVE
+                ));
+
+                // 绌挎杞﹀叆搴撻《鍗�
+                motionList.addAll(kernelService.shuttleAction(
+                        null,
+                        MotionDto.build((dto -> {
+                            dto.setShuttleNo(shuttleDevice.getId().intValue());
+                        })),
+                        MotionCtgType.SHUTTLE_PALLET_LIFT
+                ));
+
+                // 绌挎杞﹁浇璐ц蛋琛岃嚦鐩爣搴撲綅
+                motionList.addAll(kernelService.shuttleMove(
+                        MotionDto.build((dto -> {
+                            dto.setShuttleNo(shuttleDevice.getId().intValue());
+                            dto.setLocNo(conveyLocNo);
+                        })),
+                        MotionDto.build((dto -> {
+                            dto.setShuttleNo(shuttleDevice.getId().intValue());
+                            dto.setShuttleDevice(shuttleDevice);
+                            dto.setLocNo(destLoc);
+                        })),
+                        MotionCtgType.SHUTTLE_TRANSPORT
+                ));
+
+                // 绌挎杞﹀叆搴撴墭鐩樹笅闄�
+                motionList.addAll(kernelService.shuttleAction(
+                        null,
+                        MotionDto.build((dto -> {
+                            dto.setShuttleNo(shuttleDevice.getId().intValue());
+                        })),
+                        MotionCtgType.SHUTTLE_PALLET_DOWN
+                ));
+            }
+
+        }
+
+        /**
+         * 鍑哄簱
+         */
+        if (task.getTaskSts() == TaskStsType.NEW_OUTBOUND.sts) {
+            // locNo
+            String originLoc = task.getOriginLoc();
+
+            // 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();
+
+            //妫�娴嬬┛姊溅鏄惁鏈変换鍔$粦瀹�
+            boolean shuttleResult = Utils.checkShuttleHasBinding(shuttleDevice, task.getTaskNo());
+            if (shuttleResult) {
+                //瀛樺湪浠诲姟锛岀姝㈣В鏋�
+                return motionList;
+            }
+
+            //鍒嗘瀽鍑哄簱璺緞鏀捐揣搴撲綅
+            String lastPathStartLoc = shuttleDispatcher.analyzeOutPathWaitLoc(originLoc, conveyLocNo, shuttleDevice);
+            if (lastPathStartLoc == null) {
+                return motionList;//鏈垎鏋愭垚鍔�
+            }
+
+            String standbyLocNo;
+            if (originSite == 1015) {
+                standbyLocNo = "1200101";
+            } else if (originSite == 1026) {
+                standbyLocNo = "1200105";
+            } else {
+                standbyLocNo = null;
+            }
+
+            /**
+             * 鍑哄簱
+             */
+            if (Utils.getLev(shuttleLocNo) == Utils.getLev(originLoc)) {
+
+                //绌挎杞︿笉鍦ㄥ嚭搴撳簱浣�
+                if (!shuttleLocNo.equals(task.getOriginLoc())) {
+                    // 绌挎杞﹁蛋琛岃嚦鍑哄簱搴撲綅
+                    motionList.addAll(kernelService.shuttleMove(
+                            MotionDto.build((dto -> {
+                                dto.setShuttleNo(shuttleDevice.getId().intValue());
+                                dto.setLocNo(shuttleLocNo);
+                            })),
+                            MotionDto.build((dto -> {
+                                dto.setShuttleNo(shuttleDevice.getId().intValue());
+                                dto.setShuttleDevice(shuttleDevice);
+                                dto.setLocNo(originLoc);
+                            })),
+                            MotionCtgType.SHUTTLE_MOVE
+                    ));
+                }
+
+                // 绌挎杞﹀嚭搴撻《鍗�
+                motionList.addAll(kernelService.shuttleAction(
+                        null,
+                        MotionDto.build((dto -> {
+                            dto.setShuttleNo(shuttleDevice.getId().intValue());
+                        })),
+                        MotionCtgType.SHUTTLE_PALLET_LIFT
+                ));
+
+                if (!originLoc.equals(lastPathStartLoc)) {
+                    // 绌挎杞﹁浇璐у嚭搴撹嚦鏈�鍚庝竴娈佃矾寰勭瓑寰�
+                    motionList.addAll(kernelService.shuttleMove(
+                            MotionDto.build((dto -> {
+                                dto.setShuttleNo(shuttleDevice.getId().intValue());
+                                dto.setLocNo(originLoc);
+                            })),
+                            MotionDto.build((dto -> {
+                                dto.setShuttleNo(shuttleDevice.getId().intValue());
+                                dto.setShuttleDevice(shuttleDevice);
+                                dto.setLocNo(lastPathStartLoc);
+                            })),
+                            MotionCtgType.SHUTTLE_TRANSPORT
+                    ));
+                }
+
+                // 绌挎杞﹁浇璐ц嚦杈撻�佺嚎浣�
+                motionList.addAll(kernelService.shuttleMove(
+                        MotionDto.build((dto -> {
+                            dto.setShuttleNo(shuttleDevice.getId().intValue());
+                            dto.setLocNo(lastPathStartLoc);
+                        })),
+                        MotionDto.build((dto -> {
+                            dto.setShuttleNo(shuttleDevice.getId().intValue());
+                            dto.setShuttleDevice(shuttleDevice);
+                            dto.setLocNo(conveyLocNo);
+                            dto.setStaNo(getStaByLev(Utils.getLev(task.getOriginLoc())));//杈撻�佺珯
+                        })),
+                        MotionCtgType.SHUTTLE_TRANSPORT_TO_CONVEYOR
+                ));
+
+                // 绌挎杞﹀嚭搴撴墭鐩樹笅闄�
+                motionList.addAll(kernelService.shuttleAction(
+                        null,
+                        MotionDto.build((dto -> {
+                            dto.setShuttleNo(shuttleDevice.getId().intValue());
+                        })),
+                        MotionCtgType.SHUTTLE_PALLET_DOWN
+                ));
+
+                // 绌挎杞︽彁鍗囨満寰呮満浣� - 鍒板緟鏈轰綅(鑷姩閫夋嫨鍚堥�傚緟鏈轰綅)
+                motionList.addAll(kernelService.shuttleMove(
+                        MotionDto.build((dto -> {
+                            dto.setShuttleNo(shuttleDevice.getId().intValue());
+                            dto.setLocNo(conveyLocNo);
+                        })),
+                        MotionDto.build((dto -> {
+                            dto.setShuttleNo(shuttleDevice.getId().intValue());
+                            dto.setShuttleDevice(shuttleDevice);
+                            dto.setLocNo(standbyLocNo);
+                            dto.setSync(0);//寮傛鎵ц
+                            dto.setReleaseShuttle(1);//鎵ц瀹屾垚鍚庨噴鏀惧皬杞�
+                        })),
+                        MotionCtgType.SHUTTLE_MOVE_STANDBY
+                ));
+
+            }
+
+        }
+
+        return motionList;
+    }
 
     /**
      * 鐢熸垚鍏呯數鍔ㄤ綔
diff --git a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/service/impl/MainServiceImpl.java b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/service/impl/MainServiceImpl.java
index 1ceaf1b..71a47fc 100644
--- a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/service/impl/MainServiceImpl.java
+++ b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/service/impl/MainServiceImpl.java
@@ -192,7 +192,7 @@
                         if (task1 != null) {
                             News.error("宸ヤ綔妗e凡瀛樺湪,宸ヤ綔鍙�={}", task1.getTaskNo());
                             if (staProtocol.getWorkNo().intValue() != Integer.parseInt(task1.getTaskNo())) {
-                                devpThread.writeWorkSta(staProtocol.getSiteId(), Short.parseShort(task1.getTaskNo()), Short.parseShort(task1.getDestSite()));
+                                devpThread.writeWorkSta(staProtocol.getSiteId(), Short.parseShort(task1.getTaskNo()), Short.parseShort(task1.getOriginSite()));
                                 devpThread.setPakMk(staProtocol.getSiteId(), false);
                                 News.info("杈撻�佺嚎鍏ュ簱鍛戒护涓嬪彂锛屼换鍔℃暟鎹�={}", JSON.toJSON(task1));
                             }
@@ -519,6 +519,11 @@
                             //绌挎杞﹁繘鎻愬崌鏈哄緟鏈轰綅搴撲綅鍙�  杈撻�佺嚎浣嶇疆
                             String standbyLocNoTo = shuttleStandbyTo.getDeviceStandbyLoc();
 
+                            //涓嶈蛋鎻愬崌鏈�
+                            if (staProtocol.getSiteId() == 1015 || staProtocol.getSiteId() == 1026) {
+                                standbyLocNoTo = staProtocol.getLocNo();
+                            }
+
                             if (Cools.isEmpty(task.getShuttleNo())) {
                                 //鍒嗛厤灏忚溅
                                 //璋冨害绌洪棽杞﹀幓鍙栬揣寰呮満浣�
diff --git a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/utils/ConveyorDispatcher.java b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/utils/ConveyorDispatcher.java
index c59fc38..a2cd4e3 100644
--- a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/utils/ConveyorDispatcher.java
+++ b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/utils/ConveyorDispatcher.java
@@ -1,41 +1,10 @@
 package com.zy.asrs.wcs.core.utils;
 
 import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
-/**
- * Created by vincent on 2023/10/20
- */
 @Slf4j
 @Service
 public class ConveyorDispatcher {
-
-//    @Autowired
-//    private SlaveProperties slaveProperties;
-//
-//    public DevpSlave queryByInBound(Integer staNo) {
-//        for (DevpSlave devpSlave : slaveProperties.getDevp()) {
-//            for (DevpSlave.Sta sta : devpSlave.getInSta()) {
-//                if (sta.getStaNo().equals(staNo)) {
-//                    return devpSlave;
-//                }
-//            }
-//
-//        }
-//        return null;
-//    }
-//
-//    public DevpSlave queryByOutBound(Integer staNo) {
-//        for (DevpSlave devpSlave : slaveProperties.getDevp()) {
-//            for (DevpSlave.Sta sta : devpSlave.getOutSta()) {
-//                if (sta.getStaNo().equals(staNo)) {
-//                    return devpSlave;
-//                }
-//            }
-//
-//        }
-//        return null;
-//    }
 
 }
diff --git a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/model/protocol/StaProtocol.java b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/model/protocol/StaProtocol.java
index 48f6f21..5030bf3 100644
--- a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/model/protocol/StaProtocol.java
+++ b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/model/protocol/StaProtocol.java
@@ -85,6 +85,9 @@
     // 宸ヤ綔妯″紡
     private Integer workMode;
 
+    // 搴撲綅鍙�
+    private String locNo;
+
     @Override
     public StaProtocol clone() {
         try {
diff --git a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/thread/impl/FyxcDevpThread.java b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/thread/impl/FyxcDevpThread.java
index 0235998..f5a37ec 100644
--- a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/thread/impl/FyxcDevpThread.java
+++ b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/thread/impl/FyxcDevpThread.java
@@ -125,6 +125,13 @@
                 if (null == staProtocol) {
                     staProtocol = new StaProtocol();
                     staProtocol.setSiteId(siteId);
+
+                    if (siteId == 1015) {
+                        staProtocol.setLocNo("1200301");
+                    }else if (siteId == 1026) {
+                        staProtocol.setLocNo("1200305");
+                    }
+
                     station.put(siteId, staProtocol);
                 }
                 Thread.sleep(300);

--
Gitblit v1.9.1