| | |
| | | if (taskNo == null || taskNo <= 0 || stationId == null) { |
| | | return RerouteExecutionResult.skip("invalid-station-task"); |
| | | } |
| | | boolean runBlockReroute = context.sceneType() == RerouteSceneType.RUN_BLOCK_REROUTE; |
| | | if (runBlockReroute) { |
| | | if (context.cancelSessionBeforeDispatch() && stationMoveCoordinator != null) { |
| | | stationMoveCoordinator.cancelSession(taskNo); |
| | | } |
| | | if (context.resetSegmentCommandsBeforeDispatch()) { |
| | | resetSegmentMoveCommandsBeforeReroute(taskNo); |
| | | } |
| | | } |
| | | if (context.checkRecentDispatch() |
| | | && shouldSkipIdleRecoverForRecentDispatch(taskNo, stationId)) { |
| | | return RerouteExecutionResult.skip("recent-dispatch"); |
| | | } |
| | | if (countCurrentTaskBufferCommands(stationProtocol.getTaskBufferItems(), taskNo) > 0) { |
| | | int currentTaskBufferCommandCount = countCurrentTaskBufferCommands(stationProtocol.getTaskBufferItems(), taskNo); |
| | | if (currentTaskBufferCommandCount > 0 && !runBlockReroute) { |
| | | if (context.sceneType() == RerouteSceneType.IDLE_RECOVER) { |
| | | News.info("输送站点任务停留超时,但缓存区仍存在当前任务命令,已跳过重算。站点号={},工作号={},当前任务命令数={}", |
| | | stationId, |
| | | taskNo, |
| | | countCurrentTaskBufferCommands(stationProtocol.getTaskBufferItems(), taskNo)); |
| | | currentTaskBufferCommandCount); |
| | | } |
| | | return RerouteExecutionResult.skip("buffer-has-current-task"); |
| | | } |
| | | if (context.checkSuppressDispatch() |
| | | if (currentTaskBufferCommandCount > 0 && runBlockReroute) { |
| | | News.info("输送站点运行堵塞重规划检测到旧分段命令残留,已先清理本地状态后继续重发。站点号={},工作号={},当前任务命令数={}", |
| | | stationId, |
| | | taskNo, |
| | | currentTaskBufferCommandCount); |
| | | } |
| | | if (!runBlockReroute |
| | | && context.checkSuppressDispatch() |
| | | && stationMoveCoordinator != null |
| | | && stationMoveCoordinator.shouldSuppressDispatch(taskNo, stationId, plan.command())) { |
| | | return RerouteExecutionResult.skip("dispatch-suppressed"); |
| | | } |
| | | if (context.sceneType() == RerouteSceneType.RUN_BLOCK_REROUTE |
| | | && shouldSkipRunBlockRerouteForExistingSession(taskNo, stationId, plan.command())) { |
| | | News.info("输送站点堵塞重规划命中已生效同路径路线,已跳过重复下发。站点号={},工作号={},目标站={}", |
| | | stationId, |
| | | taskNo, |
| | | plan.command().getTargetStaNo()); |
| | | return RerouteExecutionResult.skip("run-block-same-path"); |
| | | } |
| | | if (context.requireOutOrderDispatchLock() |
| | | && !tryAcquireOutOrderDispatchLock(taskNo, stationId)) { |
| | | return RerouteExecutionResult.skip("out-order-lock"); |
| | | } |
| | | |
| | | if (context.cancelSessionBeforeDispatch() && stationMoveCoordinator != null) { |
| | | if (!runBlockReroute |
| | | && context.cancelSessionBeforeDispatch() && stationMoveCoordinator != null) { |
| | | stationMoveCoordinator.cancelSession(taskNo); |
| | | } |
| | | if (!isBlank(context.executionLockKey())) { |
| | |
| | | } |
| | | redisUtil.set(context.executionLockKey(), "lock", context.executionLockSeconds()); |
| | | } |
| | | if (context.resetSegmentCommandsBeforeDispatch()) { |
| | | if (!runBlockReroute && context.resetSegmentCommandsBeforeDispatch()) { |
| | | resetSegmentMoveCommandsBeforeReroute(taskNo); |
| | | } |
| | | |
| | |
| | | if (session == null) { |
| | | return false; |
| | | } |
| | | boolean protectedStatus = session.isActive() || StationMoveSession.STATUS_BLOCKED.equals(session.getStatus()); |
| | | if (!protectedStatus || !session.containsStation(stationId)) { |
| | | if (!session.isActive() || !session.containsStation(stationId)) { |
| | | return false; |
| | | } |
| | | if (StationMoveDispatchMode.CIRCLE == session.getDispatchMode()) { |
| | | return true; |
| | | } |
| | | return !Objects.equals(stationId, session.getCurrentRouteTargetStationId()); |
| | | } |
| | | |
| | | private boolean shouldSkipRunBlockRerouteForExistingSession(Integer wrkNo, |
| | | Integer stationId, |
| | | StationCommand candidateCommand) { |
| | | if (stationMoveCoordinator == null |
| | | || wrkNo == null || wrkNo <= 0 |
| | | || stationId == null |
| | | || candidateCommand == null) { |
| | | return false; |
| | | } |
| | | StationMoveSession session = stationMoveCoordinator.loadSession(wrkNo); |
| | | if (session == null) { |
| | | return false; |
| | | } |
| | | boolean protectedStatus = session.isActive() || StationMoveSession.STATUS_BLOCKED.equals(session.getStatus()); |
| | | if (!protectedStatus) { |
| | | return false; |
| | | } |
| | | boolean sameDispatchStation = Objects.equals(stationId, session.getCurrentStationId()) |
| | | || Objects.equals(stationId, session.getDispatchStationId()); |
| | | if (!sameDispatchStation) { |
| | | return false; |
| | | } |
| | | String candidateSignature = stationMoveCoordinator.buildPathSignature(candidateCommand); |
| | | return !isBlank(candidateSignature) && Objects.equals(candidateSignature, session.getPathSignature()); |
| | | } |
| | | |
| | | private boolean isWatchingCircleArrival(Integer wrkNo, Integer stationId) { |