lyhzzz 7 月之前
父節點
當前提交
458da66893

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

@@ -142,19 +142,17 @@ public class OBJToGLBUtil {
         return imgName;
     }
 
-    public static File lasOrPlyToBin(File srcFile)  {
-        if(!srcFile.exists()){
-            srcFile.mkdirs();
-        }
+    public static String lasOrPlyToBin(File srcFile)  {
+        String outPath = srcFile.getParentFile().getPath() +"/result";
         String cmd = ShellUtil.LAS_TO_BIN;
         cmd =  cmd.replace("@inPath",srcFile.getPath());
-        cmd = cmd.replace("@outPath",srcFile.getParentFile().getPath());
+        cmd = cmd.replace("@outPath",outPath);
         ShellUtil.execCmd(cmd);
         log.info("lasOrPlyToBin---------cmd-over");
-        String cloudJs = srcFile.getParentFile().getPath() +"/webcloud/"+ "cloud.js";
+        String cloudJs = outPath +"/webcloud/"+ "cloud.js";
         JSONObject jsonObject = ShellUtil.fixCloud(cloudJs);
-        FileWriterUtil.writerJson(srcFile.getParentFile().getPath() +"/webcloud/","cloud.js",jsonObject.toJSONString());
-        return srcFile.getParentFile();
+        FileWriterUtil.writerJson(outPath +"/webcloud/","cloud.js",jsonObject.toJSONString());
+        return outPath;
     }
 
     public static String OsgbToB3dm(File objPathFile) {
@@ -171,4 +169,11 @@ public class OBJToGLBUtil {
         ShellUtil.execCmd(cmd);
         return sourcePath;
     }
+    public static String OsgbToB3dm(String  targetPath,String sourcePath) {
+        String cmd = ShellCmd.osgbTob3dmCmd.replaceAll("@path",FilePath.MNT_BASE_PATH);
+        cmd =cmd.replaceAll("@inputFile",targetPath);
+        cmd =cmd.replaceAll("@outputFile",sourcePath);
+        ShellUtil.execCmd(cmd);
+        return sourcePath;
+    }
 }

+ 2 - 0
src/main/java/com/fdkankan/fusion/service/IModelService.java

@@ -51,4 +51,6 @@ public interface IModelService extends IService<Model> {
     void copyModel(Model modelEntity,UploadChunk uploadChunk);
 
     Model getByUploadSuccess(String fileMd5);
+
+    Model getByUPloadId(Integer id);
 }

+ 15 - 14
src/main/java/com/fdkankan/fusion/service/impl/ModelServiceImpl.java

@@ -148,7 +148,7 @@ public class ModelServiceImpl extends ServiceImpl<IModelMapper, Model> implement
         HashMap<String, TmDepartment> mapByDept = tmDepartmentService.getMapByDeptIds(deptIdset);
         for (ModelVo model : page.getRecords()) {
             if(model.getModelId() == null){
-                model.setCreateStatus(0);
+                model.setCreateStatus(-1);
                 model.setModelTitle(model.getUploadTitle());
             }
             if( model.getModelId() != null && StringUtils.isEmpty(model.getNum()) ) {
@@ -296,17 +296,10 @@ public class ModelServiceImpl extends ServiceImpl<IModelMapper, Model> implement
 
     @Override
     public void cancelUpload(Integer modelId) {
-        String redisKey = RedisKeyUtil.modelCancelUpload+modelId;
-        if(redisUtil.hasKey(redisKey)){
-            return;
-        }
-        Model model = this.getById(modelId);
-        if(model == null){
-            return;
-        }
-        model.setCreateStatus(-2);
-        this.updateById(model);
-        redisUtil.set(redisKey,"-2");
+        LambdaUpdateWrapper<Model> wrapper = new LambdaUpdateWrapper<>();
+        wrapper.eq(Model::getModelId,modelId);
+        wrapper.set(Model::getCreateStatus,-2);
+        this.update(wrapper);
     }
 
     @Override
@@ -363,6 +356,14 @@ public class ModelServiceImpl extends ServiceImpl<IModelMapper, Model> implement
         return list.get(0);
     }
 
-
-
+    @Override
+    public Model getByUPloadId(Integer id) {
+        LambdaQueryWrapper<Model> wrapper = new LambdaQueryWrapper<>();
+        wrapper.eq(Model::getUploadId,id);
+        List<Model> list = this.list(wrapper);
+        if(list.isEmpty()){
+            return null;
+        }
+        return list.get(0);
+    }
 }

+ 3 - 3
src/main/java/com/fdkankan/fusion/service/impl/ThreadService.java

@@ -116,10 +116,10 @@ public class ThreadService {
             }
 
             if("las".equals(model.getModelType()) || "ply".equals(model.getModelType()) ){
-                mntFile =  OBJToGLBUtil.lasOrPlyToBin(file1);
-                String ossPath = mntFile.getPath().replace("/mnt/","");
+                String outPath =  OBJToGLBUtil.lasOrPlyToBin(file1);
+                String ossPath = outPath.replace("/mnt/","");
                 redisUtil.set(RedisKeyUtil.modelUpload+model.getModelId(),"65");
-                ShellUtil.yunUpload(mntFile.getPath(),ossPath);
+                ShellUtil.yunUpload(outPath,ossPath);
 
                 model.setModelGlbUrl(JSONArray.toJSONString(Arrays.asList(queryPath  +ossPath +"/webcloud")));
                 if(!uploadToOssUtil.existKey(ossPath+"/webcloud/cloud.js")){

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

@@ -71,6 +71,8 @@ public class UploadChunkServiceImpl extends ServiceImpl<IUploadChunkMapper, Uplo
     @Autowired
     FdService fdService;
     @Autowired
+    IModelService modelService;
+    @Autowired
     ThreadService2 threadService2;
     @Override
     public void uploadSuccess(UploadChunk uploadChunk) {
@@ -84,9 +86,32 @@ public class UploadChunkServiceImpl extends ServiceImpl<IUploadChunkMapper, Uplo
             case 4:
             case 5:
             case 6:
-                threadService2.toModel(uploadChunk);
+                this.toModel(uploadChunk);
+                return;
+        }
+    }
+
+    public void toModel(UploadChunk uploadChunk) {
+
+        Model model = modelService.getByUPloadId(uploadChunk.getId());
+        if(model == null){
+            model = modelService.getByUploadSuccess(uploadChunk.getFileMd5());
+            if(model != null){
+                modelService.copyModel(model,uploadChunk);
                 return;
+            }
+            model = new Model();
         }
+        model.setModelTitle(uploadChunk.getTitle());
+        model.setModelSize(FileWriterUtil.setFileSize(uploadChunk.getFileSize()));
+        model.setType(3);
+        model.setUserName(uploadChunk.getUserName());
+        model.setDeptId(uploadChunk.getDeptId());
+        model.setCreateStatus(0);
+        model.setUploadId(uploadChunk.getId());
+        model.setFileMd5(uploadChunk.getFileMd5());
+        modelService.saveOrUpdate(model);
+        threadService2.asyn(uploadChunk,model);
     }
 
 

+ 86 - 66
src/main/java/com/fdkankan/fusion/task/ThreadService2.java

@@ -1,27 +1,24 @@
 package com.fdkankan.fusion.task;
 
 import cn.hutool.core.io.FileUtil;
+import com.alibaba.fastjson.JSONArray;
 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.OBJToGLBUtil;
-import com.fdkankan.fusion.common.util.ShellUtil;
-import com.fdkankan.fusion.common.util.UploadToOssUtil;
+import com.fdkankan.fusion.common.util.*;
 import com.fdkankan.fusion.entity.Model;
 import com.fdkankan.fusion.entity.UploadChunk;
 import com.fdkankan.fusion.exception.BusinessException;
 import com.fdkankan.fusion.service.IModelService;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.FactoryBean;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
 
 import java.io.File;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
+import java.util.*;
 
 @Service
 @Slf4j
@@ -34,66 +31,77 @@ public class ThreadService2 {
 
 
     @Async
-    public void toModel(UploadChunk uploadChunk) {
-        Model model = modelService.getByUploadSuccess(uploadChunk.getFileMd5());
-        if(model != null){
-            modelService.copyModel(model,uploadChunk);
+    public void asyn(UploadChunk uploadChunk,Model model){
+        if(checkModelCancelStatus(model.getModelId())){
             return;
         }
-        model = new Model();
-        model.setModelTitle(uploadChunk.getTitle());
-        model.setModelSize(FileWriterUtil.setFileSize(uploadChunk.getFileSize()));
-        model.setType(3);
-        model.setUserName(uploadChunk.getUserName());
-        model.setDeptId(uploadChunk.getDeptId());
         model.setCreateStatus(-1);
-        model.setUploadId(uploadChunk.getId());
-        model.setFileMd5(uploadChunk.getFileMd5());
-
-        String zipPath = FilePath.MNT_BASE_PATH+"model/"+ uploadChunk.getFilePath();
-        String unZipPath = FilePath.MNT_BASE_PATH+"model/"+ uploadChunk.getFileMd5();
-        ShellUtil.yunDownloadChunk(uploadChunk.getFilePath(),zipPath);
-        ShellUtil.unZip(zipPath,unZipPath);
-
-        File unZipFile = new File(unZipPath);
-        File modelFile = checkUnzip(unZipFile);
-        if(modelFile != null){
-            String modelFileFormat = modelFile.getName().split("\\.")[1].toLowerCase();
-            String url = null;
-            String resultFormat = modelFileFormat;
-            switch (modelFileFormat){
-                case "obj" :
-                    resultFormat = "glb";
-                    url = uploadObjOss(unZipPath,modelFile);break;
-                case "laz" :
-                    url = uploadLaz(unZipPath,modelFile); break;
-                case "shp" :
-                    url = uploadOss(unZipPath,modelFile); break;
-                case "b3dm" :
-                    url = uploadB3dm(unZipPath,modelFile); break;
-                case "las" :
-                case "ply" :
-                    url = uploadLasOrPly(unZipPath,modelFile);break;
-//                case "osgb":
-//                    resultFormat = "b3dm";
-//                    uploadOsgb(unZipPath,modelFile) ;break;
-                default:
-                    break;
+        try {
+            String zipPath = FilePath.MNT_BASE_PATH+"model/"+model.getModelId()+"/"+ UUID.randomUUID().toString().replace("-","")+".zip";
+            String unZipPath = FilePath.MNT_BASE_PATH+"model/"+model.getModelId()+"/"+ UUID.randomUUID().toString().replace("-","");
+            ShellUtil.yunDownloadChunk(uploadChunk.getFilePath(),zipPath);
+            if(checkModelCancelStatus(model.getModelId())){
+                FileUtil.del(zipPath);
+                return;
             }
-            model.setModelDateType(modelFileFormat);
-            model.setModelType(resultFormat);
-            if(StringUtils.isNotBlank(url)){
-                model.setCreateStatus(1);
-                model.setModelGlbUrl(url);
-                ShellUtil.yunUpload(zipPath,zipPath.replace(FilePath.localPath,""));
-                model.setFileNewName(ossUrlPrefix + zipPath.replace(FilePath.localPath,""));
+            ShellUtil.unZip(zipPath,unZipPath);
+            if(checkModelCancelStatus(model.getModelId())){
+                FileUtil.del(zipPath);
+                FileUtil.del(unZipPath);
+                return;
+            }
+            File unZipFile = new File(unZipPath);
+            File modelFile = checkUnzip(unZipFile);
+            if(modelFile != null){
+                String modelFileFormat = modelFile.getName().split("\\.")[1].toLowerCase();
+                String url = null;
+                String resultFormat = modelFileFormat;
+                switch (modelFileFormat){
+                    case "obj" :
+                        resultFormat = "glb";
+                        url = uploadObjOss(unZipPath,modelFile);break;
+                    case "laz" :
+                        url = uploadLaz(unZipPath,modelFile); break;
+                    case "shp" :
+                        url = uploadOss(unZipPath,modelFile); break;
+                    case "b3dm" :
+                        url = uploadB3dm(unZipPath,modelFile); break;
+                    case "las" :
+                    case "ply" :
+                        url = uploadLasOrPly(unZipPath,modelFile);break;
+                    case "osgb":
+                        resultFormat = "b3dm";
+                        url = uploadOsgb(unZipPath) ;break;
+                    default:
+                        break;
+                }
+                model.setModelDateType(modelFileFormat);
+                model.setModelType(resultFormat);
+                if(StringUtils.isNotBlank(url)){
+                    model.setCreateStatus(1);
+                    model.setModelGlbUrl(url);
+                    ShellUtil.yunUpload(zipPath,zipPath.replace(FilePath.localPath,""));
+                    model.setFileNewName(ossUrlPrefix + zipPath.replace(FilePath.localPath,""));
+                }
             }
-        }
 
-        modelService.save(model);
+            FileUtil.del(zipPath);
+            FileUtil.del(unZipFile);
+        }catch (Exception e){
+            log.info("转换失败:{}",e);
+        }
+        if(checkModelCancelStatus(model.getModelId())){
+            model.setCreateStatus(-2);
+        }
+        modelService.updateById(model);
+    }
 
-        FileUtil.del(zipPath);
-        FileUtil.del(unZipFile);
+    public Boolean checkModelCancelStatus(Integer modelId){
+        Model model1 = modelService.getById(modelId);
+        if(model1.getCreateStatus() == -2){ //已取消
+            return true;
+        }
+        return false;
     }
 
 
@@ -156,14 +164,26 @@ public class ThreadService2 {
         if(!uploadToOssUtil.existKey(ossPath)){
             return null;
         }
+        FileUtil.del(unzipPath);
         return ossUrlPrefix +  ossPath;
     }
 
 
-    private void uploadOsgb(String unzipPath, File modelFile) {
+    private String uploadOsgb(String unzipPath) {
         //容器不支持转化,通知fusion容器执行
-        HashMap<String,String > map = new HashMap<>();
-        map.put("path",unzipPath);
+        File file = new File(unzipPath);
+        String sourcePath = file.getParentFile().getPath() +"/"+ UUID.randomUUID().toString().replace("-","");
+        OBJToGLBUtil.OsgbToB3dm(unzipPath,sourcePath);
+        String b3dmJsonPath =  FileWriterUtil.checkB3dmTileset(new File(sourcePath));
+        if(b3dmJsonPath == null){
+            log.info("osgbToB3dm-msg:{},转化失败tileset.json文件",unzipPath);
+            return null;
+        }
+        String ossPath = sourcePath.replace("/mnt/","");
+        ShellUtil.yunUpload(sourcePath,ossPath);
+        FileUtil.del(unzipPath);
+        FileUtil.del(sourcePath);
+        return ossUrlPrefix + b3dmJsonPath.replace("/mnt/","");
     }
 
 
@@ -180,9 +200,9 @@ public class ThreadService2 {
     }
 
     private String uploadLasOrPly(String unzipPath ,File modelFile) {
-        File mntFile = OBJToGLBUtil.lasOrPlyToBin(modelFile);
-        String ossPath = mntFile.getPath().replace(FilePath.localPath,"");
-        ShellUtil.yunUpload(mntFile.getPath(),ossPath);
+        String outPath = OBJToGLBUtil.lasOrPlyToBin(modelFile);
+        String ossPath = outPath.replace(FilePath.localPath,"");
+        ShellUtil.yunUpload(outPath,ossPath);
         if(!uploadToOssUtil.existKey(ossPath+"/webcloud/cloud.js")){
             return null;
         }