lyhzzz 3 年之前
父節點
當前提交
6bc59fcfed

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

@@ -8,6 +8,5 @@ public class FilePath {
     public final static String OBJ_OSS_PATH = "scene_view_data/%s/data/mesh";
     public final static String GLB_OSS_PATH = "fusion/model/glb";
 
-    public final static  String OBJ_PATH = "/home/fusion/model/obj";
-    public final static String GLB_PATH = "/home/fusion/model/glb";
+
 }

+ 18 - 4
src/main/java/com/fdkankan/fusion/service/impl/CaseNumServiceImpl.java

@@ -10,8 +10,10 @@ import com.fdkankan.fusion.service.ICaseNumService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.fdkankan.fyun.oss.UploadToOssUtil;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 
+import java.io.File;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -30,6 +32,10 @@ public class CaseNumServiceImpl extends ServiceImpl<ICaseNumMapper, CaseNumEntit
 
     @Autowired
     UploadToOssUtil uploadToOssUtil;
+    @Value("${local.obj_path}")
+    private String OBJ_PATH;
+    @Value("${local.glb_path}")
+    private String GLB_PATH;
 
     @Override
     public List<CaseNumEntity> getByCaseId(Integer caseId) {
@@ -65,12 +71,20 @@ public class CaseNumServiceImpl extends ServiceImpl<ICaseNumMapper, CaseNumEntit
 
     private String getGlbUrl(Integer type, String num) {
         if(type == 0 || type == 1){ //看看,看见
-            String objPath = FilePath.OBJ_PATH+"/"+num;
-            String glbPath = FilePath.GLB_PATH+"/"+num;
+            String objPath = String.format(OBJ_PATH ,num);
+            String glbPath = String.format(GLB_PATH,num);
             String glbOssPath = FilePath.GLB_OSS_PATH +"/" + num;
-            uploadToOssUtil.downFormAli(String.format(FilePath.OBJ_OSS_PATH,num),objPath);
+            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();
+                }
+                String[] split = fileName.split("/");
+                uploadToOssUtil.downFormAli(fileName,objPath +"/"+split[split.length-1]);
+            }
 
-            OBJToGLBUtil.objToGlb(FilePath.OBJ_PATH+"/"+num,glbPath);
+            OBJToGLBUtil.objToGlb(objPath,glbPath);
             uploadToOssUtil.upload(glbPath,glbOssPath);
             return glbOssPath;
         }

+ 16 - 9
src/main/java/com/fdkankan/fusion/service/impl/ModelServiceImpl.java

@@ -28,6 +28,7 @@ import com.fdkankan.fyun.oss.UploadToOssUtil;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.tools.zip.ZipFile;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import org.springframework.web.multipart.MultipartFile;
 
@@ -48,9 +49,13 @@ public class ModelServiceImpl extends ServiceImpl<IModelMapper, Model> implement
     ICaseNumService caseNumService;
     @Autowired
     IFusionNumService fusionNumService;
+    @Value("${local.obj_path}")
+    private String OBJ_PATH;
+    @Value("${local.glb_path}")
+    private String GLB_PATH;
 
     @Override
-    public void uploadObj(MultipartFile file, String username)  {
+    public void uploadObj(MultipartFile file, String username) throws Exception {
         if(file.isEmpty()){
             throw new BusinessException(ResultCode.UPLOAD_FILE_NO_EXIST);
         }
@@ -63,7 +68,7 @@ public class ModelServiceImpl extends ServiceImpl<IModelMapper, Model> implement
         if(StringUtils.isEmpty(fileName)){
             throw new BusinessException(ResultCode.UPLOAD_FILE_NO_EXIST);
         }
-        if(fileName.toLowerCase().contains("zip") || fileName.toLowerCase().contains("rar")){
+        if(!fileName.toLowerCase().contains("zip") && !fileName.toLowerCase().contains("rar")){
             throw new BusinessException(ResultCode.UPLOAD_FILE_TYPE_ERROR);
         }
         //获取文件后缀名
@@ -75,10 +80,9 @@ public class ModelServiceImpl extends ServiceImpl<IModelMapper, Model> implement
         model.setModelSize(file.getSize());
         model.setUserName(username);
         this.save(model);
-        Integer createStatus = -1;
         try {
-            String objPath = FilePath.OBJ_PATH +"/" + model.getModelId();
-            String glbPath = FilePath.GLB_PATH +"/" + model.getModelId();
+            String objPath = String.format(OBJ_PATH , "modelId_"+model.getModelId());
+            String glbPath = String.format(GLB_PATH , "modelId_"+model.getModelId());
             String glbOssPath = FilePath.GLB_OSS_PATH +"/" + model.getModelId();
             model.setModelObjUrl(objPath);
             model.setModelGlbUrl(glbPath);
@@ -97,13 +101,16 @@ public class ModelServiceImpl extends ServiceImpl<IModelMapper, Model> implement
 
             OBJToGLBUtil.objToGlb(objPath,glbPath);
             uploadToOssUtil.upload(glbPath,glbOssPath);
-            createStatus = 1;   //上传成功
+
+            model.setCreateStatus(1);  //上传成功
+            this.updateById(model);
         }catch (Exception e){
-            e.printStackTrace();
-        }finally {
-            model.setCreateStatus(createStatus);
+            model.setCreateStatus(-1);
             this.updateById(model);
+            e.printStackTrace();
+            throw e;
         }
+
     }
 
     @Override

+ 4 - 0
src/main/resources/application-dev.yaml

@@ -23,3 +23,7 @@ spring:
   data:
     mongodb:
       uri: mongodb://4dage:1234@120.25.146.52:27017/laser
+
+local:
+  obj_path: /home/fusion/model/%s/obj
+  glb_path: /home/fusion/model/%s/glb

+ 3 - 1
src/main/resources/application-local.yaml

@@ -23,4 +23,6 @@ spring:
     mongodb:
       uri: mongodb://4dage:1234@120.25.146.52:27017/laser
 
-
+local:
+  obj_path: D:\fusion\model\%s\obj
+  glb_path: D:\fusion\model\%s\glb

+ 4 - 0
src/main/resources/application.yaml

@@ -1,6 +1,10 @@
 spring:
   profiles:
     active: ${activeProfile:local}
+  servlet:
+    multipart:
+      max-file-size: 1000MB
+      maxRequestSize: 1000MB
 
 server:
   port: 8808