|
@@ -0,0 +1,334 @@
|
|
|
|
+package com.css.simulation.resource.server.app.service;
|
|
|
|
+
|
|
|
|
+import api.common.pojo.constants.DictConstants;
|
|
|
|
+import api.common.pojo.param.MinioParameter;
|
|
|
|
+import api.common.pojo.param.scene.SceneImportParam;
|
|
|
|
+import api.common.pojo.param.scene.SceneReferenceLibParam;
|
|
|
|
+import api.common.pojo.param.scene.SceneReferenceLibSelectParam;
|
|
|
|
+import api.common.pojo.po.scene.SceneComplexityPO;
|
|
|
|
+import api.common.pojo.po.scene.SceneReferenceLibPO;
|
|
|
|
+import api.common.pojo.po.scene.SceneRiskPO;
|
|
|
|
+import api.common.pojo.po.system.SceneImportPO;
|
|
|
|
+import api.common.util.*;
|
|
|
|
+import com.css.simulation.resource.server.infra.db.mysql.mapper.SceneComplexityMapper;
|
|
|
|
+import com.css.simulation.resource.server.infra.db.mysql.mapper.SceneReferenceLibMapper;
|
|
|
|
+import com.css.simulation.resource.server.infra.db.mysql.mapper.SceneRiskMapper;
|
|
|
|
+import com.css.simulation.resource.server.infra.feign.service.FileDownService;
|
|
|
|
+import com.css.simulation.resource.server.infra.util.AuthUtil;
|
|
|
|
+import com.fasterxml.jackson.databind.JsonNode;
|
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
+import feign.Response;
|
|
|
|
+import lombok.SneakyThrows;
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+
|
|
|
|
+import javax.annotation.Resource;
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
|
|
+import java.util.function.Function;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
+
|
|
|
|
+@Slf4j
|
|
|
|
+@Service
|
|
|
|
+public class SceneReferenceLibService {
|
|
|
|
+
|
|
|
|
+ @Resource
|
|
|
|
+ private SceneReferenceLibMapper sceneReferenceLibMapper;
|
|
|
|
+
|
|
|
|
+ @Resource
|
|
|
|
+ private FileDownService fileDownService;
|
|
|
|
+
|
|
|
|
+ @Resource
|
|
|
|
+ private SceneComplexityMapper sceneComplexityMapper;
|
|
|
|
+
|
|
|
|
+ @Resource
|
|
|
|
+ private SceneRiskMapper sceneRiskMapper;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 获取基准场景库列表
|
|
|
|
+ *
|
|
|
|
+ * @param params
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public List<SceneReferenceLibPO> querySceneReferenceLibList(SceneReferenceLibParam params) {
|
|
|
|
+
|
|
|
|
+ SceneReferenceLibSelectParam srl = new SceneReferenceLibSelectParam();
|
|
|
|
+ // 场景名称
|
|
|
|
+ String sceneName = params.getSceneName();
|
|
|
|
+ // 主车行为
|
|
|
|
+ String[][] mainBehavior = params.getMainBehavior();
|
|
|
|
+ String[][] otherBehavior = params.getOtherBehavior();
|
|
|
|
+ String[][] weather = params.getWeather();
|
|
|
|
+ String[][] roadType = params.getRoadType();
|
|
|
|
+ String[][] roadGeometryPlane = params.getRoadGeometryPlane();
|
|
|
|
+ String[][] roadGeometryVertical = params.getRoadGeometryVertical();
|
|
|
|
+ String[][] autoDriveFunction = params.getAutoDriveFunction();
|
|
|
|
+ String[][] operationArea = params.getOperationArea();
|
|
|
|
+
|
|
|
|
+ if (mainBehavior != null && mainBehavior.length > 0) {
|
|
|
|
+ ParamUtil.arrConvertObj(mainBehavior, srl);
|
|
|
|
+ for (String[] arr : mainBehavior) {
|
|
|
|
+ if (arr != null && arr.length == 1) {
|
|
|
|
+ List<String> list = srl.getMainBehavior();
|
|
|
|
+ if (list == null) {
|
|
|
|
+ List<String> newList = new ArrayList<>();
|
|
|
|
+ newList.add(arr[0]);
|
|
|
|
+ srl.setMainBehavior(newList);
|
|
|
|
+ } else {
|
|
|
|
+ list.add(arr[0]);
|
|
|
|
+ srl.setMainBehavior(list);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ srl.setSceneId(params.getSceneId());
|
|
|
|
+ srl.setMinComplexity(params.getMinComplexity());
|
|
|
|
+ srl.setMaxComplexity(params.getMaxComplexity());
|
|
|
|
+ srl.setMinRisk(params.getMinRisk());
|
|
|
|
+ srl.setMaxRisk(params.getMaxRisk());
|
|
|
|
+ srl.setComplexityLevel(params.getComplexityLevel());
|
|
|
|
+ srl.setRiskLevel(params.getRiskLevel());
|
|
|
|
+ srl.setSceneDescription(params.getSceneDescription());
|
|
|
|
+ srl.setLabel(params.getLabel());
|
|
|
|
+ srl.setSceneName(sceneName);
|
|
|
|
+ if (otherBehavior != null && otherBehavior.length > 0) {
|
|
|
|
+ ParamUtil.arrConvertObj(otherBehavior, srl);
|
|
|
|
+ }
|
|
|
|
+ if (weather != null && weather.length > 0) {
|
|
|
|
+ ParamUtil.arrConvertObj(weather, srl);
|
|
|
|
+ }
|
|
|
|
+ if (roadType != null && roadType.length > 0) {
|
|
|
|
+ ParamUtil.arrConvertObj(roadType, srl);
|
|
|
|
+ }
|
|
|
|
+ if (roadGeometryPlane != null && roadGeometryPlane.length > 0) {
|
|
|
|
+ ParamUtil.arrConvertObj(roadGeometryPlane, srl);
|
|
|
|
+ }
|
|
|
|
+ if (roadGeometryVertical != null && roadGeometryVertical.length > 0) {
|
|
|
|
+ ParamUtil.arrConvertObj(roadGeometryVertical, srl);
|
|
|
|
+ }
|
|
|
|
+ if (autoDriveFunction != null && autoDriveFunction.length > 0) {
|
|
|
|
+ ParamUtil.arrConvertObj(autoDriveFunction, srl);
|
|
|
|
+ }
|
|
|
|
+ if (operationArea != null && operationArea.length > 0) {
|
|
|
|
+ ParamUtil.arrConvertObj(operationArea, srl);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 查询
|
|
|
|
+ List<SceneReferenceLibPO> sceneReferenceLibPOS = sceneReferenceLibMapper.querySceneReferenceLibList(srl);
|
|
|
|
+
|
|
|
|
+ SceneComplexityPO sceneComplexityPO = new SceneComplexityPO();
|
|
|
|
+ sceneComplexityPO.setMinComplexity(params.getMinComplexity());
|
|
|
|
+ sceneComplexityPO.setMaxComplexity(params.getMaxComplexity());
|
|
|
|
+ sceneComplexityPO.setComplexityLevel(params.getComplexityLevel());
|
|
|
|
+ // 查询复杂度的符合条件的第一条数据
|
|
|
|
+ List<SceneComplexityPO> sceneReferenceLibCSPOS = sceneComplexityMapper.selectSceneIdsByEvaluation(sceneComplexityPO);
|
|
|
|
+ Map<String, SceneComplexityPO> complexityPOMap = sceneReferenceLibCSPOS.stream().collect(Collectors.toMap(SceneComplexityPO::getSceneId, Function.identity()));
|
|
|
|
+ SceneRiskPO sceneRiskPO = new SceneRiskPO();
|
|
|
|
+ sceneRiskPO.setMaxRisk(params.getMaxRisk());
|
|
|
|
+ sceneRiskPO.setMinRisk(params.getMinRisk());
|
|
|
|
+ sceneRiskPO.setRiskLevel(params.getRiskLevel());
|
|
|
|
+ // 查询复杂度的符合条件的第一条数据
|
|
|
|
+ List<SceneRiskPO> sceneReferenceLibCRPOS = sceneRiskMapper.selectSceneIdsByEvaluation(sceneRiskPO);
|
|
|
|
+ Map<String, SceneRiskPO> riskPOMap = sceneReferenceLibCRPOS.stream().collect(Collectors.toMap(SceneRiskPO::getSceneId, Function.identity()));
|
|
|
|
+
|
|
|
|
+ // 筛选
|
|
|
|
+ List<SceneReferenceLibPO> finalSceneReferenceLibPOList = sceneReferenceLibPOS.stream()
|
|
|
|
+ .filter(srf -> complexityPOMap.get(srf.getSceneId()) != null && riskPOMap.get(srf.getSceneId()) != null)
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ for (SceneReferenceLibPO po : finalSceneReferenceLibPOList) {
|
|
|
|
+ // 赋值复杂度
|
|
|
|
+ po.setComplexity(String.valueOf(complexityPOMap.get(po.getSceneId()).getComplexity()));
|
|
|
|
+ po.setComplexityLevel(String.valueOf(complexityPOMap.get(po.getSceneId()).getComplexityLevel()));
|
|
|
|
+ po.setRisk(String.valueOf(riskPOMap.get(po.getSceneId()).getRisk()));
|
|
|
|
+ po.setRiskLevel(String.valueOf(riskPOMap.get(po.getSceneId()).getRiskLevel()));
|
|
|
|
+ if (po.getRoadType().equals("高速")) {
|
|
|
|
+ if (ObjectUtil.isNull(po.getLabel())) {
|
|
|
|
+ po.setLabel("高速");
|
|
|
|
+ } else {
|
|
|
|
+ po.setLabel(po.getLabel() + ",高速");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (po.getOtherBehavior().contains("机动车从左侧切入成功") || po.getOtherBehavior().contains("机动车从右侧切入成功")) {
|
|
|
|
+ if (ObjectUtil.isNull(po.getLabel())) {
|
|
|
|
+ po.setLabel("切入");
|
|
|
|
+ } else {
|
|
|
|
+ po.setLabel(po.getLabel() + ",切入");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (po.getOtherBehavior().equals("机动车向左侧切出成功") || po.getOtherBehavior().equals("机动车向右侧切出成功")) {
|
|
|
|
+ if (ObjectUtil.isNull(po.getLabel())) {
|
|
|
|
+ po.setLabel("切出");
|
|
|
|
+ } else {
|
|
|
|
+ po.setLabel(po.getLabel() + ",切出");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (po.getMainBehavior().contains("直路掉头") || po.getMainBehavior().contains("路口掉头")) {
|
|
|
|
+ if (ObjectUtil.isNull(po.getLabel())) {
|
|
|
|
+ po.setLabel("掉头");
|
|
|
|
+ } else {
|
|
|
|
+ po.setLabel(po.getLabel() + ",掉头");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (po.getMainBehavior().contains("向左变道成功") || po.getMainBehavior().equals("向右变道成功") || po.getMainBehavior().contains("向左连续变道") || po.getMainBehavior().indexOf("向右连续变道") > -1 || po.getMainBehavior().indexOf("向左变道超车") > -1 || po.getMainBehavior().indexOf("向右变道超车") > -1) {
|
|
|
|
+ if (ObjectUtil.isNull(po.getLabel())) {
|
|
|
|
+ po.setLabel("变道");
|
|
|
|
+ } else {
|
|
|
|
+ po.setLabel(po.getLabel() + ",变道");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return finalSceneReferenceLibPOList;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 获取基准场景数据
|
|
|
|
+ */
|
|
|
|
+ public SceneImportPO importMinio(SceneImportParam params) {
|
|
|
|
+ SceneImportPO sceneImportPO = new SceneImportPO();
|
|
|
|
+ sceneImportPO.setId(params.getId());
|
|
|
|
+ try {
|
|
|
|
+ MinioParameter MI = new MinioParameter();
|
|
|
|
+ MI.setObjectName(params.getMinioDirectory());
|
|
|
|
+ List<String> list = fileDownService.listDeepOne(MI).getInfo();
|
|
|
|
+ String OsgbPath = null;
|
|
|
|
+ String XodrPath = null;
|
|
|
|
+ int successNum = 0;
|
|
|
|
+ int falseNum = 0;
|
|
|
|
+ String errorMessage = "";
|
|
|
|
+ for (String filePath : list) {
|
|
|
|
+ if (filePath.contains("/OSGB")) {
|
|
|
|
+ OsgbPath = filePath;
|
|
|
|
+ } else if (filePath.contains("/XODR")) {
|
|
|
|
+ XodrPath = filePath;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ String sceneName = null;
|
|
|
|
+ List<String> sceneNames = new ArrayList<>();
|
|
|
|
+ for (String filePath : list) {
|
|
|
|
+ if (filePath.contains("/Scenarios")) {
|
|
|
|
+ MI.setObjectName(filePath);
|
|
|
|
+ List<String> listScene = fileDownService.listDeepOne(MI).getInfo();
|
|
|
|
+ log.info("importMinio() 共需要上传 " + listScene.size() + " 个基准场景");
|
|
|
|
+ for (String scenePath : listScene) {
|
|
|
|
+ try {
|
|
|
|
+ MI.setObjectName(scenePath);
|
|
|
|
+ List<String> addressList = fileDownService.listDeepOne(MI).getInfo();
|
|
|
|
+ SceneReferenceLibPO sceneReferenceLibPO = new SceneReferenceLibPO();
|
|
|
|
+ boolean isupdate = false;
|
|
|
|
+ List<SceneReferenceLibPO> scenes = new ArrayList<>();
|
|
|
|
+ for (String address : addressList) {
|
|
|
|
+ if (address.contains(".json")) {
|
|
|
|
+ MI.setObjectName(address);
|
|
|
|
+ Response download = fileDownService.download(MI);
|
|
|
|
+ // -------------------------------- label.json --------------------------------
|
|
|
|
+ String json = download.body().toString();
|
|
|
|
+ ObjectMapper objMap = new ObjectMapper();
|
|
|
|
+ JsonNode root = objMap.readTree(json);
|
|
|
|
+ // 判断场景名称唯一
|
|
|
|
+ sceneName = root.path("场景名称").asText();
|
|
|
|
+ sceneNames.add(sceneName);
|
|
|
|
+ String osgb = root.path("osgb").asText();
|
|
|
|
+ String xodr = root.path("xodr").asText();
|
|
|
|
+ if (StringUtil.isEmpty(sceneName)) {
|
|
|
|
+ sceneImportPO.setStatus(DictConstants.SCENE_IMPORT_STATUS_2);
|
|
|
|
+ String em = "文件 " + address + " 内容不符合标准格式(场景名称不为空)。";
|
|
|
|
+ log.error(em);
|
|
|
|
+ sceneImportPO.setErrorMessage(em);
|
|
|
|
+ return sceneImportPO;
|
|
|
|
+ }
|
|
|
|
+ String osgbAdress = OsgbPath + "/" + osgb;
|
|
|
|
+ String xodrAdress = XodrPath + "/" + xodr;
|
|
|
|
+ sceneReferenceLibPO.setSceneName(sceneName);
|
|
|
|
+ scenes = sceneReferenceLibMapper.selectAllByName(sceneReferenceLibPO);
|
|
|
|
+ // 新增数据
|
|
|
|
+ if (CollectionUtil.isNotEmpty(scenes)) {
|
|
|
|
+ isupdate = true;
|
|
|
|
+ }
|
|
|
|
+ String mainBehavior = root.path("主车行为").asText();
|
|
|
|
+ String otherBehavior = root.path("他车行为").asText();
|
|
|
|
+ sceneReferenceLibPO.setMainBehavior(mainBehavior);
|
|
|
|
+ sceneReferenceLibPO.setOtherBehavior(otherBehavior);
|
|
|
|
+ sceneReferenceLibPO.setMaxTime(root.path("max_time").asText());
|
|
|
|
+ sceneReferenceLibPO.setWeather(root.path("天气").asText());
|
|
|
|
+ sceneReferenceLibPO.setRoadType(root.path("道路类型").asText());
|
|
|
|
+ sceneReferenceLibPO.setRoadGeometryPlane(root.path("道路几何-平面").asText());
|
|
|
|
+ sceneReferenceLibPO.setRoadGeometryVertical(root.path("道路几何-纵断面").asText());
|
|
|
|
+ sceneReferenceLibPO.setAutoDriveFunction(root.path("自动驾驶功能").asText());
|
|
|
|
+ sceneReferenceLibPO.setOperationArea(root.path("运行区域").asText());
|
|
|
|
+ sceneReferenceLibPO.setSceneDescription(root.path("场景描述").asText());
|
|
|
|
+ sceneReferenceLibPO.setLabel(root.path("标签").asText());
|
|
|
|
+ sceneReferenceLibPO.setAutoDriveFunction(root.path("自动驾驶功能").asText());
|
|
|
|
+ sceneReferenceLibPO.setIsDeleted(DictConstants.IS_AVAILABLE);
|
|
|
|
+ if (ObjectUtil.isNull(sceneReferenceLibPO.getOsgbAddress())) {
|
|
|
|
+ sceneReferenceLibPO.setOsgbAddress(osgbAdress);
|
|
|
|
+ }
|
|
|
|
+ if (ObjectUtil.isNull(sceneReferenceLibPO.getXodrAddress())) {
|
|
|
|
+ sceneReferenceLibPO.setXodrAddress(xodrAdress);
|
|
|
|
+ }
|
|
|
|
+ sceneReferenceLibPO.setJsonAddress(address);
|
|
|
|
+ } else if (address.contains(".xml") || address.contains(".xosc")) {
|
|
|
|
+ sceneReferenceLibPO.setXmlAddress(address);
|
|
|
|
+ } else if (address.contains(".xodr")) {
|
|
|
|
+ sceneReferenceLibPO.setXodrAddress(address);
|
|
|
|
+ } else if (address.contains(".osgb")) {
|
|
|
|
+ sceneReferenceLibPO.setOsgbAddress(address);
|
|
|
|
+ } else if (address.contains("simulation.mp4")) {
|
|
|
|
+ sceneReferenceLibPO.setVideoAddress(address);
|
|
|
|
+ } else if (address.contains(".mp4")) {
|
|
|
|
+ sceneReferenceLibPO.setVideoPreview(address);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (isupdate) {
|
|
|
|
+ // -------------------------------- 修改数据到 mysql --------------------------------
|
|
|
|
+ scenes.forEach(scene -> {
|
|
|
|
+ sceneReferenceLibPO.setSceneId(scene.getSceneId());
|
|
|
|
+ sceneReferenceLibPO.setModifyTime(TimeUtil.getNowForMysql());
|
|
|
|
+ sceneReferenceLibPO.setModifyUserId(AuthUtil.getCurrentUserId());
|
|
|
|
+ sceneReferenceLibMapper.updateSceneReference(sceneReferenceLibPO);
|
|
|
|
+ });
|
|
|
|
+ } else {
|
|
|
|
+ // -------------------------------- 新增数据到 mysql --------------------------------
|
|
|
|
+ sceneReferenceLibPO.setSceneId(StringUtil.getRandomUUID());
|
|
|
|
+ sceneReferenceLibPO.setCreateTime(TimeUtil.getNowForMysql());
|
|
|
|
+ sceneReferenceLibPO.setCreateUserId(AuthUtil.getCurrentUserId());
|
|
|
|
+ sceneReferenceLibPO.setModifyTime(TimeUtil.getNowForMysql());
|
|
|
|
+ sceneReferenceLibMapper.saveSceneReference(sceneReferenceLibPO);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ successNum += 1;
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ errorMessage = e.getMessage();
|
|
|
|
+ log.error("parse scene reference lib file failed.", e);
|
|
|
|
+ falseNum += 1;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ sceneImportPO.setStatus(DictConstants.SCENE_IMPORT_STATUS_4);
|
|
|
|
+ sceneImportPO.setSuccessNum(successNum);
|
|
|
|
+ sceneImportPO.setFalseNum(falseNum);
|
|
|
|
+ sceneImportPO.setErrorMessage(errorMessage);
|
|
|
|
+ sceneImportPO.setSceneNames(CollectionUtil.listToSequence(sceneNames));
|
|
|
|
+ return sceneImportPO;
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ sceneImportPO.setStatus(DictConstants.SCENE_IMPORT_STATUS_2);
|
|
|
|
+ sceneImportPO.setErrorMessage("该文件地址:" + params.getMinioDirectory() + "解析失败,请检查");
|
|
|
|
+ return sceneImportPO;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @SneakyThrows
|
|
|
|
+ public void updateSceneReference(SceneReferenceLibPO sceneReferenceLibPO) {
|
|
|
|
+ sceneReferenceLibPO.setModifyTime(TimeUtil.getNowForMysql());
|
|
|
|
+ sceneReferenceLibPO.setModifyUserId(AuthUtil.getCurrentUserId());
|
|
|
|
+ sceneReferenceLibMapper.updateSceneReference(sceneReferenceLibPO);
|
|
|
|
+ LogUtil.update();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+}
|