#
Junjie
6 天以前 5cef428c0019b6455e35807a617f648840e9c65d
zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/kernel/AnalyzeService.java
@@ -1,28 +1,22 @@
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.BasConveyorPath;
import com.zy.asrs.wcs.core.entity.ShuttleStandby;
import com.zy.asrs.wcs.core.entity.Task;
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.service.BasConveyorPathService;
import com.zy.asrs.wcs.core.service.ShuttleStandbyService;
import com.zy.asrs.wcs.core.service.TaskService;
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.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.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;
@@ -57,6 +51,8 @@
    private ShuttleStandbyService shuttleStandbyService;
    @Autowired
    private BasConveyorPathService basConveyorPathService;
    @Autowired
    private TaskCtgService taskCtgService;
    public List<Motion> generateMotion(Task task) {
        List<Motion> motionList = new ArrayList<>();
@@ -119,13 +115,6 @@
                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())
@@ -167,6 +156,7 @@
                            dto.setLiftNo(transferLiftDevice.getId().intValue());
                            dto.setLev(Utils.getLev(task.getDestLoc()));
                            dto.setStaNo(0);//提升机内侧
                            dto.setSync(0);//异步执行
                        }))
                ));
@@ -178,7 +168,6 @@
                        })),
                        MotionDto.build((dto -> {
                            dto.setShuttleNo(shuttleDevice.getId().intValue());
                            dto.setLiftNo(transferLiftDevice.getId().intValue());
                            dto.setLocNo(standbyLocNoTo);
                        })),
                        MotionCtgType.SHUTTLE_MOVE
@@ -234,6 +223,7 @@
                        null
                        , MotionDto.build((dto -> {
                            dto.setLiftNo(transferLiftDevice.getId().intValue());
                            dto.setReleaseLift(1);//执行完成后释放提升机
                        }))
                ));
@@ -383,6 +373,7 @@
                        null
                        , MotionDto.build((dto -> {
                            dto.setLiftNo(transferLiftDevice.getId().intValue());
                            dto.setReleaseLift(1);//执行完成后释放提升机
                        }))
                ));
@@ -459,13 +450,6 @@
                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())
@@ -493,13 +477,22 @@
            //穿梭车出提升机待机位库位号
            String standbyLocNoFrom = shuttleStandbyFrom.getDeviceStandbyLoc();
            //穿梭车出提升机后小车待机位
            String shuttleFromLiftStandbyLoc = shuttleStandbyFrom.getStandbyLoc();
            //穿梭车出提升机后全部待机位
            String standbyLocs = shuttleStandbyFrom.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::getDeviceNo, liftProtocol.getLiftNo())
                    .eq(BasConveyorPath::getTypeNo, taskCtg.getId()));
            if (basConveyorPath == null) {
                return motionList;
            }
@@ -628,6 +621,8 @@
                            dto.setLiftNo(transferLiftDevice.getId().intValue());
                            dto.setLev(5);//索牌项目5层是输送线层
                            dto.setStaNo(1);//提升机左侧
                            dto.setSync(0);//异步执行
                            dto.setReleaseLift(1);//执行完成后释放提升机
                        }))
                ));
@@ -639,9 +634,9 @@
                        })),
                        MotionDto.build((dto -> {
                            dto.setShuttleNo(shuttleDevice.getId().intValue());
                            dto.setLocNo(shuttleFromLiftStandbyLoc);
                            dto.setLocNo(standbyLocs);
                        })),
                        MotionCtgType.SHUTTLE_MOVE
                        MotionCtgType.SHUTTLE_MOVE_STANDBY
                ));
                // 输送线运输至出库口
@@ -684,6 +679,15 @@
                            dto.setLocNo(standbyLocNoTo);
                        })),
                        MotionCtgType.SHUTTLE_MOVE
                ));
                // 锁定目标楼层穿梭车待机位路径
                motionList.addAll(kernelService.mapLockPath(
                        null,
                        MotionDto.build((dto -> {
                            dto.setShuttleNo(shuttleDevice.getId().intValue());
                            dto.setLocNo(standbyLocNoFrom);
                        }))
                ));
                // 提升机空载移动到穿梭车层
@@ -773,6 +777,7 @@
                        null
                        , MotionDto.build((dto -> {
                            dto.setLiftNo(transferLiftDevice.getId().intValue());
                            dto.setReleaseLift(1);//执行完成后释放提升机
                        }))
                ));
@@ -808,17 +813,17 @@
                        MotionDto.build((dto -> {
                            dto.setShuttleNo(shuttleDevice.getId().intValue());
                            dto.setLiftNo(transferLiftDevice.getId().intValue());
                            dto.setLocNo(standbyLocNoTo);
                            dto.setLocNo(standbyLocNoFrom);
                        })),
                        MotionCtgType.SHUTTLE_MOVE
                ));
                // 提升机空载移动到穿梭车层
                // 提升机空载移动到目标层
                motionList.addAll(kernelService.liftMove(
                        null
                        , MotionDto.build((dto -> {
                            dto.setLiftNo(transferLiftDevice.getId().intValue());
                            dto.setLev(Utils.getLev(shuttleLocNo));
                            dto.setLev(Utils.getLev(originLoc));
                        }))
                ));
@@ -834,12 +839,12 @@
                motionList.addAll(kernelService.shuttleMove(
                        MotionDto.build((dto -> {
                            dto.setShuttleNo(shuttleDevice.getId().intValue());
                            dto.setLocNo(standbyLocNoTo);
                            dto.setLocNo(standbyLocNoFrom);
                        })),
                        MotionDto.build((dto -> {
                            dto.setShuttleNo(shuttleDevice.getId().intValue());
                            dto.setLiftNo(transferLiftDevice.getId().intValue());
                            dto.setLocNo(liftLocNoTo);
                            dto.setLocNo(liftLocNoFrom);
                        })),
                        MotionCtgType.SHUTTLE_MOVE_TO_LIFT
                ));
@@ -886,6 +891,7 @@
                            dto.setLiftNo(transferLiftDevice.getId().intValue());
                            dto.setLev(5);//索牌项目5层是输送线层
                            dto.setStaNo(1);//提升机左侧
                            dto.setSync(0);//异步执行
                        }))
                ));
@@ -897,9 +903,9 @@
                        })),
                        MotionDto.build((dto -> {
                            dto.setShuttleNo(shuttleDevice.getId().intValue());
                            dto.setLocNo(shuttleFromLiftStandbyLoc);
                            dto.setLocNo(standbyLocs);
                        })),
                        MotionCtgType.SHUTTLE_MOVE
                        MotionCtgType.SHUTTLE_MOVE_STANDBY
                ));
                // 输送线运输至出库口
@@ -970,13 +976,6 @@
        //检测穿梭车是否有任务绑定
        boolean shuttleResult = Utils.checkShuttleHasBinding(shuttleDevice, task.getTaskNo());
        if (shuttleResult) {
            //存在任务,禁止解析
            return motionList;
        }
        //检测提升机是否有任务绑定
        boolean liftResult = Utils.checkLiftHasBinding(Integer.parseInt(transferLiftDevice.getDeviceNo()));
        if (liftResult) {
            //存在任务,禁止解析
            return motionList;
        }
@@ -1142,16 +1141,15 @@
                    MotionCtgType.SHUTTLE_MOVE
            ));
            task.setLiftNo(Integer.parseInt(transferLiftDevice.getDeviceNo()));
            taskService.updateById(task);
        }
        // 穿梭车开始充电
        motionList.addAll(kernelService.shuttleCharge(
        motionList.addAll(kernelService.shuttleAction(
                null,
                MotionDto.build((dto -> {
                    dto.setShuttleNo(shuttleDevice.getId().intValue());
                }))
                })),
                MotionCtgType.SHUTTLE_CHARGE_ON
        ));
        return motionList;
@@ -1188,6 +1186,15 @@
        // 判断穿梭车是否在目标层
        if (Utils.getLev(shuttleLocNo) == Utils.getLev(locNo)) {
            // 穿梭车关闭充电
            motionList.addAll(kernelService.shuttleAction(
                    null,
                    MotionDto.build((dto -> {
                        dto.setShuttleNo(shuttleDevice.getId().intValue());
                    })),
                    MotionCtgType.SHUTTLE_CHARGE_OFF
            ));
            // 穿梭车走行至目标库位
            motionList.addAll(kernelService.shuttleMove(
@@ -1292,6 +1299,15 @@
                        dto.setLocNo(standbyLocNoTo);
                    })),
                    MotionCtgType.SHUTTLE_MOVE
            ));
            // 锁定目标楼层穿梭车待机位路径
            motionList.addAll(kernelService.mapLockPath(
                    null,
                    MotionDto.build((dto -> {
                        dto.setShuttleNo(shuttleDevice.getId().intValue());
                        dto.setLocNo(standbyLocNoFrom);
                    }))
            ));
            // 提升机空载移动到穿梭车层
@@ -1409,6 +1425,91 @@
        }
        return motionList;
    }
    /**
     * 生成小车载货迁移动作
     */
    public List<Motion> generateShuttleLadenMoveMotion(Task task) {
        List<Motion> motionList = new ArrayList<>();
        if (task.getTaskSts() != TaskStsType.NEW_LADEN_MOVE.sts) {
            return motionList;
        }
        //originLoc 源库位
        String originLoc =  task.getOriginLoc();
        // locNo 目标库位
        String locNo = task.getDestLoc();
        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());
        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)) {
            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(originLoc);
                        })),
                        MotionCtgType.SHUTTLE_MOVE
                ));
                // 穿梭车顶升
                motionList.add(Motion.build(motion -> {
                    motion.setDeviceCtg(DeviceCtgType.SHUTTLE.val());
                    motion.setDevice(String.valueOf(shuttleDevice.getId()));
                    motion.setMotionCtg(MotionCtgType.SHUTTLE_PALLET_LIFT.val());
                }));
                // 穿梭车走行至目标库位
                motionList.addAll(kernelService.shuttleMove(
                        MotionDto.build((dto -> {
                            dto.setShuttleNo(shuttleDevice.getId().intValue());
                            dto.setLocNo(originLoc);
                        })),
                        MotionDto.build((dto -> {
                            dto.setShuttleNo(shuttleDevice.getId().intValue());
                            dto.setLocNo(locNo);
                        })),
                        MotionCtgType.SHUTTLE_MOVE
                ));
                //穿梭车托盘下降
                motionList.add(Motion.build(motion -> {
                    motion.setDeviceCtg(DeviceCtgType.SHUTTLE.val());
                    motion.setDevice(String.valueOf(shuttleDevice.getId()));
                    motion.setMotionCtg(MotionCtgType.SHUTTLE_PALLET_DOWN.val());
                }));
            }
        } else {
            //小车跨层
        }
        return motionList;
    }
    /**
     * 生成小车手动动作