#
Junjie
2023-09-20 fb8419ef141e16b8ec8b1d9802fa0d5a46768794
src/main/java/com/zy/common/utils/ShuttleDispatchUtils.java
@@ -1,10 +1,12 @@
package com.zy.common.utils;
import com.core.exception.CoolException;
import com.zy.asrs.entity.BasDevp;
import com.zy.asrs.entity.WrkCharge;
import com.zy.asrs.entity.WrkMast;
import com.zy.asrs.mapper.WrkChargeMapper;
import com.zy.asrs.mapper.WrkMastMapper;
import com.zy.asrs.service.BasDevpService;
import com.zy.asrs.service.WrkMastService;
import com.zy.asrs.utils.Utils;
import com.zy.common.model.NavigateNode;
@@ -13,9 +15,12 @@
import com.zy.core.News;
import com.zy.core.cache.SlaveConnection;
import com.zy.core.enums.SlaveType;
import com.zy.core.model.LiftSlave;
import com.zy.core.model.ShuttleSlave;
import com.zy.core.model.protocol.LiftProtocol;
import com.zy.core.model.protocol.NyShuttleProtocol;
import com.zy.core.properties.SlaveProperties;
import com.zy.core.thread.LiftThread;
import com.zy.core.thread.NyShuttleThread;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -41,6 +46,8 @@
    private WrkChargeMapper wrkChargeMapper;
    @Autowired
    private CommonService commonService;
    @Autowired
    private BasDevpService basDevpService;
    /**
     * 调度车辆-调度指定穿梭车
@@ -146,7 +153,7 @@
     * 小车迁移任务生成
     */
    @Transactional
    private boolean shuttleMoveGenerate(Integer wrkNo, String locNo, Integer shuttleNo) {
    public boolean shuttleMoveGenerate(Integer wrkNo, String locNo, Integer shuttleNo) {
        Date now = new Date();
        //获取四向穿梭车线程
        NyShuttleThread shuttleThread = (NyShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleNo);
@@ -181,6 +188,17 @@
            return false;
        }
        Integer staNo = null;
        if (Utils.getLev(locNo) != shuttleProtocol.getPoint().getZ()) {
            //目标库位和小车库位处于不同一楼层,需要通过提升机调度
            //获取穿梭车最近且空闲的提升机输送站点
            BasDevp liftSta = this.getRecentLiftSta(shuttleNo);
            if (liftSta == null) {
                return false;//没有可用且空闲的输送站点
            }
            staNo = liftSta.getDevNo();
        }
        // 获取工作号
        int workNo = commonService.getWorkNo(0);
        // 保存工作档
@@ -193,6 +211,7 @@
        wrkMast.setShuttleNo(shuttleNo);//穿梭车号
        wrkMast.setSourceLocNo(shuttleProtocol.getCurrentLocNo()); // 源库位 => 小车当前库位号
        wrkMast.setLocNo(locNo); // 目标库位
        wrkMast.setStaNo(staNo);//目标站
        wrkMast.setPicking("N"); // 拣料
        wrkMast.setExitMk("N"); // 退出
        wrkMast.setLinkMis("N");
@@ -214,4 +233,41 @@
        return true;
    }
    /**
     * 获取穿梭车最近且空闲的提升机输送站点
     */
    public BasDevp getRecentLiftSta(Integer shuttleNo) {
        //获取四向穿梭车线程
        NyShuttleThread shuttleThread = (NyShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleNo);
        if (shuttleThread == null) {
            return null;
        }
        NyShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol();
        if (shuttleProtocol == null) {
            return null;
        }
        for (LiftSlave slave : slaveProperties.getLift()) {
            LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, slave.getId());
            if (liftThread == null) {
                continue;
            }
            LiftProtocol liftProtocol = liftThread.getLiftProtocol();
            if (liftProtocol == null) {
                continue;
            }
            if (!liftProtocol.isIdle()) {
                continue;
            }
            BasDevp basDevp = basDevpService.selectByLevAndLiftNo(Utils.getLev(shuttleProtocol.getCurrentLocNo()), slave.getId());
            if (basDevp == null) {
                continue;
            }
            return basDevp;
        }
        return null;
    }
}