From 117c5b0b64d1be0de8c8eae00510a2f5c2664a27 Mon Sep 17 00:00:00 2001
From: liu <liujiatong112@163.com>
Date: Wed, 27 Dec 2023 15:40:35 +0800
Subject: [PATCH 1/4] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E6=8F=90=E4=BA=A4?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 virtual-patient-web/pom.xml                   |  18 +--
 .../src/main/resources/application.yml        |   2 +-
 .../com/supervision/AskTemplateIdTest.java    | 122 ++++++++++++++++++
 3 files changed, 126 insertions(+), 16 deletions(-)
 create mode 100644 virtual-patient-web/src/test/java/com/supervision/AskTemplateIdTest.java

diff --git a/virtual-patient-web/pom.xml b/virtual-patient-web/pom.xml
index 36b2ffbe..52f744b5 100644
--- a/virtual-patient-web/pom.xml
+++ b/virtual-patient-web/pom.xml
@@ -24,6 +24,8 @@
             <version>${project.version}</version>
         </dependency>
 
+
+
         <dependency>
             <groupId>com.supervision</groupId>
             <artifactId>virtual-patient-common</artifactId>
@@ -57,21 +59,7 @@
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-websocket</artifactId>
         </dependency>
-        <dependency>
-            <groupId>org.springframework.boot</groupId>
-            <artifactId>spring-boot-test</artifactId>
-            <scope>test</scope>
-        </dependency>
-        <dependency>
-            <groupId>junit</groupId>
-            <artifactId>junit</artifactId>
-            <scope>test</scope>
-        </dependency>
-        <dependency>
-            <groupId>org.springframework</groupId>
-            <artifactId>spring-test</artifactId>
-            <scope>test</scope>
-        </dependency>
+
         <dependency>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-test</artifactId>
diff --git a/virtual-patient-web/src/main/resources/application.yml b/virtual-patient-web/src/main/resources/application.yml
index caf4dfcd..ef46c2ad 100644
--- a/virtual-patient-web/src/main/resources/application.yml
+++ b/virtual-patient-web/src/main/resources/application.yml
@@ -1,3 +1,3 @@
 spring:
   profiles:
-    active: dev
\ No newline at end of file
+    active: local
\ No newline at end of file
diff --git a/virtual-patient-web/src/test/java/com/supervision/AskTemplateIdTest.java b/virtual-patient-web/src/test/java/com/supervision/AskTemplateIdTest.java
new file mode 100644
index 00000000..b6bb1eec
--- /dev/null
+++ b/virtual-patient-web/src/test/java/com/supervision/AskTemplateIdTest.java
@@ -0,0 +1,122 @@
+package com.supervision;
+
+import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.util.ArrayUtil;
+import cn.hutool.core.util.ObjectUtil;
+import cn.hutool.core.util.ReUtil;
+import cn.hutool.core.util.StrUtil;
+import cn.hutool.http.HttpUtil;
+import cn.hutool.json.JSON;
+import cn.hutool.json.JSONArray;
+import cn.hutool.json.JSONObject;
+import cn.hutool.json.JSONUtil;
+import cn.hutool.poi.excel.ExcelReader;
+import cn.hutool.poi.excel.ExcelUtil;
+import com.baomidou.mybatisplus.core.incrementer.DefaultIdentifierGenerator;
+import com.supervision.model.AskPatientAnswer;
+import com.supervision.model.AskTemplateQuestionLibrary;
+import com.supervision.model.CommonDic;
+import com.supervision.service.AskPatientAnswerService;
+import com.supervision.service.AskTemplateQuestionLibraryService;
+import com.supervision.service.CommonDicService;
+import lombok.extern.slf4j.Slf4j;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@Slf4j
+@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
+@RunWith(SpringJUnit4ClassRunner.class)
+public class AskTemplateIdTest {
+
+    @Autowired
+    private AskTemplateQuestionLibraryService askTemplateQuestionLibraryService;
+
+    @Autowired
+    private AskPatientAnswerService askPatientAnswerService;
+
+    @Autowired
+    private CommonDicService commonDicService;
+
+    @Test
+    public void creatAskId() {
+        Object o = new Object();
+        DefaultIdentifierGenerator defaultIdentifierGenerator = new DefaultIdentifierGenerator();
+
+        List<AskTemplateQuestionLibrary> list = askTemplateQuestionLibraryService.list();
+        for (AskTemplateQuestionLibrary askTemplateQuestionLibrary : list) {
+            askTemplateQuestionLibraryService.lambdaUpdate()
+                    .set(AskTemplateQuestionLibrary::getId, String.valueOf(defaultIdentifierGenerator.nextId(o)))
+                    .eq(AskTemplateQuestionLibrary::getId, askTemplateQuestionLibrary.getId()).update();
+        }
+    }
+
+    @Test
+    public void creatAnswerId() {
+        Object o = new Object();
+        DefaultIdentifierGenerator defaultIdentifierGenerator = new DefaultIdentifierGenerator();
+
+        List<AskPatientAnswer> list = askPatientAnswerService.list();
+        for (AskPatientAnswer answer : list) {
+            askPatientAnswerService.lambdaUpdate()
+                    .set(AskPatientAnswer::getId, String.valueOf(defaultIdentifierGenerator.nextId(o)))
+                    .eq(AskPatientAnswer::getId, answer.getId()).update();
+        }
+    }
+
+    @Test
+    public void insertDict() {
+        ExcelReader reader = ExcelUtil.getReader("/Users/flevance/Desktop/虚拟病人/语料库/标准病人语料1226-2.xlsx");
+        List<List<Object>> read = reader.read(1, 86);
+        for (List<Object> objects : read) {
+            String pathOne = String.valueOf(objects.get(0));
+            String pathTwo = String.valueOf(objects.get(1));
+            CommonDic dic = commonDicService.lambdaQuery().eq(CommonDic::getNameZhPath, pathOne + "/" + pathTwo).last("limit 1").one();
+            if (ObjectUtil.isNotEmpty(dic)) {
+                String code = String.valueOf(objects.get(5));
+                askTemplateQuestionLibraryService.lambdaUpdate().set(AskTemplateQuestionLibrary::getDictId, dic.getId())
+                        .eq(AskTemplateQuestionLibrary::getCode, code).update();
+            }
+        }
+    }
+
+    @Test
+    public void generateQuestion() {
+        // 使用文心一言,这里是付费的,不要随便用哦,注意数量
+        String post = HttpUtil.get("https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=8VdV7Hm4ZmPVzRovCQXaH8nN&client_secret=Bte6UKtrexydMuhWrbqciolzYzS8rEYm");
+        System.out.println(post);
+        JSONObject parse = JSONUtil.parseObj(post);
+        String accessToken = parse.getStr("access_token");
+
+        List<AskTemplateQuestionLibrary> list = askTemplateQuestionLibraryService.list();
+        for (AskTemplateQuestionLibrary ask : list) {
+            try {
+                String description = ask.getDescription();
+                Map<String, Object> map = new HashMap<>();
+                map.put("role", "user");
+                map.put("content", "请把下面这句话以20种不同的方式提问,以JSONARRAY的形式输出:" + description);
+                HashMap<String, Object> param = new HashMap<>();
+                param.put("messages", CollUtil.newArrayList(map));
+                String askAnswer = HttpUtil.post("https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/completions_pro?access_token=" + accessToken, JSONUtil.toJsonStr(param));
+                JSONObject answerJSON = JSONUtil.parseObj(askAnswer);
+                String result = answerJSON.getStr("result");
+                String s = ReUtil.get("\\[(.*?)\\]", result, 0);
+                List<String> question = JSONUtil.toList(s, String.class);
+                question.add(0, description);
+                askTemplateQuestionLibraryService.lambdaUpdate().set(AskTemplateQuestionLibrary::getQuestion, JSONUtil.toJsonStr(question)).eq(AskTemplateQuestionLibrary::getId, ask.getId()).update();
+            } catch (Exception e) {
+                log.error("{}生成错误", ask.getDescription(), e);
+            }
+
+        }
+
+    }
+
+
+}

From 7eadb12c2c8d3e04c6159af5c2e78d2caff8c309 Mon Sep 17 00:00:00 2001
From: liu <liujiatong112@163.com>
Date: Wed, 27 Dec 2023 15:52:15 +0800
Subject: [PATCH 2/4] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E6=8F=90=E4=BA=A4:?=
 =?UTF-8?q?=E9=BB=98=E8=AE=A4=E8=A7=86=E9=A2=91?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../supervision/controller/AskController.java |  7 --
 .../supervision/pojo/vo/TalkResultResVO.java  |  3 -
 .../com/supervision/service/AskService.java   |  2 -
 .../service/impl/AskServiceImpl.java          | 68 ++++++-------------
 .../src/main/resources/application-dev.yml    |  5 --
 .../src/main/resources/application-local.yml  |  6 +-
 .../src/main/resources/application-prod.yml   |  6 +-
 .../src/main/resources/application-test.yml   |  6 +-
 8 files changed, 25 insertions(+), 78 deletions(-)

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 390ca860..62d2ce2d 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
@@ -42,12 +42,5 @@ public class AskController {
     }
 
 
-    @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 1b242c4d..f105bfac 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,9 +29,6 @@ public class TalkResultResVO {
     @ApiModelProperty("type='2' 是否需要检查部位 0:否 1:是")
     private Integer requireLocation;
 
-    @ApiModelProperty("视频预览URL,本地视频的形式需要")
-    private String videoUrl;
-
     @ApiModelProperty("视频base64位编码")
     private String videoBase64;
 
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 f78516b9..aec660f6 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
@@ -20,7 +20,5 @@ public interface AskService {
     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 007c73c3..780045df 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
@@ -49,13 +49,6 @@ public class AskServiceImpl implements AskService {
     @Value("${answer.defaultNoMatchId}")
     private String defaultNoMatchId;
 
-    @Value("${answer.video.basePath}")
-    private String videoPath;
-
-    @Value("${video-url}")
-    private String videoUrl;
-
-
     @Override
     public String receiveVoiceFile(MultipartFile file) {
         if (file.getSize() <= 0) {
@@ -203,7 +196,7 @@ public class AskServiceImpl implements AskService {
     }
 
     @Override
-    public TalkResultResVO talkByVideo(TalkVideoReqVO talkReqVO) throws IOException {
+    public TalkResultResVO talkByVideo(TalkVideoReqVO talkReqVO) {
         // 根据processId找到对应的病人
         Process process = Optional.ofNullable(processService.getById(talkReqVO.getProcessId())).orElseThrow(() -> new BusinessException("未找到诊疗进程"));
         // 调用rasa获取文字内容
@@ -212,8 +205,7 @@ public class AskServiceImpl implements AskService {
         TalkResultResVO talkResultResVO = new TalkResultResVO();
         // 如果rasa没有识别出来,则返回默认值
         if (StrUtil.isBlank(rasaResult)) {
-            talkResultResVO.setVideoUrl(videoUrl + defaultNoMatchId);
-            talkResultResVO.setVideoBase64(getAnswerVideoBase64OrDefault(defaultNoMatchId,null));
+            talkResultResVO.setVideoBase64(getAnswerVideoBase64OrDefault(defaultNoMatchId));
             saveQaRecord(talkReqVO.getProcessId(), "default", null, talkReqVO.getText(), null, "您好,我没有听懂您说什么");
         }
 
@@ -234,8 +226,7 @@ public class AskServiceImpl implements AskService {
             AskTemplateQuestionLibrary library = askTemplateQuestionLibraryService.getById(rasaResult);
             if (ObjectUtil.isEmpty(library)) {
                 log.info("{}:未从问题库中找到,回答未识别语句", rasaResult);
-                talkResultResVO.setVideoUrl(videoUrl + defaultNoMatchId);
-                talkResultResVO.setVideoBase64(getAnswerVideoBase64OrDefault(defaultNoMatchId,null));
+                talkResultResVO.setVideoBase64(getAnswerVideoBase64OrDefault(defaultNoMatchId));
                 saveQaRecord(talkReqVO.getProcessId(), "default", null, talkReqVO.getText(), null, "您好,我没有听懂您说什么");
             } else {
                 AskPatientAnswer askPatientAnswer = askPatientAnswerService.lambdaQuery().eq(AskPatientAnswer::getMedicalId, process.getMedicalRecId())
@@ -246,16 +237,13 @@ public class AskServiceImpl implements AskService {
                     // 首先看看default里面是不是存在,如果存在,就从default里面去找
                     if (StrUtil.isNotEmpty(library.getDefaultAnswer()) && StrUtil.isNotBlank(library.getDefaultAnswerResourceId())) {
                         String resText = library.getDefaultAnswer();
-                        talkResultResVO.setVideoUrl(videoUrl + library.getDefaultAnswerResourceId());
-                        talkResultResVO.setVideoBase64(getAnswerVideoBase64OrDefault(library.getDefaultAnswerResourceId(),null));
+                        talkResultResVO.setVideoBase64(getAnswerVideoBase64OrDefault(library.getDefaultAnswerResourceId()));
                         // 保存记录
                         saveQaRecord(talkReqVO.getProcessId(), "default", library.getId(), talkReqVO.getText(), library, resText);
                         log.info("{}:找到了默认答案:{}", rasaResult, talkReqVO.getText());
                     } else {
                         log.info("{}:没有从默认答案中找到找到默认内容,回复未识别语句", rasaResult);
-                        talkResultResVO.setVideoUrl(videoUrl + (StrUtil.isEmpty(library.getDefaultAnswerResourceId()) ? defaultNoMatchId
-                                :library.getDefaultAnswerResourceId()));
-                        talkResultResVO.setVideoBase64(getAnswerVideoBase64OrDefault(library.getDefaultAnswerResourceId(),defaultNoMatchId));
+                        talkResultResVO.setVideoBase64(getAnswerVideoBase64OrDefault(library.getDefaultAnswerResourceId()));
                         saveQaRecord(talkReqVO.getProcessId(), "default", null, talkReqVO.getText(), library, "您好,我没有听懂您说什么");
                     }
                 } else {
@@ -265,22 +253,19 @@ public class AskServiceImpl implements AskService {
                             String resText = library.getDefaultAnswer();
                             log.info("{}:病历配置的回答:{}:为空不为空不为空,但在获取的时候,答案为空,开始回复默认语句,默认语句内容:{}", rasaResult, askPatientAnswer.getId(), resText);
                             //  这里返回视频
-                            talkResultResVO.setVideoUrl(videoUrl + library.getDefaultAnswerResourceId());
-                            talkResultResVO.setVideoBase64(getAnswerVideoBase64OrDefault(library.getDefaultAnswerResourceId(),defaultNoMatchId));
+                            talkResultResVO.setVideoBase64(getAnswerVideoBase64OrDefault(library.getDefaultAnswerResourceId()));
                             // 保存记录
                             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));
+                            talkResultResVO.setVideoBase64(getAnswerVideoBase64OrDefault(defaultNoMatchId));
                             saveQaRecord(talkReqVO.getProcessId(), "default", null, talkReqVO.getText(), library, "您好,我没有听懂您说什么");
                         }
 
                     } else {
                         String resText = askPatientAnswer.getAnswer();
                         log.info("{}:找到了病历配置的回答语句:{},回答内容:{}", rasaResult, askPatientAnswer.getId(), resText);
-                        talkResultResVO.setVideoUrl(videoUrl + askPatientAnswer.getAnswerResourceId());
-                        talkResultResVO.setVideoBase64(getAnswerVideoBase64OrDefault(askPatientAnswer.getAnswerResourceId(),defaultNoMatchId));
+                        talkResultResVO.setVideoBase64(getAnswerVideoBase64OrDefault(askPatientAnswer.getAnswerResourceId()));
                         // 保存记录
                         saveQaRecord(talkReqVO.getProcessId(), "patient", askPatientAnswer.getId(), talkReqVO.getText(), library, resText);
                     }
@@ -292,37 +277,28 @@ public class AskServiceImpl implements AskService {
         return talkResultResVO;
     }
 
-    @Override
-    public void downloadTalkVideo(String fileResourceId, HttpServletResponse response) {
+
+    /**
+     * 获取应答视频的base64位编码
+     *
+     * @param fileResourceId 应答id
+     * @return 应答视频base64位编码
+     */
+    private String getAnswerVideoBase64OrDefault(String fileResourceId) {
+        if (StrUtil.isBlank(fileResourceId)) {
+            fileResourceId = defaultNoMatchId;
+        }
         FileResource fileResource = fileResourceService.getById(fileResourceId);
         if (ObjectUtil.isEmpty(fileResource)) {
-            throw new BusinessException("未找到回复视频");
+            log.info("未找到视频,走默认视频");
+            fileResource = fileResourceService.getById(defaultNoMatchId);
         }
         try (InputStream inputStream = MinioUtil.download(fileResource.getMinioId())) {
-            IoUtil.copy(inputStream, response.getOutputStream());
+            return Base64Encoder.encode(IoUtil.readBytes(inputStream));
         } catch (Exception e) {
             log.error("获取视频失败", e);
             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 b9e55e1c..1a47548f 100644
--- a/virtual-patient-web/src/main/resources/application-dev.yml
+++ b/virtual-patient-web/src/main/resources/application-dev.yml
@@ -86,8 +86,3 @@ ws:
 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=
diff --git a/virtual-patient-web/src/main/resources/application-local.yml b/virtual-patient-web/src/main/resources/application-local.yml
index c4b6e172..25d1290e 100644
--- a/virtual-patient-web/src/main/resources/application-local.yml
+++ b/virtual-patient-web/src/main/resources/application-local.yml
@@ -86,8 +86,4 @@ ws:
   nginx-port: 443
 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
+  defaultNoMatchId: 1739173836351885313
\ 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 37cc4558..363e4912 100644
--- a/virtual-patient-web/src/main/resources/application-prod.yml
+++ b/virtual-patient-web/src/main/resources/application-prod.yml
@@ -74,8 +74,4 @@ human:
   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
+  defaultNoMatchId: 1739173836351885313
\ 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 a6fb34e5..9994adfa 100644
--- a/virtual-patient-web/src/main/resources/application-test.yml
+++ b/virtual-patient-web/src/main/resources/application-test.yml
@@ -78,8 +78,4 @@ ws:
   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
+  defaultNoMatchId: 1739173836351885313
\ No newline at end of file

From 70d20b1ac0ceb8ecd9d6f22083efa44e599b635d Mon Sep 17 00:00:00 2001
From: liu <liujiatong112@163.com>
Date: Wed, 27 Dec 2023 15:53:29 +0800
Subject: [PATCH 3/4] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E6=8F=90=E4=BA=A4:?=
 =?UTF-8?q?=E4=BF=AE=E6=94=B9minio=E4=B8=BAtest=E7=9A=84bucket?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 virtual-patient-web/src/main/resources/application-test.yml | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/virtual-patient-web/src/main/resources/application-test.yml b/virtual-patient-web/src/main/resources/application-test.yml
index 9994adfa..3ac82c03 100644
--- a/virtual-patient-web/src/main/resources/application-test.yml
+++ b/virtual-patient-web/src/main/resources/application-test.yml
@@ -52,6 +52,12 @@ spring:
     port: 6379
     password: 123456
 
+minio:
+  url: http://192.168.10.138:9002
+  accessKey: admin
+  secretKey: 12345678
+  bucketName: virtual-patient-bucket-test
+
 mybatis-plus:
   mapper-locations: classpath*:mapper/**/*.xml
   configuration:

From 6768578a16c579491f87107b577b12fe051a0c8b Mon Sep 17 00:00:00 2001
From: liu <liujiatong112@163.com>
Date: Wed, 27 Dec 2023 16:14:23 +0800
Subject: [PATCH 4/4] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E6=8F=90=E4=BA=A4:?=
 =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E8=A7=86=E9=A2=91?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../java/com/supervision/util/MinioUtil.java  |   2 +-
 .../supervision/model/AskPatientAnswer.java   |   2 +
 .../model/AskTemplateQuestionLibrary.java     |   2 +
 .../com/supervision/model/FileResource.java   |   4 +-
 .../mapper/AskPatientAnswerMapper.xml         |   3 +-
 .../AskTemplateQuestionLibraryMapper.xml      |   3 +-
 .../src/main/resources/application-test.yml   |   1 +
 .../src/main/resources/application.yml        |   2 +-
 .../src/main/resources/logback-spring.xml     |   2 +-
 .../java/com/supervision/VideoUpdateTest.java | 155 +++++++-----------
 10 files changed, 75 insertions(+), 101 deletions(-)

diff --git a/virtual-patient-common/src/main/java/com/supervision/util/MinioUtil.java b/virtual-patient-common/src/main/java/com/supervision/util/MinioUtil.java
index e24fd1a3..69566704 100644
--- a/virtual-patient-common/src/main/java/com/supervision/util/MinioUtil.java
+++ b/virtual-patient-common/src/main/java/com/supervision/util/MinioUtil.java
@@ -30,7 +30,7 @@ public class MinioUtil {
      * 上传一个文件
      */
     public static String uploadFile(InputStream stream, String objectName) throws Exception {
-        ObjectWriteResponse objectWriteResponse = minioClient.putObject(PutObjectArgs.builder().bucket(bucketName).object(objectName).contentType("video/mp4")
+        ObjectWriteResponse objectWriteResponse = minioClient.putObject(PutObjectArgs.builder().bucket(bucketName).object(objectName)
                 .stream(stream, -1, 10485760).build());
         return objectWriteResponse.object();
     }
diff --git a/virtual-patient-model/src/main/java/com/supervision/model/AskPatientAnswer.java b/virtual-patient-model/src/main/java/com/supervision/model/AskPatientAnswer.java
index 82dce8ab..4630b92a 100644
--- a/virtual-patient-model/src/main/java/com/supervision/model/AskPatientAnswer.java
+++ b/virtual-patient-model/src/main/java/com/supervision/model/AskPatientAnswer.java
@@ -36,6 +36,8 @@ public class AskPatientAnswer extends Model<AskPatientAnswer> implements Seriali
     @ApiModelProperty(" 问题库问题ID")
     private String libraryQuestionId;
 
+    private String code;
+
     /**
      * 回答
      */
diff --git a/virtual-patient-model/src/main/java/com/supervision/model/AskTemplateQuestionLibrary.java b/virtual-patient-model/src/main/java/com/supervision/model/AskTemplateQuestionLibrary.java
index 77930c22..c9da6594 100644
--- a/virtual-patient-model/src/main/java/com/supervision/model/AskTemplateQuestionLibrary.java
+++ b/virtual-patient-model/src/main/java/com/supervision/model/AskTemplateQuestionLibrary.java
@@ -50,6 +50,8 @@ public class AskTemplateQuestionLibrary implements Serializable {
      */
     private String defaultAnswer;
 
+    private String defaultAnswerCode;
+
     private String defaultAnswerResourceId;
 
     /**
diff --git a/virtual-patient-model/src/main/java/com/supervision/model/FileResource.java b/virtual-patient-model/src/main/java/com/supervision/model/FileResource.java
index 2c2b1620..4fbb5842 100644
--- a/virtual-patient-model/src/main/java/com/supervision/model/FileResource.java
+++ b/virtual-patient-model/src/main/java/com/supervision/model/FileResource.java
@@ -6,6 +6,8 @@ import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
 import java.io.Serializable;
 import java.time.LocalDateTime;
+
+import com.baomidou.mybatisplus.extension.activerecord.Model;
 import lombok.Data;
 
 /**
@@ -14,7 +16,7 @@ import lombok.Data;
  */
 @TableName(value ="vp_file_resource")
 @Data
-public class FileResource implements Serializable {
+public class FileResource extends Model<FileResource> implements Serializable {
     /**
      * 主键id
      */
diff --git a/virtual-patient-model/src/main/resources/mapper/AskPatientAnswerMapper.xml b/virtual-patient-model/src/main/resources/mapper/AskPatientAnswerMapper.xml
index ba972fbb..4b6a2418 100644
--- a/virtual-patient-model/src/main/resources/mapper/AskPatientAnswerMapper.xml
+++ b/virtual-patient-model/src/main/resources/mapper/AskPatientAnswerMapper.xml
@@ -9,6 +9,7 @@
             <result property="medicalId" column="medical_id" jdbcType="VARCHAR"/>
             <result property="libraryQuestionId" column="library_question_id" jdbcType="VARCHAR"/>
             <result property="answer" column="answer" jdbcType="VARCHAR"/>
+            <result property="code" column="code" jdbcType="VARCHAR"/>
             <result property="answerResourceId" column="answer_resources_id" jdbcType="VARCHAR"/>
             <result property="createUserId" column="create_user_id" jdbcType="VARCHAR"/>
             <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
@@ -17,7 +18,7 @@
     </resultMap>
 
     <sql id="Base_Column_List">
-        id,medical_id,library_question_id,
+        id,medical_id,library_question_id,code,
         answer,answer_resources_id,create_user_id,
         create_time,update_user_id,update_time
     </sql>
diff --git a/virtual-patient-model/src/main/resources/mapper/AskTemplateQuestionLibraryMapper.xml b/virtual-patient-model/src/main/resources/mapper/AskTemplateQuestionLibraryMapper.xml
index 921b6c16..6e7985c0 100644
--- a/virtual-patient-model/src/main/resources/mapper/AskTemplateQuestionLibraryMapper.xml
+++ b/virtual-patient-model/src/main/resources/mapper/AskTemplateQuestionLibraryMapper.xml
@@ -12,6 +12,7 @@
         <result property="question" column="question" jdbcType="ARRAY"
                 typeHandler="com.supervision.handler.StringListTypeHandler"/>
         <result property="defaultAnswer" column="default_answer" jdbcType="VARCHAR"/>
+        <result property="defaultAnswerCode" column="default_answer_code" jdbcType="VARCHAR"/>
         <result property="defaultAnswerResourceId" column="default_answer_resources_id" jdbcType="VARCHAR"/>
         <result property="createUserId" column="create_user_id" jdbcType="VARCHAR"/>
         <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
@@ -22,7 +23,7 @@
     <sql id="Base_Column_List">
         id
         ,dict_id,code,description,
-        question,default_answer,default_answer_resources_id,create_user_id,
+        question,default_answer,default_answer_code,default_answer_resources_id,create_user_id,
         create_time,update_user_id,update_time
     </sql>
 
diff --git a/virtual-patient-web/src/main/resources/application-test.yml b/virtual-patient-web/src/main/resources/application-test.yml
index 3ac82c03..e9c747f9 100644
--- a/virtual-patient-web/src/main/resources/application-test.yml
+++ b/virtual-patient-web/src/main/resources/application-test.yml
@@ -78,6 +78,7 @@ human:
   room-id: /getRoomId
   text-driven: /text_driven
   talk-status: /talkStatus
+  resourceMaxNumber: 5
 ws:
   # nginx的wss地址(如果是wss的,那么带不带s都可以访问)
   nginx-ip: 192.168.10.138
diff --git a/virtual-patient-web/src/main/resources/application.yml b/virtual-patient-web/src/main/resources/application.yml
index ef46c2ad..027b4e36 100644
--- a/virtual-patient-web/src/main/resources/application.yml
+++ b/virtual-patient-web/src/main/resources/application.yml
@@ -1,3 +1,3 @@
 spring:
   profiles:
-    active: local
\ No newline at end of file
+    active: test
\ No newline at end of file
diff --git a/virtual-patient-web/src/main/resources/logback-spring.xml b/virtual-patient-web/src/main/resources/logback-spring.xml
index b1835f87..f9110b42 100644
--- a/virtual-patient-web/src/main/resources/logback-spring.xml
+++ b/virtual-patient-web/src/main/resources/logback-spring.xml
@@ -13,7 +13,7 @@
     </springProfile>
 
     <!-- 测试环境,生产环境 -->
-    <springProfile name="test,prod">
+    <springProfile name="prod">
         <logger name="org.springframework.web" level="INFO"/>
         <logger name="org.springboot.sample" level="INFO"/>
         <logger name="com.supervision" level="INFO"/>
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 351464a7..ad1ed778 100644
--- a/virtual-patient-web/src/test/java/com/supervision/VideoUpdateTest.java
+++ b/virtual-patient-web/src/test/java/com/supervision/VideoUpdateTest.java
@@ -1,15 +1,15 @@
 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 cn.hutool.core.io.file.PathUtil;
+import com.supervision.model.AskPatientAnswer;
+import com.supervision.model.AskTemplateQuestionLibrary;
 import com.supervision.model.FileResource;
+import com.supervision.service.AskPatientAnswerService;
+import com.supervision.service.AskTemplateQuestionLibraryService;
 import com.supervision.service.FileResourceService;
 import com.supervision.util.MinioUtil;
-import io.minio.MinioClient;
-import io.minio.StatObjectArgs;
-import io.minio.StatObjectResponse;
+import lombok.extern.slf4j.Slf4j;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -17,11 +17,10 @@ import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
 
 import java.io.BufferedInputStream;
-import java.io.FileNotFoundException;
-import java.util.HashMap;
-import java.util.UUID;
-
+import java.io.File;
+import java.util.List;
 
+@Slf4j
 @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
 @RunWith(SpringJUnit4ClassRunner.class)
 public class VideoUpdateTest {
@@ -30,101 +29,67 @@ public class VideoUpdateTest {
     private FileResourceService fileResourceService;
 
     @Autowired
-    private MinioProperties minioProperties;
+    private AskTemplateQuestionLibraryService askTemplateQuestionLibraryService;
 
     @Autowired
-    private MinioClient minioClient;
-    @Test
-  public   void contextLoads() throws Exception {
-
-
-        String m = "1 你好,医生\n" +
-                "2 我最近感觉心跳特别快,喘不上气。\n" +
-                "3 感觉心跳特别快,喘不上气,活动后更严重\n" +
-                "4 比较严重\n" +
-                "5 觉得手抖、怕热,容易出汗,胃口很好,吃很多还总觉得饿,紧张,特别容易发脾气,还拉肚子,瘦了一些\n" +
-                "6 最近半年吧\n" +
-                "7 夏天很怕热,晚上也会睡不着\n" +
-                "8 活动后会加重,双腿还会没劲\n" +
-                "9 影响到我的工作和生活了\n" +
-                "10 没有注意到\n" +
-                "11 我不知道\n" +
-                "12 头痛,发烧\n" +
-                "13 感觉是全头疼\n" +
-                "14 基本上天天出现\n" +
-                "15 似乎是比之前掉的多了\n" +
-                "16 是的,我每天大约3次稀便\n" +
-                "17 之前没有\n" +
-                "18 体力好像比之前差了一些,最近这些天我经常喘不过气来,并且活动后感觉双腿乏力,感觉到非常虚弱\n" +
-                "19 没有\n" +
-                "20 之前身体很好,没吃过什么药\n" +
-                "21 胃口很好,总感觉饿\n" +
-                "22 主要是尿多,口干,喝水也多\n" +
-                "23 大约有三个月\n" +
-                "24 老是觉得饿,比以前吃得多,人反而瘦了\n" +
-                "25 是的\n" +
-                "26 次数多了,特别是晚上,以前从来不起夜,现在要起来3、4次\n" +
-                "27 3个月,瘦了7kg\n" +
-                "28 没有了\n" +
-                "29 还可以\n" +
-                "30 5年前得过胆结石,把胆囊切掉了。\n" +
-                "31 一直都比较正常。\n" +
-                "32 有,对青霉素过敏。\n" +
-                "33 是高中时,因扁桃体化脓,医生本来要给用青霉素,但做了皮试是阳性。\n" +
-                "34 应该做过,记不清了。\n" +
-                "35 喜欢抽烟,10多年了,每天1包\n" +
-                "36 我母亲身体不太好,50岁得时候体检发现有糖尿病,一直在吃药。\n" +
-                "37 天气寒冷时酸痛症状可加重,热敷可缓解\n" +
-                "38 正常\n" +
-                "39 腹部偶尔也会觉得疼痛\n" +
-                "40 说不清楚\n" +
-                "41 正常不闷,晚上睡觉向左侧睡,左胸有时闷。\n" +
-                "42 没有,有时过饱有胀满感觉\n";
-        String[] split = m.split("\n");
-
-        HashMap<Integer, String> codeMap = new HashMap<>();
-
-        for (int i = 0; i < split.length; i++) {
-            String s = split[i];
-            String[] split1 = s.split(" ");
-            System.out.println("---" + split1[0] +"----"+split1[1]);
-            codeMap.put(Integer.valueOf(split1[0]),split1[1]);
-        }
-
-
-        // 读取文件 0-41
-        // 读取文件名 1-42
-        FileResource fileResource = new FileResource();
-        fileResource.setFileType("mp4");
+    private AskPatientAnswerService askPatientAnswerService;
 
-        for (int i = 0; i < 42; i++) {
-            fileResource.setFileName(codeMap.get(i+1));
-            fileResource.setMinioId(UUID.randomUUID().toString());
-            BufferedInputStream inputStream = FileUtil.getInputStream("F:\\supervision\\doc\\数字人视频\\final_video\\final_video\\"+i+".mp4");
-            MinioUtil.uploadFile(inputStream, fileResource.getMinioId());
 
-            System.out.println("---------------------上传文件:"+fileResource.getFileName());
+    @Test
+    public void saveDefaultAnswerVideo() throws Exception {
+        String filePath = "/Users/flevance/Desktop/虚拟病人/语料库/video_texts/";
+        List<AskTemplateQuestionLibrary> list = askTemplateQuestionLibraryService.list();
+        for (AskTemplateQuestionLibrary library : list) {
+            String defaultAnswerCode = library.getDefaultAnswerCode();
+            File file = FileUtil.file(filePath + defaultAnswerCode + ".mp4");
+            if (FileUtil.exist(file)) {
+                FileResource fileResource = new FileResource();
+
+                fileResource.setFileName(FileUtil.getName(file));
+                fileResource.setFileType(FileUtil.getType(file));
+
+                BufferedInputStream inputStream = FileUtil.getInputStream(file);
+                fileResource.setFileSize(inputStream.available());
+                String minioId = MinioUtil.uploadFile(inputStream, defaultAnswerCode);
+                fileResource.setMinioId(minioId);
+                fileResource.insert();
+                askTemplateQuestionLibraryService.lambdaUpdate()
+                        .set(AskTemplateQuestionLibrary::getDefaultAnswerResourceId, fileResource.getId())
+                        .eq(AskTemplateQuestionLibrary::getId, library.getId()).update();
+            } else {
+                log.info("视频不存在:{}", defaultAnswerCode);
+            }
 
-            StatObjectResponse response = minioClient.statObject(StatObjectArgs.builder().bucket(minioProperties.getBucketName()).object(fileResource.getMinioId()).build());
-            fileResource.setFileSize(Integer.valueOf(String.valueOf(response.size())));
 
-            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);
+    @Test
+    public void saveDiseaseVideo() throws Exception {
+        String filePath = "/Users/flevance/Desktop/虚拟病人/语料库/video_texts/";
+        List<AskPatientAnswer> list = askPatientAnswerService.list();
+        for (AskPatientAnswer answer : list) {
+            String code = answer.getCode();
+            File file = FileUtil.file(filePath + code.replace("-", "") + ".mp4");
+            if (FileUtil.exist(file)) {
+                FileResource fileResource = new FileResource();
+
+                fileResource.setFileName(FileUtil.getName(file));
+                fileResource.setFileType(FileUtil.getType(file));
+
+                BufferedInputStream inputStream = FileUtil.getInputStream(file);
+                fileResource.setFileSize(inputStream.available());
+                String minioId = MinioUtil.uploadFile(inputStream, code);
+                fileResource.setMinioId(minioId);
+                fileResource.insert();
+                askPatientAnswerService.lambdaUpdate()
+                        .set(AskPatientAnswer::getAnswerResourceId, fileResource.getId())
+                        .eq(AskPatientAnswer::getId, answer.getId()).update();
+            } else {
+                log.info("视频不存在:{}", code);
+            }
 
-        Props props = new Props("F:\\supervision\\doc\\数字人视频\\final_video\\final_video\\index");
-        Object o = props.get("a");
-        System.out.println(o);
 
+        }
     }
 }