|
@@ -1,9 +1,6 @@
|
|
package com.fdkankan.fusion.service.impl;
|
|
package com.fdkankan.fusion.service.impl;
|
|
import java.io.File;
|
|
import java.io.File;
|
|
-import java.io.IOException;
|
|
|
|
-import java.math.BigDecimal;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
-import java.util.Arrays;
|
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@@ -14,21 +11,17 @@ import com.fdkankan.fusion.common.PageInfo;
|
|
import com.fdkankan.fusion.common.util.*;
|
|
import com.fdkankan.fusion.common.util.*;
|
|
import com.fdkankan.fusion.common.FilePath;
|
|
import com.fdkankan.fusion.common.FilePath;
|
|
import com.fdkankan.fusion.common.ResultCode;
|
|
import com.fdkankan.fusion.common.ResultCode;
|
|
-import com.fdkankan.fusion.entity.CaseEntity;
|
|
|
|
-import com.fdkankan.fusion.entity.CaseNumEntity;
|
|
|
|
-import com.fdkankan.fusion.entity.FusionNum;
|
|
|
|
-import com.fdkankan.fusion.entity.Model;
|
|
|
|
|
|
+import com.fdkankan.fusion.entity.*;
|
|
import com.fdkankan.fusion.exception.BusinessException;
|
|
import com.fdkankan.fusion.exception.BusinessException;
|
|
import com.fdkankan.fusion.mapper.IModelMapper;
|
|
import com.fdkankan.fusion.mapper.IModelMapper;
|
|
import com.fdkankan.fusion.request.ModelPram;
|
|
import com.fdkankan.fusion.request.ModelPram;
|
|
-import com.fdkankan.fusion.request.ScenePram;
|
|
|
|
import com.fdkankan.fusion.response.SceneVo;
|
|
import com.fdkankan.fusion.response.SceneVo;
|
|
import com.fdkankan.fusion.service.ICaseNumService;
|
|
import com.fdkankan.fusion.service.ICaseNumService;
|
|
import com.fdkankan.fusion.service.ICaseService;
|
|
import com.fdkankan.fusion.service.ICaseService;
|
|
import com.fdkankan.fusion.service.IFusionNumService;
|
|
import com.fdkankan.fusion.service.IFusionNumService;
|
|
import com.fdkankan.fusion.service.IModelService;
|
|
import com.fdkankan.fusion.service.IModelService;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
-import jdk.nashorn.tools.Shell;
|
|
|
|
|
|
+import com.fdkankan.redis.util.RedisUtil;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -36,8 +29,6 @@ import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
-import javax.xml.transform.Result;
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
* <p>
|
|
* <p>
|
|
* 服务实现类
|
|
* 服务实现类
|
|
@@ -59,6 +50,9 @@ public class ModelServiceImpl extends ServiceImpl<IModelMapper, Model> implement
|
|
ICaseService caseService;
|
|
ICaseService caseService;
|
|
@Autowired
|
|
@Autowired
|
|
IFusionNumService fusionNumService;
|
|
IFusionNumService fusionNumService;
|
|
|
|
+ @Autowired
|
|
|
|
+ RedisUtil redisUtil;
|
|
|
|
+
|
|
@Value("${local.obj_path}")
|
|
@Value("${local.obj_path}")
|
|
private String OBJ_PATH;
|
|
private String OBJ_PATH;
|
|
@Value("${local.glb_path}")
|
|
@Value("${local.glb_path}")
|
|
@@ -67,7 +61,7 @@ public class ModelServiceImpl extends ServiceImpl<IModelMapper, Model> implement
|
|
private String queryPath;
|
|
private String queryPath;
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public void uploadObj(MultipartFile file, String username) throws Exception {
|
|
|
|
|
|
+ public Model uploadObj(MultipartFile file, String username) throws Exception {
|
|
if(file.isEmpty()){
|
|
if(file.isEmpty()){
|
|
throw new BusinessException(ResultCode.UPLOAD_FILE_NO_EXIST);
|
|
throw new BusinessException(ResultCode.UPLOAD_FILE_NO_EXIST);
|
|
}
|
|
}
|
|
@@ -82,7 +76,7 @@ public class ModelServiceImpl extends ServiceImpl<IModelMapper, Model> implement
|
|
if(com.fdkankan.fusion.common.util.StringUtils.isChinese(fileName)){
|
|
if(com.fdkankan.fusion.common.util.StringUtils.isChinese(fileName)){
|
|
throw new BusinessException(ResultCode.UPLOAD_FILE_CHINA_NAME);
|
|
throw new BusinessException(ResultCode.UPLOAD_FILE_CHINA_NAME);
|
|
}
|
|
}
|
|
- if(!fileName.toLowerCase().contains("zip") && !fileName.toLowerCase().contains("rar")){
|
|
|
|
|
|
+ if(!fileName.toLowerCase().contains("zip")){
|
|
throw new BusinessException(ResultCode.UPLOAD_FILE_TYPE_ERROR);
|
|
throw new BusinessException(ResultCode.UPLOAD_FILE_TYPE_ERROR);
|
|
}
|
|
}
|
|
//获取文件后缀名
|
|
//获取文件后缀名
|
|
@@ -93,81 +87,95 @@ public class ModelServiceImpl extends ServiceImpl<IModelMapper, Model> implement
|
|
model.setModelSize(FileWriterUtil.setFileSize(file.getSize()));
|
|
model.setModelSize(FileWriterUtil.setFileSize(file.getSize()));
|
|
model.setUserName(username);
|
|
model.setUserName(username);
|
|
this.save(model);
|
|
this.save(model);
|
|
|
|
+ redisUtil.set(RedisKeyUtil.modelUpload+model.getModelId(),"0");
|
|
|
|
+
|
|
File newObjFile = null;
|
|
File newObjFile = null;
|
|
File objPathFile = null;
|
|
File objPathFile = null;
|
|
- File mntFile = null;
|
|
|
|
String objPath = String.format(OBJ_PATH , "modelId_"+model.getModelId()) ;
|
|
String objPath = String.format(OBJ_PATH , "modelId_"+model.getModelId()) ;
|
|
- try {
|
|
|
|
- String glbOssPath = String.format(FilePath.GLB_OSS_PATH, model.getModelId());
|
|
|
|
|
|
|
|
- newObjFile = new File(objPath +"/" + fileName);
|
|
|
|
- if(!newObjFile.getParentFile().exists()){
|
|
|
|
- newObjFile.mkdirs();
|
|
|
|
- }
|
|
|
|
- file.transferTo(newObjFile);
|
|
|
|
- if(fileName.toLowerCase().contains("zip")){
|
|
|
|
- ShellUtil.unZip(newObjFile.getPath(),objPath);
|
|
|
|
- }
|
|
|
|
- if(fileName.toLowerCase().contains("rar")){
|
|
|
|
- ShellUtil.unRar(newObjFile.getPath(),objPath);
|
|
|
|
- }
|
|
|
|
- objPathFile = new File(objPath );
|
|
|
|
- if(!objPathFile.isDirectory()){
|
|
|
|
- throw new BusinessException(ResultCode.UPLOAD_FILE_TYPE_ERROR);
|
|
|
|
- }
|
|
|
|
- List<File> fileList = new ArrayList<>();
|
|
|
|
- FileWriterUtil.getCanRunList(fileList,objPathFile);
|
|
|
|
|
|
+ newObjFile = new File(objPath +"/" + fileName);
|
|
|
|
+ if(!newObjFile.getParentFile().exists()){
|
|
|
|
+ newObjFile.mkdirs();
|
|
|
|
+ }
|
|
|
|
+ file.transferTo(newObjFile);
|
|
|
|
+ if(fileName.toLowerCase().contains("zip")){
|
|
|
|
+ ShellUtil.unZip(newObjFile.getPath(),objPath);
|
|
|
|
+ }
|
|
|
|
+ objPathFile = new File(objPath );
|
|
|
|
+ if(!objPathFile.isDirectory()){
|
|
|
|
+ throw new BusinessException(ResultCode.UPLOAD_FILE_TYPE_ERROR);
|
|
|
|
+ }
|
|
|
|
+ List<File> fileList = new ArrayList<>();
|
|
|
|
+ FileWriterUtil.getCanRunList(fileList,objPathFile);
|
|
|
|
|
|
- if(fileList.size() != 1){
|
|
|
|
- throw new BusinessException(ResultCode.UPLOAD_FILE_TYPE_ERROR);
|
|
|
|
- }
|
|
|
|
- File file1 = fileList.get(0);
|
|
|
|
- if(file1 == null){
|
|
|
|
- throw new BusinessException(ResultCode.UPLOAD_FILE_TYPE_ERROR);
|
|
|
|
- }
|
|
|
|
|
|
+ if(fileList.size() != 1){
|
|
|
|
+ throw new BusinessException(ResultCode.UPLOAD_FILE_TYPE_ERROR);
|
|
|
|
+ }
|
|
|
|
+ File file1 = fileList.get(0);
|
|
|
|
+ if(file1 == null){
|
|
|
|
+ throw new BusinessException(ResultCode.UPLOAD_FILE_TYPE_ERROR);
|
|
|
|
+ }
|
|
|
|
+ if(com.fdkankan.fusion.common.util.StringUtils.isChinese(file1.getName())){
|
|
|
|
+ throw new BusinessException(ResultCode.UPLOAD_FILE_CHINA_NAME);
|
|
|
|
+ }
|
|
|
|
+ redisUtil.set(RedisKeyUtil.modelUpload+model.getModelId(),"20");
|
|
|
|
+ runThread(file1,objPath,model,newObjFile,objPathFile,this);
|
|
|
|
+ return model;
|
|
|
|
+ }
|
|
|
|
|
|
- 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.objToGlb(objPath,name, file1.getPath().replace("obj","glb"));
|
|
|
|
- uploadToOssUtil.uploadOss(file1.getPath(),glbOssPath);
|
|
|
|
- }
|
|
|
|
- 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";
|
|
|
|
- uploadToOssUtil.uploadFileOss(mntFile );
|
|
|
|
- }
|
|
|
|
|
|
+ private void runThread(File file1,String objPath,Model model,File newObjFile,File objPathFile,IModelService modelService){
|
|
|
|
+ new Thread() {
|
|
|
|
+ @Override
|
|
|
|
+ public void run() {
|
|
|
|
+ File mntFile = null;
|
|
|
|
+ try {
|
|
|
|
+ String glbOssPath = String.format(FilePath.GLB_OSS_PATH, model.getModelId());
|
|
|
|
|
|
- model.setModelObjUrl(objPath);
|
|
|
|
- model.setModelGlbUrl(queryPath + glbOssPath);
|
|
|
|
- model.setCreateStatus(1); //上传成功
|
|
|
|
- this.saveOrUpdate(model);
|
|
|
|
- }catch (Exception e){
|
|
|
|
- model.setCreateStatus(-1);
|
|
|
|
- this.saveOrUpdate(model);
|
|
|
|
- throw e;
|
|
|
|
- }finally {
|
|
|
|
- if(newObjFile!=null){
|
|
|
|
- FileUtil.del(newObjFile);
|
|
|
|
- }
|
|
|
|
- if(objPathFile!=null){
|
|
|
|
- FileUtil.del(objPathFile);
|
|
|
|
- }
|
|
|
|
- if(mntFile!=null){
|
|
|
|
- FileUtil.del(mntFile.getParentFile());
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ 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.objToGlb(objPath,name, file1.getPath().replace("obj","glb"));
|
|
|
|
+ redisUtil.set(RedisKeyUtil.modelUpload+model.getModelId(),"65");
|
|
|
|
+ uploadToOssUtil.uploadOss(file1.getPath(),glbOssPath);
|
|
|
|
+ }
|
|
|
|
+ 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(),"665");
|
|
|
|
+ uploadToOssUtil.uploadFileOss(mntFile );
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ model.setModelObjUrl(objPath);
|
|
|
|
+ model.setModelGlbUrl(queryPath + glbOssPath);
|
|
|
|
+ model.setCreateStatus(1); //上传成功
|
|
|
|
+ modelService.saveOrUpdate(model);
|
|
|
|
+ redisUtil.set(RedisKeyUtil.modelUpload+model.getModelId(),"100");
|
|
|
|
+ }catch (Exception e){
|
|
|
|
+ model.setCreateStatus(-1);
|
|
|
|
+ modelService.saveOrUpdate(model);
|
|
|
|
+ }finally {
|
|
|
|
+ if(newObjFile!=null){
|
|
|
|
+ FileUtil.del(newObjFile);
|
|
|
|
+ }
|
|
|
|
+ if(objPathFile!=null){
|
|
|
|
+ FileUtil.del(objPathFile);
|
|
|
|
+ }
|
|
|
|
+ if(mntFile!=null){
|
|
|
|
+ FileUtil.del(mntFile.getParentFile());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }.start();
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -280,4 +288,13 @@ public class ModelServiceImpl extends ServiceImpl<IModelMapper, Model> implement
|
|
BeanUtils.copyProperties(model,sceneVo);
|
|
BeanUtils.copyProperties(model,sceneVo);
|
|
return sceneVo;
|
|
return sceneVo;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public String uploadObjProgress(Integer modelId) {
|
|
|
|
+ String redisKey = RedisKeyUtil.modelUpload+modelId;
|
|
|
|
+ if(redisUtil.hasKey(redisKey)){
|
|
|
|
+ return redisUtil.get(redisKey);
|
|
|
|
+ }
|
|
|
|
+ return "0";
|
|
|
|
+ }
|
|
}
|
|
}
|