zhangenzhi hace 2 años
padre
commit
77c50fa8da

+ 1 - 1
pom.xml

@@ -137,7 +137,7 @@
         <dependency>
             <groupId>com.github.pagehelper</groupId>
             <artifactId>pagehelper-spring-boot-starter</artifactId>
-            <version>1.4.6</version>
+            <version>1.4.3</version>
         </dependency>
     </dependencies>
 

+ 58 - 1
src/main/java/com/pavis/backend/slim/framework/config/MinioConfig.java

@@ -1,9 +1,15 @@
 package com.pavis.backend.slim.framework.config;
 
+import io.minio.BucketExistsArgs;
+import io.minio.DownloadObjectArgs;
+
 import io.minio.MinioClient;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
+import org.springframework.util.StringUtils;
+
+import java.io.File;
 
 /**
  * minio对象存储配置文件
@@ -20,9 +26,60 @@ public class MinioConfig {
     @Value("${minio.secretKey}")
     private String secretKey;
 
+    private MinioClient minioClient;
+
     @Bean
     public MinioClient client() {
-        return MinioClient.builder().endpoint(url)
+        // return MinioClient.builder().endpoint(url)
+        //         .credentials(accessKey, secretKey).build();
+        MinioClient minioClient=MinioClient.builder().endpoint(url)
                 .credentials(accessKey, secretKey).build();
+        this.minioClient=minioClient;
+        return minioClient;
+
+    }
+
+
+    /**
+     * 检查桶是否存在
+     *
+     * @param bucketName 桶名称
+     * @return boolean true-存在 false-不存在
+     */
+    public boolean checkBucketExist(String bucketName) throws Exception {
+        if (!StringUtils.hasLength(bucketName)) {
+            throw new RuntimeException("检测桶的时候,桶名不能为空!");
+        }
+
+        return minioClient.bucketExists(BucketExistsArgs.builder().bucket(bucketName).build());
+    }
+
+    /**
+     * 文件下载到指定路径
+     *
+     * @param downloadPath 下载到本地路径
+     * @param bucketName   下载指定服务器的桶名称
+     * @param objectName   下载的文件名称
+     */
+    public void downloadPath(String downloadPath, String bucketName, String objectName,String originalName) throws Exception {
+        if (downloadPath.isEmpty() || !StringUtils.hasLength(bucketName) || !StringUtils.hasLength(objectName)) {
+            throw new RuntimeException("下载文件参数不全!");
+        }
+
+        if (!new File(downloadPath).isDirectory()) {
+            throw new RuntimeException("本地下载路径必须是一个文件夹或者文件路径!");
+        }
+
+        if (!this.checkBucketExist(bucketName)) {
+            throw new RuntimeException("当前操作的桶不存在!");
+        }
+
+        downloadPath += originalName;
+        minioClient.downloadObject(
+                DownloadObjectArgs.builder()
+                        .bucket(bucketName) //指定是在哪一个桶下载
+                        .object(objectName)//是minio中文件存储的名字;本地上传的文件是user.xlsx到minio中存储的是user-minio,那么这里就是user-minio
+                        .filename(downloadPath)//需要下载到本地的路径,一定是带上保存的文件名;如 d:\\minio\\user.xlsx
+                        .build());
     }
 }

+ 1 - 1
src/main/java/com/pavis/backend/slim/framework/config/SecurityConfig.java

@@ -123,7 +123,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
                 .authorizeRequests()
                 // 对于登录login 注册register 验证码captchaImage 允许匿名访问
                 .antMatchers("/login", "/register","/kg/createKg","/kg/algorithm"
-                ,"/updateFile").permitAll()
+                ,"/office/online","/office/save").permitAll()
                 // 静态资源,可匿名访问
                 .antMatchers(HttpMethod.GET, "/", "/*.html", "/**/*.html", "/**/*.css", "/**/*.js", "/profile/**").permitAll()
                 .antMatchers("/swagger-ui.html", "/swagger-resources/**", "/webjars/**", "/*/api-docs", "/druid/**").permitAll()

+ 120 - 0
src/main/java/com/pavis/backend/slim/project/system/controller/EditorController.java

@@ -0,0 +1,120 @@
+package com.pavis.backend.slim.project.system.controller;
+
+
+import com.alibaba.fastjson2.JSON;
+import com.alibaba.fastjson2.JSONObject;
+import io.minio.DownloadObjectArgs;
+import io.minio.MinioClient;
+import io.minio.errors.MinioException;
+import org.springframework.stereotype.Controller;
+
+import org.springframework.util.StreamUtils;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.servlet.ModelAndView;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.*;
+import java.net.URL;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.security.InvalidKeyException;
+import java.security.NoSuchAlgorithmException;
+
+
+@Controller
+@ResponseBody
+@RequestMapping("/office")
+public class EditorController {
+
+
+    @GetMapping("/online")
+    public void online(HttpServletResponse response, HttpServletRequest request) {
+        try {
+            response.setCharacterEncoding("utf-8");
+            response.setContentType("application/octet-stream");
+
+            // 读文件输入流
+            String filePath = "D:\\test.docx";
+            InputStream inputStream = new FileInputStream(filePath);
+
+            // 复制文件流
+            StreamUtils.copy(inputStream, response.getOutputStream());
+
+            // 关闭输入流
+            inputStream.close();
+
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
+
+
+    @PostMapping(path = "/save")
+    public void save(HttpServletResponse response, HttpServletRequest request) {
+
+        try {
+            // 获得response信息
+            PrintWriter writer = response.getWriter();
+
+            // 获取数据文件信息
+            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+            StreamUtils.copy(request.getInputStream(), byteArrayOutputStream);
+            String fileInfoStr = byteArrayOutputStream.toString();
+            byteArrayOutputStream.close();
+
+            if (fileInfoStr.isEmpty()) {
+                writer.write("request的输入流为空");
+                return;
+            }
+
+            System.out.println(fileInfoStr);
+
+            // 转化字符串对象转化为JSON对象
+            JSONObject fileInfoObj = JSON.parseObject(fileInfoStr);
+
+            // 获取编辑文件的状态
+
+            int status = (Integer) fileInfoObj.get("status");
+            int saved = 0;
+
+            // 关闭正在编辑的文档10秒钟后,会收到该消息
+            if(status == 2 || status == 3) {
+                // 获取文件数据
+                try {
+                    URL url = new URL((String) fileInfoObj.get("url"));
+                    java.net.HttpURLConnection connection = (java.net.HttpURLConnection) url.openConnection();
+                    InputStream inputStream = connection.getInputStream();
+
+                    if (inputStream == null){
+                        throw new Exception("Stream is null");
+                    }
+
+                    // 保存编辑后的数据
+                    String path = "D:\\test.docx";
+                    File file = new File(path);
+
+                    // 复制数据流
+                    FileOutputStream outputStream = new FileOutputStream(file);
+                    StreamUtils.copy(inputStream, outputStream);
+
+                    // 关闭数据资源
+                    outputStream.close();
+                    inputStream.close();
+                    connection.disconnect();
+                } catch (Exception ex) {
+                    saved = 1;
+                    ex.printStackTrace();
+                }
+                System.out.println("保存文件成功");
+            }
+
+
+            writer.write("{\"error\":" + saved + "}");
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
+
+}
+

+ 42 - 0
src/main/java/com/pavis/backend/slim/project/system/controller/SysFileController.java

@@ -1,15 +1,30 @@
 package com.pavis.backend.slim.project.system.controller;
 
+import cn.hutool.core.io.resource.InputStreamResource;
+import com.pavis.backend.slim.framework.config.MinioConfig;
+import com.pavis.backend.slim.framework.minio.MinioStorage;
 import com.pavis.backend.slim.framework.web.domain.AjaxResult;
 import com.pavis.backend.slim.project.system.domain.SysFile;
+import com.pavis.backend.slim.project.system.minio.MinioFileUtil;
 import com.pavis.backend.slim.project.system.service.SysFileService;
+import com.pavis.backend.slim.project.system.service.SysKbService;
+import io.minio.GetObjectArgs;
+import io.minio.GetObjectResponse;
+import io.minio.MinioClient;
 import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.ResponseEntity;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.InputStream;
+
 /**
  * @author semi
  * @create 2023-04-24 14:09
@@ -20,6 +35,20 @@ public class SysFileController {
     @Autowired
     private SysFileService fileService;
 
+    @Autowired
+    private MinioConfig minioFileUtil;
+
+    @Autowired
+    private SysKbService sysKbService;
+
+    @Autowired
+    MinioStorage storage;
+
+    @Value("${minio.bucketName}")
+    private String bucketName;
+
+    @Value("${pavis.profile}")
+    private String urlLocal;
 
     @ApiOperation("单个文件上传")
     @ApiImplicitParams({
@@ -68,4 +97,17 @@ public class SysFileController {
     public AjaxResult updateFile(@RequestBody SysFile sysFile) {
         return AjaxResult.success(fileService.updateFile(sysFile));
     }
+
+    /**
+     * 文件下载,通过路径直接下载到本地
+     *
+     * @throws Exception
+     */
+    @GetMapping("/down")
+    public AjaxResult downloadPath(@RequestParam("objectName")String objectName,@RequestParam("originalName")String name ) throws Exception {
+        MinioClient client = minioFileUtil.client();
+        minioFileUtil.downloadPath(urlLocal, bucketName,objectName,name);
+        return AjaxResult.success();
+    }
+
 }

+ 28 - 0
src/main/java/com/pavis/backend/slim/project/system/controller/SysKbController.java

@@ -17,6 +17,8 @@ import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
 import java.util.List;
 import java.util.Timer;
 import java.util.TimerTask;
@@ -39,6 +41,9 @@ public class SysKbController {
     @Autowired
     private SysKbFileService kbFileService;
 
+    @Autowired
+    private SysKbService sysKbService;
+
     @ApiOperation("创建知识库")
     @PostMapping("/create")
     public AjaxResult createKb(@Validated @RequestBody SysKb kb) {
@@ -138,4 +143,27 @@ public class SysKbController {
         }
         return AjaxResult.success(kbService.searchFile(fileKey));
     }
+
+    @ApiOperation("文件预览接口")
+    @GetMapping("/previewFile")
+    public AjaxResult previewFile(HttpServletResponse response, HttpServletRequest request) throws Exception {
+        String fileId = "8f45bda3db84b0049fa7405abb1dd235";
+        kbService.previewFile(fileId, response, request);
+        return AjaxResult.success();
+    }
+
+    @ApiOperation("文件保存接口")
+    @PostMapping("/saveFile")
+    public AjaxResult saveFile(HttpServletResponse response, HttpServletRequest request) {
+        String name = "8b9bbd99841d4cf4beb156e84289887e.docx";
+        sysKbService.saveFile(response, request, name);
+        return AjaxResult.success();
+    }
+
+    @ApiOperation("删除本地文件")
+    @GetMapping("/deleteFile")
+    public AjaxResult deleteFile(@RequestParam("filePath") String filePath) {
+        fileService.deleteFile(filePath);
+        return AjaxResult.success();
+    }
 }

+ 94 - 0
src/main/java/com/pavis/backend/slim/project/system/minio/FileUploader.java

@@ -0,0 +1,94 @@
+package com.pavis.backend.slim.project.system.minio;
+ 
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.util.List;
+ 
+import io.minio.*;
+import io.minio.messages.Bucket;
+ 
+/**
+ * @ClassName: FileUploader
+ * @Author: jdh
+ * @CreateTime: 2022-04-15
+ * @Description: minio基本操作demo
+ */
+public class FileUploader {
+ 
+    public static void main(String[] args) {
+        try {
+            // 创建客户端
+            MinioClient minioClient =
+                    MinioClient.builder()
+                            // api地址
+                            .endpoint("192.168.1.170",9000,true)
+//                            .endpoint("http://127.0.0.1:9000")
+                            // 前面设置的账号密码
+                            .credentials("upHc9rOpkgBknGOmR9jt", "UAlOMz7KeihAStEimUoFo8h13xmO9ITXFqWDEXFn")
+                            .build();
+ 
+            System.out.println(minioClient);
+            // 检查桶是否存在
+            boolean found = minioClient.bucketExists(BucketExistsArgs.builder().bucket("default").build());
+            if (!found) {
+                // 创建桶
+                minioClient.makeBucket(MakeBucketArgs.builder().bucket("default").build());
+            }
+ 
+            //列出所有桶名
+            List<Bucket> buckets = minioClient.listBuckets();
+            for (Bucket i : buckets){
+                System.out.println(i.name());
+            }
+ 
+            //删除某一个桶
+//            minioClient.removeBucket(
+//                    RemoveBucketArgs.builder()
+//                            .bucket("桶名称")
+//                            .build());
+ 
+ 
+ 
+            System.out.println("开始你的操作");
+ 
+            File file = new File("D:\\Java_study\\javaEE-study\\user.xlsx");
+ 
+            String fileName = file.getName();
+            String realFileName = fileName.substring(fileName.lastIndexOf("\\")+1, fileName.lastIndexOf("."));
+            String fileType = fileName.substring(fileName.lastIndexOf(".")+1);
+ 
+            //通过路径上传一个文件
+            ObjectWriteResponse testDir = minioClient.uploadObject(
+                    UploadObjectArgs.builder()
+                            .bucket("test")
+                            .object("user_Path1")//文件名字
+                            .filename("D:\\Java_study\\javaEE-study\\user.xlsx")//文件存储的路径
+                            .contentType(fileType)
+                            .build());
+ 
+            //通过文件格式上传一个文件
+            InputStream fileInputStream = new FileInputStream(file);
+            long size = file.length();
+ 
+            minioClient.putObject(
+                    PutObjectArgs.builder()
+                            .bucket("test")
+                            .object("user_File1")
+                            .stream(fileInputStream, size, -1)
+                            .contentType(fileType)
+                            .build());
+ 
+            //文件下载,都是这种下载到指定路径
+            minioClient.downloadObject(DownloadObjectArgs.builder()
+                    .bucket("test")
+                    .object("user")
+                    .filename("D:\\Java_study\\javaEE-study\\user_test.xlsx")
+                    .build());
+ 
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+}
+ 

+ 503 - 0
src/main/java/com/pavis/backend/slim/project/system/minio/MinioFileUtil.java

@@ -0,0 +1,503 @@
+package com.pavis.backend.slim.project.system.minio;
+ 
+import io.minio.*;
+import io.minio.errors.*;
+import io.minio.http.Method;
+import io.minio.messages.Bucket;
+import io.minio.messages.DeleteObject;
+import io.minio.messages.Item;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.util.StringUtils;
+import org.springframework.web.multipart.MultipartFile;
+ 
+import javax.annotation.Resource;
+import javax.servlet.http.HttpServletResponse;
+import java.io.*;
+import java.security.InvalidKeyException;
+import java.security.NoSuchAlgorithmException;
+import java.time.LocalDateTime;
+import java.time.ZonedDateTime;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import java.util.concurrent.TimeUnit;
+ 
+/**
+ * @ClassName: MinioFile
+ * @Author: jdh
+ * @CreateTime: 2022-04-15
+ * @Description:
+ */
+@Configuration
+@Slf4j
+public class MinioFileUtil {
+ 
+    @Resource
+    private MinioProperties minioProperties;
+ 
+    private MinioClient minioClient;
+ 
+    /**
+     * 这个是6.0.左右的版本
+     * @return MinioClient
+     */
+//    @Bean
+//    public MinioClient getMinioClient(){
+//
+//        String url = "http:" + minioProperties.getIp() + ":" + minioProperties.getPort();
+//
+//        try {
+//            return new MinioClient(url, minioProperties.getAccessKey(), minioProperties.getSecretKey());
+//        } catch (InvalidEndpointException | InvalidPortException e) {
+//            e.printStackTrace();
+//            log.info("-----创建Minio客户端失败-----");
+//            return null;
+//        }
+//    }
+ 
+    /**
+     * 下面这个和上面的意思差不多,但是这个是新版本
+     * 获取一个连接minio服务端的客户端
+     *
+     * @return MinioClient
+     */
+//     @Bean
+//     public MinioClient getClient() {
+//
+//         String url = "http:" + minioProperties.getIp() + ":" + minioProperties.getPort();
+//         MinioClient minioClient = MinioClient.builder()
+//                 .endpoint(url)    //两种都可以,这种全路径的其实就是下面分开配置一样的
+// //                        .endpoint(minioProperties.getIp(),minioProperties.getPort(),minioProperties.getSecure())
+//                 .credentials(minioProperties.getAccessKey(), minioProperties.getSecretKey())
+//                 .build();
+//         this.minioClient = minioClient;
+//         return minioClient;
+//     }
+ 
+    /**
+     * 创建桶
+     *
+     * @param bucketName 桶名称
+     */
+    public void createBucket(String bucketName) throws Exception {
+        if (!StringUtils.hasLength(bucketName)) {
+            throw new RuntimeException("创建桶的时候,桶名不能为空!");
+        }
+ 
+        // Create bucket with default region.
+        minioClient.makeBucket(MakeBucketArgs.builder()
+                .bucket(bucketName)
+                .build());
+    }
+ 
+    /**
+     * 创建桶,固定minio容器
+     *
+     * @param bucketName 桶名称
+     */
+//     public void createBucketByRegion(String bucketName, String region) throws Exception {
+//         if (!StringUtils.hasLength(bucketName)) {
+//             throw new RuntimeException("创建桶的时候,桶名不能为空!");
+//         }
+//         MinioClient minioClient = this.getClient();
+//
+//         // Create bucket with specific region.
+//         minioClient.makeBucket(MakeBucketArgs.builder()
+//                 .bucket(bucketName)
+//                 .region(region) //
+//                 .build());
+//
+// //        // Create object-lock enabled bucket with specific region.
+// //        minioClient.makeBucket(
+// //                MakeBucketArgs.builder()
+// //                        .bucket("my-bucketname")
+// //                        .region("us-west-1")
+// //                        .objectLock(true)
+// //                        .build());
+//     }
+ 
+    /**
+     * 修改桶名
+     * (minio不支持直接修改桶名,但是可以通过复制到一个新的桶里面,然后删除老的桶)
+     *
+     * @param oldBucketName 桶名称
+     * @param newBucketName 桶名称
+     */
+    public void renameBucket(String oldBucketName, String newBucketName) throws Exception {
+        if (!StringUtils.hasLength(oldBucketName) || !StringUtils.hasLength(newBucketName)) {
+            throw new RuntimeException("修改桶名的时候,桶名不能为空!");
+        }
+ 
+    }
+ 
+    /**
+     * 删除桶
+     *
+     * @param bucketName 桶名称
+     */
+    public void deleteBucket(String bucketName) throws Exception {
+        if (!StringUtils.hasLength(bucketName)) {
+            throw new RuntimeException("删除桶的时候,桶名不能为空!");
+        }
+ 
+        minioClient.removeBucket(
+                RemoveBucketArgs.builder()
+                        .bucket(bucketName)
+                        .build());
+    }
+ 
+    /**
+     * 检查桶是否存在
+     *
+     * @param bucketName 桶名称
+     * @return boolean true-存在 false-不存在
+     */
+    public boolean checkBucketExist(String bucketName) throws Exception {
+        if (!StringUtils.hasLength(bucketName)) {
+            throw new RuntimeException("检测桶的时候,桶名不能为空!");
+        }
+ 
+        return minioClient.bucketExists(BucketExistsArgs.builder().bucket(bucketName).build());
+    }
+ 
+    /**
+     * 列出所有的桶
+     *
+     * @return 所有桶名的集合
+     */
+    public List<Bucket> getAllBucketInfo() throws Exception {
+ 
+        //列出所有桶
+        List<Bucket> buckets = minioClient.listBuckets();
+        return buckets;
+    }
+ 
+    /**
+     * 列出某个桶中的所有文件名
+     * 文件夹名为空时,则直接查询桶下面的数据,否则就查询当前桶下对于文件夹里面的数据
+     *
+     * @param bucketName 桶名称
+     * @param folderName 文件夹名
+     * @param isDeep     是否递归查询
+     */
+    public Iterable<Result<Item>> getBucketAllFile(String bucketName, String folderName, Boolean isDeep) throws Exception {
+        if (!StringUtils.hasLength(bucketName)) {
+            throw new RuntimeException("获取桶中文件列表的时候,桶名不能为空!");
+        }
+        if (!StringUtils.hasLength(folderName)) {
+            folderName = "";
+        }
+        System.out.println(folderName);
+        Iterable<Result<Item>> listObjects = minioClient.listObjects(
+                ListObjectsArgs
+                        .builder()
+                        .bucket(bucketName)
+                        .prefix(folderName + "/")
+                        .recursive(isDeep)
+                        .build());
+ 
+//        for (Result<Item> result : listObjects) {
+//            Item item = result.get();
+//            System.out.println(item.objectName());
+//        }
+ 
+        return listObjects;
+    }
+ 
+    /**
+     * 删除文件夹
+     *
+     * @param bucketName 桶名
+     * @param objectName 文件夹名
+     *
+     * @return
+     */
+    public Boolean deleteBucketFile(String bucketName, String objectName) {
+        if (!StringUtils.hasLength(bucketName) || !StringUtils.hasLength(objectName)) {
+            throw new RuntimeException("删除文件的时候,桶名或文件名不能为空!");
+        }
+        try {
+            minioClient.removeObject(RemoveObjectArgs.builder().bucket(bucketName).object(objectName).build());
+            return true;
+        } catch (Exception e) {
+            log.info("删除文件失败");
+            return false;
+        }
+    }
+ 
+    /**
+     * 删除文件夹
+     *
+     * @param bucketName 桶名
+     * @param objectName 文件夹名
+     * @param isDeep     是否递归删除
+     * @return
+     */
+    public Boolean deleteBucketFolder(String bucketName, String objectName, Boolean isDeep) {
+        if (!StringUtils.hasLength(bucketName) || !StringUtils.hasLength(objectName)) {
+            throw new RuntimeException("删除文件夹的时候,桶名或文件名不能为空!");
+        }
+        try {
+            ListObjectsArgs args = ListObjectsArgs.builder().bucket(bucketName).prefix(objectName + "/").recursive(isDeep).build();
+            Iterable<Result<Item>> listObjects = minioClient.listObjects(args);
+            listObjects.forEach(objectResult -> {
+                try {
+                    Item item = objectResult.get();
+                    minioClient.removeObject(RemoveObjectArgs.builder().bucket(bucketName).object(item.objectName()).build());
+                } catch (Exception e) {
+                    log.info("删除文件夹中的文件异常", e);
+                }
+            });
+            return true;
+        } catch (Exception e) {
+            log.info("删除文件夹失败");
+            return false;
+        }
+    }
+ 
+    /**
+     * 获取文件下载地址
+     *
+     * @param bucketName 桶名
+     * @param objectName 文件名
+     * @param expires    过期时间,默认秒
+     * @return
+     * @throws Exception
+     */
+    public String getFileDownloadUrl(String bucketName, String objectName, Integer expires) throws Exception {
+ 
+        GetPresignedObjectUrlArgs args = GetPresignedObjectUrlArgs.builder()
+                .method(Method.GET)//下载地址的请求方式
+                .bucket(bucketName)
+                .object(objectName)
+                .expiry(expires, TimeUnit.SECONDS)//下载地址过期时间
+                .build();
+        String objectUrl = minioClient.getPresignedObjectUrl(args);
+        return objectUrl;
+    }
+ 
+    /**
+     * 创建文件夹
+     *
+     * @param bucketName 桶名
+     * @param folderName 文件夹名称
+     * @return
+     * @throws Exception
+     */
+    public ObjectWriteResponse createBucketFolder(String bucketName, String folderName) throws Exception {
+ 
+        if (!checkBucketExist(bucketName)) {
+            throw new RuntimeException("必须在桶存在的情况下才能创建文件夹");
+        }
+        if (!StringUtils.hasLength(folderName)) {
+            throw new RuntimeException("创建的文件夹名不能为空");
+        }
+        PutObjectArgs putObjectArgs = PutObjectArgs.builder()
+                .bucket(bucketName)
+                .object(folderName + "/")
+                .stream(new ByteArrayInputStream(new byte[0]), 0, 0)
+                .build();
+        ObjectWriteResponse objectWriteResponse = minioClient.putObject(putObjectArgs);
+ 
+ 
+        return objectWriteResponse;
+    }
+ 
+    /**
+     * 检测某个桶内是否存在某个文件
+     *
+     * @param objectName 文件名称
+     * @param bucketName 桶名称
+     */
+    public boolean getBucketFileExist(String objectName, String bucketName) throws Exception {
+        if (!StringUtils.hasLength(objectName) || !StringUtils.hasLength(bucketName)) {
+            throw new RuntimeException("检测文件的时候,文件名和桶名不能为空!");
+        }
+ 
+        try {
+            // 判断文件是否存在
+            boolean exists = minioClient.bucketExists(BucketExistsArgs.builder().bucket(bucketName).build()) &&
+                    minioClient.statObject(StatObjectArgs.builder().bucket(bucketName).object(objectName).build()) != null;
+            return exists;
+        } catch (ErrorResponseException e) {
+            log.info("文件不存在 ! Object does not exist");
+            return false;
+        } catch (Exception e) {
+            throw new Exception(e);
+        }
+    }
+ 
+    /**
+     * 判断桶中是否存在文件夹
+     *
+     * @param bucketName 同名称
+     * @param objectName 文件夹名称
+     * @param isDeep     是否递归查询(暂不支持)
+     * @return
+     */
+    public Boolean checkBucketFolderExist(String bucketName, String objectName, Boolean isDeep) {
+ 
+        Iterable<Result<Item>> results = minioClient.listObjects(
+                ListObjectsArgs.builder().bucket(bucketName).prefix(objectName).recursive(isDeep).build());
+ 
+        return results.iterator().hasNext(); // 文件夹下存在文件
+    }
+ 
+    /**
+     * 根据MultipartFile file上传文件
+     * minio 采用文件流上传,可以换成下面的文件上传
+     *
+     * @param file       上传的文件
+     * @param bucketName 上传至服务器的桶名称
+     */
+    public boolean uploadFile(MultipartFile file, String bucketName) throws Exception {
+ 
+        if (file == null || file.getSize() == 0 || file.isEmpty()) {
+            throw new RuntimeException("上传文件为空,请重新上传");
+        }
+ 
+        if (!StringUtils.hasLength(bucketName)) {
+            log.info("传入桶名为空,将设置默认桶名:" + minioProperties.getBucketName());
+            bucketName = minioProperties.getBucketName();
+            if (!this.checkBucketExist(minioProperties.getBucketName())) {
+                this.createBucket(minioProperties.getBucketName());
+            }
+        }
+ 
+        if (!this.checkBucketExist(bucketName)) {
+            throw new RuntimeException("当前操作的桶不存在!");
+        }
+ 
+        // 获取上传的文件名
+        String filename = file.getOriginalFilename();
+        assert filename != null;
+        //可以选择生成一个minio中存储的文件名称
+        String minioFilename = UUID.randomUUID().toString() + "_" + filename;
+        String url = "http:" + minioProperties.getIp() + ":" + minioProperties.getPort();
+ 
+        InputStream inputStream = file.getInputStream();
+        long size = file.getSize();
+        String contentType = file.getContentType();
+ 
+        // Upload known sized input stream.
+        minioClient.putObject(
+                PutObjectArgs.builder()
+                        .bucket(bucketName) //上传到指定桶里面
+                        .object(minioFilename)//文件在minio中存储的名字
+                        //p1:上传的文件流;p2:上传文件总大小;p3:上传的分片大小
+                        .stream(inputStream, size, -1) //上传分片文件流大小,如果分文件上传可以采用这种形式
+                        .contentType(contentType) //文件的类型
+                        .build());
+ 
+        return this.getBucketFileExist(minioFilename, bucketName);
+    }
+ 
+    /**
+     * 上传本地文件,根据路径上传
+     * minio 采用文件内容上传,可以换成上面的流上传
+     *
+     * @param filePath 上传本地文件路径
+     * @Param bucketName 上传至服务器的桶名称
+     */
+    public boolean uploadPath(String filePath, String bucketName) throws Exception {
+ 
+        File file = new File(filePath);
+        if (!file.isFile()) {
+            throw new RuntimeException("上传文件为空,请重新上传");
+        }
+ 
+        if (!StringUtils.hasLength(bucketName)) {
+            log.info("传入桶名为空,将设置默认桶名:" + minioProperties.getBucketName());
+            bucketName = minioProperties.getBucketName();
+            if (!this.checkBucketExist(minioProperties.getBucketName())) {
+                this.createBucket(minioProperties.getBucketName());
+            }
+        }
+ 
+        if (!this.checkBucketExist(bucketName)) {
+            throw new RuntimeException("当前操作的桶不存在!");
+        }
+ 
+        String minioFilename = UUID.randomUUID().toString() + "_" + file.getName();//获取文件名称
+        String fileType = minioFilename.substring(minioFilename.lastIndexOf(".") + 1);
+ 
+        minioClient.uploadObject(
+                UploadObjectArgs.builder()
+                        .bucket(bucketName)
+                        .object(minioFilename)//文件存储在minio中的名字
+                        .filename(filePath)//上传本地文件存储的路径
+                        .contentType(fileType)//文件类型
+                        .build());
+ 
+        return this.getBucketFileExist(minioFilename, bucketName);
+    }
+ 
+    /**
+     * 文件下载,通过http返回,即在浏览器下载
+     *
+     * @param response   http请求的响应对象
+     * @param bucketName 下载指定服务器的桶名称
+     * @param objectName 下载的文件名称
+     */
+    public void downloadFile(HttpServletResponse response, String bucketName, String objectName) throws Exception {
+        if (response == null || !StringUtils.hasLength(bucketName) || !StringUtils.hasLength(objectName)) {
+            throw new RuntimeException("下载文件参数不全!");
+        }
+ 
+        if (!this.checkBucketExist(bucketName)) {
+            throw new RuntimeException("当前操作的桶不存在!");
+        }
+ 
+        //获取一个下载的文件输入流操作
+        GetObjectResponse objectResponse = minioClient.getObject(
+                GetObjectArgs.builder()
+                        .bucket(bucketName)
+                        .object(objectName)
+                        .build());
+ 
+        OutputStream outputStream = response.getOutputStream();
+        int len = 0;
+        byte[] buf = new byte[1024 * 8];
+        while ((len = objectResponse.read(buf)) != -1) {
+            outputStream.write(buf, 0, len);
+        }
+        if (outputStream != null) {
+            outputStream.close();
+            outputStream.flush();
+        }
+        objectResponse.close();
+    }
+ 
+    /**
+     * 文件下载到指定路径
+     *
+     * @param downloadPath 下载到本地路径
+     * @param bucketName   下载指定服务器的桶名称
+     * @param objectName   下载的文件名称
+     */
+    public void downloadPath(String downloadPath, String bucketName, String objectName) throws Exception {
+        if (downloadPath.isEmpty() || !StringUtils.hasLength(bucketName) || !StringUtils.hasLength(objectName)) {
+            throw new RuntimeException("下载文件参数不全!");
+        }
+ 
+        if (!new File(downloadPath).isDirectory()) {
+            throw new RuntimeException("本地下载路径必须是一个文件夹或者文件路径!");
+        }
+ 
+        if (!this.checkBucketExist(bucketName)) {
+            throw new RuntimeException("当前操作的桶不存在!");
+        }
+ 
+        downloadPath += objectName;
+ 
+        minioClient.downloadObject(
+                DownloadObjectArgs.builder()
+                        .bucket(bucketName) //指定是在哪一个桶下载
+                        .object(objectName)//是minio中文件存储的名字;本地上传的文件是user.xlsx到minio中存储的是user-minio,那么这里就是user-minio
+                        .filename(downloadPath)//需要下载到本地的路径,一定是带上保存的文件名;如 d:\\minio\\user.xlsx
+                        .build());
+    }
+ 
+}

+ 191 - 0
src/main/java/com/pavis/backend/slim/project/system/minio/MinioFileUtilTest.java

@@ -0,0 +1,191 @@
+package com.pavis.backend.slim.project.system.minio;
+ 
+import io.minio.*;
+import io.minio.messages.Bucket;
+import io.minio.messages.Item;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.multipart.MultipartFile;
+import org.springframework.web.multipart.commons.CommonsMultipartFile;
+ 
+import java.io.*;
+import java.util.List;
+
+
+
+class MinioFileUtilTest {
+ 
+    @Autowired
+    private MinioFileUtil minioFileUtil;
+ 
+    /**
+     * 创建一个桶
+     */
+
+    void createBucket() throws Exception {
+        minioFileUtil.createBucket("minio-file");
+ 
+        /**
+         这里创建桶的命名规则在默认情况下有要求
+         用于存储 CloudTrail 日志文件的 Amazon S3 存储桶的名称必须符合非美国标准区域的命名要求。
+         Amazon S3 存储桶的命名需符合以下一个或多个规则(用句点分隔开):
+         1.存储桶名称的长度介于 3 和 63 个字符之间,并且只能包含小写字母、数字、句点和短划线。
+         2.存储桶名称中的每个标签必须以小写字母或数字开头。
+         3.存储桶名称不能包含下划线、以短划线结束、包含连续句点或在句点旁边使用短划线。
+         4.存储桶名称不能采用 IP 地址格式 (198.51.100.24)。
+         */
+        boolean minioFile = minioFileUtil.checkBucketExist("minio-file");
+        System.out.println(minioFile);
+    }
+ 
+    // /**
+    //  * 创建一个桶
+    //  */
+    //
+    // void createBucketByRegion() throws Exception {
+    //     minioFileUtil.createBucketByRegion("minio-file", "minio-region");
+    //
+    //     boolean minioFile = minioFileUtil.checkBucketExist("minio-file");
+    //     System.out.println(minioFile);
+    // }
+ 
+    /**
+     * 删除一个桶
+     */
+
+    void deleteBucket() throws Exception {
+        minioFileUtil.deleteBucket("minio-file");
+ 
+        boolean minioFile = minioFileUtil.checkBucketExist("minio-file");
+        System.out.println(minioFile);
+    }
+ 
+    /**
+     * 检测桶是否存在
+     */
+
+    void checkBucketExist() throws Exception {
+        boolean test = minioFileUtil.checkBucketExist("test");
+        System.out.println(test);
+    }
+ 
+    /**
+     * 获取所有的桶信息
+     */
+
+    void getAllBucketInfo() throws Exception {
+        List<Bucket> allBucketName = minioFileUtil.getAllBucketInfo();
+        allBucketName.forEach(e -> System.out.println(e.name()));
+    }
+ 
+    /**
+     * 获取某个桶中的全部文件
+     */
+
+    void getBucketAllFile() throws Exception {
+        Iterable<Result<Item>> allFile = minioFileUtil.getBucketAllFile("minio-folder", "part", true);
+        for (Result<Item> result : allFile) {
+            Item item = result.get();
+            System.out.println(item.objectName());
+        }
+    }
+ 
+    /**
+     * 检测某个桶中是否存在某个文件
+     */
+
+    void getBucketFileExist() throws Exception {
+        boolean fileExist = minioFileUtil.getBucketFileExist("8aa570f9-53f5-4cb5-a0d1-c122ef4e3f89_出师表.docx", "minio-bucket");
+        System.out.println(fileExist);
+    }
+ 
+    /**
+     * 删除桶中的一个文件
+     *
+     * @throws Exception
+     */
+
+    void deleteBucketFile() throws Exception {
+        Boolean b = minioFileUtil.deleteBucketFile("minio-folder", "出师表.docx");
+        System.out.println(b);
+    }
+ 
+    /**
+     * 删除桶中的一个文件夹
+     *
+     * @throws Exception
+     */
+
+    void deleteBucketFolder() throws Exception {
+        boolean b = minioFileUtil.deleteBucketFolder("minio-folder", "tempFile", true);
+        System.out.println(b);
+    }
+ 
+    /**
+     * 获取文件下载路径
+     */
+
+    void getFileDownloadUrl() throws Exception {
+        String fileUrl = minioFileUtil.getFileDownloadUrl("minio-bucket", "出师表.docx", 60);
+        System.out.println(fileUrl);
+    }
+
+ 
+    /**
+     * 在一个桶中创建一个空文件夹
+     *
+     * @throws Exception
+     */
+
+    void createBucketFolder() throws Exception {
+ 
+        String buckName = "minio-bucket";
+ 
+        String folderName = "part";
+ 
+        ObjectWriteResponse bucketFolder = minioFileUtil.createBucketFolder(buckName, folderName);
+    }
+ 
+    /**
+     * 在一个桶中创建一个空文件夹
+     *
+     * @throws Exception
+     */
+
+    void checkBucketFolderExist() throws Exception {
+        Boolean tempFile = minioFileUtil.checkBucketFolderExist("minio-bucket", "down", true);
+        System.out.println(tempFile);
+    }
+ 
+
+ 
+    /**
+     * 文件上传,通过本地路径
+     *
+     * @throws Exception
+     */
+
+    void uploadPath() throws Exception {
+ 
+        boolean uploadPath = minioFileUtil.uploadPath("D:\\file\\出师表.docx", "minio-bucket");
+        System.out.println(uploadPath);
+    }
+ 
+    /**
+     * 文件下载,通过http响应下载
+     */
+
+    void downloadFile() {
+        //这里可以使用模拟请求来验证
+    }
+ 
+    // /**
+    //  * 文件下载,通过路径直接下载到本地
+    //  *
+    //  * @throws Exception
+    //  */
+    // void downloadPath() throws Exception {
+    //     MinioClient client = minioFileUtil.getClient();
+    //     minioFileUtil.downloadPath("D:\\file\\", "minio-bucket", "8aa570f9-53f5-4cb5-a0d1-c122ef4e3f89_出师表.docx");
+    // }
+}

+ 55 - 0
src/main/java/com/pavis/backend/slim/project/system/minio/MinioProperties.java

@@ -0,0 +1,55 @@
+package com.pavis.backend.slim.project.system.minio;
+ 
+import lombok.Data;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.stereotype.Component;
+ 
+/**
+ * @ClassName: MinioProperties
+ * @Author: jdh
+ * @CreateTime: 2022-04-15
+ * @Description:
+ */
+@Component
+@Data
+@ConfigurationProperties(prefix = "minio.config")
+public class MinioProperties {
+
+    /**
+     * API调用地址ip
+     */
+    private String ip;
+ 
+    /**
+     * API调用地址端口
+     */
+    private Integer port;
+ 
+    /**
+     * 连接账号
+     */
+    private String accessKey;
+ 
+    /**
+     * 连接秘钥
+     */
+    private String secretKey;
+ 
+    /**
+     * minio存储桶的名称
+     */
+    private String bucketName;
+ 
+    /**
+     * 文件下载到本地的路径
+     */
+    private String downloadDir;
+ 
+    /**
+     * #如果是true,则用的是https而不是http,默认值是true
+     */
+    private Boolean secure;
+ 
+}
+ 

+ 7 - 0
src/main/java/com/pavis/backend/slim/project/system/service/SysFileService.java

@@ -77,4 +77,11 @@ public interface SysFileService extends IService<SysFile> {
      * @return 修改后的文件详情
      */
     public SysFile updateFile(SysFile file);
+
+    /**
+     * 删除本地单个文件
+     * @param   sPath    被删除文件的文件名
+     * @return 单个文件删除成功返回true,否则返回false
+     */
+    boolean deleteFile(String sPath);
 }

+ 19 - 0
src/main/java/com/pavis/backend/slim/project/system/service/SysKbService.java

@@ -6,6 +6,8 @@ import com.pavis.backend.slim.project.system.domain.SysFile;
 import com.pavis.backend.slim.project.system.domain.SysKb;
 import com.pavis.backend.slim.project.system.domain.front.FileKey;
 
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
 import java.util.List;
 
 /**
@@ -75,4 +77,21 @@ public interface SysKbService extends IService<SysKb> {
      * @param kbId 知识库id
      */
     void delFileAndRelation(String kbId);
+
+    /**
+     * 文件预览
+     * @param fileId 文件id
+     * @param response
+     * @param request
+     * @throws Exception
+     */
+    void previewFile(String fileId, HttpServletResponse response, HttpServletRequest request) throws Exception;
+
+    /**
+     * 保存文件
+     * @param response
+     * @param request
+     * @param name 文件名字
+     */
+    void saveFile(HttpServletResponse response, HttpServletRequest request, String name);
 }

+ 19 - 0
src/main/java/com/pavis/backend/slim/project/system/service/impl/SysFileServiceImpl.java

@@ -11,17 +11,23 @@ import com.pavis.backend.slim.common.exception.ServiceException;
 import com.pavis.backend.slim.common.utils.FileUtils;
 import com.pavis.backend.slim.common.utils.SecurityUtils;
 import com.pavis.backend.slim.framework.minio.MinioStorage;
+import io.minio.MinioClient;
 import com.pavis.backend.slim.project.system.domain.SysFile;
 import com.pavis.backend.slim.project.system.domain.vo.TreeFile;
 import com.pavis.backend.slim.project.system.mapper.SysFileMapper;
 import com.pavis.backend.slim.project.system.service.SysFileService;
+import io.minio.errors.MinioException;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import org.springframework.web.multipart.MultipartFile;
 
+import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.Paths;
 import java.security.InvalidKeyException;
 import java.security.NoSuchAlgorithmException;
 import java.util.*;
@@ -221,4 +227,17 @@ public class SysFileServiceImpl extends ServiceImpl<SysFileMapper, SysFile> impl
         baseMapper.updateById(file);
         return file;
     }
+
+    @Override
+    public boolean deleteFile(String sPath) {
+        boolean flag = false;
+        File file = new File(sPath);
+        // 路径为文件且不为空则进行删除
+        if (file.isFile() && file.exists()) {
+            file.delete();
+            flag = true;
+        }
+        return flag;
+    }
+
 }

+ 93 - 93
src/main/java/com/pavis/backend/slim/project/system/service/impl/SysKbServiceImpl.java

@@ -168,34 +168,34 @@ public class SysKbServiceImpl extends ServiceImpl<SysKbMapper, SysKb> implements
     }
 
 
-    // @Override
-    // public void previewFile(String fileId, HttpServletResponse response, HttpServletRequest request) throws Exception {
-    //     //根据fileId,获取文件详情
-    //     SysFile sysFile = sysFileMapper.selectById(fileId);
-    //     //从minio将要预览的文件下载到本地
-    //     MinioClient client = minioFileUtil.client();
-    //     minioFileUtil.downloadPath(urlLocal, bucketName, sysFile.getObjectKey(), sysFile.getName());
-    //     //预览文件
-    //     try {
-    //         log.info("开始预览");
-    //         // response.setCharacterEncoding("utf-8");
-    //         // response.setContentType("application/octet-stream");
-    //
-    //         // 读文件输入流
-    //         String filePath = urlLocal + sysFile.getName();
-    //         InputStream inputStream = new FileInputStream(filePath);
-    //
-    //         // 复制文件流
-    //         StreamUtils.copy(inputStream, response.getOutputStream());
-    //
-    //         // 关闭输入流
-    //         inputStream.close();
-    //
-    //         log.info("预览结束");
-    //     } catch (IOException e) {
-    //         e.printStackTrace();
-    //     }
-    // }
+    @Override
+    public void previewFile(String fileId, HttpServletResponse response, HttpServletRequest request) throws Exception {
+        //根据fileId,获取文件详情
+        SysFile sysFile = sysFileMapper.selectById(fileId);
+        //从minio将要预览的文件下载到本地
+        MinioClient client = minioFileUtil.client();
+        minioFileUtil.downloadPath(urlLocal, bucketName, sysFile.getObjectKey(), sysFile.getName());
+        //预览文件
+        try {
+            log.info("开始预览");
+            // response.setCharacterEncoding("utf-8");
+            // response.setContentType("application/octet-stream");
+
+            // 读文件输入流
+            String filePath = urlLocal + sysFile.getName();
+            InputStream inputStream = new FileInputStream(filePath);
+
+            // 复制文件流
+            StreamUtils.copy(inputStream, response.getOutputStream());
+
+            // 关闭输入流
+            inputStream.close();
+
+            log.info("预览结束");
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
 
 
     /**
@@ -205,69 +205,69 @@ public class SysKbServiceImpl extends ServiceImpl<SysKbMapper, SysKb> implements
      * @param request
      * @param name     修改文件的本地路径
      */
-    // @Override
-    // public void saveFile(HttpServletResponse response, HttpServletRequest request, String name) {
-    //
-    //     try {
-    //         // 获得response信息
-    //         PrintWriter writer = response.getWriter();
-    //
-    //         // 获取数据文件信息
-    //         ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
-    //         StreamUtils.copy(request.getInputStream(), byteArrayOutputStream);
-    //         String fileInfoStr = byteArrayOutputStream.toString();
-    //         byteArrayOutputStream.close();
-    //
-    //         if (fileInfoStr.isEmpty()) {
-    //             writer.write("request的输入流为空");
-    //             return;
-    //         }
-    //
-    //         System.out.println(fileInfoStr);
-    //
-    //         // 转化字符串对象转化为JSON对象
-    //         JSONObject fileInfoObj = JSON.parseObject(fileInfoStr);
-    //
-    //         // 获取编辑文件的状态
-    //
-    //         int status = (Integer) fileInfoObj.get("status");
-    //         int saved = 0;
-    //
-    //         // 关闭正在编辑的文档10秒钟后,会收到该消息
-    //         if (status == 2 || status == 3) {
-    //             // 获取文件数据
-    //             try {
-    //                 URL url = new URL((String) fileInfoObj.get("url"));
-    //                 java.net.HttpURLConnection connection = (java.net.HttpURLConnection) url.openConnection();
-    //                 InputStream inputStream = connection.getInputStream();
-    //
-    //                 if (inputStream == null) {
-    //                     throw new Exception("Stream is null");
-    //                 }
-    //
-    //                 // 保存编辑后的数据
-    //                 String path = urlLocal + name;
-    //                 File file = new File(path);
-    //
-    //                 // 复制数据流
-    //                 FileOutputStream outputStream = new FileOutputStream(file);
-    //                 StreamUtils.copy(inputStream, outputStream);
-    //
-    //                 // 关闭数据资源
-    //                 outputStream.close();
-    //                 inputStream.close();
-    //                 connection.disconnect();
-    //             } catch (Exception ex) {
-    //                 saved = 1;
-    //                 ex.printStackTrace();
-    //             }
-    //             System.out.println("保存文件成功");
-    //         }
-    //
-    //
-    //         // writer.write("{\"error\":" + saved + "}");
-    //     } catch (IOException e) {
-    //         e.printStackTrace();
-    //     }
-    // }
+    @Override
+    public void saveFile(HttpServletResponse response, HttpServletRequest request, String name) {
+
+        try {
+            // 获得response信息
+            // PrintWriter writer = response.getWriter();
+
+            // 获取数据文件信息
+            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+            StreamUtils.copy(request.getInputStream(), byteArrayOutputStream);
+            String fileInfoStr = byteArrayOutputStream.toString();
+            byteArrayOutputStream.close();
+
+            // if (fileInfoStr.isEmpty()) {
+            //     writer.write("request的输入流为空");
+            //     return;
+            // }
+
+            System.out.println(fileInfoStr);
+
+            // 转化字符串对象转化为JSON对象
+            JSONObject fileInfoObj = JSON.parseObject(fileInfoStr);
+
+            // 获取编辑文件的状态
+
+            int status = (Integer) fileInfoObj.get("status");
+            int saved = 0;
+
+            // 关闭正在编辑的文档10秒钟后,会收到该消息
+            if (status == 2 || status == 3) {
+                // 获取文件数据
+                try {
+                    URL url = new URL((String) fileInfoObj.get("url"));
+                    java.net.HttpURLConnection connection = (java.net.HttpURLConnection) url.openConnection();
+                    InputStream inputStream = connection.getInputStream();
+
+                    if (inputStream == null) {
+                        throw new Exception("Stream is null");
+                    }
+
+                    // 保存编辑后的数据
+                    String path = urlLocal + name;
+                    File file = new File(path);
+
+                    // 复制数据流
+                    FileOutputStream outputStream = new FileOutputStream(file);
+                    StreamUtils.copy(inputStream, outputStream);
+
+                    // 关闭数据资源
+                    outputStream.close();
+                    inputStream.close();
+                    connection.disconnect();
+                } catch (Exception ex) {
+                    saved = 1;
+                    ex.printStackTrace();
+                }
+                System.out.println("保存文件成功");
+            }
+
+
+            // writer.write("{\"error\":" + saved + "}");
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
 }

+ 1 - 1
src/main/resources/application-formal.yml

@@ -18,7 +18,7 @@ minio:
 #  #Secret key密码
 #  secretKey: ZfmZgtZO4g1L8iMmVB8DeARCSdyxzI8G
 
-  url: http://172.23.11.26:9001
+  url: http://172.23.11.26:9000
   #Access key账户
   accessKey: fG2cm5LfIo41mXUqfYKt
   #Secret key密码

+ 2 - 2
src/main/resources/application-local.yml

@@ -56,9 +56,9 @@ spring:
           driver-class-name: com.mysql.cj.jdbc.Driver
   # redis 配置
   redis:
-    #    # 地址
+#    # 地址
     host: 192.168.1.141
-    #    # 端口,默认为6379
+#    # 端口,默认为6379
     port: 6379
 # feign 配置
 feign:

+ 93 - 0
src/main/resources/application-minio.yml

@@ -0,0 +1,93 @@
+server:
+  port: 8068
+# 通用配置
+pavis:
+  # 需要换成自己开发环境本地的地址
+  profile: D:\privacy\pavis\uploadPath
+#minio配置
+minio:
+#  #对象存储服务的URL
+#  url: http://localhost:9000/
+#  #Access key账户
+#  accessKey: minioadmin
+#  #Secret key密码
+#  secretKey: minioadmin
+#  bucketName: default
+#  #Access key账户
+#  accessKey: 2TlzVcrX1jH2oWhz
+#  #Secret key密码
+#  secretKey: ZfmZgtZO4g1L8iMmVB8DeARCSdyxzI8G
+
+#  url: http://192.168.1.170:9000/
+#  #Access key账户
+#  accessKey: upHc9rOpkgBknGOmR9jt
+#  #Secret key密码
+#  secretKey: UAlOMz7KeihAStEimUoFo8h13xmO9ITXFqWDEXFn
+#  bucketName: default
+# Minio配置
+  config:
+    ip: 127.0.0.1 #ip地址
+    port: 9000  #  端口号
+    accessKey: upHc9rOpkgBknGOmR9jt #  账号
+    secretKey: UAlOMz7KeihAStEimUoFo8h13xmO9ITXFqWDEXFn #  密码
+    secure: false #如果是true,则用的是https而不是http,默认值是true
+    bucketName: "default"  # 桶的名字
+    downloadDir: "/Temp"  #保存到本地的路径
+spring:
+  datasource:
+    dynamic:
+      primary: master #设置默认的数据源或者数据源组,默认值即为master
+      strict: false #严格匹配数据源,默认false. true未匹配到指定数据源时抛异常,false使用默认数据源
+      datasource:
+#        master:
+#          url: jdbc:mysql://192.168.1.166:3306/slim
+#          username: root
+#          password: 123456
+#          driver-class-name: com.mysql.cj.jdbc.Driver # 3.2.0开始支持SPI可省略此配置
+        master:
+          url: jdbc:mysql://192.168.1.170:3310/slim
+          username: root
+          password: Gky.i3g8,
+          driver-class-name: com.mysql.cj.jdbc.Driver # 3.2.0开始支持SPI可省略此配置
+        slave_1:
+          url: jdbc:mysql://192.168.1.170:3311/slim
+          username: root
+          password: Gky.i3g8,
+          driver-class-name: com.mysql.cj.jdbc.Driver
+        slave_2:
+          url: jdbc:mysql://192.168.1.170:3312/slim
+          username: root
+          password: Gky.i3g8,
+          driver-class-name: com.mysql.cj.jdbc.Driver
+  # redis 配置
+  redis:
+#    # 地址
+    host: 192.168.1.170
+#    # 端口,默认为6379
+    port: 6379
+# feign 配置
+feign:
+  client:
+    config:
+      default:
+        logger-level: full
+  httpclient:
+    # 开启feign对httpclient的支持
+    enabled: true
+    # 最大连接数
+    max-connections: 200
+    # 每个路径的最大连接数
+    max-connections-per-route: 50
+
+#调用算法接口
+algorithm:
+  creat:
+    # 将所需要生成图谱的文件,传给算法的接口
+    url: http://192.168.1.150:8900/data_access
+
+#PageHelper 分页插件配置
+pagehelper:
+  helperDialect: mysql
+  reasonable: true
+  supportMethodsArguments: true
+  params: count=countSql

BIN
test.docx