Jelajahi Sumber

v4.5.0 批量上传下载全景图异步操作

dengsixing 2 tahun lalu
induk
melakukan
2891f8a8bc

+ 6 - 0
src/main/java/com/fdkankan/scene/entity/SceneAsynOperLog.java

@@ -77,6 +77,12 @@ public class SceneAsynOperLog implements Serializable {
     private Integer pop;
 
     /**
+     * 扩展信息
+     */
+    @TableField("ext_data")
+    private String extData;
+
+    /**
      * 创建时间
      */
     @TableField("create_time")

+ 57 - 168
src/main/java/com/fdkankan/scene/service/impl/SceneEditInfoServiceImpl.java

@@ -944,15 +944,8 @@ public class SceneEditInfoServiceImpl extends ServiceImpl<ISceneEditInfoMapper,
             throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
         }
 
-        //查询是否存在等待中的异步操作记录,如果存在,直接反馈
-        List<SceneAsynOperLog> waittingLogList = sceneAsynOperLogService.list(
-            new LambdaQueryWrapper<SceneAsynOperLog>()
-                .eq(SceneAsynOperLog::getModule, SceneAsynModuleType.UPLOAD_DOWNLOAD.code())
-                .eq(SceneAsynOperLog::getFunction, SceneAsynFuncType.PANORAMIC_IMAGE.code())
-                .eq(SceneAsynOperLog::getState, CommonOperStatus.WAITING.code()));
-        if(CollUtil.isNotEmpty(waittingLogList)){
-            return ResultData.error(ErrorCode.FAILURE_CODE_5066);
-        }
+        //查询是否存在等待中的异步操作记录,如果存在,抛出业务异常,终止操作
+        this.checkSceneAsynOper(null, SceneAsynModuleType.UPLOAD_DOWNLOAD.code() , SceneAsynFuncType.PANORAMIC_IMAGE.code());
 
         //清除异步下载记录,防止再次下载的时候请求到旧的压缩包
         sceneAsynOperLogService.remove(
@@ -1055,7 +1048,7 @@ public class SceneEditInfoServiceImpl extends ServiceImpl<ISceneEditInfoMapper,
                     return filePath.substring(filePath.lastIndexOf(File.separator) + 1);
                 }).collect(Collectors.toList());
             }
-            return ResultData.ok(new UploadPanoramaVO(0, notExistFileList));
+            return ResultData.ok(new UploadPanoramaVO(0,0, notExistFileList));
         }
 
         //上传
@@ -1107,169 +1100,69 @@ public class SceneEditInfoServiceImpl extends ServiceImpl<ISceneEditInfoMapper,
         }
         fYunFileService.downloadFile(ConstantFilePath.OSS_PREFIX + path.replace(ConstantFilePath.BUILD_MODEL_PATH, "") + "/data.fdage", target + File.separator + "capture/data.fdage");
 
+        //如果部分成功,则需要返回成功数量和失败列表
+        if(CollUtil.isNotEmpty(notExistFileList)){
+            notExistFileList = notExistFileList.stream().map(filePath -> {
+                return filePath.substring(filePath.lastIndexOf(File.separator) + 1);
+            }).collect(Collectors.toList());
+        }
+
+        UploadPanoramaVO uploadPanoramaVO = new UploadPanoramaVO();
+        uploadPanoramaVO.setAsyn(async);
         if(async == CommonStatus.YES.code().intValue()){
+            List<String> finalUploadFileList = uploadFileList;
+            List<String> finalNotExistFileList = notExistFileList;
             CompletableFuture.runAsync(() -> {
-                CreateObjUtil.build3dModel(target , "1");
-
-                String uploadJsonPath= target + File.separator + "results" +File.separator+"upload.json";
-                Thread.sleep(2000);
-                boolean exist = ComputerUtil.checkComputeCompleted(uploadJsonPath, maxCheckTimes, waitTime);
-                if(!exist){
-                    throw new BusinessException(ErrorCode.FAILURE_CODE_7013);
-                }
-                String uploadData = FileUtils.readFile(uploadJsonPath);
-                JSONObject uploadJson = null;
-                JSONArray array = null;
-                if(uploadData!=null) {
-                    uploadJson = JSONObject.parseObject(uploadData);
-                    array = uploadJson.getJSONArray("upload");
-                }
-                if(array == null){
-                    throw new BusinessException(ErrorCode.FAILURE_CODE_7013);
-                }
-                JSONObject fileJson = null;
-                String fileName = "";
-                for(int i = 0, len = array.size(); i < len; i++) {
-                    fileJson = array.getJSONObject(i);
-                    fileName = fileJson.getString("file");
-                    //文件不存在抛出异常
-                    if (!new File(target + File.separator + "results" + File.separator + fileName)
-                        .exists()) {
-                        throw new Exception(
-                            target + File.separator + "results" + File.separator + fileName + "文件不存在");
-                    }
-
-                    //high文件夹
-                    if (fileJson.getIntValue("clazz") == 3) {
-                        map.put(target + File.separator + "results" + File.separator + fileName,
-                            imgViewPath + "pan/high/" + fileName.replace("high/", ""));
-                        continue;
-                    }
-                    //low文件夹
-                    if (fileJson.getIntValue("clazz") == 4) {
-                        map.put(target + File.separator + "results" + File.separator + fileName,
-                            imgViewPath + "pan/low/" + fileName.replace("low/", ""));
-                        continue;
-                    }
-
-                    //tiles文件夹,亚马逊没有裁剪图片api,不需要上传4k图
-                    if (fileJson.getIntValue("clazz") == 5) {
-                        map.put(target + File.separator + "results" + File.separator + fileName,
-                            imgViewPath + fileName);
-                        continue;
-                    }
-
-                    //tiles文件夹,亚马逊瓦片图
-                    if (fileJson.getIntValue("clazz") == 7) {
-                        map.put(target + File.separator + "results" + File.separator + fileName,
-                            imgViewPath + fileName);
-                        continue;
-                    }
+                SceneAsynOperLog sceneAsynOperLog = new SceneAsynOperLog();
+                sceneAsynOperLog.setNum(num);
+                sceneAsynOperLog.setOperType(SceneAsynOperType.UPLOAD.code());
+                sceneAsynOperLog.setModule(SceneAsynModuleType.UPLOAD_DOWNLOAD.code());
+                sceneAsynOperLog.setFunction(SceneAsynFuncType.PANORAMIC_IMAGE.code());
+                if(CollUtil.isNotEmpty(finalNotExistFileList)){
+                    Map<String, Object> extData = new HashMap<>();
+                    extData.put("successCnt", finalUploadFileList.size());
+                    extData.put("failList", finalNotExistFileList);
+                    sceneAsynOperLog.setExtData(JSON.toJSONString(extData));
                 }
-                if(map.size()>0) {
-                    fYunFileService.uploadMulFiles(bucket, map);
+                sceneAsynOperLogService.save(sceneAsynOperLog);
+                try {
+                    this.uploadPanoramaHandler(num,bucket,target,imgViewPath, finalUploadFileList,targetImagesPath);
+                } catch (Exception e) {
+                    log.error("上传全景图报错,num:" + num, e);
+                    sceneAsynOperLog.setState(CommonOperStatus.FAILD.code());
+                    sceneAsynOperLogService.updateById(sceneAsynOperLog);
                 }
-
-                //拷贝修改后的全景图到缓存目录
-                String cachedImagesPath = String.format(ConstantFilePath.SCENE_CACHE_IMAGES, num);
-                uploadFileList.stream().forEach(srcPath->{
-                    cn.hutool.core.io.FileUtil.copy(srcPath, srcPath.replace(targetImagesPath, cachedImagesPath), true);
-                });
-
-                //更新数据库版本号
-                SceneEditInfo sceneEditInfo = this.getByScenePlusId(scenePlus.getId());
-                this.upgradeVersionAndImgVersionById(sceneEditInfo.getId());
-                //更新scenejson缓存和oss文件版本号
-                upgradeSceneJsonVersion(num, sceneEditInfo.getVersion() + 1, sceneEditInfo.getImgVersion() + 1, bucket);
             });
-
+        }else{
+            this.uploadPanoramaHandler(num,bucket,target,imgViewPath,uploadFileList,targetImagesPath);
+            if(CollUtil.isNotEmpty(notExistFileList)){
+                uploadPanoramaVO.setSuccessCnt(uploadFileList.size());
+                uploadPanoramaVO.setFailList(notExistFileList);
+            }
         }
+        return ResultData.ok(uploadPanoramaVO);
+    }
 
-        CreateObjUtil.build3dModel(target , "1");
-
-        String uploadJsonPath= target + File.separator + "results" +File.separator+"upload.json";
-        Thread.sleep(2000);
-        boolean exist = ComputerUtil.checkComputeCompleted(uploadJsonPath, maxCheckTimes, waitTime);
-        if(!exist){
-            throw new BusinessException(ErrorCode.FAILURE_CODE_7013);
+    private void checkSceneAsynOper(String operType, String module, String function){
+        LambdaQueryWrapper<SceneAsynOperLog> queryWrapper =
+            new LambdaQueryWrapper<SceneAsynOperLog>()
+                .eq(SceneAsynOperLog::getState, CommonOperStatus.WAITING.code());
+        if(StrUtil.isNotEmpty(operType)){
+            queryWrapper.eq(SceneAsynOperLog::getOperType, operType);
         }
-        String uploadData = FileUtils.readFile(uploadJsonPath);
-        JSONObject uploadJson = null;
-        JSONArray array = null;
-        if(uploadData!=null) {
-            uploadJson = JSONObject.parseObject(uploadData);
-            array = uploadJson.getJSONArray("upload");
+        if(StrUtil.isNotEmpty(module)){
+            queryWrapper.eq(SceneAsynOperLog::getModule, module);
         }
-        if(array == null){
-            throw new BusinessException(ErrorCode.FAILURE_CODE_7013);
+        if(StrUtil.isNotEmpty(function)){
+            queryWrapper.eq(SceneAsynOperLog::getFunction, function);
         }
-        JSONObject fileJson = null;
-        String fileName = "";
-        for(int i = 0, len = array.size(); i < len; i++) {
-            fileJson = array.getJSONObject(i);
-            fileName = fileJson.getString("file");
-            //文件不存在抛出异常
-            if (!new File(target + File.separator + "results" + File.separator + fileName)
-                .exists()) {
-                throw new Exception(
-                    target + File.separator + "results" + File.separator + fileName + "文件不存在");
-            }
-
-            //high文件夹
-            if (fileJson.getIntValue("clazz") == 3) {
-                map.put(target + File.separator + "results" + File.separator + fileName,
-                    imgViewPath + "pan/high/" + fileName.replace("high/", ""));
-                continue;
-            }
-            //low文件夹
-            if (fileJson.getIntValue("clazz") == 4) {
-                map.put(target + File.separator + "results" + File.separator + fileName,
-                    imgViewPath + "pan/low/" + fileName.replace("low/", ""));
-                continue;
-            }
-
-            //tiles文件夹,亚马逊没有裁剪图片api,不需要上传4k图
-            if (fileJson.getIntValue("clazz") == 5) {
-                map.put(target + File.separator + "results" + File.separator + fileName,
-                    imgViewPath + fileName);
-                continue;
-            }
-
-            //tiles文件夹,亚马逊瓦片图
-            if (fileJson.getIntValue("clazz") == 7) {
-                map.put(target + File.separator + "results" + File.separator + fileName,
-                    imgViewPath + fileName);
-                continue;
-            }
-        }
-        if(map.size()>0) {
-            fYunFileService.uploadMulFiles(bucket, map);
-        }
-
-        //拷贝修改后的全景图到缓存目录
-        String cachedImagesPath = String.format(ConstantFilePath.SCENE_CACHE_IMAGES, num);
-        uploadFileList.stream().forEach(srcPath->{
-            cn.hutool.core.io.FileUtil.copy(srcPath, srcPath.replace(targetImagesPath, cachedImagesPath), true);
-        });
-
-        //更新数据库版本号
-        SceneEditInfo sceneEditInfo = this.getByScenePlusId(scenePlus.getId());
-        this.upgradeVersionAndImgVersionById(sceneEditInfo.getId());
-        //更新scenejson缓存和oss文件版本号
-        this.upgradeSceneJsonVersion(num, sceneEditInfo.getVersion() + 1, sceneEditInfo.getImgVersion() + 1, bucket);
-
-        //如果部分成功,则需要返回成功数量和失败列表
-        if(CollUtil.isNotEmpty(notExistFileList)){
-            notExistFileList = notExistFileList.stream().map(filePath -> {
-                return filePath.substring(filePath.lastIndexOf(File.separator) + 1);
-            }).collect(Collectors.toList());
-            return ResultData.ok(new UploadPanoramaVO(uploadFileList.size(), notExistFileList));
+        List<SceneAsynOperLog> waittingLogList = sceneAsynOperLogService.list(queryWrapper);
+        if(CollUtil.isNotEmpty(waittingLogList)){
+            throw new BusinessException(ErrorCode.FAILURE_CODE_5066);
         }
-
-        return ResultData.ok();
     }
 
-    public ResultData uploadPanoramaHandler(String num, String bucket, String target, String imgViewPath, List<String> uploadFileList, String targetImagesPath, List<String> notExistFileList) throws Exception {
+    public void uploadPanoramaHandler(String num, String bucket, String target, String imgViewPath, List<String> uploadFileList, String targetImagesPath) throws Exception {
         CreateObjUtil.build3dModel(target , "1");
 
         String uploadJsonPath= target + File.separator + "results" +File.separator+"upload.json";
@@ -1344,14 +1237,6 @@ public class SceneEditInfoServiceImpl extends ServiceImpl<ISceneEditInfoMapper,
         this.upgradeVersionAndImgVersionById(sceneEditInfo.getId());
         //更新scenejson缓存和oss文件版本号
         this.upgradeSceneJsonVersion(num, sceneEditInfo.getVersion() + 1, sceneEditInfo.getImgVersion() + 1, bucket);
-
-        //如果部分成功,则需要返回成功数量和失败列表
-        if(CollUtil.isNotEmpty(notExistFileList)){
-            notExistFileList = notExistFileList.stream().map(filePath -> {
-                return filePath.substring(filePath.lastIndexOf(File.separator) + 1);
-            }).collect(Collectors.toList());
-            return ResultData.ok(new UploadPanoramaVO(uploadFileList.size(), notExistFileList));
-        }
     }
 
 
@@ -1366,6 +1251,10 @@ public class SceneEditInfoServiceImpl extends ServiceImpl<ISceneEditInfoMapper,
         if(Objects.isNull(scenePlus)){
             throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
         }
+
+        //查询是否存在等待中的异步操作记录,如果存在,抛出业务异常,终止操作
+        this.checkSceneAsynOper(null, SceneAsynModuleType.UPLOAD_DOWNLOAD.code() , SceneAsynFuncType.PANORAMIC_IMAGE.code());
+
         ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
         String bucket = scenePlusExt.getYunFileBucket();
         String path = scenePlusExt.getDataSource();

+ 2 - 0
src/main/java/com/fdkankan/scene/vo/UploadPanoramaVO.java

@@ -20,6 +20,8 @@ import lombok.NoArgsConstructor;
 @AllArgsConstructor
 public class UploadPanoramaVO {
 
+    private int asyn;
+
     private Integer successCnt;
 
     private List<String> failList;