mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-11-28 04:59:52 +01:00
fixed agent creation failde due to duplicate plugin
This commit is contained in:
parent
c1cf912446
commit
d7fcbdfdbb
2 changed files with 20 additions and 3 deletions
|
|
@ -38,6 +38,7 @@ public class RenExceptionHandler {
|
||||||
|
|
||||||
@ExceptionHandler(DuplicateKeyException.class)
|
@ExceptionHandler(DuplicateKeyException.class)
|
||||||
public Result<Void> handleDuplicateKeyException(DuplicateKeyException ex) {
|
public Result<Void> handleDuplicateKeyException(DuplicateKeyException ex) {
|
||||||
|
log.error("Duplicate key error: {}", ex.getMessage(), ex);
|
||||||
Result<Void> result = new Result<>();
|
Result<Void> result = new Result<>();
|
||||||
result.error(ErrorCode.DB_RECORD_EXISTS);
|
result.error(ErrorCode.DB_RECORD_EXISTS);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -96,7 +96,7 @@ public class AgentServiceImpl extends BaseServiceImpl<AgentDao, AgentEntity> imp
|
||||||
|
|
||||||
// 如果智能体编码为空,自动生成一个带前缀的编码
|
// 如果智能体编码为空,自动生成一个带前缀的编码
|
||||||
if (entity.getAgentCode() == null || entity.getAgentCode().trim().isEmpty()) {
|
if (entity.getAgentCode() == null || entity.getAgentCode().trim().isEmpty()) {
|
||||||
entity.setAgentCode("AGT_" + System.currentTimeMillis());
|
entity.setAgentCode("AGT_" + UUID.randomUUID().toString().replace("-", "").substring(0, 8));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 如果排序字段为空,设置默认值0
|
// 如果排序字段为空,设置默认值0
|
||||||
|
|
@ -393,7 +393,21 @@ public class AgentServiceImpl extends BaseServiceImpl<AgentDao, AgentEntity> imp
|
||||||
// 播放音乐、播放故事、查天气、查新闻
|
// 播放音乐、播放故事、查天气、查新闻
|
||||||
String[] pluginIds = new String[] { "SYSTEM_PLUGIN_MUSIC", "SYSTEM_PLUGIN_STORY",
|
String[] pluginIds = new String[] { "SYSTEM_PLUGIN_MUSIC", "SYSTEM_PLUGIN_STORY",
|
||||||
"SYSTEM_PLUGIN_WEATHER", "SYSTEM_PLUGIN_NEWS_NEWSNOW" };
|
"SYSTEM_PLUGIN_WEATHER", "SYSTEM_PLUGIN_NEWS_NEWSNOW" };
|
||||||
|
|
||||||
|
// 检查已存在的插件映射
|
||||||
|
List<AgentPluginMapping> existingMappings = agentPluginMappingService.list(
|
||||||
|
new QueryWrapper<AgentPluginMapping>().eq("agent_id", entity.getId())
|
||||||
|
);
|
||||||
|
List<String> existingPluginIds = existingMappings.stream()
|
||||||
|
.map(AgentPluginMapping::getPluginId)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
for (String pluginId : pluginIds) {
|
for (String pluginId : pluginIds) {
|
||||||
|
// 跳过已存在的插件映射
|
||||||
|
if (existingPluginIds.contains(pluginId)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
ModelProviderDTO provider = modelProviderService.getById(pluginId);
|
ModelProviderDTO provider = modelProviderService.getById(pluginId);
|
||||||
if (provider == null) {
|
if (provider == null) {
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -412,8 +426,10 @@ public class AgentServiceImpl extends BaseServiceImpl<AgentDao, AgentEntity> imp
|
||||||
mapping.setAgentId(entity.getId());
|
mapping.setAgentId(entity.getId());
|
||||||
toInsert.add(mapping);
|
toInsert.add(mapping);
|
||||||
}
|
}
|
||||||
// 保存默认插件
|
// 只保存不存在的默认插件
|
||||||
agentPluginMappingService.saveBatch(toInsert);
|
if (!toInsert.isEmpty()) {
|
||||||
|
agentPluginMappingService.saveBatch(toInsert);
|
||||||
|
}
|
||||||
return entity.getId();
|
return entity.getId();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue