ソースを参照

获取剩余证书数量

martin 2 年 前
コミット
df81de8dbb

+ 21 - 0
api-common/src/main/java/api/common/pojo/po/project/SchedulerProjectPO.java

@@ -0,0 +1,21 @@
+package api.common.pojo.po.project;
+
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
+public class SchedulerProjectPO {
+
+    private String id;
+    private String scenePackageId;
+    private String createUserId;
+    private String parallelism;
+    private String projectType;
+
+
+}

+ 7 - 0
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/util/ProjectUtil.java

@@ -17,6 +17,7 @@ import com.css.simulation.resource.scheduler.pojo.to.KubernetesNodeTO;
 import com.css.simulation.resource.scheduler.pojo.to.PrefixTO;
 import io.kubernetes.client.openapi.ApiClient;
 import lombok.SneakyThrows;
+import lombok.Synchronized;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.data.redis.core.StringRedisTemplate;
@@ -388,6 +389,12 @@ public class ProjectUtil {
                 .build();
     }
 
+    /**
+     * 将 redis 中的变量 +1,需要保证同步
+     *
+     * @param nodeName 节点名称
+     */
+    @Synchronized
     public void addOneParallelismToNode(String nodeName) {
         String key = "node:" + nodeName + ":parallelism";
         String parallelismString = stringRedisTemplate.opsForValue().get(key);

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

@@ -18,7 +18,10 @@ import api.common.pojo.po.model.VehiclePO;
 import api.common.pojo.po.project.*;
 import api.common.pojo.po.scene.ScenePackagePO;
 import api.common.pojo.vo.project.*;
-import api.common.util.*;
+import api.common.util.JsonUtil;
+import api.common.util.ObjectUtil;
+import api.common.util.StringUtil;
+import api.common.util.TimeUtil;
 import com.css.simulation.resource.algorithm.mapper.AlgorithmMapper;
 import com.css.simulation.resource.algorithm.service.AlgorithmService;
 import com.css.simulation.resource.common.utils.AuthUtil;
@@ -44,7 +47,6 @@ import feign.Response;
 import lombok.SneakyThrows;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.BeanUtils;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.support.CronExpression;
 import org.springframework.stereotype.Service;
 import org.springframework.web.context.request.RequestContextHolder;
@@ -58,8 +60,8 @@ import java.math.RoundingMode;
 import java.net.URLEncoder;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
-import java.util.*;
 import java.util.List;
+import java.util.*;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipOutputStream;
 
@@ -67,31 +69,27 @@ import java.util.zip.ZipOutputStream;
 @Slf4j
 public class SimulationProjectServiceImpl implements SimulationProjectService {
 
-    @Autowired
-    private SimulationProjectMapper simulationProjectMapper;
-
-    @Autowired
-    private SimulationAutomaticProjectMapper simulationAutomaticProjectMapper;
-
-    @Autowired
-    private SimulationProjectTaskMapper simulationProjectTaskMapper;
-
-    @Autowired
-    private SimulationAutomaticSubProjectMapper simulationAutomaticSubProjectMapper;
-
-    @Autowired
-    private SimulationMptFirstTargetScoreMapper simulationMptFirstTargetScoreMapper;
-
-    @Autowired
-    private SimulationMptLastTargetScoreMapper simulationMptLastTargetScoreMapper;
-
-    @Autowired
-    private AlgorithmMapper algorithmMapper;
-
     @Resource
-    private KafkaService kafkaService;
-
-    @Autowired
+     SimulationProjectMapper simulationProjectMapper;
+    @Resource
+    ManualProjectMapper manualProjectMapper;
+    @Resource
+    AutoSubProjectMapper autoSubProjectMapper;
+    @Resource
+     SimulationAutomaticProjectMapper simulationAutomaticProjectMapper;
+    @Resource
+     SimulationProjectTaskMapper simulationProjectTaskMapper;
+    @Resource
+     SimulationAutomaticSubProjectMapper simulationAutomaticSubProjectMapper;
+    @Resource
+     SimulationMptFirstTargetScoreMapper simulationMptFirstTargetScoreMapper;
+    @Resource
+     SimulationMptLastTargetScoreMapper simulationMptLastTargetScoreMapper;
+    @Resource
+     AlgorithmMapper algorithmMapper;
+    @Resource
+     KafkaService kafkaService;
+    @Resource
     DictService dictService;
 
     @Resource
@@ -3242,35 +3240,37 @@ public class SimulationProjectServiceImpl implements SimulationProjectService {
     }
 
     @Override
-    public ResponseBodyVO saveEvaluationLevel(SimulationManualProjectParam param) {
+    public ResponseBodyVO<String> saveEvaluationLevel(SimulationManualProjectParam param) {
 
-        String id = param.getId();
-        if (StringUtil.isEmpty(id)) {
-            return new ResponseBodyVO(ResponseBodyVO.Response.CLIENT_FAILURE, "工作id不能为空");
-        }
-        if (isEmpty(param.getProjectType())) {
-            param.setProjectType("1");//默认
+        String projectId = param.getId();
+
+        //1 根据 projectId 获取类型 projectType
+        String projectType = null;
+        SchedulerProjectPO manualProjectPO = manualProjectMapper.selectById(projectId);
+        SchedulerProjectPO autoSubProjectPO = autoSubProjectMapper.selectById(projectId);
+        if (manualProjectPO != null) {
+            projectType = DictConstants.PROJECT_TYPE_MANUAL;
+        } else if (autoSubProjectPO != null) {
+            projectType = DictConstants.PROJECT_TYPE_AUTO_SUB;
         }
 
-        String scene = "";
-        //手动运行
-        if ("1".equals(param.getProjectType())) {
 
-            SimulationManualProjectPo po = simulationProjectMapper.selectProjectBaseById(param);
-            if (po == null) {
+        String scene = "";
+        // 手动运行
+        if (DictConstants.PROJECT_TYPE_MANUAL.equals(projectType)) {
+            SimulationManualProjectPo simulationManualProjectPo = simulationProjectMapper.selectProjectBaseById(param);
+            if (simulationManualProjectPo == null) {
                 return new ResponseBodyVO(ResponseBodyVO.Response.SERVER_FAILURE, "没有查到工作信息");
             }
-            scene = po.getScene();
-
+            scene = simulationManualProjectPo.getScene();
         }
-        //自动运行
-        else if ("2".equals(param.getProjectType())) {
-            SimulationManualProjectVo pv = simulationAutomaticSubProjectMapper.selectProjectInfo(param);
-            if (pv == null) {
+        // 自动运行
+        else if (DictConstants.PROJECT_TYPE_AUTO_SUB.equals(projectType)) {
+            SimulationManualProjectVo simulationManualProjectVo = simulationAutomaticSubProjectMapper.selectProjectInfo(param);
+            if (simulationManualProjectVo == null) {
                 return new ResponseBodyVO(ResponseBodyVO.Response.SERVER_FAILURE, "没有查到工作信息");
             }
-            scene = pv.getScene();
-
+            scene = simulationManualProjectVo.getScene();
         }
 
         //TODO 该段代码可优化,有时间再优化
@@ -3279,9 +3279,9 @@ public class SimulationProjectServiceImpl implements SimulationProjectService {
         String evaluationLevelReport = "";
 
         if (!isEmpty(scenePackageSubListVOS)) {
-            Double totalScore = 0D;
+            double totalScore = 0D;
             for (ScenePackageSubListVO v : scenePackageSubListVOS) {
-                Double weightDouble = Double.valueOf(v.getWeight());
+                double weightDouble = Double.parseDouble(v.getWeight());
                 //单个二级指标得分
                 SimulationMptFirstTargetScorePo simulationMptFirstTargetScorePo = new SimulationMptFirstTargetScorePo();
                 simulationMptFirstTargetScorePo.setPId(param.getId()); //直接(子)任务表id
@@ -3298,11 +3298,11 @@ public class SimulationProjectServiceImpl implements SimulationProjectService {
         }
 
         SimulationManualProjectPo simulationManualProjectPo = new SimulationManualProjectPo();
-        simulationManualProjectPo.setId(id);
+        simulationManualProjectPo.setId(projectId);
         simulationManualProjectPo.setEvaluationLevel(evaluationLevelReport);
         simulationProjectMapper.saveEvaluationLevel(simulationManualProjectPo);
 
-        return new ResponseBodyVO(ResponseBodyVO.Response.SUCCESS);
+        return new ResponseBodyVO<>(ResponseBodyVO.Response.SUCCESS);
     }
 
     @Override

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

@@ -0,0 +1,34 @@
+package com.css.simulation.resource.project.mapper;
+
+
+import api.common.pojo.po.project.SchedulerProjectPO;
+import org.apache.ibatis.annotations.*;
+import org.apache.ibatis.type.JdbcType;
+
+import java.util.List;
+
+@Mapper
+public interface AutoSubProjectMapper {
+
+    @Results(id = "project", value = {
+            @Result(column = "id", property = "id", jdbcType = JdbcType.VARCHAR),
+            @Result(column = "scene", property = "scenePackageId", jdbcType = JdbcType.VARCHAR),
+            @Result(column = "create_user_id", property = "createUserId", jdbcType = JdbcType.VARCHAR),
+            @Result(column = "parallelism", property = "parallelism", jdbcType = JdbcType.VARCHAR),
+            @Result(column = "project_type", property = "projectType", jdbcType = JdbcType.VARCHAR)
+    })
+    @Select("select sas.id, sap.scene, sas.create_user_id\n" +
+            "from simulation_automatic_subproject sas\n" +
+            "         left join simulation_automatic_project sap on sas.parent_id = sap.id\n" +
+            "where sas.id = #{projectId}")
+    SchedulerProjectPO selectById(@Param("projectId") String projectId);
+
+    @ResultMap("project")
+    @Select("select sas.id, sap.scene, sas.create_user_id, sap.parallelism, '2' project_type\n" +
+            "from simulation_automatic_subproject sas\n" +
+            "         left join simulation_automatic_project sap on sas.parent_id = sap.id\n" +
+            "where sas.is_deleted = '0'\n" +
+            "  and sas.now_run_state = #{nowRunState}")
+    List<SchedulerProjectPO> selectByNowRunState(@Param("nowRunState") String nowRunState);
+
+}

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

@@ -0,0 +1,34 @@
+package com.css.simulation.resource.project.mapper;
+
+
+import api.common.pojo.po.project.SchedulerProjectPO;
+import org.apache.ibatis.annotations.*;
+import org.apache.ibatis.type.JdbcType;
+
+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),
+            @Result(column = "create_user_id", property = "createUserId", jdbcType = JdbcType.VARCHAR),
+            @Result(column = "parallelism", property = "parallelism", jdbcType = JdbcType.VARCHAR),
+            @Result(column = "project_type", property = "projectType", jdbcType = JdbcType.VARCHAR)
+    })
+    @Select("select id, scene, create_user_id\n" +
+            "from simulation_manual_project\n" +
+            "where id = #{projectId}")
+    SchedulerProjectPO selectById(@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<SchedulerProjectPO> selectByNowRunState(@Param("nowRunState") String nowRunState);
+
+
+}