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] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E6=8F=90=E4=BA=A4:=E4=B8=8A?=
 =?UTF-8?q?=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);
 
+        }
     }
 }