Forráskód Böngészése

Merge remote-tracking branch 'origin/master'

martin 3 éve
szülő
commit
06d003bd4d

+ 13 - 3
simulation-resource-common/src/main/java/com/css/simulation/resource/common/configuration/minio/MinioConfiguration.java

@@ -11,14 +11,24 @@ import org.springframework.context.annotation.Configuration;
 @ConfigurationProperties(prefix = "minio")
 public class MinioConfiguration {
 
-    private String endpoint;
+    private String endpointPrivate;
+    private String endpointPublic;
     private String accessKey;
     private String secretKey;
 
     @Bean
-    public SubMinioClient minioClient() {
+    public SubMinioClient minioClientPrivate() {
         MinioClient minioClient = MinioClient.builder()
-                .endpoint(endpoint)
+                .endpoint(endpointPrivate)
+                .credentials(accessKey, secretKey)
+                .build();
+        return new SubMinioClient(minioClient);
+    }
+
+    @Bean
+    public SubMinioClient minioClientPublic() {
+        MinioClient minioClient = MinioClient.builder()
+                .endpoint(endpointPublic)
                 .credentials(accessKey, secretKey)
                 .build();
         return new SubMinioClient(minioClient);

+ 16 - 13
simulation-resource-common/src/main/java/com/css/simulation/resource/common/controller/MinioController.java

@@ -32,8 +32,11 @@ import java.util.*;
 @RequestMapping("/minio")
 public class MinioController {
 
-    @Resource
-    private SubMinioClient minioClient;
+    @Resource(name = "minioClientPrivate")
+    private SubMinioClient minioClientPrivate;
+
+    @Resource(name = "minioClientPublic")
+    private SubMinioClient minioClientPublic;
 
     @Value("${minio.bucket-name}")
     private String bucketName;
@@ -53,12 +56,12 @@ public class MinioController {
             @RequestParam("objectName") String objectName//  "/xx/xxx/x/xx"
     ) throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException {
         MinioUtil.uploadFromMultipartFile(
-                minioClient,
+                minioClientPrivate,
                 file,
                 bucketName,
                 objectName
         );
-        String previewUrl = MinioUtil.getPreviewUrl(minioClient, Method.GET, bucketName, objectName);
+        String previewUrl = MinioUtil.getPreviewUrl(minioClientPrivate, Method.GET, bucketName, objectName);
 
         return new ResponseBodyVO<>(ResponseBodyVO.Response.SUCCESS, "请求成功!", previewUrl);
     }
@@ -79,7 +82,7 @@ public class MinioController {
             }
 
             MinioUtil.uploadProcessBar(
-                    minioClient,
+                    minioClientPrivate,
                     file,
                     bucketName,
                     objectName,
@@ -99,7 +102,7 @@ public class MinioController {
             @RequestBody @Validated MinioParameter minioParameter
     ) throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException {
 
-        List<String> objects = MinioUtil.listObjects(minioClient, bucketName, minioParameter.getObjectName());
+        List<String> objects = MinioUtil.listObjects(minioClientPrivate, bucketName, minioParameter.getObjectName());
         return new ResponseBodyVO<>(ResponseBodyVO.Response.SUCCESS, objects);
     }
 
@@ -109,7 +112,7 @@ public class MinioController {
             HttpServletResponse response
     ) throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException {
         InputStream inputStream = MinioUtil.downloadToStream(
-                minioClient,
+                minioClientPrivate,
                 bucketName,
                 minioParameter.getObjectName()
         );
@@ -120,7 +123,7 @@ public class MinioController {
     @RequestMapping("/preview")
     public void preview(@RequestParam("objectName") String objectName, HttpServletResponse response ) throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException {
         InputStream inputStream = MinioUtil.downloadToStream(
-                minioClient,
+                minioClientPrivate,
                 bucketName,
                 objectName
         );
@@ -130,7 +133,7 @@ public class MinioController {
 
     @RequestMapping("/getPreviewUrl")
     public ResponseBodyVO<String> getPreviewUrl(@RequestBody @Validated MinioParameter minioParameter) throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException {
-        String previewUrl = MinioUtil.getPreviewUrl(minioClient, Method.GET, bucketName, minioParameter.getObjectName());
+        String previewUrl = MinioUtil.getPreviewUrl(minioClientPublic, Method.GET, bucketName, minioParameter.getObjectName());
         return new ResponseBodyVO<>(ResponseBodyVO.Response.SUCCESS,"请求成功!", previewUrl);
     }
 
@@ -148,7 +151,7 @@ public class MinioController {
             objectName = "algorithm/" + nowTime + "/" + objectName;
         }
         Map<String, Object> result = new HashMap<>();//结果数据
-        CreateMultipartUploadResponse multipartUpload = minioClient.createMultipartUpload(bucketName, null, objectName, null, null);
+        CreateMultipartUploadResponse multipartUpload = minioClientPrivate.createMultipartUpload(bucketName, null, objectName, null, null);
         String uploadId = multipartUpload.result().uploadId();
         List<String> UrlList = new LinkedList<>();
         Map<String, String> queryParam = new HashMap<>();
@@ -156,7 +159,7 @@ public class MinioController {
         int size = Integer.parseInt(chunkSize);
         for (int i = 1; i <= size; i++) {
             queryParam.put("partNumber", String.valueOf(i));
-            String presignedObjectUrl = minioClient.getPresignedObjectUrl(GetPresignedObjectUrlArgs.builder()
+            String presignedObjectUrl = minioClientPublic.getPresignedObjectUrl(GetPresignedObjectUrlArgs.builder()
                     .method(Method.PUT)
                     .bucket(bucketName)
                     .object(objectName)
@@ -179,7 +182,7 @@ public class MinioController {
         if (ObjectUtil.isNull(objectName) || ObjectUtil.isNull(uploadId)) {
             return new ResponseBodyVO(ResponseBodyVO.Response.CLIENT_FAILURE, "请求参数缺失!");
         }
-        ListPartsResponse listPartsResponse = minioClient.listParts(bucketName, null, objectName, 10000, 0, uploadId, null, null);
+        ListPartsResponse listPartsResponse = minioClientPrivate.listParts(bucketName, null, objectName, 10000, 0, uploadId, null, null);
         List<Part> parts = listPartsResponse.result().partList();
         Part[] partArr = new Part[parts.size()];
         int partNumber = 1;
@@ -187,7 +190,7 @@ public class MinioController {
             partArr[partNumber - 1] = new Part(partNumber, part.etag());
             partNumber++;
         }
-        minioClient.completeMultipartUpload(bucketName, null, objectName, uploadId, partArr, null, null);
+        minioClientPrivate.completeMultipartUpload(bucketName, null, objectName, uploadId, partArr, null, null);
         return new ResponseBodyVO(ResponseBodyVO.Response.SUCCESS, "合并成功!");
     }
 }

+ 46 - 26
simulation-resource-server/src/main/java/com/css/simulation/resource/project/impl/SimulationProjectServiceImpl.java

@@ -896,6 +896,7 @@ public class SimulationProjectServiceImpl implements SimulationProjectService {
 
             //平均速度
             Double pjsd = lc/time_list.get(time_list.size()-1);
+            pjsd = saveTwoDecimalPlaces(pjsd, 4);
 
             //最大速度
             Double zdsd = Collections.max(longitudinal_velocity_list);
@@ -918,6 +919,7 @@ public class SimulationProjectServiceImpl implements SimulationProjectService {
                 zcsdfc +=Math.pow(d-pjsd,2);
             }
             zcsdfc = zcsdfc/longitudinal_velocity_list.size();
+            zcsdfc = saveTwoDecimalPlaces(zcsdfc, 4);
 
             //自车横摆角速度均方根
             Double zchbjsdjfg = 0D;
@@ -925,6 +927,7 @@ public class SimulationProjectServiceImpl implements SimulationProjectService {
                 zchbjsdjfg += Math.pow(d-pjsd,2);
             }
             zchbjsdjfg = Math.sqrt(zchbjsdjfg/yawrate_list.size());
+            zchbjsdjfg = saveTwoDecimalPlaces(zchbjsdjfg, 4);
 
             for(int i=0; i<lateral_acceleration.size(); i++){
                 Double aDouble = lateral_acceleration.get(i);
@@ -1354,6 +1357,13 @@ public class SimulationProjectServiceImpl implements SimulationProjectService {
         return new BigDecimal(d).setScale(2, RoundingMode.UP).doubleValue();
     }
 
+    private Double saveTwoDecimalPlaces(Double d, int num){
+        if(d == null){
+            return null;
+        }
+        return new BigDecimal(d).setScale(num, RoundingMode.UP).doubleValue();
+    }
+
     /**
      * 设置场景基本字段
      */
@@ -3282,17 +3292,11 @@ public class SimulationProjectServiceImpl implements SimulationProjectService {
             response.setHeader("Content-Disposition", "attachment;fileName=" + URLEncoder.encode("运行任务包.zip", "UTF-8"));
             zos = new ZipOutputStream(response.getOutputStream());
             int i = 1;
+            String egoFile= "Ego.csv";
             for(ManualProjectTaskVo v : manualProjectTaskVos){
                 String runResultFilePath = v.getRunResultFilePath();
                 if(!isEmpty(runResultFilePath)){
 
-                    MinioParameter minioParameter = new MinioParameter();
-                    minioParameter.setObjectName(runResultFilePath+"/Ego.csv");
-                    Response download = fileDownService.download(minioParameter);
-                    Response.Body body = download.body();
-                    inputStream = body.asInputStream();
-                    in =  new BufferedInputStream(inputStream);
-
                     //获取场景名
                     SceneBaseInfoVo sceneBaseInfoVo = getsceneNameAndOther(v.getSceneId(), v.getSceneType());
                     String sceneName = sceneBaseInfoVo.getCommonSceneName();
@@ -3301,33 +3305,25 @@ public class SimulationProjectServiceImpl implements SimulationProjectService {
                     String taskPagePath = rootPath+File.separator+sceneName+"("+i+")";
 //                    FileUtil.createDirectory(taskPagePath);
 
-                    //任务文件路径
-                    String taskFilePath = taskPagePath +File.separator+ ".Ego.csv";
-//                    FileUtil.writeInputStreamToLocalFile(inputStream,taskFilePath);
-
-                    ZipEntry entry = new ZipEntry(taskFilePath);
-                    in = new BufferedInputStream(inputStream);
-                    zos.putNextEntry(entry);
-                    while ((len = in.read(buffer)) != -1 ) {
-                        zos.write(buffer, 0, len);
-                    }
-
                     //视频文件路径
                     MinioParameter minioParameter1 = new MinioParameter();
                     minioParameter1.setObjectName(runResultFilePath);
                     ResponseBodyVO<List<String>> list = fileDownService.list(minioParameter1);
                     List<String> info = list.getInfo();
                     for(String s : info){
-                        String videoPath = "";
+                        String fileName = "";
+                        String zipPath = "";
+                        //获取文件名
+                        if(s.contains("/")){
+                            fileName = s.substring(s.lastIndexOf("/")+1);
+                        }else{
+                            fileName = s.substring(s.lastIndexOf("\\")+1);
+                        }
+                        zipPath = taskPagePath + File.separator + fileName;
+                        //文件后缀
                         String substring = s.substring(s.lastIndexOf(".") + 1);
                         if("mp4".equals(substring)){
                             //mp4视频文件导出
-                            if(s.contains("/")){
-                                videoPath = taskPagePath + File.separator + s.substring(s.lastIndexOf("/")+1);
-                            }else{
-                                videoPath = taskPagePath + File.separator + s.substring(s.lastIndexOf("\\")+1);
-                            }
-
                             MinioParameter minioParameter2 = new MinioParameter();
                             minioParameter2.setObjectName(s);
                             Response download2 = fileDownService.download(minioParameter2);
@@ -3335,12 +3331,36 @@ public class SimulationProjectServiceImpl implements SimulationProjectService {
                             inputStream = body2.asInputStream();
                             in = new BufferedInputStream(inputStream);
 
-                            ZipEntry entry2 = new ZipEntry(videoPath);
+                            ZipEntry entry2 = new ZipEntry(zipPath);
                             zos.putNextEntry(entry2);
                             while ((len = in.read(buffer)) != -1 ) {
                                 zos.write(buffer, 0, len);
                             }
 
+                        }else if(egoFile.equals(fileName)){
+
+                            MinioParameter minioParameter = new MinioParameter();
+                            if(s.contains("/")){
+                                minioParameter.setObjectName(runResultFilePath+"/"+egoFile);
+                            }else{
+                                minioParameter.setObjectName(runResultFilePath+"\\"+egoFile);
+                            }
+
+                            Response download = fileDownService.download(minioParameter);
+                            Response.Body body = download.body();
+                            inputStream = body.asInputStream();
+                            in =  new BufferedInputStream(inputStream);
+
+                            //任务文件路径
+                            String taskFilePath = taskPagePath +File.separator + egoFile;
+//                          FileUtil.writeInputStreamToLocalFile(inputStream,taskFilePath);
+
+                            ZipEntry entry = new ZipEntry(taskFilePath);
+                            in = new BufferedInputStream(inputStream);
+                            zos.putNextEntry(entry);
+                            while ((len = in.read(buffer)) != -1 ) {
+                                zos.write(buffer, 0, len);
+                            }
                         }
 
                     }

+ 3 - 3
simulation-resource-server/src/main/resources/mapper/project/SimulationProjectMapper.xml

@@ -340,20 +340,20 @@
     <select id="selectSceneAccidentById" parameterType="string" resultType="api.common.pojo.vo.project.SceneBaseInfoVo">
         select scene_name
         from scene_accident
-        where accident_id = #{id,jdbcType=VARCHAR} and is_deleted = '0'
+        where accident_id = #{id,jdbcType=VARCHAR}
     </select>
     <!--查询自然场景信息-->
     <select id="selectSceneNatural" parameterType="string" resultType="api.common.pojo.vo.project.SceneBaseInfoVo">
         select natural_name
         from scene_natural
-        where natural_id = #{id,jdbcType=VARCHAR} and is_deleted = '0'
+        where natural_id = #{id,jdbcType=VARCHAR}
 
     </select>
     <!--查询标准法规场景信息-->
     <select id="selectSceneStandardsRegulations" parameterType="string" resultType="api.common.pojo.vo.project.SceneBaseInfoVo">
         select scene_name
         from scene_standards_regulations
-        where regulations_id = #{id,jdbcType=VARCHAR} and is_deleted = '0'
+        where regulations_id = #{id,jdbcType=VARCHAR}
     </select>
 
     <!--根据场景包id获取场景子集-->

+ 1 - 1
simulation-resource-server/src/main/resources/mapper/project/SimulationProjectTaskMapper.xml

@@ -46,7 +46,7 @@
     <select id="selectRunResultCount" parameterType="string" resultType="api.common.pojo.vo.project.ProjectRunResultRatioNumVo">
         select run_result as resultName, count(*) as num
         from simulation_manual_project_task
-        where p_id = #{id,jdbcType=VARCHAR} and is_deleted = '0'
+        where p_id = #{id,jdbcType=VARCHAR} and is_deleted = '0' and run_result != null and run_result != ""
         group by run_result
     </select>