|
@@ -66,6 +66,8 @@ public class ModelServiceImpl extends ServiceImpl<IModelMapper, Model> implement
|
|
|
ITmUserService tmUserService;
|
|
|
@Autowired
|
|
|
ITmCameraService tmCameraService;
|
|
|
+ @Autowired
|
|
|
+ ThreadService threadService;
|
|
|
|
|
|
@Value("${upload.query-path}")
|
|
|
private String queryPath;
|
|
@@ -106,170 +108,17 @@ public class ModelServiceImpl extends ServiceImpl<IModelMapper, Model> implement
|
|
|
this.save(model);
|
|
|
redisUtil.set(RedisKeyUtil.modelUpload+model.getModelId(),"0");
|
|
|
|
|
|
- runThread(file,model,this);
|
|
|
- return model;
|
|
|
- }
|
|
|
-
|
|
|
- private void setCreateStatus(Model model,Integer status){
|
|
|
- String redisKey = RedisKeyUtil.modelCancelUpload+model.getModelId();
|
|
|
- if(redisUtil.hasKey(redisKey)){
|
|
|
- if(redisUtil.get(redisKey).equals("-2")){
|
|
|
- return;
|
|
|
- }
|
|
|
- }
|
|
|
- model.setCreateStatus(status);
|
|
|
- this.saveOrUpdate(model);
|
|
|
- if(status != 1){
|
|
|
- redisUtil.set(RedisKeyUtil.modelUpload+model.getModelId(),status.toString());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public void runThread(MultipartFile file,Model model,IModelService modelService) throws IOException {
|
|
|
- String fileName = UUID.randomUUID().toString().replace("-","") +".zip";
|
|
|
+ String fileName2 = UUID.randomUUID().toString().replace("-","") +".zip";
|
|
|
String objPath = String.format(FilePath.OBJ_LOCAL_PATH,environment , "modelId_"+model.getModelId()) ;
|
|
|
- log.info("uploadObj--ThreadStart-fileName:{},modeId:{}",fileName,model.getModelId());
|
|
|
+ log.info("uploadObj--ThreadStart-fileName:{},modeId:{}",fileName2,model.getModelId());
|
|
|
|
|
|
- File newObjFile = new File(objPath +"/" + fileName);
|
|
|
+ File newObjFile = new File(objPath +"/" + fileName2);
|
|
|
if(!newObjFile.getParentFile().exists()){
|
|
|
newObjFile.getParentFile().mkdirs();
|
|
|
}
|
|
|
- // file.transferTo(newObjFile); 异步会出现 FileNotFoundException temp.
|
|
|
- FileUtils.copyInputStreamToFile(file.getInputStream(), newObjFile);
|
|
|
-
|
|
|
- ExecutorService executor = ThreadUtil.newSingleExecutor();
|
|
|
- try {
|
|
|
- CompletableFuture.runAsync(() -> {
|
|
|
- File objPathFile = null;
|
|
|
- File mntFile = null;
|
|
|
- File b3dmFile = null;
|
|
|
- File osgbFile = null;
|
|
|
- try {
|
|
|
- // file.transferTo(newObjFile); 异步会出现 FileNotFoundException temp.
|
|
|
- FileUtils.copyInputStreamToFile(file.getInputStream(), newObjFile);
|
|
|
-
|
|
|
- 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){
|
|
|
- throw new BusinessException(-1,"可上传文件不存在");
|
|
|
- }
|
|
|
-
|
|
|
- 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,"压缩包中文");
|
|
|
- }
|
|
|
- String b3dmJsonPath = null;
|
|
|
- if(file1.getName().endsWith(".b3dm") ){
|
|
|
- b3dmJsonPath = FileWriterUtil.checkB3dmTileset(objPathFile);
|
|
|
- if(b3dmJsonPath == null){
|
|
|
- throw new BusinessException(-1,"缺少tileset.json文件");
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- redisUtil.set(RedisKeyUtil.modelUpload+model.getModelId(),"20");
|
|
|
-
|
|
|
- String glbOssPath = String.format(FilePath.GLB_OSS_PATH,environment, model.getModelId());
|
|
|
-
|
|
|
- String name = file1.getName();
|
|
|
- if(name.contains("obj") || name.contains("OBJ")){
|
|
|
- glbOssPath = glbOssPath.replace("mesh.glb",file1.getName().replace(".obj",".glb"));
|
|
|
- model.setModelDateType("obj");
|
|
|
- model.setModelType("glb");
|
|
|
- OBJToGLBUtil.objToGlb2(file1.getPath(), file1.getPath().replace(".obj",".glb"));
|
|
|
- redisUtil.set(RedisKeyUtil.modelUpload+model.getModelId(),"65");
|
|
|
- uploadToOssUtil.uploadOss(file1.getPath().replace(".obj",".glb"),glbOssPath);
|
|
|
- if(!uploadToOssUtil.existKey(glbOssPath)){
|
|
|
- throw new BusinessException(-1,"缺少.glb文件");
|
|
|
- }
|
|
|
- }
|
|
|
- if(name.contains(".ply")){
|
|
|
- model.setModelDateType("ply");
|
|
|
- model.setModelType("ply");
|
|
|
- }
|
|
|
- if(name.contains(".las")){
|
|
|
- model.setModelDateType("las");
|
|
|
- model.setModelType("las");
|
|
|
- }
|
|
|
- if("las".equals(model.getModelType()) || "ply".equals(model.getModelType()) ){
|
|
|
- mntFile = OBJToGLBUtil.lasOrPlyToBin(file1);
|
|
|
- glbOssPath = mntFile.getPath().replace("/mnt/","")+"/webcloud";
|
|
|
- redisUtil.set(RedisKeyUtil.modelUpload+model.getModelId(),"65");
|
|
|
- uploadToOssUtil.uploadFileOss(mntFile );
|
|
|
- if(!uploadToOssUtil.existKey(glbOssPath+"/cloud.js")){
|
|
|
- throw new BusinessException(-1,"缺少cloud.js文件");
|
|
|
- }
|
|
|
- }
|
|
|
- model.setModelGlbUrl(JSONArray.toJSONString(Arrays.asList(queryPath + glbOssPath)));
|
|
|
-
|
|
|
- String b3dmPath = objPathFile.getPath().replace(FilePath.LOCAL_BASE_PATH,"fusion/");
|
|
|
- if(name.contains(".osgb")){
|
|
|
- model.setModelDateType("b3dm");
|
|
|
- model.setModelType("b3dm");
|
|
|
-
|
|
|
- redisUtil.set(RedisKeyUtil.modelUpload+model.getModelId(),"60");
|
|
|
- String localPath = OBJToGLBUtil.OsgbToB3dm(objPathFile);
|
|
|
- osgbFile = new File(localPath.replace("mnt/fusion/b3dm","/mnt/fusion/osgb"));
|
|
|
- b3dmFile = new File(localPath);
|
|
|
- b3dmJsonPath = FileWriterUtil.checkB3dmTileset(b3dmFile);
|
|
|
- if(b3dmJsonPath == null){
|
|
|
- throw new BusinessException(-1,"缺少tileset.json文件");
|
|
|
- }
|
|
|
- redisUtil.set(RedisKeyUtil.modelUpload+model.getModelId(),"80");
|
|
|
-
|
|
|
- String replace = b3dmJsonPath.replace(FilePath.MNT_BASE_PATH, "fusion/test");
|
|
|
- File file2 = new File(replace);
|
|
|
- ShellUtil.yunUpload(localPath,file2.getParent());
|
|
|
- model.setModelGlbUrl((JSONArray.toJSONString(Arrays.asList(queryPath + replace))));
|
|
|
- }
|
|
|
-
|
|
|
- if(name.contains(".b3dm") && b3dmJsonPath != null){
|
|
|
- model.setModelDateType("b3dm");
|
|
|
- model.setModelType("b3dm");
|
|
|
- redisUtil.set(RedisKeyUtil.modelUpload+model.getModelId(),"60");
|
|
|
- ShellUtil.yunUpload(objPathFile.getPath(),b3dmPath);
|
|
|
- model.setModelGlbUrl((JSONArray.toJSONString(Arrays.asList(queryPath + b3dmJsonPath.replace(FilePath.LOCAL_BASE_PATH,"fusion/")))));
|
|
|
- }
|
|
|
-
|
|
|
- setCreateStatus(model,1);
|
|
|
- modelService.saveOrUpdate(model);
|
|
|
- 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);
|
|
|
- }
|
|
|
- if(objPathFile!=null){
|
|
|
- FileUtil.del(objPathFile);
|
|
|
- }
|
|
|
- if(mntFile!=null){
|
|
|
- FileUtil.del(mntFile.getParentFile());
|
|
|
- }
|
|
|
- if(b3dmFile != null){
|
|
|
- FileUtil.del(b3dmFile.getParentFile());
|
|
|
- }
|
|
|
- if(osgbFile != null){
|
|
|
- FileUtil.del(osgbFile.getParentFile());
|
|
|
- }
|
|
|
- }
|
|
|
- }, executor).whenComplete((reslut, e) -> {
|
|
|
- log.info("uploadObj--ThreadEnd-modeId:{}",model.getModelId());
|
|
|
- });
|
|
|
- }catch (Exception e){
|
|
|
- setCreateStatus(model,-1);
|
|
|
- log.error("uploadObj--ThreadError-modeId:{},error:{}",model.getModelId(),e);
|
|
|
- }
|
|
|
+ file.transferTo(newObjFile);
|
|
|
+ threadService.uploadModelObj(fileName2,objPath,newObjFile,model);
|
|
|
+ return model;
|
|
|
}
|
|
|
|
|
|
@Override
|