root 2 роки тому
батько
коміт
328c8cfba7

+ 4 - 3
api-common/src/main/java/api/common/util/ObjectUtil.java

@@ -91,7 +91,7 @@ public class ObjectUtil {
     }
 
     public static List<DictVO> DictListToTree(List<DictVO> list) {
-        List<DictVO> treeList = new ArrayList<DictVO>();
+        List<DictVO> treeList = new ArrayList<>();
         for (DictVO dictVO : list) {
             if ("0".equals(dictVO.getPid())) {
                 treeList.add(findChildren(dictVO, list));
@@ -104,7 +104,7 @@ public class ObjectUtil {
         for (DictVO node : list) {
             if (dictVO.getId().equals(node.getPid())) {
                 if (dictVO.getChildren() == null || dictVO.getChildren().size() == 0) {
-                    dictVO.setChildren(new ArrayList<DictVO>());
+                    dictVO.setChildren(new ArrayList<>());
                 }
                 dictVO.getChildren().add(findChildren(node, list));
             }
@@ -265,6 +265,7 @@ public class ObjectUtil {
     /**
      * list转tree递归调用
      */
+    @SuppressWarnings("all")
     private static <T, String> T findChildren(T parent, List<T> list, Function<T, String> getId, Function<T, String> getPid, Function<T, List<T>> getChildren, BiConsumer<T, List<T>> setChildren) {
         for (T node : list)
             if (getId.apply(parent).equals(getPid.apply(node))) {
@@ -281,7 +282,7 @@ public class ObjectUtil {
      */
     public static <T> List<T> listToTree(List<T> list) {
         if (isNull(list)) {
-            return new LinkedList<T>();
+            return new LinkedList<>();
         }
         return listToTree(list, "0");
     }

+ 1 - 1
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/configuration/redis/CustomRedisClient.java

@@ -78,7 +78,7 @@ public class CustomRedisClient {
      * 尝试加锁,无阻塞
      */
     public Boolean tryLock(String name, long expire) {
-        return stringRedisTemplate.opsForValue().setIfAbsent(name, "None", Duration.ofMillis(expire));
+        return stringRedisTemplate.opsForValue().setIfAbsent(name, "任意值", Duration.ofMillis(expire));
     }
 
     /**

+ 7 - 6
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/service/ProjectService.java

@@ -5,12 +5,12 @@ import api.common.pojo.dto.ProjectMessageDTO;
 import api.common.util.*;
 import com.css.simulation.resource.scheduler.configuration.docker.DockerConfiguration;
 import com.css.simulation.resource.scheduler.configuration.git.GitConfiguration;
-import com.css.simulation.resource.scheduler.configuration.kubernetes.KubernetesConfiguration;
+import com.css.simulation.resource.scheduler.configuration.redis.CustomRedisClient;
 import com.css.simulation.resource.scheduler.entity.AlgorithmEntity;
 import com.css.simulation.resource.scheduler.entity.IndexTemplateEntity;
+import com.css.simulation.resource.scheduler.entity.PrefixEntity;
 import com.css.simulation.resource.scheduler.entity.SceneEntity;
 import com.css.simulation.resource.scheduler.mapper.*;
-import com.css.simulation.resource.scheduler.entity.PrefixEntity;
 import com.css.simulation.resource.scheduler.util.*;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import io.minio.MinioClient;
@@ -91,15 +91,13 @@ public class ProjectService {
     @Resource
     private DockerConfiguration dockerConfiguration;
     @Resource
-    private KubernetesConfiguration kubernetesConfiguration;
-    @Resource
     private GitConfiguration gitConfiguration;
     @Resource
-    private ProjectManager projectManager;
-    @Resource
     private ManualProjectMapper manualProjectMapper;
     @Resource
     private AutoSubProjectMapper autoSubProjectMapper;
+    @Resource
+    private CustomRedisClient customRedisClient;
 
 
     // -------------------------------- Comment --------------------------------
@@ -339,6 +337,9 @@ public class ProjectService {
         } else if (DictConstants.PROJECT_TYPE_AUTO_SUB.equals(projectType)) {
             autoSubProjectMapper.updateProjectState(projectId, DictConstants.PROJECT_TERMINATED, TimeUtil.getNowForMysql());
         }
+
+        //9 如果在打分过程中被终止需要删除锁
+        customRedisClient.delete("project:" + projectId + ":completed-lock");
     }
 
 

+ 8 - 4
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/service/TaskService.java

@@ -29,18 +29,22 @@ public class TaskService {
 
     @SneakyThrows
     public void taskState(String taskId, String state, String podName) {
-        String lockName = "taskId:" + taskId + ":state:" + state + ":pod-name:" + podName;
-        customRedisClient.lock(lockName, 1L, 30 * 60L);
+        String lock1 = "taskId:" + taskId + ":state:" + state + ":pod-name:" + podName;
+        customRedisClient.lock(lock1, 1L, 30 * 60L);
         try {
+            // 查询相关信息
             TaskEntity taskEntity = taskMapper.selectById(taskId);
             String projectId = taskEntity.getPId(); // 项目 id
             ProjectEntity projectEntity = projectUtil.getProjectByProjectId(projectId);
             String projectType = projectEntity.getProjectType();  // 项目类型
             String maxSimulationTime = projectEntity.getMaxSimulationTime();  // 项目类型
             String userId = taskEntity.getCreateUserId();   // 用户 id
-            PrefixEntity redisPrefix = projectUtil.getRedisPrefixByUserIdAndProjectIdAndTaskId(userId, projectId, taskId);  // 项目前缀
+            PrefixEntity redisPrefix = projectUtil.getRedisPrefixByUserIdAndProjectIdAndTaskId(userId, projectId, taskId);
+            // 判断是否完成
             boolean projectCompleted = taskManager.isProjectCompleted(redisPrefix, projectId, projectType, maxSimulationTime, taskId, state, podName);
             if (projectCompleted) {
+                String lock2 = "project:" + projectId + ":completed-lock";
+                customRedisClient.tryLock(lock2, 10 * 60L);
                 log.info("项目 {} 开始打分。", projectId);
                 taskManager.score(redisPrefix.getProjectRunningKey(), userId, projectId, projectType);
                 log.info("项目 {} 计算评价等级。", projectId);
@@ -50,7 +54,7 @@ public class TaskService {
                 log.info("项目 {} 运行结束。", projectId);
             }
         } finally {
-            customRedisClient.unlock(lockName);
+            customRedisClient.unlock(lock1);
         }
 
     }

+ 1 - 1
simulation-resource-server/src/main/java/com/css/simulation/resource/model/service/CameraService.java

@@ -84,7 +84,7 @@ public class CameraService {
         saveCamera(cameraPO);
         cameraPO.setShare(DictConstants.YES);//转公有
         cameraPO.setCreateUserId(null);
-        //名称校验
+        // 同名覆盖,不同名新增
         List<CameraVO> list = cameraMapper.checkCameraName(cameraPO);
         if (ObjectUtil.isNotNull(list)) {
             String currentUserId = AuthUtil.getCurrentUserId();

+ 2 - 1
simulation-resource-server/src/main/java/com/css/simulation/resource/project/impl/SimulationProjectServiceImpl.java

@@ -868,7 +868,8 @@ public class SimulationProjectServiceImpl implements SimulationProjectService {
 
         totalScoreRatio = Double.valueOf(totalSceneScoreNum) / Double.valueOf(totalSceneNum) * 100;
         // 汇总得分率计算方式修改
-        algorithmScoreVo.setScoreRatio(saveTwoDecimalPlaces(totalScoreRatio));
+//        algorithmScoreVo.setScoreRatio(saveTwoDecimalPlaces(totalScoreRatio));
+        algorithmScoreVo.setScoreRatio(NumberUtil.cut(totalScoreRatio,2));
         algorithmScoreVoList.add(algorithmScoreVo);
         projectReportVo.setScoreRatio(saveTwoDecimalPlaces(totalScoreRatio));
         projectReportVo.setAlgorithmScore(saveTwoDecimalPlaces(totalScore));

+ 1 - 2
simulation-resource-server/src/main/java/com/css/simulation/resource/scene/service/ScoringRulesService.java

@@ -22,7 +22,7 @@ public class ScoringRulesService {
     @Resource
     private ScoringRulesMapper scoringRulesMapper;
     @Resource
-    ScenePackageMapper scenePackageMapper;
+    private  ScenePackageMapper scenePackageMapper;
 
     /**
      * 打分规则数据录入:
@@ -101,7 +101,6 @@ public class ScoringRulesService {
 
     @SneakyThrows
     public Integer queryCsbById(ScoringRulesParam params) {
-
         return scoringRulesMapper.queryCsbById(params);
     }