回复增加本地video接口

dev_2.0.0
liu 1 year ago
parent f85c2a627b
commit 976b33d6e7

@ -13,14 +13,17 @@ import com.supervision.pojo.vo.TalkReqVO;
import com.supervision.pojo.vo.TalkResultResVO;
import com.supervision.service.*;
import com.supervision.util.*;
import io.minio.MinioClient;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;
import java.util.Optional;
@ -40,6 +43,11 @@ public class AskServiceImpl implements AskService {
private final ConfigAncillaryItemService configAncillaryItemService;
private final FileResourceService fileResourceService;
@Value("${defaultNoMatchId}")
private String defaultNoMatchId;
@Override
public String receiveVoiceFile(MultipartFile file) {
@ -195,10 +203,7 @@ public class AskServiceImpl implements AskService {
String rasaResult = RasaUtil.talkRasa(talkReqVO.getText(), UserUtil.getUser().getId(), process.getPatientId());
// 如果rasa没有识别出来,则返回默认值
if (StrUtil.isBlank(rasaResult)) {
// TODO 这里应该返回视频流
String roomId = HumanUtil.queryRoomId(talkReqVO.getRoomKey(), talkReqVO.getRoomToken());
HumanUtil.textDriven("您好,我没有听懂您说什么", roomId);
downloadTalkVideo(defaultNoMatchId,response);
saveQaRecord(talkReqVO.getProcessId(), "default", null, talkReqVO.getText(), null, "您好,我没有听懂您说什么");
}
TalkResultResVO talkResultResVO = new TalkResultResVO();
@ -220,9 +225,7 @@ public class AskServiceImpl implements AskService {
AskTemplateQuestionLibrary library = askTemplateQuestionLibraryService.getById(rasaResult);
if (ObjectUtil.isEmpty(library)) {
log.info("{}:未从问题库中找到,回答未识别语句", rasaResult);
// TODO 这里应该返回视频
HumanUtil.textDriven("您好,我没有听懂您说什么", roomId);
downloadTalkVideo(defaultNoMatchId,response);
saveQaRecord(talkReqVO.getProcessId(), "default", null, talkReqVO.getText(), null, "您好,我没有听懂您说什么");
} else {
AskPatientAnswer askPatientAnswer = askPatientAnswerService.lambdaQuery().eq(AskPatientAnswer::getPatientId, process.getPatientId())
@ -233,9 +236,7 @@ public class AskServiceImpl implements AskService {
// 首先看看default里面是不是存在,如果存在,就从default里面去找
if (StrUtil.isNotEmpty(library.getDefaultAnswer())) {
String resText = library.getDefaultAnswer();
// TODO 这里应该返回视频
HumanUtil.textDriven(resText, roomId);
downloadTalkVideo(defaultNoMatchId,response);
// 保存记录
saveQaRecord(talkReqVO.getProcessId(), "default", library.getId(), talkReqVO.getText(), library, resText);
log.info("{}:找到了默认答案:{}", rasaResult, talkReqVO.getText());
@ -250,21 +251,19 @@ public class AskServiceImpl implements AskService {
if (StrUtil.isNotEmpty(library.getDefaultAnswer())) {
String resText = library.getDefaultAnswer();
log.info("{}:病历配置的回答:{}:为空不为空不为空,但在获取的时候,答案为空,开始回复默认语句,默认语句内容:{}", rasaResult, askPatientAnswer.getId(), resText);
// TODO 这里应该返回视频
HumanUtil.textDriven(resText, roomId);
// 这里返回视频
downloadTalkVideo(library.getDefaultAnswerResourceId(), response);
// 保存记录
saveQaRecord(talkReqVO.getProcessId(), "default", library.getId(), talkReqVO.getText(), library, resText);
} else {
log.info("{}:病历配置的回答:{}:为空不为空,但在获取的时候,答案为空,但是获取默认语句也为空,那么回复未识别语句", rasaResult, askPatientAnswer.getId());
// TODO 这里应该返回视频
HumanUtil.textDriven("您好,我没有听懂您说什么", roomId);
downloadTalkVideo(defaultNoMatchId,response);
}
} else {
String resText = askPatientAnswer.getAnswer();
log.info("{}:找到了病历配置的回答语句:{},回答内容:{}", rasaResult, askPatientAnswer.getId(), resText);
// TODO 这里应该返回视频
HumanUtil.textDriven(resText, roomId);
downloadTalkVideo(askPatientAnswer.getAnswerResourceId(),response);
// 保存记录
saveQaRecord(talkReqVO.getProcessId(), "patient", askPatientAnswer.getId(), talkReqVO.getText(), library, resText);
}
@ -275,7 +274,20 @@ public class AskServiceImpl implements AskService {
talkResultResVO.setType(1);
return talkResultResVO;
// IoUtil.copy(inputStream, response.getOutputStream());
//
// return null;
}
private void downloadTalkVideo(String fileId, HttpServletResponse response) {
FileResource fileResource = fileResourceService.getById(fileId);
if (ObjectUtil.isEmpty(fileResource)) {
throw new BusinessException("未找到回复视频");
}
try (InputStream inputStream = MinioUtil.download(fileResource.getMinioId())) {
IoUtil.copy(inputStream, response.getOutputStream());
} catch (Exception e) {
log.error("获取视频失败", e);
throw new BusinessException("未找到回复视频");
}
}
}

@ -82,4 +82,6 @@ human:
ws:
# nginx的wss地址(如果是wss的,那么带不带s都可以访问)
nginx-ip: 192.168.10.138
nginx-port: 443
nginx-port: 443
# 对于没有匹配上的缺省回答ID,关联的是vp_file_resource的ID
defaultNoMatchId: 1

@ -83,4 +83,6 @@ human:
ws:
# nginx的wss地址(如果是wss的,那么带不带s都可以访问)
nginx-ip: 192.168.10.138
nginx-port: 443
nginx-port: 443
# 对于没有匹配上的缺省回答ID,关联的是vp_file_resource的ID
defaultNoMatchId: 1
Loading…
Cancel
Save