mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-28 10:03:54 +08:00
Merge pull request #1856 from xinnan-tech/manager-api-mcp
修改智控台删除声纹,声纹服务不在线,无法删除的业务逻辑错误
This commit is contained in:
+29
-9
@@ -3,9 +3,11 @@ package xiaozhi.modules.agent.service.impl;
|
|||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.Executor;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
import org.springframework.core.io.ByteArrayResource;
|
import org.springframework.core.io.ByteArrayResource;
|
||||||
import org.springframework.http.HttpEntity;
|
import org.springframework.http.HttpEntity;
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
@@ -22,7 +24,6 @@ import org.springframework.web.client.RestTemplate;
|
|||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import xiaozhi.common.constant.Constant;
|
import xiaozhi.common.constant.Constant;
|
||||||
import xiaozhi.common.exception.RenException;
|
import xiaozhi.common.exception.RenException;
|
||||||
@@ -43,7 +44,6 @@ import xiaozhi.modules.sys.service.SysParamsService;
|
|||||||
* @author zjy
|
* @author zjy
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
@AllArgsConstructor
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class AgentVoicePrintServiceImpl extends ServiceImpl<AgentVoicePrintDao, AgentVoicePrintEntity>
|
public class AgentVoicePrintServiceImpl extends ServiceImpl<AgentVoicePrintDao, AgentVoicePrintEntity>
|
||||||
implements AgentVoicePrintService {
|
implements AgentVoicePrintService {
|
||||||
@@ -55,6 +55,18 @@ public class AgentVoicePrintServiceImpl extends ServiceImpl<AgentVoicePrintDao,
|
|||||||
private final TransactionTemplate transactionTemplate;
|
private final TransactionTemplate transactionTemplate;
|
||||||
// 识别度
|
// 识别度
|
||||||
private final Double RECOGNITION = 0.5;
|
private final Double RECOGNITION = 0.5;
|
||||||
|
private final Executor taskExecutor;
|
||||||
|
|
||||||
|
public AgentVoicePrintServiceImpl(AgentChatAudioService agentChatAudioService, RestTemplate restTemplate,
|
||||||
|
SysParamsService sysParamsService, AgentChatHistoryService agentChatHistoryService,
|
||||||
|
TransactionTemplate transactionTemplate, @Qualifier("taskExecutor") Executor taskExecutor) {
|
||||||
|
this.agentChatAudioService = agentChatAudioService;
|
||||||
|
this.restTemplate = restTemplate;
|
||||||
|
this.sysParamsService = sysParamsService;
|
||||||
|
this.agentChatHistoryService = agentChatHistoryService;
|
||||||
|
this.transactionTemplate = transactionTemplate;
|
||||||
|
this.taskExecutor = taskExecutor;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean insert(AgentVoicePrintSaveDTO dto) {
|
public boolean insert(AgentVoicePrintSaveDTO dto) {
|
||||||
@@ -96,7 +108,7 @@ public class AgentVoicePrintServiceImpl extends ServiceImpl<AgentVoicePrintDao,
|
|||||||
@Override
|
@Override
|
||||||
public boolean delete(Long userId, String voicePrintId) {
|
public boolean delete(Long userId, String voicePrintId) {
|
||||||
// 开启事务
|
// 开启事务
|
||||||
return Boolean.TRUE.equals(transactionTemplate.execute(status -> {
|
boolean b = Boolean.TRUE.equals(transactionTemplate.execute(status -> {
|
||||||
try {
|
try {
|
||||||
// 删除声纹,按照指定当前登录用户和智能体
|
// 删除声纹,按照指定当前登录用户和智能体
|
||||||
int row = baseMapper.delete(new LambdaQueryWrapper<AgentVoicePrintEntity>()
|
int row = baseMapper.delete(new LambdaQueryWrapper<AgentVoicePrintEntity>()
|
||||||
@@ -106,17 +118,25 @@ public class AgentVoicePrintServiceImpl extends ServiceImpl<AgentVoicePrintDao,
|
|||||||
status.setRollbackOnly(); // 标记事务回滚
|
status.setRollbackOnly(); // 标记事务回滚
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
cancelVoicePrint(voicePrintId);
|
|
||||||
return true;
|
return true;
|
||||||
} catch (RenException e) {
|
|
||||||
status.setRollbackOnly(); // 标记事务回滚
|
|
||||||
throw e;
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
status.setRollbackOnly(); // 标记事务回滚
|
status.setRollbackOnly(); // 标记事务回滚
|
||||||
log.error("删除声纹错误原因:{}", e.getMessage());
|
log.error("删除声纹存在错误原因:{}", e.getMessage());
|
||||||
throw new RenException("删除声纹错误,请联系管理员");
|
throw new RenException("删除声纹出现了错误");
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
// 数据库声纹数据删除成功才继续执行删除声纹服务的数据
|
||||||
|
if(b){
|
||||||
|
taskExecutor.execute(()-> {
|
||||||
|
try {
|
||||||
|
cancelVoicePrint(voicePrintId);
|
||||||
|
}catch (RuntimeException e) {
|
||||||
|
log.error("删除声纹存在运行时错误原因:{},id:{}", e.getMessage(),voicePrintId);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user