自动化立体仓库 - WCS系统
#
Junjie
2025-04-10 1d624dfdb040825ffecba6c792c480be662b2dbc
src/main/java/com/zy/core/dispatcher/ShuttleDispatchUtils.java
@@ -15,6 +15,7 @@
import com.zy.common.model.enums.NavigationMapType;
import com.zy.common.service.CommonService;
import com.zy.common.utils.ForkLiftUtils;
import com.zy.common.utils.LiftUtils;
import com.zy.common.utils.NavigateUtils;
import com.zy.core.News;
import com.zy.core.cache.SlaveConnection;
@@ -22,10 +23,12 @@
import com.zy.core.enums.WrkIoType;
import com.zy.core.enums.WrkStsType;
import com.zy.core.model.ForkLiftSlave;
import com.zy.core.model.LiftSlave;
import com.zy.core.model.ShuttleSlave;
import com.zy.core.model.protocol.*;
import com.zy.core.properties.SlaveProperties;
import com.zy.core.thread.ForkLiftThread;
import com.zy.core.thread.LiftThread;
import com.zy.core.thread.ShuttleThread;
import com.zy.system.entity.Config;
import com.zy.system.service.ConfigService;
@@ -53,6 +56,13 @@
    private ConfigService configService;
    @Autowired
    private BasShuttleService basShuttleService;
    /**
     * 调度车辆-调度指定穿梭车
     */
    public boolean dispatchShuttle(Integer wrkNo, String sourceLocNo, String locNo, Integer shuttleNo, String flag) {
        return shuttleMoveGenerate(wrkNo, sourceLocNo, locNo, shuttleNo, flag, false);
    }
    /**
     * 调度车辆-调度指定穿梭车
@@ -203,6 +213,14 @@
     */
    @Transactional
    public boolean shuttleMoveGenerate(Integer wrkNo, String locNo, Integer shuttleNo) {
        return shuttleMoveGenerate(wrkNo, null, locNo, shuttleNo, null, false);
    }
    /**
     * 小车迁移任务生成
     */
    @Transactional
    public boolean shuttleMoveGenerate(Integer wrkNo, String sourceLocNo, String locNo, Integer shuttleNo, String flag, boolean disableCheck) {
        Date now = new Date();
        //获取四向穿梭车线程
        ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleNo);
@@ -224,7 +242,7 @@
        //判断穿梭车是否存在未完成的小车移库任务
        WrkMast hasMoveWorking = wrkMastService.selectShuttleHasMoveWorking(shuttleNo);
        if (hasMoveWorking != null) {//小车存在移库任务,等待执行完成后再生成新的任务
        if (hasMoveWorking != null && !disableCheck) {//小车存在移库任务,等待执行完成后再生成新的任务
            News.info("{}号小车,存在移动任务,等待执行完成后再生成新的任务", shuttleNo);
            return false;
        }
@@ -234,7 +252,7 @@
        //判断是否有其他任务正在使用穿梭车
        WrkMast wrkMast2 = wrkMastService.selectShuttleWorking(shuttleNo);
        if (wrkMast2 != null) {//小车存在其他工作档任务,等待执行完成后再生成新的任务
        if (wrkMast2 != null && !disableCheck) {//小车存在其他工作档任务,等待执行完成后再生成新的任务
            if (mainWrkMast == null) {
                News.info("{}号小车,存在其他工作档任务,等待执行完成再生成新的任务", shuttleNo);
                return false;
@@ -246,41 +264,24 @@
            }
        }
        Integer sourceStaNo = null;//小车换层源站点
        Integer staNo = null;//小车换层目标站点
        if (Utils.getLev(locNo) != Utils.getLev(shuttleProtocol.getCurrentLocNo())) {
            //目标库位和小车库位处于不同一楼层,需要通过提升机调度
            //获取穿梭车最近且空闲的提升机输送站点
            ForkLiftStaProtocol liftSta = this.getRecentLiftSta(shuttleNo, Utils.getLev(locNo));
            if (liftSta == null) {
                News.info("{}号小车,{}目标库位,没有可用空闲输送站点", shuttleNo, locNo);
                return false;//没有可用且空闲的输送站点
            }
            sourceStaNo = liftSta.getStaNo();//源站点
            ForkLiftStaProtocol targetLiftSta = ForkLiftUtils.getLiftStaByLev(liftSta.getLiftNo(), Utils.getLev(locNo));
            if (targetLiftSta == null) {
                News.info("{}号小车,{}目标库位,没有目标站点", shuttleNo, locNo);
                return false;//没有找到目标站点
            }
            //目标站点
            staNo = targetLiftSta.getStaNo();//目标站
        String currentLocNo = shuttleProtocol.getCurrentLocNo();
        if (sourceLocNo != null) {
            currentLocNo = sourceLocNo;
        }
        // 获取工作号
        int workNo = commonService.getWorkNo(WrkIoType.SHUTTLE_MOVE.id);
        // 保存工作档
        WrkMast wrkMast = new WrkMast();
        wrkMast.setMk(flag);
        wrkMast.setWrkNo(workNo);
        wrkMast.setIoTime(now);
        wrkMast.setWrkSts(WrkStsType.NEW_MOVE.sts); // 工作状态:301.生成迁移任务
        wrkMast.setIoType(WrkIoType.SHUTTLE_MOVE.id); // 入出库状态: 200.小车迁移
        wrkMast.setIoPri(800D);
        wrkMast.setShuttleNo(shuttleNo);//穿梭车号
        wrkMast.setSourceLocNo(shuttleProtocol.getCurrentLocNo()); // 源库位 => 小车当前库位号
        wrkMast.setSourceLocNo(currentLocNo); // 源库位
        wrkMast.setLocNo(locNo); // 目标库位
        wrkMast.setSourceStaNo(sourceStaNo);//源站
        wrkMast.setStaNo(staNo);//目标站
        wrkMast.setAppeTime(now);
        wrkMast.setModiTime(now);
        boolean res = wrkMastService.insert(wrkMast);
@@ -395,94 +396,7 @@
        return levCount < Integer.parseInt(config.getValue());
    }
    /**
     * 获取穿梭车最近且空闲的提升机输送站点
     */
    public ForkLiftStaProtocol getRecentLiftSta(Integer shuttleNo, Integer targetLev) {
        //获取四向穿梭车线程
        ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleNo);
        if (shuttleThread == null) {
            return null;
        }
        ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
        if (shuttleProtocol == null) {
            return null;
        }
        //获取小车同一楼层的站点
        ArrayList<ForkLiftStaProtocol> list = new ArrayList<>();
        int lev = Utils.getLev(shuttleProtocol.getCurrentLocNo());//小车楼层
        for (ForkLiftSlave slave : slaveProperties.getForkLift()) {
            ForkLiftThread forkLiftThread = (ForkLiftThread) SlaveConnection.get(SlaveType.ForkLift, slave.getId());
            if (forkLiftThread == null) {
                continue;
            }
            ForkLiftProtocol forkLiftProtocol = forkLiftThread.getStatus();
            if (forkLiftProtocol == null) {
                continue;
            }
            if (!forkLiftThread.isIdle()) {
                continue;
            }
            ForkLiftStaProtocol forkLiftStaProtocol = ForkLiftUtils.getLiftStaByLev(slave.getId(), lev);
            if (forkLiftStaProtocol == null) {
                continue;
            }
            //判断当前层是否无托盘
            if (forkLiftStaProtocol.getHasTray()) {
                continue;
            }
            if (forkLiftStaProtocol.getHasCar()) {
                continue;
            }
            //判断目标楼层站点是否无托盘
            ForkLiftStaProtocol targetLiftStaProtocol = ForkLiftUtils.getLiftStaByLev(slave.getId(), targetLev);
            if (targetLiftStaProtocol == null) {
                continue;
            }
            if (targetLiftStaProtocol.getHasTray()) {
                continue;//有托盘跳过
            }
            if (targetLiftStaProtocol.getHasCar()) {
                continue;
            }
            list.add(forkLiftStaProtocol);
        }
        if (list.isEmpty()) {
            return null;
        }
        String currentLocNo = shuttleProtocol.getCurrentLocNo();//小车位置
        Integer recentAllDistance = 9999999;
        ForkLiftStaProtocol recentSta = null;//最近站点
        //搜索距离小车最近的站点
        for (ForkLiftStaProtocol forkLiftStaProtocol : list) {
            Integer staNo = forkLiftStaProtocol.getStaNo();//站点号
            String locNo = forkLiftStaProtocol.getLocNo();//站点库位号
            //当前穿梭车线程到目标地点距离
            List<NavigateNode> currentShuttlePath = navigateUtils.calc(currentLocNo, locNo, NavigationMapType.NORMAL.id, Utils.getShuttlePoints(shuttleNo, Utils.getLev(currentLocNo)), null);//使用正常通道地图
            if (currentShuttlePath == null) {
                continue;
            }
            Integer currentAllDistance = navigateUtils.getOriginPathAllDistance(currentShuttlePath);//计算当前路径行走总距离
            if (currentAllDistance < recentAllDistance) {
                //如果当前楼层的车路径更小,则更新最近站点
                recentSta = forkLiftStaProtocol;
                recentAllDistance = currentAllDistance;
            }
        }
        return recentSta;
    }
    /**
     * 检测是否穿梭车是否有充电任务