|
@@ -1,7 +1,6 @@
|
|
package com.css.simulation.resource.scheduler.domain.service;
|
|
package com.css.simulation.resource.scheduler.domain.service;
|
|
|
|
|
|
import api.common.pojo.constants.DictConstants;
|
|
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.SceneEvaluationComputeParam;
|
|
import api.common.pojo.param.scene.SceneImportParam;
|
|
import api.common.pojo.param.scene.SceneImportParam;
|
|
import api.common.pojo.po.scene.SceneComplexityPO;
|
|
import api.common.pojo.po.scene.SceneComplexityPO;
|
|
@@ -32,6 +31,10 @@ import org.springframework.stereotype.Component;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
import java.io.*;
|
|
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.*;
|
|
import java.util.concurrent.TimeUnit;
|
|
import java.util.concurrent.TimeUnit;
|
|
import java.util.function.Function;
|
|
import java.util.function.Function;
|
|
@@ -49,8 +52,6 @@ public class TaskDomainService {
|
|
private String pyPath;
|
|
private String pyPath;
|
|
@Value("${scheduler.linux-path.temp}")
|
|
@Value("${scheduler.linux-path.temp}")
|
|
private String linuxTempPath;
|
|
private String linuxTempPath;
|
|
- @Value("${scheduler.scene-evaluation.script}")
|
|
|
|
- private String sceneEvaluationScript;
|
|
|
|
@Resource
|
|
@Resource
|
|
private StringRedisTemplate stringRedisTemplate;
|
|
private StringRedisTemplate stringRedisTemplate;
|
|
@Resource
|
|
@Resource
|
|
@@ -135,6 +136,8 @@ public class TaskDomainService {
|
|
List<SceneEntity> sceneEntityList = getSceneList(projectId, packageId);
|
|
List<SceneEntity> sceneEntityList = getSceneList(projectId, packageId);
|
|
Map<String, SceneEntity> sceneEntityMap = sceneEntityList.stream().collect(Collectors.toMap(SceneEntity::getId, Function.identity()));
|
|
Map<String, SceneEntity> sceneEntityMap = sceneEntityList.stream().collect(Collectors.toMap(SceneEntity::getId, Function.identity()));
|
|
List<LeafIndexEntity> leafIndexList = new ArrayList<>();
|
|
List<LeafIndexEntity> leafIndexList = new ArrayList<>();
|
|
|
|
+ List<SceneEvaluationComputeParam> sceneComplexityEvaluationComputeParamList = new ArrayList<>();
|
|
|
|
+ List<SceneEvaluationComputeParam> sceneRiskEvaluationComputeParamList = new ArrayList<>();
|
|
for (int i = 0; i < leafIndexTemplateList.size(); i++) {
|
|
for (int i = 0; i < leafIndexTemplateList.size(); i++) {
|
|
String scoreExplain = null; // 每个叶子指标下的任务的得分说明一样和叶子指标一致
|
|
String scoreExplain = null; // 每个叶子指标下的任务的得分说明一样和叶子指标一致
|
|
IndexTemplateEntity leafIndexTemplate = leafIndexTemplateList.get(i);
|
|
IndexTemplateEntity leafIndexTemplate = leafIndexTemplateList.get(i);
|
|
@@ -260,13 +263,7 @@ public class TaskDomainService {
|
|
sceneEvaluationComputeParam.setSceneType(sceneEntityMap.get(sceneId).getType());
|
|
sceneEvaluationComputeParam.setSceneType(sceneEntityMap.get(sceneId).getType());
|
|
sceneEvaluationComputeParam.setTaskId(projectId);
|
|
sceneEvaluationComputeParam.setTaskId(projectId);
|
|
sceneEvaluationComputeParam.setComputeType(DictConstants.COMPLEXITY);
|
|
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())) {
|
|
if (!StringUtils.isEmpty(projectEntity.getRiskEvaluationRuleId())) {
|
|
@@ -278,13 +275,7 @@ public class TaskDomainService {
|
|
sceneEvaluationComputeParam.setComputeType(DictConstants.RISK);
|
|
sceneEvaluationComputeParam.setComputeType(DictConstants.RISK);
|
|
sceneEvaluationComputeParam.setAlgorithmId(projectEntity.getAlgorithm());
|
|
sceneEvaluationComputeParam.setAlgorithmId(projectEntity.getAlgorithm());
|
|
sceneEvaluationComputeParam.setVehicleId(projectEntity.getVehicle());
|
|
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);
|
|
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 + "/"); // 删除临时文件
|
|
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) {
|
|
public void computeFirst(List<LeafIndexEntity> leafIndexList, List<IndexTemplateEntity> allIndexTemplateList, String projectId, int maxLevel) {
|
|
-
|
|
|
|
log.debug("计算父指标得分:" + leafIndexList);
|
|
log.debug("计算父指标得分:" + leafIndexList);
|
|
Iterator<LeafIndexEntity> leafTaskIndexIterator = leafIndexList.iterator();
|
|
Iterator<LeafIndexEntity> leafTaskIndexIterator = leafIndexList.iterator();
|
|
// 把 1 级的指标得分直接保存
|
|
// 把 1 级的指标得分直接保存
|
|
@@ -458,7 +466,7 @@ public class TaskDomainService {
|
|
*
|
|
*
|
|
* @param param
|
|
* @param param
|
|
*/
|
|
*/
|
|
- public boolean computeSceneReference(SceneImportParam param, SceneEvaluationComputeParam sceneEvaluationComputeParam) {
|
|
|
|
|
|
+ public boolean computeSceneReference(SceneImportParam param, List<SceneEvaluationComputeParam> sceneEvaluationComputeParams) {
|
|
String ruleId = param.getSceneEvaluationRuleId();
|
|
String ruleId = param.getSceneEvaluationRuleId();
|
|
// 获取场景评价规则
|
|
// 获取场景评价规则
|
|
SceneEvaluationRulePO sceneEvaluationRulePO = sceneEvaluationRuleMapper.querySceneEvaluationPyById(ruleId);
|
|
SceneEvaluationRulePO sceneEvaluationRulePO = sceneEvaluationRuleMapper.querySceneEvaluationPyById(ruleId);
|
|
@@ -467,126 +475,168 @@ public class TaskDomainService {
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
// 1 判断有没有用户目录,没有则复制
|
|
// 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()) {
|
|
if (!new File(evaluationDirectoryOfUser).exists()) {
|
|
// 1 将场景评价规则脚本保存到 script 目录
|
|
// 1 将场景评价规则脚本保存到 script 目录
|
|
FileUtil.createDirectory(scriptsPath);
|
|
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) {
|
|
if (sceneEvaluationRulePO.getScriptPath() == null) {
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
- String pyMainPath = scriptsPath + "/" + sceneEvaluationRulePO.getRuleId() + ".py";
|
|
|
|
|
|
+ String pyMainPath = scriptsPath + "/" + sceneEvaluationRulePO.getRuleId();
|
|
if (!new File(pyMainPath).exists()) {
|
|
if (!new File(pyMainPath).exists()) {
|
|
MinioUtil.downloadToFile(minioClient, bucketName, sceneEvaluationRulePO.getScriptPath(), pyMainPath);
|
|
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 {
|
|
} else {
|
|
|
|
+ // 一个场景只计算一次
|
|
return false;
|
|
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;
|
|
String sceneEvaluationResult;
|
|
log.info("开始执行场景评价命令:" + sceneEvaluationCommand);
|
|
log.info("开始执行场景评价命令:" + sceneEvaluationCommand);
|
|
Runtime r = Runtime.getRuntime();
|
|
Runtime r = Runtime.getRuntime();
|
|
Process p = null;
|
|
Process p = null;
|
|
try {
|
|
try {
|
|
- p = r.exec(sceneEvaluationCommand, null, new File(evaluationDirectoryOfUser + sceneEvaluationComputeParam.getSceneId()));
|
|
|
|
|
|
+ p = r.exec(sceneEvaluationCommand);
|
|
} catch (IOException e) {
|
|
} catch (IOException e) {
|
|
log.error("执行场景评价脚本失败,脚本命令为: " + sceneEvaluationCommand, e);
|
|
log.error("执行场景评价脚本失败,脚本命令为: " + sceneEvaluationCommand, e);
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
- BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
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 {
|
|
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;
|
|
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;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|