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 69566704..e24fd1a3 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) + ObjectWriteResponse objectWriteResponse = minioClient.putObject(PutObjectArgs.builder().bucket(bucketName).object(objectName).contentType("video/mp4") .stream(stream, -1, 10485760).build()); return objectWriteResponse.object(); } diff --git a/virtual-patient-web/pom.xml b/virtual-patient-web/pom.xml index 4830043f..36b2ffbe 100644 --- a/virtual-patient-web/pom.xml +++ b/virtual-patient-web/pom.xml @@ -57,6 +57,36 @@ org.springframework.boot spring-boot-starter-websocket + + org.springframework.boot + spring-boot-test + test + + + junit + junit + test + + + org.springframework + spring-test + test + + + org.springframework.boot + spring-boot-test + test + + + junit + junit + test + + + org.springframework + spring-test + test + diff --git a/virtual-patient-web/src/test/java/com/supervision/VideoUpdateTest.java b/virtual-patient-web/src/test/java/com/supervision/VideoUpdateTest.java new file mode 100644 index 00000000..b21d9c08 --- /dev/null +++ b/virtual-patient-web/src/test/java/com/supervision/VideoUpdateTest.java @@ -0,0 +1,124 @@ +package com.supervision; + +import cn.hutool.core.io.FileUtil; +import com.supervision.config.MinioProperties; +import com.supervision.model.FileResource; +import com.supervision.service.FileResourceService; +import com.supervision.util.MinioUtil; +import io.minio.MinioClient; +import io.minio.StatObjectArgs; +import io.minio.StatObjectResponse; +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.io.BufferedInputStream; +import java.io.File; +import java.util.HashMap; +import java.util.UUID; + + +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +@RunWith(SpringJUnit4ClassRunner.class) +public class VideoUpdateTest { + + @Autowired + private FileResourceService fileResourceService; + + @Autowired + private MinioProperties minioProperties; + + @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 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"); + + 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()); + + 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); + } + + + + + + + + + + + + } +}