#
Junjie
13 小时以前 aed8dfd97e8979b138cd858f35c15bec898542b3
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) {