root 2 роки тому
батько
коміт
c5f0a91be1

+ 15 - 0
simulation-resource-common/src/main/java/com/css/simulation/resource/common/controller/MinioController.java

@@ -93,6 +93,21 @@ public class MinioController {
         return new ResponseBodyVO<>(ResponseBodyVO.Response.SUCCESS);
     }
 
+    @GetMapping(value = "/move")
+    public ResponseBodyVO<String> move(
+            @RequestParam("source") String source,
+            @RequestParam("target") String target//  "/xx/xxx/x/xx"
+    ) {
+        MinioUtil.moveObject(
+                minioClientPrivate,
+                minioConfiguration.getBucketName(),
+                source,
+                minioConfiguration.getBucketName(),
+                target
+        );
+        return new ResponseBodyVO<>(ResponseBodyVO.Response.SUCCESS);
+    }
+
 
     @PostMapping("/list")
     @SneakyThrows

+ 15 - 11
simulation-resource-common/src/main/java/com/css/simulation/resource/common/util/MinioUtil.java

@@ -28,6 +28,17 @@ public class MinioUtil {
                 .build());
     }
 
+    /**
+     * 复制文件
+     */
+    @SneakyThrows
+    public static void moveObject(MinioClient minioClient, String sourceBucket, String sourceObject, String targetBucket, String targetObject) {
+        minioClient.copyObject(CopyObjectArgs.builder().source(CopySource.builder()
+                        .bucket(sourceBucket).object(sourceObject).build())
+                .bucket(targetBucket).object(targetObject)
+                .build());
+        removeObject(minioClient, sourceBucket, sourceObject);
+    }
 
 
     /**
@@ -38,7 +49,7 @@ public class MinioUtil {
      * @param prefix      目录名
      * @return 文件路径列表
      */
-    public static List<String> listObjectsUnRecursive(MinioClient minioClient, String bucket, String prefix) throws Exception{
+    public static List<String> listObjectsUnRecursive(MinioClient minioClient, String bucket, String prefix) throws Exception {
 
         if (prefix.startsWith("/")) {
             prefix = prefix.substring(1);
@@ -109,7 +120,6 @@ public class MinioUtil {
     }
 
 
-
     /**
      * 获取预览路径
      *
@@ -277,14 +287,8 @@ public class MinioUtil {
      * @param bucket      桶
      * @param object      文件对象
      */
-    public static void removeObject(
-            MinioClient minioClient,
-            String bucket,
-            String object
-    ) throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, io.minio.errors.InternalException {
-        minioClient.removeObject(RemoveObjectArgs.builder()
-                .bucket(bucket)
-                .object(object)
-                .build());
+    @SneakyThrows
+    public static void removeObject(MinioClient minioClient, String bucket, String object) {
+        minioClient.removeObject(RemoveObjectArgs.builder().bucket(bucket).object(object).build());
     }
 }

+ 7 - 1
simulation-resource-server/src/main/java/com/css/simulation/resource/feign/FileDownService.java

@@ -28,7 +28,7 @@ public interface FileDownService {
     ResponseBodyVO<String> upload(@RequestPart("file") MultipartFile file,
                                   @RequestParam("objectName") String objectName);
 
-    @PostMapping(value = "/minio/uploadLocalFile")
+    @GetMapping(value = "/minio/uploadLocalFile")
     ResponseBodyVO<String> uploadLocalFile(@RequestParam("localFilePath") String localFilePath,
                                            @RequestParam("objectName") String objectName);
 
@@ -38,6 +38,12 @@ public interface FileDownService {
             @RequestParam("target") String target//  "/xx/xxx/x/xx"
     );
 
+    @GetMapping(value = "/minio/move")
+    ResponseBodyVO<String> move(
+            @RequestParam("source") String source,
+            @RequestParam("target") String target//  "/xx/xxx/x/xx"
+    );
+
     @PostMapping(value = "/minio/uploadProcessBar", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
     ResponseBodyVO<String> uploadProcessBar(@RequestPart("file") MultipartFile file,
                                             @RequestParam("objectName") String objectName,

+ 7 - 0
simulation-resource-server/src/main/java/com/css/simulation/resource/feign/fallback/FileDownServiceFallback.java

@@ -39,6 +39,13 @@ public class FileDownServiceFallback implements FileDownService {
     ){
         return new ResponseBodyVO<>(ResponseBodyVO.Response.SERVER_FAILURE);
     }
+    @GetMapping(value = "/minio/move")
+    public ResponseBodyVO<String> move(
+            @RequestParam("source") String source,
+            @RequestParam("target") String target//  "/xx/xxx/x/xx"
+    ){
+        return new ResponseBodyVO<>(ResponseBodyVO.Response.SERVER_FAILURE);
+    }
 
     @Override
     public ResponseBodyVO<String> uploadProcessBar(@RequestPart("file") MultipartFile file,

+ 2 - 2
simulation-resource-server/src/main/java/com/css/simulation/resource/model/service/VehicleService.java

@@ -243,7 +243,7 @@ public class VehicleService {
             vehiclePO.setModifyTime(currentTime);
             String sourceParFilePath = vehiclePO.getParFilePath();
             String targetParFilePath = "/model/" + StringUtil.getRandomEightBitUUID() + ".par";
-            fileDownService.copy(sourceParFilePath, targetParFilePath);
+            fileDownService.move(sourceParFilePath, targetParFilePath);
             vehiclePO.setParFilePath(targetParFilePath);
             vehicleMapper.update(vehiclePO);
             LogUtil.update();
@@ -254,7 +254,7 @@ public class VehicleService {
             vehiclePO.setVehicleCode(StringUtil.getRandomCode());
             String sourceParFilePath = vehiclePO.getParFilePath();
             String targetParFilePath = "/model/" + StringUtil.getRandomEightBitUUID() + ".par";
-            fileDownService.copy(sourceParFilePath, targetParFilePath);
+            fileDownService.move(sourceParFilePath, targetParFilePath);
             vehiclePO.setParFilePath(targetParFilePath);
             vehicleMapper.insert(vehiclePO);
         }