lyhzzz 4 月之前
父節點
當前提交
c28c169720

+ 5 - 2
src/main/java/com/fdkankan/fusion/config/FusionConfig.java

@@ -10,9 +10,12 @@ import org.springframework.context.annotation.Configuration;
 @Data
 public class FusionConfig {
 
-    @Value("${upload.type}")
+    @Value("${fyun.type}")
     private String uploadType;
 
-    @Value("${upload.query-path}")
+    @Value("${fyun.host}")
     private String ossUrlPrefix;
+
+    @Value("${fyun.bucket}")
+    private String bucket;
 }

+ 37 - 41
src/main/java/com/fdkankan/fusion/service/impl/CaseNumServiceImpl.java

@@ -2,11 +2,13 @@ package com.fdkankan.fusion.service.impl;
 
 import cn.hutool.core.io.FileUtil;
 import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
 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.ResultData;
 import com.fdkankan.fusion.common.util.*;
+import com.fdkankan.fusion.config.FusionConfig;
 import com.fdkankan.fusion.entity.CaseNumEntity;
 import com.fdkankan.fusion.entity.FusionNum;
 import com.fdkankan.fusion.entity.Model;
@@ -19,6 +21,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.fdkankan.fusion.websocket.SessionService;
 import com.fdkankan.fusion.websocket.enums.CommonEnum;
 import com.fdkankan.fusion.websocket.vo.WsMessage;
+import com.fdkankan.fyun.face.FYunFileServiceInterface;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -44,9 +47,9 @@ import java.util.stream.Collectors;
 public class CaseNumServiceImpl extends ServiceImpl<ICaseNumMapper, CaseNumEntity> implements ICaseNumService {
 
     @Autowired
-    UploadToOssUtil uploadToOssUtil;
-    @Value("${upload.query-path}")
-    private String queryPath;
+    FYunFileServiceInterface fYunFileServiceInterface;
+    @Autowired
+    FusionConfig fusionConfig;
     @Value("${spring.profiles.active}")
     private String environment;
     @Autowired
@@ -125,15 +128,40 @@ public class CaseNumServiceImpl extends ServiceImpl<ICaseNumMapper, CaseNumEntit
                 if(type == 0 || type == 1 || type == 4 || type == 6 || type == 7){           //看看,看见
                     String mesh3DtilesPath  = String.format(FilePath.OBJ_OSS_PATH,num) + "/images/3dtiles/tileset.json";
                     String sizePath = String.format(FilePath.OBJ_OSS_PATH,num) + "/images/3dtiles";
-                    if(uploadToOssUtil.existKey(mesh3DtilesPath)){
+                    if(fYunFileServiceInterface.fileExist(mesh3DtilesPath)){
                         model.setModelDateType("b3dm");
                         model.setModelType("b3dm");
-                        model.setModelGlbUrl(JSONArray.toJSONString(Arrays.asList(queryPath +mesh3DtilesPath)));
-                        model.setModelSize(FileWriterUtil.setFileSize(uploadToOssUtil.getSize( sizePath)));
+                        model.setModelGlbUrl(JSONArray.toJSONString(Arrays.asList(fusionConfig.getOssUrlPrefix() +mesh3DtilesPath)));
+                        model.setModelSize(FileWriterUtil.setFileSize(fYunFileServiceInterface.getSpace(fusionConfig.getBucket(), sizePath)));
                     }else {
-                        model.setModelObjUrl(String.format(FilePath.OBJ_LOCAL_PATH,environment ,num) +"/mesh.obj");
-                        model.setModelGlbUrl(getGlbUrl(type,num,model));
-                        model.setModelType("glb");
+                        String meshPath = String.format(FilePath.OBJ_OSS_PATH, num)+"/data/mesh";
+                        if(fYunFileServiceInterface.fileExist( meshPath +"/mesh.obj")){
+                            Long size = fYunFileServiceInterface.getSpace(fusionConfig.getBucket(), meshPath);
+                            model.setModelSize(FileWriterUtil.setFileSize(size));
+                            model.setModelGlbUrl(JSONArray.toJSONString(Arrays.asList(File.separator + meshPath+"/mesh.obj")));
+                        }else {
+                            List<String> objPaths = new ArrayList<>();
+                            String meshPathjs =  String.format(FilePath.OBJ_OSS_PATH, num)+"/data/";
+
+                            String jsonPath = meshPath + "/floors.json";
+                            if(!fYunFileServiceInterface.fileExist(jsonPath)){
+                               jsonPath = meshPath +"mesh.json";
+                            }
+                            if(fYunFileServiceInterface.fileExist(jsonPath)){
+                                String objectContent = fYunFileServiceInterface.getFileContent(meshPath + "/floors.json");
+                                JSONObject jsonObject = JSONObject.parseObject(objectContent);
+                                JSONArray floors1 = jsonObject.getJSONArray("floors");
+                                for (Object object : floors1) {
+                                    JSONObject jb = (JSONObject) object;
+                                    String string = jb.getString("objPath");
+                                    objPaths.add(File.separator +meshPathjs + string);
+                                }
+                                model.setModelGlbUrl(JSONArray.toJSONString(objPaths));
+                                Long size = fYunFileServiceInterface.getSpace(fusionConfig.getBucket(),meshPath);
+                                model.setModelSize(FileWriterUtil.setFileSize(size));
+                            }
+                        }
+                        model.setModelType("obj");
                     }
 
                 }
@@ -152,38 +180,6 @@ public class CaseNumServiceImpl extends ServiceImpl<ICaseNumMapper, CaseNumEntit
 
 
 
-    private String getGlbUrl(Integer type, String num,Model model) {
-        if(type == 0 || type == 1 || type == 4 || type == 6 || type == 7){ //看看,看见
-            String objPath = String.format(FilePath.OBJ_LOCAL_PATH ,environment,num);
-            ShellUtil.yunDownload(String.format(FilePath.OBJ_OSS_PATH, num)+"/data/mesh" ,objPath);
-            List<String> localGlbPaths = new ArrayList<>();
-            List<String> ossGlbPaths = new ArrayList<>();
-            File localFile = new File(objPath);
-            this.toGlB(localFile,localGlbPaths);
-            Long modelSize = 0L;
-            if(localGlbPaths.size() >0){
-                for (String localGlbPath : localGlbPaths) {
-                    String ossGlbPath = localGlbPath.replace(FilePath.LOCAL_BASE_PATH,"fusion/");
-                    uploadToOssUtil.uploadOss(localGlbPath,ossGlbPath);
-                    if(ossGlbPath.contains("lod_")){
-                        if(ossGlbPath.contains("lod_0")){
-                            ossGlbPaths.add(queryPath  +ossGlbPath);
-                            modelSize +=  uploadToOssUtil.getSize(ossGlbPath);
-                        }
-                        continue;
-                    }
-                    modelSize +=  uploadToOssUtil.getSize(ossGlbPath);
-                    ossGlbPaths.add(queryPath +ossGlbPath);
-                }
-                model.setModelSize(FileWriterUtil.setFileSize(modelSize));
-                FileUtil.del(objPath);
-                return JSONArray.toJSONString(ossGlbPaths);
-            }
-            FileUtil.del(objPath);
-        }
-        return null;
-    }
-
     private void toGlB(File localFile, List<String> localGlbPath) {
         File[] files = localFile.listFiles();
         for (File file : files) {