Junjie
2024-12-11 8ef2bb5e46d84594e6ed632c07ea0b47a1bf6c4d
zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/kernel/KernelService.java
@@ -1,10 +1,21 @@
package com.zy.asrs.wcs.core.kernel;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zy.asrs.framework.exception.CoolException;
import com.zy.asrs.wcs.core.domain.dto.MotionDto;
import com.zy.asrs.wcs.core.model.NavigateNode;
import com.zy.asrs.wcs.core.model.enums.DeviceCtgType;
import com.zy.asrs.wcs.core.model.enums.MotionCtgType;
import com.zy.asrs.wcs.core.entity.Motion;
import com.zy.asrs.wcs.core.model.enums.NavigationMapType;
import com.zy.asrs.wcs.core.service.MotionService;
import com.zy.asrs.wcs.core.utils.LiftDispatcher;
import com.zy.asrs.wcs.core.utils.NavigateUtils;
import com.zy.asrs.wcs.core.utils.Utils;
import com.zy.asrs.wcs.rcs.News;
import com.zy.asrs.wcs.rcs.entity.Device;
import com.zy.asrs.wcs.rcs.service.DeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -19,7 +30,12 @@
    @Autowired
    private MotionService motionService;
    @Autowired
    private LiftDispatcher liftDispatcher;
    @Autowired
    private NavigateUtils navigateUtils;
    @Autowired
    private DeviceService deviceService;
    // agv -----------------------------------------------------------------------------
    @Deprecated
@@ -50,16 +66,18 @@
            motion.setMotionCtg(MotionCtgType.LIFT_MOVE.val());
            if (null != origin) {
                motion.setOrigin(String.valueOf(origin.getLev()));
                motion.setOrigin(String.valueOf(liftDispatcher.getLiftLevOffset(target.getLiftNo(), origin.getLev())));
            }
            motion.setTarget(String.valueOf(target.getLev()));
        }));
            motion.setTarget(String.valueOf(liftDispatcher.getLiftLevOffset(target.getLiftNo(), target.getLev())));
//        if (target.getUpdateLiftNo() != null && target.getWrkNo() != null) {
//            if (target.getUpdateLiftNo()) {
//
//            }
//        }
            if (target.getSync() != null) {
                motion.setSync(target.getSync());
            }
            if (target.getReleaseLift() != null) {
                motion.setReleaseLift(target.getReleaseLift());
            }
        }));
        return motionList;
    }
@@ -77,11 +95,23 @@
            motion.setMotionCtg(MotionCtgType.LIFT_WITH_GOODS.val());
            if (null != origin) {
                motion.setOrigin(String.valueOf(origin.getLev()));
                motion.setOrigin(String.valueOf(liftDispatcher.getLiftLevOffset(target.getLiftNo(), origin.getLev())));
                motion.setOriDrt(origin.getStaNo());//源站
            }
            motion.setTarget(String.valueOf(target.getLev()));
            motion.setTarget(String.valueOf(liftDispatcher.getLiftLevOffset(target.getLiftNo(), target.getLev())));
            motion.setTarDrt(target.getStaNo());//目标站
            if (target.getDevpNo() != null) {
                motion.setDockNo(String.valueOf(target.getDevpNo()));//输送线ID
            }
            if (target.getSync() != null) {
                motion.setSync(target.getSync());
            }
            if (target.getReleaseLift() != null) {
                motion.setReleaseLift(target.getReleaseLift());
            }
        }));
        return motionList;
@@ -100,9 +130,14 @@
            motion.setMotionCtg(MotionCtgType.LIFT_WITH_SHUTTLE.val());
            if (null != origin) {
                motion.setOrigin(String.valueOf(origin.getLev()));
                motion.setOrigin(String.valueOf(liftDispatcher.getLiftLevOffset(target.getLiftNo(), origin.getLev())));
            }
            motion.setTarget(String.valueOf(target.getLev()));
            if (target.getTaskNo() != null) {
                motion.setTaskNo(target.getTaskNo());
            }
            motion.setTarget(String.valueOf(liftDispatcher.getLiftLevOffset(target.getLiftNo(), target.getLev())));
        }));
        return motionList;
@@ -121,9 +156,9 @@
            motion.setMotionCtg(MotionCtgType.LIFT_WITH_GOODS_AND_SHUTTLE.val());
            if (null != origin) {
                motion.setOrigin(String.valueOf(origin.getLev()));
                motion.setOrigin(String.valueOf(liftDispatcher.getLiftLevOffset(target.getLiftNo(), origin.getLev())));
            }
            motion.setTarget(String.valueOf(target.getLev()));
            motion.setTarget(String.valueOf(liftDispatcher.getLiftLevOffset(target.getLiftNo(), target.getLev())));
        }));
        return motionList;
@@ -141,7 +176,7 @@
            motion.setMotionCtg(MotionCtgType.LIFT_TRANSPORT_TO_CONVEYOR.val());
            motion.setOrigin(String.valueOf(origin.getLev()));
            motion.setOrigin(String.valueOf(liftDispatcher.getLiftLevOffset(origin.getLiftNo(), origin.getLev())));
            motion.setDockNo(String.valueOf(target.getDevpNo()));
            motion.setTarget(String.valueOf(target.getStaNo()));
@@ -150,8 +185,100 @@
        return motionList;
    }
    /**
     * 提升机锁定
     */
    public List<Motion> liftLock(MotionDto origin, MotionDto target) {
        List<Motion> motionList = new ArrayList<>();
        motionList.add(Motion.build(motion -> {
            motion.setDeviceCtg(DeviceCtgType.LIFT.val());
            motion.setDevice(String.valueOf(target.getLiftNo()));
            motion.setMotionCtg(MotionCtgType.LIFT_LOCK.val());
            if (target.getSync() != null) {
                motion.setSync(target.getSync());
            }
            if (target.getReleaseLift() != null) {
                motion.setReleaseLift(target.getReleaseLift());
            }
        }));
        return motionList;
    }
    /**
     * 提升机解锁
     */
    public List<Motion> liftUnlock(MotionDto origin, MotionDto target) {
        List<Motion> motionList = new ArrayList<>();
        motionList.add(Motion.build(motion -> {
            motion.setDeviceCtg(DeviceCtgType.LIFT.val());
            motion.setDevice(String.valueOf(target.getLiftNo()));
            motion.setMotionCtg(MotionCtgType.LIFT_UNLOCK.val());
            if (target.getSync() != null) {
                motion.setSync(target.getSync());
            }
            if (target.getReleaseLift() != null) {
                motion.setReleaseLift(target.getReleaseLift());
            }
        }));
        return motionList;
    }
    /**
     * 提升机-小车已到位
     */
    public List<Motion> liftShuttleArrival(MotionDto origin, MotionDto target) {
        List<Motion> motionList = new ArrayList<>();
        motionList.add(Motion.build(motion -> {
            motion.setDeviceCtg(DeviceCtgType.LIFT.val());
            motion.setDevice(String.valueOf(target.getLiftNo()));
            motion.setMotionCtg(MotionCtgType.LIFT_SHUTTLE_ARRIVAL.val());
        }));
        return motionList;
    }
    /**
     * 提升机-小车已驶离
     */
    public List<Motion> liftShuttleLeave(MotionDto origin, MotionDto target) {
        List<Motion> motionList = new ArrayList<>();
        motionList.add(Motion.build(motion -> {
            motion.setDeviceCtg(DeviceCtgType.LIFT.val());
            motion.setDevice(String.valueOf(target.getLiftNo()));
            motion.setMotionCtg(MotionCtgType.LIFT_SHUTTLE_LEAVE.val());
        }));
        return motionList;
    }
    // shuttle -----------------------------------------------------------------------------
    /**
     * 小车坐标更新
     */
    public List<Motion> shuttleUpdateLocation(MotionDto origin, MotionDto target) {
        List<Motion> motionList = new ArrayList<>();
        motionList.add(Motion.build(motion -> {
            motion.setDeviceCtg(DeviceCtgType.SHUTTLE.val());
            motion.setDevice(String.valueOf(target.getShuttleNo()));
            motion.setMotionCtg(MotionCtgType.SHUTTLE_UPDATE_LOCATION.val());
            motion.setTarget(target.getLocNo());
        }));
        return motionList;
    }
    /**
     * 穿梭车空载移动
@@ -185,8 +312,35 @@
                    motion.setTemp(String.valueOf(origin.getLiftNo()));//保存提升机号
                    motion.setDockNo(String.valueOf(target.getStaNo()));
                    break;
                case SHUTTLE_TRANSPORT_TO_CONVEYOR://穿梭车载货进输送线
                    motion.setDockNo(String.valueOf(target.getStaNo()));
                    break;
                case SHUTTLE_MOVE_STANDBY://穿梭车移动到待机位
                    motion.setTarget(null);//等待自动搜索
                    motion.setTemp(target.getLocNo());//全部待机位
                    break;
                default:
                    break;
            }
            if (target.getSync() != null) {
                motion.setSync(target.getSync());
            }
            if (target.getReleaseShuttle() != null) {
                motion.setReleaseShuttle(target.getReleaseShuttle());
            }
            if (target.getReleaseLift() != null) {
                motion.setReleaseLift(target.getReleaseLift());
            }
            if (motion.getOrigin() != null && motion.getTarget() != null) {
                List<NavigateNode> nodeList = navigateUtils.calc(motion.getOrigin(), motion.getTarget(), NavigationMapType.NONE_LOCK.id, Utils.getShuttlePoints(Integer.parseInt(target.getShuttleDevice().getDeviceNo()), Utils.getLev(motion.getTarget())));
                if (nodeList == null) {
                    throw new CoolException(motion.getOrigin() + " dash " + motion.getTarget() + " can't find navigate path!");
                }
                motion.setMovePath(JSON.toJSONString(nodeList));
            }
        }));
@@ -230,14 +384,34 @@
        return motionList;
    }
    public List<Motion> shuttleCharge(MotionDto origin, MotionDto target) {
    /**
     * 穿梭车动作
     */
    public List<Motion> shuttleAction(MotionDto origin, MotionDto target, MotionCtgType motionCtgType) {
        List<Motion> motionList = new ArrayList<>();
        motionList.add(Motion.build(motion -> {
            motion.setDeviceCtg(DeviceCtgType.SHUTTLE.val());
            motion.setDevice(String.valueOf(target.getShuttleNo()));
            motion.setMotionCtg(MotionCtgType.SHUTTLE_CHARGE_ON.val());
            motion.setMotionCtg(motionCtgType.val());
            switch (motionCtgType) {
                case SHUTTLE_PALLET_LIFT://托盘顶升
                    break;
                case SHUTTLE_PALLET_DOWN://托盘下降
                    break;
                case SHUTTLE_CHARGE_ON://充电开
                    break;
                case SHUTTLE_CHARGE_OFF://充电关
                    break;
                default:
                    break;
            }
        }));
@@ -307,4 +481,40 @@
        return motionList;
    }
    // Map -----------------------------------------------------------------------------
    /**
     * 地图路径锁定
     */
    public List<Motion> mapLockPath(MotionDto origin, MotionDto target) {
        List<Motion> motionList = new ArrayList<>();
        motionList.add(Motion.build(motion -> {
            motion.setDeviceCtg(DeviceCtgType.MAP.val());
            motion.setDevice(String.valueOf(target.getShuttleNo()));
            motion.setMotionCtg(MotionCtgType.MAP_LOCK_PATH.val());
            motion.setTarget(target.getLocNo());
        }));
        return motionList;
    }
    /**
     * 地图路径解锁
     */
    public List<Motion> mapUnlockPath(MotionDto origin, MotionDto target) {
        List<Motion> motionList = new ArrayList<>();
        motionList.add(Motion.build(motion -> {
            motion.setDeviceCtg(DeviceCtgType.MAP.val());
            motion.setDevice(String.valueOf(target.getShuttleNo()));
            motion.setMotionCtg(MotionCtgType.MAP_UNLOCK_PATH.val());
            motion.setTarget(target.getLocNo());
        }));
        return motionList;
    }
}