|
|
|
@ -148,6 +148,8 @@ public class AiModelConfigService { |
|
|
|
deactivateByAppType(config.getAppType()); |
|
|
|
} |
|
|
|
aiModelConfigMapper.insert(config); |
|
|
|
// JSONB 字段 MyBatis Plus typeHandler 可能不触发,用 JdbcTemplate 显式写入保证可靠 |
|
|
|
persistExtraConfig(config.getId(), config.getExtraConfig()); |
|
|
|
log.info("新建 AI 模型配置: name={}, appType={}, modelName={}", |
|
|
|
config.getName(), config.getAppType(), config.getModelName()); |
|
|
|
return config; |
|
|
|
@ -184,6 +186,8 @@ public class AiModelConfigService { |
|
|
|
// 设置 ID 确保更新正确 |
|
|
|
config.setId(id); |
|
|
|
aiModelConfigMapper.updateById(config); |
|
|
|
// JSONB 字段 MyBatis Plus typeHandler 可能不触发,用 JdbcTemplate 显式写入保证可靠 |
|
|
|
persistExtraConfig(id, config.getExtraConfig()); |
|
|
|
log.info("更新 AI 模型配置: id={}", id); |
|
|
|
return aiModelConfigMapper.selectById(id); |
|
|
|
} |
|
|
|
@ -265,4 +269,33 @@ public class AiModelConfigService { |
|
|
|
} |
|
|
|
return apiKey.substring(0, 4) + "****" + apiKey.substring(apiKey.length() - 4); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 显式持久化 extraConfig JSONB 字段 |
|
|
|
* MyBatis Plus 的 insert/updateById 对带 typeHandler 的 JSONB 字段可能不触发写入, |
|
|
|
* 使用 JdbcTemplate 显式更新保证数据可靠落库。 |
|
|
|
* |
|
|
|
* @param id 配置ID |
|
|
|
* @param extraConfig 扩展配置 Map |
|
|
|
*/ |
|
|
|
private void persistExtraConfig(Long id, Map<String, Object> extraConfig) { |
|
|
|
if (id == null) { |
|
|
|
return; |
|
|
|
} |
|
|
|
try { |
|
|
|
String json; |
|
|
|
if (extraConfig == null || extraConfig.isEmpty()) { |
|
|
|
json = "{}"; |
|
|
|
} else { |
|
|
|
com.fasterxml.jackson.databind.ObjectMapper om = new com.fasterxml.jackson.databind.ObjectMapper(); |
|
|
|
json = om.writeValueAsString(extraConfig); |
|
|
|
} |
|
|
|
jdbcTemplate.update( |
|
|
|
"UPDATE ai_model_config SET extra_config = ?::jsonb WHERE id = ?", |
|
|
|
json, id); |
|
|
|
log.debug("持久化 extraConfig: id={}, extraConfig={}", id, json); |
|
|
|
} catch (Exception e) { |
|
|
|
log.warn("持久化 extraConfig 失败: id={}, error={}", id, e.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |