Merge pull request #2317 from xinnan-tech/hot-fix

fix:python config api no need maskSensitive
This commit is contained in:
欣南科技
2025-10-08 22:45:22 +08:00
committed by GitHub
3 changed files with 21 additions and 61 deletions
@@ -298,7 +298,7 @@ public class ConfigServiceImpl implements ConfigService {
Map<String, Object> voiceprintConfig = new HashMap<>();
voiceprintConfig.put("url", voiceprintUrl);
voiceprintConfig.put("speakers", speakers);
// 获取声纹识别相似度阈值,默认0.4
String thresholdStr = sysParamsService.getValue("server.voiceprint_similarity_threshold", true);
if (StringUtils.isNotBlank(thresholdStr) && !"null".equals(thresholdStr)) {
@@ -350,7 +350,7 @@ public class ConfigServiceImpl implements ConfigService {
* @param result 结果Map
*/
private void buildModuleConfig(
String assistantName,
String assistantName,
String prompt,
String summaryMemory,
String voice,
@@ -366,18 +366,18 @@ public class ConfigServiceImpl implements ConfigService {
Map<String, Object> result,
boolean isCache) {
Map<String, String> selectedModule = new HashMap<>();
String[] modelTypes = { "VAD", "ASR", "TTS", "Memory", "Intent", "LLM", "VLLM" };
String[] modelIds = { vadModelId, asrModelId, ttsModelId, memModelId, intentModelId, llmModelId, vllmModelId };
String intentLLMModelId = null;
String memLocalShortLLMModelId = null;
for (int i = 0; i < modelIds.length; i++) {
if (modelIds[i] == null) {
continue;
}
// 关键:第三个参数传false,确保获取原始密钥
ModelConfigEntity model = modelConfigService.getModelById(modelIds[i], isCache, false);
ModelConfigEntity model = modelConfigService.getModelByIdFromCache(modelIds[i]);
if (model == null) {
continue;
}
@@ -426,7 +426,7 @@ public class ConfigServiceImpl implements ConfigService {
if (StringUtils.isNotBlank(intentLLMModelId)) {
if (!typeConfig.containsKey(intentLLMModelId)) {
// 修改这里:添加isMaskSensitive=false参数
ModelConfigEntity intentLLM = modelConfigService.getModelById(intentLLMModelId, isCache, false);
ModelConfigEntity intentLLM = modelConfigService.getModelByIdFromCache(intentLLMModelId);
typeConfig.put(intentLLM.getId(), intentLLM.getConfigJson());
}
}
@@ -434,7 +434,7 @@ public class ConfigServiceImpl implements ConfigService {
if (!typeConfig.containsKey(memLocalShortLLMModelId)) {
// 修改这里:添加isMaskSensitive=false参数
ModelConfigEntity memLocalShortLLM = modelConfigService
.getModelById(memLocalShortLLMModelId, isCache, false);
.getModelByIdFromCache(memLocalShortLLMModelId);
typeConfig.put(memLocalShortLLM.getId(), memLocalShortLLM.getConfigJson());
}
}
@@ -36,27 +36,16 @@ public interface ModelConfigService extends BaseService<ModelConfigEntity> {
/**
* 根据ID获取模型配置
*
* @param id 模型ID
* @param isCache 是否缓存
* @param isMaskSensitive 是否掩码敏感信息
* @param id 模型ID
* @return 模型配置实体
*/
ModelConfigEntity getModelById(String id, boolean isCache, boolean isMaskSensitive);
ModelConfigEntity getModelByIdFromCache(String id);
/**
* 根据ID获取模型配置(默认掩码敏感信息)
*
* @param id 模型ID
* @param isCache 是否缓存
* @return 模型配置实体
*/
ModelConfigEntity getModelById(String id, boolean isCache);
/**
* 设置默认模型
*
* @param modelType 模型类型
* @param isDefault 是否默认(1:是,0:否)
* @param modelType 模型类型
* @param isDefault 是否默认(1:是,0:否)
*/
void setDefaultModel(String modelType, int isDefault);
@@ -211,44 +211,15 @@ public class ModelConfigServiceImpl extends BaseServiceImpl<ModelConfigDao, Mode
}
@Override
public ModelConfigEntity getModelById(String id, boolean isCache) {
return getModelById(id, isCache, true);
}
@Override
public ModelConfigEntity getModelById(String id, boolean isCache, boolean isMaskSensitive) {
public ModelConfigEntity getModelByIdFromCache(String id) {
if (StringUtils.isBlank(id)) {
return null;
}
ModelConfigEntity entity = null;
String cacheKey = RedisKeys.getModelConfigById(id);
if (isCache) {
// 从缓存获取
entity = (ModelConfigEntity) redisUtils.get(cacheKey);
ModelConfigEntity entity = (ModelConfigEntity) redisUtils.get(cacheKey);
if (entity == null) {
entity = modelConfigDao.selectById(id);
if (entity != null) {
// 修改:根据isMaskSensitive参数重新处理敏感信息
if (!isMaskSensitive && entity.getConfigJson() != null) {
// 如果需要获取原始配置,但缓存的是掩码后的配置,则从数据库重新获取
ModelConfigEntity originalEntity = modelConfigDao.selectById(id);
if (originalEntity != null) {
entity.setConfigJson(originalEntity.getConfigJson());
}
}
return entity;
}
}
// 从数据库获取数据
entity = modelConfigDao.selectById(id);
if (entity != null) {
// 根据isMaskSensitive参数决定是否掩码敏感信息
if (isMaskSensitive && entity.getConfigJson() != null) {
entity.setConfigJson(maskSensitiveFields(entity.getConfigJson()));
}
if (isCache) {
redisUtils.set(cacheKey, entity);
}
}
@@ -367,19 +338,19 @@ public class ModelConfigServiceImpl extends BaseServiceImpl<ModelConfigDao, Mode
// 2. 只更新非敏感字段
modelConfigEntity.setModelName(modelConfigBodyDTO.getModelName());
modelConfigEntity.setSort(modelConfigBodyDTO.getSort());
modelConfigEntity.setIsEnabled(modelConfigBodyDTO.getIsEnabled());
modelConfigEntity.setIsEnabled(modelConfigBodyDTO.getIsEnabled());
// 3. 处理配置JSON,仅更新非敏感字段和明确修改的敏感字段
if (modelConfigBodyDTO.getConfigJson() != null && originalEntity.getConfigJson() != null) {
JSONObject originalJson = originalEntity.getConfigJson();
JSONObject updatedJson = new JSONObject(originalJson); // 基于原始JSON进行修改
// 遍历更新的JSON,只更新非敏感字段或确实被修改的敏感字段
for (String key : modelConfigBodyDTO.getConfigJson().keySet()) {
Object value = modelConfigBodyDTO.getConfigJson().get(key);
// 如果是敏感字段,需要确认是否真的被修改(前端传入的可能是掩码后的值)
if (SensitiveDataUtils.isSensitiveField(key)) {
if (value instanceof String && !SensitiveDataUtils.isMaskedValue((String) value)) {
updatedJson.put(key, value);
}
@@ -391,10 +362,10 @@ public class ModelConfigServiceImpl extends BaseServiceImpl<ModelConfigDao, Mode
updatedJson.put(key, value);
}
}
modelConfigEntity.setConfigJson(updatedJson);
}
return modelConfigEntity;
}