Junjie
9 小时以前 a72c3844450381a872e4f0f149210e480679984a
refactor: unify station out-order reroute flow
2个文件已修改
151 ■■■■■ 已修改文件
src/main/java/com/zy/core/utils/StationOperateProcessUtils.java 118 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/test/java/com/zy/core/utils/StationOperateProcessUtilsReroutePipelineTest.java 33 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/utils/StationOperateProcessUtils.java
@@ -742,56 +742,21 @@
                    continue;
                }
                if (countCurrentTaskBufferCommands(stationProtocol.getTaskBufferItems(), stationProtocol.getTaskNo()) > 0) {
                    continue;
                }
                Double pathLenFactor = resolveOutboundPathLenFactor(wrkMast);
                OutOrderDispatchDecision dispatchDecision = resolveOutboundDispatchDecision(
                        stationProtocol.getStationId(),
                RerouteContext context = RerouteContext.create(
                        RerouteSceneType.OUT_ORDER,
                        basDevp,
                        stationThread,
                        stationProtocol,
                        wrkMast,
                        outOrderStationIds,
                        pathLenFactor
                );
                Integer moveStaNo = dispatchDecision == null ? null : dispatchDecision.getTargetStationId();
                if (moveStaNo == null || Objects.equals(moveStaNo, stationProtocol.getStationId())) {
                    continue;
                }
                StationCommand command = buildOutboundMoveCommand(
                        stationThread,
                        wrkMast,
                        stationProtocol.getStationId(),
                        moveStaNo,
                        pathLenFactor
                );
                if (command == null) {
                    News.taskInfo(wrkMast.getWrkNo(), "获取输送线命令失败");
                    continue;
                }
                if (stationMoveCoordinator != null
                        && stationMoveCoordinator.shouldSuppressDispatch(wrkMast.getWrkNo(), stationProtocol.getStationId(), command)) {
                    continue;
                }
                if (!tryAcquireOutOrderDispatchLock(wrkMast.getWrkNo(), stationProtocol.getStationId())) {
                    continue;
                }
                resetSegmentMoveCommandsBeforeReroute(wrkMast.getWrkNo());
                boolean offered = offerDevpCommandWithDedup(stationObjModel.getDeviceNo(), command, "checkStationOutOrder");
                if (!offered) {
                    continue;
                }
                syncOutOrderWatchState(wrkMast, stationProtocol.getStationId(), outOrderStationIds, dispatchDecision, command);
                if (stationMoveCoordinator != null) {
                    stationMoveCoordinator.recordDispatch(
                            wrkMast.getWrkNo(),
                            stationProtocol.getStationId(),
                            "checkStationOutOrder",
                            command,
                            dispatchDecision != null && dispatchDecision.isCircle()
                    );
                }
                News.info(dispatchDecision.isCircle() ? "{}任务进行绕圈" : "{}任务直接去目标点", wrkMast.getWrkNo());
                        pathLenFactor,
                        "checkStationOutOrder"
                ).withDispatchDeviceNo(stationObjModel.getDeviceNo())
                        .withSuppressDispatchGuard()
                        .withOutOrderDispatchLock()
                        .withResetSegmentCommandsBeforeDispatch();
                executeSharedReroute(context);
            }
        }
    }
@@ -838,55 +803,20 @@
                if (Objects.equals(stationProtocol.getStationId(), wrkMast.getStaNo())) {
                    continue;
                }
                if (countCurrentTaskBufferCommands(stationProtocol.getTaskBufferItems(), stationProtocol.getTaskNo()) > 0) {
                    continue;
                }
                Double pathLenFactor = resolveOutboundPathLenFactor(wrkMast);
                OutOrderDispatchDecision dispatchDecision = resolveOutboundDispatchDecision(
                        stationProtocol.getStationId(),
                RerouteContext context = RerouteContext.create(
                        RerouteSceneType.WATCH_CIRCLE,
                        basDevp,
                        stationThread,
                        stationProtocol,
                        wrkMast,
                        outOrderList,
                        pathLenFactor
                );
                Integer moveStaNo = dispatchDecision == null ? null : dispatchDecision.getTargetStationId();
                if (moveStaNo == null || Objects.equals(moveStaNo, stationProtocol.getStationId())) {
                    continue;
                }
                StationCommand command = buildOutboundMoveCommand(
                        stationThread,
                        wrkMast,
                        stationProtocol.getStationId(),
                        moveStaNo,
                        pathLenFactor
                );
                if (command == null) {
                    News.taskInfo(wrkMast.getWrkNo(), "获取输送线命令失败");
                    continue;
                }
                if (stationMoveCoordinator != null
                        && stationMoveCoordinator.shouldSuppressDispatch(wrkMast.getWrkNo(), stationProtocol.getStationId(), command)) {
                    continue;
                }
                if (!tryAcquireOutOrderDispatchLock(wrkMast.getWrkNo(), stationProtocol.getStationId())) {
                    continue;
                }
                resetSegmentMoveCommandsBeforeReroute(wrkMast.getWrkNo());
                boolean offered = offerDevpCommandWithDedup(basDevp.getDevpNo(), command, "watchCircleStation");
                if (!offered) {
                    continue;
                }
                syncOutOrderWatchState(wrkMast, stationProtocol.getStationId(), outOrderList, dispatchDecision, command);
                if (stationMoveCoordinator != null) {
                    stationMoveCoordinator.recordDispatch(
                            wrkMast.getWrkNo(),
                            stationProtocol.getStationId(),
                            "watchCircleStation",
                            command,
                            dispatchDecision != null && dispatchDecision.isCircle()
                    );
                }
                        pathLenFactor,
                        "watchCircleStation"
                ).withSuppressDispatchGuard()
                        .withOutOrderDispatchLock()
                        .withResetSegmentCommandsBeforeDispatch();
                executeSharedReroute(context);
            }
        }
    }
@@ -1018,7 +948,7 @@
        return RerouteExecutionResult.dispatched(plan.command(), clearedCommandCount);
    }
    private RerouteDecision resolveSharedRerouteDecision(RerouteContext context) {
    RerouteDecision resolveSharedRerouteDecision(RerouteContext context) {
        if (context == null || context.wrkMast() == null || context.stationProtocol() == null) {
            return RerouteDecision.skip("missing-runtime-dependency");
        }
src/test/java/com/zy/core/utils/StationOperateProcessUtilsReroutePipelineTest.java
@@ -104,6 +104,39 @@
        assertEquals("buffer-has-current-task", result.skipReason());
    }
    @Test
    void outOrderAndWatchCircle_shareDecisionFlow() {
        StationOperateProcessUtils utils = new StationOperateProcessUtils();
        WrkMast wrkMast = buildWrkMast(100, 20);
        StationOperateProcessUtils.RerouteContext outOrderContext = StationOperateProcessUtils.RerouteContext.create(
                StationOperateProcessUtils.RerouteSceneType.OUT_ORDER,
                buildBasDevp(1),
                mock(StationThread.class),
                buildStationProtocol(10, 100, 10),
                wrkMast,
                Collections.emptyList(),
                0.0d,
                "checkStationOutOrder"
        );
        StationOperateProcessUtils.RerouteContext watchCircleContext = StationOperateProcessUtils.RerouteContext.create(
                StationOperateProcessUtils.RerouteSceneType.WATCH_CIRCLE,
                buildBasDevp(1),
                mock(StationThread.class),
                buildStationProtocol(10, 100, 10),
                wrkMast,
                Collections.emptyList(),
                0.0d,
                "watchCircleStation"
        );
        StationOperateProcessUtils.RerouteDecision outOrderDecision = utils.resolveSharedRerouteDecision(outOrderContext);
        StationOperateProcessUtils.RerouteDecision watchCircleDecision = utils.resolveSharedRerouteDecision(watchCircleContext);
        assertEquals(20, outOrderDecision.targetStationId());
        assertEquals(20, watchCircleDecision.targetStationId());
    }
    private static BasDevp buildBasDevp(int devpNo) {
        BasDevp basDevp = new BasDevp();
        basDevp.setDevpNo(devpNo);