#
Junjie
2024-10-16 0f5a5a759221bde50ace126eae797326837f5f72
zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/utils/ShuttleDispatcher.java
@@ -9,17 +9,16 @@
import com.zy.asrs.wcs.core.entity.*;
import com.zy.asrs.wcs.core.kernel.AnalyzeService;
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.NavigationMapType;
import com.zy.asrs.wcs.core.model.enums.TaskCtgType;
import com.zy.asrs.wcs.core.model.enums.TaskStsType;
import com.zy.asrs.wcs.core.model.enums.*;
import com.zy.asrs.wcs.core.service.*;
import com.zy.asrs.wcs.rcs.News;
import com.zy.asrs.wcs.rcs.cache.SlaveConnection;
import com.zy.asrs.wcs.rcs.entity.Device;
import com.zy.asrs.wcs.rcs.model.enums.ShuttleProtocolStatusType;
import com.zy.asrs.wcs.rcs.model.enums.SlaveType;
import com.zy.asrs.wcs.rcs.model.protocol.ShuttleProtocol;
import com.zy.asrs.wcs.rcs.service.DeviceService;
import com.zy.asrs.wcs.rcs.thread.LiftThread;
import com.zy.asrs.wcs.rcs.thread.ShuttleThread;
import com.zy.asrs.wcs.system.entity.Dict;
import com.zy.asrs.wcs.system.service.DictService;
@@ -126,10 +125,12 @@
                    continue;
                }
                Device recentTransferLift = Utils.getRecentTransferLift(locNo, Integer.parseInt(device.getDeviceNo()));
                if (recentTransferLift == null) {
                //获取距离目标位置最近的空闲可换层提升机
                LiftThread liftThread = liftDispatcher.searchIdleLift(locNo, task.getHostId(), true);
                if (liftThread == null) {
                    continue;
                }
                Device recentTransferLift = liftThread.getDevice();
                //获取小车楼层提升机待机位
                ShuttleStandby shuttleStandby = shuttleStandbyService.getOne(new LambdaQueryWrapper<ShuttleStandby>()
@@ -158,7 +159,7 @@
            }
            // 挂载任务权重
            List<Task> tasks = taskService.selectWorkingByShuttle(Integer.valueOf(device.getDeviceNo()));
            List<Task> tasks = taskService.selectWorkingByShuttle(Integer.valueOf(device.getDeviceNo()), null);
            if (!Cools.isEmpty(tasks)) {
                currDistance += tasks.size() * WEIGHT;
            }
@@ -283,9 +284,9 @@
    }
    /**
     * 搜索避让库位,通过小车号和目标库位
     * 搜索可用库位,通过小车号和目标库位
     */
    public String searchStandByLocNo(Integer shuttleNo, Long hostId, String locNo) {
    public String searchAvailableLocNo(Integer shuttleNo, Long hostId, String currentLocNo, List<String> locNos) {
        BasShuttle basShuttle = basShuttleService.getOne(new LambdaQueryWrapper<BasShuttle>()
                .eq(BasShuttle::getShuttleNo, shuttleNo)
                .eq(BasShuttle::getHostId, hostId));
@@ -293,29 +294,18 @@
            throw new CoolException("小车基础数据不存在");
        }
        String idleLoc = basShuttle.getIdleLoc();
        if (Cools.isEmpty(idleLoc)) {
            throw new CoolException("小车避让数据不存在");
        if (locNos.isEmpty()) {
            throw new CoolException("当前层无避让位置");
        }
        int lev = Utils.getLev(locNo);//当前楼层
        JSONArray standbyLoc = JSON.parseArray(idleLoc);
        if (lev > standbyLoc.size()) {
            throw new CoolException("避让数据异常");
        }
        Object object = standbyLoc.get(lev - 1);
        List<String> locs = JSON.parseArray(object.toString(), String.class);
        if (locs.isEmpty()) {
            throw new CoolException("避让数据为空");
        }
        int lev = Utils.getLev(currentLocNo);
        Integer finalDistance = ShuttleDispatcher.INF;
        String recentLoc = null;
        for (String loc : locs) {
        for (String loc : locNos) {
            //当前穿梭车到避让位计算
            List<NavigateNode> currentShuttlePath = NavigateUtils.calc(
                    locNo
                    currentLocNo
                    , loc
                    , NavigationMapType.NORMAL.id
                    , Utils.getShuttlePoints(shuttleNo, lev)
@@ -366,6 +356,18 @@
                continue;
            }
            if (shuttleProtocol.getProtocolStatusType().equals(ShuttleProtocolStatusType.OFFLINE)) {
                continue;
            }
            if(!shuttleThread.isDeviceIdle()) {
                continue;
            }
            if(shuttleProtocol.getCurrentLocNo() == null) {
                continue;
            }
            if (Utils.getLev(shuttleProtocol.getCurrentLocNo()) == lev) {
                if (shuttleProtocol.getHasCharge()) {
                    continue;//充电中
@@ -395,8 +397,68 @@
        }
        //搜索是否存在前往目标楼层的小车工作档
        for (Task task : taskService.list(new LambdaQueryWrapper<Task>()
                .in(Task::getTaskSts, TaskStsType.NEW_INBOUND.sts, TaskStsType.ANALYZE_INBOUND.sts, TaskStsType.EXECUTE_INBOUND.sts, TaskStsType.COMPLETE_INBOUND.sts
                        , TaskStsType.NEW_OUTBOUND.sts, TaskStsType.ANALYZE_OUTBOUND.sts, TaskStsType.EXECUTE_OUTBOUND.sts, TaskStsType.COMPLETE_OUTBOUND.sts))) {
            List<Motion> motions = motionService.list(new LambdaQueryWrapper<Motion>()
                    .eq(Motion::getTaskNo, task.getTaskNo())
                    .in(Motion::getMotionCtg, MotionCtgType.SHUTTLE_MOVE
                            , MotionCtgType.SHUTTLE_MOVE_LIFT_PALLET
                            , MotionCtgType.SHUTTLE_MOVE_DOWN_PALLET
                            , MotionCtgType.SHUTTLE_MOVE_FROM_LIFT
                            , MotionCtgType.SHUTTLE_MOVE_TO_LIFT
                            , MotionCtgType.SHUTTLE_MOVE_FROM_CONVEYOR
                            , MotionCtgType.SHUTTLE_MOVE_TO_CONVEYOR
                            , MotionCtgType.SHUTTLE_MOVE_FROM_LIFT_TO_CONVEYOR
                    ));
            boolean isUpdateLev = false;
            for (Motion motion : motions) {
                if (motion.getOrigin() == null || motion.getTarget() == null) {
                    continue;
                }
                int sourceLev = Utils.getLev(motion.getOrigin());//动作源楼层
                int targetLev = Utils.getLev(motion.getTarget());//动作目标楼层
                if (sourceLev != targetLev) {
                    isUpdateLev = true;
                    break;
                }
            }
            if(isUpdateLev) {
                levCount++;//工作档属于跨层任务,小车归属于目标楼层
                continue;
            }
        }
        return levCount < Integer.parseInt(dict.getValue());
    }
    //分析出库路径待机库位
    public String analyzeOutPathWaitLoc(String startLoc, String targetLoc, Device shuttleDevice) {
        //计算路径并分解成两段动作
        List<NavigateNode> nodeList = NavigateUtils.calc(startLoc, targetLoc, NavigationMapType.DFX.id, Utils.getShuttlePoints(Integer.parseInt(shuttleDevice.getDeviceNo()), Utils.getLev(startLoc)));
        if (nodeList == null) {
            News.error("{} dash {} can't find navigate path!", startLoc, targetLoc);
            return null;
        }
        //获取分段路径
        ArrayList<ArrayList<NavigateNode>> data = NavigateUtils.getSectionPath(nodeList);
        if (data.size() <= 1) {
            return null;//两点之间只有一段路径
        }
        //取出倒数第二段路径
        ArrayList<NavigateNode> navigateNodes = data.get(data.size() - 2);
        NavigateNode startNode = navigateNodes.get(0);
        String lastPathStartLoc = Utils.getLocNo(startNode.getX(), startNode.getY(), startNode.getZ());
        return lastPathStartLoc;
    }
}