From 873941c1a6c4aefe7e172be973865957b0ae4378 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期四, 19 三月 2026 15:21:44 +0800
Subject: [PATCH] #
---
src/main/java/com/zy/asrs/service/impl/StationPathPolicyServiceImpl.java | 46 ++++++++++++++++++++++++++--------------------
1 files changed, 26 insertions(+), 20 deletions(-)
diff --git a/src/main/java/com/zy/asrs/service/impl/StationPathPolicyServiceImpl.java b/src/main/java/com/zy/asrs/service/impl/StationPathPolicyServiceImpl.java
index 2e82a25..36db2db 100644
--- a/src/main/java/com/zy/asrs/service/impl/StationPathPolicyServiceImpl.java
+++ b/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<>();
--
Gitblit v1.9.1