|
@@ -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;
|
|
|
}
|