Explorar o código

交通事故场景模板修改

wangzhiqiang %!s(int64=3) %!d(string=hai) anos
pai
achega
636bde3eb8

+ 3 - 0
api-common/src/main/java/api/common/pojo/po/scene/SceneAccidentPO.java

@@ -22,6 +22,9 @@ public class SceneAccidentPO implements Serializable {
     private String selfReaction ; //自车反应行为
     private String conflictBehavior ; //冲突行为
     private String conflictType ; //冲突类型
+    private String scenceResume ; //场景描述
+    private String sceneTime ; //场景时间
+    private String sceneWeather ; //天气
     private String share ; //是否分析  1为分享
     private String videoAddress ; //视频地址
     private String osgbAddress  ;//

+ 3 - 0
api-common/src/main/java/api/common/pojo/vo/scene/SceneAccidentVO.java

@@ -25,5 +25,8 @@ public class SceneAccidentVO extends PageVO implements Serializable {
     private String videoAddress ; //视频地址
     private String videoPreview;//视频预览地址
     private String label;//标签
+    private String scenceResume ; //场景描述
+    private String sceneTime ; //场景时间
+    private String sceneWeather ; //天气
 
 }

+ 24 - 0
simulation-resource-server/pom.xml

@@ -16,6 +16,30 @@
     </properties>
 
     <dependencies>
+
+        <!-- 测试excel解析-->
+        <dependency>
+            <groupId>org.apache.poi</groupId>
+            <artifactId>poi</artifactId>
+            <version>3.9</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.poi</groupId>
+            <artifactId>poi-ooxml</artifactId>
+            <version>3.9</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.poi</groupId>
+            <artifactId>poi-ooxml-schemas</artifactId>
+            <version>3.9</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring-test</artifactId>
+            <version>5.3.2</version>
+            <scope>compile</scope>
+        </dependency>
         <!-- api-common -->
         <dependency>
             <groupId>com.css</groupId>

+ 2 - 1
simulation-resource-server/src/main/java/com/css/simulation/resource/scene/mapper/SceneAccidentMapper.java

@@ -18,6 +18,7 @@ public interface SceneAccidentMapper {
 
     void deleteSceneAccidentList(SceneAccidentPO params);
 
-    List<SceneAccidentPO> querySceneAccidentByNmae(SceneAccidentParam params);
+    Integer querySceneAccidentByNmae(String sceneName);
+
 
 }

+ 107 - 5
simulation-resource-server/src/main/java/com/css/simulation/resource/scene/service/SceneAccidentService.java

@@ -15,13 +15,19 @@ import com.fasterxml.jackson.databind.ObjectMapper;
 import feign.Response;
 import lombok.SneakyThrows;
 import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.BeanUtils;
+import org.apache.poi.util.IOUtils;
+import org.springframework.mock.web.MockMultipartFile;
 import org.springframework.stereotype.Service;
+import org.springframework.web.multipart.MultipartFile;
+
 import javax.annotation.Resource;
 import java.io.File;
+import java.io.FileInputStream;
 import java.util.ArrayList;
+import java.util.Date;
 import java.util.List;
 
+
 @Slf4j
 @Service
 public class SceneAccidentService {
@@ -52,9 +58,8 @@ public class SceneAccidentService {
         JsonNode root = objMap.readTree(json);
         //判断场景名称唯一
         String sceneName = root.path("场景名称").asText();
-        param.setSceneName(sceneName);
-        List<SceneAccidentPO> list = SceneAccidentMapper.querySceneAccidentByNmae(param);
-        if (list != null && list.size() > 0) {
+       Integer sceneNum = SceneAccidentMapper.querySceneAccidentByNmae(sceneName);
+        if (sceneNum > 0) {
             return new ResponseBodyVO(ResponseBodyVO.Response.CLIENT_FAILURE, "该场景名称" + sceneName + "已存在,请检查");
         }
 
@@ -62,11 +67,14 @@ public class SceneAccidentService {
         sceneAccidentPO = sceneAccidentPO.builder()
                 .accidentId(StringUtil.getRandomUUID())
                 .sceneName(sceneName)
+                .scenceResume(root.path("场景描述").asText())
                 .selfDriving(root.path("自车驾驶行为").asText())
                 .targetDriving(root.path("目标驾驶行为").asText())
                 .selfReaction(root.path("自车反应行为").asText())
                 .conflictBehavior(root.path("冲突行为").asText())
                 .conflictType(root.path("冲突类型").asText())
+                .sceneTime(root.path("时间").asText())
+                .sceneWeather(root.path("天气").asText())
                 .isDeleted("0")
                 .build();
         // -------------------------------- 保存数据到 mysql --------------------------------
@@ -96,7 +104,6 @@ public class SceneAccidentService {
 
         return new ResponseBodyVO(ResponseBodyVO.Response.SUCCESS);
 
-
     }
 
     /**
@@ -131,11 +138,14 @@ public class SceneAccidentService {
                     sceneAccidentPO = sceneAccidentPO.builder()
                             .accidentId(StringUtil.getRandomUUID())
                             .sceneName(root.path("场景名称").asText())
+                            .scenceResume(root.path("场景描述").asText())
                             .selfDriving(root.path("自车驾驶行为").asText())
                             .targetDriving(root.path("目标驾驶行为").asText())
                             .selfReaction(root.path("自车反应行为").asText())
                             .conflictBehavior(root.path("冲突行为").asText())
                             .conflictType(root.path("冲突类型").asText())
+                            .sceneTime(root.path("时间").asText())
+                            .sceneWeather(root.path("天气").asText())
                             .isDeleted("0")
                             .build();
                     // -------------------------------- 保存数据到 mysql --------------------------------
@@ -278,4 +288,96 @@ public class SceneAccidentService {
         SceneAccidentMapper.deleteSceneAccidentList(params);
         //systemUserSceneService.deleteSystemUserSceneBySceneId(params.getAccidentId());
     }
+
+
+    /**
+     * 获取交通事故场景数据:
+     */
+    @SneakyThrows
+    public ResponseBodyVO<String> saveAll(SceneAccidentParam param) {
+        //1 获取所有目录下所有场景
+        String dataUrl0 = "D:\\交通事故场景";     // 场景数据根路径
+        //  System.out.println("--------"+param.getPath());
+        File[] scenes = FileUtil.getDirectory(dataUrl0).listFiles();
+        if (scenes == null) {
+            throw new RuntimeException("目录:" + dataUrl0 + " 下没有文件!");
+        }
+
+        String fileName = null;
+        try {
+            List<SceneAccidentPO> list=new ArrayList<SceneAccidentPO>();
+                Integer wJNum=1;
+            for (File scene1 : scenes) {
+                String dataUrlNew = scene1.getAbsolutePath();
+                File[] scenes1 = FileUtil.getDirectory(dataUrlNew).listFiles();
+                if (scenes1 == null) {
+                    throw new RuntimeException("目录:" + dataUrlNew + " 下没有文件!");
+                }
+                SceneAccidentPO sceneAccidentPO = null;
+                Integer nowTime = TimeUtil.getRq(new Date(), 0);
+                for (File scene : scenes1) {
+                    String dataUrl = scene.getAbsolutePath();
+                   // File pdfFile = new File(dataUrl);
+                    fileName= scene.getName();
+                    //文件上传测试1  遍历拿到的文件scene
+                    FileInputStream inputStream = new FileInputStream(scene);
+                    MultipartFile multipartFile = new MockMultipartFile("file", fileName, "text/plain", IOUtils.toByteArray(inputStream));
+                    //调用文件上传方法
+                   String  nowNum=nowTime+""+wJNum;
+                    String  objectName = "交通事故场景1111/" + nowNum  + "/" + fileName;
+                    ResponseBodyVO<String> respon= fileDownService.upload(multipartFile, objectName);
+
+                    if (dataUrl.indexOf(".json") != -1) {
+                        // -------------------------------- 读取结构化数据文件 --------------------------------
+                        // -------------------------------- label.json --------------------------------
+                        String json = FileUtil.readFile(dataUrl);
+                        ObjectMapper objMap = new ObjectMapper();
+                        JsonNode root = objMap.readTree(json);
+                        //判断是否存在
+                        String sceneName=root.path("场景名称").asText();
+                        Integer sceneNum = SceneAccidentMapper.querySceneAccidentByNmae(root.path("场景名称").asText());
+                        if (sceneNum > 0) {
+                            return new ResponseBodyVO(ResponseBodyVO.Response.CLIENT_FAILURE, "该场景名称" + sceneName + "已存在,请检查");
+                        }
+                        sceneAccidentPO = sceneAccidentPO.builder()
+                                .accidentId(StringUtil.getRandomUUID())
+                                .sceneName(root.path("场景名称").asText())
+                                .scenceResume(root.path("场景描述").asText())
+                                .selfDriving(root.path("自车驾驶行为").asText())
+                                .targetDriving(root.path("目标驾驶行为").asText())
+                                .selfReaction(root.path("自车反应行为").asText())
+                                .conflictBehavior(root.path("冲突行为").asText())
+                                .conflictType(root.path("冲突类型").asText())
+                                .sceneTime(root.path("时间").asText())
+                                .sceneWeather(root.path("天气").asText())
+                                .isDeleted("0")
+                                .build();
+                        // -------------------------------- 保存数据到 mysql --------------------------------
+                        sceneAccidentPO.setCreateTime(TimeUtil.getNowForMysql());
+                        sceneAccidentPO.setCreateUserId(AuthUtil.getCurrentUserId());
+                        sceneAccidentPO.setModifyTime(TimeUtil.getNowForMysql());
+                    }
+                    //插入地址
+                    if (null != objectName && objectName.indexOf(".json")!=-1) {
+                        sceneAccidentPO.setJsonAddress(objectName);
+                    }else if (null != objectName && objectName.indexOf(".xml")!=-1) {
+                        sceneAccidentPO.setXmlAddress(objectName);
+                    }else if (null != objectName && objectName.indexOf(".xodr")!=-1) {
+                        sceneAccidentPO.setXodrAddress(objectName);
+                    }else if (null != objectName && objectName.indexOf(".osgb")!=-1) {
+                        sceneAccidentPO.setOsgbAddress(objectName);
+                    }else if (null != objectName && objectName.indexOf(".mp4")!=-1) {
+                        sceneAccidentPO.setVideoAddress(objectName);
+                    }
+                }
+            list.add(sceneAccidentPO);
+                wJNum++;
+            }
+            //SceneAccidentMapper.saveSceneAccident(sceneAccidentPO);
+        } catch (Exception e) {
+            return new ResponseBodyVO(ResponseBodyVO.Response.CLIENT_FAILURE, "该场景文件" + fileName + "解析出错");
+        }
+        return new ResponseBodyVO(ResponseBodyVO.Response.SUCCESS);
+
+    }
 }

+ 13 - 7
simulation-resource-server/src/main/resources/mapper/scene/SceneAccidentMapper.xml

@@ -6,11 +6,14 @@
         insert into simulation.scene_accident
         (accident_id,scene_name,self_driving,target_driving,
         self_reaction,conflict_behavior,conflict_type,
+        scence_resume,scene_time,scene_weather,
        create_user_id,create_time,modify_user_id,modify_time,
          is_deleted,share,video_preview,video_address,osgb_address,xml_address,xodr_address,
         json_address)
         values (#{accidentId,jdbcType=VARCHAR},#{sceneName,jdbcType=VARCHAR},#{selfDriving,jdbcType=VARCHAR}, #{targetDriving,jdbcType=VARCHAR},
         #{selfReaction,jdbcType=VARCHAR}, #{conflictBehavior,jdbcType=VARCHAR},#{conflictType,jdbcType=VARCHAR},
+        #{scenceResume,jdbcType=VARCHAR}, #{sceneTime,jdbcType=VARCHAR},#{sceneWeather,jdbcType=VARCHAR},
+
 
        #{createUserId,jdbcType=VARCHAR},#{createTime},#{modifyUserId,jdbcType=VARCHAR},#{modifyTime},
         #{isDeleted,jdbcType=VARCHAR}, #{share,jdbcType=VARCHAR},#{videoPreview,jdbcType=VARCHAR},#{videoAddress,jdbcType=VARCHAR},#{osgbAddress,jdbcType=VARCHAR},
@@ -23,6 +26,7 @@
         select
         accident_id,scene_name,self_driving,target_driving,
         self_reaction,conflict_behavior,conflict_type,
+        scence_resume,scene_time,scene_weather,
         create_user_id,create_time,modify_user_id,modify_time,
         is_deleted,share,video_address,video_preview,osgb_address,xml_address,xodr_address,
         json_address
@@ -30,6 +34,7 @@
         select
         accident_id,scene_name,self_driving,target_driving,
         self_reaction,conflict_behavior,conflict_type,
+        scence_resume,scene_time,scene_weather,
         create_user_id,create_time,modify_user_id,modify_time,
         is_deleted,share,video_address,video_preview,osgb_address,xml_address,xodr_address,
         json_address
@@ -86,6 +91,7 @@
             select
             accident_id,scene_name,self_driving,target_driving,
             self_reaction,conflict_behavior,conflict_type,
+             scence_resume,scene_time,scene_weather,
             create_user_id,create_time,modify_user_id,modify_time,
             is_deleted,share,video_address,video_preview,osgb_address,xml_address,xodr_address,
             json_address
@@ -123,12 +129,14 @@
         select
         accident_id,scene_name,self_driving,target_driving,
         self_reaction,conflict_behavior,conflict_type,
+        scence_resume,scene_time,scene_weather,
         create_user_id,create_time,modify_user_id,modify_time,
         is_deleted,share,video_address,video_preview,osgb_address,xml_address,xodr_address,
         json_address
         from( select
         accident_id,scene_name,self_driving,target_driving,
         self_reaction,conflict_behavior,conflict_type,
+        scence_resume,scene_time,scene_weather,
         create_user_id,create_time,modify_user_id,modify_time,
         is_deleted,share,video_address,video_preview,osgb_address,xml_address,xodr_address,
         json_address
@@ -163,6 +171,7 @@
         select
         accident_id,scene_name,self_driving,target_driving,
         self_reaction,conflict_behavior,conflict_type,
+        scence_resume,scene_time,scene_weather,
         create_user_id,create_time,modify_user_id,modify_time,
         is_deleted,share,video_address,video_preview,osgb_address,xml_address,xodr_address,
         json_address
@@ -243,16 +252,13 @@
     </update>
 
 
-    <select id="querySceneAccidentByNmae" parameterType="api.common.pojo.param.scene.SceneAccidentParam"
-            resultType="api.common.pojo.po.scene.SceneAccidentPO">
+    <select id="querySceneAccidentByNmae" parameterType="java.lang.String"
+            resultType="java.lang.Integer">
         select
-        accident_id,scene_name
+        count(scene_name)
         from simulation.scene_accident
-        <where>
+        where
             is_deleted = '0'
-            <if test="sceneName != null and sceneName != ''">
                 and scene_name =#{sceneName,jdbcType=VARCHAR}
-            </if>
-        </where>
     </select>
 </mapper>