Browse Source

本地dataSouce文件删除,获取oss中资源

lyhzzz 2 years ago
parent
commit
ea501f42f0

+ 0 - 1
src/main/java/com/fdkankan/fusion/common/FilePath.java

@@ -15,7 +15,6 @@ public class FilePath {
    // public final static String VIDEO_LOCAL_PATH = "D:\\video\\merge";
    public final static String VIDEO_LOCAL_PATH = LOCAL_BASE_PATH + "%s/video/merge";
    public final static String OBJ_LOCAL_PATH = LOCAL_BASE_PATH + "%s/model/%s";
-   public final static String GLB_LOCAL_PATH = LOCAL_BASE_PATH + "%s/model/%s";
 
 
 }

+ 2 - 2
src/main/java/com/fdkankan/fusion/common/util/OBJToGLBUtil.java

@@ -13,17 +13,17 @@ import java.util.LinkedHashSet;
 @Slf4j
 public class OBJToGLBUtil {
 
-    public static void objToGlb(String objPath, String glbPath)  {
+    public static String objToGlb(String objPath, String glbPath)  {
         log.info("obj转换glb开始,{}",objPath);
         if(!checkObj(objPath)){
             throw new BusinessException(-1,"obj文件错误");
         }
-        objPath += "/mesh.obj";
         log.info("obj转换glb开始");
         String command = "obj2gltf -i " + objPath + " -o " + glbPath;
         log.info("执行obj转换glb命令路径-{}", command);
         ShellUtil.execCmd(command);
         log.info("obj转换glb完毕:" + command);
+        return glbPath;
     }
     public static void objToGlb2(String objPath,String glbPath)  {
         log.info("obj转换glb开始,{}",objPath);

+ 13 - 0
src/main/java/com/fdkankan/fusion/common/util/ShellCmd.java

@@ -0,0 +1,13 @@
+package com.fdkankan.fusion.common.util;
+
+public class ShellCmd {
+
+	/**
+	 * oss文件上传命令 bash /opt/ossutil/fyun-upload.sh {bucket} {srcPath} {destPath} {fyunType} {opType}
+	 * opType: file or folder
+	 * fyunType : oss ,aws
+	 */
+	public static final String FYUN_UPLOAD = "sudo bash /opt/ossutil/fyun-upload.sh %s %s /%s %s %s";
+	public static final String FYUN_DOWN = "sudo bash /opt/ossutil/fyun-download.sh %s /%s %s %s %s";
+
+}

+ 20 - 0
src/main/java/com/fdkankan/fusion/common/util/ShellUtil.java

@@ -151,4 +151,24 @@ public class ShellUtil {
         json.put("pointAttributes", pointAttributes);
         return json;
     }
+
+
+    /**
+     * oss文件上传命令 bash /opt/ossutil/fyun-upload.sh {bucket} {srcPath} {destPath} {fyunType} {opType}
+     * opType: file or folder
+     *  //@param bucket     桶名
+     * @param srcPath    源文件路径
+     * @param destPath   目标文件路径
+     *  //@param fyunType   oss or aws
+     */
+    public static void yunUpload(String srcPath,String destPath){
+        String opType = srcPath.contains(".")? "file":"folder" ;
+        String cmd = String.format(ShellCmd.FYUN_UPLOAD, "4dkankan",srcPath,destPath,"oss",opType);
+        execCmd(cmd);
+    }
+    public static void yunDownload(String srcPath,String destPath){
+        String opType = srcPath.contains(".")? "file":"folder" ;
+        String cmd = String.format(ShellCmd.FYUN_DOWN,"4dkankan",srcPath,destPath,"oss",opType);
+        execCmd(cmd);
+    }
 }

+ 35 - 53
src/main/java/com/fdkankan/fusion/service/impl/CaseNumServiceImpl.java

@@ -1,13 +1,11 @@
 package com.fdkankan.fusion.service.impl;
 
 import cn.hutool.core.io.FileUtil;
+import com.alibaba.fastjson.JSONArray;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.fdkankan.fusion.common.FilePath;
 import com.fdkankan.fusion.common.ResultCode;
-import com.fdkankan.fusion.common.util.FileWriterUtil;
-import com.fdkankan.fusion.common.util.JwtUtil;
-import com.fdkankan.fusion.common.util.OBJToGLBUtil;
-import com.fdkankan.fusion.common.util.UploadToOssUtil;
+import com.fdkankan.fusion.common.util.*;
 import com.fdkankan.fusion.entity.CaseNumEntity;
 import com.fdkankan.fusion.entity.Model;
 import com.fdkankan.fusion.exception.BusinessException;
@@ -99,15 +97,11 @@ public class CaseNumServiceImpl extends ServiceImpl<ICaseNumMapper, CaseNumEntit
                 model.setModelDateType("obj");
                 model.setType(param.getType());
                 model.setModelType("pointcloud");    //深时点云类型
-                if(param.getType() == 0 || param.getType() == 1){           //看看,看见
+                if(param.getType() == 0 || param.getType() == 1 || param.getType() == 4){           //看看,看见
                     model.setModelObjUrl(String.format(FilePath.OBJ_LOCAL_PATH,environment ,num) +"/mesh.obj");
                     model.setModelGlbUrl(getGlbUrl(param.getType(),num,model));
                     model.setModelType("glb");
                 }
-                if(param.getType() == 4){   //深时obj场景
-                    getGlbSsObj(model,num);
-                    model.setModelType("glb");
-                }
                 model.setNum(num);
                 model.setCreateStatus(1);
                 modelList.add(model);
@@ -122,63 +116,51 @@ public class CaseNumServiceImpl extends ServiceImpl<ICaseNumMapper, CaseNumEntit
         }
     }
 
-    private void getGlbSsObj(Model model, String num) {
-        String dataSource = fdKKClient.querySceneDataSource(num);
-        if(StringUtils.isBlank(dataSource)){
-            throw new BusinessException(ResultCode.SCENE_DATA_SOURCE_EMPTY.code,num +ResultCode.SCENE_DATA_SOURCE_EMPTY.msg);
-        }
-        String meshPath = dataSource +"_laserData/laserData/mesh";
-        File meshFile = new File(meshPath);
-        if(!meshFile.exists()){
-            throw new BusinessException(ResultCode.SCENE_DATA_SOURCE_EMPTY.code,num +ResultCode.SCENE_DATA_SOURCE_EMPTY.msg);
-        }
-
-        String objPath = String.format(FilePath.OBJ_LOCAL_PATH ,environment,num);
-        String glbPath = String.format(FilePath.GLB_LOCAL_PATH,environment,num) +"/mesh.glb";
-        String glbOssPath = String.format(FilePath.GLB_OSS_PATH ,environment, num);
-
-        FileUtil.copy(meshPath,objPath,true);
-        OBJToGLBUtil.objToGlb(objPath +"/mesh",glbPath );
-        File file = new File(glbPath);
-        model.setModelSize(FileWriterUtil.setFileSize(file.length()));
-        uploadToOssUtil.uploadOss(glbPath,glbOssPath);
-        FileUtil.del(objPath);
-        String ossglbPath = queryPath +glbOssPath;
-        model.setModelObjUrl(objPath +"/mesh");
-        model.setModelGlbUrl(ossglbPath);
-    }
 
 
     private String getGlbUrl(Integer type, String num,Model model) {
-        if(type == 0 || type == 1){ //看看,看见
+        if(type == 0 || type == 1 || type == 4){ //看看,看见
             String objPath = String.format(FilePath.OBJ_LOCAL_PATH ,environment,num);
-            String glbPath = String.format(FilePath.GLB_LOCAL_PATH,environment,num) +"/mesh.glb";
-            String glbOssPath = String.format(FilePath.GLB_OSS_PATH ,environment, num);
 //            if(uploadToOssUtil.existKey(glbOssPath)){
 //                return queryPath + "/"+glbOssPath;
 //            }
-            List<String> fileList = uploadToOssUtil.listKeysFromAli(String.format(FilePath.OBJ_OSS_PATH, num));
-            for (String fileName : fileList) {
-                File file = new File(objPath);
-                if(!file.exists()){
-                    file.mkdirs();
+            ShellUtil.yunDownload(String.format(FilePath.OBJ_OSS_PATH, num) ,objPath);
+            List<String> localGlbPaths = new ArrayList<>();
+            List<String> ossGlbPaths = new ArrayList<>();
+            File localFile = new File(objPath);
+            this.toGlB(localFile,localGlbPaths);
+
+            if(localGlbPaths.size() >0){
+                for (String localGlbPath : localGlbPaths) {
+                    File file = new File(localGlbPath);
+                    if(file!=null){
+                        model.setModelSize(FileWriterUtil.setFileSize(file.length()));
+                    }
+                    String ossGlbPath = localGlbPath.replace(FilePath.LOCAL_BASE_PATH,"fusion/");
+                    uploadToOssUtil.uploadOss(localGlbPath,ossGlbPath);
+                    ossGlbPaths.add(queryPath + "/"+ossGlbPath);
                 }
-                String[] split = fileName.split("/");
-                String localPath = objPath +"/"+split[split.length-1];
-                uploadToOssUtil.downFormAli(fileName,localPath);
+                return JSONArray.toJSONString(ossGlbPaths);
             }
-            OBJToGLBUtil.objToGlb(objPath,glbPath );
-            File file = new File(glbPath);
-            if(file!=null){
-                model.setModelSize(FileWriterUtil.setFileSize(file.length()));
-            }
-            uploadToOssUtil.uploadOss(glbPath,glbOssPath);
-            FileUtil.del(objPath);
-            return queryPath + "/"+glbOssPath;
+
+            //FileUtil.del(objPath);
         }
         return null;
     }
 
+    private void toGlB(File localFile, List<String> localGlbPath) {
+        File[] files = localFile.listFiles();
+        for (File file : files) {
+            if(file.isDirectory()){
+                toGlB(file,localGlbPath);
+            }
+            if(file.getName().contains(".obj")){
+               String glbPath =  OBJToGLBUtil.objToGlb(file.getPath(),file.getPath().replace(".obj",".glb") );
+               localGlbPath.add(glbPath);
+            }
+        }
+    }
+
     private List<String> updateByNumList(Integer caseId, List<SceneNumParam> sceneNumParam) {
         List<String> addList = new ArrayList<>();
         for (SceneNumParam param : sceneNumParam) {