LingxinMeng 2 tahun lalu
induk
melakukan
5252b2f962

+ 3 - 4
api-common/src/main/java/api/common/pojo/po/project/SchedulerProjectPO.java → api-common/src/main/java/api/common/pojo/po/scheduler/SchedulerProjectPO.java

@@ -1,4 +1,4 @@
-package api.common.pojo.po.project;
+package api.common.pojo.po.scheduler;
 
 import lombok.AllArgsConstructor;
 import lombok.Builder;
@@ -10,12 +10,11 @@ import lombok.NoArgsConstructor;
 @NoArgsConstructor
 @AllArgsConstructor
 public class SchedulerProjectPO {
-
     private String id;
+    private String projectId;
     private String scenePackageId;
     private String createUserId;
     private String parallelism;
     private String projectType;
-
-
+    private String errorMessage;
 }

+ 3 - 3
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/consumer/ProjectConsumer.java

@@ -287,7 +287,7 @@ public class ProjectConsumer {
             cacheProject(projectMessageDTO);
         } catch (Exception e) {
             log.error("项目报错。", e);
-            projectService.stopProject(projectId, projectType);
+            projectService.stopProject(projectId, projectType, e.getMessage());
             throw new RuntimeException(e);
         }
 
@@ -512,8 +512,8 @@ public class ProjectConsumer {
         log.info("接收到的项目终止消息为:" + stopRecord);
         JsonNode jsonNode = new ObjectMapper().readTree(stopRecord.value());
         String projectId = jsonNode.path("projectId").asText();
-        String type = jsonNode.path("type").asText();
-        projectService.stopProject(projectId, type);
+        String projectType = jsonNode.path("type").asText();
+        projectService.stopProject(projectType, projectId);
     }
 
 

+ 6 - 16
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/mapper/ManualProjectMapper.java

@@ -1,17 +1,16 @@
 package com.css.simulation.resource.scheduler.mapper;
 
 
+import api.common.pojo.po.scheduler.SchedulerProjectPO;
 import com.css.simulation.resource.scheduler.entity.ProjectEntity;
 import org.apache.ibatis.annotations.*;
 import org.apache.ibatis.type.JdbcType;
 
 import java.sql.Timestamp;
-import java.util.List;
 
 @Mapper
 public interface ManualProjectMapper {
 
-
     @Results(id = "project", value = {
             @Result(column = "id", property = "id", jdbcType = JdbcType.VARCHAR),
             @Result(column = "scene", property = "scenePackageId", jdbcType = JdbcType.VARCHAR),
@@ -31,20 +30,6 @@ public interface ManualProjectMapper {
             "where id = #{projectId}")
     ProjectEntity selectById(@Param("projectId") String projectId);
 
-
-    @Select("select is_choice_gpu\n" +
-            "from simulation_manual_project\n" +
-            "where id = #{projectId}")
-    String selectIsChoiceGpuById(@Param("projectId") String projectId);
-
-    @ResultMap("project")
-    @Select("select id, scene, create_user_id, parallelism, '1' project_type\n" +
-            "from simulation_manual_project\n" +
-            "where is_deleted = '0'\n" +
-            "  and now_run_state = #{nowRunState}")
-    List<ProjectEntity> selectByNowRunState(@Param("nowRunState") String nowRunState);
-
-
     @Update("update simulation_manual_project\n" +
             "set now_run_state  = #{state},\n" +
             "    finish_time = #{finishTime}\n" +
@@ -56,4 +41,9 @@ public interface ManualProjectMapper {
             "from simulation_manual_project\n" +
             "where id = #{id}")
     String selectCreateUserById(@Param("id") String id);
+
+    @Update("update simulation_manual_project\n" +
+            "set error_message = #{errorMessage}\n" +
+            "where project_id = #{id}\n")
+    void saveErrorMessage(SchedulerProjectPO schedulerProjectPO);
 }

+ 13 - 1
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/service/ProjectService.java

@@ -2,6 +2,7 @@ package com.css.simulation.resource.scheduler.service;
 
 import api.common.pojo.constants.DictConstants;
 import api.common.pojo.dto.ProjectMessageDTO;
+import api.common.pojo.po.scheduler.SchedulerProjectPO;
 import api.common.util.*;
 import com.css.simulation.resource.scheduler.configuration.docker.DockerConfiguration;
 import com.css.simulation.resource.scheduler.configuration.git.GitConfiguration;
@@ -284,13 +285,24 @@ public class ProjectService {
         return dockerImage;
     }
 
+    public void stopProject(String projectType, String projectId, String errorMessage) {
+        Optional.ofNullable(errorMessage)
+                .ifPresent(em -> {
+                    if (DictConstants.PROJECT_TYPE_MANUAL.equals(projectType)) {
+                        manualProjectMapper.saveErrorMessage(SchedulerProjectPO.builder().id(projectId).errorMessage(em).build());
+                    } else if (DictConstants.PROJECT_TYPE_AUTO_SUB.equals(projectType)) {
+                        autoSubProjectMapper.updateProjectState(projectId, DictConstants.PROJECT_TERMINATING, TimeUtil.getNowForMysql());
+                    }
+                });
+        stopProject(projectType, projectId);
+    }
 
     /**
      * @param projectId   手动项目 id 或自动项目子id
      * @param projectType 项目类型
      */
     @SneakyThrows
-    public void stopProject(String projectId, String projectType) {
+    public void stopProject(String projectType, String projectId) {
         // 将项目状态修改为终止中
         if (DictConstants.PROJECT_TYPE_MANUAL.equals(projectType)) {
             manualProjectMapper.updateProjectState(projectId, DictConstants.PROJECT_TERMINATING, TimeUtil.getNowForMysql());

+ 391 - 385
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/util/TaskUtil.java

@@ -35,415 +35,421 @@ import java.util.stream.Collectors;
 @Slf4j
 public class TaskUtil {
 
- @Value("${minio.bucket-name}")
- private String bucketName;
- @Value("${scheduler.linux-path.score-py}")
- private String pyPath;
- @Value("${scheduler.linux-path.temp}")
- private String linuxTempPath;
- @Value("${simulation-cloud.client-id}")
- private String clientId;
- @Value("${simulation-cloud.client-secret}")
- private String clientSecret;
- @Value("${simulation-cloud.token-uri}")
- private String tokenUri;
- @Value("${simulation-cloud.evaluation-level-uri}")
- private String evaluationLevelUri;
- @Value("${scheduler.minio-path.project-result}")
- private String resultPathMinio;
- @Resource
- private StringRedisTemplate stringRedisTemplate;
- @Resource
- private TaskMapper taskMapper;
- @Resource
- private MinioClient minioClient;
- @Resource
- private ManualProjectMapper manualProjectMapper;
- @Resource
- private AutoSubProjectMapper autoSubProjectMapper;
- @Resource
- private TaskIndexManager taskIndexManager;
- @Resource
- private IndexMapper indexMapper;
- @Resource
- private ScoringRulesMapper scoringRulesMapper;
- @Resource
- private CloseableHttpClient closeableHttpClient;
- @Resource
- private RequestConfig requestConfig;
- @Resource
- private ProjectUtil projectUtil;
- @Resource
- private VideoFeignClient videoFeignClient;
- @Resource
- private SqlSessionFactory sqlSessionFactory;
- @Resource
- private KubernetesConfiguration kubernetesConfiguration;
- @Resource
- private ApiClient apiClient;
- @Resource(name = "myKafkaAdmin")
- private Admin admin;
+    @Value("${minio.bucket-name}")
+    private String bucketName;
+    @Value("${scheduler.linux-path.score-py}")
+    private String pyPath;
+    @Value("${scheduler.linux-path.temp}")
+    private String linuxTempPath;
+    @Value("${simulation-cloud.client-id}")
+    private String clientId;
+    @Value("${simulation-cloud.client-secret}")
+    private String clientSecret;
+    @Value("${simulation-cloud.token-uri}")
+    private String tokenUri;
+    @Value("${simulation-cloud.evaluation-level-uri}")
+    private String evaluationLevelUri;
+    @Value("${scheduler.minio-path.project-result}")
+    private String resultPathMinio;
+    @Resource
+    private StringRedisTemplate stringRedisTemplate;
+    @Resource
+    private TaskMapper taskMapper;
+    @Resource
+    private MinioClient minioClient;
+    @Resource
+    private ManualProjectMapper manualProjectMapper;
+    @Resource
+    private AutoSubProjectMapper autoSubProjectMapper;
+    @Resource
+    private TaskIndexManager taskIndexManager;
+    @Resource
+    private IndexMapper indexMapper;
+    @Resource
+    private ScoringRulesMapper scoringRulesMapper;
+    @Resource
+    private CloseableHttpClient closeableHttpClient;
+    @Resource
+    private RequestConfig requestConfig;
+    @Resource
+    private ProjectUtil projectUtil;
+    @Resource
+    private VideoFeignClient videoFeignClient;
+    @Resource
+    private SqlSessionFactory sqlSessionFactory;
+    @Resource
+    private KubernetesConfiguration kubernetesConfiguration;
+    @Resource
+    private ApiClient apiClient;
+    @Resource(name = "myKafkaAdmin")
+    private Admin admin;
 
- public void batchInsertTask(List<TaskEntity> taskEntityList) {
-  try (SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false)) {
-   TaskMapper taskMapper1 = sqlSession.getMapper(TaskMapper.class);
-   for (TaskEntity taskEntity : taskEntityList) {
-    taskMapper1.insert(taskEntity);
-   }
-   sqlSession.commit();
-  }
- }
+    public void saveErrorMessage(String projectType,String projectId,String errorMessage){
+        if(DictConstants.PROJECT_TYPE_MANUAL.equals(projectType)){
+            manualProjectMapper.saveErrorMessage()
+        }
+    };
 
- public boolean handleErrorTask(PrefixEntity redisPrefix, String projectId, String projectType, String maxSimulationTime, String taskId, String state, String podName) {
-  return isProjectCompleted(redisPrefix, projectId, projectType, maxSimulationTime, taskId, state, podName);
- }
+    public void batchInsertTask(List<TaskEntity> taskEntityList) {
+        try (SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false)) {
+            TaskMapper taskMapper1 = sqlSession.getMapper(TaskMapper.class);
+            for (TaskEntity taskEntity : taskEntityList) {
+                taskMapper1.insert(taskEntity);
+            }
+            sqlSession.commit();
+        }
+    }
 
- /**
-  * 加事务的话高并发情况下会死锁
-  */
- @SneakyThrows
- public boolean isProjectCompleted(PrefixEntity redisPrefix, String projectId, String projectType, String maxSimulationTime, String taskId, String state, String podName) {
-  boolean result;
-  String nodeName = projectUtil.getNodeNameOfPod(projectId, podName);
-  if (DictConstants.TASK_RUNNING.equals(state)) {  // 运行中的 pod 无需删除
-   // 将运行中的任务的 pod 名称放入 redis
-   stringRedisTemplate.opsForValue().set(redisPrefix.getTaskPodKey(), podName);
-   taskTick(taskId); // 刷新一下心跳
-   log.info("修改任务 " + taskId + " 的状态为 " + state + ",pod 名称为:" + podName);
-   taskMapper.updateStateWithStartTime(taskId, state, TimeUtil.getNowForMysql());
-   return false;
-  } else { // 结束的 pod 都直接删除,并判断项目是否完成
-   // -------------------------------- 处理状态 --------------------------------
-   log.info("修改任务 {} 的状态为 {} ,pod 名称为 {} ,并删除 pod。", taskId, state, podName);
-   if (DictConstants.TASK_ABORTED.equals(state)) {
-    String minioPathOfErrorLog = resultPathMinio + projectId + "/" + taskId + "error.log";
-    boolean objectExist = MinioUtil.isObjectExist(minioClient, bucketName, minioPathOfErrorLog);
-    String targetEvaluate;
-    if (objectExist) {
-     String errorString = MinioUtil.downloadToString(minioClient, bucketName, minioPathOfErrorLog);
-     String[] lines = errorString.split("\n");
-     StringBuilder errorMessage = new StringBuilder();
-     for (String line : lines) {
-      if (line.startsWith("Original Error")) {
-       errorMessage.append(line).append("\n");
-      }
-      if (line.startsWith("Possible Cause")) {
-       errorMessage.append(line);
-       break;
-      }
-     }
-     targetEvaluate = errorMessage.toString();
-    } else {
-     targetEvaluate = DictConstants.TASK_ERROR_REASON_2;
+    public boolean handleErrorTask(PrefixEntity redisPrefix, String projectId, String projectType, String maxSimulationTime, String taskId, String state, String podName) {
+        return isProjectCompleted(redisPrefix, projectId, projectType, maxSimulationTime, taskId, state, podName);
     }
-    taskMapper.updateFailStateWithStopTime(taskId, state, TimeUtil.getNowForMysql(), targetEvaluate);
-   } else if (DictConstants.TASK_TERMINATED.equals(state)) {
-    taskMapper.updateFailStateWithStopTime(taskId, state, TimeUtil.getNowForMysql(), DictConstants.TASK_ERROR_REASON_3);
-   } else if (DictConstants.TASK_ANALYSIS.equals(state)) { // 该状态只会获得一次
-    taskMapper.updateSuccessStateWithStopTime(taskId, state, TimeUtil.getNowForMysql());
-    // 查询项目是否使用 gpu 生成视频(0是1否)
-    String isChoiceGpu = projectUtil.getProjectByProjectId(projectId).getIsChoiceGpu();
-    if (DictConstants.VIDEO_GPU.equals(isChoiceGpu)) {
-     log.info("项目 {} 使用 GPU 生成视频。", projectId);
-    } else if (DictConstants.VIDEO_CPU.equals(isChoiceGpu)) {
-     log.info("项目 {} 使用 CPU 生成视频。", projectId);
-     videoFeignClient.generateVideo(projectId, projectType, maxSimulationTime, taskId);
-    } else {
-     throw new RuntimeException("未设置视频生成。");
+
+    /**
+     * 加事务的话高并发情况下会死锁
+     */
+    @SneakyThrows
+    public boolean isProjectCompleted(PrefixEntity redisPrefix, String projectId, String projectType, String maxSimulationTime, String taskId, String state, String podName) {
+        boolean result;
+        String nodeName = projectUtil.getNodeNameOfPod(projectId, podName);
+        if (DictConstants.TASK_RUNNING.equals(state)) {  // 运行中的 pod 无需删除
+            // 将运行中的任务的 pod 名称放入 redis
+            stringRedisTemplate.opsForValue().set(redisPrefix.getTaskPodKey(), podName);
+            taskTick(taskId); // 刷新一下心跳
+            log.info("修改任务 " + taskId + " 的状态为 " + state + ",pod 名称为:" + podName);
+            taskMapper.updateStateWithStartTime(taskId, state, TimeUtil.getNowForMysql());
+            return false;
+        } else { // 结束的 pod 都直接删除,并判断项目是否完成
+            // -------------------------------- 处理状态 --------------------------------
+            log.info("修改任务 {} 的状态为 {} ,pod 名称为 {} ,并删除 pod。", taskId, state, podName);
+            if (DictConstants.TASK_ABORTED.equals(state)) {
+                String minioPathOfErrorLog = resultPathMinio + projectId + "/" + taskId + "error.log";
+                boolean objectExist = MinioUtil.isObjectExist(minioClient, bucketName, minioPathOfErrorLog);
+                String targetEvaluate;
+                if (objectExist) {
+                    String errorString = MinioUtil.downloadToString(minioClient, bucketName, minioPathOfErrorLog);
+                    String[] lines = errorString.split("\n");
+                    StringBuilder errorMessage = new StringBuilder();
+                    for (String line : lines) {
+                        if (line.startsWith("Original Error")) {
+                            errorMessage.append(line).append("\n");
+                        }
+                        if (line.startsWith("Possible Cause")) {
+                            errorMessage.append(line);
+                            break;
+                        }
+                    }
+                    targetEvaluate = errorMessage.toString();
+                } else {
+                    targetEvaluate = DictConstants.TASK_ERROR_REASON_2;
+                }
+                taskMapper.updateFailStateWithStopTime(taskId, state, TimeUtil.getNowForMysql(), targetEvaluate);
+            } else if (DictConstants.TASK_TERMINATED.equals(state)) {
+                taskMapper.updateFailStateWithStopTime(taskId, state, TimeUtil.getNowForMysql(), DictConstants.TASK_ERROR_REASON_3);
+            } else if (DictConstants.TASK_ANALYSIS.equals(state)) { // 该状态只会获得一次
+                taskMapper.updateSuccessStateWithStopTime(taskId, state, TimeUtil.getNowForMysql());
+                // 查询项目是否使用 gpu 生成视频(0是1否)
+                String isChoiceGpu = projectUtil.getProjectByProjectId(projectId).getIsChoiceGpu();
+                if (DictConstants.VIDEO_GPU.equals(isChoiceGpu)) {
+                    log.info("项目 {} 使用 GPU 生成视频。", projectId);
+                } else if (DictConstants.VIDEO_CPU.equals(isChoiceGpu)) {
+                    log.info("项目 {} 使用 CPU 生成视频。", projectId);
+                    videoFeignClient.generateVideo(projectId, projectType, maxSimulationTime, taskId);
+                } else {
+                    throw new RuntimeException("未设置视频生成。");
+                }
+            }
+            // -------------------------------- 判断项目是否结束 --------------------------------
+            result = projectUtil.complete(redisPrefix, projectId);
+            if (!result) {
+                log.info("项目 " + projectId + " 还未运行完成。");
+                projectUtil.createNextPod(projectId, nodeName, podName);
+            } else {
+                //如果项目已完成先把 pod 删除,并归还并行度
+                KubernetesUtil.deletePod2(apiClient, kubernetesConfiguration.getNamespace(), podName);
+                projectUtil.incrementOneParallelismOfGpuNode(nodeName);
+            }
+            RedisUtil.deleteByPrefix(stringRedisTemplate, redisPrefix.getTaskMessageKey());
+            RedisUtil.deleteByPrefix(stringRedisTemplate, redisPrefix.getTaskPodKey());
+        }
+        return result;
     }
-   }
-   // -------------------------------- 判断项目是否结束 --------------------------------
-   result = projectUtil.complete(redisPrefix, projectId);
-   if (!result) {
-    log.info("项目 " + projectId + " 还未运行完成。");
-    projectUtil.createNextPod(projectId, nodeName, podName);
-   } else {
-    //如果项目已完成先把 pod 删除,并归还并行度
-    KubernetesUtil.deletePod2(apiClient, kubernetesConfiguration.getNamespace(), podName);
-    projectUtil.incrementOneParallelismOfGpuNode(nodeName);
-   }
-   RedisUtil.deleteByPrefix(stringRedisTemplate, redisPrefix.getTaskMessageKey());
-   RedisUtil.deleteByPrefix(stringRedisTemplate, redisPrefix.getTaskPodKey());
-  }
-  return result;
- }
 
 
- /**
-  * @param userId 项目创建用户的 id
-  */
- @SneakyThrows
- public void score(String projectRunningKey, String userId, String projectId, String projectType) {
-  stringRedisTemplate.delete(projectRunningKey);
-  // -------------------------------- 打分 --------------------------------
-  ProjectEntity projectEntity = null;
-  if (DictConstants.PROJECT_TYPE_MANUAL.equals(projectType)) {
-   projectEntity = manualProjectMapper.selectById(projectId);
-  } else if (DictConstants.PROJECT_TYPE_AUTO_SUB.equals(projectType)) {
-   projectEntity = autoSubProjectMapper.selectById(projectId);
-  }
-  if (projectEntity == null) {
-   log.error("不存在项目 {}" + projectId);
-   return;
-  }
-  String packageId = projectEntity.getScenePackageId();  // 场景测试包 id,指标的rootId
-  TimeUnit.SECONDS.sleep(10); // 先等一下数据库更新
-  List<TaskEntity> taskList = taskMapper.selectTaskListByProjectId(projectId);  // 所有任务信息
-  if (CollectionUtil.isEmpty(taskList)) {
-   log.error("项目 {} 下没有查询到任务!", projectId);
-   return;
-  }
-  indexMapper.deleteFirstByProjectId(projectId);
-  indexMapper.deleteLastByProjectId(projectId);
-  //1 查询场景包对应指标
-  String allIndexKey = "project:" + projectId + ":package:" + packageId + ":all";
-  String leafIndexKey = "project:" + projectId + ":package:" + packageId + ":leaf";
-  String allIndexTemplateListJson = stringRedisTemplate.opsForValue().get(allIndexKey);
-  String leafIndexTemplateListJson = stringRedisTemplate.opsForValue().get(leafIndexKey);
-  List<IndexTemplateEntity> allIndexTemplateList = JsonUtil.jsonToList(allIndexTemplateListJson, IndexTemplateEntity.class);
-  List<IndexTemplateEntity> leafIndexTemplateList = JsonUtil.jsonToList(leafIndexTemplateListJson, IndexTemplateEntity.class);
-  log.info("共有 " + leafIndexTemplateList.size() + "个叶子节点:" + leafIndexTemplateListJson);
-  int maxLevel = 1; // 用于计算指标得分
-  List<LeafIndexEntity> leafIndexList = new ArrayList<>();
-  for (int i = 0; i < leafIndexTemplateList.size(); i++) {
-   String scoreExplain = null; // 每个叶子指标下的任务的得分说明一样和叶子指标一致
-   IndexTemplateEntity leafIndexTemplate = leafIndexTemplateList.get(i);
-   String indexId = leafIndexTemplate.getIndexId(); // 叶子指标id
-   String parentId = leafIndexTemplate.getParentId(); // 父 id
-   String rootId = leafIndexTemplate.getRootId(); // 包 id
-   String weight = leafIndexTemplate.getWeight(); // 权重
-   Integer packageLevel = leafIndexTemplate.getPackageLevel(); // 几级指标
-   String ruleName = leafIndexTemplate.getRuleName();    // 打分脚本名称,例如 AEB_1-1
-   String ruleDetails = leafIndexTemplate.getRuleDetails();    // 打分脚本内容
-   if (packageLevel > maxLevel) {
-    maxLevel = packageLevel;
-   }
-   log.info("开始执行对第 " + (i + 1) + " 个叶子节点 " + indexId + " 进行打分!");
-   // 根据叶子指标id查询评分规则创建用户id
-   String createUserIdOfRule = scoringRulesMapper.selectCreateUserIdByIndexId(indexId);
-   //1 判断有没有用户目录,没有则复制
-   String scoreDirectoryOfUser = linuxTempPath + "score/" + createUserIdOfRule + "/";
-   if (!new File(scoreDirectoryOfUser + "main.py").exists()) {
-    // 复制 main.py
-    FileUtil.createDirectory(scoreDirectoryOfUser);
-    FileUtil.cpR(pyPath, scoreDirectoryOfUser);
-   }
-   //2 将打分规则保存到script目录
+    /**
+     * @param userId 项目创建用户的 id
+     */
+    @SneakyThrows
+    public void score(String projectRunningKey, String userId, String projectId, String projectType) {
+        stringRedisTemplate.delete(projectRunningKey);
+        // -------------------------------- 打分 --------------------------------
+        ProjectEntity projectEntity = null;
+        if (DictConstants.PROJECT_TYPE_MANUAL.equals(projectType)) {
+            projectEntity = manualProjectMapper.selectById(projectId);
+        } else if (DictConstants.PROJECT_TYPE_AUTO_SUB.equals(projectType)) {
+            projectEntity = autoSubProjectMapper.selectById(projectId);
+        }
+        if (projectEntity == null) {
+            log.error("不存在项目 {}" + projectId);
+            return;
+        }
+        String packageId = projectEntity.getScenePackageId();  // 场景测试包 id,指标的rootId
+        TimeUnit.SECONDS.sleep(10); // 先等一下数据库更新
+        List<TaskEntity> taskList = taskMapper.selectTaskListByProjectId(projectId);  // 所有任务信息
+        if (CollectionUtil.isEmpty(taskList)) {
+            log.error("项目 {} 下没有查询到任务!", projectId);
+            return;
+        }
+        indexMapper.deleteFirstByProjectId(projectId);
+        indexMapper.deleteLastByProjectId(projectId);
+        //1 查询场景包对应指标
+        String allIndexKey = "project:" + projectId + ":package:" + packageId + ":all";
+        String leafIndexKey = "project:" + projectId + ":package:" + packageId + ":leaf";
+        String allIndexTemplateListJson = stringRedisTemplate.opsForValue().get(allIndexKey);
+        String leafIndexTemplateListJson = stringRedisTemplate.opsForValue().get(leafIndexKey);
+        List<IndexTemplateEntity> allIndexTemplateList = JsonUtil.jsonToList(allIndexTemplateListJson, IndexTemplateEntity.class);
+        List<IndexTemplateEntity> leafIndexTemplateList = JsonUtil.jsonToList(leafIndexTemplateListJson, IndexTemplateEntity.class);
+        log.info("共有 " + leafIndexTemplateList.size() + "个叶子节点:" + leafIndexTemplateListJson);
+        int maxLevel = 1; // 用于计算指标得分
+        List<LeafIndexEntity> leafIndexList = new ArrayList<>();
+        for (int i = 0; i < leafIndexTemplateList.size(); i++) {
+            String scoreExplain = null; // 每个叶子指标下的任务的得分说明一样和叶子指标一致
+            IndexTemplateEntity leafIndexTemplate = leafIndexTemplateList.get(i);
+            String indexId = leafIndexTemplate.getIndexId(); // 叶子指标id
+            String parentId = leafIndexTemplate.getParentId(); // 父 id
+            String rootId = leafIndexTemplate.getRootId(); // 包 id
+            String weight = leafIndexTemplate.getWeight(); // 权重
+            Integer packageLevel = leafIndexTemplate.getPackageLevel(); // 几级指标
+            String ruleName = leafIndexTemplate.getRuleName();    // 打分脚本名称,例如 AEB_1-1
+            String ruleDetails = leafIndexTemplate.getRuleDetails();    // 打分脚本内容
+            if (packageLevel > maxLevel) {
+                maxLevel = packageLevel;
+            }
+            log.info("开始执行对第 " + (i + 1) + " 个叶子节点 " + indexId + " 进行打分!");
+            // 根据叶子指标id查询评分规则创建用户id
+            String createUserIdOfRule = scoringRulesMapper.selectCreateUserIdByIndexId(indexId);
+            //1 判断有没有用户目录,没有则复制
+            String scoreDirectoryOfUser = linuxTempPath + "score/" + createUserIdOfRule + "/";
+            if (!new File(scoreDirectoryOfUser + "main.py").exists()) {
+                // 复制 main.py
+                FileUtil.createDirectory(scoreDirectoryOfUser);
+                FileUtil.cpR(pyPath, scoreDirectoryOfUser);
+            }
+            //2 将打分规则保存到script目录
 
-   String ruleFilePath = scoreDirectoryOfUser + "scripts/" + ruleName.split("_")[0] + "/" + ruleName + ".py";
-   FileUtil.writeInputStreamToLocalFile(IoUtil.stringToInputStream(ruleDetails), ruleFilePath);
-   log.info("将叶子节点 " + indexId + " 对应的打分规则保存到临时目录:" + ruleFilePath);
-   List<TaskEntity> taskListOfLeafIndex = taskList.stream().filter(task -> indexId.equals(task.getLastTargetId())).collect(Collectors.toList());
-   log.info("叶子节点 " + indexId + " 包括 " + taskListOfLeafIndex.size() + " 个任务:" + taskListOfLeafIndex);
-   // 计算叶子指标的得分
-   // 使用 stream 流会出现无法进入循环的情况
-   for (TaskEntity taskOfLeaf : taskListOfLeafIndex) {
-    String task2Id = taskOfLeaf.getId();
+            String ruleFilePath = scoreDirectoryOfUser + "scripts/" + ruleName.split("_")[0] + "/" + ruleName + ".py";
+            FileUtil.writeInputStreamToLocalFile(IoUtil.stringToInputStream(ruleDetails), ruleFilePath);
+            log.info("将叶子节点 " + indexId + " 对应的打分规则保存到临时目录:" + ruleFilePath);
+            List<TaskEntity> taskListOfLeafIndex = taskList.stream().filter(task -> indexId.equals(task.getLastTargetId())).collect(Collectors.toList());
+            log.info("叶子节点 " + indexId + " 包括 " + taskListOfLeafIndex.size() + " 个任务:" + taskListOfLeafIndex);
+            // 计算叶子指标的得分
+            // 使用 stream 流会出现无法进入循环的情况
+            for (TaskEntity taskOfLeaf : taskListOfLeafIndex) {
+                String task2Id = taskOfLeaf.getId();
 
-    String runState = taskOfLeaf.getRunState();
-    log.info("TaskManager--score 任务 " + task2Id + " 的运行状态为:" + runState);
-    if (DictConstants.TASK_ANALYSIS.equals(runState)) {
-     taskMapper.updateSuccessStateWithStopTime(task2Id, DictConstants.TASK_ANALYSING, TimeUtil.getNowForMysql());
-     // 计算每个任务的得分
-     String result1OfMinio = taskOfLeaf.getRunResultFilePath() + "/Ego.csv";
-     String result1OfLinux = linuxTempPath + result1OfMinio;
-     String result2OfMinio = taskOfLeaf.getRunResultFilePath() + "/evaluation.csv";
-     String result2OfLinux = linuxTempPath + result2OfMinio;
-     String scoreCommand = "python3 " + scoreDirectoryOfUser + "main.py " + result1OfLinux + " " + result2OfLinux + " " + taskOfLeaf.getSceneType() + " " + ruleName; // 指定打分脚本
-     String scoreResult;
-     ScoreEntity score = null;
-     log.info("下载 minio 上的结果文件 " + result1OfMinio + " 和 " + result2OfMinio + " 到临时目录:" + linuxTempPath);
-     MinioUtil.downloadToFile(minioClient, bucketName, result1OfMinio, result1OfLinux);  // 也可改成下载到指定ip的服务器上,需要保证和打分脚本在一台机器上。
-     MinioUtil.downloadToFile(minioClient, bucketName, result2OfMinio, result2OfLinux);  // 也可改成下载到指定ip的服务器上,需要保证和打分脚本在一台机器上。
-     log.info("开始执行打分命令:" + scoreCommand);
-     Runtime r = Runtime.getRuntime();
-     Process p = r.exec(scoreCommand, null, new File(scoreDirectoryOfUser));
-     BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
-     StringBuilder sb = new StringBuilder();
-     String inline;
-     while (null != (inline = br.readLine())) {
-      sb.append(inline).append("\n");
-     }
-     scoreResult = sb.toString();
-     log.info("项目" + projectId + " 的任务 " + task2Id + " 打分结束,结果为:" + scoreResult);
-     String replace = StringUtil.replace(scoreResult, "'", "\"");
-     try {
-      score = JsonUtil.jsonToBean(replace, ScoreEntity.class);
-     } catch (Exception e) { // 打分失败
-      log.info("项目" + projectId + " 的任务 " + task2Id + " 打分失败:", e);
-     }
-     if (score != null) {
-      taskOfLeaf.setReturnSceneId(score.getUnit_scene_ID());
-      taskOfLeaf.setTargetEvaluate(score.getEvaluate_item());
-      taskOfLeaf.setScoreExplain(score.getScore_description());
-      taskOfLeaf.setModifyUserId(userId);
-      taskOfLeaf.setModifyTime(TimeUtil.getNowForMysql());
-      scoreExplain = score.getScore_description();
-      taskOfLeaf.setRunState(DictConstants.TASK_COMPLETED);
-      double taskScore = score.getUnit_scene_score();
-      if (taskScore == -1.0) {
-       taskOfLeaf.setScore(0.0);
-       taskOfLeaf.setScored(false);
-      } else {
-       taskOfLeaf.setScore(NumberUtil.cut(taskScore, 2));
-       taskOfLeaf.setScored(true);
-      }
-      taskMapper.updateSuccessState(taskOfLeaf, DictConstants.TASK_COMPLETED);
-     } else {
-      //1 修改任务状态为 aborted
-      taskOfLeaf.setRunState(DictConstants.TASK_ABORTED);
-      taskOfLeaf.setScore(0.0);
-      taskOfLeaf.setScored(false);
-      taskMapper.updateFailStateWithStopTime(task2Id, DictConstants.TASK_ABORTED, TimeUtil.getNowForMysql(), DictConstants.TASK_ERROR_REASON_5);
-     }
-    }
-   }
+                String runState = taskOfLeaf.getRunState();
+                log.info("TaskManager--score 任务 " + task2Id + " 的运行状态为:" + runState);
+                if (DictConstants.TASK_ANALYSIS.equals(runState)) {
+                    taskMapper.updateSuccessStateWithStopTime(task2Id, DictConstants.TASK_ANALYSING, TimeUtil.getNowForMysql());
+                    // 计算每个任务的得分
+                    String result1OfMinio = taskOfLeaf.getRunResultFilePath() + "/Ego.csv";
+                    String result1OfLinux = linuxTempPath + result1OfMinio;
+                    String result2OfMinio = taskOfLeaf.getRunResultFilePath() + "/evaluation.csv";
+                    String result2OfLinux = linuxTempPath + result2OfMinio;
+                    String scoreCommand = "python3 " + scoreDirectoryOfUser + "main.py " + result1OfLinux + " " + result2OfLinux + " " + taskOfLeaf.getSceneType() + " " + ruleName; // 指定打分脚本
+                    String scoreResult;
+                    ScoreEntity score = null;
+                    log.info("下载 minio 上的结果文件 " + result1OfMinio + " 和 " + result2OfMinio + " 到临时目录:" + linuxTempPath);
+                    MinioUtil.downloadToFile(minioClient, bucketName, result1OfMinio, result1OfLinux);  // 也可改成下载到指定ip的服务器上,需要保证和打分脚本在一台机器上。
+                    MinioUtil.downloadToFile(minioClient, bucketName, result2OfMinio, result2OfLinux);  // 也可改成下载到指定ip的服务器上,需要保证和打分脚本在一台机器上。
+                    log.info("开始执行打分命令:" + scoreCommand);
+                    Runtime r = Runtime.getRuntime();
+                    Process p = r.exec(scoreCommand, null, new File(scoreDirectoryOfUser));
+                    BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
+                    StringBuilder sb = new StringBuilder();
+                    String inline;
+                    while (null != (inline = br.readLine())) {
+                        sb.append(inline).append("\n");
+                    }
+                    scoreResult = sb.toString();
+                    log.info("项目" + projectId + " 的任务 " + task2Id + " 打分结束,结果为:" + scoreResult);
+                    String replace = StringUtil.replace(scoreResult, "'", "\"");
+                    try {
+                        score = JsonUtil.jsonToBean(replace, ScoreEntity.class);
+                    } catch (Exception e) { // 打分失败
+                        log.info("项目" + projectId + " 的任务 " + task2Id + " 打分失败:", e);
+                    }
+                    if (score != null) {
+                        taskOfLeaf.setReturnSceneId(score.getUnit_scene_ID());
+                        taskOfLeaf.setTargetEvaluate(score.getEvaluate_item());
+                        taskOfLeaf.setScoreExplain(score.getScore_description());
+                        taskOfLeaf.setModifyUserId(userId);
+                        taskOfLeaf.setModifyTime(TimeUtil.getNowForMysql());
+                        scoreExplain = score.getScore_description();
+                        taskOfLeaf.setRunState(DictConstants.TASK_COMPLETED);
+                        double taskScore = score.getUnit_scene_score();
+                        if (taskScore == -1.0) {
+                            taskOfLeaf.setScore(0.0);
+                            taskOfLeaf.setScored(false);
+                        } else {
+                            taskOfLeaf.setScore(NumberUtil.cut(taskScore, 2));
+                            taskOfLeaf.setScored(true);
+                        }
+                        taskMapper.updateSuccessState(taskOfLeaf, DictConstants.TASK_COMPLETED);
+                    } else {
+                        //1 修改任务状态为 aborted
+                        taskOfLeaf.setRunState(DictConstants.TASK_ABORTED);
+                        taskOfLeaf.setScore(0.0);
+                        taskOfLeaf.setScored(false);
+                        taskMapper.updateFailStateWithStopTime(task2Id, DictConstants.TASK_ABORTED, TimeUtil.getNowForMysql(), DictConstants.TASK_ERROR_REASON_5);
+                    }
+                }
+            }
 
-   // 全部参与计算
-   // 计算不合格的任务数(不到100分就是不合格,执行失败的不算)
-   // 计算叶子指标下任务得分总和
-   int errorSceneNumber = 0;   // 仿真失败的任务
-   int notScoredSceneNumber = 0;   // 评分失败的任务
-   int notStandardSceneNumber = 0;
-   int standardSceneNumber = 0;
-   double leafSum = 0.0;
-   for (TaskEntity task : taskListOfLeafIndex) {
-    Double scoreTemp = task.getScore();
-    if (scoreTemp == null) {   // 失败状态的任务是没有分数的,计作 0 分。
-     errorSceneNumber++;
-     scoreTemp = 0.0;
-    } else if (task.getScored() == null || !task.getScored()) {  // 如果评分失败,也计作 0 分
-     notScoredSceneNumber++;
-     scoreTemp = 0.0;
-    } else if (scoreTemp < 100.0) {
-     notStandardSceneNumber++;
-    } else if (scoreTemp == 100.0) {
-     standardSceneNumber++;
-    }
-    // 计算分数总和
-    leafSum += scoreTemp;
-   }
+            // 全部参与计算
+            // 计算不合格的任务数(不到100分就是不合格,执行失败的不算)
+            // 计算叶子指标下任务得分总和
+            int errorSceneNumber = 0;   // 仿真失败的任务
+            int notScoredSceneNumber = 0;   // 评分失败的任务
+            int notStandardSceneNumber = 0;
+            int standardSceneNumber = 0;
+            double leafSum = 0.0;
+            for (TaskEntity task : taskListOfLeafIndex) {
+                Double scoreTemp = task.getScore();
+                if (scoreTemp == null) {   // 失败状态的任务是没有分数的,计作 0 分。
+                    errorSceneNumber++;
+                    scoreTemp = 0.0;
+                } else if (task.getScored() == null || !task.getScored()) {  // 如果评分失败,也计作 0 分
+                    notScoredSceneNumber++;
+                    scoreTemp = 0.0;
+                } else if (scoreTemp < 100.0) {
+                    notStandardSceneNumber++;
+                } else if (scoreTemp == 100.0) {
+                    standardSceneNumber++;
+                }
+                // 计算分数总和
+                leafSum += scoreTemp;
+            }
 
-   // 计算任务的个数
-   long taskNumberToScore = taskListOfLeafIndex.size();
-   log.info("项目 " + projectId + " 的叶子指标 " + indexId + " 下参与计算的任务总数为 " + taskNumberToScore + ":仿真异常场景个数 " + errorSceneNumber + "、未达标场景个数 " + notStandardSceneNumber + "、达标场景个数 " + standardSceneNumber);
+            // 计算任务的个数
+            long taskNumberToScore = taskListOfLeafIndex.size();
+            log.info("项目 " + projectId + " 的叶子指标 " + indexId + " 下参与计算的任务总数为 " + taskNumberToScore + ":仿真异常场景个数 " + errorSceneNumber + "、未达标场景个数 " + notStandardSceneNumber + "、达标场景个数 " + standardSceneNumber);
 
-   // 计算叶子指标得分(任务得分总和 / 任务数量)
-   double leafIndexScore = NumberUtil.cut(leafSum / taskNumberToScore, 2);
-   // 创建叶子指标对象
-   leafIndexTemplate.setTempScore(leafIndexScore);
+            // 计算叶子指标得分(任务得分总和 / 任务数量)
+            double leafIndexScore = NumberUtil.cut(leafSum / taskNumberToScore, 2);
+            // 创建叶子指标对象
+            leafIndexTemplate.setTempScore(leafIndexScore);
 
-   LeafIndexEntity leafIndex = LeafIndexEntity.builder().id(StringUtil.getRandomUUID()).pId(projectId).target(leafIndexTemplate.getIndexId()).errorSceneNum(errorSceneNumber).notScoredSceneNum(notScoredSceneNumber).notStandardSceneNum(notStandardSceneNumber).standardSceneNum(standardSceneNumber).score(leafIndexScore).indexId(indexId).parentId(parentId).rootId(rootId).weight(weight).scoreExplain(scoreExplain).packageLevel(packageLevel).build();
-   leafIndex.setCreateUserId(userId);
-   leafIndex.setCreateTime(TimeUtil.getNowForMysql());
-   leafIndex.setModifyUserId(userId);
-   leafIndex.setModifyTime(TimeUtil.getNowForMysql());
-   leafIndex.setIsDeleted("0");
+            LeafIndexEntity leafIndex = LeafIndexEntity.builder().id(StringUtil.getRandomUUID()).pId(projectId).target(leafIndexTemplate.getIndexId()).errorSceneNum(errorSceneNumber).notScoredSceneNum(notScoredSceneNumber).notStandardSceneNum(notStandardSceneNumber).standardSceneNum(standardSceneNumber).score(leafIndexScore).indexId(indexId).parentId(parentId).rootId(rootId).weight(weight).scoreExplain(scoreExplain).packageLevel(packageLevel).build();
+            leafIndex.setCreateUserId(userId);
+            leafIndex.setCreateTime(TimeUtil.getNowForMysql());
+            leafIndex.setModifyUserId(userId);
+            leafIndex.setModifyTime(TimeUtil.getNowForMysql());
+            leafIndex.setIsDeleted("0");
 
-   leafIndexList.add(leafIndex);
-  }
-  // 保存叶子指标得分
-  taskIndexManager.batchInsertLeafIndex(leafIndexList);
-  // 保存一级指标分数
-  log.info("项目 " + projectId + " 的所有任务分数为:" + taskList);
-  computeFirst(leafIndexList, allIndexTemplateList, projectId, maxLevel);
-  log.info("项目 " + projectId + " 打分完成!");
- }
+            leafIndexList.add(leafIndex);
+        }
+        // 保存叶子指标得分
+        taskIndexManager.batchInsertLeafIndex(leafIndexList);
+        // 保存一级指标分数
+        log.info("项目 " + projectId + " 的所有任务分数为:" + taskList);
+        computeFirst(leafIndexList, allIndexTemplateList, projectId, maxLevel);
+        log.info("项目 " + projectId + " 打分完成!");
+    }
 
- 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.info("计算父指标得分:" + leafIndexList);
-  Iterator<LeafIndexEntity> leafTaskIndexIterator = leafIndexList.iterator();
-  // 把 1 级的指标得分直接保存
-  while (leafTaskIndexIterator.hasNext()) {
-   LeafIndexEntity leafTaskIndex = leafTaskIndexIterator.next();
-   if (leafTaskIndex.getPackageLevel() == 1) {
-    leafTaskIndex.setCreateUserId(leafTaskIndex.getCreateUserId());
-    leafTaskIndex.setCreateTime(TimeUtil.getNowForMysql());
-    leafTaskIndex.setModifyUserId(leafTaskIndex.getModifyUserId());
-    leafTaskIndex.setModifyTime(TimeUtil.getNowForMysql());
-    leafTaskIndex.setIsDeleted("0");
-    indexMapper.insertFirstIndex(leafTaskIndex);
-    leafTaskIndexIterator.remove();
-   }
-  }
-  if (leafIndexList.size() > 0) {
-   List<LeafIndexEntity> nextLevelIndexList = new ArrayList<>();
-   // 找出等级和 maxLevel 不相同的指标暂时不计算
-   leafIndexList.stream().filter(po -> maxLevel != po.getPackageLevel()).forEach(nextLevelIndexList::add);
-   // 找出等级和 maxLevel 相同的指标并根据父指标分组
-   Map<String, List<LeafIndexEntity>> sonTaskIndexMap = leafIndexList.stream().filter(po -> maxLevel == po.getPackageLevel()).collect(Collectors.groupingBy(LeafIndexEntity::getParentId));
-   Set<String> parentIdSet = sonTaskIndexMap.keySet();
-   List<String> parentIdList = CollectionUtil.setToList(parentIdSet);
+        log.info("计算父指标得分:" + leafIndexList);
+        Iterator<LeafIndexEntity> leafTaskIndexIterator = leafIndexList.iterator();
+        // 把 1 级的指标得分直接保存
+        while (leafTaskIndexIterator.hasNext()) {
+            LeafIndexEntity leafTaskIndex = leafTaskIndexIterator.next();
+            if (leafTaskIndex.getPackageLevel() == 1) {
+                leafTaskIndex.setCreateUserId(leafTaskIndex.getCreateUserId());
+                leafTaskIndex.setCreateTime(TimeUtil.getNowForMysql());
+                leafTaskIndex.setModifyUserId(leafTaskIndex.getModifyUserId());
+                leafTaskIndex.setModifyTime(TimeUtil.getNowForMysql());
+                leafTaskIndex.setIsDeleted("0");
+                indexMapper.insertFirstIndex(leafTaskIndex);
+                leafTaskIndexIterator.remove();
+            }
+        }
+        if (leafIndexList.size() > 0) {
+            List<LeafIndexEntity> nextLevelIndexList = new ArrayList<>();
+            // 找出等级和 maxLevel 不相同的指标暂时不计算
+            leafIndexList.stream().filter(po -> maxLevel != po.getPackageLevel()).forEach(nextLevelIndexList::add);
+            // 找出等级和 maxLevel 相同的指标并根据父指标分组
+            Map<String, List<LeafIndexEntity>> sonTaskIndexMap = leafIndexList.stream().filter(po -> maxLevel == po.getPackageLevel()).collect(Collectors.groupingBy(LeafIndexEntity::getParentId));
+            Set<String> parentIdSet = sonTaskIndexMap.keySet();
+            List<String> parentIdList = CollectionUtil.setToList(parentIdSet);
 
-   List<IndexTemplateEntity> parentIndexTemplateList = allIndexTemplateList.stream().filter(indexTemplate -> parentIdList.contains(indexTemplate.getIndexId())).collect(Collectors.toList());
-   // 计算父指标得分
-   parentIndexTemplateList.forEach(indexTemplate -> {
-    String weight = indexTemplate.getWeight();
-    List<LeafIndexEntity> sonTaskIndexList = sonTaskIndexMap.get(indexTemplate.getIndexId());
-    double parentScore = NumberUtil.cut(sonTaskIndexList.stream().mapToDouble(taskIndex -> taskIndex.getScore() * Double.parseDouble(taskIndex.getWeight()) / 100).sum(), 2);
-    LeafIndexEntity parentTaskIndex = LeafIndexEntity.builder().id(StringUtil.getRandomUUID()).pId(projectId).target(indexTemplate.getIndexId()).score(parentScore).indexId(indexTemplate.getIndexId()).parentId(indexTemplate.getParentId()).rootId(indexTemplate.getRootId()).weight(weight).packageLevel(maxLevel - 1).build();
-    nextLevelIndexList.add(parentTaskIndex);
-   });
-   // 将父指标作为叶子指标递归
-   computeFirst(nextLevelIndexList, allIndexTemplateList, projectId, maxLevel - 1);
-  }
- }
+            List<IndexTemplateEntity> parentIndexTemplateList = allIndexTemplateList.stream().filter(indexTemplate -> parentIdList.contains(indexTemplate.getIndexId())).collect(Collectors.toList());
+            // 计算父指标得分
+            parentIndexTemplateList.forEach(indexTemplate -> {
+                String weight = indexTemplate.getWeight();
+                List<LeafIndexEntity> sonTaskIndexList = sonTaskIndexMap.get(indexTemplate.getIndexId());
+                double parentScore = NumberUtil.cut(sonTaskIndexList.stream().mapToDouble(taskIndex -> taskIndex.getScore() * Double.parseDouble(taskIndex.getWeight()) / 100).sum(), 2);
+                LeafIndexEntity parentTaskIndex = LeafIndexEntity.builder().id(StringUtil.getRandomUUID()).pId(projectId).target(indexTemplate.getIndexId()).score(parentScore).indexId(indexTemplate.getIndexId()).parentId(indexTemplate.getParentId()).rootId(indexTemplate.getRootId()).weight(weight).packageLevel(maxLevel - 1).build();
+                nextLevelIndexList.add(parentTaskIndex);
+            });
+            // 将父指标作为叶子指标递归
+            computeFirst(nextLevelIndexList, allIndexTemplateList, projectId, maxLevel - 1);
+        }
+    }
 
- @SneakyThrows
- public void evaluationLevel(String projectId) {
-  String tokenUrl = tokenUri + "?grant_type=client_credentials" + "&client_id=" + clientId + "&client_secret=" + clientSecret;
-  log.info("获取仿真云平台 token:" + tokenUrl);
-  String response = HttpUtil.get(closeableHttpClient, requestConfig, tokenUrl);
-  ObjectMapper objectMapper = new ObjectMapper();
-  JsonNode jsonNode = objectMapper.readTree(response);
-  String accessToken = jsonNode.path("access_token").asText();
-  log.info("仿真云平台 token 为:" + accessToken);
-  Map<String, String> headers = new HashMap<>();
-  headers.put("Authorization", "Bearer " + accessToken);
-  Map<String, String> params = new HashMap<>();
-  params.put("id", projectId);
-  String post = HttpUtil.post(closeableHttpClient, requestConfig, evaluationLevelUri, headers, params);
-  log.info("访问仿真云平台评价等级接口:" + evaluationLevelUri + ",请求头为:" + headers + ",请求体为:" + params + "结果为:" + post);
- }
+    @SneakyThrows
+    public void evaluationLevel(String projectId) {
+        String tokenUrl = tokenUri + "?grant_type=client_credentials" + "&client_id=" + clientId + "&client_secret=" + clientSecret;
+        log.info("获取仿真云平台 token:" + tokenUrl);
+        String response = HttpUtil.get(closeableHttpClient, requestConfig, tokenUrl);
+        ObjectMapper objectMapper = new ObjectMapper();
+        JsonNode jsonNode = objectMapper.readTree(response);
+        String accessToken = jsonNode.path("access_token").asText();
+        log.info("仿真云平台 token 为:" + accessToken);
+        Map<String, String> headers = new HashMap<>();
+        headers.put("Authorization", "Bearer " + accessToken);
+        Map<String, String> params = new HashMap<>();
+        params.put("id", projectId);
+        String post = HttpUtil.post(closeableHttpClient, requestConfig, evaluationLevelUri, headers, params);
+        log.info("访问仿真云平台评价等级接口:" + evaluationLevelUri + ",请求头为:" + headers + ",请求体为:" + params + "结果为:" + post);
+    }
 
 
- public Boolean taskConfirm(String taskId) {
-  // 查询 task 如果不是 pending 则不执行
-  String state = taskMapper.selectStateById(taskId);
-  return DictConstants.TASK_PENDING.equals(state);
- }
+    public Boolean taskConfirm(String taskId) {
+        // 查询 task 如果不是 pending 则不执行
+        String state = taskMapper.selectStateById(taskId);
+        return DictConstants.TASK_PENDING.equals(state);
+    }
 
- public void taskTick(String taskId) {
-  log.info("收到任务 " + taskId + " 的心跳。");
-  TaskEntity taskEntity = taskMapper.selectById(taskId);
-  String projectId = taskEntity.getPId();
-  String userId = taskEntity.getCreateUserId();
-  // 刷新 redis 心跳时间
-  PrefixEntity redisPrefix = projectUtil.getRedisPrefixByUserIdAndProjectIdAndTaskId(userId, projectId, taskId);
-  if (RedisUtil.getStringByKey(stringRedisTemplate, redisPrefix.getProjectRunningKey()) != null) {
-   stringRedisTemplate.opsForValue().set(redisPrefix.getTaskTickKey(), TimeUtil.getNowString());
-  }
+    public void taskTick(String taskId) {
+        log.info("收到任务 " + taskId + " 的心跳。");
+        TaskEntity taskEntity = taskMapper.selectById(taskId);
+        String projectId = taskEntity.getPId();
+        String userId = taskEntity.getCreateUserId();
+        // 刷新 redis 心跳时间
+        PrefixEntity redisPrefix = projectUtil.getRedisPrefixByUserIdAndProjectIdAndTaskId(userId, projectId, taskId);
+        if (RedisUtil.getStringByKey(stringRedisTemplate, redisPrefix.getProjectRunningKey()) != null) {
+            stringRedisTemplate.opsForValue().set(redisPrefix.getTaskTickKey(), TimeUtil.getNowString());
+        }
 
- }
+    }
 
 
- @SneakyThrows
- public void done(PrefixEntity redisPrefix, String projectId, String projectType) {
-  // 更新项目状态为已完成
-  if (DictConstants.PROJECT_TYPE_MANUAL.equals(projectType)) {
-   manualProjectMapper.updateProjectState(projectId, DictConstants.PROJECT_COMPLETED, TimeUtil.getNowForMysql());
-  } else if (DictConstants.PROJECT_TYPE_AUTO_SUB.equals(projectType)) {
-   autoSubProjectMapper.updateProjectState(projectId, DictConstants.PROJECT_COMPLETED, TimeUtil.getNowForMysql());
-  }
-  // 删除 kafka topic
-  ApacheKafkaUtil.deleteTopic(admin, projectId);
-  // 删除 redis 中的 项目运行信息 键值对
-  RedisUtil.deleteByPrefix(stringRedisTemplate, redisPrefix.getProjectRunningKey());
-  RedisUtil.deleteByPrefix(stringRedisTemplate, "project:" + projectId);
-  // 删除剩余 yaml
-  projectUtil.deleteYamlByProjectId(projectId);
- }
+    @SneakyThrows
+    public void done(PrefixEntity redisPrefix, String projectId, String projectType) {
+        // 更新项目状态为已完成
+        if (DictConstants.PROJECT_TYPE_MANUAL.equals(projectType)) {
+            manualProjectMapper.updateProjectState(projectId, DictConstants.PROJECT_COMPLETED, TimeUtil.getNowForMysql());
+        } else if (DictConstants.PROJECT_TYPE_AUTO_SUB.equals(projectType)) {
+            autoSubProjectMapper.updateProjectState(projectId, DictConstants.PROJECT_COMPLETED, TimeUtil.getNowForMysql());
+        }
+        // 删除 kafka topic
+        ApacheKafkaUtil.deleteTopic(admin, projectId);
+        // 删除 redis 中的 项目运行信息 键值对
+        RedisUtil.deleteByPrefix(stringRedisTemplate, redisPrefix.getProjectRunningKey());
+        RedisUtil.deleteByPrefix(stringRedisTemplate, "project:" + projectId);
+        // 删除剩余 yaml
+        projectUtil.deleteYamlByProjectId(projectId);
+    }
 
 
 }

+ 1 - 1
simulation-resource-server/src/main/java/com/css/simulation/resource/project/mapper/AutoSubProjectMapper.java

@@ -1,7 +1,7 @@
 package com.css.simulation.resource.project.mapper;
 
 
-import api.common.pojo.po.project.SchedulerProjectPO;
+import api.common.pojo.po.scheduler.SchedulerProjectPO;
 import org.apache.ibatis.annotations.*;
 import org.apache.ibatis.type.JdbcType;
 

+ 1 - 1
simulation-resource-server/src/main/java/com/css/simulation/resource/project/mapper/ManualProjectMapper.java

@@ -1,7 +1,7 @@
 package com.css.simulation.resource.project.mapper;
 
 
-import api.common.pojo.po.project.SchedulerProjectPO;
+import api.common.pojo.po.scheduler.SchedulerProjectPO;
 import org.apache.ibatis.annotations.*;
 import org.apache.ibatis.type.JdbcType;
 

+ 1 - 1
simulation-resource-server/src/main/java/com/css/simulation/resource/util/ProjectUtil.java

@@ -2,7 +2,7 @@ package com.css.simulation.resource.util;
 
 import api.common.pojo.constants.DictConstants;
 import api.common.pojo.param.project.SimulationManualProjectParam;
-import api.common.pojo.po.project.SchedulerProjectPO;
+import api.common.pojo.po.scheduler.SchedulerProjectPO;
 import api.common.pojo.po.project.SimulationManualProjectPo;
 import api.common.util.StringUtil;
 import com.css.simulation.resource.algorithm.mapper.AlgorithmMapper;