#
Junjie
2024-04-13 13c199274ed4d9b1f81880619867ee4d16b90dce
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;
@@ -12,12 +13,12 @@
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.rcs.entity.Motion;
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.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.thread.ShuttleThread;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -45,6 +46,8 @@
    private LiftDispatcher liftDispatcher;
//    @Autowired
//    private ConveyorDispatcher conveyorDispatcher;
    @Autowired
    private DeviceService deviceService;
    public List<Motion> generateMotion(Task task) {
        List<Motion> motionList = new ArrayList<>();
@@ -706,11 +709,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;
//        }
@@ -869,15 +872,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;
//        }
@@ -912,9 +915,195 @@
//            ));
//
//        }
//        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();
        Device device = 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 (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 sourceLoc = task.getOriginLoc();//源库位
        String targetLoc = task.getDestLoc();//任务目标(借用字段)
        String targetSite = task.getDestSite();//任务类型(借用字段)
        Device device = 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 (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(device.getId().intValue());
                            dto.setLocNo(shuttleLocNo);
                        })),
                        MotionDto.build((dto -> {
                            dto.setShuttleNo(device.getId().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(device.getId()));
                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(device.getId()));
                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(device.getId()));
                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(device.getId()));
                motion.setMotionCtg(MotionCtgType.SHUTTLE_CHARGE_OFF.val());
            }));
        } else if (targetSite.equals("reset")) {
            //复位
        } else if (targetSite.equals("takeMove")) {
            //取放货
            String shuttleLocNo = shuttleProtocol.getCurrentLocNo();
            // 判断穿梭车是否在目标层
            if (Utils.getLev(shuttleLocNo) == Utils.getLev(targetLoc)) {
                // 穿梭车走行至源库位
                motionList.addAll(kernelService.shuttleMove(
                        MotionDto.build((dto -> {
                            dto.setShuttleNo(device.getId().intValue());
                            dto.setLocNo(shuttleLocNo);
                        })),
                        MotionDto.build((dto -> {
                            dto.setShuttleNo(device.getId().intValue());
                            dto.setLocNo(sourceLoc);
                        })),
                        MotionCtgType.SHUTTLE_MOVE
                ));
                //托盘顶升
                motionList.add(Motion.build(motion -> {
                    motion.setDeviceCtg(DeviceCtgType.SHUTTLE.val());
                    motion.setDevice(String.valueOf(device.getId()));
                    motion.setMotionCtg(MotionCtgType.SHUTTLE_PALLET_LIFT.val());
                }));
                // 穿梭车走行至目标库位
                motionList.addAll(kernelService.shuttleMove(
                        MotionDto.build((dto -> {
                            dto.setShuttleNo(device.getId().intValue());
                            dto.setLocNo(sourceLoc);
                        })),
                        MotionDto.build((dto -> {
                            dto.setShuttleNo(device.getId().intValue());
                            dto.setLocNo(targetLoc);
                        })),
                        MotionCtgType.SHUTTLE_MOVE
                ));
                //托盘下降
                motionList.add(Motion.build(motion -> {
                    motion.setDeviceCtg(DeviceCtgType.SHUTTLE.val());
                    motion.setDevice(String.valueOf(device.getId()));
                    motion.setMotionCtg(MotionCtgType.SHUTTLE_PALLET_DOWN.val());
                }));
            }
        }
        return motionList;
    }
}