1.优化目录结构

This commit is contained in:
2025-08-01 15:10:15 +08:00
parent 4c0d5dbd75
commit 93c10482d0
44 changed files with 68 additions and 274 deletions

View File

@@ -0,0 +1,43 @@
package vvpkassistant.config;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import vvpkassistant.FunctionConfig.mapper.FunctionConfigMapper;
import vvpkassistant.FunctionConfig.model.FunctionConfigModel;
import javax.annotation.PostConstruct;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
@Component
@RequiredArgsConstructor
public class FunctionConfigHolder {
// 线程安全的全局配置容器
static public final List<FunctionConfigModel> CONFIGS = new CopyOnWriteArrayList<>();
@Autowired
private FunctionConfigMapper configMapper;
/**
* 启动时加载所有配置到内存
*/
@PostConstruct
public void init() {
List<FunctionConfigModel> dbConfigs = configMapper.selectList(null);
CONFIGS.clear();
CONFIGS.addAll(dbConfigs);
System.out.println("已加载 "+CONFIGS.size()+" 条功能配置");
}
/**
* 按功能名获取配置值
*/
public static String getValue(String functionName) {
return CONFIGS.stream()
.filter(c -> functionName.equals(c.getFunctionName()))
.findFirst()
.map(FunctionConfigModel::getFunctionValue)
.orElse(null);
}
}