#
Administrator
2026-04-25 a55f2835748bd494ff46ca3e1a2d7d672153cb2f
src/main/java/com/zy/core/utils/StationOperateProcessUtils.java
@@ -26,6 +26,8 @@
import com.zy.core.model.Task;
import com.zy.core.model.command.StationCommand;
import com.zy.core.model.protocol.StationProtocol;
import com.zy.core.task.MainProcessLane;
import com.zy.core.task.MainProcessTaskSubmitter;
import com.zy.core.thread.StationThread;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@@ -56,6 +58,203 @@
    private BasStationService basStationService;
    @Autowired
    private StationCycleCapacityService stationCycleCapacityService;
    @Autowired
    private MainProcessTaskSubmitter mainProcessTaskSubmitter;
    public void submitStationEnableInTasks(long minIntervalMs) {
        submitStationEnableInTasks(MainProcessLane.STATION_ENABLE_IN, minIntervalMs);
    }
    public void submitStationEnableInTasks(MainProcessLane lane, long minIntervalMs) {
        List<BasDevp> basDevps = basDevpService.selectList(new EntityWrapper<BasDevp>());
        for (final BasDevp basDevp : basDevps) {
            StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basDevp.getDevpNo());
            if (stationThread == null) {
                continue;
            }
            Map<Integer, StationProtocol> stationMap = stationThread.getStatusMap();
            if (stationMap == null || stationMap.isEmpty()) {
                continue;
            }
            List<StationObjModel> list = basDevp.getInStationList$();
            for (final StationObjModel stationObjModel : list) {
                Integer stationId = stationObjModel == null ? null : stationObjModel.getStationId();
                if (stationId == null || !stationMap.containsKey(stationId)) {
                    continue;
                }
                mainProcessTaskSubmitter.submitKeyedSerialTask(
                        lane,
                        stationId,
                        "stationEnableInExecute",
                        minIntervalMs,
                        new Runnable() {
                            @Override
                            public void run() {
                                stationEnableInExecute(basDevp, stationObjModel);
                            }
                        }
                );
            }
        }
    }
    public void submitStationInTasks(long minIntervalMs) {
        submitStationInTasks(MainProcessLane.STATION_IN, minIntervalMs);
    }
    public void submitStationInTasks(MainProcessLane lane, long minIntervalMs) {
        // 入库下发依赖单轮共享的承载预占状态,必须整体串行,避免多个站点并发时同时通过容量检查。
        mainProcessTaskSubmitter.submitSerialTask(
                MainProcessLane.STATION,
                "stationInExecute",
                minIntervalMs,
                new Runnable() {
                    @Override
                    public void run() {
                        stationInExecute();
                    }
                }
        );
    }
    public void submitCrnStationOutTasks(long minIntervalMs) {
        submitCrnStationOutTasks(MainProcessLane.STATION_OUT, minIntervalMs);
    }
    public void submitCrnStationOutTasks(MainProcessLane lane, long minIntervalMs) {
        // 出库站点下发同样会预占输送线/环线容量,与 stationInExecute 共用 STATION lane 串行。
        mainProcessTaskSubmitter.submitSerialTask(
                MainProcessLane.STATION,
                "crnStationOutExecute",
                minIntervalMs,
                new Runnable() {
                    @Override
                    public void run() {
                        crnStationOutExecute();
                    }
                }
        );
    }
    public void submitDualCrnStationOutTasks(long minIntervalMs) {
        submitDualCrnStationOutTasks(MainProcessLane.DUAL_STATION_OUT, minIntervalMs);
    }
    public void submitDualCrnStationOutTasks(MainProcessLane lane, long minIntervalMs) {
        List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>()
                .eq("wrk_sts", WrkStsType.OUTBOUND_RUN_COMPLETE.sts)
                .isNotNull("dual_crn_no")
        );
        for (final WrkMast wrkMast : wrkMasts) {
            Integer laneKey = wrkMast == null ? null : wrkMast.getSourceStaNo();
            if (laneKey == null) {
                laneKey = wrkMast == null ? null : wrkMast.getWrkNo();
            }
            mainProcessTaskSubmitter.submitKeyedSerialTask(
                    lane,
                    laneKey,
                    "dualCrnStationOutExecute",
                    minIntervalMs,
                    new Runnable() {
                        @Override
                        public void run() {
                            dualCrnStationOutExecute(wrkMast);
                        }
                    }
            );
        }
    }
    public void submitStationOutExecuteFinishTasks(long minIntervalMs) {
        submitStationOutExecuteFinishTasks(MainProcessLane.STATION_OUT_FINISH, minIntervalMs);
    }
    public void submitStationOutExecuteFinishTasks(MainProcessLane lane, long minIntervalMs) {
        List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>().eq("wrk_sts", WrkStsType.STATION_RUN.sts));
        for (final WrkMast wrkMast : wrkMasts) {
            Integer laneKey = wrkMast == null ? null : wrkMast.getStaNo();
            if (laneKey == null) {
                laneKey = wrkMast == null ? null : wrkMast.getWrkNo();
            }
            mainProcessTaskSubmitter.submitKeyedSerialTask(
                    lane,
                    laneKey,
                    "stationOutExecuteFinish",
                    minIntervalMs,
                    new Runnable() {
                        @Override
                        public void run() {
                            stationOutExecuteFinish(wrkMast);
                        }
                    }
            );
        }
    }
    public void submitCheckTaskToCompleteTasks(long minIntervalMs) {
        submitCheckTaskToCompleteTasks(MainProcessLane.STATION_COMPLETE, minIntervalMs);
    }
    public void submitCheckTaskToCompleteTasks(MainProcessLane lane, long minIntervalMs) {
        List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>().eq("wrk_sts", WrkStsType.STATION_RUN_COMPLETE.sts));
        for (final WrkMast wrkMast : wrkMasts) {
            Integer laneKey = wrkMast == null ? null : wrkMast.getStaNo();
            if (laneKey == null) {
                laneKey = wrkMast == null ? null : wrkMast.getWrkNo();
            }
            mainProcessTaskSubmitter.submitKeyedSerialTask(
                    lane,
                    laneKey,
                    "checkTaskToComplete",
                    minIntervalMs,
                    new Runnable() {
                        @Override
                        public void run() {
                            checkTaskToComplete(wrkMast);
                        }
                    }
            );
        }
    }
    public void submitCheckStationRunBlockTasks(long minIntervalMs) {
        submitCheckStationRunBlockTasks(MainProcessLane.STATION_RUN_BLOCK, minIntervalMs);
    }
    public void submitCheckStationRunBlockTasks(MainProcessLane lane, long minIntervalMs) {
        List<BasDevp> basDevps = basDevpService.selectList(new EntityWrapper<BasDevp>());
        for (final BasDevp basDevp : basDevps) {
            StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basDevp.getDevpNo());
            if (stationThread == null) {
                continue;
            }
            List<StationProtocol> statusList = stationThread.getStatus();
            for (StationProtocol stationProtocol : statusList) {
                final Integer stationId = stationProtocol == null ? null : stationProtocol.getStationId();
                if (stationId == null) {
                    continue;
                }
                if (!stationProtocol.isAutoing()
                        || !stationProtocol.isLoading()
                        || stationProtocol.getTaskNo() <= 0
                        || !stationProtocol.isRunBlock()) {
                    continue;
                }
                mainProcessTaskSubmitter.submitKeyedSerialTask(
                        lane,
                        stationId,
                        "checkStationRunBlock",
                        minIntervalMs,
                        new Runnable() {
                            @Override
                            public void run() {
                                checkStationRunBlock(basDevp, stationId);
                            }
                        }
                );
            }
        }
    }
    //执行输送站点入库任务
    public synchronized void stationInExecute() {
@@ -75,19 +274,109 @@
                List<StationObjModel> list = basDevp.getBarcodeStationList$();
                for (StationObjModel entity : list) {
                    Integer stationId = entity.getStationId();
                    if (stationInExecute(basDevp, entity, limitConfig, currentStationTaskCountRef, loadGuardState)) {
                        return;
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public void stationEnableInExecute(BasDevp basDevp, StationObjModel stationObjModel) {
        try {
            if (basDevp == null || stationObjModel == null || stationObjModel.getStationId() == null) {
                return;
            }
            StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basDevp.getDevpNo());
            if (stationThread == null) {
                return;
            }
            Map<Integer, StationProtocol> stationMap = stationThread.getStatusMap();
            if (stationMap == null) {
                return;
            }
            Integer stationId = stationObjModel.getStationId();
                    if (!stationMap.containsKey(stationId)) {
                        continue;
                return;
                    }
                    StationProtocol stationProtocol = stationMap.get(stationId);
                    if (stationProtocol == null) {
                        continue;
                return;
            }
            Object lock = redisUtil.get(RedisKeyType.GENERATE_ENABLE_IN_STATION_DATA_LIMIT.key + stationId);
            if (lock != null) {
                return;
            }
            if (stationProtocol.isAutoing()
                    && stationProtocol.isLoading()
                    && stationProtocol.getTaskNo() == 0
                    && stationProtocol.isEnableIn()
            ) {
                StationObjModel barcodeStation = stationObjModel.getBarcodeStation();
                if (barcodeStation == null || barcodeStation.getStationId() == null) {
                    return;
                }
                StationCommand command = stationThread.getCommand(StationCommandType.MOVE, commonService.getWorkNo(WrkIoType.ENABLE_IN.id), stationId, barcodeStation.getStationId(), 0);
                if (command == null) {
                    News.info("{}站点启动入库失败,获取输送线命令失败", stationId);
                    return;
                }
                MessageQueue.offer(SlaveType.Devp, basDevp.getDevpNo(), new Task(2, command));
                redisUtil.set(RedisKeyType.GENERATE_ENABLE_IN_STATION_DATA_LIMIT.key + stationId, "lock", 15);
                News.info("{}站点启动入库成功,数据包:{}", stationId, JSON.toJSONString(command));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public void stationInExecute(BasDevp basDevp, StationObjModel stationObjModel) {
        try {
            DispatchLimitConfig limitConfig = getDispatchLimitConfig();
            int[] currentStationTaskCountRef = new int[]{countCurrentStationTask()};
            LoadGuardState loadGuardState = buildLoadGuardState(limitConfig);
            stationInExecute(basDevp, stationObjModel, limitConfig, currentStationTaskCountRef, loadGuardState);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    private boolean stationInExecute(BasDevp basDevp,
                                     StationObjModel stationObjModel,
                                     DispatchLimitConfig limitConfig,
                                     int[] currentStationTaskCountRef,
                                     LoadGuardState loadGuardState) {
        if (basDevp == null || stationObjModel == null || stationObjModel.getStationId() == null) {
            return false;
        }
        StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basDevp.getDevpNo());
        if (stationThread == null) {
            return false;
        }
        Map<Integer, StationProtocol> stationMap = stationThread.getStatusMap();
        Integer stationId = stationObjModel.getStationId();
        if (stationMap == null || !stationMap.containsKey(stationId)) {
            return false;
        }
        StationProtocol stationProtocol = stationMap.get(stationId);
        if (stationProtocol == null) {
            return false;
                    }
                    Object lock = redisUtil.get(RedisKeyType.STATION_IN_EXECUTE_LIMIT.key + stationId);
                    if (lock != null) {
                        continue;
            return false;
                    }
                    //满足自动、有物、有工作号
@@ -98,36 +387,36 @@
                        //检测任务是否生成
                        WrkMast wrkMast = wrkMastService.selectOne(new EntityWrapper<WrkMast>().eq("barcode", stationProtocol.getBarcode()));
                        if (wrkMast == null) {
                            continue;
                return false;
                        }
                        if (wrkMast.getWrkSts() == WrkStsType.INBOUND_DEVICE_RUN.sts) {
                            continue;
                return false;
                        }
                        String locNo = wrkMast.getLocNo();
                        FindCrnNoResult findCrnNoResult = commonService.findCrnNoByLocNo(locNo);
                        if (findCrnNoResult == null) {
                            News.taskInfo(wrkMast.getWrkNo(), "{}工作,未匹配到堆垛机", wrkMast.getWrkNo());
                            continue;
                return false;
                        }
                        Integer targetStationId = commonService.findInStationId(findCrnNoResult, stationId);
                        if (targetStationId == null) {
                            News.taskInfo(wrkMast.getWrkNo(), "{}站点,搜索入库站点失败", stationId);
                            continue;
                return false;
                        }
                        LoopHitResult loopHitResult = findPathLoopHit(limitConfig, stationProtocol.getStationId(), targetStationId, loadGuardState);
                        if (isDispatchBlocked(limitConfig, currentStationTaskCountRef[0], loadGuardState, loopHitResult.isThroughLoop())) {
                            return;
                return true;
                        }
                        StationCommand command = stationThread.getCommand(StationCommandType.MOVE, wrkMast.getWrkNo(), stationId, targetStationId, 0);
                        if (command == null) {
                            News.taskInfo(wrkMast.getWrkNo(), "{}工作,获取输送线命令失败", wrkMast.getWrkNo());
                            continue;
                return false;
                        }
                        wrkMast.setWrkSts(WrkStsType.INBOUND_DEVICE_RUN.sts);
@@ -143,11 +432,7 @@
                            saveLoopLoadReserve(wrkMast.getWrkNo(), loopHitResult);
                        }
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }
    //执行堆垛机输送站点出库任务
@@ -164,27 +449,60 @@
            List<Integer> outOrderList = getAllOutOrderList();
            for (WrkMast wrkMast : wrkMasts) {
                if (crnStationOutExecute(wrkMast, limitConfig, currentStationTaskCountRef, loadGuardState, outOrderList)) {
                    return;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public void crnStationOutExecute(WrkMast wrkMast) {
        try {
            DispatchLimitConfig limitConfig = getDispatchLimitConfig();
            int[] currentStationTaskCountRef = new int[]{countCurrentStationTask()};
            LoadGuardState loadGuardState = buildLoadGuardState(limitConfig);
            List<Integer> outOrderList = getAllOutOrderList();
            crnStationOutExecute(wrkMast, limitConfig, currentStationTaskCountRef, loadGuardState, outOrderList);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    private boolean crnStationOutExecute(WrkMast wrkMast,
                                         DispatchLimitConfig limitConfig,
                                         int[] currentStationTaskCountRef,
                                         LoadGuardState loadGuardState,
                                         List<Integer> outOrderList) {
        if (wrkMast == null || wrkMast.getWrkNo() == null) {
            return false;
        }
                Object infoObj = redisUtil.get(RedisKeyType.CRN_OUT_TASK_COMPLETE_STATION_INFO.key + wrkMast.getWrkNo());
                if (infoObj == null) {
                    News.info("出库任务{}数据缓存不存在", wrkMast.getWrkNo());
                    continue;
            return false;
                }
                StationObjModel stationObjModel = JSON.parseObject(infoObj.toString(), StationObjModel.class);
        if (stationObjModel == null) {
            return false;
        }
                StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, stationObjModel.getDeviceNo());
                if (stationThread == null) {
                    continue;
            return false;
                }
                Map<Integer, StationProtocol> stationMap = stationThread.getStatusMap();
                StationProtocol stationProtocol = stationMap.get(stationObjModel.getStationId());
        StationProtocol stationProtocol = stationMap == null ? null : stationMap.get(stationObjModel.getStationId());
                if (stationProtocol == null) {
                    continue;
            return false;
                }
                Object lock = redisUtil.get(RedisKeyType.STATION_OUT_EXECUTE_LIMIT.key + stationProtocol.getStationId());
                if (lock != null) {
                    continue;
            return false;
                }
                //满足自动、有物、工作号0
@@ -194,7 +512,7 @@
                ) {
                    Integer moveStaNo = wrkMast.getStaNo();
                    if (!outOrderList.isEmpty()) {
            if (outOrderList != null && !outOrderList.isEmpty()) {
                        List<NavigateNode> nodes = navigateUtils.calcByStationId(stationProtocol.getStationId(), wrkMast.getStaNo());
                        for (int i = nodes.size() - 1; i >= 0; i--) {
                            NavigateNode node = nodes.get(i);
@@ -212,13 +530,13 @@
                    LoopHitResult loopHitResult = findPathLoopHit(limitConfig, stationProtocol.getStationId(), moveStaNo, loadGuardState);
                    if (isDispatchBlocked(limitConfig, currentStationTaskCountRef[0], loadGuardState, loopHitResult.isThroughLoop())) {
                        return;
                return true;
                    }
                    StationCommand command = stationThread.getCommand(StationCommandType.MOVE, wrkMast.getWrkNo(), stationProtocol.getStationId(), moveStaNo, 0);
                    if (command == null) {
                        News.taskInfo(wrkMast.getWrkNo(), "获取输送线命令失败");
                        continue;
                return false;
                    }
                    wrkMast.setWrkSts(WrkStsType.STATION_RUN.sts);
@@ -234,10 +552,7 @@
                        saveLoopLoadReserve(wrkMast.getWrkNo(), loopHitResult);
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }
    //执行双工位堆垛机输送站点出库任务
@@ -248,27 +563,43 @@
                    .isNotNull("dual_crn_no")
            );
            for (WrkMast wrkMast : wrkMasts) {
                dualCrnStationOutExecute(wrkMast);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public void dualCrnStationOutExecute(WrkMast wrkMast) {
        try {
            if (wrkMast == null || wrkMast.getWrkNo() == null) {
                return;
            }
                Object infoObj = redisUtil.get(RedisKeyType.DUAL_CRN_OUT_TASK_STATION_INFO.key + wrkMast.getWrkNo());
                if (infoObj == null) {
                    News.info("出库任务{}数据缓存不存在", wrkMast.getWrkNo());
                    continue;
                return;
                }
                StationObjModel stationObjModel = JSON.parseObject(infoObj.toString(), StationObjModel.class);
            if (stationObjModel == null) {
                return;
            }
                StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, stationObjModel.getDeviceNo());
                if (stationThread == null) {
                    continue;
                return;
                }
                Map<Integer, StationProtocol> stationMap = stationThread.getStatusMap();
                StationProtocol stationProtocol = stationMap.get(stationObjModel.getStationId());
            StationProtocol stationProtocol = stationMap == null ? null : stationMap.get(stationObjModel.getStationId());
                if (stationProtocol == null) {
                    continue;
                return;
                }
                Object lock = redisUtil.get(RedisKeyType.STATION_OUT_EXECUTE_LIMIT.key + stationProtocol.getStationId());
                if (lock != null) {
                    continue;
                return;
                }
                //满足自动、有物、工作号0
@@ -279,7 +610,7 @@
                    StationCommand command = stationThread.getCommand(StationCommandType.MOVE, wrkMast.getWrkNo(), stationProtocol.getStationId(), wrkMast.getStaNo(), 0);
                    if (command == null) {
                        News.taskInfo(wrkMast.getWrkNo(), "获取输送线命令失败");
                        continue;
                    return;
                    }
                    wrkMast.setWrkSts(WrkStsType.STATION_RUN.sts);
@@ -293,7 +624,6 @@
                        redisUtil.del(RedisKeyType.DUAL_CRN_OUT_TASK_STATION_INFO.key + wrkMast.getWrkNo());
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
@@ -304,24 +634,36 @@
        try {
            List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>().eq("wrk_sts", WrkStsType.STATION_RUN.sts));
            for (WrkMast wrkMast : wrkMasts) {
                stationOutExecuteFinish(wrkMast);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public void stationOutExecuteFinish(WrkMast wrkMast) {
        try {
            if (wrkMast == null) {
                return;
            }
                Integer wrkNo = wrkMast.getWrkNo();
                Integer targetStaNo = wrkMast.getStaNo();
                boolean complete = false;
                BasStation basStation = basStationService.selectOne(new EntityWrapper<BasStation>().eq("station_id", targetStaNo));
                if (basStation == null) {
                    continue;
                return;
                }
                StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basStation.getDeviceNo());
                if (stationThread == null) {
                    continue;
                return;
                }
                Map<Integer, StationProtocol> statusMap = stationThread.getStatusMap();
                StationProtocol stationProtocol = statusMap.get(basStation.getStationId());
            StationProtocol stationProtocol = statusMap == null ? null : statusMap.get(basStation.getStationId());
                if (stationProtocol == null) {
                    continue;
                return;
                }
                if (stationProtocol.getTaskNo().equals(wrkNo)) {
@@ -335,7 +677,6 @@
                    notifyUtils.notify(String.valueOf(SlaveType.Devp), basStation.getDeviceNo(), String.valueOf(wrkMast.getWrkNo()), wrkMast.getWmsWrkNo(), NotifyMsgType.STATION_OUT_TASK_RUN_COMPLETE, null);
                    redisUtil.set(RedisKeyType.STATION_OUT_EXECUTE_COMPLETE_LIMIT.key + wrkMast.getWrkNo(), "lock", 60);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
@@ -346,29 +687,41 @@
        try {
            List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>().eq("wrk_sts", WrkStsType.STATION_RUN_COMPLETE.sts));
            for (WrkMast wrkMast : wrkMasts) {
                checkTaskToComplete(wrkMast);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public void checkTaskToComplete(WrkMast wrkMast) {
        try {
            if (wrkMast == null) {
                return;
            }
                Integer wrkNo = wrkMast.getWrkNo();
                Integer targetStaNo = wrkMast.getStaNo();
                Object lock = redisUtil.get(RedisKeyType.STATION_OUT_EXECUTE_COMPLETE_LIMIT.key + wrkNo);
                if (lock != null) {
                    continue;
                return;
                }
                boolean complete = false;
                BasStation basStation = basStationService.selectOne(new EntityWrapper<BasStation>().eq("station_id", targetStaNo));
                if (basStation == null) {
                    continue;
                return;
                }
                StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basStation.getDeviceNo());
                if (stationThread == null) {
                    continue;
                return;
                }
                Map<Integer, StationProtocol> statusMap = stationThread.getStatusMap();
                StationProtocol stationProtocol = statusMap.get(basStation.getStationId());
            StationProtocol stationProtocol = statusMap == null ? null : statusMap.get(basStation.getStationId());
                if (stationProtocol == null) {
                    continue;
                return;
                }
                if (!stationProtocol.getTaskNo().equals(wrkNo)) {
@@ -379,7 +732,6 @@
                    wrkMast.setWrkSts(WrkStsType.COMPLETE_OUTBOUND.sts);
                    wrkMast.setIoTime(new Date());
                    wrkMastService.updateById(wrkMast);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
@@ -523,6 +875,147 @@
        }
    }
    public void checkStationRunBlock(BasDevp basDevp, Integer stationId) {
        try {
            if (basDevp == null || stationId == null) {
                return;
            }
            StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basDevp.getDevpNo());
            if (stationThread == null) {
                return;
            }
            Map<Integer, StationProtocol> statusMap = stationThread.getStatusMap();
            StationProtocol stationProtocol = statusMap == null ? null : statusMap.get(stationId);
            if (stationProtocol == null) {
                return;
            }
            List<Integer> runBlockReassignLocStationList = new ArrayList<>();
            for (StationObjModel stationObjModel : basDevp.getRunBlockReassignLocStationList$()) {
                runBlockReassignLocStationList.add(stationObjModel.getStationId());
            }
            if (!(stationProtocol.isAutoing()
                    && stationProtocol.isLoading()
                    && stationProtocol.getTaskNo() > 0
                    && stationProtocol.isRunBlock())) {
                return;
            }
            WrkMast wrkMast = wrkMastService.selectByWorkNo(stationProtocol.getTaskNo());
            if (wrkMast == null) {
                News.info("输送站点号={} 运行阻塞,但无法找到对应任务,工作号={}", stationProtocol.getStationId(), stationProtocol.getTaskNo());
                return;
            }
            Object lock = redisUtil.get(RedisKeyType.CHECK_STATION_RUN_BLOCK_LIMIT_.key + stationProtocol.getTaskNo());
            if (lock != null) {
                return;
            }
            redisUtil.set(RedisKeyType.CHECK_STATION_RUN_BLOCK_LIMIT_.key + stationProtocol.getTaskNo(), "lock", 15);
            if (wrkMast.getIoType() == WrkIoType.IN.id && runBlockReassignLocStationList.contains(stationProtocol.getStationId())) {
                //站点处于重新分配库位区域
                //运行堵塞,重新申请任务
                String response = wmsOperateUtils.applyReassignTaskLocNo(wrkMast.getWrkNo(), stationProtocol.getStationId());
                if (response == null) {
                    News.taskError(wrkMast.getWrkNo(), "请求WMS重新分配库位接口失败,接口未响应!!!response:{}", response);
                    return;
                }
                JSONObject jsonObject = JSON.parseObject(response);
                if (jsonObject.getInteger("code").equals(200)) {
                    StartupDto dto = jsonObject.getObject("data", StartupDto.class);
                    String sourceLocNo = wrkMast.getLocNo();
                    String locNo = dto.getLocNo();
                    LocMast sourceLocMast = locMastService.queryByLoc(sourceLocNo);
                    if (sourceLocMast == null) {
                        News.taskInfo(wrkMast.getWrkNo(), "库位号:{} 源库位信息不存在", sourceLocNo);
                        return;
                    }
                    if (!sourceLocMast.getLocSts().equals("S")) {
                        News.taskInfo(wrkMast.getWrkNo(), "库位号:{} 源库位状态不处于入库预约", sourceLocNo);
                        return;
                    }
                    LocMast locMast = locMastService.queryByLoc(locNo);
                    if (locMast == null) {
                        News.taskInfo(wrkMast.getWrkNo(), "库位号:{} 目标库位信息不存在", locNo);
                        return;
                    }
                    if (!locMast.getLocSts().equals("O")) {
                        News.taskInfo(wrkMast.getWrkNo(), "库位号:{} 目标库位状态不处于空库位", locNo);
                        return;
                    }
                    FindCrnNoResult findCrnNoResult = commonService.findCrnNoByLocNo(locNo);
                    if (findCrnNoResult == null) {
                        News.taskInfo(wrkMast.getWrkNo(), "{}工作,未匹配到堆垛机", wrkMast.getWrkNo());
                        return;
                    }
                    Integer crnNo = findCrnNoResult.getCrnNo();
                    Integer targetStationId = commonService.findInStationId(findCrnNoResult, stationProtocol.getStationId());
                    if (targetStationId == null) {
                        News.taskInfo(wrkMast.getWrkNo(), "{}站点,搜索入库站点失败", stationProtocol.getStationId());
                        return;
                    }
                    StationCommand command = stationThread.getCommand(StationCommandType.MOVE, wrkMast.getWrkNo(), stationProtocol.getStationId(), targetStationId, 0);
                    if (command == null) {
                        News.taskInfo(wrkMast.getWrkNo(), "{}工作,获取输送线命令失败", wrkMast.getWrkNo());
                        return;
                    }
                    //更新源库位
                    sourceLocMast.setLocSts("O");
                    sourceLocMast.setModiTime(new Date());
                    locMastService.updateById(sourceLocMast);
                    //更新目标库位
                    locMast.setLocSts("S");
                    locMast.setModiTime(new Date());
                    locMastService.updateById(locMast);
                    //更新工作档数据
                    wrkMast.setLocNo(locNo);
                    wrkMast.setStaNo(targetStationId);
                    if (findCrnNoResult.getCrnType().equals(SlaveType.Crn)) {
                        wrkMast.setCrnNo(crnNo);
                    } else if (findCrnNoResult.getCrnType().equals(SlaveType.DualCrn)) {
                        wrkMast.setDualCrnNo(crnNo);
                    } else {
                        throw new CoolException("未知设备类型");
                    }
                    if (wrkMastService.updateById(wrkMast)) {
                        MessageQueue.offer(SlaveType.Devp, basDevp.getDevpNo(), new Task(2, command));
                    }
                } else {
                    News.error("请求WMS接口失败!!!response:{}", response);
                }
            } else {
                //运行堵塞,重新计算路线
                StationCommand command = stationThread.getCommand(StationCommandType.MOVE, wrkMast.getWrkNo(), stationProtocol.getStationId(), wrkMast.getStaNo(), 0);
                if (command == null) {
                    News.taskInfo(wrkMast.getWrkNo(), "获取输送线命令失败");
                    return;
                }
                MessageQueue.offer(SlaveType.Devp, basDevp.getDevpNo(), new Task(2, command));
                News.info("输送站点堵塞后重新计算路径命令下发成功,站点号={},工作号={},命令数据={}", stationProtocol.getStationId(), wrkMast.getWrkNo(), JSON.toJSONString(command));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    //获取输送线任务数量
    public synchronized int getCurrentStationTaskCount() {
        return countCurrentStationTask();