Junjie
14 小时以前 cc9439b33e3f8ec9ba3e274bc3b392d3cef20ae6
src/main/java/com/zy/common/service/CommonService.java
@@ -31,6 +31,8 @@
@Service
public class CommonService {
    private static final long OUT_STATION_ROUTE_CACHE_SECONDS = 60 * 60 * 24 * 30;
    @Autowired
    private WrkMastService wrkMastService;
    @Autowired
@@ -113,6 +115,8 @@
            wrkMast.setWrkSts(WrkStsType.COMPLETE_OUTBOUND.sts);
        } else if (wrkMast.getIoType() == WrkIoType.LOC_MOVE.id) {
            wrkMast.setWrkSts(WrkStsType.COMPLETE_LOC_MOVE.sts);
        } else if (wrkMast.getIoType() == WrkIoType.CRN_MOVE.id) {
            wrkMast.setWrkSts(WrkStsType.COMPLETE_CRN_MOVE.sts);
        }
        wrkMast.setModiTime(new Date());
@@ -143,6 +147,8 @@
        } else if (wrkMast.getIoType().equals(WrkIoType.OUT.id) && !wrkMast.getWrkSts().equals(WrkStsType.NEW_OUTBOUND.sts)) {
            cancelSuccess = true;
        } else if (wrkMast.getIoType().equals(WrkIoType.LOC_MOVE.id) && !wrkMast.getWrkSts().equals(WrkStsType.NEW_LOC_MOVE.sts)) {
            cancelSuccess = true;
        } else if (wrkMast.getIoType().equals(WrkIoType.CRN_MOVE.id) && !wrkMast.getWrkSts().equals(WrkStsType.NEW_CRN_MOVE.sts)) {
            cancelSuccess = true;
        }
@@ -650,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) {
@@ -682,12 +694,18 @@
            stationList = basDualCrnp.getOutStationList$();
        }
        Integer cachedSourceStationId = resolveCachedOutStationId(findCrnNoResult, targetStationId, stationList);
        if (cachedSourceStationId != null) {
            return cachedSourceStationId;
        }
        Integer finalSourceStationId = null;
        for (StationObjModel stationObjModel : stationList) {
            try {
                List<NavigateNode> navigateNodes = navigateUtils.calcReachablePathByStationId(stationObjModel.getStationId(), targetStationId);
                if(!navigateNodes.isEmpty()) {
                    finalSourceStationId = stationObjModel.getStationId();
                    cacheOutStationId(findCrnNoResult, targetStationId, finalSourceStationId);
                    break;
                }
            } catch (Exception e) {
@@ -697,4 +715,125 @@
        return finalSourceStationId;
    }
    /**
     * 入库路径搜索同样代价较高,只缓存已确认可达的目标站点结果,并通过 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,
                                              Integer targetStationId,
                                              List<StationObjModel> stationList) {
        if (findCrnNoResult == null || findCrnNoResult.getCrnType() == null
                || findCrnNoResult.getCrnNo() == null || targetStationId == null
                || stationList == null || stationList.isEmpty()) {
            return null;
        }
        Object cacheValue = redisUtil.get(buildOutStationRouteCacheKey(findCrnNoResult, targetStationId));
        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 cacheOutStationId(FindCrnNoResult findCrnNoResult,
                                   Integer targetStationId,
                                   Integer sourceStationId) {
        if (findCrnNoResult == null || findCrnNoResult.getCrnType() == null
                || findCrnNoResult.getCrnNo() == null || targetStationId == null
                || sourceStationId == null) {
            return;
        }
        redisUtil.set(buildOutStationRouteCacheKey(findCrnNoResult, targetStationId),
                sourceStationId,
                OUT_STATION_ROUTE_CACHE_SECONDS);
    }
    private String buildOutStationRouteCacheKey(FindCrnNoResult findCrnNoResult, Integer targetStationId) {
        return RedisKeyType.OUT_STATION_ROUTE_CACHE.key
                + findCrnNoResult.getCrnType().name()
                + "_"
                + findCrnNoResult.getCrnNo()
                + "_"
                + targetStationId;
    }
    private Integer parseInteger(Object value) {
        if (value == null) {
            return null;
        }
        if (value instanceof Integer) {
            return (Integer) value;
        }
        if (value instanceof Number) {
            return ((Number) value).intValue();
        }
        try {
            return Integer.parseInt(String.valueOf(value));
        } catch (Exception ignore) {
            return null;
        }
    }
}