diff --git a/virtual-patient-common/src/main/java/com/supervision/config/WebConfig.java b/virtual-patient-common/src/main/java/com/supervision/config/WebConfig.java index fa9bd682..47f2ceb5 100644 --- a/virtual-patient-common/src/main/java/com/supervision/config/WebConfig.java +++ b/virtual-patient-common/src/main/java/com/supervision/config/WebConfig.java @@ -42,6 +42,7 @@ public class WebConfig implements WebMvcConfigurer { paths.add("/favicon.ico"); paths.add("/user/login"); paths.add("/webSocket/**"); + paths.add("/ask/downloadTalkVideo"); // 开发环境,放开不校验token.每次修改这里需要重启(热部署不行) // paths.add("/**"); return paths; diff --git a/virtual-patient-web/src/main/java/com/supervision/controller/AskController.java b/virtual-patient-web/src/main/java/com/supervision/controller/AskController.java index fcc2d7e7..390ca860 100644 --- a/virtual-patient-web/src/main/java/com/supervision/controller/AskController.java +++ b/virtual-patient-web/src/main/java/com/supervision/controller/AskController.java @@ -37,10 +37,17 @@ public class AskController { @ApiOperation("使用本地视频的形式来做") @PostMapping("/talkByVideo") - public TalkResultResVO talkByVideo(@RequestBody TalkVideoReqVO talkReqVO, HttpServletResponse response) throws IOException { - return askService.talkByVideo(talkReqVO,response); + public TalkResultResVO talkByVideo(@RequestBody TalkVideoReqVO talkReqVO) throws IOException { + return askService.talkByVideo(talkReqVO); } + @ApiOperation("获取本地视频的文件流") + @GetMapping("/downloadTalkVideo") + public void downloadTalkVideo(String fileResourceId, HttpServletResponse response) { + askService.downloadTalkVideo(fileResourceId, response); + response.setContentType("video/mp4"); + } + } diff --git a/virtual-patient-web/src/main/java/com/supervision/pojo/vo/TalkResultResVO.java b/virtual-patient-web/src/main/java/com/supervision/pojo/vo/TalkResultResVO.java index 8ffb27d3..19ba7ca7 100644 --- a/virtual-patient-web/src/main/java/com/supervision/pojo/vo/TalkResultResVO.java +++ b/virtual-patient-web/src/main/java/com/supervision/pojo/vo/TalkResultResVO.java @@ -29,6 +29,10 @@ public class TalkResultResVO { @ApiModelProperty("type='2' 是否需要检查部位 0:否 1:是") private Integer requireLocation; + @ApiModelProperty("视频预览URL,本地视频的形式需要") + private String videoUrl; + + } diff --git a/virtual-patient-web/src/main/java/com/supervision/service/AskService.java b/virtual-patient-web/src/main/java/com/supervision/service/AskService.java index 176584fe..f78516b9 100644 --- a/virtual-patient-web/src/main/java/com/supervision/service/AskService.java +++ b/virtual-patient-web/src/main/java/com/supervision/service/AskService.java @@ -17,7 +17,10 @@ public interface AskService { TalkResultResVO talk(TalkReqVO talkReqVO) throws IOException; - TalkResultResVO talkByVideo(TalkVideoReqVO talkReqVO, HttpServletResponse response) throws IOException; + TalkResultResVO talkByVideo(TalkVideoReqVO talkReqVO) throws IOException; + + + void downloadTalkVideo(String fileResourceId, HttpServletResponse response); } 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 d631f5bf..309021e4 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 @@ -45,6 +45,9 @@ public class AskServiceImpl implements AskService { @Value("${defaultNoMatchId}") private String defaultNoMatchId; + @Value("${video-url}") + private String videoUrl; + @Override public String receiveVoiceFile(MultipartFile file) { @@ -193,18 +196,19 @@ public class AskServiceImpl implements AskService { } @Override - public TalkResultResVO talkByVideo(TalkVideoReqVO talkReqVO, HttpServletResponse response) throws IOException { + public TalkResultResVO talkByVideo(TalkVideoReqVO talkReqVO) throws IOException { // 根据processId找到对应的病人 Process process = Optional.ofNullable(processService.getById(talkReqVO.getProcessId())).orElseThrow(() -> new BusinessException("未找到诊疗进程")); // 调用rasa获取文字内容 String rasaResult = RasaUtil.talkRasa(talkReqVO.getText(), UserUtil.getUser().getId(), process.getPatientId()); - log.info("rasa的回复是:{}",rasaResult); + log.info("rasa的回复是:{}", rasaResult); + TalkResultResVO talkResultResVO = new TalkResultResVO(); // 如果rasa没有识别出来,则返回默认值 if (StrUtil.isBlank(rasaResult)) { - downloadTalkVideo(defaultNoMatchId, response); + talkResultResVO.setVideoUrl(videoUrl + defaultNoMatchId); saveQaRecord(talkReqVO.getProcessId(), "default", null, talkReqVO.getText(), null, "您好,我没有听懂您说什么"); } - TalkResultResVO talkResultResVO = new TalkResultResVO(); + // 这里校验,rasa回复的结果是不是action // 这里设置的模板,对于action的动作全部是用ancillary_ | tool_进行标记,详情看生成rasa的yml的代码:RasaServiceImpl.generateDomain // ancillary_ | tool_ @@ -222,7 +226,7 @@ public class AskServiceImpl implements AskService { AskTemplateQuestionLibrary library = askTemplateQuestionLibraryService.getById(rasaResult); if (ObjectUtil.isEmpty(library)) { log.info("{}:未从问题库中找到,回答未识别语句", rasaResult); - downloadTalkVideo(defaultNoMatchId, response); + talkResultResVO.setVideoUrl(videoUrl + defaultNoMatchId); saveQaRecord(talkReqVO.getProcessId(), "default", null, talkReqVO.getText(), null, "您好,我没有听懂您说什么"); } else { AskPatientAnswer askPatientAnswer = askPatientAnswerService.lambdaQuery().eq(AskPatientAnswer::getPatientId, process.getPatientId()) @@ -233,13 +237,13 @@ public class AskServiceImpl implements AskService { // 首先看看default里面是不是存在,如果存在,就从default里面去找 if (StrUtil.isNotEmpty(library.getDefaultAnswer()) && StrUtil.isNotBlank(library.getDefaultAnswerResourceId())) { String resText = library.getDefaultAnswer(); - downloadTalkVideo(library.getDefaultAnswerResourceId(), response); + talkResultResVO.setVideoUrl(videoUrl + library.getDefaultAnswerResourceId()); // 保存记录 saveQaRecord(talkReqVO.getProcessId(), "default", library.getId(), talkReqVO.getText(), library, resText); log.info("{}:找到了默认答案:{}", rasaResult, talkReqVO.getText()); } else { log.info("{}:没有从默认答案中找到找到默认内容,回复未识别语句", rasaResult); - downloadTalkVideo(library.getDefaultAnswerResourceId(), response); + talkResultResVO.setVideoUrl(videoUrl + library.getDefaultAnswerResourceId()); saveQaRecord(talkReqVO.getProcessId(), "default", null, talkReqVO.getText(), library, "您好,我没有听懂您说什么"); } } else { @@ -249,19 +253,19 @@ public class AskServiceImpl implements AskService { String resText = library.getDefaultAnswer(); log.info("{}:病历配置的回答:{}:为空不为空不为空,但在获取的时候,答案为空,开始回复默认语句,默认语句内容:{}", rasaResult, askPatientAnswer.getId(), resText); // 这里返回视频 - downloadTalkVideo(library.getDefaultAnswerResourceId(), response); + talkResultResVO.setVideoUrl(videoUrl + library.getDefaultAnswerResourceId()); // 保存记录 saveQaRecord(talkReqVO.getProcessId(), "default", library.getId(), talkReqVO.getText(), library, resText); } else { log.info("{}:病历配置的回答:{}:为空不为空,但在获取的时候,答案为空,但是获取默认语句也为空,那么回复未识别语句", rasaResult, askPatientAnswer.getId()); - downloadTalkVideo(defaultNoMatchId, response); + talkResultResVO.setVideoUrl(videoUrl + defaultNoMatchId); saveQaRecord(talkReqVO.getProcessId(), "default", null, talkReqVO.getText(), library, "您好,我没有听懂您说什么"); } } else { String resText = askPatientAnswer.getAnswer(); log.info("{}:找到了病历配置的回答语句:{},回答内容:{}", rasaResult, askPatientAnswer.getId(), resText); - downloadTalkVideo(askPatientAnswer.getAnswerResourceId(), response); + talkResultResVO.setVideoUrl(videoUrl + askPatientAnswer.getAnswerResourceId()); // 保存记录 saveQaRecord(talkReqVO.getProcessId(), "patient", askPatientAnswer.getId(), talkReqVO.getText(), library, resText); } @@ -273,8 +277,9 @@ public class AskServiceImpl implements AskService { return talkResultResVO; } - private void downloadTalkVideo(String fileId, HttpServletResponse response) { - FileResource fileResource = fileResourceService.getById(fileId); + @Override + public void downloadTalkVideo(String fileResourceId, HttpServletResponse response) { + FileResource fileResource = fileResourceService.getById(fileResourceId); if (ObjectUtil.isEmpty(fileResource)) { 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 5ba49b31..10d84831 100644 --- a/virtual-patient-web/src/main/resources/application-dev.yml +++ b/virtual-patient-web/src/main/resources/application-dev.yml @@ -84,4 +84,6 @@ ws: nginx-ip: 192.168.10.138 nginx-port: 443 # 对于没有匹配上的缺省回答ID,关联的是vp_file_resource的ID -defaultNoMatchId: 1739173836351885313 \ No newline at end of file +defaultNoMatchId: 1739173836351885313 +# 视频预览 +video-url: http://192.168.10.138:8899/virtual-patient/ \ 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 46883679..aed64f59 100644 --- a/virtual-patient-web/src/main/resources/application-local.yml +++ b/virtual-patient-web/src/main/resources/application-local.yml @@ -85,4 +85,6 @@ ws: nginx-ip: 192.168.10.138 nginx-port: 443 # 对于没有匹配上的缺省回答ID,关联的是vp_file_resource的ID -defaultNoMatchId: 1739173836351885313 \ No newline at end of file +defaultNoMatchId: 1739173836351885313 +# 视频预览 +video-url: http://192.168.10.138:8899/virtual-patient/ask/downloadTalkVideo?fileResourceId= \ No newline at end of file