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); } }