Browse Source

计算优化
上传全景图,可以部分成功,部分失败

dengsixing 3 years ago
parent
commit
411e847771

+ 113 - 110
4dkankan-center-modeling/src/main/java/com/fdkankan/modeling/receiver/BuildSceneListener.java

@@ -163,9 +163,8 @@ public class BuildSceneListener implements RocketMQListener<String> {
         watch.start();
 
         BuildLog buildLog = new BuildLog();
-        BuildSceneResultBean buildSceneResult = new BuildSceneResultBean();
-
-        Future<BuildSceneResultBean> future = null;
+        final BuildSceneResultBean buildSceneResult = new BuildSceneResultBean();
+        Future<ModelingBuildStatus> future = null;
         try {
 
             //休眠2秒等待准备数据
@@ -175,9 +174,9 @@ public class BuildSceneListener implements RocketMQListener<String> {
             preBuild(message, buildLog);
 
             future = SysConstants.executorService.submit(()->{
-                return buildScene(message);
+                return buildScene(message, buildSceneResult);
             });
-            buildSceneResult = future.get(SysConstants.modelTimeOut, TimeUnit.SECONDS);
+            future.get(SysConstants.modelTimeOut, TimeUnit.HOURS);
 
             //结束计时
             watch.stop();
@@ -202,8 +201,7 @@ public class BuildSceneListener implements RocketMQListener<String> {
 
     }
 
-    private BuildSceneResultBean buildScene(BuildSceneMqMessage message){
-        ModelingBuildStatus buildStatus = ModelingBuildStatus.FAILED;
+    private ModelingBuildStatus buildScene(BuildSceneMqMessage message, BuildSceneResultBean buildSceneResult) throws Exception{
         String projectNum = null;
         Long computeTime = null;//计算耗时
         //如果mq生产者在消息体中执行了计算结果mq的主题名,就发到这个主题名,否则就发送到配置的主题名
@@ -229,129 +227,134 @@ public class BuildSceneListener implements RocketMQListener<String> {
 
         String dataPath = "data/data" + projectNum;//老版本文件路径
 
-        Map<String,String> map = new HashMap<>();
+        Map<String,String> map = null;
         Integer pushChannel = null;
         String pushToken = null;
         Integer videoVersion = null;
 
-        try{
-
-            Map<String, String> dataMap = ComputerUtil.getTypeString(cameraType, algorithm,
-                    resolution);
-            String splitType = dataMap.get("splitType");
-            String skyboxType = dataMap.get("skyboxType");
-            String dataDescribe = dataMap.get("dataDescribe");
+        buildSceneResult.setResultTopicName(resultTopicName);
+        buildSceneResult.setCameraType(cameraType);
+        buildSceneResult.setNum(projectNum);
 
-            log.info("用的算法是:"+algorithm);
-            log.info("用的相机是:"+ (Integer.parseInt(cameraType) < 4 ? "单球目" : "双球目(八目)"));
 
-            //4表示硬件部研发的双球目相机,其余为旧版本相机
-            if(Integer.parseInt(cameraType) < 3){
-
-                String data = FileUtils.readFile(path + File.separator + "capture" +File.separator+"data.fdage");
-                JSONObject dataJson = new JSONObject();
-                if(data!=null){
-                    dataJson = JSONObject.parseObject(data);
-                    if(dataJson.containsKey("imgs")){
-                        splitType = "SPLIT_V4";
-                    }
-                }
-                //生成project.json和data.json供算法部使用
-                ComputerUtil.createJson(path, splitType, skyboxType, dataDescribe, projectNum, path);
-                //计算模型并返回需要上传oss的文件集合
-                map = ComputerUtil.computer(projectNum, path, buildType);
+        Map<String, String> dataMap = ComputerUtil.getTypeString(cameraType, algorithm,
+                resolution);
+        String splitType = dataMap.get("splitType");
+        String skyboxType = dataMap.get("skyboxType");
+        String dataDescribe = dataMap.get("dataDescribe");
 
-            } else {
+        log.info("用的算法是:"+algorithm);
+        log.info("用的相机是:"+ (Integer.parseInt(cameraType) < 4 ? "单球目" : "双球目(八目)"));
 
-                path = SceneUtil.getPath(path, cameraName, fileId, Integer.parseInt(cameraType), unicode);
+        //4表示硬件部研发的双球目相机,其余为旧版本相机
+        if(Integer.parseInt(cameraType) < 3){
 
-                String dataFdagePath = path + File.separator + "capture" +File.separator+"data.fdage";
-                log.info("dataFdagePath 文件路径 :{}", dataFdagePath);
-                String data = FileUtils.readFile(dataFdagePath);
-                //获取data.fdage的内容
-                JSONObject dataJson = new JSONObject();
-                if(data!=null){
-                    dataJson = JSONObject.parseObject(data);
-                }
-                pushChannel = dataJson.getInteger("pushChannel");
-                pushToken = dataJson.getString("pushToken");
-
-                /*
-                 1、判断是否计算过资源,若计算过删除缓存, 如果caches中存在_images文件或者目录,就删除掉,否则就删除除了images以外的所有文件和目录
-                 2、删除上一次计算出来的result目录
-                 */
-                this.deleteCachesAndResult(path);
-
-                //v2版本使用4k算法
-                if(dataJson.containsKey("videoVersion")
-                        && StringUtils.isNotEmpty(dataJson.getString("videoVersion"))
-                        && Integer.parseInt(dataJson.getString("videoVersion")) < 4){
-                    skyboxType = "SKYBOX_V6";
+            String data = FileUtils.readFile(path + File.separator + "capture" +File.separator+"data.fdage");
+            JSONObject dataJson = new JSONObject();
+            if(data!=null){
+                dataJson = JSONObject.parseObject(data);
+                if(dataJson.containsKey("imgs")){
+                    splitType = "SPLIT_V4";
                 }
+            }
+            //生成project.json和data.json供算法部使用
+            ComputerUtil.createJson(path, splitType, skyboxType, dataDescribe, projectNum, path);
+            //计算模型并返回需要上传oss的文件集合
+            map = ComputerUtil.computer(projectNum, path, buildType);
+
+        } else {
+
+            path = SceneUtil.getPath(path, cameraName, fileId, Integer.parseInt(cameraType), unicode);
+
+            String dataFdagePath = path + File.separator + "capture" +File.separator+"data.fdage";
+            log.info("dataFdagePath 文件路径 :{}", dataFdagePath);
+            String data = FileUtils.readFile(dataFdagePath);
+            //获取data.fdage的内容
+            JSONObject dataJson = new JSONObject();
+            if(data!=null){
+                dataJson = JSONObject.parseObject(data);
+            }
+            pushChannel = dataJson.getInteger("pushChannel");
+            pushToken = dataJson.getString("pushToken");
+
+            /*
+             1、判断是否计算过资源,若计算过删除缓存, 如果caches中存在_images文件或者目录,就删除掉,否则就删除除了images以外的所有文件和目录
+             2、删除上一次计算出来的result目录
+             */
+            this.deleteCachesAndResult(path);
+
+            //v2版本使用4k算法
+            if(dataJson.containsKey("videoVersion")
+                    && StringUtils.isNotEmpty(dataJson.getString("videoVersion"))
+                    && Integer.parseInt(dataJson.getString("videoVersion")) < 4){
+                skyboxType = "SKYBOX_V6";
+            }
 
-                //生成project.json和data.json并写到path目录下供算法部使用
-                log.info("path:" + path);
-                ComputerUtil.createJson(path, splitType, skyboxType, dataDescribe, projectNum, path);
-                //计算模型并返回需要上传oss的文件集合
-                map = ComputerUtil.computer(projectNum, path, buildType);
-                //计算完成时间
-                log.info("计算完成耗时:{}",computeTime);
+            //生成project.json和data.json并写到path目录下供算法部使用
+            log.info("path:" + path);
+            ComputerUtil.createJson(path, splitType, skyboxType, dataDescribe, projectNum, path);
+            //计算模型并返回需要上传oss的文件集合
+            map = ComputerUtil.computer(projectNum, path, buildType);
+            //计算完成时间
+            log.info("计算完成耗时:{}",computeTime);
 
-                if(Integer.parseInt(cameraType) == 5 || Integer.parseInt(cameraType) == 6){
-                    map.put(path + File.separator + "capture/stitch_params.txt", dataPath + "/stitch_params.txt");
-                }
-                map.put(path + File.separator + "capture/Up.xml", dataPath + "/Up.xml");
-                map.put(path + File.separator + "capture/Up2.xml", dataPath + "/Up2.xml");
+            if(Integer.parseInt(cameraType) == 5 || Integer.parseInt(cameraType) == 6){
+                map.put(path + File.separator + "capture/stitch_params.txt", dataPath + "/stitch_params.txt");
+            }
+            map.put(path + File.separator + "capture/Up.xml", dataPath + "/Up.xml");
+            map.put(path + File.separator + "capture/Up2.xml", dataPath + "/Up2.xml");
 
-                //转台相机
-                if(Integer.parseInt(cameraType) == 13){
-                    map.put(path + File.separator + "capture/Up.txt", dataPath + "/Up.txt");
-                    map.put(path + File.separator + "capture/Up2.txt", dataPath + "/Up2.txt");
-                }
+            //转台相机
+            if(Integer.parseInt(cameraType) == 13){
+                map.put(path + File.separator + "capture/Up.txt", dataPath + "/Up.txt");
+                map.put(path + File.separator + "capture/Up2.txt", dataPath + "/Up2.txt");
+            }
 
-                //计算已使用容量
-                payStatus = 1;
+            //计算已使用容量
+            payStatus = 1;
 
-                log.info("八目上完oss结束修改数据:"+projectNum);
+            log.info("八目上完oss结束修改数据:"+projectNum);
 
-                //读取计算结果文件生成videosJson
+            //读取计算结果文件生成videosJson
 //                videosJson = this.getVideosJson(path, dataJson, projectNum, Integer.valueOf(cameraType));
-                String videoVersionStr = dataJson.getString("videoVersion");
-                videoVersion = StrUtil.isEmpty(videoVersionStr) ? null : Integer.parseInt(videoVersionStr);
+            String videoVersionStr = dataJson.getString("videoVersion");
+            videoVersion = StrUtil.isEmpty(videoVersionStr) ? null : Integer.parseInt(videoVersionStr);
 
-                //更新scene.json里面的video数据
+            //更新scene.json里面的video数据
 //                this.updateVideosToSceneJson(projectNum, videosJson);
 
-                //计算成功  激光转台相机 同步 请求
-                this.jgSynch(message);
-            }
-
-            CreateObjUtil.deleteFile(path.replace(ConstantFilePath.BUILD_MODEL_PATH, "/") + "/capture");
-            buildStatus = ModelingBuildStatus.SUCCESS;
-        }
-        finally {
-            //上传status.json   console.log
-//            this.uploadStatusJsonAndConsoleLog(sceneStatus, webSite, projectNum, thumb, payStatus);
-
-            //发送计算结果到mq,再由消费者消费并操作数据库
-//            this.sendCallResult(buildSuccess, resultTopicName, cameraType, computeTime, fileId, payStatus,
-//                projectNum, videosJson, map, path, pushChannel, pushToken,prefix, videoVersion);
-
-            return BuildSceneResultBean.builder()
-                .buildStatus(buildStatus)
-                .resultTopicName(resultTopicName)
-                .cameraType(cameraType)
-                .fileId(fileId)
-                .payStatus(payStatus)
-                .num(projectNum)
-                .uploadMap(map)
-                .path(path)
-                .pushChannel(pushChannel)
-                .pushToken(pushToken)
-                .prefix(prefix)
-                .videoVersion(videoVersion)
-                .build();
+            //计算成功  激光转台相机 同步 请求
+            this.jgSynch(message);
         }
+
+        buildSceneResult.setBuildStatus(ModelingBuildStatus.SUCCESS);
+        buildSceneResult.setFileId(fileId);
+        buildSceneResult.setPayStatus(payStatus);
+        buildSceneResult.setUploadMap(map);
+        buildSceneResult.setPath(path);
+        buildSceneResult.setPushChannel(pushChannel);
+        buildSceneResult.setPushToken(pushToken);
+        buildSceneResult.setPrefix(prefix);
+        buildSceneResult.setVideoVersion(videoVersion);
+
+        CreateObjUtil.deleteFile(path.replace(ConstantFilePath.BUILD_MODEL_PATH, "/") + "/capture");
+
+        return ModelingBuildStatus.SUCCESS;
+
+//        return BuildSceneResultBean.builder()
+//            .buildStatus(ModelingBuildStatus.SUCCESS)
+//            .resultTopicName(resultTopicName)
+//            .cameraType(cameraType)
+//            .fileId(fileId)
+//            .payStatus(payStatus)
+//            .num(projectNum)
+//            .uploadMap(map)
+//            .path(path)
+//            .pushChannel(pushChannel)
+//            .pushToken(pushToken)
+//            .prefix(prefix)
+//            .videoVersion(videoVersion)
+//            .build();
     }
 
     private void afterBuild(BuildSceneMqMessage message, BuildSceneResultBean buildSceneResult, BuildLog buildLog){
@@ -477,7 +480,7 @@ public class BuildSceneListener implements RocketMQListener<String> {
         //如果是计算失败,需要发送钉钉
         if(!buildSuccess){
             // TODO: 2022/1/25 测试阶段,先注释掉推送
-//            this.sendDingTalkMq(buildStatus.message(), message);
+            this.sendDingTalkMq(buildStatus.message(), message);
         }
     }
 

+ 2 - 1
4dkankan-center-scene/src/main/java/com/fdkankan/scene/controller/TestController.java

@@ -98,8 +98,9 @@ public class TestController {
 
 //        folderService.list();
 
+        long aaaaaaa = redisUtil.incr("aaaaaaa", 1);
 
-        return "123";
+        return aaaaaaa + "";
 
     }
 

+ 1 - 0
4dkankan-center-scene/src/main/java/com/fdkankan/scene/listener/BuildScenePreMQListener.java

@@ -109,6 +109,7 @@ public class BuildScenePreMQListener implements RocketMQListener<String> {
             if (building.compareTo(1L) != 0) {
                 log.error("场景正在构建中,退出构建,参数:{}", JSONObject.toJSONString(message));
                 reason = "重复计算";
+                return;
             } else {
                 redisUtil.expire(key, Duration.of(modelTimeOut, ChronoUnit.HOURS));
             }

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

@@ -50,6 +50,7 @@ import com.fdkankan.scene.service.IScenePlusExtService;
 import com.fdkankan.scene.service.IScenePlusService;
 import com.fdkankan.scene.service.ISceneProExtService;
 import com.fdkankan.scene.service.ISceneProService;
+import com.fdkankan.scene.service.impl.IFdkkLaserServiceImpl.Result;
 import com.fdkankan.scene.vo.*;
 import com.google.common.collect.Lists;
 import com.google.errorprone.annotations.Var;
@@ -723,7 +724,8 @@ public class SceneEditInfoServiceImpl extends ServiceImpl<ISceneEditInfoMapper,
         SceneProExt sceneProExt = sceneProExtService.findBySceneProId(scenePro.getId());
 
         //原始计算根目录
-        String path = sceneProExt.getDataSource();
+                String path = "F:\\test";
+//        String path = sceneProExt.getDataSource();
         //全景图计算根目录
         String target = path + "_images";
         //解压缩文件存放目录
@@ -733,7 +735,6 @@ public class SceneEditInfoServiceImpl extends ServiceImpl<ISceneEditInfoMapper,
 
         //压缩包保存到本地
 //        String cachePath =  String.format(ConstantFilePath.SCENE_CACHE_IMAGES, num);
-//        String path = "F:\\mnt\\4Dkankan\\scene\\t-ieXdyGl6Md\\caches\\images\\";
 
         //先删除本地文件
         FileUtils.deleteDirectory(targetImagesPath);
@@ -768,13 +769,14 @@ public class SceneEditInfoServiceImpl extends ServiceImpl<ISceneEditInfoMapper,
                 }
             }
             return true;
-        }).map(filePath -> {
-            return filePath.substring(filePath.lastIndexOf(File.separator) + 1);
         }).collect(Collectors.toList());
 
         //有文件对不上号,就退出
         if(CollUtil.isNotEmpty(notExistFileList)){
-            return ResultData.error(ErrorCode.FAILURE_CODE_7012, notExistFileList);
+            //删除错误文件
+            notExistFileList.parallelStream().forEach(filePath->{
+                FileUtils.deleteFile(filePath);
+            });
         }
 
         //上传
@@ -891,7 +893,13 @@ public class SceneEditInfoServiceImpl extends ServiceImpl<ISceneEditInfoMapper,
             uploadToOssUtil.uploadMulFiles(map);
         }
 
-        return null;
+        if(CollUtil.isNotEmpty(notExistFileList)){
+            notExistFileList = notExistFileList.stream().map(filePath -> {
+                return filePath.substring(filePath.lastIndexOf(File.separator) + 1);
+            }).collect(Collectors.toList());
+        }
+
+        return ResultData.ok(notExistFileList);
     }
 
     @Override