From d4a8f0f3e9d383d6602783085e98810524cf1749 Mon Sep 17 00:00:00 2001 From: youahng <2998465706@qq.com> Date: Thu, 8 Aug 2024 16:13:01 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AC=AC=E4=B8=80=E7=89=88=E6=96=87=E6=A1=A3?= =?UTF-8?q?=E8=AF=B4=E6=98=8E+=E5=88=A0=E9=99=A4=E4=BA=86=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E7=B1=BB=EF=BC=88=E6=89=93=E5=8C=85=E6=97=B6=E6=8A=A5?= =?UTF-8?q?=E9=94=99=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/文档说明.md | 35 ++++++++ src/test/java/com/teaching/MinioTest.java | 101 ---------------------- src/test/java/com/teaching/test.java | 36 -------- 3 files changed, 35 insertions(+), 137 deletions(-) create mode 100644 docs/文档说明.md delete mode 100644 src/test/java/com/teaching/MinioTest.java delete mode 100644 src/test/java/com/teaching/test.java diff --git a/docs/文档说明.md b/docs/文档说明.md new file mode 100644 index 0000000..0d63d00 --- /dev/null +++ b/docs/文档说明.md @@ -0,0 +1,35 @@ +## 文档说明 + +##### 资源接口 + + resourcesController 资源上传 uploadFile / 下载 deleteResource / 预览 readFile + +用minio 作为资源管理 + +minio 网址:http://39.106.16.162:9001/ +用户名:minioadmin +密码:minioadmin + +以日期分类 文件类型 文件名前10个(超出10)+yyyymmddhhmmss + +yml 配置 + +```java +minio: + endpoint: http://39.106.16.162:9090 #MinIO服务所在地址 + bucketName: teaching # 存储桶名称 + accessKey: minioadmin # 访问的key + secretKey: minioadmin # 访问的秘钥 +``` + +minioutils 工具类 + +> 逻辑就是,文件上传之后,存入图数据库,返回节点信息 , 删除文件 也得删除文件在图数据库的节点 + +##### 图数据库 + +http://39.106.16.162:7474/ + +用户名 neo4j + +密码123456 diff --git a/src/test/java/com/teaching/MinioTest.java b/src/test/java/com/teaching/MinioTest.java deleted file mode 100644 index cbdb77d..0000000 --- a/src/test/java/com/teaching/MinioTest.java +++ /dev/null @@ -1,101 +0,0 @@ -package com.teaching; - -import org.junit.jupiter.api.Test; -import org.springframework.util.DigestUtils; - -import java.io.*; -import java.util.Arrays; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; - -public class MinioTest { - //分块测试 - @Test - public void testChunk() throws IOException { - //源文件 - File sourseFile = new File("D:/Users/Desktop/image/剪映/7.18/7月20.mp4"); - //分块文件存储路径 - String chunkFilePath = "D:/Users/Desktop/image/剪映/7.18/chunk/"; - //分块文件大小 - int chunkSize = 1024 * 1024 * 1; - //分块文件个数 - int chunkNum = (int) Math.ceil(sourseFile.length() * 1.0 / chunkSize); - //使用流从源文件读数据,向分块文件中写数据 - RandomAccessFile raf_r = new RandomAccessFile(sourseFile, "r"); - //缓存区 - byte[] bytes = new byte[1024]; - for (int i = 0; i < chunkNum; i++) { - File chunkFile = new File(chunkFilePath + i); - //分块文件写入流 - RandomAccessFile raf_rw = new RandomAccessFile(chunkFile, "rw"); - int len = -1; - while((len=raf_r.read(bytes)) != -1){ - raf_rw.write(bytes, 0, len); - if (chunkFile.length() >= chunkSize){ - break; - } - } - raf_rw.close(); - } - raf_r.close(); - } - - //将分块进行合并 - @Test - public void testMerge() throws IOException { - //块文件目录 - File chunkFolder = new File("D:\\Users\\Desktop\\image\\剪映\\7.18\\chunk"); - //源文件 - File sourseFile = new File("D:/Users/Desktop/image/剪映/7.18/7月20.mp4"); - //合并后的文件 - File mergeFile = new File("D:/Users/Desktop/image/剪映/7.18/7月20_merge.mp4"); - - //取出所有分块文件 - File[] files = chunkFolder.listFiles(); - //将数组转成list - List fileList = Arrays.asList(files); - //对分块文件排序 - Collections.sort(fileList, new Comparator() { - @Override - public int compare(File o1, File o2) { - return Integer.parseInt(o1.getName()) - Integer.parseInt(o2.getName()); //升序 - } - }); - //向合并文件写的流 - RandomAccessFile raf_rw = new RandomAccessFile(mergeFile, "rw"); - //缓存区 - byte[] bytes = new byte[1024]; - //遍历分块文件,向合并的文件写 - for (File file : fileList) { - //读分块的流 - RandomAccessFile raf_r = new RandomAccessFile(file, "r"); - int len = -1; - while((len = raf_r.read(bytes)) != -1){ - raf_rw.write(bytes, 0, len); - } - raf_r.close(); - } - raf_rw.close(); - //合并文件完成后对合并的文件校验 - FileInputStream fileInputStream_merge = new FileInputStream(mergeFile); - FileInputStream fileInputStream_source = new FileInputStream(sourseFile); - String md5_merge = DigestUtils.md5DigestAsHex(fileInputStream_merge); - String md5_source = DigestUtils.md5DigestAsHex(fileInputStream_source); - if (md5_merge.equals(md5_source)){ - System.out.println("文件合并成功!"); - } - } - - //将分块文件上传到minio - public void uploadChunk(){ - - } - - //调用minio接口合并分块 - - - //批量清理分块文件 - - -} diff --git a/src/test/java/com/teaching/test.java b/src/test/java/com/teaching/test.java deleted file mode 100644 index 6d75620..0000000 --- a/src/test/java/com/teaching/test.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.teaching; - - -import lombok.extern.slf4j.Slf4j; -import org.junit.jupiter.api.Test; -import org.springframework.boot.test.context.SpringBootTest; - -import javax.annotation.Resource; - -@Slf4j -@SpringBootTest -public class test { - - - @Test - public void countknowledge(){ - String userId = "2"; -// System.out.println(knowledgeLearningCountService.list()); -// List list = knowledgeLearningCountService.query().eq("user_id", userId).list(); -// HashSet set = new HashSet<>(list); -// System.out.println(set.size()); -// Long count = knowledgeLearningCountService.query().eq("user_id", userId).count(); -// if (count == 0){ -// KnowledgeLearningCount knowledgeLearningCount = new KnowledgeLearningCount(); -// knowledgeLearningCount.setUserId(userId); -// knowledgeLearningCount.setNumber(1); -// knowledgeLearningCountService.save(knowledgeLearningCount); -// }else { -// //该用户学习知识点数+1 -// boolean is = knowledgeLearningCountService.update() -// .setSql("number = "+set.size()) -// .eq("user_id", userId).update(); -// System.out.println(is); -// } - } -}