From 736cfc3291764cc28a48a06b47ed5c703d0d62ed Mon Sep 17 00:00:00 2001 From: xueqingkun Date: Wed, 27 Dec 2023 14:08:58 +0800 Subject: [PATCH] =?UTF-8?q?web=20:=20talkByVideo=E6=B7=BB=E5=8A=A0video-ba?= =?UTF-8?q?se64?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../supervision/pojo/vo/TalkResultResVO.java | 3 ++ .../service/impl/AskServiceImpl.java | 36 ++++++++++++++++++- .../src/main/resources/application-dev.yml | 10 ++++-- .../src/main/resources/application-local.yml | 7 ++-- .../src/main/resources/application-prod.yml | 9 ++++- .../src/main/resources/application-test.yml | 9 ++++- .../java/com/supervision/VideoUpdateTest.java | 20 +++++++---- 7 files changed, 79 insertions(+), 15 deletions(-) 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 19ba7ca7..1b242c4d 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 @@ -32,6 +32,9 @@ public class TalkResultResVO { @ApiModelProperty("视频预览URL,本地视频的形式需要") private String videoUrl; + @ApiModelProperty("视频base64位编码") + private String videoBase64; + 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 74e87b21..007c73c3 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 @@ -1,9 +1,12 @@ package com.supervision.service.impl; +import cn.hutool.core.codec.Base64Encoder; +import cn.hutool.core.io.FileUtil; import cn.hutool.core.io.IoUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.crypto.digest.MD5; +import cn.hutool.setting.dialect.Props; import com.supervision.exception.BusinessException; import com.supervision.model.Process; import com.supervision.model.*; @@ -20,6 +23,7 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletResponse; +import java.io.File; import java.io.IOException; import java.io.InputStream; import java.util.List; @@ -42,9 +46,12 @@ public class AskServiceImpl implements AskService { private final FileResourceService fileResourceService; - @Value("${defaultNoMatchId}") + @Value("${answer.defaultNoMatchId}") private String defaultNoMatchId; + @Value("${answer.video.basePath}") + private String videoPath; + @Value("${video-url}") private String videoUrl; @@ -206,6 +213,7 @@ public class AskServiceImpl implements AskService { // 如果rasa没有识别出来,则返回默认值 if (StrUtil.isBlank(rasaResult)) { talkResultResVO.setVideoUrl(videoUrl + defaultNoMatchId); + talkResultResVO.setVideoBase64(getAnswerVideoBase64OrDefault(defaultNoMatchId,null)); saveQaRecord(talkReqVO.getProcessId(), "default", null, talkReqVO.getText(), null, "您好,我没有听懂您说什么"); } @@ -227,6 +235,7 @@ public class AskServiceImpl implements AskService { if (ObjectUtil.isEmpty(library)) { log.info("{}:未从问题库中找到,回答未识别语句", rasaResult); talkResultResVO.setVideoUrl(videoUrl + defaultNoMatchId); + talkResultResVO.setVideoBase64(getAnswerVideoBase64OrDefault(defaultNoMatchId,null)); saveQaRecord(talkReqVO.getProcessId(), "default", null, talkReqVO.getText(), null, "您好,我没有听懂您说什么"); } else { AskPatientAnswer askPatientAnswer = askPatientAnswerService.lambdaQuery().eq(AskPatientAnswer::getMedicalId, process.getMedicalRecId()) @@ -238,6 +247,7 @@ public class AskServiceImpl implements AskService { if (StrUtil.isNotEmpty(library.getDefaultAnswer()) && StrUtil.isNotBlank(library.getDefaultAnswerResourceId())) { String resText = library.getDefaultAnswer(); talkResultResVO.setVideoUrl(videoUrl + library.getDefaultAnswerResourceId()); + talkResultResVO.setVideoBase64(getAnswerVideoBase64OrDefault(library.getDefaultAnswerResourceId(),null)); // 保存记录 saveQaRecord(talkReqVO.getProcessId(), "default", library.getId(), talkReqVO.getText(), library, resText); log.info("{}:找到了默认答案:{}", rasaResult, talkReqVO.getText()); @@ -245,6 +255,7 @@ public class AskServiceImpl implements AskService { log.info("{}:没有从默认答案中找到找到默认内容,回复未识别语句", rasaResult); talkResultResVO.setVideoUrl(videoUrl + (StrUtil.isEmpty(library.getDefaultAnswerResourceId()) ? defaultNoMatchId :library.getDefaultAnswerResourceId())); + talkResultResVO.setVideoBase64(getAnswerVideoBase64OrDefault(library.getDefaultAnswerResourceId(),defaultNoMatchId)); saveQaRecord(talkReqVO.getProcessId(), "default", null, talkReqVO.getText(), library, "您好,我没有听懂您说什么"); } } else { @@ -255,11 +266,13 @@ public class AskServiceImpl implements AskService { log.info("{}:病历配置的回答:{}:为空不为空不为空,但在获取的时候,答案为空,开始回复默认语句,默认语句内容:{}", rasaResult, askPatientAnswer.getId(), resText); // 这里返回视频 talkResultResVO.setVideoUrl(videoUrl + library.getDefaultAnswerResourceId()); + talkResultResVO.setVideoBase64(getAnswerVideoBase64OrDefault(library.getDefaultAnswerResourceId(),defaultNoMatchId)); // 保存记录 saveQaRecord(talkReqVO.getProcessId(), "default", library.getId(), talkReqVO.getText(), library, resText); } else { log.info("{}:病历配置的回答:{}:为空不为空,但在获取的时候,答案为空,但是获取默认语句也为空,那么回复未识别语句", rasaResult, askPatientAnswer.getId()); talkResultResVO.setVideoUrl(videoUrl + defaultNoMatchId); + talkResultResVO.setVideoBase64(getAnswerVideoBase64OrDefault(defaultNoMatchId,null)); saveQaRecord(talkReqVO.getProcessId(), "default", null, talkReqVO.getText(), library, "您好,我没有听懂您说什么"); } @@ -267,6 +280,7 @@ public class AskServiceImpl implements AskService { String resText = askPatientAnswer.getAnswer(); log.info("{}:找到了病历配置的回答语句:{},回答内容:{}", rasaResult, askPatientAnswer.getId(), resText); talkResultResVO.setVideoUrl(videoUrl + askPatientAnswer.getAnswerResourceId()); + talkResultResVO.setVideoBase64(getAnswerVideoBase64OrDefault(askPatientAnswer.getAnswerResourceId(),defaultNoMatchId)); // 保存记录 saveQaRecord(talkReqVO.getProcessId(), "patient", askPatientAnswer.getId(), talkReqVO.getText(), library, resText); } @@ -291,4 +305,24 @@ public class AskServiceImpl implements AskService { throw new BusinessException("未找到回复视频"); } } + + /** + * 获取应答视频的base64位编码 + * @param answerId 应答id + * @param defaultValue 默认应答id + * @return 应答视频base64位编码 + */ + private String getAnswerVideoBase64OrDefault(String answerId, String defaultValue) { + Props props = new Props(videoPath + File.separator + "index"); + String fileName = ""; + if (StrUtil.isNotEmpty(answerId) && StrUtil.isNotEmpty(props.getStr(answerId))){ + fileName = props.getStr(answerId); + }else if (StrUtil.isNotEmpty(defaultValue)){ + fileName = props.getStr(defaultValue); + } + if (StrUtil.isEmpty(fileName)){ + return null; + } + return Base64Encoder.encode(FileUtil.readBytes(videoPath + File.separator + fileName)); + } } diff --git a/virtual-patient-web/src/main/resources/application-dev.yml b/virtual-patient-web/src/main/resources/application-dev.yml index 95f831ce..b9e55e1c 100644 --- a/virtual-patient-web/src/main/resources/application-dev.yml +++ b/virtual-patient-web/src/main/resources/application-dev.yml @@ -83,7 +83,11 @@ ws: # nginx的wss地址(如果是wss的,那么带不带s都可以访问) nginx-ip: 192.168.10.138 nginx-port: 443 -# 对于没有匹配上的缺省回答ID,关联的是vp_file_resource的ID -defaultNoMatchId: 1739173836351885313 +answer: + # 对于没有匹配上的缺省回答ID,关联的是vp_file_resource的ID + defaultNoMatchId: 1739173836351885313 + video: + basePath: /data/vp/video #最后一级不需要加分割符 + # 视频预览,NGINX的地址,https的地址 -video-url: https://124.220.94.55:8025/virtual-patient/ask/downloadTalkVideo?fileResourceId= \ No newline at end of file +video-url: https://124.220.94.55:8025/virtual-patient/ask/downloadTalkVideo?fileResourceId= diff --git a/virtual-patient-web/src/main/resources/application-local.yml b/virtual-patient-web/src/main/resources/application-local.yml index aed64f59..c4b6e172 100644 --- a/virtual-patient-web/src/main/resources/application-local.yml +++ b/virtual-patient-web/src/main/resources/application-local.yml @@ -84,7 +84,10 @@ ws: # nginx的wss地址(如果是wss的,那么带不带s都可以访问) nginx-ip: 192.168.10.138 nginx-port: 443 -# 对于没有匹配上的缺省回答ID,关联的是vp_file_resource的ID -defaultNoMatchId: 1739173836351885313 +answer: + # 对于没有匹配上的缺省回答ID,关联的是vp_file_resource的ID + defaultNoMatchId: 1739173836351885313 + video: + basePath: F:\supervision\doc\数字人视频\final_video\final_video # 视频预览 video-url: http://192.168.10.138:8899/virtual-patient/ask/downloadTalkVideo?fileResourceId= \ No newline at end of file diff --git a/virtual-patient-web/src/main/resources/application-prod.yml b/virtual-patient-web/src/main/resources/application-prod.yml index 0f5ad5ff..37cc4558 100644 --- a/virtual-patient-web/src/main/resources/application-prod.yml +++ b/virtual-patient-web/src/main/resources/application-prod.yml @@ -71,4 +71,11 @@ human: base-url: https://digital-human.jd.com room-id: /getRoomId text-driven: /text_driven - talk-status: /talkStatus \ No newline at end of file + talk-status: /talkStatus +answer: + # 对于没有匹配上的缺省回答ID,关联的是vp_file_resource的ID + defaultNoMatchId: 1739173836351885313 + video: + basePath: /data/vp/video #最后一级不需要加分割符 +# 视频预览,NGINX的地址,https的地址 +video-url: https://124.220.94.55:8025/virtual-patient/ask/downloadTalkVideo?fileResourceId= \ No newline at end of file diff --git a/virtual-patient-web/src/main/resources/application-test.yml b/virtual-patient-web/src/main/resources/application-test.yml index c2e5506b..a6fb34e5 100644 --- a/virtual-patient-web/src/main/resources/application-test.yml +++ b/virtual-patient-web/src/main/resources/application-test.yml @@ -75,4 +75,11 @@ human: ws: # nginx的wss地址(如果是wss的,那么带不带s都可以访问) nginx-ip: 192.168.10.138 - nginx-port: 443 \ No newline at end of file + nginx-port: 443 +answer: + # 对于没有匹配上的缺省回答ID,关联的是vp_file_resource的ID + defaultNoMatchId: 1739173836351885313 + video: + basePath: /data/vp/video #最后一级不需要加分割符 +# 视频预览,NGINX的地址,https的地址 +video-url: https://124.220.94.55:8025/virtual-patient/ask/downloadTalkVideo?fileResourceId= \ No newline at end of file diff --git a/virtual-patient-web/src/test/java/com/supervision/VideoUpdateTest.java b/virtual-patient-web/src/test/java/com/supervision/VideoUpdateTest.java index b21d9c08..351464a7 100644 --- a/virtual-patient-web/src/test/java/com/supervision/VideoUpdateTest.java +++ b/virtual-patient-web/src/test/java/com/supervision/VideoUpdateTest.java @@ -1,6 +1,8 @@ package com.supervision; +import cn.hutool.core.codec.Base64Encoder; import cn.hutool.core.io.FileUtil; +import cn.hutool.setting.dialect.Props; import com.supervision.config.MinioProperties; import com.supervision.model.FileResource; import com.supervision.service.FileResourceService; @@ -15,7 +17,7 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import java.io.BufferedInputStream; -import java.io.File; +import java.io.FileNotFoundException; import java.util.HashMap; import java.util.UUID; @@ -109,16 +111,20 @@ public class VideoUpdateTest { fileResourceService.save(fileResource); fileResource.setId(null); } + } + public static void main(String[] args) throws FileNotFoundException { + long l = System.currentTimeMillis(); + byte[] bytes = FileUtil.readBytes("F:\\supervision\\doc\\数字人视频\\final_video\\final_video\\0.mp4"); + String encode = Base64Encoder.encode(bytes); + long l1 = System.currentTimeMillis() - l; + System.out.println(l1); - - - - - - + Props props = new Props("F:\\supervision\\doc\\数字人视频\\final_video\\final_video\\index"); + Object o = props.get("a"); + System.out.println(o); } }