Junjie
15 小时以前 e6fbd5ebbca2ebc52adc4f0add47bcb5137b79fd
#入库任务路径计算增加cache
2个文件已修改
59 ■■■■■ 已修改文件
src/main/java/com/zy/common/service/CommonService.java 58 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/enums/RedisKeyType.java 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/common/service/CommonService.java
@@ -656,12 +656,18 @@
            stationList = basDualCrnp.getInStationList$();
        }
        Integer cachedTargetStationId = resolveCachedInStationId(findCrnNoResult, sourceStationId, stationList);
        if (cachedTargetStationId != null) {
            return cachedTargetStationId;
        }
        Integer targetStationId = null;
        for (StationObjModel stationObjModel : stationList) {
            try {
                List<NavigateNode> navigateNodes = navigateUtils.calcReachablePathByStationId(sourceStationId, stationObjModel.getStationId());
                if(!navigateNodes.isEmpty()) {
                    targetStationId = stationObjModel.getStationId();
                    cacheInStationId(findCrnNoResult, sourceStationId, targetStationId);
                    break;
                }
            } catch (Exception e) {
@@ -710,6 +716,58 @@
    }
    /**
     * 入库路径搜索同样代价较高,只缓存已确认可达的目标站点结果,并通过 TTL 限制陈旧风险。
     */
    private Integer resolveCachedInStationId(FindCrnNoResult findCrnNoResult,
                                             Integer sourceStationId,
                                             List<StationObjModel> stationList) {
        if (findCrnNoResult == null || findCrnNoResult.getCrnType() == null
                || findCrnNoResult.getCrnNo() == null || sourceStationId == null
                || stationList == null || stationList.isEmpty()) {
            return null;
        }
        Object cacheValue = redisUtil.get(buildInStationRouteCacheKey(findCrnNoResult, sourceStationId));
        if (cacheValue == null) {
            return null;
        }
        Integer cachedStationId = parseInteger(cacheValue);
        if (cachedStationId == null) {
            return null;
        }
        for (StationObjModel stationObjModel : stationList) {
            if (stationObjModel != null && cachedStationId.equals(stationObjModel.getStationId())) {
                return cachedStationId;
            }
        }
        return null;
    }
    private void cacheInStationId(FindCrnNoResult findCrnNoResult,
                                  Integer sourceStationId,
                                  Integer targetStationId) {
        if (findCrnNoResult == null || findCrnNoResult.getCrnType() == null
                || findCrnNoResult.getCrnNo() == null || sourceStationId == null
                || targetStationId == null) {
            return;
        }
        redisUtil.set(buildInStationRouteCacheKey(findCrnNoResult, sourceStationId),
                targetStationId,
                OUT_STATION_ROUTE_CACHE_SECONDS);
    }
    private String buildInStationRouteCacheKey(FindCrnNoResult findCrnNoResult, Integer sourceStationId) {
        return RedisKeyType.IN_STATION_ROUTE_CACHE.key
                + findCrnNoResult.getCrnType().name()
                + "_"
                + findCrnNoResult.getCrnNo()
                + "_"
                + sourceStationId;
    }
    /**
     * 出库路径搜索代价较高,只缓存已确认可达的站点结果,并通过 TTL 控制陈旧风险。
     */
    private Integer resolveCachedOutStationId(FindCrnNoResult findCrnNoResult,
src/main/java/com/zy/core/enums/RedisKeyType.java
@@ -16,6 +16,7 @@
    LOG_LIMIT("log_limit_"),
    SYSTEM_CONFIG_MAP("system_config_map"),
    FAKE_TASK_NO_AREA("fake_task_no_area"),
    IN_STATION_ROUTE_CACHE("in_station_route_cache_"),
    OUT_STATION_ROUTE_CACHE("out_station_route_cache_"),
    STATION_REACHABLE_CACHE("station_reachable_cache_"),
    PRECOMPUTE_IN_TASK_ROW_CACHE("precompute_in_task_row_cache_"),