#
Junjie
2025-04-15 d56b8093dc9e3e75f8efe1a0f1aa6d821c9c3dfb
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;
    }
@@ -111,11 +119,6 @@
                return motionList;
            }
            BasConveyorSta basConveyorStaDest = basConveyorStaService.selectBySiteNo(task.getDestSite());
            if (basConveyorStaDest == null) {
                return motionList;
            }
            //检测穿梭车是否有任务绑定
            boolean shuttleResult = Utils.checkShuttleHasBinding(shuttleDevice, task.getTaskNo());
            if (shuttleResult) {
@@ -150,9 +153,9 @@
                            dto.setLiftNo(transferLiftDevice.getId().intValue());
                            dto.setLev(Utils.getLev(task.getDestLoc()));
                            dto.setStaNo(Integer.parseInt(task.getDestSite()));
                            dto.setDevpNo(basConveyorStaDest.getConveyorDeviceId().intValue());
                            dto.setReleaseLift(1);//执行完成后释放提升机
                        }))
//                            dto.setReleaseLift(1);//执行完成后释放提升机
                        })),
                        MotionCtgType.LIFT_WITH_GOODS_IN
                ));
                // 穿梭车走行至提升机库位
@@ -189,6 +192,7 @@
                            dto.setShuttleDevice(shuttleDevice);
                            dto.setLiftNo(transferLiftDevice.getId().intValue());
                            dto.setLocNo(standbyLocNoTo);
                            dto.setReleaseLift(1);//执行完成后释放提升机
                        })),
                        MotionCtgType.SHUTTLE_TRANSPORT
                ));
@@ -260,11 +264,6 @@
                return motionList;
            }
            BasConveyorSta basConveyorStaOrigin = basConveyorStaService.selectBySiteNo(task.getOriginSite());
            if (basConveyorStaOrigin == null) {
                return motionList;
            }
            //检测穿梭车是否有任务绑定
            boolean shuttleResult = Utils.checkShuttleHasBinding(shuttleDevice, task.getTaskNo());
            if (shuttleResult) {
@@ -284,22 +283,14 @@
            //穿梭车进提升机待机位库位号 输送线位置
            String standbyLocNoTo = shuttleStandbyTo.getDeviceStandbyLoc();
            //穿梭车换层时待机位置 使用表列 memo数据
            String standbyLocNoMemo = shuttleStandbyTo.getMemo();
            //穿梭车待机位置 使用表列
            String standbyLocNoList = shuttleStandbyTo.getStandbyLoc();
            //获取出库任务类型
            TaskCtg taskCtg = taskCtgService.getOne(new LambdaQueryWrapper<TaskCtg>()
                    .eq(TaskCtg::getFlag, String.valueOf(TaskCtgType.OUT))
                    .eq(TaskCtg::getStatus, 1));
            if (taskCtg == null) {
                return motionList;
            }
            //获取输送线路径
            BasConveyorPath basConveyorPath = basConveyorPathService.getOne(new LambdaQueryWrapper<BasConveyorPath>()
                    .eq(BasConveyorPath::getDeviceStn, task.getOriginSite())
                    .eq(BasConveyorPath::getDeviceNo, liftProtocol.getLiftNo())
                    .eq(BasConveyorPath::getTypeNo, taskCtg.getId()));
            if (basConveyorPath == null) {
                return motionList;
            }
@@ -369,15 +360,16 @@
                            dto.setLocNo(standbyLocNoTo);
                            dto.setStaNo(getStaByLev(Utils.getLev(task.getOriginLoc())));//输送站
                        })),
                        MotionCtgType.SHUTTLE_TRANSPORT_TO_CONVEYOR
                        MotionCtgType.SHUTTLE_TRANSPORT
                ));
                Integer liftLevLogic = liftDispatcher.getLiftLevOffset(transferLiftDevice.getId().intValue(), Utils.getLev(originLoc));
                // 提升机空载移动到出库层
                motionList.addAll(kernelService.liftMove(
                        null
                        , MotionDto.build((dto -> {
                            dto.setLiftNo(transferLiftDevice.getId().intValue());
                            dto.setLev(Utils.getLev(originLoc));
                            dto.setLev(liftLevLogic);
                        }))
                ));
@@ -413,8 +405,8 @@
                        MotionDto.build((dto -> {
                            dto.setShuttleNo(shuttleDevice.getId().intValue());
                            dto.setShuttleDevice(shuttleDevice);
                            dto.setLocNo(standbyLocNoTo);
                            dto.setSync(0);//异步执行
                            dto.setLocNo(standbyLocNoList);
//                            dto.setSync(0);//异步执行
                            dto.setReleaseShuttle(1);//执行完成后释放小车
                        })),
                        MotionCtgType.SHUTTLE_MOVE_STANDBY
@@ -430,9 +422,9 @@
                        , MotionDto.build((dto -> {
                            dto.setLiftNo(transferLiftDevice.getId().intValue());
                            dto.setStaNo(Integer.parseInt(task.getDestSite()));//出库站点
                            dto.setDevpNo(basConveyorStaOrigin.getConveyorDeviceId().intValue());
                            dto.setReleaseLift(1);//执行完成后释放提升机
                        }))
                        })),
                        MotionCtgType.LIFT_WITH_GOODS_OUT
                ));
            }
@@ -442,6 +434,269 @@
        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();
            //检测穿梭车是否有任务绑定
            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;//未分析成功
            }
            //获取小车待机库位 ==> 进提升机
            ShuttleStandby shuttleStandbyTo = shuttleStandbyService.getOne(new LambdaQueryWrapper<ShuttleStandby>()
                    .eq(ShuttleStandby::getDeviceLev, Utils.getLev(shuttleLocNo))
                    .eq(ShuttleStandby::getStatus, 1));
            //穿梭车待机位置 使用表列
            String standbyLocNoList = shuttleStandbyTo.getStandbyLoc();
            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(standbyLocNoList);
//                            dto.setSync(0);//异步执行
                            dto.setReleaseShuttle(1);//执行完成后释放小车
                        })),
                        MotionCtgType.SHUTTLE_MOVE_STANDBY
                ));
            }
        }
        return motionList;
    }
    /**
     * 生成充电动作
@@ -956,12 +1211,13 @@
        if (destSite.equals("move")) {
            //提升机升降楼层
            Integer liftLevLogic = liftDispatcher.getLiftLevOffset(device.getId().intValue(), Integer.parseInt(task.getDestLoc()));
            // 提升机空载移动到穿梭车层
            motionList.addAll(kernelService.liftMove(
                    null
                    , MotionDto.build((dto -> {
                        dto.setLiftNo(device.getId().intValue());
                        dto.setLev(Integer.parseInt(task.getDestLoc()));
                        dto.setLev(liftLevLogic);
                    }))
            ));
@@ -973,19 +1229,23 @@
                return motionList;
            }
            Integer originLev = liftDispatcher.getLiftLevOffset(device.getId().intValue(), Utils.getLev(basConveyorStaOrigin.getLocNo()));
            Integer targetLev = liftDispatcher.getLiftLevOffset(device.getId().intValue(), Utils.getLev(basConveyorStaDest.getLocNo()));
            // 提升机移动托盘
            motionList.addAll(kernelService.liftMoveGoods(
                    MotionDto.build((dto -> {
                        dto.setLiftNo(device.getId().intValue());
                        dto.setLev(Utils.getLev(basConveyorStaOrigin.getLocNo()));
                        dto.setLev(originLev);
                        dto.setStaNo(Integer.parseInt(task.getOriginSite()));
                    }))
                    , MotionDto.build((dto -> {
                        dto.setLiftNo(device.getId().intValue());
                        dto.setLev(Utils.getLev(basConveyorStaDest.getLocNo()));
                        dto.setLev(targetLev);
                        dto.setDevpNo(basConveyorStaDest.getConveyorDeviceId().intValue());
                        dto.setStaNo(Integer.parseInt(task.getDestSite()));
                    }))
                    })),
                    MotionCtgType.LIFT_WITH_GOODS
            ));
        } else if (destSite.equals("lock")) {