Browse Source

nas瘦身改造

dsx 2 years ago
parent
commit
6bdd41334f

+ 30 - 35
src/main/java/com/fdkankan/scene/service/impl/SceneEditInfoServiceImpl.java

@@ -985,7 +985,7 @@ public class SceneEditInfoServiceImpl extends ServiceImpl<ISceneEditInfoMapper,
         String zipTargetFilePath = targetImagesPath + file.getOriginalFilename();
 
         //判断全景图缓存是否存在,如果不存在,从计算目录中拷贝到缓存目录
-        this.cachePanorama(path, num);
+//        this.cachePanorama(path, num);
 
         //先删除本地文件
         FileUtils.deleteDirectory(targetImagesPath);
@@ -1037,11 +1037,11 @@ public class SceneEditInfoServiceImpl extends ServiceImpl<ISceneEditInfoMapper,
         }
 
         //比对图片列表,不存在的要返回名称集合
-        String visionPath = path + "/results/vision.txt";
+        String visionPath =  fYunFileService.getFileContent(bucket, String.format(UploadFilePath.IMG_VIEW_PATH, num) + "vision.txt");
         List<String> panoramaImageList = SceneUtil.getPanoramaImageList(visionPath);
         List<String> notExistFileList = uploadFileList.stream().filter(filePath -> {
             filePath = filePath.substring(filePath.lastIndexOf(File.separator) + 1);
-            if(panoramaImageList.contains(filePath)){
+            if(CollUtil.isEmpty(panoramaImageList) || panoramaImageList.contains(filePath)){
                 return false;
             }
             return true;
@@ -1073,8 +1073,9 @@ public class SceneEditInfoServiceImpl extends ServiceImpl<ISceneEditInfoMapper,
         CreateObjUtil.convertVisionmodeldataToTxt(target + File.separator + "extras" + File.separator + "vision.modeldata",
             target + File.separator + "extras" + File.separator + "vision.txt");
 
-        FileUtils.copyFile(path + File.separator + "data.json", target + File.separator+"data.json", true);
-        FileUtils.copyFile(path + File.separator + "project.json", target + File.separator+"project.json", true);
+        String ossResultPath = String.format(UploadFilePath.scene_result_data_path, num);
+        fYunFileService.downloadFile(bucket, ossResultPath + "data.json", target + File.separator+"data.json");
+        fYunFileService.downloadFile(bucket, ossResultPath + "project.json", target + File.separator+"project.json");
 
         //data.json增加extras为执行重建算法
         String data = FileUtils.readFile(target + File.separator+"data.json");
@@ -1108,10 +1109,7 @@ public class SceneEditInfoServiceImpl extends ServiceImpl<ISceneEditInfoMapper,
         if(new File(target + File.separator + "results").exists()){
             FileUtils.delAllFile(target + File.separator + "results");
         }
-//        if(FYunTypeEnum.AWS.code().equals(fyunType)){
-//            //亚马逊保持旧方式,超链接capture
-//            CreateObjUtil.createSoftConnection(path + File.separator + "capture", target + File.separator + "capture");
-//        }
+
         fYunFileService.downloadFile(ConstantFilePath.OSS_PREFIX + path.replace(ConstantFilePath.BUILD_MODEL_PATH, "") + "/data.fdage", target + File.separator + "capture/data.fdage");
 
         //如果部分成功,则需要返回成功数量和失败列表
@@ -1237,16 +1235,17 @@ public class SceneEditInfoServiceImpl extends ServiceImpl<ISceneEditInfoMapper,
                 continue;
             }
         }
-        if(map.size()>0) {
-            fYunFileService.uploadMulFiles(bucket, map);
-        }
 
-        //拷贝修改后的全景图到缓存目录
-        String cachedImagesPath = String.format(ConstantFilePath.SCENE_CACHE_IMAGES, num);
+        //用户上传的全景图上传到ossresult目录
+        String ossCachesImagesPath = String.format(UploadFilePath.scene_result_data_path, num) + "caches/images/";
         uploadFileList.stream().forEach(srcPath->{
-            cn.hutool.core.io.FileUtil.copy(srcPath, srcPath.replace(targetImagesPath, cachedImagesPath), true);
+            map.put(srcPath, srcPath.replace(targetImagesPath, ossCachesImagesPath));
         });
 
+        if(map.size()>0) {
+            fYunFileService.uploadMulFiles(bucket, map);
+        }
+
         //更新数据库版本号
         ScenePlus scenePlus = scenePlusService.getScenePlusByNum(num);
         SceneEditInfo sceneEditInfo = this.getByScenePlusId(scenePlus.getId());
@@ -1283,29 +1282,27 @@ public class SceneEditInfoServiceImpl extends ServiceImpl<ISceneEditInfoMapper,
         String cacheImageFormat = "downloads/scene/%s/caches/images/";
 
         //判断全景图缓存是否存在,如果不存在,从计算目录中拷贝到缓存目录
-        this.cachePanorama(scenePlusExt.getDataSource(), num);
+//        this.cachePanorama(scenePlusExt.getDataSource(), num);
 
         Map<String, Object> map = new HashMap<>();
 
         //标记是否是异步操作,默认是同步操作
         //如果入参文件名不为空,则是单个文件下载,不需要打包
+        String ossResultPath = String.format(UploadFilePath.scene_result_data_path, num) + "caches/images/";
         if(StrUtil.isNotEmpty(fileName)){
             //如果是单张图片,直接提供oss url
-            String localFilePath = localImagesPath + fileName;
-            String ossFilePath = imgCachePath + fileName;
-            if(!cn.hutool.core.io.FileUtil.exist(localFilePath)){
+            if(!fYunFileService.fileExist(bucket, ossResultPath + fileName)){
                 throw new BusinessException(ErrorCode.FAILURE_CODE_5063);
             }
-            fYunFileService.uploadFile(bucket, localFilePath, ossFilePath);
-            String url = ossUrlPrefix + ossFilePath;
+            String url = ossUrlPrefix + ossResultPath + fileName;
             String downloadName = fileName;
             map.put("asyn", CommonStatus.NO.code());
             map.put("fileUrl", url + "?t=" + System.currentTimeMillis());
             map.put("fileName", downloadName);
             return ResultData.ok(map);
         }else{
-            if(!cn.hutool.core.io.FileUtil.exist(localImagesPath)
-                || cn.hutool.core.io.FileUtil.isDirEmpty(new File(localImagesPath))){
+            //判断全景图目录是否存在
+            if(!fYunFileService.fileExist(bucket, ossResultPath)){
                 throw new BusinessException(ErrorCode.FAILURE_CODE_5063);
             }
 
@@ -1328,6 +1325,11 @@ public class SceneEditInfoServiceImpl extends ServiceImpl<ISceneEditInfoMapper,
                 sceneAsynOperLog.setVersion(sceneEditInfo.getImgVersion());
                 sceneAsynOperLogService.save(sceneAsynOperLog);
                 try {
+
+                    //下载到本地目录
+                    FileUtil.del(localImagesPath);
+                    fYunFileService.downloadFileByCommand(bucket, localImagesPath, ossResultPath);
+
                     String downloadName = num + "_images.zip";
                     long start = Calendar.getInstance().getTimeInMillis();
                     //打包
@@ -1919,7 +1921,6 @@ public class SceneEditInfoServiceImpl extends ServiceImpl<ISceneEditInfoMapper,
         ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
         String bucket = scenePlusExt.getYunFileBucket();
 
-        String localDataPath = String.format(ConstantFilePath.DATABUFFER_FORMAT, num);
         String localImagesPath = String.format(ConstantFilePath.IMAGESBUFFER_FORMAT, num);
         String path = scenePlusExt.getDataSource();
         String target = localImagesPath + "panorama/" + sid;
@@ -1934,8 +1935,9 @@ public class SceneEditInfoServiceImpl extends ServiceImpl<ISceneEditInfoMapper,
         file.transferTo(targetFile);
 
         //调用算法切全景图
-        FileUtils.copyFile(path + File.separator + "data.json", target + File.separator+"data.json", true);
-        FileUtils.copyFile(path + File.separator + "project.json", target + File.separator+"project.json", true);
+        String ossResultPath = String.format(UploadFilePath.scene_result_data_path, num);
+        fYunFileService.downloadFile(bucket, ossResultPath + "data.json", target + File.separator+"data.json");
+        fYunFileService.downloadFile(bucket, ossResultPath + "project.json", target + File.separator+"project.json");
         JSONObject visionJson = new JSONObject();
         JSONArray visionArray = new JSONArray();
         visionJson.put("uuid", sid);
@@ -1944,9 +1946,7 @@ public class SceneEditInfoServiceImpl extends ServiceImpl<ISceneEditInfoMapper,
         visionArray.add(visionJson);
         JSONObject vision = new JSONObject();
         vision.put("sweepLocations", visionArray);
-        cn.hutool.core.io.FileUtil.writeString(vision.toString(),
-            target + "/extras" + File.separator + "vision.txt",
-            StandardCharsets.UTF_8);
+        cn.hutool.core.io.FileUtil.writeString(vision.toString(), target + "/extras" + File.separator + "vision.txt", StandardCharsets.UTF_8);
 
         //data.json增加extras为执行重建算法
         String type = "4k";
@@ -1974,8 +1974,7 @@ public class SceneEditInfoServiceImpl extends ServiceImpl<ISceneEditInfoMapper,
             }
             dataJson.put("skybox_type", skyboxType);
 
-            cn.hutool.core.io.FileUtil.writeString(dataJson.toString(),
-                target + File.separator+"data.json", StandardCharsets.UTF_8);
+            cn.hutool.core.io.FileUtil.writeString(dataJson.toString(), target + File.separator+"data.json", StandardCharsets.UTF_8);
         }
 
         //创建文件夹软连接并且复制data.json和project.json
@@ -1990,10 +1989,6 @@ public class SceneEditInfoServiceImpl extends ServiceImpl<ISceneEditInfoMapper,
             cn.hutool.core.io.FileUtil.del(resultPath);
         }
         //下载data.fdage
-//        if(FYunTypeEnum.AWS.code().equals(this.fyunType)){
-//            //亚马逊保持旧方式,超链接capture
-//            CreateObjUtil.createSoftConnection(path + File.separator + "capture", capturePath);
-//        }
         fYunFileService.downloadFile(ConstantFilePath.OSS_PREFIX + path.replace(ConstantFilePath.BUILD_MODEL_PATH, "") + "/data.fdage", capturePath + "/data.fdage");
         CreateObjUtil.build3dModel(target , "1");
 

+ 35 - 94
src/main/java/com/fdkankan/scene/service/impl/SceneProServiceImpl.java

@@ -723,7 +723,8 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
                     .set(SceneEditInfo::getIsUploadObj, CommonStatus.YES.code())
                     .eq(SceneEditInfo::getId, sceneEditInfo.getId()));
 
-            sceneEditInfoService.upgradeSceneJsonVersion(num, sceneEditInfo.getVersion() + 1, sceneEditInfo.getImgVersion() + 1, bucket);        }
+            sceneEditInfoService.upgradeSceneJsonVersion(num, sceneEditInfo.getVersion() + 1, sceneEditInfo.getImgVersion() + 1, bucket);
+        }
 
         return ResultData.ok();
     }
@@ -758,7 +759,7 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
         }
 
         //算法计算完后,生成压缩文件,上传到oss
-        this.uploadFileofterRebuildPanoram(path, num, bucket);
+        this.uploadFileofterRebuildPanoram(path, filePath, num, bucket);
     }
 
     /**
@@ -859,7 +860,7 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
 
     }
 
-    private void uploadFileofterRebuildPanoram(String path, String sceneNum, String bucket) throws Exception {
+    private void uploadFileofterRebuildPanoram(String path, String filePath, String sceneNum, String bucket) throws Exception {
         //因为共享目录有延迟,这里循环检测算法是否计算完毕3次,每次隔五秒
         String uploadJsonPath = path + File.separator + "results" +File.separator+"upload.json";
         boolean exist = ComputerUtil.checkComputeCompleted(uploadJsonPath, maxCheckTimes, waitTime);
@@ -905,6 +906,13 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
 //        map.put(path + File.separator + "results" +File.separator+ConstantFileName.modelUUID+"_50k.dam.lzma", imgViewPath +ConstantFileName.modelUUID+"_50k.dam.lzma");
         map.put(path + File.separator + "results" +File.separator+ConstantFileName.modelUUID+"_50k.dam", imgViewPath+ConstantFileName.modelUUID+"_50k.dam");
 
+        String ossMeshPath = String.format(UploadFilePath.DATA_VIEW_PATH, sceneNum) + "mesh";
+        //删除oss中的mesh
+        fYunFileService.deleteFolder(bucket, ossMeshPath);
+        //上传obj相关文件
+        List<String> fileNames = FileUtil.listFileNames(filePath);
+        fileNames.stream().forEach(name->map.put(filePath + name, ossMeshPath + File.separator + name));
+
         fYunFileService.uploadMulFiles(bucket, map);
     }
 
@@ -1033,7 +1041,7 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
             return this.downloadModel43dtiles(num, bucket, scenePlusExt, sceneEditInfo);
         }
 
-        return this.downloadModel4Dam(num, bucket, scenePlusExt, sceneEditInfo);
+        return this.downloadModel4Dam(num, bucket);
     }
 
     @Override
@@ -1068,106 +1076,38 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
     }
 
 
-    private ResultData downloadModel4Dam(String num, String bucket, ScenePlusExt scenePlusExt, SceneEditInfo sceneEditInfo){
+    private ResultData downloadModel4Dam(String num, String bucket){
         String localImagePath = String.format(ConstantFilePath.IMAGESBUFFER_FORMAT, num);
         if(!new File(localImagePath).exists()){
             new File(localImagePath).mkdirs();
         }
 
-
-        String newData =  scenePlusExt.getDataSource() + "_obj2txt/extras";
-        String newResultData = scenePlusExt.getDataSource() + "_obj2txt/results/upload.json";
         String zipName = num + "_extras.zip";
         String zipPath = localImagePath + zipName;
-        //如果用户上传过模型,就打包上传到oss,直接返回
-        if(CommonStatus.YES.code().equals(sceneEditInfo.getIsUploadObj())
-                && new File(newData).exists()
-                && new File(newResultData).exists()){
-            //打包
-            ZipUtil.zip(newData, zipPath);
-            //上传压缩包
-            fYunFileService.uploadFile(bucket, zipPath, "downloads/extras/" + zipName);
-            String url = ossUrlPrefix + "downloads/extras/" + zipName + "?t=" + Calendar.getInstance().getTimeInMillis();
-            return ResultData.ok(url);
-        }
-
 
-        String buildType = scenePlusExt.getBuildType();
-        if("V3".equals(buildType)){
-            String dataViewPath = String.format(UploadFilePath.DATA_VIEW_PATH, num);
-            //V3版本去oss下载2048模型
-            String meshPath =  String.format(ConstantFilePath.DATABUFFER_FORMAT, num) + "mesh";
-            FileUtils.deleteDirectory(meshPath);
-            fYunFileService.downloadFileByCommand(bucket, meshPath, dataViewPath + "mesh");
-            log.info("meshPath="+meshPath);
-            if(!new File(meshPath).exists()){
-                throw new BusinessException(ErrorCode.FAILURE_CODE_7006);
-            }
-            log.info(new File(meshPath).listFiles().toString());
-            if(new File(meshPath).listFiles().length > 0){
-                for(File file : new File(meshPath).listFiles()){
-                    if(file.isDirectory()){
-                        for (File item : file.listFiles()) {
-                            if(item.getName().endsWith(".obj") && !"output.house.obj".equals(item.getName()) &&
-                                    !"mesh.obj".equals(item.getName())){
-                                item.delete();
-                            }
-                            if(item.getName().endsWith(".mtl") && !"output.house.mtl".equals(item.getName()) &&
-                                    !"mesh.mtl".equals(item.getName())){
-                                item.delete();
-                            }
-                        }
-                        continue;
-                    }
-                    if(file.getName().endsWith(".obj") && !"output.house.obj".equals(file.getName()) &&
-                            !"mesh.obj".equals(file.getName())){
-                        file.delete();
+        String dataViewPath = String.format(UploadFilePath.DATA_VIEW_PATH, num);
+        //V3版本去oss下载2048模型
+        String meshPath =  String.format(ConstantFilePath.DATABUFFER_FORMAT, num) + "mesh";
+        FileUtils.deleteDirectory(meshPath);
+        fYunFileService.downloadFileByCommand(bucket, meshPath, dataViewPath + "mesh");
+        log.info("meshPath="+meshPath);
+        if(!new File(meshPath).exists() || new File(meshPath).listFiles().length < 1){
+            throw new BusinessException(ErrorCode.FAILURE_CODE_7006);
+        }
+        for(File file : new File(meshPath).listFiles()){
+            if(file.isDirectory()){
+                for (File item : file.listFiles()) {
+                    if(item.getName().endsWith(".obj") && !"output.house.obj".equals(item.getName()) &&
+                            !"mesh.obj".equals(item.getName())){
+                        item.delete();
                     }
-                    if(file.getName().endsWith(".mtl") && !"output.house.mtl".equals(file.getName()) &&
-                            !"mesh.mtl".equals(file.getName())){
-                        file.delete();
+                    if(item.getName().endsWith(".mtl") && !"output.house.mtl".equals(item.getName()) &&
+                            !"mesh.mtl".equals(item.getName())){
+                        item.delete();
                     }
                 }
-                //打包
-                ZipUtil.zip(meshPath, zipPath);
-                //上传压缩包
-                fYunFileService.uploadFile(bucket, zipPath, "downloads/extras/" + zipName);
-                String url = ossUrlPrefix + "downloads/extras/" + zipName + "?t=" + Calendar.getInstance().getTimeInMillis();
-//                FileUtil.del(zipPath);
-                return ResultData.ok(url);
-            }
-        }
-
-        //V2版本在本地获取模型资源
-        //修改过的资源
-        String editData =  scenePlusExt.getDataSource() + "_edit/caches/tex";
-        String results = scenePlusExt.getDataSource() + "_edit/results";
-        if (new File(editData).exists() && new File(results).exists()){
-            for(File file : new File(editData).listFiles()){
-                if(file.getName().endsWith(".obj") && !"output.house.obj".equals(file.getName()) &&
-                        !"mesh.obj".equals(file.getName())){
-                    file.delete();
-                }
-                if(file.getName().endsWith(".mtl") && !"output.house.mtl".equals(file.getName()) &&
-                        !"mesh.mtl".equals(file.getName())){
-                    file.delete();
-                }
+                continue;
             }
-
-            ZipUtil.zip(editData, zipPath);
-            //上传压缩包
-            fYunFileService.uploadFile(bucket, zipPath, "downloads/extras/" + zipName);
-            String url = ossUrlPrefix + "downloads/extras/" + zipName + "?t=" + Calendar.getInstance().getTimeInMillis();
-            return ResultData.ok(url);
-        }
-
-        //没上传过返回源资源
-        String dataPath = scenePlusExt.getDataSource() + "/caches/tex";
-        File dataFile = new File(dataPath);
-        if(!dataFile.exists()){
-            throw new BusinessException(ErrorCode.FAILURE_CODE_3018);
-        }
-        for(File file : dataFile.listFiles()){
             if(file.getName().endsWith(".obj") && !"output.house.obj".equals(file.getName()) &&
                     !"mesh.obj".equals(file.getName())){
                 file.delete();
@@ -1177,11 +1117,12 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
                 file.delete();
             }
         }
-
-        ZipUtil.zip(dataPath, zipPath);
+        //打包
+        ZipUtil.zip(meshPath, zipPath);
         //上传压缩包
         fYunFileService.uploadFile(bucket, zipPath, "downloads/extras/" + zipName);
         String url = ossUrlPrefix + "downloads/extras/" + zipName + "?t=" + Calendar.getInstance().getTimeInMillis();
+        FileUtil.del(zipPath);
         return ResultData.ok(url);
     }
 }