root 2 жил өмнө
parent
commit
fae87247b1

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

@@ -82,6 +82,21 @@ public class MinioController {
         return new ResponseBodyVO<>(ResponseBodyVO.Response.SUCCESS, "请求成功!", previewUrl);
     }
 
+    @GetMapping(value = "/copy")
+    public ResponseBodyVO<String> copy(
+            @RequestParam("source") String source,
+            @RequestParam("target") String target//  "/xx/xxx/x/xx"
+    ) {
+        MinioUtil.copyObject(
+                minioClientPrivate,
+                minioConfiguration.getBucketName(),
+                source,
+                minioConfiguration.getBucketName(),
+                target
+        );
+        return new ResponseBodyVO<>(ResponseBodyVO.Response.SUCCESS);
+    }
+
 
     @PostMapping("/list")
     @SneakyThrows

+ 12 - 0
simulation-resource-common/src/main/java/com/css/simulation/resource/common/util/MinioUtil.java

@@ -20,6 +20,18 @@ import java.util.Set;
 public class MinioUtil {
 
 
+    /**
+     * 复制文件
+     */
+    @SneakyThrows
+    public static void copyObject(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());
+    }
+
+
 
     /**
      * 获取下一级文件列表

+ 8 - 2
simulation-resource-server/src/main/java/com/css/simulation/resource/feign/FileDownService.java

@@ -30,7 +30,13 @@ public interface FileDownService {
 
     @PostMapping(value = "/minio/uploadLocalFile")
     ResponseBodyVO<String> uploadLocalFile(@RequestParam("localFilePath") String localFilePath,
-                                  @RequestParam("objectName") String objectName);
+                                           @RequestParam("objectName") String objectName);
+
+    @GetMapping(value = "/minio/copy")
+    ResponseBodyVO<String> copy(
+            @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,
@@ -44,7 +50,7 @@ public interface FileDownService {
     ResponseBodyVO<List<String>> list(@RequestBody @Validated MinioParameter minioParameter);
 
     @PostMapping("/minio/listDeepOne")
-    ResponseBodyVO<List<String>> listDeepOne( @RequestBody @Validated MinioParameter minioParameter );
+    ResponseBodyVO<List<String>> listDeepOne(@RequestBody @Validated MinioParameter minioParameter);
 
     @RequestMapping("/minio/getPreviewUrl")
     ResponseBodyVO<String> getPreviewUrl(@RequestBody @Validated MinioParameter minioParameter);

+ 15 - 2
simulation-resource-server/src/main/java/com/css/simulation/resource/feign/fallback/FileDownServiceFallback.java

@@ -2,13 +2,12 @@ package com.css.simulation.resource.feign.fallback;
 
 import api.common.pojo.common.ResponseBodyVO;
 import api.common.pojo.param.MinioParameter;
-import api.common.pojo.param.RedisParameter;
 import com.css.simulation.resource.feign.FileDownService;
-import com.css.simulation.resource.feign.RedisService;
 import feign.Response;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RequestPart;
@@ -27,6 +26,20 @@ public class FileDownServiceFallback implements FileDownService {
         return new ResponseBodyVO<>(ResponseBodyVO.Response.SERVER_FAILURE);
     }
 
+    @Override
+    public ResponseBodyVO<String> uploadLocalFile(@RequestParam("localFilePath") String localFilePath,
+                                                  @RequestParam("objectName") String objectName) {
+        return new ResponseBodyVO<>(ResponseBodyVO.Response.SERVER_FAILURE);
+    }
+
+    @GetMapping(value = "/minio/copy")
+    public ResponseBodyVO<String> copy(
+            @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,
                                                    @RequestParam("objectName") String objectName,

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

@@ -14,7 +14,6 @@ import com.fasterxml.jackson.core.JsonProcessingException;
 import org.apache.tomcat.util.buf.StringUtils;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
-import org.springframework.web.bind.annotation.RequestBody;
 
 import javax.annotation.Resource;
 import java.math.BigDecimal;
@@ -30,10 +29,12 @@ public class VehicleService {
     VehicleMapper vehicleMapper;
     @Resource
     FileDownService fileDownService;
-    @Value("${par-directory}")
-    String parDirectory;
+    @Value("${par.template}")
+    String parTemplate;
+    @Value("${par.temp}")
+    String parTemp;
 
-    public List<VehicleVO> getVehicleList(@RequestBody VehicleParam vehicleParam) {
+    public List<VehicleVO> getVehicleList(VehicleParam vehicleParam) {
         vehicleParam.setCreateUserId(AuthUtil.getCurrentUserId());
         vehicleParam.setShare(null);
         return vehicleMapper.getVehicleList(vehicleParam);
@@ -77,7 +78,7 @@ public class VehicleService {
             String parameterType = vehicleVO.getParameterType();    //1 判断参数是 1 vtd 还是 2 carsim
             if ("2".equals(parameterType)) {
                 VehicleUtil.listToJson(vehiclePO);
-                String par = FileUtil.read("/mnt/disk001/simulation-cloud/simulation-resource-server-8005/Example.par");
+                String par = FileUtil.read(parTemplate);
                 String replace1 = par.replaceAll("wheelCenterToTop", vehiclePO.getWheelCenterToTop());
                 String replace2 = replace1.replaceAll("wheelCenterToGround", vehiclePO.getWheelCenterToGround());
                 String replace3 = replace2.replaceAll("centroidToFrontWheelCenter", vehiclePO.getCentroidToFrontWheelCenter());
@@ -196,10 +197,10 @@ public class VehicleService {
                 String replace49 = replace48.replaceAll("relationCurveRightWheelAngleAndSteeringGearOutput", convertArrayToTable(vehiclePO.getRelationCurveRightWheelAngleAndSteeringGearOutput()));
                 String replace50 = replace49.replaceAll("relationCurveLeftWheelAngleAndSteeringGearOutput", convertArrayToTable(vehiclePO.getRelationCurveLeftWheelAngleAndSteeringGearOutput()));
                 String parFileName = StringUtil.getRandomEightBitUUID() + ".par";
-                String localParFilePath = parDirectory + parFileName;
-                String minioParFilePath = "/model/"+parFileName;
+                String localParFilePath = parTemp + parFileName;
+                String minioParFilePath = "/model/" + parFileName;
                 FileUtil.writeStringToLocalFile(replace50, localParFilePath);
-                fileDownService.uploadLocalFile(localParFilePath,minioParFilePath);
+                fileDownService.uploadLocalFile(localParFilePath, minioParFilePath);
                 vehiclePO.setParFilePath(minioParFilePath);
             }
             if (ObjectUtil.isNull(id)) {//新增
@@ -236,6 +237,10 @@ public class VehicleService {
             Timestamp currentTime = TimeUtil.getNowForMysql();
             vehiclePO.setModifyUserId(currentUserId);
             vehiclePO.setModifyTime(currentTime);
+            String sourceParFilePath = vehiclePO.getParFilePath();
+            String targetParFilePath = "/model/" + StringUtil.getRandomEightBitUUID() + ".par";
+            fileDownService.copy(sourceParFilePath,targetParFilePath);
+            vehiclePO.setParFilePath(targetParFilePath);
             vehicleMapper.update(vehiclePO);
             LogUtil.update();
         } else { // 新增
@@ -243,6 +248,10 @@ public class VehicleService {
             PoUtil.initAddPo(vehiclePO);
             vehiclePO.setId(StringUtil.getRandomUUID());
             vehiclePO.setVehicleCode(StringUtil.getRandomCode());
+            String sourceParFilePath = vehiclePO.getParFilePath();
+            String targetParFilePath = "/model/" + StringUtil.getRandomEightBitUUID() + ".par";
+            fileDownService.copy(sourceParFilePath,targetParFilePath);
+            vehiclePO.setParFilePath(targetParFilePath);
             vehicleMapper.insert(vehiclePO);
         }
         LogUtil.share();

+ 5 - 0
simulation-resource-server/src/main/resources/mapper/model/VehicleMapper.xml

@@ -117,6 +117,7 @@
         description,
         vehicle_front_view,
         vehicle_top_view,
+        parameter_type,
         share
         from model_vehicle v
         where v.is_deleted = '0'
@@ -140,6 +141,7 @@
                description,
                vehicle_front_view,
                vehicle_top_view,
+               parameter_type,
                share
         from model_vehicle
         where is_deleted = '0'
@@ -303,6 +305,7 @@
                                   modify_user_id,
                                   is_deleted,
                                   parameter_type,
+                                  par_file_path,
                                   wheelCenterToGround, centroidToFrontWheelCenter, centroidToGround, sprungMass,
                                   vehicleWidth,
                                   rotationalInertiaX, rotationalInertiaY, rotationalInertiaZ,
@@ -371,6 +374,7 @@
                 #{modifyUserId,jdbcType=VARCHAR},
                 #{isDeleted,jdbcType=VARCHAR},
                 #{parameterType},
+                #{parFilePath},
                 #{wheelCenterToGround},
                 #{centroidToFrontWheelCenter},
                 #{centroidToGround},
@@ -476,6 +480,7 @@
             modify_time                                                   = #{modifyTime,jdbcType=TIMESTAMP},
             modify_user_id                                                = #{modifyUserId,jdbcType=VARCHAR},
             parameter_type                                                 = #{parameterType},
+            par_file_path                                                 = #{parFilePath},
             wheelCenterToTop                                              = #{wheelCenterToTop},
             wheelCenterToGround                                           = #{wheelCenterToGround},
             centroidToFrontWheelCenter                                    = #{centroidToFrontWheelCenter},