#
Junjie
2024-10-17 d62c5c0eb2e28b7bf27d23de84a609b5a2e415e4
zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/kernel/AnalyzeService.java
@@ -1,17 +1,14 @@
package com.zy.asrs.wcs.core.kernel;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zy.asrs.wcs.core.domain.dto.MotionDto;
import com.zy.asrs.wcs.core.entity.*;
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.TaskCtgType;
import com.zy.asrs.wcs.core.model.enums.TaskStsType;
import com.zy.asrs.wcs.core.model.NavigateNode;
import com.zy.asrs.wcs.core.model.enums.*;
import com.zy.asrs.wcs.core.service.*;
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;
import com.zy.asrs.wcs.core.utils.*;
import com.zy.asrs.wcs.rcs.News;
import com.zy.asrs.wcs.rcs.cache.SlaveConnection;
import com.zy.asrs.wcs.rcs.entity.Device;
import com.zy.asrs.wcs.rcs.model.enums.SlaveType;
@@ -24,6 +21,7 @@
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
/**
@@ -57,6 +55,15 @@
    private BasConveyorService basConveyorService;
    @Autowired
    private TaskCtgService taskCtgService;
    public Integer getStaByLev(Integer lev) {
        HashMap<Integer, Integer> map = new HashMap<>();
        map.put(1, 31006);
        map.put(2, 31007);
        map.put(3, 31008);
        return map.get(lev);
    }
    public List<Motion> generateMotion(Task task) {
        List<Motion> motionList = new ArrayList<>();
@@ -106,6 +113,11 @@
                return motionList;
            }
            BasConveyorSta basConveyorStaDest = basConveyorStaService.selectBySiteNo(task.getDestSite());
            if (basConveyorStaDest == null) {
                return motionList;
            }
            //检测穿梭车是否有任务绑定
            boolean shuttleResult = Utils.checkShuttleHasBinding(shuttleDevice, task.getTaskNo());
            if (shuttleResult) {
@@ -140,6 +152,9 @@
            //穿梭车出提升机待机位库位号
            String standbyLocNoFrom = shuttleStandbyFrom.getDeviceStandbyLoc();
            //换层需要锁定的路径
            List<String> lockPath = shuttleStandbyFrom.getLockPath$();
            // 入库目标层有穿梭车
            if (Utils.getLev(shuttleLocNo) == Utils.getLev(task.getDestLoc())) {
@@ -153,8 +168,9 @@
                        , MotionDto.build((dto -> {
                            dto.setLiftNo(transferLiftDevice.getId().intValue());
                            dto.setLev(Utils.getLev(task.getDestLoc()));
                            dto.setStaNo(Integer.parseInt(task.getDestSite()));
                            dto.setSync(0);//异步执行
                            dto.setStaNo(getStaByLev(Utils.getLev(task.getDestLoc())));
                            dto.setDevpNo(basConveyorStaDest.getConveyorDeviceId().intValue());
//                            dto.setSync();//异步执行
                        }))
                ));
@@ -180,7 +196,7 @@
                        MotionCtgType.SHUTTLE_PALLET_LIFT
                ));
                // 穿梭车走行至目标库位
                // 穿梭车载货走行至目标库位
                motionList.addAll(kernelService.shuttleMove(
                        MotionDto.build((dto -> {
                            dto.setShuttleNo(shuttleDevice.getId().intValue());
@@ -190,8 +206,9 @@
                            dto.setShuttleNo(shuttleDevice.getId().intValue());
                            dto.setLiftNo(transferLiftDevice.getId().intValue());
                            dto.setLocNo(destLoc);
                            dto.setReleaseLift(2);//执行中释放提升机
                        })),
                        MotionCtgType.SHUTTLE_MOVE
                        MotionCtgType.SHUTTLE_TRANSPORT
                ));
                // 穿梭车入库托盘下降
@@ -218,7 +235,8 @@
                        , MotionDto.build((dto -> {
                            dto.setLiftNo(transferLiftDevice.getId().intValue());
                            dto.setLev(Utils.getLev(task.getDestLoc()));
                            dto.setStaNo(Integer.parseInt(task.getDestSite()));
                            dto.setStaNo(getStaByLev(Utils.getLev(task.getDestLoc())));
                            dto.setDevpNo(basConveyorStaDest.getConveyorDeviceId().intValue());
                        }))
                ));
@@ -234,6 +252,15 @@
                            dto.setLocNo(standbyLocNoTo);
                        })),
                        MotionCtgType.SHUTTLE_MOVE
                ));
                // 锁定换层路径
                motionList.addAll(kernelService.mapLockPath(
                        null,
                        MotionDto.build((dto -> {
                            dto.setShuttleNo(shuttleDevice.getId().intValue());
                            dto.setLocNo(JSON.toJSONString(lockPath));
                        }))
                ));
                // 提升机空载移动到穿梭车层
@@ -327,6 +354,15 @@
                        }))
                ));
                // 解锁换层路径
                motionList.addAll(kernelService.mapUnlockPath(
                        null,
                        MotionDto.build((dto -> {
                            dto.setShuttleNo(shuttleDevice.getId().intValue());
                            dto.setLocNo(JSON.toJSONString(lockPath));
                        }))
                ));
                // 穿梭车入库顶升
                motionList.addAll(kernelService.shuttleAction(
                        null,
@@ -336,7 +372,7 @@
                        MotionCtgType.SHUTTLE_PALLET_LIFT
                ));
                // 穿梭车走行至目标库位
                // 穿梭车载货走行至目标库位
                motionList.addAll(kernelService.shuttleMove(
                        MotionDto.build((dto -> {
                            dto.setShuttleNo(shuttleDevice.getId().intValue());
@@ -346,8 +382,9 @@
                            dto.setShuttleNo(shuttleDevice.getId().intValue());
                            dto.setLiftNo(transferLiftDevice.getId().intValue());
                            dto.setLocNo(destLoc);
                            dto.setReleaseLift(2);//执行中释放提升机
                        })),
                        MotionCtgType.SHUTTLE_MOVE
                        MotionCtgType.SHUTTLE_TRANSPORT
                ));
                // 穿梭车入库托盘下降
@@ -402,6 +439,11 @@
                return motionList;
            }
            BasConveyorSta basConveyorStaOrigin = basConveyorStaService.selectBySiteNo(task.getOriginSite());
            if (basConveyorStaOrigin == null) {
                return motionList;
            }
            //检测穿梭车是否有任务绑定
            boolean shuttleResult = Utils.checkShuttleHasBinding(shuttleDevice, task.getTaskNo());
            if (shuttleResult) {
@@ -436,8 +478,11 @@
            //穿梭车出提升机待机位库位号
            String standbyLocNoFrom = shuttleStandbyFrom.getDeviceStandbyLoc();
            //穿梭车出提升机后小车待机位
            String shuttleFromLiftStandbyLoc = shuttleStandbyFrom.getStandbyLoc();
            //穿梭车出提升机后全部待机位
            String standbyLocs = shuttleStandbyFrom.getStandbyLoc();//获取全部待机位
            //换层需要锁定的路径
            List<String> lockPath = shuttleStandbyFrom.getLockPath$();
            //获取出库任务类型
            TaskCtg taskCtg = taskCtgService.getOne(new LambdaQueryWrapper<TaskCtg>()
@@ -453,6 +498,12 @@
                    .eq(BasConveyorPath::getTypeNo, taskCtg.getId()));
            if (basConveyorPath == null) {
                return motionList;
            }
            //分析出库路径待机库位
            String lastPathStartLoc = shuttleDispatcher.analyzeOutPathWaitLoc(originLoc, standbyLocNoTo, shuttleDevice);
            if (lastPathStartLoc == null) {
                return motionList;//未分析成功
            }
            /**
@@ -485,7 +536,7 @@
                        MotionCtgType.SHUTTLE_PALLET_LIFT
                ));
                // 穿梭车出库至提升机待机位
                // 穿梭车载货出库至最后一段路径等待
                motionList.addAll(kernelService.shuttleMove(
                        MotionDto.build((dto -> {
                            dto.setShuttleNo(shuttleDevice.getId().intValue());
@@ -493,10 +544,24 @@
                        })),
                        MotionDto.build((dto -> {
                            dto.setShuttleNo(shuttleDevice.getId().intValue());
                            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.setLiftNo(transferLiftDevice.getId().intValue());
                            dto.setLocNo(standbyLocNoTo);
                            dto.setStaNo(getStaByLev(Utils.getLev(task.getOriginLoc())));//输送站
                        })),
                        MotionCtgType.SHUTTLE_MOVE
                        MotionCtgType.SHUTTLE_TRANSPORT_TO_CONVEYOR
                ));
                // 穿梭车出库托盘下降
@@ -508,23 +573,7 @@
                        MotionCtgType.SHUTTLE_PALLET_DOWN
                ));
                // 提升机载货移动
                motionList.addAll(kernelService.liftMoveGoods(
                        MotionDto.build((dto -> {
                            dto.setLiftNo(transferLiftDevice.getId().intValue());
                            dto.setLev(Utils.getLev(task.getOriginLoc()));
                            dto.setStaNo(Integer.parseInt(task.getOriginSite()));//起始站点
                        }))
                        , MotionDto.build((dto -> {
                            dto.setLiftNo(transferLiftDevice.getId().intValue());
                            dto.setLev(1);//光泰1层是输送线层
                            dto.setStaNo(31004);//出库站点
                            dto.setSync(0);//异步执行
                            dto.setReleaseLift(1);//执行完成后释放提升机
                        }))
                ));
                // 穿梭车提升机待机位 - 到待机位
                // 穿梭车提升机待机位 - 到待机位(自动选择合适待机位)
                motionList.addAll(kernelService.shuttleMove(
                        MotionDto.build((dto -> {
                            dto.setShuttleNo(shuttleDevice.getId().intValue());
@@ -532,23 +581,41 @@
                        })),
                        MotionDto.build((dto -> {
                            dto.setShuttleNo(shuttleDevice.getId().intValue());
                            dto.setLocNo(shuttleFromLiftStandbyLoc);
                            dto.setLocNo(standbyLocs);
                            dto.setSync(0);//异步执行
                            dto.setReleaseShuttle(1);//执行完成后释放小车
                        })),
                        MotionCtgType.SHUTTLE_MOVE
                        MotionCtgType.SHUTTLE_MOVE_STANDBY
                ));
                // 提升机载货移动
                motionList.addAll(kernelService.liftMoveGoods(
                        MotionDto.build((dto -> {
                            dto.setLiftNo(transferLiftDevice.getId().intValue());
                            dto.setLev(Utils.getLev(task.getOriginLoc()));
                            dto.setStaNo(getStaByLev(Utils.getLev(task.getOriginLoc())));//起始站点
                        }))
                        , MotionDto.build((dto -> {
                            dto.setLiftNo(transferLiftDevice.getId().intValue());
                            dto.setLev(1);//光泰1层是输送线层
                            dto.setStaNo(31001);//出库站点
                            dto.setDevpNo(basConveyorStaOrigin.getConveyorDeviceId().intValue());
                            dto.setReleaseLift(1);//执行完成后释放提升机
                        }))
                ));
                // 输送线运输至出库口
                motionList.addAll(kernelService.conveyorOutbound(
                        MotionDto.build((dto -> {
                            dto.setDevpNo(basConveyorPath.getDeviceId().intValue());
                            dto.setStaNo(basConveyorPath.getDeviceStn());
                        })),
                        MotionDto.build((dto -> {
                            dto.setDevpNo(basConveyorPath.getDeviceId().intValue());
                            dto.setStaNo(basConveyorPath.getStnNo());
                        })),
                        MotionCtgType.CONVEYOR_OUTBOUND
                ));
//                motionList.addAll(kernelService.conveyorOutbound(
//                        MotionDto.build((dto -> {
//                            dto.setDevpNo(basConveyorPath.getDeviceId().intValue());
//                            dto.setStaNo(basConveyorPath.getDeviceStn());
//                        })),
//                        MotionDto.build((dto -> {
//                            dto.setDevpNo(basConveyorPath.getDeviceId().intValue());
//                            dto.setStaNo(basConveyorPath.getStnNo());
//                        })),
//                        MotionCtgType.CONVEYOR_OUTBOUND
//                ));
            /**
             * 二、出库起始层没有穿梭车
@@ -567,6 +634,15 @@
                            dto.setLocNo(standbyLocNoTo);
                        })),
                        MotionCtgType.SHUTTLE_MOVE
                ));
                // 锁定换层路径
                motionList.addAll(kernelService.mapLockPath(
                        null,
                        MotionDto.build((dto -> {
                            dto.setShuttleNo(shuttleDevice.getId().intValue());
                            dto.setLocNo(JSON.toJSONString(lockPath));
                        }))
                ));
                // 提升机空载移动到穿梭车层
@@ -660,6 +736,15 @@
                        }))
                ));
                // 解锁换层路径
                motionList.addAll(kernelService.mapUnlockPath(
                        null,
                        MotionDto.build((dto -> {
                            dto.setShuttleNo(shuttleDevice.getId().intValue());
                            dto.setLocNo(JSON.toJSONString(lockPath));
                        }))
                ));
                // 穿梭车提升机待机位至出库库位
                motionList.addAll(kernelService.shuttleMove(
                        MotionDto.build((dto -> {
@@ -683,7 +768,7 @@
                        MotionCtgType.SHUTTLE_PALLET_LIFT
                ));
                // 穿梭车出库至提升机待机位
                // 穿梭车载货出库至最后一段路径等待
                motionList.addAll(kernelService.shuttleMove(
                        MotionDto.build((dto -> {
                            dto.setShuttleNo(shuttleDevice.getId().intValue());
@@ -691,10 +776,24 @@
                        })),
                        MotionDto.build((dto -> {
                            dto.setShuttleNo(shuttleDevice.getId().intValue());
                            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.setLiftNo(transferLiftDevice.getId().intValue());
                            dto.setLocNo(standbyLocNoFrom);
                            dto.setStaNo(getStaByLev(Utils.getLev(task.getOriginLoc())));//输送站
                        })),
                        MotionCtgType.SHUTTLE_MOVE
                        MotionCtgType.SHUTTLE_TRANSPORT_TO_CONVEYOR
                ));
                // 穿梭车出库托盘下降
@@ -706,23 +805,7 @@
                        MotionCtgType.SHUTTLE_PALLET_DOWN
                ));
                // 提升机载货移动
                motionList.addAll(kernelService.liftMoveGoods(
                        MotionDto.build((dto -> {
                            dto.setLiftNo(transferLiftDevice.getId().intValue());
                            dto.setLev(Utils.getLev(task.getOriginLoc()));
                            dto.setStaNo(Integer.parseInt(task.getOriginSite()));//起始站点
                        }))
                        , MotionDto.build((dto -> {
                            dto.setLiftNo(transferLiftDevice.getId().intValue());
                            dto.setLev(1);//光泰1层是输送线层
                            dto.setStaNo(31004);//出库站点
                            dto.setSync(0);//异步执行
                            dto.setReleaseLift(1);//执行完成后释放提升机
                        }))
                ));
                // 穿梭车提升机待机位 - 到待机位
                // 穿梭车提升机待机位 - 到待机位(自动选择合适待机位)
                motionList.addAll(kernelService.shuttleMove(
                        MotionDto.build((dto -> {
                            dto.setShuttleNo(shuttleDevice.getId().intValue());
@@ -730,23 +813,41 @@
                        })),
                        MotionDto.build((dto -> {
                            dto.setShuttleNo(shuttleDevice.getId().intValue());
                            dto.setLocNo(shuttleFromLiftStandbyLoc);
                            dto.setLocNo(standbyLocs);
                            dto.setSync(0);//异步执行
                            dto.setReleaseShuttle(1);//执行完成后释放小车
                        })),
                        MotionCtgType.SHUTTLE_MOVE
                        MotionCtgType.SHUTTLE_MOVE_STANDBY
                ));
                // 提升机载货移动
                motionList.addAll(kernelService.liftMoveGoods(
                        MotionDto.build((dto -> {
                            dto.setLiftNo(transferLiftDevice.getId().intValue());
                            dto.setLev(Utils.getLev(task.getOriginLoc()));
                            dto.setStaNo(getStaByLev(Utils.getLev(task.getOriginLoc())));//起始站点
                        }))
                        , MotionDto.build((dto -> {
                            dto.setLiftNo(transferLiftDevice.getId().intValue());
                            dto.setLev(1);//光泰1层是输送线层
                            dto.setStaNo(31001);//出库站点
                            dto.setDevpNo(basConveyorStaOrigin.getConveyorDeviceId().intValue());
                            dto.setReleaseLift(1);//执行完成后释放提升机
                        }))
                ));
                // 输送线运输至出库口
                motionList.addAll(kernelService.conveyorOutbound(
                        MotionDto.build((dto -> {
                            dto.setDevpNo(basConveyorPath.getDeviceId().intValue());
                            dto.setStaNo(basConveyorPath.getDeviceStn());
                        })),
                        MotionDto.build((dto -> {
                            dto.setDevpNo(basConveyorPath.getDeviceId().intValue());
                            dto.setStaNo(basConveyorPath.getStnNo());
                        })),
                        MotionCtgType.CONVEYOR_OUTBOUND
                ));
//                motionList.addAll(kernelService.conveyorOutbound(
//                        MotionDto.build((dto -> {
//                            dto.setDevpNo(basConveyorPath.getDeviceId().intValue());
//                            dto.setStaNo(basConveyorPath.getDeviceStn());
//                        })),
//                        MotionDto.build((dto -> {
//                            dto.setDevpNo(basConveyorPath.getDeviceId().intValue());
//                            dto.setStaNo(basConveyorPath.getStnNo());
//                        })),
//                        MotionCtgType.CONVEYOR_OUTBOUND
//                ));
            }
@@ -1113,6 +1214,9 @@
            //穿梭车出提升机待机位库位号
            String standbyLocNoFrom = liftDispatcher.getLiftStandByLocNo(liftThread, Utils.getLev(task.getDestLoc()));
            //换层需要锁定的路径
            List<String> lockPath = liftDispatcher.getLockPathByLocNo(liftThread, Utils.getLev(task.getDestLoc()));
            // 穿梭车走行至提升机库位待机位
            motionList.addAll(kernelService.shuttleMove(
@@ -1126,6 +1230,15 @@
                        dto.setLocNo(standbyLocNoTo);
                    })),
                    MotionCtgType.SHUTTLE_MOVE
            ));
            // 锁定换层路径
            motionList.addAll(kernelService.mapLockPath(
                    null,
                    MotionDto.build((dto -> {
                        dto.setShuttleNo(shuttleDevice.getId().intValue());
                        dto.setLocNo(JSON.toJSONString(lockPath));
                    }))
            ));
            // 提升机空载移动到穿梭车层
@@ -1215,6 +1328,15 @@
                    null
                    , MotionDto.build((dto -> {
                        dto.setLiftNo(liftDevice.getId().intValue());
                    }))
            ));
            // 解锁换层路径
            motionList.addAll(kernelService.mapUnlockPath(
                    null,
                    MotionDto.build((dto -> {
                        dto.setShuttleNo(shuttleDevice.getId().intValue());
                        dto.setLocNo(JSON.toJSONString(lockPath));
                    }))
            ));
@@ -1347,7 +1469,7 @@
                    motion.setMotionCtg(MotionCtgType.SHUTTLE_PALLET_LIFT.val());
                }));
                // 穿梭车走行至目标库位
                // 穿梭车载货走行至目标库位
                motionList.addAll(kernelService.shuttleMove(
                        MotionDto.build((dto -> {
                            dto.setShuttleNo(device.getId().intValue());
@@ -1357,7 +1479,7 @@
                            dto.setShuttleNo(device.getId().intValue());
                            dto.setLocNo(targetLoc);
                        })),
                        MotionCtgType.SHUTTLE_MOVE
                        MotionCtgType.SHUTTLE_TRANSPORT
                ));
                //托盘下降