Переглянути джерело

Merge branch '20240309-saq-fix' of gitee.com:lingxinmeng/simulation-cloud into 20240309-saq-fix
mereg

夜得朦胧 1 рік тому
батько
коміт
fbda6239de
19 змінених файлів з 554 додано та 317 видалено
  1. 2 0
      api-common/src/main/java/api/common/pojo/param/scene/SceneEvaluationComputeParam.java
  2. 2 0
      api-common/src/main/java/api/common/pojo/po/system/DictPO.java
  3. 8 0
      api-common/src/main/java/api/common/pojo/vo/project/SimulationManualProjectSingleVo.java
  4. 160 110
      simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/domain/service/TaskDomainService.java
  5. 1 1
      simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/infra/configuration/kubernetes/KubernetesConfiguration.java
  6. 1 1
      simulation-resource-server/src/main/java/com/css/simulation/resource/server/adapter/controller/scene_library/score_rule/ScoreRuleController.java
  7. 20 0
      simulation-resource-server/src/main/java/com/css/simulation/resource/server/app/impl/SimulationProjectServiceImpl.java
  8. 11 1
      simulation-resource-server/src/main/java/com/css/simulation/resource/server/app/service/DictService.java
  9. 24 14
      simulation-resource-server/src/main/java/com/css/simulation/resource/server/app/service/SceneAccidentService.java
  10. 179 114
      simulation-resource-server/src/main/java/com/css/simulation/resource/server/app/service/SceneEvaluationRuleService.java
  11. 25 14
      simulation-resource-server/src/main/java/com/css/simulation/resource/server/app/service/SceneNaturalService.java
  12. 24 19
      simulation-resource-server/src/main/java/com/css/simulation/resource/server/app/service/SceneReferenceLibService.java
  13. 30 17
      simulation-resource-server/src/main/java/com/css/simulation/resource/server/app/service/SceneStandardsService.java
  14. 2 0
      simulation-resource-server/src/main/java/com/css/simulation/resource/server/infra/db/mysql/mapper/DictMapper.java
  15. 38 0
      simulation-resource-server/src/main/resources/mysql/mapper/DictMapper.xml
  16. 11 12
      simulation-resource-server/src/main/resources/mysql/mapper/SceneComplexityMapper.xml
  17. 0 1
      simulation-resource-server/src/main/resources/mysql/mapper/SceneReferenceLibMapper.xml
  18. 11 12
      simulation-resource-server/src/main/resources/mysql/mapper/SceneRiskMapper.xml
  19. 5 1
      simulation-resource-server/src/main/resources/mysql/mapper/SimulationManualProjectMapper.xml

+ 2 - 0
api-common/src/main/java/api/common/pojo/param/scene/SceneEvaluationComputeParam.java

@@ -3,6 +3,7 @@ package api.common.pojo.param.scene;
 import lombok.*;
 
 import java.io.Serializable;
+import java.util.List;
 
 /**
  * 场景评价规则
@@ -18,6 +19,7 @@ public class SceneEvaluationComputeParam implements Serializable {
 
     // 场景评价规则 Id
     private String sceneId;
+    private List<String> copySceneId;
     private String sceneXOSCPath;
     private String sceneXODRPath;
     private String sceneType;

+ 2 - 0
api-common/src/main/java/api/common/pojo/po/system/DictPO.java

@@ -16,6 +16,8 @@ public class DictPO extends CommonPO {
     private String dictName;
     //编码
     private String dictCode;
+    // 字典描述
+    private String dictComment;
     //序号
     private int dictOrder;
 

+ 8 - 0
api-common/src/main/java/api/common/pojo/vo/project/SimulationManualProjectSingleVo.java

@@ -49,5 +49,13 @@ public class SimulationManualProjectSingleVo {
     private String[] vehicleArrayS;
     //场景测试包数组(公私有)
     private String[] sceneArrayS;
+    // 复杂度规则
+    private String complexityEvaluationRuleName;
+    // 危险度
+    private String riskEvaluationRuleName;
+    // 暴露率
+    private String exposureRateEvaluationRuleName;
+    // 覆盖率
+    private String coverageRateEvaluationRuleName;
 
 }

+ 160 - 110
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/domain/service/TaskDomainService.java

@@ -1,7 +1,6 @@
 package com.css.simulation.resource.scheduler.domain.service;
 
 import api.common.pojo.constants.DictConstants;
-import api.common.pojo.enums.SceneEvaluationEnum;
 import api.common.pojo.param.scene.SceneEvaluationComputeParam;
 import api.common.pojo.param.scene.SceneImportParam;
 import api.common.pojo.po.scene.SceneComplexityPO;
@@ -32,6 +31,10 @@ import org.springframework.stereotype.Component;
 
 import javax.annotation.Resource;
 import java.io.*;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.attribute.PosixFilePermission;
 import java.util.*;
 import java.util.concurrent.TimeUnit;
 import java.util.function.Function;
@@ -49,8 +52,6 @@ public class TaskDomainService {
     private String pyPath;
     @Value("${scheduler.linux-path.temp}")
     private String linuxTempPath;
-    @Value("${scheduler.scene-evaluation.script}")
-    private String sceneEvaluationScript;
     @Resource
     private StringRedisTemplate stringRedisTemplate;
     @Resource
@@ -135,6 +136,8 @@ public class TaskDomainService {
         List<SceneEntity> sceneEntityList = getSceneList(projectId, packageId);
         Map<String, SceneEntity> sceneEntityMap = sceneEntityList.stream().collect(Collectors.toMap(SceneEntity::getId, Function.identity()));
         List<LeafIndexEntity> leafIndexList = new ArrayList<>();
+        List<SceneEvaluationComputeParam> sceneComplexityEvaluationComputeParamList = new ArrayList<>();
+        List<SceneEvaluationComputeParam> sceneRiskEvaluationComputeParamList = new ArrayList<>();
         for (int i = 0; i < leafIndexTemplateList.size(); i++) {
             String scoreExplain = null; // 每个叶子指标下的任务的得分说明一样和叶子指标一致
             IndexTemplateEntity leafIndexTemplate = leafIndexTemplateList.get(i);
@@ -260,13 +263,7 @@ public class TaskDomainService {
                         sceneEvaluationComputeParam.setSceneType(sceneEntityMap.get(sceneId).getType());
                         sceneEvaluationComputeParam.setTaskId(projectId);
                         sceneEvaluationComputeParam.setComputeType(DictConstants.COMPLEXITY);
-                        try {
-                            SceneImportParam sceneImportParam = new SceneImportParam();
-                            sceneImportParam.setSceneEvaluationRuleId(projectEntity.getComplexityEvaluationRuleId());
-                            computeSceneReference(sceneImportParam, sceneEvaluationComputeParam);
-                        } catch (Exception e) {
-                            log.error("计算复杂度失败", e);
-                        }
+                        sceneComplexityEvaluationComputeParamList.add(sceneEvaluationComputeParam);
                     }
                     // 计算复杂度和危险度
                     if (!StringUtils.isEmpty(projectEntity.getRiskEvaluationRuleId())) {
@@ -278,13 +275,7 @@ public class TaskDomainService {
                         sceneEvaluationComputeParam.setComputeType(DictConstants.RISK);
                         sceneEvaluationComputeParam.setAlgorithmId(projectEntity.getAlgorithm());
                         sceneEvaluationComputeParam.setVehicleId(projectEntity.getVehicle());
-                        try {
-                            SceneImportParam sceneImportParam = new SceneImportParam();
-                            sceneImportParam.setSceneEvaluationRuleId(projectEntity.getRiskEvaluationRuleId());
-                            computeSceneReference(sceneImportParam, sceneEvaluationComputeParam);
-                        } catch (Exception e) {
-                            log.error("计算复杂度失败", e);
-                        }
+                        sceneRiskEvaluationComputeParamList.add(sceneEvaluationComputeParam);
                     }
                 }
             }
@@ -332,6 +323,24 @@ public class TaskDomainService {
 
             leafIndexList.add(leafIndex);
         }
+        if (!StringUtils.isEmpty(projectEntity.getComplexityEvaluationRuleId())) {
+            try {
+                SceneImportParam sceneImportParam = new SceneImportParam();
+                sceneImportParam.setSceneEvaluationRuleId(projectEntity.getComplexityEvaluationRuleId());
+                computeSceneReference(sceneImportParam, sceneComplexityEvaluationComputeParamList);
+            } catch (Exception e) {
+                log.error("计算复杂度失败", e);
+            }
+        }
+        if (!StringUtils.isEmpty(projectEntity.getRiskEvaluationRuleId())) {
+            try {
+                SceneImportParam sceneImportParam = new SceneImportParam();
+                sceneImportParam.setSceneEvaluationRuleId(projectEntity.getRiskEvaluationRuleId());
+                computeSceneReference(sceneImportParam, sceneRiskEvaluationComputeParamList);
+            } catch (Exception e) {
+                log.error("计算复杂度失败", e);
+            }
+        }
         // 删除临时文件
         FileUtil.rm(linuxTempPath + "scene/evaluation/" + projectId + "/");   // 删除临时文件
         // 保存叶子指标得分
@@ -343,7 +352,6 @@ public class TaskDomainService {
     }
 
     public void computeFirst(List<LeafIndexEntity> leafIndexList, List<IndexTemplateEntity> allIndexTemplateList, String projectId, int maxLevel) {
-
         log.debug("计算父指标得分:" + leafIndexList);
         Iterator<LeafIndexEntity> leafTaskIndexIterator = leafIndexList.iterator();
         // 把 1 级的指标得分直接保存
@@ -458,7 +466,7 @@ public class TaskDomainService {
      *
      * @param param
      */
-    public boolean computeSceneReference(SceneImportParam param, SceneEvaluationComputeParam sceneEvaluationComputeParam) {
+    public boolean computeSceneReference(SceneImportParam param, List<SceneEvaluationComputeParam> sceneEvaluationComputeParams) {
         String ruleId = param.getSceneEvaluationRuleId();
         // 获取场景评价规则
         SceneEvaluationRulePO sceneEvaluationRulePO = sceneEvaluationRuleMapper.querySceneEvaluationPyById(ruleId);
@@ -467,126 +475,168 @@ public class TaskDomainService {
             return false;
         }
         // 1 判断有没有用户目录,没有则复制
-        String evaluationDirectoryOfUser = linuxTempPath + "scene/evaluation/" + sceneEvaluationComputeParam.getTaskId() + "/";
-        String scriptsPath = evaluationDirectoryOfUser + "scripts/";
+        String evaluationDirectoryOfUser = linuxTempPath + "scene/evaluation/" + sceneEvaluationComputeParams.get(0).getTaskId() + "/";
+        String scriptsPath = evaluationDirectoryOfUser + "scripts";
         if (!new File(evaluationDirectoryOfUser).exists()) {
             // 1 将场景评价规则脚本保存到 script 目录
             FileUtil.createDirectory(scriptsPath);
-            final ArrayList<String> scriptFilePath = CollectionUtil.createArrayList(
-                    "/data_preprocessing.py",
-                    "/elevation.py",
-                    "/scenario_criticality_algorithm.py",
-                    "/scenario_evaluation_main.py",
-                    "/scenario_evaluation_utils52.py"
-            );
-            for (String pyFilePath : scriptFilePath) {
-                MinioUtil.downloadToFile(minioClient, bucketName, sceneEvaluationScript + pyFilePath, scriptsPath + pyFilePath);
-            }
         }
         // 下载场景评价脚本到脚本目录
         if (sceneEvaluationRulePO.getScriptPath() == null) {
             return false;
         }
-        String pyMainPath = scriptsPath + "/" + sceneEvaluationRulePO.getRuleId() + ".py";
+        String pyMainPath = scriptsPath + "/" + sceneEvaluationRulePO.getRuleId();
         if (!new File(pyMainPath).exists()) {
             MinioUtil.downloadToFile(minioClient, bucketName, sceneEvaluationRulePO.getScriptPath(), pyMainPath);
+            try {
+                Path path = Paths.get(pyMainPath);
+                Set<PosixFilePermission> permissions = new HashSet<>();
+                permissions.add(PosixFilePermission.OWNER_READ);
+                permissions.add(PosixFilePermission.OWNER_WRITE);
+                permissions.add(PosixFilePermission.OWNER_EXECUTE);
+                permissions.add(PosixFilePermission.GROUP_READ);
+                permissions.add(PosixFilePermission.GROUP_WRITE);
+                permissions.add(PosixFilePermission.GROUP_EXECUTE);
+                permissions.add(PosixFilePermission.OTHERS_READ);
+                permissions.add(PosixFilePermission.OTHERS_WRITE);
+                permissions.add(PosixFilePermission.OTHERS_EXECUTE);
+                Files.setPosixFilePermissions(path, permissions);
+            } catch (IOException e) {
+                log.error("更改执行文件权限失败: " + sceneEvaluationRulePO.getScriptPath(), e);
+                return false;
+            }
         }
-        // 创建场景路径
-        String scenePath = evaluationDirectoryOfUser + sceneEvaluationComputeParam.getSceneId();
-        if (!new File(scenePath).exists()) {
-            FileUtil.createDirectory(scenePath);
-        } else {
-            // 一个场景只计算一次
-            return false;
-        }
-        try {
-            if (StringUtils.equals(sceneEvaluationComputeParam.getComputeType(), DictConstants.COMPLEXITY)) {
-                // 计算复杂度,根据场景 id 获取场景信息,下载 osc odr
-                String scenarioOsc = sceneEvaluationComputeParam.getSceneXOSCPath();
-                String[] splitXosc = scenarioOsc.split("/");
-                String xoscName = splitXosc[splitXosc.length - 1];
-                MinioUtil.downloadToFile(minioClient, bucketName, sceneEvaluationComputeParam.getSceneXOSCPath(), scenePath + "/" + xoscName);
-                String scenarioOdr = sceneEvaluationComputeParam.getSceneXODRPath();
-                String[] splitXodr = scenarioOdr.split("/");
-                String xodrName = splitXodr[splitXodr.length - 1];
-                MinioUtil.downloadToFile(minioClient, bucketName, sceneEvaluationComputeParam.getSceneXODRPath(), scenePath + "/" + xodrName);
-            } else if (StringUtils.equals(sceneEvaluationComputeParam.getComputeType(), DictConstants.RISK)) {
-                // 计算危险度 从 minio path 下载 csv (ego 和 sensors)
-                MinioUtil.downloadToFile(minioClient, bucketName, sceneEvaluationComputeParam.getEvaluationPath() + "/Ego.csv", scenePath + "/Ego.csv");
-                MinioUtil.downloadToFile(minioClient, bucketName, sceneEvaluationComputeParam.getEvaluationPath() + "/sensors.csv", scenePath + "/sensors.csv");
+        String scenePathFather = evaluationDirectoryOfUser + "scene/";
+        for (SceneEvaluationComputeParam sceneEvaluationComputeParam : sceneEvaluationComputeParams) {
+            // 创建场景路径
+            String scenePath = evaluationDirectoryOfUser + sceneEvaluationComputeParam.getSceneId();
+            if (!new File(scenePath).exists()) {
+                FileUtil.createDirectory(scenePath);
             } else {
+                // 一个场景只计算一次
                 return false;
             }
-        } catch (Exception e) {
-            log.error("文件下载失败", e);
-            return false;
+            try {
+                if (StringUtils.equals(sceneEvaluationComputeParam.getComputeType(), DictConstants.COMPLEXITY)) {
+                    if (StringUtil.isEmpty(sceneEvaluationComputeParam.getSceneXODRPath())
+                            || StringUtil.isEmpty(sceneEvaluationComputeParam.getSceneXOSCPath())) {
+                        continue;
+                    }
+                    // 计算复杂度,根据场景 id 获取场景信息,下载 osc odr
+                    String scenarioOsc = sceneEvaluationComputeParam.getSceneXOSCPath();
+                    String[] splitXosc = scenarioOsc.split("/");
+                    String xoscName = splitXosc[splitXosc.length - 1];
+                    MinioUtil.downloadToFile(minioClient, bucketName, sceneEvaluationComputeParam.getSceneXOSCPath(), scenePath + "/" + xoscName);
+                    String scenarioOdr = sceneEvaluationComputeParam.getSceneXODRPath();
+                    String[] splitXodr = scenarioOdr.split("/");
+                    String xodrName = splitXodr[splitXodr.length - 1];
+                    MinioUtil.downloadToFile(minioClient, bucketName, sceneEvaluationComputeParam.getSceneXODRPath(), scenePath + "/" + xodrName);
+                } else if (StringUtils.equals(sceneEvaluationComputeParam.getComputeType(), DictConstants.RISK)) {
+                    if (StringUtil.isEmpty(sceneEvaluationComputeParam.getEvaluationPath())) {
+                        continue;
+                    }
+                    // 计算危险度 从 minio path 下载 csv (ego 和 sensors)
+                    MinioUtil.downloadToFile(minioClient, bucketName, sceneEvaluationComputeParam.getEvaluationPath() + "/Ego.csv", scenePath + "/Ego.csv");
+                    MinioUtil.downloadToFile(minioClient, bucketName, sceneEvaluationComputeParam.getEvaluationPath() + "/evaluation.csv", scenePath + "/evaluation.csv");
+                } else {
+                    return false;
+                }
+            } catch (Exception e) {
+                log.error("文件下载失败", e);
+                FileUtil.deleteFolder(scenePath);   // 删除临时文件
+            }
+        }
+        String sceneEvaluationCommand;
+        if (StringUtils.equals(sceneEvaluationComputeParams.get(0).getComputeType(), DictConstants.COMPLEXITY)) {
+            sceneEvaluationCommand = pyMainPath + " " + scenePathFather + " complexity";
+        } else {
+            sceneEvaluationCommand = pyMainPath + " " + scenePathFather + " criticality";
         }
-        String sceneEvaluationCommand = "python3 " + pyMainPath + " " + (scenePath);
         String sceneEvaluationResult;
         log.info("开始执行场景评价命令:" + sceneEvaluationCommand);
         Runtime r = Runtime.getRuntime();
         Process p = null;
         try {
-            p = r.exec(sceneEvaluationCommand, null, new File(evaluationDirectoryOfUser + sceneEvaluationComputeParam.getSceneId()));
+            p = r.exec(sceneEvaluationCommand);
         } catch (IOException e) {
             log.error("执行场景评价脚本失败,脚本命令为: " + sceneEvaluationCommand, e);
             return false;
         }
-        BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
         StringBuilder sb = new StringBuilder();
-        String inline;
-        while (true) {
-            try {
-                if (null == (inline = br.readLine())) break;
-            } catch (IOException e) {
-                log.error("获取脚本返回内容失败", e);
-                return false;
-            }
-            sb.append(inline).append("\n");
-        }
-        sceneEvaluationResult = sb.toString();
-        log.info("场景" + sceneEvaluationComputeParam.getSceneId() + " 的场景评价结束,结果为:" + sceneEvaluationResult);
-        String replace = StringUtil.replace(sceneEvaluationResult, "'", "\"");
-        JsonNode rootNode;
         try {
-            ObjectMapper mapper = new ObjectMapper();
-            //JSON ----> JsonNode
-            rootNode = mapper.readTree(replace);
-        } catch (Exception e) {
-            log.error("场景" + sceneEvaluationComputeParam.getSceneId() + " 的场景评价失败:", e);
+            BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
+            String inline;
+            while ((inline = br.readLine()) != null) {
+                sb.append(inline).append("\n");
+            }
+            br.close();
+        } catch (IOException e) {
+            log.error("获取场景评价脚本返回内容失败", e);
             return false;
         }
-        if (StringUtils.equals(sceneEvaluationComputeParam.getComputeType(), DictConstants.COMPLEXITY)) {
-            String complexity = rootNode.path("复杂度").asText();
-            String complexityLevel = rootNode.path("复杂度等级").asText();
-            SceneComplexityPO sceneComplexityPO = new SceneComplexityPO();
-            sceneComplexityPO.setSceneId(sceneEvaluationComputeParam.getSceneId());
-            sceneComplexityPO.setComplexityId(StringUtil.getRandomUUID());
-            sceneComplexityPO.setSceneType(sceneEvaluationComputeParam.getSceneType());
-            sceneComplexityPO.setRuleId(ruleId);
-            sceneComplexityPO.setTaskId(sceneEvaluationComputeParam.getTaskId());
-            sceneComplexityPO.setComplexity(complexity);
-            sceneComplexityPO.setComplexityLevel(matchLevelEnumByLevel(complexityLevel));
-            sceneComplexityPO.setIsDeleted(DictConstants.IS_NOT_DELETED);
-            sceneComplexityPO.setCreateUserId(null);
-            sceneComplexityPO.setCreateTime(TimeUtil.getNowForMysql());
-            sceneComplexityMapper.saveSceneComplexity(sceneComplexityPO);
-        } else {
-            String risk = rootNode.path("危险度").asText();
-            String riskLevel = rootNode.path("危险度等级").asText();
-            SceneRiskPO sceneRiskPO = new SceneRiskPO();
-            sceneRiskPO.setSceneId(sceneEvaluationComputeParam.getSceneId());
-            sceneRiskPO.setRuleId(StringUtil.getRandomUUID());
-            sceneRiskPO.setSceneType(sceneEvaluationComputeParam.getSceneType());
-            sceneRiskPO.setRuleId(ruleId);
-            sceneRiskPO.setTaskId(sceneEvaluationComputeParam.getTaskId());
-            sceneRiskPO.setRisk(risk);
-            sceneRiskPO.setRiskLevel(matchLevelEnumByLevel(riskLevel));
-            sceneRiskPO.setIsDeleted(DictConstants.IS_NOT_DELETED);
-            sceneRiskPO.setCreateUserId(null);
-            sceneRiskPO.setCreateTime(TimeUtil.getNowForMysql());
-            sceneRiskMapper.saveSceneRisk(sceneRiskPO);
+        sceneEvaluationResult = sb.toString();
+        log.info("场景评价结束,结果为:" + sceneEvaluationResult);
+        for (SceneEvaluationComputeParam sceneEvaluationComputeParam : sceneEvaluationComputeParams) {
+            // 读文件
+            StringBuilder result = new StringBuilder();
+            try {
+                FileInputStream fileInputStream = new FileInputStream(scenePathFather + sceneEvaluationComputeParam.getSceneId() + "/scenario_evaluation.json");
+                BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(fileInputStream));
+
+                String line;
+                while ((line = bufferedReader.readLine()) != null) {
+                    result.append(line).append("\n");
+                }
+                bufferedReader.close();
+            } catch (IOException e) {
+                log.error("读取场景评价结果失败", e);
+                continue;
+            }
+            String resultStr = result.toString();
+            String replace = StringUtil.replace(resultStr, "'", "\"");
+            JsonNode rootNode;
+            try {
+                ObjectMapper mapper = new ObjectMapper();
+                //JSON ----> JsonNode
+                rootNode = mapper.readTree(replace);
+            } catch (Exception e) {
+                log.error("场景" + sceneEvaluationComputeParam.getSceneId() + " 的场景评价失败:", e);
+                continue;
+            }
+            if (StringUtils.equals(sceneEvaluationComputeParam.getComputeType(), DictConstants.COMPLEXITY)) {
+                String complexity = rootNode.path("复杂度").asText();
+                String complexityLevel = rootNode.path("复杂度等级").asText();
+                SceneComplexityPO sceneComplexityPO = new SceneComplexityPO();
+                sceneComplexityPO.setSceneId(sceneEvaluationComputeParam.getSceneId());
+                sceneComplexityPO.setComplexityId(StringUtil.getRandomUUID());
+                sceneComplexityPO.setSceneType(sceneEvaluationComputeParam.getSceneType());
+                sceneComplexityPO.setRuleId(ruleId);
+                sceneComplexityPO.setTaskId(sceneEvaluationComputeParam.getTaskId());
+                sceneComplexityPO.setComplexity(complexity);
+                sceneComplexityPO.setComplexityLevel(matchLevelEnumByLevel(complexityLevel));
+                sceneComplexityPO.setIsDeleted(DictConstants.IS_NOT_DELETED);
+                sceneComplexityPO.setCreateUserId(null);
+                sceneComplexityPO.setCreateTime(TimeUtil.getNowForMysql());
+                sceneComplexityMapper.saveSceneComplexity(sceneComplexityPO);
+            } else {
+                String risk = rootNode.path("危险度").asText();
+                String riskLevel = rootNode.path("危险度等级").asText();
+                SceneRiskPO sceneRiskPO = new SceneRiskPO();
+                sceneRiskPO.setSceneId(sceneEvaluationComputeParam.getSceneId());
+                sceneRiskPO.setRuleId(StringUtil.getRandomUUID());
+                sceneRiskPO.setSceneType(sceneEvaluationComputeParam.getSceneType());
+                sceneRiskPO.setRuleId(ruleId);
+                sceneRiskPO.setTaskId(sceneEvaluationComputeParam.getTaskId());
+                sceneRiskPO.setRisk(risk);
+                sceneRiskPO.setRiskLevel(matchLevelEnumByLevel(riskLevel));
+                sceneRiskPO.setIsDeleted(DictConstants.IS_NOT_DELETED);
+                sceneRiskPO.setCreateUserId(null);
+                sceneRiskPO.setCreateTime(TimeUtil.getNowForMysql());
+                sceneRiskMapper.saveSceneRisk(sceneRiskPO);
+            }
         }
+        // 删除临时文件
+        FileUtil.deleteFolder(linuxTempPath + "scene/evaluation/" + sceneEvaluationComputeParams.get(0).getTaskId());   // 删除临时文件
         return true;
     }
 

+ 1 - 1
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/infra/configuration/kubernetes/KubernetesConfiguration.java

@@ -51,7 +51,7 @@ public class KubernetesConfiguration {
     @SneakyThrows
     public ApiClient apiClient() {
 //        File config = ResourceUtils.getFile("classpath:kubernetes/config");  // 开发环境可用,生产环境不行,无法从jar 包读取
-//        File config = new File("D:\\idea-project\\simulation-cloud\\simulation-resource-scheduler\\src\\main\\resources\\kubernetes\\config");  //windows
+//        File config = new File("E:\\project\\simulation-cloud\\simulation-resource-scheduler\\src\\main\\resources\\kubernetes\\config");  //windows
         File config = new File("/root/.kube/config");   //linux
 //
 //        ClassPathResource classPathResource = new ClassPathResource("kubernetes/config");

+ 1 - 1
simulation-resource-server/src/main/java/com/css/simulation/resource/server/adapter/controller/scene_library/score_rule/ScoreRuleController.java

@@ -189,7 +189,7 @@ public class ScoreRuleController {
      * 新增场景评价规则
      */
     @PostMapping("/saveSceneEvaluationRule")
-    public ResponseBodyVO<String> saveSceneEvaluationRule(@RequestParam("file") MultipartFile file, @RequestPart("content") SceneEvaluationRulePO sceneEvaluationRulePO) {
+    public ResponseBodyVO<String> saveSceneEvaluationRule(@RequestParam(value = "file", required = false) MultipartFile file, @RequestPart("content") SceneEvaluationRulePO sceneEvaluationRulePO) {
         if (ObjectUtil.isNull(sceneEvaluationRulePO.getRuleName())) {
             return new ResponseBodyVO<>(ResponseBodyVO.Response.CLIENT_FAILURE, "参数 RulesName 不能为空,请检查");
         }

+ 20 - 0
simulation-resource-server/src/main/java/com/css/simulation/resource/server/app/impl/SimulationProjectServiceImpl.java

@@ -20,6 +20,7 @@ import api.common.pojo.po.model.ConfigSensorPO;
 import api.common.pojo.po.model.VehiclePO;
 import api.common.pojo.po.project.*;
 import api.common.pojo.po.scene.SceneComplexityPO;
+import api.common.pojo.po.scene.SceneEvaluationRulePO;
 import api.common.pojo.po.scene.ScenePackagePO;
 import api.common.pojo.po.scene.SceneRiskPO;
 import api.common.pojo.vo.algorithm.AlgorithmVO;
@@ -122,6 +123,8 @@ public class SimulationProjectServiceImpl implements SimulationProjectService {
     private SceneComplexityMapper sceneComplexityMapper;
     @Resource
     private SceneRiskMapper sceneRiskMapper;
+    @Resource
+    private SceneEvaluationRuleMapper sceneEvaluationRuleMapper;
 
     // * -------------------------------- Comment --------------------------------
 
@@ -227,6 +230,23 @@ public class SimulationProjectServiceImpl implements SimulationProjectService {
 
         SimulationManualProjectSingleVo vo = new SimulationManualProjectSingleVo();
         convertPoToVo(po, vo);
+        if (StringUtil.isNotEmpty(po.getComplexityEvaluationRuleId())) {
+            SceneEvaluationRulePO sceneComRule = sceneEvaluationRuleMapper.querySceneEvaluationPyById(po.getComplexityEvaluationRuleId());
+            vo.setComplexityEvaluationRuleName(sceneComRule == null ? null : sceneComRule.getRuleName());
+        }
+        if (StringUtil.isNotEmpty(po.getRiskEvaluationRuleId())) {
+            SceneEvaluationRulePO sceneRiskRule = sceneEvaluationRuleMapper.querySceneEvaluationPyById(po.getRiskEvaluationRuleId());
+            vo.setRiskEvaluationRuleName(sceneRiskRule == null ? null : sceneRiskRule.getRuleName());
+        }
+        if (StringUtil.isNotEmpty(po.getCoverageRateEvaluationRuleId())) {
+            SceneEvaluationRulePO sceneCoverRule = sceneEvaluationRuleMapper.querySceneEvaluationPyById(po.getCoverageRateEvaluationRuleId());
+            vo.setCoverageRateEvaluationRuleName(sceneCoverRule == null ? null : sceneCoverRule.getRuleName());
+        }
+        if (StringUtil.isNotEmpty(po.getExposureRateEvaluationRuleId())) {
+            SceneEvaluationRulePO sceneExposureRule = sceneEvaluationRuleMapper.querySceneEvaluationPyById(po.getExposureRateEvaluationRuleId());
+            vo.setExposureRateEvaluationRuleName(sceneExposureRule == null ? null : sceneExposureRule.getRuleName());
+        }
+
         if (ObjectUtil.isNotNull(po.getAlgorithmArray())) {
             vo.setAlgorithmArrayS(po.getAlgorithmArray().split(","));
         }

+ 11 - 1
simulation-resource-server/src/main/java/com/css/simulation/resource/server/app/service/DictService.java

@@ -3,9 +3,11 @@ package com.css.simulation.resource.server.app.service;
 import api.common.pojo.common.ResponseBodyVO;
 import api.common.pojo.param.RedisParameter;
 import api.common.pojo.param.system.DictParam;
+import api.common.pojo.po.system.DictPO;
 import api.common.pojo.vo.system.DictVO;
 import api.common.util.JsonUtil;
 import api.common.util.ObjectUtil;
+import api.common.util.StringUtil;
 import com.css.simulation.resource.server.infra.feign.service.RedisService;
 import com.css.simulation.resource.server.infra.db.mysql.mapper.DictMapper;
 import lombok.SneakyThrows;
@@ -125,7 +127,7 @@ public class DictService {
         for (String key : keySet) {
             String val = map.get(key);
             //json转map
-            Map<String,String> hashMap = JsonUtil.jsonToMap(val);
+            Map<String, String> hashMap = JsonUtil.jsonToMap(val);
             dictMaps.put(key, hashMap);
         }
         return dictMaps;
@@ -162,4 +164,12 @@ public class DictService {
         return dictMap;
     }
 
+    public void deleteSystemDictByCodeAndType(DictPO dictPO) {
+        dictMapper.deleteSystemDictByCodeAndType(dictPO);
+    }
+
+    public void createSystemDict(DictPO dictPO) {
+        dictPO.setId(StringUtil.getRandomUUID());
+        dictMapper.createSystemDict(dictPO);
+    }
 }

+ 24 - 14
simulation-resource-server/src/main/java/com/css/simulation/resource/server/app/service/SceneAccidentService.java

@@ -234,7 +234,8 @@ public class SceneAccidentService {
         Map<String, SceneRiskPO> riskPOMap = sceneEvaluationOperatePO.getSceneRiskPOMap();
         // 筛选
         List<SceneAccidentPO> sceneAccidentPOS = list.stream()
-                .filter(sn -> complexityPOMap.get(sn.getAccidentId()) != null && riskPOMap.get(sn.getAccidentId()) != null)
+                .filter(sn -> sceneEvaluationRuleService.checkSelectReferenceComplexity(sn.getAccidentId(), sceneEvaluationForListParam, complexityPOMap) &&
+                        sceneEvaluationRuleService.checkSelectReferenceRisk(sn.getAccidentId(), sceneEvaluationForListParam, riskPOMap))
                 .collect(Collectors.toList());
 
      /*   if ((params.getXlk().equals("1") && params.getBq().equals(1)) || (params.getXlk().equals("0") && params.getBq().equals(0)) || (params.getXlk().equals("1") && params.getBq().equals(0))) {
@@ -303,10 +304,15 @@ public class SceneAccidentService {
 
         for (SceneAccidentPO po : sceneAccidentPOS) {
             // 赋值复杂度
-            po.setComplexity(String.valueOf(complexityPOMap.get(po.getAccidentId()).getComplexity()));
-            po.setComplexityLevel(String.valueOf(complexityPOMap.get(po.getAccidentId()).getComplexityLevel()));
-            po.setRisk(String.valueOf(riskPOMap.get(po.getAccidentId()).getRisk()));
-            po.setRiskLevel(String.valueOf(riskPOMap.get(po.getAccidentId()).getRiskLevel()));
+            // 赋值复杂度
+            if (complexityPOMap.get(po.getAccidentId()) != null) {
+                po.setComplexity(String.valueOf(complexityPOMap.get(po.getAccidentId()).getComplexity()));
+                po.setComplexityLevel(String.valueOf(complexityPOMap.get(po.getAccidentId()).getComplexityLevel()));
+            }
+            if (riskPOMap.get(po.getAccidentId()) != null) {
+                po.setRisk(String.valueOf(riskPOMap.get(po.getAccidentId()).getRisk()));
+                po.setRiskLevel(String.valueOf(riskPOMap.get(po.getAccidentId()).getRiskLevel()));
+            }
             if (po.getConflictBehavior().contains("追尾")) {
                 po.setLabel("追尾");
             }
@@ -773,6 +779,7 @@ public class SceneAccidentService {
                     List<String> listScene = fileDownService.listDeepOne(MI).getInfo();
                     log.info("共需要上传 " + listScene.size() + " 个交通事故场景");
                     String taskId = api.common.util.StringUtil.getRandomUUID();
+                    List<SceneEvaluationComputeParam> paramList = new ArrayList<>();
                     for (String scenePath : listScene) {
                         try {
                             MI.setObjectName(scenePath);
@@ -873,22 +880,18 @@ public class SceneAccidentService {
 
                             // 计算复杂度
                             if (!StringUtils.isEmpty(params.getSceneEvaluationRuleId())) {
-                                String tempSceneId = scenes.get(0).getAccidentId();
                                 SceneEvaluationComputeParam sceneEvaluationComputeParam = new SceneEvaluationComputeParam();
-                                sceneEvaluationComputeParam.setSceneId(isupdate.equals("0") ? tempSceneId : sceneAccidentPO.getAccidentId());
+                                sceneEvaluationComputeParam.setSceneId(isupdate.equals("0") ? sceneAccidentPO.getAccidentId() : scenes.get(0).getAccidentId());
                                 sceneEvaluationComputeParam.setSceneXOSCPath(sceneAccidentPO.getXmlAddress());
                                 sceneEvaluationComputeParam.setSceneXODRPath(sceneAccidentPO.getXodrAddress());
                                 sceneEvaluationComputeParam.setSceneType(DictConstants.SCENE_ACCIDENT);
                                 sceneEvaluationComputeParam.setTaskId(taskId);
                                 sceneEvaluationComputeParam.setComputeType(DictConstants.COMPLEXITY);
-                                try {
-                                    boolean sceneEvaluationResult = sceneEvaluationRuleService.computeSceneReference(params, sceneEvaluationComputeParam);
-                                    if (isupdate.equals("0") && sceneEvaluationResult) {
-                                        sceneEvaluationRuleService.copySceneComplexityResult(taskId, tempSceneId, scenes.stream().map(SceneAccidentPO::getAccidentId).filter(sceneId -> !StringUtils.equals(tempSceneId, sceneId)).collect(Collectors.toList()));
-                                    }
-                                } catch (Exception e) {
-                                    log.error("计算复杂度失败", e);
+                                if (isupdate.equals("1")) {
+                                    String tempSceneId = scenes.get(0).getAccidentId();
+                                    sceneEvaluationComputeParam.setCopySceneId(scenes.stream().map(SceneAccidentPO::getAccidentId).filter(sceneId -> !StringUtils.equals(tempSceneId, sceneId)).collect(Collectors.toList()));
                                 }
+                                paramList.add(sceneEvaluationComputeParam);
                             }
                         } catch (Exception e) {
                             errorMessage = e.getMessage();
@@ -896,6 +899,13 @@ public class SceneAccidentService {
                             falseNum = falseNum + 1;
                         }
                     }
+                    try {
+                        if (CollectionUtil.isNotEmpty(paramList)) {
+                            sceneEvaluationRuleService.computeSceneReference(params, paramList);
+                        }
+                    } catch (Exception e) {
+                        log.error("计算复杂度失败", e);
+                    }
                 }
             }
             sceneImportPO.setStatus(DictConstants.SCENE_IMPORT_STATUS_4);

+ 179 - 114
simulation-resource-server/src/main/java/com/css/simulation/resource/server/app/service/SceneEvaluationRuleService.java

@@ -31,10 +31,10 @@ import javax.annotation.Resource;
 import java.io.*;
 import java.nio.charset.StandardCharsets;
 import java.nio.file.Files;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.attribute.PosixFilePermission;
+import java.util.*;
 import java.util.function.Function;
 import java.util.stream.Collectors;
 
@@ -48,9 +48,6 @@ public class SceneEvaluationRuleService {
     @Value("${server.linux-path.temp}")
     private String linuxTempPath;
 
-    @Value("${server.scene-evaluation.script}")
-    private String sceneEvaluationScript;
-
     @Resource
     private ScenePackageMapper scenePackageMapper;
 
@@ -89,12 +86,12 @@ public class SceneEvaluationRuleService {
                 return new ResponseBodyVO<>(ResponseBodyVO.Response.CLIENT_FAILURE, "非管理员禁止上传文件");
             }
             // 检查文件内容是否合规
-            String pyStr = new String(file.getBytes(), StandardCharsets.UTF_8);
-            //1 校验 python 语法错误
-            String pylint = PythonUtil.pylint(pyStr, PythonUtil.C, PythonUtil.R, PythonUtil.W, PythonUtil.E0401, PythonUtil.E0601);
-            if (!pylint.contains(PythonUtil.PASS)) {
-                return new ResponseBodyVO<>(ResponseBodyVO.Response.CLIENT_FAILURE, "代码格式错误,请检查。");
-            }
+//            String pyStr = new String(file.getBytes(), StandardCharsets.UTF_8);
+//            //1 校验 python 语法错误
+//            String pylint = PythonUtil.pylint(pyStr, PythonUtil.C, PythonUtil.R, PythonUtil.W, PythonUtil.E0401, PythonUtil.E0601);
+//            if (!pylint.contains(PythonUtil.PASS)) {
+//                return new ResponseBodyVO<>(ResponseBodyVO.Response.CLIENT_FAILURE, "代码格式错误,请检查。");
+//            }
             // 获取文件原本的名字
             String originName = file.getOriginalFilename();
             if (null == originName) {
@@ -161,7 +158,7 @@ public class SceneEvaluationRuleService {
         if (sceneEvaluationRulePO == null) {
             return false;
         }
-        return StringUtils.equals(DictConstants.COMPLEXITY, sceneEvaluationRulePO.getRuleId());
+        return StringUtils.equals(DictConstants.COMPLEXITY, sceneEvaluationRulePO.getRuleType());
     }
 
 
@@ -225,7 +222,7 @@ public class SceneEvaluationRuleService {
      *
      * @param param
      */
-    public boolean computeSceneReference(SceneImportParam param, SceneEvaluationComputeParam sceneEvaluationComputeParam) {
+    public boolean computeSceneReference(SceneImportParam param, List<SceneEvaluationComputeParam> sceneEvaluationComputeParams) {
         String ruleId = param.getSceneEvaluationRuleId();
         // 获取场景评价规则
         SceneEvaluationRulePO sceneEvaluationRulePO = sceneEvaluationRuleMapper.querySceneEvaluationPyById(ruleId);
@@ -234,137 +231,187 @@ public class SceneEvaluationRuleService {
             return false;
         }
         // 1 判断有没有用户目录,没有则复制
-        String evaluationDirectoryOfUser = linuxTempPath + "scene/evaluation/" + sceneEvaluationComputeParam.getTaskId() + "/";
-        String scriptsPath = evaluationDirectoryOfUser + "scripts/";
+        String evaluationDirectoryOfUser = linuxTempPath + "scene/evaluation/" + sceneEvaluationComputeParams.get(0).getTaskId() + "/";
+        String scriptsPath = evaluationDirectoryOfUser + "scripts";
         if (!new File(evaluationDirectoryOfUser).exists()) {
             // 1 将场景评价规则脚本保存到 script 目录
             FileUtil.createDirectory(scriptsPath);
-            final ArrayList<String> scriptFilePath = CollectionUtil.createArrayList(
-                    "/data_preprocessing.py",
-                    "/elevation.py",
-                    "/scenario_criticality_algorithm.py",
-                    "/scenario_evaluation_main.py",
-                    "/scenario_evaluation_utils52.py"
-            );
-            for (String pyFilePath : scriptFilePath) {
-                try {
-                    downloadDependFile(sceneEvaluationScript + pyFilePath, scriptsPath + pyFilePath);
-                } catch (IOException e) {
-                    log.error("下载 py 依赖文件失败: " + sceneEvaluationScript + pyFilePath, e);
-                    return false;
-                }
-            }
+//            final ArrayList<String> scriptFilePath = CollectionUtil.createArrayList(
+//                    "/data_preprocessing.py",
+//                    "/elevation.py",
+//                    "/scenario_evaluation_utils52.py"
+//            );
+//            for (String pyFilePath : scriptFilePath) {
+//                try {
+//                    downloadDependFile(sceneEvaluationScript + pyFilePath, scriptsPath + pyFilePath);
+//                } catch (IOException e) {
+//                    log.error("下载 py 依赖文件失败: " + sceneEvaluationScript + pyFilePath, e);
+//                    return false;
+//                }
+//            }
         }
+
         // 下载场景评价脚本到脚本目录
         if (sceneEvaluationRulePO.getScriptPath() == null) {
             return false;
         }
-        String pyMainPath = scriptsPath + "/" + sceneEvaluationRulePO.getRuleId() + ".py";
+        String pyMainPath = scriptsPath + "/" + sceneEvaluationRulePO.getRuleId();
         if (!new File(pyMainPath).exists()) {
             try {
                 downloadDependFile(sceneEvaluationRulePO.getScriptPath(), pyMainPath);
+                Path path = Paths.get(pyMainPath);
+                Set<PosixFilePermission> permissions = new HashSet<>();
+                permissions.add(PosixFilePermission.OWNER_READ);
+                permissions.add(PosixFilePermission.OWNER_WRITE);
+                permissions.add(PosixFilePermission.OWNER_EXECUTE);
+                permissions.add(PosixFilePermission.GROUP_READ);
+                permissions.add(PosixFilePermission.GROUP_WRITE);
+                permissions.add(PosixFilePermission.GROUP_EXECUTE);
+                permissions.add(PosixFilePermission.OTHERS_READ);
+                permissions.add(PosixFilePermission.OTHERS_WRITE);
+                permissions.add(PosixFilePermission.OTHERS_EXECUTE);
+                Files.setPosixFilePermissions(path, permissions);
             } catch (IOException e) {
-                log.error("下载 py 执行文件失败: " + sceneEvaluationRulePO.getScriptPath(), e);
+                log.error("下载执行文件失败: " + sceneEvaluationRulePO.getScriptPath(), e);
                 return false;
             }
         }
-        // 创建场景路径
-        String scenePath = evaluationDirectoryOfUser + sceneEvaluationComputeParam.getSceneId();
-        if (!new File(scenePath).exists()) {
-            FileUtil.createDirectory(scenePath);
-        } else {
-            // 一个场景只计算一次
-            return false;
-        }
-        try {
-            if (StringUtils.equals(sceneEvaluationComputeParam.getComputeType(), DictConstants.COMPLEXITY)) {
-                // 计算复杂度,根据场景 id 获取场景信息,下载 osc odr
-                String scenarioOsc = sceneEvaluationComputeParam.getSceneXOSCPath();
-                String[] splitXosc = scenarioOsc.split("/");
-                String xoscName = splitXosc[splitXosc.length - 1];
-                downloadDependFile(sceneEvaluationComputeParam.getSceneXOSCPath(), scenePath + "/" + xoscName);
-
-                String scenarioOdr = sceneEvaluationComputeParam.getSceneXODRPath();
-                String[] splitXodr = scenarioOdr.split("/");
-                String xodrName = splitXodr[splitXodr.length - 1];
-                downloadDependFile(sceneEvaluationComputeParam.getSceneXODRPath(), scenePath + "/" + xodrName);
-            } else if (StringUtils.equals(sceneEvaluationComputeParam.getComputeType(), DictConstants.RISK)) {
-                // 计算危险度 从 minio path 下载 csv (ego 和 sensors)
-                downloadDependFile(sceneEvaluationComputeParam.getEvaluationPath() + "/Ego.csv", scenePath + "/Ego.csv");
-                downloadDependFile(sceneEvaluationComputeParam.getEvaluationPath() + "/sensors.csv", scenePath + "/sensors.csv");
+        String scenePathFather = evaluationDirectoryOfUser + "scene/";
+        for (SceneEvaluationComputeParam sceneEvaluationComputeParam : sceneEvaluationComputeParams) {
+            // 创建场景路径
+            String scenePath = scenePathFather + sceneEvaluationComputeParam.getSceneId();
+            if (!new File(scenePath).exists()) {
+                FileUtil.createDirectory(scenePath);
             } else {
+                // 一个场景只计算一次
                 return false;
             }
-        } catch (IOException e) {
-            log.error("文件下载失败", e);
-            return false;
+            try {
+                if (StringUtils.equals(sceneEvaluationComputeParam.getComputeType(), DictConstants.COMPLEXITY)) {
+                    if (StringUtil.isEmpty(sceneEvaluationComputeParam.getSceneXODRPath())
+                            || StringUtil.isEmpty(sceneEvaluationComputeParam.getSceneXOSCPath())) {
+                        continue;
+                    }
+                    // 计算复杂度,根据场景 id 获取场景信息,下载 osc odr
+                    String scenarioOsc = sceneEvaluationComputeParam.getSceneXOSCPath();
+                    String[] splitXosc = scenarioOsc.split("/");
+                    String xoscName = splitXosc[splitXosc.length - 1];
+                    downloadDependFile(sceneEvaluationComputeParam.getSceneXOSCPath(), scenePath + "/" + xoscName);
+
+                    String scenarioOdr = sceneEvaluationComputeParam.getSceneXODRPath();
+                    String[] splitXodr = scenarioOdr.split("/");
+                    String xodrName = splitXodr[splitXodr.length - 1];
+                    downloadDependFile(sceneEvaluationComputeParam.getSceneXODRPath(), scenePath + "/" + xodrName);
+                } else if (StringUtils.equals(sceneEvaluationComputeParam.getComputeType(), DictConstants.RISK)) {
+                    if (StringUtil.isEmpty(sceneEvaluationComputeParam.getEvaluationPath())) {
+                        continue;
+                    }
+                    // 计算危险度 从 minio path 下载 csv (ego 和 sensors)
+                    downloadDependFile(sceneEvaluationComputeParam.getEvaluationPath() + "/Ego.csv", scenePath + "/Ego.csv");
+                    downloadDependFile(sceneEvaluationComputeParam.getEvaluationPath() + "/evaluation.csv", scenePath + "/evaluation.csv");
+                } else {
+                    return false;
+                }
+            } catch (IOException e) {
+                log.error("文件下载失败", e);
+                FileUtil.deleteFolder(scenePath);   // 删除临时文件
+            }
+        }
+        String sceneEvaluationCommand;
+        if (StringUtils.equals(sceneEvaluationComputeParams.get(0).getComputeType(), DictConstants.COMPLEXITY)) {
+            sceneEvaluationCommand = pyMainPath + " " + scenePathFather + " complexity";
+        } else {
+            sceneEvaluationCommand = pyMainPath + " " + scenePathFather + " criticality";
         }
-        String sceneEvaluationCommand = "python3 " + pyMainPath + " " + (scenePath);
         String sceneEvaluationResult;
         log.info("开始执行场景评价命令:" + sceneEvaluationCommand);
         Runtime r = Runtime.getRuntime();
-        Process p = null;
+        Process p;
         try {
-            p = r.exec(sceneEvaluationCommand, null, new File(evaluationDirectoryOfUser + sceneEvaluationComputeParam.getSceneId()));
+            p = r.exec(sceneEvaluationCommand);
         } catch (IOException e) {
             log.error("执行场景评价脚本失败,脚本命令为: " + sceneEvaluationCommand, e);
             return false;
         }
-        BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
+
         StringBuilder sb = new StringBuilder();
-        String inline;
-        while (true) {
-            try {
-                if (null == (inline = br.readLine())) break;
-            } catch (IOException e) {
-                log.error("获取脚本返回内容失败", e);
-                return false;
-            }
-            sb.append(inline).append("\n");
-        }
-        sceneEvaluationResult = sb.toString();
-        log.info("场景" + sceneEvaluationComputeParam.getSceneId() + " 的场景评价结束,结果为:" + sceneEvaluationResult);
-        String replace = StringUtil.replace(sceneEvaluationResult, "'", "\"");
-        JsonNode rootNode;
         try {
-            ObjectMapper mapper = new ObjectMapper();
-            //JSON ----> JsonNode
-            rootNode = mapper.readTree(replace);
-        } catch (Exception e) {
-            log.error("场景" + sceneEvaluationComputeParam.getSceneId() + " 的场景评价失败:", e);
+            BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
+            String inline;
+            while ((inline = br.readLine()) != null) {
+                sb.append(inline).append("\n");
+            }
+            br.close();
+        } catch (IOException e) {
+            log.error("获取场景评价脚本返回内容失败", e);
             return false;
         }
-        if (StringUtils.equals(sceneEvaluationComputeParam.getComputeType(), DictConstants.COMPLEXITY)) {
-            String complexity = rootNode.path("复杂度").asText();
-            String complexityLevel = rootNode.path("复杂度等级").asText();
-            SceneComplexityPO sceneComplexityPO = new SceneComplexityPO();
-            sceneComplexityPO.setSceneId(sceneEvaluationComputeParam.getSceneId());
-            sceneComplexityPO.setComplexityId(StringUtil.getRandomUUID());
-            sceneComplexityPO.setSceneType(sceneEvaluationComputeParam.getSceneType());
-            sceneComplexityPO.setRuleId(ruleId);
-            sceneComplexityPO.setTaskId(sceneEvaluationComputeParam.getTaskId());
-            sceneComplexityPO.setComplexity(complexity);
-            sceneComplexityPO.setComplexityLevel(matchLevelEnumByLevel(complexityLevel));
-            sceneComplexityPO.setIsDeleted(DictConstants.IS_NOT_DELETED);
-            sceneComplexityPO.setCreateUserId(AuthUtil.getCurrentUserId());
-            sceneComplexityPO.setCreateTime(TimeUtil.getNowForMysql());
-            sceneComplexityMapper.saveSceneComplexity(sceneComplexityPO);
-        } else {
-            String risk = rootNode.path("危险度").asText();
-            String riskLevel = rootNode.path("危险度等级").asText();
-            SceneRiskPO sceneRiskPO = new SceneRiskPO();
-            sceneRiskPO.setSceneId(sceneEvaluationComputeParam.getSceneId());
-            sceneRiskPO.setRuleId(StringUtil.getRandomUUID());
-            sceneRiskPO.setSceneType(sceneEvaluationComputeParam.getSceneType());
-            sceneRiskPO.setRuleId(ruleId);
-            sceneRiskPO.setTaskId(sceneEvaluationComputeParam.getTaskId());
-            sceneRiskPO.setRisk(risk);
-            sceneRiskPO.setRiskLevel(matchLevelEnumByLevel(riskLevel));
-            sceneRiskPO.setIsDeleted(DictConstants.IS_NOT_DELETED);
-            sceneRiskPO.setCreateUserId(AuthUtil.getCurrentUserId());
-            sceneRiskPO.setCreateTime(TimeUtil.getNowForMysql());
-            sceneRiskMapper.saveSceneRisk(sceneRiskPO);
+        sceneEvaluationResult = sb.toString();
+        log.info("场景评价结束,结果为:" + sceneEvaluationResult);
+        for (SceneEvaluationComputeParam sceneEvaluationComputeParam : sceneEvaluationComputeParams) {
+            // 读文件
+            StringBuilder result = new StringBuilder();
+            try {
+                FileInputStream fileInputStream = new FileInputStream(scenePathFather + sceneEvaluationComputeParam.getSceneId() + "/scenario_evaluation.json");
+                BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(fileInputStream));
+
+                String line;
+                while ((line = bufferedReader.readLine()) != null) {
+                    result.append(line).append("\n");
+                }
+                bufferedReader.close();
+            } catch (IOException e) {
+                log.error("读取场景评价结果失败", e);
+                continue;
+            }
+            String resultStr = result.toString();
+            String replace = StringUtil.replace(resultStr, "'", "\"");
+            JsonNode rootNode;
+            try {
+                ObjectMapper mapper = new ObjectMapper();
+                //JSON ----> JsonNode
+                rootNode = mapper.readTree(replace);
+
+                if (StringUtils.equals(sceneEvaluationComputeParam.getComputeType(), DictConstants.COMPLEXITY)) {
+                    String complexity = rootNode.path("复杂度").asText();
+                    String complexityLevel = rootNode.path("复杂度等级").asText();
+                    SceneComplexityPO sceneComplexityPO = new SceneComplexityPO();
+                    sceneComplexityPO.setSceneId(sceneEvaluationComputeParam.getSceneId());
+                    sceneComplexityPO.setComplexityId(StringUtil.getRandomUUID());
+                    sceneComplexityPO.setSceneType(sceneEvaluationComputeParam.getSceneType());
+                    sceneComplexityPO.setRuleId(ruleId);
+                    sceneComplexityPO.setTaskId(sceneEvaluationComputeParam.getTaskId());
+                    sceneComplexityPO.setComplexity(complexity);
+                    sceneComplexityPO.setComplexityLevel(matchLevelEnumByLevel(complexityLevel));
+                    sceneComplexityPO.setIsDeleted(DictConstants.IS_NOT_DELETED);
+                    sceneComplexityPO.setCreateUserId(AuthUtil.getCurrentUserId());
+                    sceneComplexityPO.setCreateTime(TimeUtil.getNowForMysql());
+                    sceneComplexityMapper.saveSceneComplexity(sceneComplexityPO);
+                    if (CollectionUtil.isNotEmpty(sceneEvaluationComputeParam.getCopySceneId())) {
+                        copySceneComplexityResult(sceneEvaluationComputeParam.getTaskId(), sceneEvaluationComputeParam.getSceneId(), sceneEvaluationComputeParam.getCopySceneId());
+                    }
+                } else {
+                    String risk = rootNode.path("危险度").asText();
+                    String riskLevel = rootNode.path("危险度等级").asText();
+                    SceneRiskPO sceneRiskPO = new SceneRiskPO();
+                    sceneRiskPO.setSceneId(sceneEvaluationComputeParam.getSceneId());
+                    sceneRiskPO.setRuleId(StringUtil.getRandomUUID());
+                    sceneRiskPO.setSceneType(sceneEvaluationComputeParam.getSceneType());
+                    sceneRiskPO.setRuleId(ruleId);
+                    sceneRiskPO.setTaskId(sceneEvaluationComputeParam.getTaskId());
+                    sceneRiskPO.setRisk(risk);
+                    sceneRiskPO.setRiskLevel(matchLevelEnumByLevel(riskLevel));
+                    sceneRiskPO.setIsDeleted(DictConstants.IS_NOT_DELETED);
+                    sceneRiskPO.setCreateUserId(AuthUtil.getCurrentUserId());
+                    sceneRiskPO.setCreateTime(TimeUtil.getNowForMysql());
+                    sceneRiskMapper.saveSceneRisk(sceneRiskPO);
+                }
+            } catch (Exception e) {
+                log.error("场景" + sceneEvaluationComputeParam.getSceneId() + " 的场景评价失败:", e);
+            }
         }
+        // 删除临时文件
+//        FileUtil.deleteFolder(linuxTempPath + "scene/evaluation/" + sceneEvaluationComputeParams.get(0).getTaskId());   // 删除临时文件
         return true;
     }
 
@@ -403,4 +450,22 @@ public class SceneEvaluationRuleService {
             }
         }
     }
+
+    public boolean checkSelectReferenceComplexity(String sceneId, SceneEvaluationForListParam sceneEvaluationForListParam, Map<String, SceneComplexityPO> complexityPOMap) {
+        if (StringUtil.isEmpty(sceneEvaluationForListParam.getMinComplexity()) &&
+                StringUtil.isEmpty(sceneEvaluationForListParam.getMaxComplexity()) &&
+                StringUtil.isEmpty(sceneEvaluationForListParam.getComplexityLevel())) {
+            return true;
+        }
+        return complexityPOMap.get(sceneId) != null;
+    }
+
+    public boolean checkSelectReferenceRisk(String sceneId, SceneEvaluationForListParam sceneEvaluationForListParam, Map<String, SceneRiskPO> riskPOMap) {
+        if (StringUtil.isEmpty(sceneEvaluationForListParam.getMinRisk()) &&
+                StringUtil.isEmpty(sceneEvaluationForListParam.getMaxRisk()) &&
+                StringUtil.isEmpty(sceneEvaluationForListParam.getRiskLevel())) {
+            return true;
+        }
+        return riskPOMap.get(sceneId) != null;
+    }
 }

+ 25 - 14
simulation-resource-server/src/main/java/com/css/simulation/resource/server/app/service/SceneNaturalService.java

@@ -312,16 +312,22 @@ public class SceneNaturalService {
         Map<String, SceneRiskPO> riskPOMap = sceneEvaluationOperatePO.getSceneRiskPOMap();
         // 筛选
         List<SceneNaturalPO> finalSceneNaturalList = list.stream()
-                .filter(sn -> complexityPOMap.get(sn.getNaturalId()) != null && riskPOMap.get(sn.getNaturalId()) != null)
+                .filter(sn -> sceneEvaluationRuleService.checkSelectReferenceComplexity(sn.getNaturalId(), sceneEvaluationForListParam, complexityPOMap) &&
+                        sceneEvaluationRuleService.checkSelectReferenceRisk(sn.getNaturalId(), sceneEvaluationForListParam, riskPOMap))
                 .collect(Collectors.toList());
 
 
         for (SceneNaturalPO vo : finalSceneNaturalList) {
             // 赋值复杂度
-            vo.setComplexity(String.valueOf(complexityPOMap.get(vo.getNaturalId()).getComplexity()));
-            vo.setComplexityLevel(String.valueOf(complexityPOMap.get(vo.getNaturalId()).getComplexityLevel()));
-            vo.setRisk(String.valueOf(riskPOMap.get(vo.getNaturalId()).getRisk()));
-            vo.setRiskLevel(String.valueOf(riskPOMap.get(vo.getNaturalId()).getRiskLevel()));
+            // 赋值复杂度
+            if (complexityPOMap.get(vo.getNaturalId()) != null) {
+                vo.setComplexity(String.valueOf(complexityPOMap.get(vo.getNaturalId()).getComplexity()));
+                vo.setComplexityLevel(String.valueOf(complexityPOMap.get(vo.getNaturalId()).getComplexityLevel()));
+            }
+            if (riskPOMap.get(vo.getNaturalId()) != null) {
+                vo.setRisk(String.valueOf(riskPOMap.get(vo.getNaturalId()).getRisk()));
+                vo.setRiskLevel(String.valueOf(riskPOMap.get(vo.getNaturalId()).getRiskLevel()));
+            }
             if (vo.getRoadType().equals("高速")) {
                 if (ObjectUtil.isNull(vo.getLabel())) {
                     vo.setLabel("高速");
@@ -548,6 +554,7 @@ public class SceneNaturalService {
                     List<String> listScene = fileDownService.listDeepOne(MI).getInfo();
                     log.info("共需要上传 " + listScene.size() + " 个自然驾驶场景");
                     String taskId = api.common.util.StringUtil.getRandomUUID();
+                    List<SceneEvaluationComputeParam> paramList = new ArrayList<>();
                     HashSet<String> strings = new HashSet<>(listScene);
                     log.info("去重之后还剩 " + strings.size() + " 个自然驾驶场景");
                     int addNumber = 0;
@@ -697,22 +704,19 @@ public class SceneNaturalService {
 
                             // 计算复杂度
                             if (!StringUtils.isEmpty(parms.getSceneEvaluationRuleId())) {
-                                String tempSceneId = scenes.get(0).getNaturalId();
                                 SceneEvaluationComputeParam sceneEvaluationComputeParam = new SceneEvaluationComputeParam();
-                                sceneEvaluationComputeParam.setSceneId(update ? tempSceneId : sceneNaturalPO.getNaturalId());
+                                sceneEvaluationComputeParam.setSceneId(update ? scenes.get(0).getNaturalId() : sceneNaturalPO.getNaturalId());
                                 sceneEvaluationComputeParam.setSceneXOSCPath(sceneNaturalPO.getXoscAddress());
                                 sceneEvaluationComputeParam.setSceneXODRPath(sceneNaturalPO.getXodrAddress());
                                 sceneEvaluationComputeParam.setSceneType(DictConstants.SCENE_NATURAL);
                                 sceneEvaluationComputeParam.setTaskId(taskId);
                                 sceneEvaluationComputeParam.setComputeType(DictConstants.COMPLEXITY);
-                                try {
-                                    boolean sceneEvaluationResult = sceneEvaluationRuleService.computeSceneReference(parms, sceneEvaluationComputeParam);
-                                    if (update && sceneEvaluationResult) {
-                                        sceneEvaluationRuleService.copySceneComplexityResult(taskId, tempSceneId, scenes.stream().map(SceneNaturalPO::getNaturalId).filter(sceneId -> !StringUtils.equals(tempSceneId, sceneId)).collect(Collectors.toList()));
-                                    }
-                                } catch (Exception e) {
-                                    log.error("计算复杂度失败", e);
+                                if (update) {
+                                    String tempSceneId = scenes.get(0).getNaturalId();
+                                    sceneEvaluationComputeParam.setCopySceneId(scenes.stream().map(SceneNaturalPO::getNaturalId).filter(sceneId -> !StringUtils.equals(tempSceneId, sceneId)).collect(Collectors.toList()));
                                 }
+                                paramList.add(sceneEvaluationComputeParam);
+                                log.info("添加计算复杂度数据:" + sceneEvaluationComputeParam);
                             }
                         } catch (Exception e) {
                             errorMessage = e.getMessage();
@@ -721,6 +725,13 @@ public class SceneNaturalService {
                         }
                     }
                     log.info("共新增 " + addNumber + " 个自然驾驶场景,修改 " + updateNumber + "个场景。");
+                    try {
+                        if (CollectionUtil.isNotEmpty(paramList)) {
+                            sceneEvaluationRuleService.computeSceneReference(parms, paramList);
+                        }
+                    } catch (Exception e) {
+                        log.error("计算复杂度失败", e);
+                    }
                 }
             }
             sceneImportPO.setStatus(DictConstants.SCENE_IMPORT_STATUS_4);

+ 24 - 19
simulation-resource-server/src/main/java/com/css/simulation/resource/server/app/service/SceneReferenceLibService.java

@@ -30,8 +30,6 @@ import java.util.stream.Collectors;
 @Service
 public class SceneReferenceLibService {
 
-    @Value("${server.linux-path.temp}")
-    private String linuxTempPath;
     @Resource
     private SceneReferenceLibMapper sceneReferenceLibMapper;
 
@@ -135,15 +133,20 @@ public class SceneReferenceLibService {
         Map<String, SceneRiskPO> riskPOMap = sceneEvaluationOperatePO.getSceneRiskPOMap();
         // 筛选
         List<SceneReferenceLibPO> finalSceneReferenceLibPOList = sceneReferenceLibPOS.stream()
-                .filter(srf -> complexityPOMap.get(srf.getSceneId()) != null && riskPOMap.get(srf.getSceneId()) != null)
+                .filter(srf -> sceneEvaluationRuleService.checkSelectReferenceComplexity(srf.getSceneId(), sceneEvaluationForListParam, complexityPOMap) &&
+                        sceneEvaluationRuleService.checkSelectReferenceRisk(srf.getSceneId(), sceneEvaluationForListParam, riskPOMap))
                 .collect(Collectors.toList());
 
         for (SceneReferenceLibPO po : finalSceneReferenceLibPOList) {
             // 赋值复杂度
-            po.setComplexity(String.valueOf(complexityPOMap.get(po.getSceneId()).getComplexity()));
-            po.setComplexityLevel(String.valueOf(complexityPOMap.get(po.getSceneId()).getComplexityLevel()));
-            po.setRisk(String.valueOf(riskPOMap.get(po.getSceneId()).getRisk()));
-            po.setRiskLevel(String.valueOf(riskPOMap.get(po.getSceneId()).getRiskLevel()));
+            if (complexityPOMap.get(po.getSceneId()) != null) {
+                po.setComplexity(String.valueOf(complexityPOMap.get(po.getSceneId()).getComplexity()));
+                po.setComplexityLevel(String.valueOf(complexityPOMap.get(po.getSceneId()).getComplexityLevel()));
+            }
+            if (riskPOMap.get(po.getSceneId()) != null) {
+                po.setRisk(String.valueOf(riskPOMap.get(po.getSceneId()).getRisk()));
+                po.setRiskLevel(String.valueOf(riskPOMap.get(po.getSceneId()).getRiskLevel()));
+            }
             if (po.getRoadType().equals("高速")) {
                 if (ObjectUtil.isNull(po.getLabel())) {
                     po.setLabel("高速");
@@ -215,6 +218,7 @@ public class SceneReferenceLibService {
                     List<String> listScene = fileDownService.listDeepOne(MI).getInfo();
                     log.info("importMinio() 共需要上传 " + listScene.size() + " 个基准场景");
                     String taskId = StringUtil.getRandomUUID();
+                    List<SceneEvaluationComputeParam> paramList = new ArrayList<>();
                     for (String scenePath : listScene) {
                         try {
                             MI.setObjectName(scenePath);
@@ -327,24 +331,19 @@ public class SceneReferenceLibService {
 
                             }
                             successNum += 1;
-                            // 计算复杂度
                             if (!StringUtils.isEmpty(params.getSceneEvaluationRuleId())) {
-                                String tempSceneId = scenes.get(0).getSceneId();
                                 SceneEvaluationComputeParam sceneEvaluationComputeParam = new SceneEvaluationComputeParam();
-                                sceneEvaluationComputeParam.setSceneId(isUpdate ? tempSceneId : sceneReferenceLibPO.getSceneId());
+                                sceneEvaluationComputeParam.setSceneId(isUpdate ? scenes.get(0).getSceneId() : sceneReferenceLibPO.getSceneId());
                                 sceneEvaluationComputeParam.setSceneXOSCPath(sceneReferenceLibPO.getXmlAddress());
                                 sceneEvaluationComputeParam.setSceneXODRPath(sceneReferenceLibPO.getXodrAddress());
                                 sceneEvaluationComputeParam.setSceneType(DictConstants.SCENE_REFERENCE_LIB);
                                 sceneEvaluationComputeParam.setTaskId(taskId);
                                 sceneEvaluationComputeParam.setComputeType(DictConstants.COMPLEXITY);
-                                try {
-                                    boolean sceneEvaluationResult = sceneEvaluationRuleService.computeSceneReference(params, sceneEvaluationComputeParam);
-                                    if (isUpdate && sceneEvaluationResult) {
-                                        sceneEvaluationRuleService.copySceneComplexityResult(taskId, tempSceneId, scenes.stream().map(SceneReferenceLibPO::getSceneId).filter(sceneId -> !StringUtils.equals(tempSceneId, sceneId)).collect(Collectors.toList()));
-                                    }
-                                } catch (Exception e) {
-                                    log.error("计算复杂度失败", e);
+                                if (isUpdate) {
+                                    String tempSceneId = scenes.get(0).getSceneId();
+                                    sceneEvaluationComputeParam.setCopySceneId(scenes.stream().map(SceneReferenceLibPO::getSceneId).filter(sceneId -> !StringUtils.equals(tempSceneId, sceneId)).collect(Collectors.toList()));
                                 }
+                                paramList.add(sceneEvaluationComputeParam);
                             }
                         } catch (Exception e) {
                             errorMessage = e.getMessage();
@@ -352,8 +351,14 @@ public class SceneReferenceLibService {
                             falseNum += 1;
                         }
                     }
-                    // 删除临时文件
-                    FileUtil.deleteFolder(linuxTempPath + "scene/evaluation/" + taskId);   // 删除临时文件
+                    // 计算复杂度
+                    if (!StringUtils.isEmpty(params.getSceneEvaluationRuleId())) {
+                        try {
+                            sceneEvaluationRuleService.computeSceneReference(params, paramList);
+                        } catch (Exception e) {
+                            log.error("计算复杂度失败", e);
+                        }
+                    }
                 }
             }
             sceneImportPO.setStatus(DictConstants.SCENE_IMPORT_STATUS_4);

+ 30 - 17
simulation-resource-server/src/main/java/com/css/simulation/resource/server/app/service/SceneStandardsService.java

@@ -154,13 +154,22 @@ public class SceneStandardsService {
         Map<String, SceneRiskPO> riskPOMap = sceneEvaluationOperatePO.getSceneRiskPOMap();
         // 筛选
         List<StandardsRegulationsPO> standardsRegulationsPOS = list.stream()
-                .filter(sn -> complexityPOMap.get(sn.getRegulationsId()) != null && riskPOMap.get(sn.getRegulationsId()) != null)
+                .filter(sn -> sceneEvaluationRuleService.checkSelectReferenceComplexity(sn.getRegulationsId(), sceneEvaluationForListParam, complexityPOMap) &&
+                        sceneEvaluationRuleService.checkSelectReferenceRisk(sn.getRegulationsId(), sceneEvaluationForListParam, riskPOMap))
                 .collect(Collectors.toList());
-        standardsRegulationsPOS.stream().forEach(po -> {            // 赋值复杂度
-            po.setComplexity(String.valueOf(complexityPOMap.get(po.getRegulationsId()).getComplexity()));
-            po.setComplexityLevel(String.valueOf(complexityPOMap.get(po.getRegulationsId()).getComplexityLevel()));
-            po.setRisk(String.valueOf(riskPOMap.get(po.getRegulationsId()).getRisk()));
-            po.setRiskLevel(String.valueOf(riskPOMap.get(po.getRegulationsId()).getRiskLevel()));
+
+
+        standardsRegulationsPOS.forEach(po -> {            // 赋值复杂度
+
+            // 赋值复杂度
+            if (complexityPOMap.get(po.getRegulationsId()) != null) {
+                po.setComplexity(String.valueOf(complexityPOMap.get(po.getRegulationsId()).getComplexity()));
+                po.setComplexityLevel(String.valueOf(complexityPOMap.get(po.getRegulationsId()).getComplexityLevel()));
+            }
+            if (riskPOMap.get(po.getRegulationsId()) != null) {
+                po.setRisk(String.valueOf(riskPOMap.get(po.getRegulationsId()).getRisk()));
+                po.setRiskLevel(String.valueOf(riskPOMap.get(po.getRegulationsId()).getRiskLevel()));
+            }
         });
 
        /* if(params.getLabel()!=null&&params.getLabel().size()>0){
@@ -309,6 +318,7 @@ public class SceneStandardsService {
      * 获取标准法规场景数据:
      */
     public SceneImportPO importMinio(SceneImportParam parms) {
+        log.info("接到场景上传请求:" + parms);
         SceneImportPO sceneImportPO = new SceneImportPO();
         sceneImportPO.setId(parms.getId());
         try {
@@ -335,6 +345,7 @@ public class SceneStandardsService {
                     List<String> listScene = fileDownService.listDeepOne(MI).getInfo();
                     log.info("importMinio() 共需要上传 " + listScene.size() + " 个标准法规场景");
                     String taskId = api.common.util.StringUtil.getRandomUUID();
+                    List<SceneEvaluationComputeParam> paramList = new ArrayList<>();
                     for (String scenePath : listScene) {
                         try {
                             MI.setObjectName(scenePath);
@@ -424,31 +435,33 @@ public class SceneStandardsService {
 
                             // 计算复杂度
                             if (!StringUtils.isEmpty(parms.getSceneEvaluationRuleId())) {
-                                String tempSceneId = scenes.get(0).getRegulationsId();
                                 SceneEvaluationComputeParam sceneEvaluationComputeParam = new SceneEvaluationComputeParam();
-                                sceneEvaluationComputeParam.setSceneId(isupdate.equals("0") ? tempSceneId : standardsRegulationsPO.getRegulationsId());
+                                sceneEvaluationComputeParam.setSceneId(isupdate.equals("0") ? standardsRegulationsPO.getRegulationsId() : scenes.get(0).getRegulationsId());
                                 sceneEvaluationComputeParam.setSceneXOSCPath(standardsRegulationsPO.getXmlAddress());
                                 sceneEvaluationComputeParam.setSceneXODRPath(standardsRegulationsPO.getXodrAddress());
                                 sceneEvaluationComputeParam.setSceneType(DictConstants.SCENE_STANDARD);
                                 sceneEvaluationComputeParam.setTaskId(taskId);
                                 sceneEvaluationComputeParam.setComputeType(DictConstants.COMPLEXITY);
-                                try {
-                                    boolean sceneEvaluationResult = sceneEvaluationRuleService.computeSceneReference(parms, sceneEvaluationComputeParam);
-                                    if (isupdate.equals("0") && sceneEvaluationResult) {
-                                        sceneEvaluationRuleService.copySceneComplexityResult(taskId, tempSceneId, scenes.stream().map(StandardsRegulationsPO::getRegulationsId).filter(sceneId -> !StringUtils.equals(tempSceneId, sceneId)).collect(Collectors.toList()));
-                                    }
-                                } catch (Exception e) {
-                                    log.error("计算复杂度失败", e);
+                                if (isupdate.equals("1")) {
+                                    String tempSceneId = scenes.get(0).getRegulationsId();
+                                    sceneEvaluationComputeParam.setCopySceneId(scenes.stream().map(StandardsRegulationsPO::getRegulationsId).filter(sceneId -> !StringUtils.equals(tempSceneId, sceneId)).collect(Collectors.toList()));
                                 }
+                                log.info("添加计算复杂度数据:" + sceneEvaluationComputeParam);
+                                paramList.add(sceneEvaluationComputeParam);
                             }
-
-
                         } catch (Exception e) {
                             errorMessage = e.getMessage();
                             e.printStackTrace();
                             falseNum = falseNum + 1;
                         }
                     }
+                    try {
+                        if (!StringUtils.isEmpty(parms.getSceneEvaluationRuleId())) {
+                            sceneEvaluationRuleService.computeSceneReference(parms, paramList);
+                        }
+                    } catch (Exception e) {
+                        log.error("计算复杂度失败", e);
+                    }
                 }
             }
             sceneImportPO.setStatus(DictConstants.SCENE_IMPORT_STATUS_4);

+ 2 - 0
simulation-resource-server/src/main/java/com/css/simulation/resource/server/infra/db/mysql/mapper/DictMapper.java

@@ -14,8 +14,10 @@ public interface DictMapper {
 
     List<DictVO> getDicts(List dictTypeList);
     void saveSystemDict(DictPO po);
+    void createSystemDict(DictPO po);
     void updateSystemDict(DictPO po);
     int deleteSystemDict(DictPO po);
+    int deleteSystemDictByCodeAndType(DictPO po);
 
     String getDictByDictCode(DictPO po);
 }

+ 38 - 0
simulation-resource-server/src/main/resources/mysql/mapper/DictMapper.xml

@@ -53,6 +53,35 @@
         )
     </insert>
 
+    <insert id="createSystemDict" parameterType="api.common.pojo.po.system.DictPO">
+        INSERT INTO system_dict(
+            id,
+            dict_comment,
+            dict_type,
+            dict_name,
+            dict_code,
+            dict_order,
+            create_time,
+            modify_time,
+            create_user_id,
+            modify_user_id,
+            is_deleted
+        )
+        VALUES(
+                  #{id,jdbcType=VARCHAR},
+                  #{dictComment,jdbcType=VARCHAR},
+                  #{dictType,jdbcType=VARCHAR},
+                  #{dictName,jdbcType=VARCHAR},
+                  #{dictCode,jdbcType=VARCHAR},
+                  #{dictOrder,jdbcType=VARCHAR},
+                  #{createTime,jdbcType=TIMESTAMP},
+                  #{modifyTime,jdbcType=TIMESTAMP},
+                  #{createUserId,jdbcType=VARCHAR},
+                  #{modifyUserId,jdbcType=VARCHAR},
+                  #{isDeleted,jdbcType=VARCHAR}
+              )
+    </insert>
+
     <update id="updateSystemDict" parameterType="api.common.pojo.po.system.DictPO">
         update system_dict set
         dict_name = #{dictName,jdbcType=VARCHAR},
@@ -72,6 +101,15 @@
         and is_deleted='0'
     </update>
 
+    <update id="deleteSystemDictByCodeAndType" parameterType="api.common.pojo.po.system.DictPO">
+        update system_dict set
+                               is_deleted ='1',
+                               modify_time = #{modifyTime,jdbcType=TIMESTAMP},
+                               modify_user_id = #{modifyUserId,jdbcType=VARCHAR}
+        where dict_code = #{dictCode,jdbcType=VARCHAR}
+          and dict_type = #{dictType,jdbcType=VARCHAR}
+          and is_deleted='0'
+    </update>
 
     <select id="getDictByDictCode"  resultType="java.lang.String" parameterType="api.common.pojo.po.system.DictPO" >
         select

+ 11 - 12
simulation-resource-server/src/main/resources/mysql/mapper/SceneComplexityMapper.xml

@@ -8,26 +8,25 @@
         FROM
         (
         SELECT
-        srl.scene_id scene_id,
-        sc.complexity complexity,
-        sc.complexity_level complexity_level,
-        sc.create_time create_time
+        DISTINCT(scene_id),
+        complexity,
+        complexity_level,
+        create_time
         FROM
-        simulation.scene_reference_lib srl
-        LEFT JOIN scene_complexity sc ON srl.scene_id = sc.scene_id
+        scene_complexity
         <where>
-            srl.is_deleted = '0'
+            is_deleted = '0'
             <if test="minComplexity != null and minComplexity != ''">
-                AND sc.complexity+0 >= #{minComplexity}
+                AND complexity+0 >= #{minComplexity}
             </if>
             <if test="maxComplexity != null and maxComplexity != ''">
-                AND sc.complexity+0 &lt;=  #{maxComplexity}
+                AND complexity+0 &lt;=  #{maxComplexity}
             </if>
             <if test="complexityLevel != null and complexityLevel != ''">
-                AND sc.complexity_level+0 >=  #{complexityLevel}
+                AND complexity_level+0 >=  #{complexityLevel}
             </if>
             <if test="sceneIdList != null and sceneIdList.size()>0">
-                AND srl.scene_id IN
+                AND scene_id IN
                 <foreach collection="sceneIdList" item="item" index="index"
                          separator="," open="(" close=")">
                     #{item}
@@ -35,7 +34,7 @@
             </if>
         </where>
         ORDER BY
-        sc.create_time DESC LIMIT 1
+        create_time DESC
         ) srlsc GROUP BY scene_id;
     </select>
 

+ 0 - 1
simulation-resource-server/src/main/resources/mysql/mapper/SceneReferenceLibMapper.xml

@@ -56,7 +56,6 @@
             operation_area=#{operationArea},
             scene_description=#{sceneDescription},
             label=#{label},
-            is_deleted=#{isDeleted},
             modify_user_id=#{modifyUserId},
             modify_time=#{modifyTime},
             video_address=#{videoAddress},

+ 11 - 12
simulation-resource-server/src/main/resources/mysql/mapper/SceneRiskMapper.xml

@@ -8,26 +8,25 @@
         FROM
         (
         SELECT
-        srl.scene_id scene_id,
-        sr.risk risk,
-        sr.risk_level risk_level,
-        sr.create_time create_time
+        DISTINCT(scene_id),
+        risk,
+        risk_level,
+        create_time
         FROM
-        simulation.scene_reference_lib srl
-        LEFT JOIN scene_risk sr ON srl.scene_id = sr.scene_id
+        scene_risk
         <where>
-            srl.is_deleted = '0'
+            is_deleted = '0'
             <if test="minRisk != null and minRisk != ''">
-                AND sr.risk+0 >= #{minRisk}
+                AND risk+0 >= #{minRisk}
             </if>
             <if test="maxRisk != null and maxRisk != ''">
-                AND sr.risk+0 &lt;=  #{maxRisk}
+                AND risk+0 &lt;=  #{maxRisk}
             </if>
             <if test="riskLevel != null and riskLevel != ''">
-                AND sr.risk_level+0 >=  #{riskLevel}
+                AND risk_level+0 >=  #{riskLevel}
             </if>
             <if test="sceneIdList != null and sceneIdList.size()>0">
-                AND srl.scene_id IN
+                AND scene_id IN
                 <foreach collection="sceneIdList" item="item" index="index"
                          separator="," open="(" close=")">
                     #{item}
@@ -35,7 +34,7 @@
             </if>
         </where>
         ORDER BY
-        sr.create_time DESC LIMIT 1
+        create_time DESC
         ) srlsc GROUP BY scene_id;
     </select>
 

+ 5 - 1
simulation-resource-server/src/main/resources/mysql/mapper/SimulationManualProjectMapper.xml

@@ -256,7 +256,11 @@
                details,
                algorithm_array,
                vehicle_array,
-               scene_array
+               scene_array,
+               coverage_rate_evaluation_ruleId,
+               exposure_rate_rvaluation_rule_id,
+               complexity_evaluation_rule_id,
+               risk_evaluation_rule_id
         from simulation_manual_project
         where id = #{id}
           and is_deleted = '0'