Junjie
2 天以前 63b01db83d9aad8a15276b4236a9a22e4aeef065
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package com.zy.ai.service.impl;
 
import com.zy.ai.domain.autotune.AutoTuneControlModeSnapshot;
import com.zy.ai.service.AutoTuneControlModeService;
import com.zy.system.service.ConfigService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
 
@Service("autoTuneControlModeService")
@RequiredArgsConstructor
public class AutoTuneControlModeServiceImpl implements AutoTuneControlModeService {
 
    private static final String CONFIG_AUTO_TUNE_ENABLED = "aiAutoTuneEnabled";
    private static final String CONFIG_ANALYSIS_ONLY = "aiAutoTuneAnalysisOnly";
    private static final String MODE_ANALYSIS_ONLY = "analysis_only";
    private static final String MODE_APPLY_ENABLED = "apply_enabled";
 
    private final ConfigService configService;
 
    @Override
    public AutoTuneControlModeSnapshot currentMode() {
        boolean enabled = readConfigBoolean(CONFIG_AUTO_TUNE_ENABLED, false);
        boolean analysisOnly = readConfigBoolean(CONFIG_ANALYSIS_ONLY, true);
 
        AutoTuneControlModeSnapshot snapshot = new AutoTuneControlModeSnapshot();
        snapshot.setEnabled(enabled);
        snapshot.setAnalysisOnly(analysisOnly);
        snapshot.setAllowApply(!analysisOnly);
        snapshot.setModeCode(analysisOnly ? MODE_ANALYSIS_ONLY : MODE_APPLY_ENABLED);
        snapshot.setModeLabel(analysisOnly ? "仅分析模式" : "允许正式调参");
        return snapshot;
    }
 
    private boolean readConfigBoolean(String code, boolean defaultValue) {
        String value = configService.getConfigValue(code, defaultValue ? "Y" : "N");
        if (value == null || value.trim().isEmpty()) {
            return defaultValue;
        }
        String normalized = value.trim();
        return "Y".equalsIgnoreCase(normalized)
                || "true".equalsIgnoreCase(normalized)
                || "1".equals(normalized);
    }
}