ProjectUtil.java 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. package com.css.simulation.resource.util;
  2. import api.common.pojo.constants.DictConstants;
  3. import api.common.pojo.param.project.SimulationManualProjectParam;
  4. import api.common.pojo.po.project.SchedulerProjectPO;
  5. import api.common.pojo.po.project.SimulationManualProjectPo;
  6. import api.common.util.StringUtil;
  7. import com.css.simulation.resource.algorithm.mapper.AlgorithmMapper;
  8. import com.css.simulation.resource.model.mapper.ModelConfigMapper;
  9. import com.css.simulation.resource.model.mapper.ModelVehicleMapper;
  10. import com.css.simulation.resource.project.mapper.AutoSubProjectMapper;
  11. import com.css.simulation.resource.project.mapper.ManualProjectMapper;
  12. import com.css.simulation.resource.project.mapper.SimulationProjectMapper;
  13. import com.css.simulation.resource.scene.mapper.ScenePackageMapper;
  14. import com.css.simulation.resource.scene.mapper.ScenePackageSublistMapper;
  15. import com.css.simulation.resource.scene.mapper.ScoringRulesMapper;
  16. import lombok.extern.slf4j.Slf4j;
  17. import org.springframework.stereotype.Component;
  18. import javax.annotation.Resource;
  19. @Component
  20. @Slf4j
  21. public class ProjectUtil {
  22. @Resource
  23. private ManualProjectMapper manualProjectMapper;
  24. @Resource
  25. private AutoSubProjectMapper autoSubProjectMapper;
  26. @Resource
  27. private SimulationProjectMapper simulationProjectMapper;
  28. @Resource
  29. private ScenePackageMapper scenePackageMapper;
  30. @Resource
  31. private AlgorithmMapper algorithmMapper;
  32. @Resource
  33. private ScoringRulesMapper scoringRulesMapper;
  34. @Resource
  35. private ModelConfigMapper modelConfigMapper;
  36. @Resource
  37. private ModelVehicleMapper modelVehicleMapper;
  38. @Resource
  39. private ScenePackageSublistMapper scenePackageSublistMapper;
  40. @Resource
  41. private SceneUtil sceneUtil;
  42. public String getProjectTypeByProjectId(String projectId) {
  43. String projectType = null;
  44. SchedulerProjectPO manualProjectPO = manualProjectMapper.selectById(projectId);
  45. SchedulerProjectPO autoSubProjectPO = autoSubProjectMapper.selectById(projectId);
  46. if (manualProjectPO != null) {
  47. projectType = DictConstants.PROJECT_TYPE_MANUAL;
  48. } else if (autoSubProjectPO != null) {
  49. projectType = DictConstants.PROJECT_TYPE_AUTO_SUB;
  50. }
  51. return projectType;
  52. }
  53. public static String getEvaluationLevelReport(double algorithmScore) {
  54. if (algorithmScore >= 90) {
  55. return DictConstants.REPORT_LEVEL_G;
  56. } else if (algorithmScore >= 80) {
  57. return DictConstants.REPORT_LEVEL_A;
  58. } else if (algorithmScore >= 70) {
  59. return DictConstants.REPORT_LEVEL_M;
  60. } else {
  61. return DictConstants.REPORT_LEVEL_P;
  62. }
  63. }
  64. public SimulationManualProjectPo getProjectInfo(SimulationManualProjectParam param) {
  65. if (StringUtil.isEmpty(param.getId()) || StringUtil.isEmpty(param.getNowRunState())) {
  66. throw new RuntimeException("参数为空。");
  67. } else {
  68. SimulationManualProjectPo po = simulationProjectMapper.selectProjectById(param);
  69. if (po == null) {
  70. throw new RuntimeException("手动项目" + param.getId() + "不存在。");
  71. }
  72. return po;
  73. }
  74. }
  75. public void checkProject(String algorithmId, String vehicleConfigId, String scenePackageId) {
  76. log.info("1 检查算法是否被删除:" + algorithmId);
  77. if (DictConstants.IS_DELETED.equals(algorithmMapper.selectIsDeletedById(algorithmId))) {
  78. throw new RuntimeException("项目所使用算法已被删除。");
  79. }
  80. log.info("2 查询车辆配置是否被删除:" + vehicleConfigId);
  81. if (DictConstants.IS_DELETED.equals(modelConfigMapper.selectIsDeletedByConfigId(vehicleConfigId))) {
  82. throw new RuntimeException("项目所使用的车辆配置已被删除。");
  83. }
  84. log.info("3 查询车辆配置中是否存在车辆模型:" + vehicleConfigId);
  85. final String vehicleIsDeleted = modelVehicleMapper.selectIsDeletedByConfigId(vehicleConfigId);
  86. if (DictConstants.IS_DELETED.equals(vehicleIsDeleted)) {
  87. throw new RuntimeException("车辆配置绑定的动力学配置已被删除。");
  88. }
  89. log.info("4 查询场景测试包是否被删除:" + scenePackageId);
  90. String packageIsDeleted = scenePackageMapper.selectIsDeletedByPackageId(scenePackageId);
  91. if (DictConstants.IS_DELETED.equals(packageIsDeleted)) {
  92. throw new RuntimeException("场景测试包已被删除。");
  93. }
  94. log.info("5 查询场景测试包是否被禁用:" + scenePackageId);
  95. String isUnavailable = scenePackageMapper.selectIsUnavailableByPackageId(scenePackageId);
  96. if (DictConstants.SCENE_PACKAGE_UNAVAILABLE.equals(isUnavailable)) {
  97. throw new RuntimeException("场景测试包已被禁用,编辑场景测试包后可重新运行。");
  98. }
  99. log.info("6 查询评分规则是否被删除。");
  100. sceneUtil.checkRules(scenePackageId);
  101. log.info("7 查询场景测试包是否有场景。");
  102. final int sceneNum = scenePackageSublistMapper.selectSceneNumByPackageId(scenePackageId);
  103. if (sceneNum == 0) {
  104. throw new RuntimeException("场景测试包内的场景已被全部删除,请添加场景。");
  105. }
  106. }
  107. }