mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-23 15:43:54 +08:00
update:删除指定智能体关联的所有设备 (#699)
This commit is contained in:
@@ -35,6 +35,7 @@ import xiaozhi.modules.agent.entity.AgentEntity;
|
||||
import xiaozhi.modules.agent.entity.AgentTemplateEntity;
|
||||
import xiaozhi.modules.agent.service.AgentService;
|
||||
import xiaozhi.modules.agent.service.AgentTemplateService;
|
||||
import xiaozhi.modules.device.service.DeviceService;
|
||||
import xiaozhi.modules.security.user.SecurityUser;
|
||||
|
||||
@Tag(name = "智能体管理")
|
||||
@@ -44,6 +45,7 @@ import xiaozhi.modules.security.user.SecurityUser;
|
||||
public class AgentController {
|
||||
private final AgentService agentService;
|
||||
private final AgentTemplateService agentTemplateService;
|
||||
private final DeviceService deviceService;
|
||||
|
||||
@GetMapping("/list")
|
||||
@Operation(summary = "获取用户智能体列表")
|
||||
@@ -81,6 +83,22 @@ public class AgentController {
|
||||
public Result<Void> save(@RequestBody @Valid AgentCreateDTO dto) {
|
||||
AgentEntity entity = ConvertUtils.sourceToTarget(dto, AgentEntity.class);
|
||||
|
||||
// 获取默认模板
|
||||
AgentTemplateEntity template = agentTemplateService.getDefaultTemplate();
|
||||
if (template != null) {
|
||||
// 设置模板中的默认值
|
||||
entity.setAsrModelId(template.getAsrModelId());
|
||||
entity.setVadModelId(template.getVadModelId());
|
||||
entity.setLlmModelId(template.getLlmModelId());
|
||||
entity.setTtsModelId(template.getTtsModelId());
|
||||
entity.setTtsVoiceId(template.getTtsVoiceId());
|
||||
entity.setMemModelId(template.getMemModelId());
|
||||
entity.setIntentModelId(template.getIntentModelId());
|
||||
entity.setSystemPrompt(template.getSystemPrompt());
|
||||
entity.setLangCode(template.getLangCode());
|
||||
entity.setLanguage(template.getLanguage());
|
||||
}
|
||||
|
||||
// 设置用户ID和创建者信息
|
||||
UserDetail user = SecurityUser.getUser();
|
||||
entity.setUserId(user.getId());
|
||||
@@ -158,6 +176,9 @@ public class AgentController {
|
||||
@Operation(summary = "删除智能体")
|
||||
@RequiresPermissions("sys:role:normal")
|
||||
public Result<Void> delete(@PathVariable String id) {
|
||||
// 先删除关联的设备
|
||||
deviceService.deleteByAgentId(id);
|
||||
// 再删除智能体
|
||||
agentService.deleteById(id);
|
||||
return new Result<>();
|
||||
}
|
||||
|
||||
@@ -11,4 +11,10 @@ import xiaozhi.modules.agent.entity.AgentTemplateEntity;
|
||||
*/
|
||||
public interface AgentTemplateService extends IService<AgentTemplateEntity> {
|
||||
|
||||
/**
|
||||
* 获取默认模板
|
||||
*
|
||||
* @return 默认模板实体
|
||||
*/
|
||||
AgentTemplateEntity getDefaultTemplate();
|
||||
}
|
||||
|
||||
+13
-1
@@ -2,6 +2,7 @@ package xiaozhi.modules.agent.service.impl;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
|
||||
import xiaozhi.modules.agent.dao.AgentTemplateDao;
|
||||
@@ -15,6 +16,17 @@ import xiaozhi.modules.agent.service.AgentTemplateService;
|
||||
*/
|
||||
@Service
|
||||
public class AgentTemplateServiceImpl extends ServiceImpl<AgentTemplateDao, AgentTemplateEntity>
|
||||
implements AgentTemplateService {
|
||||
implements AgentTemplateService {
|
||||
|
||||
/**
|
||||
* 获取默认模板
|
||||
*
|
||||
* @return 默认模板实体
|
||||
*/
|
||||
public AgentTemplateEntity getDefaultTemplate() {
|
||||
LambdaQueryWrapper<AgentTemplateEntity> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.orderByAsc(AgentTemplateEntity::getSort)
|
||||
.last("LIMIT 1");
|
||||
return this.getOne(wrapper);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,6 +44,13 @@ public interface DeviceService {
|
||||
*/
|
||||
void deleteByUserId(Long userId);
|
||||
|
||||
/**
|
||||
* 删除指定智能体关联的所有设备
|
||||
*
|
||||
* @param agentId 智能体id
|
||||
*/
|
||||
void deleteByAgentId(String agentId);
|
||||
|
||||
/**
|
||||
* 获取指定用户的设备数量
|
||||
*
|
||||
|
||||
+7
@@ -208,6 +208,13 @@ public class DeviceServiceImpl extends BaseServiceImpl<DeviceDao, DeviceEntity>
|
||||
return baseDao.selectCount(wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteByAgentId(String agentId) {
|
||||
UpdateWrapper<DeviceEntity> wrapper = new UpdateWrapper<>();
|
||||
wrapper.eq("agent_id", agentId);
|
||||
baseDao.delete(wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageData<UserShowDeviceListVO> page(DevicePageUserDTO dto) {
|
||||
Map<String, Object> params = new HashMap<String, Object>();
|
||||
|
||||
+1
-1
@@ -41,7 +41,7 @@ public class ModelController {
|
||||
|
||||
@GetMapping("/names")
|
||||
@Operation(summary = "获取所有模型名称")
|
||||
@RequiresPermissions("sys:role:superAdmin")
|
||||
@RequiresPermissions("sys:role:normal")
|
||||
public Result<List<ModelBasicInfoDTO>> getModelNames(@RequestParam String modelType,
|
||||
@RequestParam(required = false) String modelName) {
|
||||
List<ModelBasicInfoDTO> modelList = modelConfigService.getModelCodeList(modelType, modelName);
|
||||
|
||||
Reference in New Issue
Block a user