Kaynağa Gözat

上传调试

lyhzzz 2 yıl önce
ebeveyn
işleme
f827550be0

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

@@ -131,7 +131,7 @@ public class OBJToGLBUtil {
         String dockerPath = FilePath.MNT_BASE_PATH +"b3dm";
         String cmd = ShellCmd.osgbTob3dmCmd.replaceAll("@path",dockerPath);
         cmd =cmd.replaceAll("@inputFile",objPathFile.getPath());
-        cmd =cmd.replaceAll("@outputFile",dockerPath + objPathFile.getName());
+        cmd =cmd.replaceAll("@outputFile",dockerPath +"/"+ objPathFile.getName());
         ShellUtil.execCmd(cmd);
         return dockerPath + objPathFile.getName();
     }

+ 45 - 55
src/main/java/com/fdkankan/fusion/service/impl/ModelServiceImpl.java

@@ -122,57 +122,50 @@ public class ModelServiceImpl extends ServiceImpl<IModelMapper, Model> implement
         ExecutorService executor = ThreadUtil.newSingleExecutor();
         try {
             CompletableFuture.runAsync(() -> {
-                String fileName = UUID.randomUUID().toString().replace("-","") +".zip";
-                File newObjFile = null;
-                File objPathFile = null;
-                String objPath = String.format(FilePath.OBJ_LOCAL_PATH,environment , "modelId_"+model.getModelId()) ;
-                log.info("uploadObj--ThreadStart-fileName:{},modeId:{}",fileName,model.getModelId());
-
-                newObjFile = new File(objPath +"/" + fileName);
-                if(!newObjFile.getParentFile().exists()){
-                    newObjFile.mkdirs();
-                }
                 try {
+                    String fileName = UUID.randomUUID().toString().replace("-","") +".zip";
+                    File newObjFile = null;
+                    File objPathFile = null;
+                    String objPath = String.format(FilePath.OBJ_LOCAL_PATH,environment , "modelId_"+model.getModelId()) ;
+                    log.info("uploadObj--ThreadStart-fileName:{},modeId:{}",fileName,model.getModelId());
+
+                    newObjFile = new File(objPath +"/" + fileName);
+                    if(!newObjFile.getParentFile().exists()){
+                        newObjFile.mkdirs();
+                    }
                     file.transferTo(newObjFile);
-                } catch (IOException e) {
-                    e.printStackTrace();
-                }
-                if(fileName.toLowerCase().endsWith(".zip")){
-                    ShellUtil.unZip(newObjFile.getPath(),objPath);
-                }
-                objPathFile = new File(objPath );
-                if(!objPathFile.isDirectory()){
-                    setCreateStatus(model,-1);
-                    return;
-                }
-                List<File> fileList = new ArrayList<>();
-                FileWriterUtil.getCanRunList(fileList,objPathFile);
+                    if(fileName.toLowerCase().endsWith(".zip")){
+                        ShellUtil.unZip(newObjFile.getPath(),objPath);
+                    }
+                    objPathFile = new File(objPath );
+                    if(!objPathFile.isDirectory()){
+                        throw new BusinessException(-1,"解压错误");
+                    }
+                    List<File> fileList = new ArrayList<>();
+                    FileWriterUtil.getCanRunList(fileList,objPathFile);
 
-                if(fileList.size() <=0){
-                    setCreateStatus(model,-1);
-                    return;
-                }
+                    if(fileList.size() <=0){
+                        throw new BusinessException(-1,"可上传文件不存在");
+                    }
 
-                File file1 = fileList.get(0);
-                if(file1 == null){
-                    setCreateStatus(model,-1);
-                    return;
-                }
-                if(com.fdkankan.fusion.common.util.StringUtils.isChinese(file1.getName())){
-                    setCreateStatus(model,-1);
-                    return;
-                }
+                    File file1 = fileList.get(0);
+                    if(file1 == null){
+                        throw new BusinessException(-1,"可上传文件不存在");
+                    }
+                    if(com.fdkankan.fusion.common.util.StringUtils.isChinese(file1.getName())){
+                        throw new BusinessException(-1,"压缩包中文");
+                    }
 
-                if(file1.getName().endsWith(".b3dm")  ){
-                    if(!FileWriterUtil.checkB3dmTileset(objPathFile)){
-                        setCreateStatus(model,-1);
-                        return;
+                    if(file1.getName().endsWith(".b3dm")  ){
+                        if(!FileWriterUtil.checkB3dmTileset(objPathFile)){
+                            throw new BusinessException(-1,"缺少tileset.json文件");
+
+                        }
                     }
-                }
-                redisUtil.set(RedisKeyUtil.modelUpload+model.getModelId(),"20");
+                    redisUtil.set(RedisKeyUtil.modelUpload+model.getModelId(),"20");
+
+                    File mntFile = null;
 
-                File mntFile = null;
-                try {
                     String glbOssPath = String.format(FilePath.GLB_OSS_PATH,environment, model.getModelId());
 
                     String name = file1.getName();
@@ -184,9 +177,7 @@ public class ModelServiceImpl extends ServiceImpl<IModelMapper, Model> implement
                         redisUtil.set(RedisKeyUtil.modelUpload+model.getModelId(),"65");
                         uploadToOssUtil.uploadOss(file1.getPath().replace(".obj",".glb"),glbOssPath);
                         if(!uploadToOssUtil.existKey(glbOssPath)){
-                            setCreateStatus(model,-1);
-                            redisUtil.set(RedisKeyUtil.modelUpload+model.getModelId(),"-1");
-                            return;
+                            throw new BusinessException(-1,"缺少.glb文件");
                         }
                     }
                     if(name.contains(".ply")){
@@ -203,9 +194,7 @@ public class ModelServiceImpl extends ServiceImpl<IModelMapper, Model> implement
                         redisUtil.set(RedisKeyUtil.modelUpload+model.getModelId(),"65");
                         uploadToOssUtil.uploadFileOss(mntFile );
                         if(!uploadToOssUtil.existKey(glbOssPath+"/cloud.js")){
-                            setCreateStatus(model,-1);
-                            redisUtil.set(RedisKeyUtil.modelUpload+model.getModelId(),"-1");
-                            return;
+                            throw new BusinessException(-1,"缺少cloud.js文件");
                         }
                     }
                     model.setModelGlbUrl(JSONArray.toJSONString(Arrays.asList(queryPath + glbOssPath)));
@@ -218,7 +207,7 @@ public class ModelServiceImpl extends ServiceImpl<IModelMapper, Model> implement
                         String localPath = OBJToGLBUtil.OsgbToB3dm(objPathFile);
 
                         if(!FileWriterUtil.checkB3dmTileset(new File(localPath))){
-                            throw new BusinessException(ResultCode.UPLOAD_FILE_MSG_ERROR);
+                            throw new BusinessException(-1,"缺少tileset.json文件");
                         }
 
                         redisUtil.set(RedisKeyUtil.modelUpload+model.getModelId(),"80");
@@ -239,15 +228,16 @@ public class ModelServiceImpl extends ServiceImpl<IModelMapper, Model> implement
                     redisUtil.set(RedisKeyUtil.modelUpload+model.getModelId(),"100");
                 }catch (Exception e){
                     setCreateStatus(model,-1);
+                    log.error("uploadObj--ThreadError-modeId:{},error:{}",model.getModelId(),e);
                 }finally {
                     if(newObjFile!=null){
-                        FileUtil.del(newObjFile);
+                        //FileUtil.del(newObjFile);
                     }
                     if(objPathFile!=null){
-                        FileUtil.del(objPathFile);
+                        //FileUtil.del(objPathFile);
                     }
                     if(mntFile!=null){
-                        FileUtil.del(mntFile.getParentFile());
+                       // FileUtil.del(mntFile.getParentFile());
                     }
                 }
             }, executor).whenComplete((reslut, e) -> {
@@ -255,7 +245,7 @@ public class ModelServiceImpl extends ServiceImpl<IModelMapper, Model> implement
             });
         }catch (Exception e){
             setCreateStatus(model,-1);
-            log.info("uploadObj--ThreadError-modeId:{},error:{}",model.getModelId(),e);
+            log.error("uploadObj--ThreadError-modeId:{},error:{}",model.getModelId(),e);
         }
     }