Przeglądaj źródła

计算完成时间

lyhzzz 5 miesięcy temu
rodzic
commit
a4fcbb1bcd

+ 11 - 28
src/main/java/com/fdkankan/fusion/common/util/LocalToOssUtil.java

@@ -14,6 +14,7 @@ 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
@@ -45,13 +46,19 @@ public class LocalToOssUtil {
     public boolean existKey(String objectName) {
         return FileUtil.exist(getOssPath(bucket, objectName));
     }
-    public boolean existKeyAbs(String objectName) {
-        return FileUtil.exist( objectName);
-    }
 
 
-    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);
@@ -61,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 {
@@ -96,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()

+ 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

@@ -475,7 +475,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);
 
         }
     }
@@ -492,13 +492,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();
 }

+ 9 - 11
src/main/java/com/fdkankan/fusion/service/impl/CaseNumServiceImpl.java

@@ -120,29 +120,27 @@ public class CaseNumServiceImpl extends ServiceImpl<ICaseNumMapper, CaseNumEntit
                 model.setCreateStatus(1);
                 Scene scene = sceneService.getByNum(num);
                 if(type == 0 || type == 1 || type == 4 || type == 6 || type == 7){           //看看,看见
-                    String mesh3DtilesPath  = scene.getWebPath() + String.format(FilePath.OBJ_OSS_PATH,num) + "/images/3dtiles/tileset.json";
+                    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.existKeyAbs(mesh3DtilesPath)){
+                    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.getSizeCount( sizePath)));
                     }else {
-                        //model.setModelObjUrl(String.format(FilePath.OBJ_LOCAL_PATH,environment ,num) +"/mesh.obj");
-                        //model.setModelGlbUrl(getGlbUrl(param.getType(),num,model));
-                        String meshPath = scene.getWebPath() + String.format(FilePath.OBJ_OSS_PATH, num)+"/data/mesh";
-                        if(localToOssUtil.existKeyAbs(meshPath +"/mesh.obj")){
-                            Long size = localToOssUtil.getSizeCount(meshPath);
+                        String meshPath = String.format(FilePath.OBJ_OSS_PATH, num)+"/data/mesh";
+                        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 = scene.getWebPath() + 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");
@@ -154,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;
     }

+ 4 - 5
src/main/java/com/fdkankan/fusion/service/impl/UploadService.java

@@ -7,6 +7,7 @@ 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;
@@ -22,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
@@ -63,10 +65,6 @@ public class UploadService {
             return localFile.getPath();
         }catch (Exception e){
            e.printStackTrace();
-        }finally {
-            if(localFile!=null){
-                localFile.deleteOnExit();   //退出删除,后续需要使用文件
-            }
         }
         return null;
     }
@@ -96,7 +94,8 @@ public class UploadService {
                 localFile.getParentFile().mkdirs();
             }
             file.transferTo(localFile);
-            return localFile.getPath();
+            //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);

+ 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/";
         }
     }