Junjie
2026-04-16 413b42a497ed1b695ceb0acada0122e553021ddb
src/main/java/com/zy/asrs/controller/OpenController.java
@@ -6,6 +6,7 @@
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;
@@ -21,13 +22,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 +36,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
@@ -63,10 +64,6 @@
    private ConfigService configService;
    @Autowired
    private DeviceConfigService deviceConfigService;
    @Autowired
    private HighPrivilegeGrantService highPrivilegeGrantService;
    @Autowired
    private HttpServletRequest request;
    // 移库任务
    @PostMapping("/createLocMoveTask")
@@ -144,13 +141,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 +167,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);
    }
@@ -443,4 +428,62 @@
        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;
        for (Map.Entry<String, Object> entry : param.getConfigMap().entrySet()) {
            String key = entry.getKey();
            if (!allowKeys.contains(key)) {
                return R.error("不支持的配置项: " + key);
            }
            String normalized = normalizeFakeConfigValue(key, entry.getValue());
            if (!configService.saveConfigValue(key, normalized)) {
                return R.error("保存失败: " + key);
            }
        }
        configService.refreshSystemConfigCache();
        return getFakeConfig();
    }
    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);
    }
}