Junjie
2026-04-13 b8640dc78123f4be2483feed2f48b9183983f51f
src/main/java/com/zy/core/utils/station/StationRerouteProcessor.java
@@ -51,6 +51,7 @@
public class StationRerouteProcessor {
    private static final int OUT_ORDER_DISPATCH_LIMIT_SECONDS = 2;
    private static final long STATION_MOVE_RESET_WAIT_MS = 1000L;
    private static final int RUN_BLOCK_DIRECT_REASSIGN_LIMIT_SECONDS = 15 * 60;
    @Autowired
    private BasDevpService basDevpService;
@@ -447,15 +448,26 @@
        if (basDevp == null || stationThread == null || stationProtocol == null || wrkMast == null) {
            return;
        }
        if (isDirectReassignContextStale(stationProtocol, wrkMast)) {
            return;
        }
        int currentTaskBufferCommandCount = countCurrentTaskBufferCommands(
                stationProtocol.getTaskBufferItems(),
                stationProtocol.getTaskNo()
        );
        if (currentTaskBufferCommandCount > 0) {
            News.info("输送站点运行堵塞重分配已跳过,缓存区仍存在当前任务命令。站点号={},工作号={},当前任务命令数={}",
            News.info("输送站点运行堵塞重分配检测到旧分段命令残留,将先重置本地分段状态后继续重发。站点号={},工作号={},当前任务命令数={}",
                    stationProtocol.getStationId(),
                    stationProtocol.getTaskNo(),
                    currentTaskBufferCommandCount);
        }
        if (!stationDispatchRuntimeStateSupport.tryAcquireRunBlockDirectReassignLock(
                wrkMast.getWrkNo(),
                stationProtocol.getStationId(),
                RUN_BLOCK_DIRECT_REASSIGN_LIMIT_SECONDS)) {
            News.info("输送站点运行堵塞重分配已跳过,15分钟内不允许重复申请。站点号={},工作号={}",
                    stationProtocol.getStationId(),
                    wrkMast.getWrkNo());
            return;
        }
        String response = wmsOperateUtils.applyReassignTaskLocNo(wrkMast.getWrkNo(), stationProtocol.getStationId());
@@ -534,6 +546,7 @@
        if (!wrkMastService.updateById(wrkMast)) {
            return;
        }
        stationDispatchRuntimeStateSupport.signalSegmentReset(wrkMast.getWrkNo(), STATION_MOVE_RESET_WAIT_MS);
        boolean offered = offerDevpCommandWithDedup(basDevp.getDevpNo(), command, "checkStationRunBlock_direct");
        if (!offered) {
            return;
@@ -551,6 +564,30 @@
        }
    }
    private boolean isDirectReassignContextStale(StationProtocol stationProtocol, WrkMast wrkMast) {
        if (stationProtocol == null || wrkMast == null || stationMoveCoordinator == null) {
            return false;
        }
        Integer taskNo = wrkMast.getWrkNo();
        Integer triggerStationId = stationProtocol.getStationId();
        if (taskNo == null || taskNo <= 0 || triggerStationId == null) {
            return false;
        }
        StationMoveSession session = stationMoveCoordinator.loadSession(taskNo);
        if (session == null || !session.isActive()) {
            return false;
        }
        Integer currentStationId = session.getCurrentStationId();
        if (currentStationId == null || Objects.equals(currentStationId, triggerStationId)) {
            return false;
        }
        News.info("输送站点运行堵塞重分配已跳过,任务已离开触发站点。触发站点={},当前站点={},工作号={}",
                triggerStationId,
                currentStationId,
                taskNo);
        return true;
    }
    private int countCurrentTaskBufferCommands(List<StationTaskBufferItem> taskBufferItems, Integer currentTaskNo) {
        if (taskBufferItems == null || taskBufferItems.isEmpty() || currentTaskNo == null || currentTaskNo <= 0) {
            return 0;