From 656429e94f5989911bdf07848ef44b1cc71dfaf1 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期四, 19 三月 2026 12:55:31 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/asrs/controller/BasStationPathPolicyController.java |  103 ++++++++++++++++++++++++---------------------------
 1 files changed, 49 insertions(+), 54 deletions(-)

diff --git a/src/main/java/com/zy/asrs/controller/BasStationPathPolicyController.java b/src/main/java/com/zy/asrs/controller/BasStationPathPolicyController.java
index 17fffc3..33d83e2 100644
--- a/src/main/java/com/zy/asrs/controller/BasStationPathPolicyController.java
+++ b/src/main/java/com/zy/asrs/controller/BasStationPathPolicyController.java
@@ -18,11 +18,7 @@
 import com.zy.asrs.service.StationPathPolicyService;
 import com.zy.common.model.NavigateNode;
 import com.zy.common.utils.NavigateUtils;
-import com.zy.common.utils.RedisUtil;
 import com.zy.common.web.BaseController;
-import com.zy.core.enums.RedisKeyType;
-import com.zy.system.entity.Config;
-import com.zy.system.service.ConfigService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -46,10 +42,6 @@
     @Autowired
     private BasStationPathRuleService basStationPathRuleService;
     @Autowired
-    private ConfigService configService;
-    @Autowired
-    private RedisUtil redisUtil;
-    @Autowired
     private StationPathPolicyService stationPathPolicyService;
     @Autowired
     private BasStationService basStationService;
@@ -61,11 +53,14 @@
     @RequestMapping("/data/auth")
     @ManagerAuth
     public R data() {
+        List<BasStationPathProfile> profileList = basStationPathProfileService.list(new QueryWrapper<BasStationPathProfile>()
+                .orderByDesc("is_default")
+                .orderByAsc("priority", "id"));
         Map<String, Object> data = new HashMap<>();
-        data.put("profiles", basStationPathProfileService.list(new QueryWrapper<BasStationPathProfile>().orderByAsc("priority", "id")));
+        data.put("profiles", profileList);
         data.put("rules", basStationPathRuleService.list(new QueryWrapper<BasStationPathRule>().orderByAsc("priority", "id")));
-        data.put("scoreMode", getSystemConfig("stationPathScoreMode", "legacy"));
-        data.put("defaultProfileCode", getSystemConfig("stationPathDefaultProfileCode", "default"));
+        data.put("scoreMode", "twoStage");
+        data.put("defaultProfileCode", resolveDefaultProfileCode(profileList));
         data.put("stations", buildStationSummaryList());
         data.put("levList", basMapService.getLevList());
         return R.ok(data);
@@ -76,12 +71,6 @@
     public R save(@RequestBody JSONObject payload) {
         JSONArray profiles = payload.getJSONArray("profiles");
         JSONArray rules = payload.getJSONArray("rules");
-
-        upsertSystemConfig("绔欑偣璺緞璇勫垎妯″紡", "stationPathScoreMode", defaultIfBlank(payload.getString("scoreMode"), "legacy"), "String");
-        upsertSystemConfig("绔欑偣璺緞榛樿妯℃澘缂栫爜", "stationPathDefaultProfileCode", defaultIfBlank(payload.getString("defaultProfileCode"), "default"), "String");
-
-        basStationPathProfileService.remove(new QueryWrapper<>());
-        basStationPathRuleService.remove(new QueryWrapper<>());
 
         List<BasStationPathProfile> profileList = new ArrayList<>();
         if (profiles != null) {
@@ -98,6 +87,7 @@
                 profile.setProfileName(defaultIfBlank(item.getString("profileName"), item.getString("profileCode")));
                 profile.setPriority(item.getInteger("priority") == null ? 100 : item.getInteger("priority"));
                 profile.setStatus(item.getShort("status") == null ? (short) 1 : item.getShort("status"));
+                profile.setIsDefault((short) 0);
                 profile.setMemo(item.getString("memo"));
                 Object configObj = item.get("config");
                 if (configObj != null) {
@@ -108,6 +98,29 @@
                 profileList.add(profile);
             }
         }
+        if (profileList.isEmpty()) {
+            return R.error("鑷冲皯闇�瑕佷繚鐣欎竴涓ā鏉�");
+        }
+
+        String defaultProfileCode = defaultIfBlank(payload.getString("defaultProfileCode"), profileList.get(0).getProfileCode());
+        BasStationPathProfile defaultProfile = null;
+        for (BasStationPathProfile profile : profileList) {
+            if (profile != null && defaultProfileCode.equals(profile.getProfileCode())) {
+                profile.setIsDefault((short) 1);
+                defaultProfile = profile;
+                break;
+            }
+        }
+        if (defaultProfile == null) {
+            return R.error("榛樿妯℃澘缂栫爜娌℃湁瀵瑰簲妯℃澘");
+        }
+        if (!Short.valueOf((short) 1).equals(defaultProfile.getStatus())) {
+            return R.error("榛樿妯℃澘蹇呴』鍚敤");
+        }
+
+        basStationPathProfileService.remove(new QueryWrapper<>());
+        basStationPathRuleService.remove(new QueryWrapper<>());
+
         if (!profileList.isEmpty()) {
             basStationPathProfileService.saveBatch(profileList);
         }
@@ -142,8 +155,6 @@
         if (!ruleList.isEmpty()) {
             basStationPathRuleService.saveBatch(ruleList);
         }
-
-        refreshSystemConfigCache();
         stationPathPolicyService.evictCache();
         return R.ok();
     }
@@ -264,44 +275,28 @@
         return result;
     }
 
-    private void upsertSystemConfig(String name, String code, String value, String selectType) {
-        String finalValue = value == null ? "" : value.trim();
-        Config config = configService.getOne(new QueryWrapper<Config>().eq("code", code));
-        if (config == null) {
-            config = new Config(name, code, finalValue, (short) 1, (short) 1);
-            config.setSelectType(selectType);
-            configService.save(config);
-        } else {
-            config.setName(name);
-            config.setValue(finalValue);
-            config.setType((short) 1);
-            config.setStatus((short) 1);
-            config.setSelectType(selectType);
-            configService.updateById(config);
+    private String resolveDefaultProfileCode(List<BasStationPathProfile> profileList) {
+        if (profileList == null || profileList.isEmpty()) {
+            return "default";
         }
-    }
-
-    private void refreshSystemConfigCache() {
-        HashMap<String, String> systemConfigMap = new HashMap<>();
-        List<Config> configList = configService.list(new QueryWrapper<>());
-        for (Config config : configList) {
-            systemConfigMap.put(config.getCode(), config.getValue());
-        }
-        redisUtil.set(RedisKeyType.SYSTEM_CONFIG_MAP.key, systemConfigMap);
-    }
-
-    private String getSystemConfig(String code, String defaultValue) {
-        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;
-                }
+        for (BasStationPathProfile profile : profileList) {
+            if (profile != null
+                    && Short.valueOf((short) 1).equals(profile.getIsDefault())
+                    && !isBlank(profile.getProfileCode())) {
+                return profile.getProfileCode();
             }
         }
-        return defaultValue;
+        for (BasStationPathProfile profile : profileList) {
+            if (profile != null && "default".equals(profile.getProfileCode())) {
+                return profile.getProfileCode();
+            }
+        }
+        for (BasStationPathProfile profile : profileList) {
+            if (profile != null && !isBlank(profile.getProfileCode())) {
+                return profile.getProfileCode();
+            }
+        }
+        return "default";
     }
 
     private List<Integer> parseStationIdArray(JSONArray array) {

--
Gitblit v1.9.1