Sfoglia il codice sorgente

Merge branch 'local-jm' of http://192.168.0.115:3000/lyhzzz/4dkankan-fusion into local-jm

cong82269021 7 mesi fa
parent
commit
011b76a6cd

+ 22 - 25
src/main/java/com/fdkankan/fusion/common/util/LocalToOssUtil.java

@@ -10,8 +10,11 @@ import org.springframework.stereotype.Component;
 
 import java.io.File;
 import java.nio.charset.Charset;
+import java.nio.file.Path;
+import java.nio.file.Paths;
 import java.util.List;
 import java.util.Map;
+import java.util.regex.Matcher;
 import java.util.stream.Collectors;
 
 @Component
@@ -23,11 +26,19 @@ public class LocalToOssUtil {
 
 
     private String getOssPath(String bucket, String filePath) {
+        Path p = Paths.get(filePath);
+        if(p.isAbsolute()){
+            return filePath;
+        }
         return CacheUtil.basePath.concat(bucket).concat(File.separator).concat(filePath);
 
     }
 
     public String getOssPath( String filePath) {
+        Path p = Paths.get(filePath);
+        if(p.isAbsolute()){
+            return filePath;
+        }
         return CacheUtil.basePath.concat(bucket).concat(File.separator).concat(filePath);
 
     }
@@ -37,8 +48,17 @@ public class LocalToOssUtil {
     }
 
 
-    public boolean downFormRel(String objectName, String localPath) {
+    public boolean downForm(String objectName, String localPath) {
         try {
+            String[] split = objectName.replaceAll("/", Matcher.quoteReplacement(File.separator)).split(Matcher.quoteReplacement(File.separator));
+            StringBuilder result = new StringBuilder();
+            for (int i = 1; i <split.length;i++){
+                result.append(split[i]);
+                if(i <split.length -1){
+                    result.append(File.separator);
+                }
+            }
+            objectName = result.toString();
             FileUtil.copyContent(new File(getOssPath(bucket, objectName)), new File(localPath), true);
         }catch (Exception e){
             log.info("下载文件失败,remoteFilePath:{},localPath:{}", objectName, localPath);
@@ -48,16 +68,6 @@ public class LocalToOssUtil {
         return true;
     }
 
-    public boolean downFormAbs(String objectName, String localPath) {
-        try {
-            FileUtil.copyContent(new File( objectName), new File(localPath), true);
-        }catch (Exception e){
-            log.info("下载文件失败,remoteFilePath:{},localPath:{}", objectName, localPath);
-            log.info("下载文件失败", e);
-            return false;
-        }
-        return true;
-    }
 
     public String uploadFile(String bucket, String filePath, String remoteFilePath, Map<String, String> headers) {
         try {
@@ -83,20 +93,6 @@ public class LocalToOssUtil {
 
     }
 
-    public void uploadFileOss(File file) {
-        if(file.isFile()){
-            String ossPath = file.getPath();
-            ossPath = ossPath.replace("/mnt/","");
-            ossPath =  ossPath.replace("\\","/");
-            this.uploadOss(file.getPath(),ossPath);
-        }else {
-            File[] files = file.listFiles();
-            for (File file1 : files) {
-                uploadFileOss(file1);
-            }
-        }
-
-    }
 
     public List<String> listKeysFromAli(String sourcePath) {
         return FileUtil.loopFiles(getOssPath(bucket, sourcePath)).stream()
@@ -141,4 +137,5 @@ public class LocalToOssUtil {
     public String getObjectContent(String s) {
         return FileUtil.readUtf8String(new File(getOssPath(s)));
     }
+
 }

+ 1 - 0
src/main/java/com/fdkankan/fusion/config/CacheUtil.java

@@ -8,6 +8,7 @@ public class CacheUtil {
     public static String uploadType;
 
     public static String basePath;
+    public static String mapping;
     public static String installPath;
 
 }

+ 2 - 7
src/main/java/com/fdkankan/fusion/down/CaseDownService.java

@@ -472,7 +472,7 @@ public class CaseDownService {
             if(res.contains(".json") || res.contains(".shp")){
                 res = new File(res).getParentFile().getPath();
             }
-            localToOssUtil.downFormAbs(res,path+queryPath+res);
+            localToOssUtil.downForm(res,path+queryPath+res);
 
         }
     }
@@ -489,13 +489,8 @@ public class CaseDownService {
         if(StringUtils.isBlank(url) ){
             return;
         }
-        url = url.replace(queryPath, "");
-        if( !localToOssUtil.existKey(url)){
-            log.info("downResource文件不存在:{},{}",caseId,url);
-            return;
-        }
         String path = offPath + FilePath.OFFLINE_OSS_PATH;
-        localToOssUtil.downFormAbs(url,path+queryPath+url);
+        localToOssUtil.downForm(url,path+queryPath+url);
     }
 
     public void downWordByTemplate(Integer caseId,XWPFTemplate template,String name,String offPath){

+ 3 - 1
src/main/java/com/fdkankan/fusion/mq/consumer/OsgbToB3dmConsumer.java

@@ -44,6 +44,8 @@ public class OsgbToB3dmConsumer {
     public void consumerQueue(String localPath)  {
         String sourcePath = null;
         try {
+
+            localPath = CacheUtil.basePath+ localPath;
             File file = new File(localPath);
             if(!file.exists()){
                 log.info("osgbToB3dm-mq--,msg:{},文件不存在",localPath);
@@ -67,7 +69,7 @@ public class OsgbToB3dmConsumer {
             }
             //String ossPath = sourcePath.replace(CacheUtil.basePath,"");
             //localToOssUtil.uploadOss(sourcePath,ossPath);
-            String url = ossUrlPrefix + dir+ File.separator +jsonFile.getName();
+            String url = CacheUtil.mapping + dir+ File.separator +jsonFile.getName();
             HashMap<String,String> resultMap = ReadXmlUtil.getLatMap(file);
             if(resultMap != null && !resultMap.isEmpty()){
                 commonUploadService.updateByPath(localPath,url,resultMap.get("wgs84"),resultMap.get("gcj02"));

+ 1 - 1
src/main/java/com/fdkankan/fusion/service/IPathService.java

@@ -13,5 +13,5 @@ import com.baomidou.mybatisplus.extension.service.IService;
  */
 public interface IPathService extends IService<Path> {
 
-    String getBasePath();
+    Path getBasePath();
 }

+ 1 - 0
src/main/java/com/fdkankan/fusion/service/ISceneService.java

@@ -13,4 +13,5 @@ import com.baomidou.mybatisplus.extension.service.IService;
  */
 public interface ISceneService extends IService<Scene> {
 
+    Scene getByNum(String num);
 }

+ 15 - 16
src/main/java/com/fdkankan/fusion/service/impl/CaseNumServiceImpl.java

@@ -8,10 +8,7 @@ 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.entity.CaseEntity;
-import com.fdkankan.fusion.entity.CaseNumEntity;
-import com.fdkankan.fusion.entity.FusionNum;
-import com.fdkankan.fusion.entity.Model;
+import com.fdkankan.fusion.entity.*;
 import com.fdkankan.fusion.exception.BusinessException;
 import com.fdkankan.fusion.httpClient.client.FdKKClient;
 import com.fdkankan.fusion.mapper.ICaseNumMapper;
@@ -64,6 +61,8 @@ public class CaseNumServiceImpl extends ServiceImpl<ICaseNumMapper, CaseNumEntit
     ICaseTagPointService caseTagPointService;
     @Autowired
     ThreadService threadService;
+    @Autowired
+    ISceneService sceneService;
 
     @Override
     public List<CaseNumEntity> getByCaseId(Integer caseId) {
@@ -119,29 +118,29 @@ public class CaseNumServiceImpl extends ServiceImpl<ICaseNumMapper, CaseNumEntit
                 model.setType(type);
                 model.setModelType("pointcloud");    //深时点云类型
                 model.setCreateStatus(1);
+                Scene scene = sceneService.getByNum(num);
                 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(localToOssUtil.existKey(mesh3DtilesPath)){
+                    String mesh3DtilesPath  =  String.format(FilePath.OBJ_OSS_PATH,num) + "/images/3dtiles/tileset.json";
+
+                    String sizePath = scene.getWebPath() + String.format(FilePath.OBJ_OSS_PATH,num) + "/images/3dtiles";
+                    if(localToOssUtil.existKey(scene.getWebPath() +mesh3DtilesPath)){
                         model.setModelDateType("b3dm");
                         model.setModelType("b3dm");
                         model.setModelGlbUrl(JSONArray.toJSONString(Arrays.asList(queryPath +mesh3DtilesPath)));
-                        model.setModelSize(FileWriterUtil.setFileSize(localToOssUtil.getSize( sizePath)));
+                        model.setModelSize(FileWriterUtil.setFileSize(localToOssUtil.getSizeCount( sizePath)));
                     }else {
-                        //model.setModelObjUrl(String.format(FilePath.OBJ_LOCAL_PATH,environment ,num) +"/mesh.obj");
-                        //model.setModelGlbUrl(getGlbUrl(param.getType(),num,model));
                         String meshPath = String.format(FilePath.OBJ_OSS_PATH, num)+"/data/mesh";
-                        if(localToOssUtil.existKey(meshPath +"/mesh.obj")){
-                            Long size = localToOssUtil.getSize(meshPath);
+                        if(localToOssUtil.existKey( scene.getWebPath() +meshPath +"/mesh.obj")){
+                            Long size = localToOssUtil.getSizeCount( scene.getWebPath() +meshPath);
                             model.setModelSize(FileWriterUtil.setFileSize(size));
                             model.setModelGlbUrl(JSONArray.toJSONString(Arrays.asList(queryPath + meshPath+"/mesh.obj")));
                         }else {
                             List<String> objPaths = new ArrayList<>();
-                            String meshPathjs = String.format(FilePath.OBJ_OSS_PATH, num)+"/data/";
+                            String meshPathjs =  String.format(FilePath.OBJ_OSS_PATH, num)+"/data/";
 
-                            String jsonPath = meshPath + "/floors.json";
+                            String jsonPath =scene.getWebPath() + meshPath + "/floors.json";
                             if(!localToOssUtil.existKey(jsonPath)){
-                               jsonPath = meshPath +"mesh.json";
+                               jsonPath =scene.getWebPath() + meshPath +"mesh.json";
                             }
                             if(localToOssUtil.existKey(jsonPath)){
                                 String objectContent = localToOssUtil.getObjectContent(meshPath + "/floors.json");
@@ -153,7 +152,7 @@ public class CaseNumServiceImpl extends ServiceImpl<ICaseNumMapper, CaseNumEntit
                                     objPaths.add(queryPath +meshPathjs + string);
                                 }
                                 model.setModelGlbUrl(JSONArray.toJSONString(objPaths));
-                                Long size = localToOssUtil.getSize(meshPath);
+                                Long size = localToOssUtil.getSize(scene.getWebPath() +meshPath);
                                 model.setModelSize(FileWriterUtil.setFileSize(size));
                             }
                         }

+ 1 - 1
src/main/java/com/fdkankan/fusion/service/impl/CaseVideoServiceImpl.java

@@ -123,7 +123,7 @@ public class CaseVideoServiceImpl extends ServiceImpl<ICaseVideoMapper, CaseVide
                     String mergeVideoUrl = null;
                     if (StringUtils.isNotBlank(videoFolder.getVideoMergeUrl())) {
                         mergeVideoUrl = videoFolder.getVideoMergeUrl().replace(queryPath, "/home/");
-                        localToOssUtil.downFormAbs(videoFolder.getVideoMergeUrl().replace(queryPath, ""), mergeVideoUrl);
+                        localToOssUtil.downForm(videoFolder.getVideoMergeUrl().replace(queryPath, ""), mergeVideoUrl);
                         ossDelList.add(videoFolder.getVideoMergeUrl());
                     }
                     caseVideoService.deleteByFolderId(videoFolder.getVideoFolderId());

+ 16 - 20
src/main/java/com/fdkankan/fusion/service/impl/CommonUploadServiceImpl.java

@@ -80,7 +80,7 @@ public class CommonUploadServiceImpl extends ServiceImpl<ICommonUploadMapper, Co
             }
             //localToOssUtil.uploadOss(tempFile.getPath(), ossPath);
             //String url = this.ossUrlPrefix + ossPath;
-            String url = tempFile.getPath();
+            String url = CacheUtil.mapping + ossPath;
 
             FileTypeEnum fileTypeEnum = FileTypeEnum.getByType(extName.replace(".", ""));
             if(fileTypeEnum == null){
@@ -134,14 +134,14 @@ public class CommonUploadServiceImpl extends ServiceImpl<ICommonUploadMapper, Co
         String resultFormat = modelFileFormat;
         switch (modelFileFormat){
             case "obj" :  resultFormat = "glb";
-                url = uploadObjOss(unZipFile.getPath(),modelFile);break;
-            case "laz" :    url = uploadLazOss(unZipFile.getPath(),modelFile); break;
-            case "shp" :   url = uploadOss(unZipFile.getPath(),modelFile); break;
-            case "b3dm" :  url = uploadB3dm(unZipFile.getPath(),modelFile); break;
+                url = uploadObjOss(ossZipPath,modelFile);break;
+            case "laz" :    url = uploadLazOss(ossZipPath,modelFile); break;
+            case "shp" :   url = uploadOss(ossZipPath,modelFile); break;
+            case "b3dm" :  url = uploadB3dm(ossZipPath,modelFile); break;
             case "las" :
-            case "ply" :  url = uploadLasOrPly(unZipFile.getPath(),modelFile);break;
+            case "ply" :  url = uploadLasOrPly(ossZipPath,modelFile);break;
             case "osgb":  resultFormat = "b3dm";
-                    uploadOsgb(unZipFile.getPath(),modelFile) ;break;
+                    uploadOsgb(ossZipPath,modelFile) ;break;
             default: break;
         }
         FileTypeEnum fileTypeEnum = FileTypeEnum.getByType(modelFileFormat);
@@ -149,6 +149,7 @@ public class CommonUploadServiceImpl extends ServiceImpl<ICommonUploadMapper, Co
             throw new BusinessException(ResultCode.FILE_TYPE_ERROR2);
         }
         Integer status = StringUtils.isNotBlank(url) ?1:-1;
+        url = StringUtils.isNotBlank(url) ?CacheUtil.mapping + url:null;
         CommonUpload commonUpload = commonUploadService.add(oldName,url, String.valueOf(getDirectorySize(unZipFile)),
                 null, fileTypeEnum, modelFileFormat,resultFormat,status,unZipFile.getPath(),dictId);
         return ResultData.ok(commonUpload);
@@ -158,16 +159,11 @@ public class CommonUploadServiceImpl extends ServiceImpl<ICommonUploadMapper, Co
         OBJToGLBUtil.checkObj(modelFile.getPath());
         String localGlbPath = modelFile.getPath().replace(".obj",".glb");
         OBJToGLBUtil.objToGlb2(modelFile.getPath(),localGlbPath);
-        //String ossPath = unzipPath.replace(OssPath.localPath,"");
-        //localToOssUtil.uploadOss(unzipPath,ossPath);
-//        if(!localToOssUtil.existKey(localGlbPath.replace(OssPath.localPath,""))){
-//            throw new BusinessException(ResultCode.UPLOAD_FILE_ERROR);
-//        }
         File file = new File(localGlbPath);
         if(!file.exists()){
             throw new BusinessException(ResultCode.UPLOAD_FILE_ERROR);
         }
-        return  ossUrlPrefix + unzipPath +File.separator+file.getName();
+        return  unzipPath +File.separator+file.getName();
     }
 
     private String uploadB3dm(String unzipPath, File modelFile) {
@@ -180,7 +176,7 @@ public class CommonUploadServiceImpl extends ServiceImpl<ICommonUploadMapper, Co
         if(!file.exists()){
             throw new BusinessException(ResultCode.UPLOAD_FILE_ERROR);
         }
-        return  ossUrlPrefix +unzipPath +File.separator +file.getName();
+        return unzipPath +File.separator +file.getName();
     }
 
     @Autowired
@@ -195,16 +191,16 @@ public class CommonUploadServiceImpl extends ServiceImpl<ICommonUploadMapper, Co
         if(!modelFile.exists()){
             throw new BusinessException(ResultCode.UPLOAD_FILE_ERROR);
         }
-       // return  ossUrlPrefix +unzipPath +File.separator +modelFile.getParentFile().getName();
-        return  modelFile.getParentFile().getPath();
+       return  unzipPath +File.separator +modelFile.getParentFile().getName();
+       // return  modelFile.getParentFile().getPath();
     }
 
     private String uploadOss(String unzipPath,File modelFile) {
         if(!modelFile.exists()){
             throw new BusinessException(ResultCode.UPLOAD_FILE_ERROR);
         }
-       // return  ossUrlPrefix + unzipPath+File.separator +modelFile.getName();
-        return  modelFile.getPath();
+        return unzipPath+File.separator +modelFile.getName();
+       // return  modelFile.getPath();
     }
 
     private String uploadLasOrPly(String unzipPath ,File modelFile) {
@@ -213,8 +209,8 @@ public class CommonUploadServiceImpl extends ServiceImpl<ICommonUploadMapper, Co
         if(!file.exists()){
             throw new BusinessException(ResultCode.UPLOAD_FILE_ERROR);
         }
-       // return  ossUrlPrefix +unzipPath+File.separator +mntFile.getName() + File.separator +"webcloud";
-        return  mntFile.getPath()+ File.separator +"webcloud";
+        return  unzipPath+File.separator +mntFile.getName() + File.separator +"webcloud";
+       // return  mntFile.getPath()+ File.separator +"webcloud";
 
     }
 

+ 2 - 2
src/main/java/com/fdkankan/fusion/service/impl/PathServiceImpl.java

@@ -21,7 +21,7 @@ import java.util.List;
 public class PathServiceImpl extends ServiceImpl<IPathMapper, Path> implements IPathService {
 
     @Override
-    public String getBasePath() {
+    public Path getBasePath() {
         LambdaQueryWrapper<Path> wrapper = new LambdaQueryWrapper<>();
         wrapper.eq(Path::getType,2);
         wrapper.eq(Path::getStatus,1);
@@ -29,7 +29,7 @@ public class PathServiceImpl extends ServiceImpl<IPathMapper, Path> implements I
 
         List<Path> list = this.list(wrapper);
         if(!list.isEmpty()){
-            return list.get(0).getDir();
+            return list.get(0);
         }
         return null;
     }

+ 13 - 0
src/main/java/com/fdkankan/fusion/service/impl/SceneServiceImpl.java

@@ -1,11 +1,14 @@
 package com.fdkankan.fusion.service.impl;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.fdkankan.fusion.entity.Scene;
 import com.fdkankan.fusion.mapper.ISceneMapper;
 import com.fdkankan.fusion.service.ISceneService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.springframework.stereotype.Service;
 
+import java.util.List;
+
 /**
  * <p>
  * 初始化信息表 服务实现类
@@ -17,4 +20,14 @@ import org.springframework.stereotype.Service;
 @Service
 public class SceneServiceImpl extends ServiceImpl<ISceneMapper, Scene> implements ISceneService {
 
+    @Override
+    public Scene getByNum(String num) {
+        LambdaQueryWrapper<Scene> wrapper = new LambdaQueryWrapper<>();
+        wrapper.eq(Scene::getSceneCode,num);
+        List<Scene> list = this.list(wrapper);
+        if(list == null || list.isEmpty()){
+            return null;
+        }
+        return list.get(0);
+    }
 }

+ 11 - 22
src/main/java/com/fdkankan/fusion/service/impl/UploadService.java

@@ -1,11 +1,13 @@
 package com.fdkankan.fusion.service.impl;
 
 import com.fdkankan.fusion.common.FilePath;
+import com.fdkankan.fusion.common.OssPath;
 import com.fdkankan.fusion.common.ResultCode;
 import com.fdkankan.fusion.common.util.LocalToOssUtil;
 import com.fdkankan.fusion.common.util.ShellUtil;
 import com.fdkankan.fusion.common.util.LocalToOssUtil;
 import com.fdkankan.fusion.common.util.VideoUtil;
+import com.fdkankan.fusion.config.CacheUtil;
 import com.fdkankan.fusion.exception.BusinessException;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
@@ -21,6 +23,7 @@ import java.io.IOException;
 import java.net.URLEncoder;
 import java.util.LinkedHashSet;
 import java.util.UUID;
+import java.util.regex.Matcher;
 
 @Service
 @Slf4j
@@ -62,10 +65,6 @@ public class UploadService {
             return localFile.getPath();
         }catch (Exception e){
            e.printStackTrace();
-        }finally {
-            if(localFile!=null){
-                localFile.deleteOnExit();   //退出删除,后续需要使用文件
-            }
         }
         return null;
     }
@@ -87,29 +86,19 @@ public class UploadService {
             //获取文件后缀名
             String suffixName = fileName.substring(fileName.lastIndexOf("."));
             //重新生成文件名
-            if(newName){
-                fileName = UUID.randomUUID().toString().replace("-","") ;
-            }else {
-                fileName= fileName.substring(0,fileName.lastIndexOf("."));
-            }
-            if(fileName.length() >50){
-                fileName =  fileName.substring(0,50);
+            String uuid  = UUID.randomUUID().toString().replace("-","") ;
+            String ossPath = String.format(OssPath.MANAGE_FILE_PATH, uuid + suffixName);
+
+            localFile = new File(OssPath.localPath + ossPath);
+            if(!localFile.getParentFile().exists()){
+                localFile.getParentFile().mkdirs();
             }
-            localFile = File.createTempFile(fileName + suffixName,suffixName);
             file.transferTo(localFile);
-            String path = localFile.getPath();
-            localToOssUtil.uploadOss(path,filePathAdd+ fileName + suffixName);
-            if(!localToOssUtil.existKey(filePathAdd + fileName + suffixName)){
-                throw new BusinessException(ResultCode.UPLOAD_ERROR.code,ResultCode.UPLOAD_ERROR.msg);
-            }
-            return queryPath +filePathAdd+ URLEncoder.encode(fileName,"utf-8") + suffixName;
+            //localToOssUtil.uploadOss(localFile.getPath(),ossPath);
+            return CacheUtil.mapping + ossPath;
         }catch (Exception e){
             log.info("upload-error:{}",e);
             throw new BusinessException(ResultCode.UPLOAD_ERROR.code,ResultCode.UPLOAD_ERROR.msg);
-        }finally {
-            if(localFile!=null){
-                localFile.delete();
-            }
         }
 
     }

+ 5 - 8
src/main/java/com/fdkankan/fusion/task/InitService.java

@@ -6,10 +6,7 @@ import com.alibaba.fastjson.JSONArray;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.fdkankan.fusion.common.util.LocalToOssUtil;
 import com.fdkankan.fusion.config.CacheUtil;
-import com.fdkankan.fusion.entity.CaseFiles;
-import com.fdkankan.fusion.entity.CommonUpload;
-import com.fdkankan.fusion.entity.HotIcon;
-import com.fdkankan.fusion.entity.Model;
+import com.fdkankan.fusion.entity.*;
 import com.fdkankan.fusion.service.*;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.io.FileUtils;
@@ -53,12 +50,12 @@ public class InitService {
     public void initConfig(){
         CacheUtil.uploadType = uploadType;
         CacheUtil.installPath = new File(installPath).getParentFile().getPath() +File.separator;
-        log.info(installPath);
-        log.info(CacheUtil.installPath);
-        String path = pathService.getBasePath();
+        Path path = pathService.getBasePath();
         if(path != null){
-            CacheUtil.basePath = path ;
+            CacheUtil.mapping = path.getMapping() + File.separator;
+            CacheUtil.basePath = path.getDir() ;
         }else {
+            CacheUtil.mapping = "profile" + File.separator;
             CacheUtil.basePath =  CacheUtil.installPath +"/4DKK_PROGRAM_STATIC/";
         }
     }