ソースを参照

计算结果处理

dengsixing 3 年 前
コミット
55c53038a6

+ 8 - 5
4dkankan-center-modeling/src/main/java/com/fdkankan/modeling/receiver/BuildSceneListener.java

@@ -248,6 +248,7 @@ public class BuildSceneListener implements RocketMQListener<String> {
         Map<String,String> map = new HashMap<>();
         Integer pushChannel = null;
         String pushToken = null;
+        Integer videoVersion = null;
 
         try{
             if(StringUtils.equals(message.getIsStandardization(),"1")){
@@ -347,10 +348,12 @@ public class BuildSceneListener implements RocketMQListener<String> {
                 log.info("八目上完oss结束修改数据:"+projectNum);
 
                 //读取计算结果文件生成videosJson
-                videosJson = this.getVideosJson(path, dataJson, projectNum, Integer.valueOf(cameraType));
+//                videosJson = this.getVideosJson(path, dataJson, projectNum, Integer.valueOf(cameraType));
+                String videoVersionStr = dataJson.getString("videoVersion");
+                videoVersion = StrUtil.isEmpty(videoVersionStr) ? null : Integer.parseInt(videoVersionStr);
 
                 //更新scene.json里面的video数据
-                this.updateVideosToSceneJson(projectNum, videosJson);
+//                this.updateVideosToSceneJson(projectNum, videosJson);
 
                 //计算成功  激光转台相机 同步 请求
                 this.jgSynch(message);
@@ -365,7 +368,7 @@ public class BuildSceneListener implements RocketMQListener<String> {
         }finally {
             //发送计算结果到mq,再由消费者消费并操作数据库
             this.sendCallResult(buildSuccess, resultTopicName, cameraType, computeTime, fileId, payStatus,
-                projectNum, videosJson, map, path, pushChannel, pushToken,prefix);
+                projectNum, videosJson, map, path, pushChannel, pushToken,prefix, videoVersion);
             //上传status.json   console.log
             this.uploadStatusJsonAndConsoleLog(sceneProId, sceneStatus, webSite, projectNum, thumb, payStatus);
 
@@ -411,7 +414,7 @@ public class BuildSceneListener implements RocketMQListener<String> {
 
     private void sendCallResult(boolean buildSuccess, String resultTopicName, String cameraType, Long computeTime, String fileId,
                                 Integer payStatus, String projectNum, JSONObject videosJson,Map<String, String> uploadFiles,
-                                String path, Integer pushChannel, String pushToken, String prefix){
+                                String path, Integer pushChannel, String pushToken, String prefix, Integer videoVersion){
         rocketMQProducer.sendOneWay(resultTopicName,
                 BuildSceneResultMqMessage.builder()
                     .buildSuccess(buildSuccess)
@@ -420,12 +423,12 @@ public class BuildSceneListener implements RocketMQListener<String> {
                     .fileId(fileId)
                     .payStatus(payStatus)
                     .sceneCode(projectNum)
-                    .videosJson(buildSuccess? videosJson.toJSONString() : null)
                     .uploadFiles(uploadFiles)
                     .path(path)
                     .pushChannel(pushChannel)
                     .pushToken(pushToken)
                     .prefix(prefix)
+                    .videoVersion(videoVersion)
                     .build());
     }
 

+ 1 - 0
4dkankan-center-scene/src/main/java/com/fdkankan/scene/bean/SceneJsonBean.java

@@ -1,5 +1,6 @@
 package com.fdkankan.scene.bean;
 
+import com.alibaba.fastjson.JSONObject;
 import com.fdkankan.scene.vo.SceneEditControlsVO;
 import lombok.AllArgsConstructor;
 import lombok.Builder;

+ 38 - 17
4dkankan-center-scene/src/main/java/com/fdkankan/scene/listener/BuildSceneResultMQListener.java

@@ -1,6 +1,7 @@
 package com.fdkankan.scene.listener;
 
 import cn.hutool.http.HttpStatus;
+import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.fdkankan.common.constant.BuildStatus;
 import com.fdkankan.common.constant.ConstantFilePath;
@@ -19,6 +20,8 @@ import com.fdkankan.platform.api.feign.PlatformGoodsClient;
 import com.fdkankan.platform.api.feign.PlatformUserClient;
 import com.fdkankan.platform.api.vo.CameraDetail;
 import com.fdkankan.platform.api.vo.UserIncrement;
+import com.fdkankan.redis.util.RedisUtil;
+import com.fdkankan.scene.bean.SceneJsonBean;
 import com.fdkankan.scene.entity.SceneEditControls;
 import com.fdkankan.scene.entity.SceneEditInfo;
 import com.fdkankan.scene.entity.SceneFileBuild;
@@ -99,6 +102,8 @@ public class BuildSceneResultMQListener implements RocketMQListener<String> {
     UploadToOssUtil uploadToOssUtil;
     @Autowired
     IBuildScenePreService buildScenePreService;
+    @Autowired
+    RedisUtil redisUtil;
 
 
     @Override
@@ -115,9 +120,9 @@ public class BuildSceneResultMQListener implements RocketMQListener<String> {
         String sceneCode = message.getSceneCode();
         String fileId = message.getFileId();
         Integer payStatus = message.getPayStatus();
-        String videosJson = message.getVideosJson();
         Long computeTime = message.getComputeTime();
         Boolean buildSuccess = message.getBuildSuccess();
+        Integer videoVersion = message.getVideoVersion();
 
         Map<String, String> uploadFiles = message.getUploadFiles();
         String path = message.getPath();
@@ -148,9 +153,15 @@ public class BuildSceneResultMQListener implements RocketMQListener<String> {
                 return;
             }
 
+            //读取计算结果文件生成videosJson
+            String videosJson = buildScenePreService.getVideosJson(path, videoVersion, sceneCode, cameraType);
+
             //写入数据库
             ScenePro scenePro = this.updateDb(sceneCode, space, payStatus, videosJson, computeTime, fileId);
             SceneProExt sceneProExt = sceneProExtService.findBySceneProId(scenePro.getId());
+            Object[] editInfoArr = this.updateEditInfo(scenePro);
+            SceneEditInfo sceneEditInfo = (SceneEditInfo)editInfoArr[0];
+            SceneEditControls sceneEditControls = (SceneEditControls)editInfoArr[1];
 
             String sceneUrl = mainUrl + "/" + sceneProNewUrl;
             String outPathZh = ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+sceneCode+".png";
@@ -183,6 +194,12 @@ public class BuildSceneResultMQListener implements RocketMQListener<String> {
             //上传日志文件
             buildScenePreService.uploadLogFile(sceneCode, sceneProExt.getDataSource());
 
+            //写scene.json
+            String sceneJson = buildScenePreService.writeSceneJson(sceneCode, videosJson, sceneEditInfo, sceneEditControls, scenePro, sceneProExt);
+            //上传sceneJson文件
+            String sceneJsonPath = String.format(UploadFilePath.DATA_VIEW_PATH+"scene.json", sceneCode);
+            uploadToOssUtil.upload(sceneJson.getBytes(), sceneJsonPath);
+
         }catch (Exception e){
             log.error("场景计算后置处理出错", e);
             //发送钉钉
@@ -245,25 +262,29 @@ public class BuildSceneResultMQListener implements RocketMQListener<String> {
             }
             sceneProExtService.updateById(sceneProExt);
 
-            SceneEditInfo sceneEditInfo = sceneEditInfoService.getBySceneProId(scenePro.getId());
-            SceneEditControls sceneEditControls = null;
-            if(sceneEditInfo == null){
-                sceneEditInfo = new SceneEditInfo();
-                sceneEditInfo.setSceneProId(scenePro.getId());
-                sceneEditInfo.setDescription(scenePro.getSceneDec());
-                sceneEditInfo.setTitle(scenePro.getSceneName());
-                sceneEditInfoService.save(sceneEditInfo);
-            }else{
-                sceneEditControls = sceneEditControlsService.getBySceneEditId(sceneEditInfo.getId());
-            }
-            if(sceneEditControls == null){
-                sceneEditControls = new SceneEditControls();
-                sceneEditControls.setEditInfoId(sceneEditInfo.getId());
-                sceneEditControlsService.save(sceneEditControls);
-            }
         }
 
         return scenePro;
     }
 
+    private Object[] updateEditInfo(ScenePro scenePro){
+        SceneEditInfo sceneEditInfo = sceneEditInfoService.getBySceneProId(scenePro.getId());
+        SceneEditControls sceneEditControls = null;
+        if(sceneEditInfo == null){
+            sceneEditInfo = new SceneEditInfo();
+            sceneEditInfo.setSceneProId(scenePro.getId());
+            sceneEditInfo.setDescription(scenePro.getSceneDec());
+            sceneEditInfo.setTitle(scenePro.getSceneName());
+            sceneEditInfoService.save(sceneEditInfo);
+        }else{
+            sceneEditControls = sceneEditControlsService.getBySceneEditId(sceneEditInfo.getId());
+        }
+        if(sceneEditControls == null){
+            sceneEditControls = new SceneEditControls();
+            sceneEditControls.setEditInfoId(sceneEditInfo.getId());
+            sceneEditControlsService.save(sceneEditControls);
+        }
+        return new Object[]{sceneEditInfo, sceneEditControls};
+    }
+
 }

+ 9 - 0
4dkankan-center-scene/src/main/java/com/fdkankan/scene/service/IBuildScenePreService.java

@@ -2,7 +2,12 @@ package com.fdkankan.scene.service;
 
 import com.alibaba.fastjson.JSONObject;
 import com.fdkankan.mq.message.BuildSceneMqMessage;
+import com.fdkankan.scene.entity.SceneEditControls;
+import com.fdkankan.scene.entity.SceneEditInfo;
+import com.fdkankan.scene.entity.ScenePro;
+import com.fdkankan.scene.entity.SceneProExt;
 import java.io.IOException;
+import java.util.Date;
 import java.util.Map;
 
 /**
@@ -35,6 +40,10 @@ public interface IBuildScenePreService {
 
     void uploadLogFile(String num, String dataSource);
 
+    String getVideosJson(String path, Integer videoVersion, String projectNum, int cameraType) throws Exception ;
+
+    String writeSceneJson(String num, String videoJson, SceneEditInfo sceneEditInfo, SceneEditControls sceneEditControls, ScenePro scenePro, SceneProExt sceneProExt) throws Exception;
+
 
 
 }

+ 136 - 0
4dkankan-center-scene/src/main/java/com/fdkankan/scene/service/impl/BuildScenePreServiceImpl.java

@@ -9,10 +9,13 @@ import static com.fdkankan.push.PushMessageConfig.IOS_KEY_Z;
 import static com.fdkankan.push.PushMessageConfig.IOS_SECRET;
 import static com.fdkankan.push.PushMessageConfig.IOS_SECRET_Z;
 
+import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.util.StrUtil;
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.fdkankan.common.constant.ConstantFilePath;
+import com.fdkankan.common.constant.ConstantUrl;
 import com.fdkankan.common.constant.UploadFilePath;
 import com.fdkankan.common.util.CreateObjUtil;
 import com.fdkankan.common.util.FileUtil;
@@ -23,7 +26,14 @@ import com.fdkankan.fyun.oss.UploadToOssUtil;
 import com.fdkankan.mq.message.BuildSceneMqMessage;
 import com.fdkankan.push.PushMessageConfig;
 import com.fdkankan.push.PushMsgUtil;
+import com.fdkankan.scene.bean.SceneJsonBean;
+import com.fdkankan.scene.entity.SceneEditControls;
+import com.fdkankan.scene.entity.SceneEditInfo;
+import com.fdkankan.scene.entity.ScenePro;
+import com.fdkankan.scene.entity.SceneProExt;
 import com.fdkankan.scene.service.IBuildScenePreService;
+import com.fdkankan.scene.vo.SceneEditControlsVO;
+import com.fdkankan.scene.vo.SceneEditInfoVO;
 import com.taobao.api.ApiException;
 import java.io.File;
 import java.io.IOException;
@@ -38,6 +48,7 @@ import java.util.Map.Entry;
 import java.util.Objects;
 import java.util.concurrent.CompletableFuture;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
@@ -54,6 +65,8 @@ import org.springframework.stereotype.Service;
 @Service
 public class BuildScenePreServiceImpl implements IBuildScenePreService {
 
+    @Value("${oss.prefix.ali}")
+    private String prefixAli;
     @Autowired
     UploadToOssUtil uploadToOssUtil;
     @Value("${upload.type}")
@@ -341,4 +354,127 @@ public class BuildScenePreServiceImpl implements IBuildScenePreService {
         uploadToOssUtil.upload(dataSource+File.separator+"console.log",
             dataPath+"console.log");
     }
+
+    @Override
+    public String getVideosJson(String path, Integer videoVersion, String projectNum, int cameraType) throws Exception {
+        //读取videos_hdr_param.json, 保存点位视频的value
+        Map<String, Object> videoMap = new HashMap<>();
+        String videosHdr = FileUtils.readFile(path + File.separator + "results/videos/videos_hdr_param.json");
+        JSONArray videoArray = null;
+        if(StringUtils.isNotEmpty(videosHdr)){
+            videoArray = JSONObject.parseObject(videosHdr).getJSONArray("hdr_param");
+        }
+        if(videoArray != null){
+            for(int i = 0, len = videoArray.size(); i < len; i++) {
+                videoMap.put(videoArray.getJSONObject(i).getString("name"), videoArray.getJSONObject(i).getString("value"));
+                if(videoArray.getJSONObject(i).containsKey("fov")){
+                    videoMap.put(videoArray.getJSONObject(i).getString("name") + "_fov", videoArray.getJSONObject(i).getString("fov"));
+                }
+            }
+        }
+
+        //获取upload中的video视频名称
+        String uploadData = FileUtils.readFile(path + File.separator + "results" +File.separator+"upload.json");
+        JSONObject uploadJson = null;
+        JSONArray array = null;
+        if(uploadData!=null) {
+            uploadJson = JSONObject.parseObject(uploadData);
+            array = uploadJson.getJSONArray("upload");
+        }
+        JSONObject fileJson = null;
+        String fileName = "";
+
+        //计算ts文件的大小,并拼接成json格式
+        JSONArray jsonArray = new JSONArray();
+        JSONObject videoJson = null;
+        JSONObject videosJson = new JSONObject();
+        long videoSize = 0L;
+        for(int i = 0, len = array.size(); i < len; i++) {
+            fileJson = array.getJSONObject(i);
+            fileName = fileJson.getString("file");
+            if(fileJson.getIntValue("clazz") == 11 && fileName.contains(".mp4") && !fileName.contains("-ios.mp4")){
+                videoJson = new JSONObject();
+                videoJson.put("id", fileName.substring(
+                    0, fileName.lastIndexOf(".")).replace("videos/", ""));
+
+                //如果ts文件存在,就计算ts大小
+                if(new File(path + File.separator + "results" +File.separator+ fileName.replace(".mp4", ".ts")).exists()){
+                    videoSize = new File(path + File.separator + "results" +File.separator+ fileName.replace(".mp4", ".ts")).length();
+                    videoJson.put("tsSize", videoSize);
+                }
+                if(videoMap.containsKey(videoJson.get("id"))){
+                    videoJson.put("value", videoMap.get(videoJson.get("id")));
+                }
+                if(videoMap.containsKey(videoJson.get("id") + "_fov")){
+                    videoJson.put("blend_fov", videoMap.get(videoJson.get("id") + "_fov"));
+                }else {
+                    videoJson.put("blend_fov", 7);
+                }
+                jsonArray.add(videoJson);
+            }
+        }
+
+        videosJson.put("data", jsonArray);
+        if(Objects.nonNull(videoVersion) && videoVersion >= 4){
+            videosJson.put("version", 3);
+            if(StorageType.OSS.code().equals(ossType)){
+                videosJson.put("upPath", prefixAli + "data/data" + projectNum + "/Up.xml");
+            }
+            if(StorageType.AWS.code().equals(ossType)){
+                videosJson.put("upPath", ConstantUrl.PREFIX_AWS + "data/data" + projectNum + "/Up.xml");
+            }
+            if(cameraType == 13){
+                //转台相机
+                videosJson.put("upPath", videosJson.getString("upPath").replace(".xml", ".txt"));
+            }
+        }else {
+            videosJson.put("version", 1);
+            if("oss".equals(ossType)){
+                videosJson.put("upPath", prefixAli + "data/data" + projectNum + "/Up2.xml");
+            }
+            if("aws".equals(ossType)){
+                videosJson.put("upPath", ConstantUrl.PREFIX_AWS + "data/data" + projectNum + "/Up2.xml");
+            }
+
+            if(cameraType == 13){
+                //转台相机
+                videosJson.put("upPath", videosJson.getString("upPath").replace(".xml", ".txt"));
+            }
+        }
+
+        if(cameraType == 5 || cameraType == 6){
+            videosJson.put("version", 1);
+            if("oss".equals(ossType)){
+                videosJson.put("upPath", prefixAli + "data/data" + projectNum + "/stitch_params.txt");
+            }
+            if("aws".equals(ossType)){
+                videosJson.put("upPath", ConstantUrl.PREFIX_AWS + "data/data" + projectNum + "/stitch_params.txt");
+            }
+        }
+
+        return videosJson.toJSONString();
+    }
+
+    @Override
+    public String writeSceneJson(String num, String videosJson, SceneEditInfo sceneEditInfo,
+        SceneEditControls sceneEditControls, ScenePro scenePro, SceneProExt sceneProExt)  throws Exception{
+        String sceneJsonPath = String.format(ConstantFilePath.SCENE_PATH_FORMAT, num);
+        String strsceneInfos = FileUtils.readFile(sceneJsonPath);
+        JSONObject scenejson = new JSONObject();
+        if(strsceneInfos!=null){
+            scenejson = JSONObject.parseObject(strsceneInfos);
+        }else{
+            SceneJsonBean sceneJson = BeanUtil.copyProperties(sceneEditInfo, SceneJsonBean.class);
+            SceneEditControlsVO sceneEditControlsVO = BeanUtil.copyProperties(sceneEditControls, SceneEditControlsVO.class);
+            sceneJson.setControls(sceneEditControlsVO);
+            sceneJson.setNum(num);
+            sceneJson.setCreateTime(scenePro.getCreateTime());
+            sceneJson.setSceneResolution(sceneProExt.getSceneResolution());
+            sceneJson.setSceneFrom(sceneProExt.getSceneFrom());
+            sceneJson.setVideos(videosJson);
+        }
+        scenejson.put("videos", videosJson);
+        FileUtils.writeFile(sceneJsonPath, scenejson.toString());
+        return scenejson.toString();
+    }
 }

+ 3 - 0
4dkankan-center-scene/src/main/java/com/fdkankan/scene/service/impl/SceneEditInfoServiceImpl.java

@@ -200,6 +200,9 @@ public class SceneEditInfoServiceImpl extends ServiceImpl<ISceneEditInfoMapper,
         //处理球幕视频
 //        this.buildVideo(sceneEditInfo, sceneProExt.getDataSource(), sceneNum);
 
+        //本地写sceneJson文件
+        String localSceneJsonPath = String.format(ConstantFilePath.SCENE_PATH_FORMAT, sceneNum);
+        FileUtils.writeFile(localSceneJsonPath, JSON.toJSONString(sceneJson));
         //上传sceneJson文件
         String sceneJsonPath = String.format(UploadFilePath.DATA_VIEW_PATH+"scene.json", sceneNum);
         uploadToOssUtil.upload(JSON.toJSONBytes(sceneJson), sceneJsonPath);