#
Junjie
17 分钟以前 fd837cb1e5b3f5ebfba12c29f32fe34dd4c38669
src/main/java/com/zy/asrs/service/impl/StationPathPolicyServiceImpl.java
@@ -10,8 +10,6 @@
import com.zy.asrs.service.BasStationPathProfileService;
import com.zy.asrs.service.BasStationPathRuleService;
import com.zy.asrs.service.StationPathPolicyService;
import com.zy.common.utils.RedisUtil;
import com.zy.core.enums.RedisKeyType;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -32,8 +30,6 @@
    private BasStationPathProfileService basStationPathProfileService;
    @Autowired
    private BasStationPathRuleService basStationPathRuleService;
    @Autowired
    private RedisUtil redisUtil;
    private volatile CacheSnapshot cacheSnapshot = new CacheSnapshot();
    private volatile long cacheTime = 0L;
@@ -41,10 +37,10 @@
    @Override
    public StationPathResolvedPolicy resolvePolicy(Integer startStationId, Integer endStationId) {
        StationPathResolvedPolicy resolved = new StationPathResolvedPolicy();
        resolved.setScoreMode(getSystemConfig("stationPathScoreMode", "legacy"));
        resolved.setDefaultProfileCode(getSystemConfig("stationPathDefaultProfileCode", "default"));
        resolved.setScoreMode("twoStage");
        CacheSnapshot snapshot = getCacheSnapshot();
        resolved.setDefaultProfileCode(snapshot.defaultProfileCode);
        BasStationPathRule matchedRule = matchRule(snapshot.ruleList, startStationId, endStationId);
        BasStationPathProfile matchedProfile = null;
        if (matchedRule != null && notBlank(matchedRule.getProfileCode())) {
@@ -95,6 +91,7 @@
        try {
            List<BasStationPathProfile> profiles = basStationPathProfileService.list(new QueryWrapper<BasStationPathProfile>()
                    .eq("status", 1)
                    .orderByDesc("is_default")
                    .orderByAsc("priority", "id"));
            if (profiles != null) {
                snapshot.profileList.addAll(profiles);
@@ -103,6 +100,7 @@
                        snapshot.profileMap.put(profile.getProfileCode(), profile);
                    }
                }
                snapshot.defaultProfileCode = resolveDefaultProfileCode(profiles);
            }
        } catch (Exception e) {
            log.warn("加载站点路径模板失败,回退默认配置: {}", e.getMessage());
@@ -230,21 +228,28 @@
        return config;
    }
    private String getSystemConfig(String code, String defaultValue) {
        try {
            Object mapObj = redisUtil.get(RedisKeyType.SYSTEM_CONFIG_MAP.key);
            if (mapObj instanceof Map) {
                Object value = ((Map<?, ?>) mapObj).get(code);
                if (value != null) {
                    String text = String.valueOf(value).trim();
                    if (!text.isEmpty()) {
                        return text;
                    }
                }
            }
        } catch (Exception ignore) {
    private String resolveDefaultProfileCode(List<BasStationPathProfile> profiles) {
        if (profiles == null || profiles.isEmpty()) {
            return "default";
        }
        return defaultValue;
        for (BasStationPathProfile profile : profiles) {
            if (profile != null
                    && Short.valueOf((short) 1).equals(profile.getIsDefault())
                    && notBlank(profile.getProfileCode())) {
                return profile.getProfileCode();
            }
        }
        for (BasStationPathProfile profile : profiles) {
            if (profile != null && "default".equals(profile.getProfileCode())) {
                return profile.getProfileCode();
            }
        }
        for (BasStationPathProfile profile : profiles) {
            if (profile != null && notBlank(profile.getProfileCode())) {
                return profile.getProfileCode();
            }
        }
        return "default";
    }
    private boolean notBlank(String value) {
@@ -257,6 +262,7 @@
    private static class CacheSnapshot {
        private boolean loaded = false;
        private String defaultProfileCode = "default";
        private final List<BasStationPathProfile> profileList = new ArrayList<>();
        private final List<BasStationPathRule> ruleList = new ArrayList<>();
        private final Map<String, BasStationPathProfile> profileMap = new HashMap<>();