Преглед изворни кода

v1.13.4 上传三维模型 增加上传原始文件到oss

dengsixing пре 6 месеци
родитељ
комит
9916d3bc7f
1 измењених фајлова са 43 додато и 26 уклоњено
  1. 43 26
      src/main/java/com/fdkankan/scene/service/impl/BoxModelServiceImpl.java

+ 43 - 26
src/main/java/com/fdkankan/scene/service/impl/BoxModelServiceImpl.java

@@ -43,6 +43,8 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.web.multipart.MultipartFile;
 
+import javax.annotation.Resource;
+
 /**
  * <p>
  * TODO
@@ -55,7 +57,7 @@ import org.springframework.web.multipart.MultipartFile;
 @Service
 public class BoxModelServiceImpl implements IBoxModelService {
 
-    @Autowired
+    @Resource
     private FYunFileServiceInterface fYunFileService;
     @Autowired
     private IScenePlusService scenePlusService;
@@ -82,36 +84,51 @@ public class BoxModelServiceImpl implements IBoxModelService {
             throw new BusinessException(ErrorCode.FAILURE_CODE_7023, "5M");
         }
         String path = String.format(ConstantFilePath.SCENE_USER_PATH_V4, num) + "boxModel/" + sid + "/";
-        String zipPath = path + file.getOriginalFilename();
-        String srcPath = path + "data/";
-        String glbPath = path + sid + ".glb";
-
-        FileUtil.del(path);
-        FileUtil.mkParentDirs(zipPath);
-        file.transferTo(new File(zipPath));
-
-        //解压
-        ZipUtil.unzip(zipPath,srcPath);
-
-        //校验是否包含目录,如果包含目录提示错误
-        File srcFile = new File(srcPath);
-        Arrays.stream(srcFile.listFiles()).forEach(subFile->{
-            if(subFile.isDirectory()){
-                throw new BusinessException(ErrorCode.FAILURE_CODE_5065);
+        try {
+            String zipPath = path + file.getOriginalFilename();
+            String srcPath = path + "data/";
+            String glbPath = path + sid + ".glb";
+
+            FileUtil.del(path);
+            FileUtil.mkParentDirs(zipPath);
+            file.transferTo(new File(zipPath));
+
+            //解压
+            ZipUtil.unzip(zipPath,srcPath);
+
+            //校验是否包含目录,如果包含目录提示错误
+            File srcFile = new File(srcPath);
+            Arrays.stream(srcFile.listFiles()).forEach(subFile->{
+                if(subFile.isDirectory()){
+                    throw new BusinessException(ErrorCode.FAILURE_CODE_5065);
+                }
+            });
+
+            //转glb
+            OBJToGLBUtil.objToGlb(srcPath, glbPath);
+
+            if(!ComputerUtil.checkComputeCompleted(glbPath, 3, 2000)){
+                throw new BusinessException(ErrorCode.FAILURE_CODE_7013);
             }
-        });
 
-        //转glb
-        OBJToGLBUtil.objToGlb(srcPath, glbPath);
+            //上传glb
+            fYunFileService.uploadFile(bucket, glbPath, String.format(UploadFilePath.USER_EDIT_PATH, num) + "boxModels/" + sid + ".glb");
 
-        if(!ComputerUtil.checkComputeCompleted(glbPath, 3, 2000)){
-            throw new BusinessException(ErrorCode.FAILURE_CODE_7013);
-        }
+            //上传原始obj相关文件
+            List<File> files = FileUtil.loopFiles(srcPath);
+            files.stream().forEach(v->{
+                String ossKey = String.format(UploadFilePath.USER_EDIT_PATH, num) + "boxModels/" + sid + "/" + v.getAbsolutePath().replace(srcPath, "");
+                fYunFileService.uploadFile(v.getAbsolutePath(), ossKey);
+            });
 
-        //上传glb
-        fYunFileService.uploadFile(bucket, glbPath, String.format(UploadFilePath.USER_EDIT_PATH, num) + "boxModels/" + sid + ".glb");
+            return ResultData.ok(sid + ".glb");
 
-        return ResultData.ok(sid + ".glb");
+        }catch (Exception e){
+            log.error("上传三维模型失败", e);
+            throw e;
+        }finally {
+            FileUtil.del(path);
+        }
     }
 
     public static void main(String[] args) {