#
Junjie
10 小时以前 aed8dfd97e8979b138cd858f35c15bec898542b3
#
2个文件已修改
87 ■■■■ 已修改文件
src/main/java/com/zy/core/utils/StationOperateProcessUtils.java 49 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/test/java/com/zy/core/utils/StationOperateProcessUtilsReroutePipelineTest.java 38 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/utils/StationOperateProcessUtils.java
@@ -1863,31 +1863,52 @@
    }
    private boolean shouldSkipIdleRecoverForRecentDispatch(Integer taskNo, Integer stationId) {
        if (stationMoveCoordinator == null || taskNo == null || taskNo <= 0 || stationId == null) {
        if (taskNo == null || taskNo <= 0 || stationId == null) {
            return false;
        }
        StationMoveSession session = stationMoveCoordinator.loadSession(taskNo);
        if (session == null || !session.isActive() || session.getLastIssuedAt() == null) {
            return false;
        }
        long thresholdMs = STATION_IDLE_RECOVER_SECONDS * 1000L;
        StationMoveSession session = stationMoveCoordinator == null ? null : stationMoveCoordinator.loadSession(taskNo);
        if (session != null && session.isActive() && session.getLastIssuedAt() != null) {
        // 分段执行过程中,刚下发下一段命令时,session 的 currentStationId/dispatchStationId
        // 可能还没来得及和当前观察站点完全对齐;只要当前站点仍在这条活动路线里,
        // 就说明这次 recent dispatch 仍然和它相关,idle recover 不应在 10 秒窗口内再次介入。
        if (!Objects.equals(stationId, session.getCurrentStationId())
                && !Objects.equals(stationId, session.getDispatchStationId())
                && !session.containsStation(stationId)) {
            return false;
        }
            if (Objects.equals(stationId, session.getCurrentStationId())
                    || Objects.equals(stationId, session.getDispatchStationId())
                    || session.containsStation(stationId)) {
        long elapsedMs = System.currentTimeMillis() - session.getLastIssuedAt();
        long thresholdMs = STATION_IDLE_RECOVER_SECONDS * 1000L;
        if (elapsedMs >= thresholdMs) {
            return false;
        }
                if (elapsedMs < thresholdMs) {
        saveStationTaskIdleTrack(new StationTaskIdleTrack(taskNo, stationId, System.currentTimeMillis()));
        News.info("输送站点任务刚完成命令下发,已跳过停留重算。站点号={},工作号={},距上次下发={}ms,routeVersion={}",
                stationId, taskNo, elapsedMs, session.getRouteVersion());
        return true;
    }
            }
        }
        if (!hasRecentIssuedMoveCommand(taskNo, stationId, thresholdMs)) {
            return false;
        }
        saveStationTaskIdleTrack(new StationTaskIdleTrack(taskNo, stationId, System.currentTimeMillis()));
        News.info("输送站点任务刚完成命令下发,已跳过停留重算。站点号={},工作号={},距最近命令下发<{}ms,routeVersion={}",
                stationId, taskNo, thresholdMs, session == null ? null : session.getRouteVersion());
        return true;
    }
    private boolean hasRecentIssuedMoveCommand(Integer taskNo, Integer stationId, long thresholdMs) {
        if (taskNo == null || taskNo <= 0 || stationId == null || thresholdMs <= 0L || basStationOptService == null) {
            return false;
        }
        Date thresholdTime = new Date(System.currentTimeMillis() - thresholdMs);
        List<BasStationOpt> optList = basStationOptService.list(new QueryWrapper<BasStationOpt>()
                .select("id")
                .eq("task_no", taskNo)
                .eq("station_id", stationId)
                .eq("mode", String.valueOf(StationCommandType.MOVE))
                .eq("send", 1)
                .ge("send_time", thresholdTime)
                .orderByDesc("send_time")
                .last("limit 1"));
        return optList != null && !optList.isEmpty();
    }
    private void resetSegmentMoveCommandsBeforeReroute(Integer taskNo) {
        if (redisUtil == null || taskNo == null || taskNo <= 0) {
src/test/java/com/zy/core/utils/StationOperateProcessUtilsReroutePipelineTest.java
@@ -1,8 +1,10 @@
package com.zy.core.utils;
import com.zy.asrs.entity.BasStationOpt;
import com.zy.asrs.entity.BasDevp;
import com.zy.asrs.entity.WrkMast;
import com.zy.asrs.service.BasDevpService;
import com.zy.asrs.service.BasStationOptService;
import com.zy.asrs.service.WrkMastService;
import com.zy.asrs.service.WrkAnalysisService;
import com.zy.asrs.utils.NotifyUtils;
@@ -25,6 +27,7 @@
import org.junit.jupiter.api.Test;
import org.springframework.test.util.ReflectionTestUtils;
import java.util.Date;
import java.util.Collections;
import java.util.List;
import java.util.Map;
@@ -265,6 +268,41 @@
    }
    @Test
    void idleRecover_skipsWhenStationCommandLogShowsRecentIssuedMove() {
        StationOperateProcessUtils utils = new StationOperateProcessUtils();
        StationMoveCoordinator coordinator = mock(StationMoveCoordinator.class);
        BasStationOptService basStationOptService = mock(BasStationOptService.class);
        RedisUtil redisUtil = mock(RedisUtil.class);
        ReflectionTestUtils.setField(utils, "stationMoveCoordinator", coordinator);
        ReflectionTestUtils.setField(utils, "basStationOptService", basStationOptService);
        ReflectionTestUtils.setField(utils, "redisUtil", redisUtil);
        StationMoveSession session = new StationMoveSession();
        session.setStatus(StationMoveSession.STATUS_RUNNING);
        session.setDispatchStationId(136);
        session.setCurrentStationId(145);
        session.setFullPathStationIds(List.of(136, 137, 139, 142, 143, 145, 148, 149, 151));
        session.setLastIssuedAt(System.currentTimeMillis() - 20_000L);
        when(coordinator.loadSession(10493)).thenReturn(session);
        BasStationOpt recentOpt = new BasStationOpt();
        recentOpt.setTaskNo(10493);
        recentOpt.setStationId(148);
        recentOpt.setSend(1);
        recentOpt.setMode(String.valueOf(com.zy.core.enums.StationCommandType.MOVE));
        recentOpt.setSendTime(new Date());
        when(basStationOptService.list(any(com.baomidou.mybatisplus.core.conditions.Wrapper.class)))
                .thenReturn(Collections.singletonList(recentOpt));
        Boolean skipped = ReflectionTestUtils.invokeMethod(utils,
                "shouldSkipIdleRecoverForRecentDispatch",
                10493,
                148);
        assertTrue(Boolean.TRUE.equals(skipped));
    }
    @Test
    void checkStationOutOrder_skipsWhenActiveSessionAlreadyOwnsCurrentStation() {
        StationOperateProcessUtils utils = new StationOperateProcessUtils();
        BasDevpService basDevpService = mock(BasDevpService.class);