|
@@ -1,95 +1,95 @@
|
|
|
-package com.css.simulation.resource.scheduler.consumer;
|
|
|
-
|
|
|
-
|
|
|
-import api.common.util.JsonUtil;
|
|
|
-import com.css.simulation.resource.scheduler.mapper.ProjectMapper;
|
|
|
-import com.css.simulation.resource.scheduler.mapper.SensorMapper;
|
|
|
-import com.css.simulation.resource.scheduler.mapper.TaskMapper;
|
|
|
-import com.css.simulation.resource.scheduler.pojo.dto.task.*;
|
|
|
-import com.css.simulation.resource.scheduler.pojo.po.TaskPO;
|
|
|
-import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
-import org.apache.kafka.clients.consumer.ConsumerRecord;
|
|
|
-import org.springframework.boot.configurationprocessor.json.JSONException;
|
|
|
-import org.springframework.boot.configurationprocessor.json.JSONObject;
|
|
|
-import org.springframework.kafka.annotation.KafkaListener;
|
|
|
-import org.springframework.kafka.core.KafkaTemplate;
|
|
|
-import org.springframework.stereotype.Component;
|
|
|
-
|
|
|
-import javax.annotation.Resource;
|
|
|
-import java.util.List;
|
|
|
-
|
|
|
-@Component
|
|
|
-public class ProjectConsumer {
|
|
|
-
|
|
|
- @Resource
|
|
|
- ProjectMapper projectMapper;
|
|
|
- @Resource
|
|
|
- TaskMapper taskMapper;
|
|
|
- @Resource
|
|
|
- SensorMapper sensorMapper;
|
|
|
- @Resource
|
|
|
- private KafkaTemplate<String, String> kafkaTemplate;
|
|
|
-
|
|
|
- @KafkaListener(topics = "project")
|
|
|
- public void parseProject(ConsumerRecord<String, String> projectRecord) throws JsonProcessingException, JSONException {
|
|
|
-
|
|
|
- String projectJson = projectRecord.value();
|
|
|
-
|
|
|
- JSONObject projectJsonObject = new JSONObject(projectJson);
|
|
|
- String projectId = projectJsonObject.optString("projectId");
|
|
|
- String defaultTime = projectJsonObject.optString("defaultTime");
|
|
|
- String parallelism = projectJsonObject.optString("parallelism");
|
|
|
-
|
|
|
- projectMapper.updateProjectState(projectId, "2");
|
|
|
-
|
|
|
- List<TaskPO> taskPOList = taskMapper.selectByProjectId(projectId);
|
|
|
-
|
|
|
- for (TaskPO taskPO : taskPOList) {
|
|
|
-
|
|
|
- TaskDTO taskDTO = TaskDTO.builder()
|
|
|
- .info(InfoDTO.builder()
|
|
|
- .project_id(projectId)
|
|
|
- .task_id(taskPO.getId())
|
|
|
- .task_path(taskPO.getResultPath())
|
|
|
- .build())
|
|
|
- .scenario(ScenarioDTO.builder()
|
|
|
- .scenario_osc(taskPO.getScenarioOsc())
|
|
|
- .scenario_odr(taskPO.getScenarioOdr())
|
|
|
- .scenario_osgb(taskPO.getScenarioOsgb())
|
|
|
- .build())
|
|
|
- .vehicle(VehicleDTO.builder()
|
|
|
- .model(ModelDTO.builder().model_label(taskPO.getModelLabel()).build())
|
|
|
- .dynamics(DynamicsDTO.builder()
|
|
|
- .dynamics_maxspeed(taskPO.getMaxSpeed())
|
|
|
- .dynamics_enginepower(taskPO.getEnginePower())
|
|
|
- .dynamics_maxdecel(taskPO.getMaxDeceleration())
|
|
|
- .dynamics_maxsteering(taskPO.getMaxSteeringAngle())
|
|
|
- .dynamics_mass(taskPO.getMass())
|
|
|
- .dynamics_frontsurfaceeffective(taskPO.getFrontSurfaceEffective())
|
|
|
- .dynamics_airdragcoefficient(taskPO.getAirDragCoefficient())
|
|
|
- .dynamics_rollingresistance(taskPO.getRollingResistanceCoefficient())
|
|
|
- .dynamics_wheeldiameter(taskPO.getWheelDiameter())
|
|
|
- .dynamics_wheeldrive(taskPO.getDrive())
|
|
|
- .dynamics_overallefficiency(taskPO.getOverallEfficiency())
|
|
|
- .dynamics_distfront(taskPO.getFrontDistance())
|
|
|
- .dynamics_distrear(taskPO.getRearDistance())
|
|
|
- .dynamics_distleft(taskPO.getLeftDistance())
|
|
|
- .dynamics_distright(taskPO.getRightDistance())
|
|
|
- .dynamics_distheight(taskPO.getHeight())
|
|
|
- .dynamics_wheelbase(taskPO.getDynamicsWheelbase())
|
|
|
- .build())
|
|
|
- .sensors(SensorsDTO.builder()
|
|
|
- .camera(sensorMapper.selectCameraByVehicleId(taskPO.getVehicleId()))
|
|
|
- .OGT(sensorMapper.selectOgtByVehicleId(taskPO.getVehicleId()))
|
|
|
- .build())
|
|
|
- .build())
|
|
|
- .build();
|
|
|
-
|
|
|
- String taskJson = JsonUtil.beanToJson(taskDTO);
|
|
|
-
|
|
|
- kafkaTemplate.send(projectId, 0, taskPO.getId(), taskJson);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
-}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|