root 2 lat temu
rodzic
commit
e9d695eb0d

+ 1 - 0
api-common/src/main/java/api/common/pojo/param/project/SimulationManualProjectKafkaParam.java

@@ -17,4 +17,5 @@ public class SimulationManualProjectKafkaParam {
     private Long maxSimulationTime; //  最大仿真时间
     private Integer parallelism;    // 并行度
     private String type;    // 项目类型
+    private String modelType;    // 项目类型
 }

+ 4 - 0
simulation-resource-server/src/main/java/com/css/simulation/resource/model/mapper/VehicleMapper.java

@@ -5,6 +5,7 @@ import api.common.pojo.po.model.VehiclePO;
 import api.common.pojo.vo.model.VehicleVO;
 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 org.springframework.stereotype.Repository;
 
@@ -33,4 +34,7 @@ public interface VehicleMapper {
             "set model_label = #{newModelLabel}\n" +
             "where model_label = #{oldModelLabel}")
     void updateModelLabel(@Param("oldModelLabel") String oldModelLabel, @Param("newModelLabel") String newModelLabel);
+
+    @Select("select parameter_type from model_vehicle where id = #{id}}")
+    String selectParameterTypeById(@Param("id") String id);
 }

+ 1 - 1
simulation-resource-server/src/main/java/com/css/simulation/resource/project/ctrl/SimulationProjectCtrl.java

@@ -72,7 +72,7 @@ public class SimulationProjectCtrl {
      */
     @RequestMapping("deleteProjectByids")
     @ResponseBody
-    public ResponseBodyVO deleteProjectByids(@RequestBody SimulationManualProjectParam param) {
+    public ResponseBodyVO<String> deleteProjectByids(@RequestBody SimulationManualProjectParam param) {
         return service.deleteProjectByids(param);
     }
 

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

@@ -26,6 +26,7 @@ import com.css.simulation.resource.common.utils.PageUtil;
 import com.css.simulation.resource.feign.AlgoPlatformService;
 import com.css.simulation.resource.feign.FileDownService;
 import com.css.simulation.resource.feign.MonitorService;
+import com.css.simulation.resource.model.mapper.VehicleMapper;
 import com.css.simulation.resource.project.constants.ProjectConstants;
 import com.css.simulation.resource.project.enums.ProjectRunStateEnum;
 import com.css.simulation.resource.project.enums.SceneTypeEnum;
@@ -73,95 +74,81 @@ import java.util.zip.ZipOutputStream;
 public class SimulationProjectServiceImpl implements SimulationProjectService {
 
     @Resource(name = "myKafkaAdmin")
-    Admin kafkaAdminClient;
+    private Admin kafkaAdminClient;
     @Resource
-    SimulationProjectMapper simulationProjectMapper;
+    private SimulationProjectMapper simulationProjectMapper;
     @Resource
-    ManualProjectMapper manualProjectMapper;
+    private ManualProjectMapper manualProjectMapper;
     @Resource
-    AutoSubProjectMapper autoSubProjectMapper;
+    private  AutoSubProjectMapper autoSubProjectMapper;
     @Resource
-    SimulationAutomaticProjectMapper simulationAutomaticProjectMapper;
+    private SimulationAutomaticProjectMapper simulationAutomaticProjectMapper;
     @Resource
-    SimulationProjectTaskMapper simulationProjectTaskMapper;
+    private SimulationProjectTaskMapper simulationProjectTaskMapper;
     @Resource
-    SimulationAutomaticSubProjectMapper simulationAutomaticSubProjectMapper;
+    private SimulationAutomaticSubProjectMapper simulationAutomaticSubProjectMapper;
     @Resource
-    SimulationMptFirstTargetScoreMapper simulationMptFirstTargetScoreMapper;
+    private SimulationMptFirstTargetScoreMapper simulationMptFirstTargetScoreMapper;
     @Resource
-    SimulationMptLastTargetScoreMapper simulationMptLastTargetScoreMapper;
+    private SimulationMptLastTargetScoreMapper simulationMptLastTargetScoreMapper;
     @Resource
-    AlgorithmMapper algorithmMapper;
-
+    private AlgorithmMapper algorithmMapper;
     @Resource
-    KafkaTemplate<String, String> kafkaTemplate;
+    private  KafkaTemplate<String, String> kafkaTemplate;
     @Resource
-    DictService dictService;
-
+    private  DictService dictService;
     @Resource
-    AlgoPlatformService algoPlatformService;
-
+    private AlgoPlatformService algoPlatformService;
     @Resource
-    FileDownService fileDownService;
-
+    private FileDownService fileDownService;
     @Resource
-    AlgorithmService algorithmService;
+    private AlgorithmService algorithmService;
     @Resource
-    MonitorService monitorService;
+    private MonitorService monitorService;
+    @Resource
+    private ProjectUtil projectUtil;
 
     @Resource
-    ProjectUtil projectUtil;
+    private VehicleMapper vehicleMapper;
 
     //* -------------------------------- Comment --------------------------------
 
-    private String[] dateFmtArr = new String[]{"yyyyMMdd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd"};
+    private final String[] dateFmtArr = new String[]{"yyyyMMdd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd"};
 
     @Override
     public ResponseBodyVO<String> addOrUpdateProject(SimulationManualProjectParam param) {
 
         if (isEmpty(param.getProjectName())) {
-            return new ResponseBodyVO<>(ResponseBodyVO.Response.CLIENT_FAILURE, "工作名称不能为空");
+            return new ResponseBodyVO<>(ResponseBodyVO.Response.CLIENT_FAILURE, "工作名称不能为空");
         }
         SimulationManualProjectPo po = convertParamToPo(param);
 
         if (isEmpty(param.getId())) {
-
-            //工作名称一样的的不能创建
+            // 工作名称一样的的不能创建
             List<SimulationManualProjectPo> simulationManualProjectPos = simulationProjectMapper.selectProjectByName(param);
             if (!isEmpty(simulationManualProjectPos)) {
-                return new ResponseBodyVO<>(ResponseBodyVO.Response.CLIENT_FAILURE, "工作名称已经存在,请修改后再保存");
+                return new ResponseBodyVO<>(ResponseBodyVO.Response.CLIENT_FAILURE, "工作名称已经存在,请修改后再保存");
             }
-
-
             po.createPo(AuthUtil.getCurrentUserId());
-            //生成id
+            // 生成id
             createProjectId(po);
-
             int add = simulationProjectMapper.add(po);
             if (add > 0) {
-                //第三方算法存到算发表(索为)
-//                insertOtherAlgorithm(param);
-
                 return new ResponseBodyVO<>(ResponseBodyVO.Response.SUCCESS, ResponseBodyVO.Response.SUCCESS.getMessage(), po.getId());
             }
             return new ResponseBodyVO<>(ResponseBodyVO.Response.SERVER_FAILURE, "添加失败");
         } else {
-            //TODO 删除逻辑有待商议
-            //获取工作状态,仅未开始的才可以修改信息
+            // 取工作状态,仅未开始的才可以修改信息
             SimulationManualProjectPo simulationManualProjectPo = simulationProjectMapper.selectProjectById(param);
             if (!ProjectRunStateEnum.NOT_START.getCode().equals(simulationManualProjectPo.getNowRunState())) {
                 return new ResponseBodyVO<>(ResponseBodyVO.Response.SERVER_FAILURE, "当前状态不支持修改。");
             }
-
             po.updatePo(AuthUtil.getCurrentUserId());
             int update = simulationProjectMapper.update(po);
             if (update > 0) {
-                //第三方算法存到算发表(索为)
-//                insertOtherAlgorithm(param);
-                return new ResponseBodyVO(ResponseBodyVO.Response.SUCCESS, ResponseBodyVO.Response.SUCCESS.getMessage(), po.getId());
+                return new ResponseBodyVO<>(ResponseBodyVO.Response.SUCCESS, ResponseBodyVO.Response.SUCCESS.getMessage(), po.getId());
             }
-
-            return new ResponseBodyVO(ResponseBodyVO.Response.SERVER_FAILURE, "修改失败");
+            return new ResponseBodyVO<>(ResponseBodyVO.Response.SERVER_FAILURE, "修改失败。");
         }
 
     }
@@ -209,7 +196,6 @@ public class SimulationProjectServiceImpl implements SimulationProjectService {
 
         //查询有效数据
         param.setIsDeleted("0");
-
         setPage(param.getCurrentPage() == null ? 1 : param.getCurrentPage(), param.getPageSize() == null ? 10 : param.getPageSize());
         List<SimulationManualProjectVo> vos = simulationProjectMapper.selectProjectList(param); // 查出来的 algorithm 字段内容是算法 id
         PageInfo<SimulationManualProjectVo> pageInfo = new PageInfo<>(vos);
@@ -240,11 +226,11 @@ public class SimulationProjectServiceImpl implements SimulationProjectService {
 
 
     @Override
-    public ResponseBodyVO deleteProjectByids(SimulationManualProjectParam param) {
+    public ResponseBodyVO<String> deleteProjectByids(SimulationManualProjectParam param) {
 
         String ids = param.getIds();
         if (isEmpty(ids)) {
-            return new ResponseBodyVO(ResponseBodyVO.Response.CLIENT_FAILURE);
+            return new ResponseBodyVO<>(ResponseBodyVO.Response.CLIENT_FAILURE);
         }
 
         String[] idArr = ids.split(",");
@@ -253,16 +239,16 @@ public class SimulationProjectServiceImpl implements SimulationProjectService {
         List<SimulationManualProjectPo> pos = simulationProjectMapper.selectProjectNowRunState(idArr);
         for (SimulationManualProjectPo p : pos) {
             if (ProjectRunStateEnum.EXECUTION.getCode().equals(p.getNowRunState())) {
-                return new ResponseBodyVO(ResponseBodyVO.Response.SERVER_FAILURE, "数据不支持删除。");
+                return new ResponseBodyVO<>(ResponseBodyVO.Response.SERVER_FAILURE, "数据不支持删除。");
             }
         }
 
         int i = simulationProjectMapper.deleteProject(idArr);
         if (i > 0) {
-            return new ResponseBodyVO(ResponseBodyVO.Response.SUCCESS);
+            return new ResponseBodyVO<>(ResponseBodyVO.Response.SUCCESS);
         }
 
-        return new ResponseBodyVO(ResponseBodyVO.Response.SERVER_FAILURE, "删除失败。");
+        return new ResponseBodyVO<>(ResponseBodyVO.Response.SERVER_FAILURE, "删除失败。");
     }
 
     /**
@@ -335,36 +321,40 @@ public class SimulationProjectServiceImpl implements SimulationProjectService {
         return new ResponseBodyVO<>(ResponseBodyVO.Response.SUCCESS);
     }
 
-    private void projectRunToKafka(SimulationManualProjectPo po) throws JsonProcessingException {
-        SimulationManualProjectKafkaParam kafkaParam = new SimulationManualProjectKafkaParam();
-        kafkaParam.setProjectId(po.getId());
-        kafkaParam.setAlgorithmId(po.getAlgorithm());
-        kafkaParam.setVehicleConfigId(po.getVehicle());
-        kafkaParam.setScenePackageId(po.getScene());
-        kafkaParam.setMaxSimulationTime(po.getMaxSimulationTime());
-        kafkaParam.setParallelism(Integer.valueOf(po.getParallelism()));
-        kafkaParam.setType(DictConstants.PROJECT_TYPE_MANUAL);
-        KafkaParameter kafkaParameter = new KafkaParameter();
-        kafkaParameter.setTopic(ProjectConstants.RUN_TASK_TOPIC);
-        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();
-            // 消息发送到的分区
-            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());
-        });
+    private void projectRunToKafka(SimulationManualProjectPo po) {
+        try {
+            SimulationManualProjectKafkaParam kafkaParam = new SimulationManualProjectKafkaParam();
+            kafkaParam.setProjectId(po.getId());
+            kafkaParam.setAlgorithmId(po.getAlgorithm());
+            kafkaParam.setVehicleConfigId(po.getVehicle());
+            kafkaParam.setScenePackageId(po.getScene());
+            kafkaParam.setMaxSimulationTime(po.getMaxSimulationTime());
+            kafkaParam.setParallelism(Integer.valueOf(po.getParallelism()));
+            kafkaParam.setType(DictConstants.PROJECT_TYPE_MANUAL);
+            kafkaParam.setModelType(vehicleMapper.selectParameterTypeById(po.getVehicle()));
+            KafkaParameter kafkaParameter = new KafkaParameter();
+            kafkaParameter.setTopic(ProjectConstants.RUN_TASK_TOPIC);
+            String data = JsonUtil.beanToJson(kafkaParam);
+            kafkaParameter.setData(data);
+            log.info("推送项目运行消息到kafka:" + data);
+            kafkaTemplate.send(kafkaParameter.getTopic(), kafkaParameter.getData()).addCallback(success -> {
+                // 消息发送到的topic
+                String topic = success.getRecordMetadata().topic();
+                // 消息发送到的分区
+                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());
+            });
+        } catch (NumberFormatException | JsonProcessingException e) {
+            throw new RuntimeException(e);
+        }
     }
 
     private void projectStopToKafka(SimulationManualProjectPo po) throws JsonProcessingException {