root před 2 roky
rodič
revize
f4db7aa559

+ 13 - 0
simulation-resource-server/src/main/java/com/css/simulation/resource/model/mapper/ModelConfigMapper.java

@@ -0,0 +1,13 @@
+package com.css.simulation.resource.model.mapper;
+
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Select;
+
+@Mapper
+public interface ModelConfigMapper {
+    @Select("select is_deleted\n" +
+            "from model_config\n" +
+            "where id = #{configId}")
+    String selectIsDeletedByConfigId(@Param("configId") String configId);
+}

+ 18 - 0
simulation-resource-server/src/main/java/com/css/simulation/resource/model/mapper/ModelVehicleMapper.java

@@ -0,0 +1,18 @@
+package com.css.simulation.resource.model.mapper;
+
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Select;
+
+import java.util.List;
+
+@Mapper
+public interface ModelVehicleMapper {
+    @Select("select is_deleted\n" +
+            "from model_vehicle\n" +
+            "where id in (select vehicle_id\n" +
+            "             from model_config\n" +
+            "             where id = #{configId}\n" +
+            ")")
+    List<String> selectIsDeletedByConfigId(@Param("configId") String configId);
+}

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

@@ -265,8 +265,7 @@ public class SimulationProjectServiceImpl implements SimulationProjectService {
             simulationProjectMapper.updateProjectNowRunState(param);
         } else {
             //3 校验项目的信息是否可用
-            projectUtil.checkProject(DictConstants.PROJECT_TYPE_MANUAL, po.getId(), po.getAlgorithm(), po.getVehicle(),
-                    po.getScene());
+            projectUtil.checkProject(po.getAlgorithm(), po.getVehicle(), po.getScene());
             // 已经完成的项目再次运行
             if (DictConstants.PROJECT_COMPLETED.equals(po.getNowRunState())) {
                 po.createPo(AuthUtil.getCurrentUserId());
@@ -314,7 +313,7 @@ public class SimulationProjectServiceImpl implements SimulationProjectService {
 
     private void projectRunToKafka(SimulationManualProjectPo po) {
         try {
-            log.info("projectRunToKafka() 准备发送项目消息:" + po);
+            log.info("准备发送项目消息:" + po);
             SimulationManualProjectKafkaParam kafkaParam = new SimulationManualProjectKafkaParam();
             kafkaParam.setProjectId(po.getId());
             kafkaParam.setAlgorithmId(po.getAlgorithm());
@@ -328,7 +327,7 @@ public class SimulationProjectServiceImpl implements SimulationProjectService {
             kafkaParameter.setTopic(ProjectConstants.RUN_TASK_TOPIC);
             String data = JsonUtil.beanToJson(kafkaParam);
             kafkaParameter.setData(data);
-            log.info("projectRunToKafka() 推送项目运行消息到kafka:" + data);
+            log.info("推送项目运行消息到kafka:" + data);
             kafkaTemplate.send(kafkaParameter.getTopic(), kafkaParameter.getData()).addCallback(success -> {
                 // 消息发送到的topic
                 String topic = success.getRecordMetadata().topic();
@@ -336,10 +335,8 @@ public class SimulationProjectServiceImpl implements SimulationProjectService {
                 int partition = success.getRecordMetadata().partition();
                 // 消息在分区内的offset
                 long offset = success.getRecordMetadata().offset();
-                log.info("------- 发送消息成功,主题 topic 为:" + topic + ",分区 partition 为:" + partition + ",偏移量为:" + offset + ",消息体为:" + kafkaParameter.getData());
-            }, failure -> {
-                log.error("发送消息失败:" + failure.getMessage());
-            });
+                log.info("发送消息成功,主题 topic 为:" + topic + ",分区 partition 为:" + partition + ",偏移量为:" + offset + ",消息体为:" + kafkaParameter.getData());
+            }, failure -> log.error("发送消息失败:" + failure.getMessage()));
         } catch (NumberFormatException e) {
             throw new RuntimeException(e);
         }
@@ -354,7 +351,6 @@ public class SimulationProjectServiceImpl implements SimulationProjectService {
         String data = JsonUtil.beanToJson(kafkaParam);
         kafkaParameter.setData(data);
         log.info("推送项目中止消息到kafka:" + data);
-//        kafkaService.send(kafkaParameter);
         kafkaTemplate.send(kafkaParameter.getTopic(), kafkaParameter.getData()).addCallback(success -> {
             // 消息发送到的topic
             String topic = success.getRecordMetadata().topic();
@@ -362,15 +358,9 @@ public class SimulationProjectServiceImpl implements SimulationProjectService {
             int partition = success.getRecordMetadata().partition();
             // 消息在分区内的offset
             long offset = success.getRecordMetadata().offset();
-            log.info("------- 发送消息成功:\n"
-                    + "主题 topic 为:" + topic + "\n"
-                    + "分区 partition 为:" + partition + "\n"
-                    + "偏移量为:" + offset + "\n"
-                    + "消息体为:" + kafkaParameter.getData());
-        }, failure -> {
-            log.error("发送消息失败:" + failure.getMessage());
-        });
-
+            log.info("------- 发送消息成功:主题 topic 为:" + topic + "分区 partition 为:" + partition + "偏移量为:"
+                    + offset + "消息体为:" + kafkaParameter.getData());
+        }, failure -> log.error("发送消息失败:" + failure.getMessage()));
     }
 
     private void autoProjectStopToKafka(SimulationAutomaticSubProjectPo po) {

+ 6 - 0
simulation-resource-server/src/main/java/com/css/simulation/resource/scene/mapper/ScenePackageSublistMapper.java

@@ -5,6 +5,7 @@ import api.common.pojo.po.scene.ScenePackageSublistPO;
 import api.common.pojo.vo.scene.ScenePackageSublistVO;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Select;
 import org.apache.ibatis.annotations.Update;
 
 import java.util.List;
@@ -47,4 +48,9 @@ public interface ScenePackageSublistMapper {
             "set scene_num = scene_num - 1\n" +
             "where scene_traffic_ids like concat('%', #{sceneId}, '%')")
     void updateSceneNumAfterDeleteSceneByAccidentId(@Param("sceneId")String sceneId);
+
+    @Select("select sum(scene_num)\n" +
+            "from scene_package_sublist\n" +
+            "where root_id = #{scenePackageId}")
+    int selectSceneNumByPackageId(@Param("scenePackageId")String scenePackageId);
 }

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

@@ -7,10 +7,13 @@ import api.common.pojo.po.project.SimulationManualProjectPo;
 import api.common.util.CollectionUtil;
 import api.common.util.StringUtil;
 import com.css.simulation.resource.algorithm.mapper.AlgorithmMapper;
+import com.css.simulation.resource.model.mapper.ModelConfigMapper;
+import com.css.simulation.resource.model.mapper.ModelVehicleMapper;
 import com.css.simulation.resource.project.mapper.AutoSubProjectMapper;
 import com.css.simulation.resource.project.mapper.ManualProjectMapper;
 import com.css.simulation.resource.project.mapper.SimulationProjectMapper;
 import com.css.simulation.resource.scene.mapper.ScenePackageMapper;
+import com.css.simulation.resource.scene.mapper.ScenePackageSublistMapper;
 import com.css.simulation.resource.scene.mapper.ScoringRulesMapper;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Component;
@@ -34,6 +37,12 @@ public class ProjectUtil {
     private AlgorithmMapper algorithmMapper;
     @Resource
     private ScoringRulesMapper scoringRulesMapper;
+    @Resource
+    private ModelConfigMapper modelConfigMapper;
+    @Resource
+    private ModelVehicleMapper modelVehicleMapper;
+    @Resource
+    private ScenePackageSublistMapper scenePackageSublistMapper;
 
 
     public String getProjectTypeByProjectId(String projectId) {
@@ -73,27 +82,35 @@ public class ProjectUtil {
         }
     }
 
-    public void checkProject(String projectType, String projectId, String algorithmId, String vehicleConfigId,
-                             String scenePackageId) {
+    public void checkProject(String algorithmId, String vehicleConfigId, String scenePackageId) {
         //1 检查算法是否被删除
         if (DictConstants.IS_DELETED.equals(algorithmMapper.selectIsDeletedById(algorithmId))) {
             throw new RuntimeException("项目所使用算法已被删除。");
         }
-        //2 查询场景测试包是否被禁用
+        //2 查询车辆配置是否被删除。
+        if (DictConstants.IS_DELETED.equals(modelConfigMapper.selectIsDeletedByConfigId(vehicleConfigId))) {
+            throw new RuntimeException("项目所使用的车辆配置已被删除。");
+        }
+        //3 查询车辆配置中是否存在车辆模型。
+        final List<String> vehicles = modelVehicleMapper.selectIsDeletedByConfigId(scenePackageId);
+        if (CollectionUtil.isNotEmpty(vehicles)) {
+            throw new RuntimeException("项目所使用的车辆配置不存在动力学配置。");
+        }
+        //4 查询场景测试包是否被禁用。
         String isUnavailable = scenePackageMapper.selectIsUnavailableByPackageId(scenePackageId);
         if (DictConstants.SCENE_PACKAGE_UNAVAILABLE.equals(isUnavailable)) {
             throw new RuntimeException("场景测试包已被禁用,编辑场景测试包后可重新运行。");
         }
-        //3 查询评分规则是否被删除
+        //5 查询评分规则是否被删除
         final List<String> rules = scoringRulesMapper.selectDeletedRulesByPackageId(scenePackageId);
         if (CollectionUtil.isNotEmpty(rules)) {
-            throw new RuntimeException("评分规则 " + rules + " 已被删除。");
+            throw new RuntimeException("评分规则已被删除:" + rules);
         }
-        //4 查询场景测试包是否有场景
-
-        if (DictConstants.PROJECT_TYPE_MANUAL.equals(projectType)) {
-            final SchedulerProjectPO schedulerProjectPO = manualProjectMapper.selectById(projectId);
-
+        //6 查询场景测试包是否有场景
+        final int sceneNum = scenePackageSublistMapper.selectSceneNumByPackageId(scenePackageId);
+        if (sceneNum == 0) {
+            throw new RuntimeException("场景测试包内的场景已被全部删除,请添加场景。");
         }
+
     }
 }