| | |
| | | |
| | | boolean complete = false; |
| | | Integer targetDeviceNo = null; |
| | | StationThread stationThread = null; |
| | | BasStation basStation = basStationService.getOne(new QueryWrapper<BasStation>().eq("station_id", targetStaNo)); |
| | | if (basStation != null) { |
| | | targetDeviceNo = basStation.getDeviceNo(); |
| | | StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basStation.getDeviceNo()); |
| | | stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basStation.getDeviceNo()); |
| | | if (stationThread != null) { |
| | | Map<Integer, StationProtocol> statusMap = stationThread.getStatusMap(); |
| | | StationProtocol stationProtocol = statusMap.get(basStation.getStationId()); |
| | |
| | | } |
| | | |
| | | if (complete) { |
| | | attemptClearTaskPath(stationThread, wrkNo); |
| | | completeStationRunTask(wrkMast, targetDeviceNo); |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | private void attemptClearTaskPath(StationThread stationThread, Integer taskNo) { |
| | | if (stationThread == null || taskNo == null || taskNo <= 0) { |
| | | return; |
| | | } |
| | | try { |
| | | boolean cleared = stationThread.clearPath(taskNo); |
| | | if (cleared) { |
| | | News.info("输送站点任务运行完成后清理残留路径,工作号={}", taskNo); |
| | | } |
| | | } catch (Exception e) { |
| | | News.error("输送站点任务运行完成后清理残留路径异常,工作号={}", taskNo, e); |
| | | } |
| | | } |
| | | |
| | |
| | | if (taskNo == null || taskNo <= 0 || stationId == null) { |
| | | return RerouteExecutionResult.skip("invalid-station-task"); |
| | | } |
| | | boolean runBlockReroute = context.sceneType() == RerouteSceneType.RUN_BLOCK_REROUTE; |
| | | if (runBlockReroute) { |
| | | // 站点进入堵塞后,设备侧可能已经把之前预下发的分段命令清掉了。 |
| | | // 先作废本地 session/segment 状态,再按新路线重发,避免被旧状态反向卡住。 |
| | | if (context.cancelSessionBeforeDispatch() && stationMoveCoordinator != null) { |
| | | stationMoveCoordinator.cancelSession(taskNo); |
| | | } |
| | | if (context.resetSegmentCommandsBeforeDispatch()) { |
| | | resetSegmentMoveCommandsBeforeReroute(taskNo); |
| | | } |
| | | if (stationMoveCoordinator != null) { |
| | | return stationMoveCoordinator.withTaskDispatchLock(taskNo, |
| | | () -> executeReroutePlanWithTaskLock(context, plan, stationProtocol, taskNo, stationId)); |
| | | } |
| | | return executeReroutePlanWithTaskLock(context, plan, stationProtocol, taskNo, stationId); |
| | | } |
| | | |
| | | private RerouteExecutionResult executeReroutePlanWithTaskLock(RerouteContext context, |
| | | RerouteCommandPlan plan, |
| | | StationProtocol stationProtocol, |
| | | Integer taskNo, |
| | | Integer stationId) { |
| | | boolean runBlockReroute = context.sceneType() == RerouteSceneType.RUN_BLOCK_REROUTE; |
| | | if (context.checkRecentDispatch() |
| | | && shouldSkipIdleRecoverForRecentDispatch(taskNo, stationId)) { |
| | | return RerouteExecutionResult.skip("recent-dispatch"); |
| | |
| | | return RerouteExecutionResult.skip("out-order-lock"); |
| | | } |
| | | |
| | | if (context.cancelSessionBeforeDispatch() && stationMoveCoordinator != null) { |
| | | // 切路前先把旧 session 置为 CANCEL_PENDING,让已经排队中的旧分段线程在最终发送前停下。 |
| | | stationMoveCoordinator.markCancelPending(taskNo, "reroute_pending"); |
| | | } |
| | | |
| | | if (runBlockReroute) { |
| | | // 站点进入堵塞后,设备侧可能已经把之前预下发的分段命令清掉了。 |
| | | // 先作废本地 session/segment 状态,再按新路线重发,避免被旧状态反向卡住。 |
| | | if (context.cancelSessionBeforeDispatch() && stationMoveCoordinator != null) { |
| | | stationMoveCoordinator.cancelSession(taskNo); |
| | | } |
| | | if (context.resetSegmentCommandsBeforeDispatch()) { |
| | | resetSegmentMoveCommandsBeforeReroute(taskNo); |
| | | } |
| | | } |
| | | |
| | | if (!runBlockReroute |
| | | && context.cancelSessionBeforeDispatch() && stationMoveCoordinator != null) { |
| | | stationMoveCoordinator.cancelSession(taskNo); |