From dc3f9cc91759823ce59486f19b138be4b296a0f1 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期二, 28 四月 2026 09:43:28 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/asrs/controller/OpenController.java |  120 ++++++++++++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 100 insertions(+), 20 deletions(-)

diff --git a/src/main/java/com/zy/asrs/controller/OpenController.java b/src/main/java/com/zy/asrs/controller/OpenController.java
index b9436ce..e421c08 100644
--- a/src/main/java/com/zy/asrs/controller/OpenController.java
+++ b/src/main/java/com/zy/asrs/controller/OpenController.java
@@ -6,11 +6,13 @@
 import com.core.exception.CoolException;
 import com.zy.asrs.domain.Result.CancelTaskBatchResult;
 import com.zy.asrs.domain.param.*;
+import com.core.annotations.ManagerAuth;
 import com.zy.asrs.entity.DeviceConfig;
 import com.zy.asrs.entity.LocMast;
 import com.zy.asrs.entity.WrkMast;
 import com.zy.asrs.service.DeviceConfigService;
 import com.zy.asrs.service.LocMastService;
+import com.zy.asrs.service.RuntimeConfigService;
 import com.zy.asrs.service.WrkMastService;
 import com.zy.common.annotations.OpenApiLog;
 import com.zy.common.service.CommonService;
@@ -21,13 +23,13 @@
 import com.zy.core.model.protocol.DualCrnProtocol;
 import com.zy.core.model.protocol.RgvProtocol;
 import com.zy.core.model.protocol.StationProtocol;
+import com.zy.core.network.fake.FakeConfigKeys;
 import com.zy.core.thread.CrnThread;
 import com.zy.core.thread.DualCrnThread;
 import com.zy.core.thread.RgvThread;
 import com.zy.core.thread.StationThread;
 import com.zy.system.entity.Config;
 import com.zy.system.service.ConfigService;
-import com.zy.system.service.HighPrivilegeGrantService;
 
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -35,12 +37,12 @@
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.*;
 
-import jakarta.servlet.http.HttpServletRequest;
-
 import java.util.ArrayList;
+import java.util.LinkedHashMap;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 @Slf4j
 @RestController
@@ -64,9 +66,7 @@
     @Autowired
     private DeviceConfigService deviceConfigService;
     @Autowired
-    private HighPrivilegeGrantService highPrivilegeGrantService;
-    @Autowired
-    private HttpServletRequest request;
+    private RuntimeConfigService runtimeConfigService;
 
     // 绉诲簱浠诲姟
     @PostMapping("/createLocMoveTask")
@@ -144,13 +144,7 @@
         if (param == null) {
             return R.error("鍙傛暟涓嶈兘涓虹┖");
         }
-        boolean directCancel = false;
-        try {
-            highPrivilegeGrantService.assertGranted(request.getHeader("token"), "鍙栨秷浠诲姟");
-            directCancel = true;
-        } catch (CoolException ignore) {
-        }
-        boolean completeTask = commonService.cancelTask(param, directCancel);
+        boolean completeTask = commonService.cancelTask(param);
         if (completeTask) {
             return R.ok();
         }
@@ -176,13 +170,7 @@
         if (param == null) {
             return R.error("鍙傛暟涓嶈兘涓虹┖");
         }
-        boolean directCancel = false;
-        try {
-            highPrivilegeGrantService.assertGranted(request.getHeader("token"), "鍙栨秷浠诲姟");
-            directCancel = true;
-        } catch (CoolException ignore) {
-        }
-        CancelTaskBatchResult result = commonService.cancelTaskBatch(param, directCancel);
+        CancelTaskBatchResult result = commonService.cancelTaskBatch(param);
         return R.ok().add(result);
     }
 
@@ -403,6 +391,15 @@
         return R.ok().add(map);
     }
 
+    @PostMapping("/runtimeConfig/update")
+    @OpenApiLog(memo = "淇敼杩愯鍙傛暟")
+    public R updateRuntimeConfig(@RequestBody RuntimeConfigUpdateParam param) {
+        if (param == null || param.getConfigMap() == null || param.getConfigMap().isEmpty()) {
+            return R.error("鍙傛暟涓嶈兘涓虹┖");
+        }
+        return R.ok().add(runtimeConfigService.updateRuntimeConfig(param.getConfigMap()));
+    }
+
     @GetMapping("/getFakeSystemRunStatus")
     public R getFakeSystemRunStatus() {
         HashMap<String, Object> map = new HashMap<>();
@@ -443,4 +440,87 @@
         return R.ok();
     }
 
+    @GetMapping("/fakeConfig/auth")
+    @ManagerAuth
+    public R getFakeConfig() {
+        LinkedHashMap<String, Object> map = new LinkedHashMap<>();
+        for (String key : FakeConfigKeys.ALL_KEYS) {
+            String defaultValue = FakeConfigKeys.DEFAULTS.get(key);
+            map.put(key, configService.getConfigValue(key, defaultValue));
+        }
+        return R.ok().add(map);
+    }
+
+    @PostMapping("/fakeConfig/save/auth")
+    @ManagerAuth
+    public R saveFakeConfig(@RequestBody FakeConfigSaveParam param) {
+        if (param == null || param.getConfigMap() == null || param.getConfigMap().isEmpty()) {
+            return R.error("鍙傛暟涓嶈兘涓虹┖");
+        }
+        Set<String> allowKeys = FakeConfigKeys.ALL_KEYS;
+        Map<String, String> normalizedMap = new LinkedHashMap<>();
+        for (Map.Entry<String, Object> entry : param.getConfigMap().entrySet()) {
+            String key = entry.getKey();
+            if (!allowKeys.contains(key)) {
+                return R.error("涓嶆敮鎸佺殑閰嶇疆椤�: " + key);
+            }
+            normalizedMap.put(key, normalizeFakeConfigValue(key, entry.getValue()));
+        }
+        validateFakeCrnLaserConfig(normalizedMap);
+        for (Map.Entry<String, String> entry : normalizedMap.entrySet()) {
+            if (!configService.saveConfigValue(entry.getKey(), entry.getValue())) {
+                return R.error("淇濆瓨澶辫触: " + entry.getKey());
+            }
+        }
+        configService.refreshSystemConfigCache();
+        return getFakeConfig();
+    }
+
+    private void validateFakeCrnLaserConfig(Map<String, String> normalizedMap) {
+        long bayMin = resolveFakeLongValue(normalizedMap, FakeConfigKeys.FAKE_CRN_BAY_MIN);
+        long bayMax = resolveFakeLongValue(normalizedMap, FakeConfigKeys.FAKE_CRN_BAY_MAX);
+        long laserMin = resolveFakeLongValue(normalizedMap, FakeConfigKeys.FAKE_CRN_LASER_MIN);
+        long laserMax = resolveFakeLongValue(normalizedMap, FakeConfigKeys.FAKE_CRN_LASER_MAX);
+        if (bayMax <= bayMin) {
+            throw new CoolException("鍫嗗灈鏈� bay 鏈�澶у�煎繀椤诲ぇ浜庢渶灏忓��");
+        }
+        if (laserMax <= laserMin) {
+            throw new CoolException("鍫嗗灈鏈洪暛灏勬渶澶у�煎繀椤诲ぇ浜庢渶灏忓��");
+        }
+    }
+
+    private long resolveFakeLongValue(Map<String, String> normalizedMap, String key) {
+        String value = normalizedMap.get(key);
+        if (value == null) {
+            value = configService.getConfigValue(key, FakeConfigKeys.DEFAULTS.get(key));
+        }
+        return Long.parseLong(value);
+    }
+
+    private String normalizeFakeConfigValue(String key, Object rawValue) {
+        if (rawValue == null) {
+            throw new CoolException(key + " 鍙傛暟涓嶈兘涓虹┖");
+        }
+        String value = String.valueOf(rawValue).trim();
+        if (FakeConfigKeys.BOOLEAN_KEYS.contains(key)) {
+            if (!"Y".equalsIgnoreCase(value) && !"N".equalsIgnoreCase(value)) {
+                throw new CoolException(key + " 浠呮敮鎸� Y/N");
+            }
+            return value.toUpperCase();
+        }
+        if (FakeConfigKeys.LONG_KEYS.contains(key)) {
+            long parsed;
+            try {
+                parsed = Long.parseLong(value);
+            } catch (Exception e) {
+                throw new CoolException(key + " 蹇呴』涓洪潪璐熸暣鏁�");
+            }
+            if (parsed < 0) {
+                throw new CoolException(key + " 蹇呴』涓洪潪璐熸暣鏁�");
+            }
+            return String.valueOf(parsed);
+        }
+        throw new CoolException("涓嶆敮鎸佺殑閰嶇疆椤�: " + key);
+    }
+
 }

--
Gitblit v1.9.1