From 976b33d6e7a7f4031bf259a739e4575c673da2c1 Mon Sep 17 00:00:00 2001 From: liu Date: Mon, 25 Dec 2023 13:52:03 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=9E=E5=A4=8D=E5=A2=9E=E5=8A=A0=E6=9C=AC?= =?UTF-8?q?=E5=9C=B0video=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/AskServiceImpl.java | 46 ++++++++++++------- .../src/main/resources/application-dev.yml | 4 +- .../src/main/resources/application-local.yml | 4 +- 3 files changed, 35 insertions(+), 19 deletions(-) diff --git a/virtual-patient-web/src/main/java/com/supervision/service/impl/AskServiceImpl.java b/virtual-patient-web/src/main/java/com/supervision/service/impl/AskServiceImpl.java index 8f4f17f6..4e1d8e59 100644 --- a/virtual-patient-web/src/main/java/com/supervision/service/impl/AskServiceImpl.java +++ b/virtual-patient-web/src/main/java/com/supervision/service/impl/AskServiceImpl.java @@ -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("未找到回复视频"); + } + } } diff --git a/virtual-patient-web/src/main/resources/application-dev.yml b/virtual-patient-web/src/main/resources/application-dev.yml index e83815c3..08c6b22f 100644 --- a/virtual-patient-web/src/main/resources/application-dev.yml +++ b/virtual-patient-web/src/main/resources/application-dev.yml @@ -82,4 +82,6 @@ human: ws: # nginx的wss地址(如果是wss的,那么带不带s都可以访问) nginx-ip: 192.168.10.138 - nginx-port: 443 \ No newline at end of file + nginx-port: 443 +# 对于没有匹配上的缺省回答ID,关联的是vp_file_resource的ID +defaultNoMatchId: 1 \ No newline at end of file diff --git a/virtual-patient-web/src/main/resources/application-local.yml b/virtual-patient-web/src/main/resources/application-local.yml index 31dca534..d4c0220e 100644 --- a/virtual-patient-web/src/main/resources/application-local.yml +++ b/virtual-patient-web/src/main/resources/application-local.yml @@ -83,4 +83,6 @@ human: ws: # nginx的wss地址(如果是wss的,那么带不带s都可以访问) nginx-ip: 192.168.10.138 - nginx-port: 443 \ No newline at end of file + nginx-port: 443 +# 对于没有匹配上的缺省回答ID,关联的是vp_file_resource的ID +defaultNoMatchId: 1 \ No newline at end of file