|
@@ -2,6 +2,7 @@ package com.fdkankan.scene.service.impl;
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
+import cn.hutool.core.util.CharsetUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.core.util.ZipUtil;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
@@ -43,6 +44,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
+
|
|
|
/**
|
|
|
* <p>
|
|
|
* TODO
|
|
@@ -55,7 +58,7 @@ import org.springframework.web.multipart.MultipartFile;
|
|
|
@Service
|
|
|
public class BoxModelServiceImpl implements IBoxModelService {
|
|
|
|
|
|
- @Autowired
|
|
|
+ @Resource
|
|
|
private FYunFileServiceInterface fYunFileService;
|
|
|
@Autowired
|
|
|
private IScenePlusService scenePlusService;
|
|
@@ -78,40 +81,55 @@ public class BoxModelServiceImpl implements IBoxModelService {
|
|
|
throw new BusinessException(ErrorCode.FAILURE_CODE_7015);
|
|
|
}
|
|
|
|
|
|
- if(!FileUtils.checkFileSizeIsLimit(file.getSize(), 5, "M")){
|
|
|
- throw new BusinessException(ErrorCode.FAILURE_CODE_7023, "5M");
|
|
|
- }
|
|
|
+// if(!FileUtils.checkFileSizeIsLimit(file.getSize(), 5, "M")){
|
|
|
+// throw new BusinessException(ErrorCode.FAILURE_CODE_7023, "5M");
|
|
|
+// }
|
|
|
String path = String.format(ConstantFilePath.SCENE_USER_PATH_V4, num) + "boxModel/" + sid + "/";
|
|
|
- String zipPath = path + file.getOriginalFilename();
|
|
|
- String srcPath = path + "data/";
|
|
|
- String glbPath = path + sid + ".glb";
|
|
|
-
|
|
|
- FileUtil.del(path);
|
|
|
- FileUtil.mkParentDirs(zipPath);
|
|
|
- file.transferTo(new File(zipPath));
|
|
|
-
|
|
|
- //解压
|
|
|
- ZipUtil.unzip(zipPath,srcPath);
|
|
|
-
|
|
|
- //校验是否包含目录,如果包含目录提示错误
|
|
|
- File srcFile = new File(srcPath);
|
|
|
- Arrays.stream(srcFile.listFiles()).forEach(subFile->{
|
|
|
- if(subFile.isDirectory()){
|
|
|
- throw new BusinessException(ErrorCode.FAILURE_CODE_5065);
|
|
|
+ try {
|
|
|
+ String zipPath = path + file.getOriginalFilename();
|
|
|
+ String srcPath = path + "data/";
|
|
|
+ String glbPath = path + sid + ".glb";
|
|
|
+
|
|
|
+ FileUtil.del(path);
|
|
|
+ FileUtil.mkParentDirs(zipPath);
|
|
|
+ file.transferTo(new File(zipPath));
|
|
|
+
|
|
|
+ //解压
|
|
|
+ ZipUtil.unzip(zipPath,srcPath, CharsetUtil.CHARSET_GBK);
|
|
|
+
|
|
|
+ //校验是否包含目录,如果包含目录提示错误
|
|
|
+ File srcFile = new File(srcPath);
|
|
|
+ Arrays.stream(srcFile.listFiles()).forEach(subFile->{
|
|
|
+ if(subFile.isDirectory()){
|
|
|
+ throw new BusinessException(ErrorCode.FAILURE_CODE_5065);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ //转glb
|
|
|
+ OBJToGLBUtil.objToGlb(srcPath, glbPath);
|
|
|
+
|
|
|
+ if(!ComputerUtil.checkComputeCompleted(glbPath, 10, 2000)){
|
|
|
+ throw new BusinessException(ErrorCode.FAILURE_CODE_7013);
|
|
|
}
|
|
|
- });
|
|
|
|
|
|
- //转glb
|
|
|
- OBJToGLBUtil.objToGlb(srcPath, glbPath);
|
|
|
+ //上传glb
|
|
|
+ fYunFileService.uploadFile(bucket, glbPath, String.format(UploadFilePath.USER_EDIT_PATH, num) + "boxModels/" + sid + ".glb");
|
|
|
|
|
|
- if(!ComputerUtil.checkComputeCompleted(glbPath, 3, 2000)){
|
|
|
- throw new BusinessException(ErrorCode.FAILURE_CODE_7013);
|
|
|
- }
|
|
|
+ //上传原始obj相关文件
|
|
|
+ List<File> files = FileUtil.loopFiles(srcPath);
|
|
|
+ files.stream().forEach(v->{
|
|
|
+ String ossKey = String.format(UploadFilePath.USER_EDIT_PATH, num) + "boxModels/" + sid + "/" + v.getAbsolutePath().replace(srcPath, "");
|
|
|
+ fYunFileService.uploadFile(v.getAbsolutePath(), ossKey);
|
|
|
+ });
|
|
|
|
|
|
- //上传glb
|
|
|
- fYunFileService.uploadFile(bucket, glbPath, String.format(UploadFilePath.USER_EDIT_PATH, num) + "boxModels/" + sid + ".glb");
|
|
|
+ return ResultData.ok(sid + ".glb");
|
|
|
|
|
|
- return ResultData.ok(sid + ".glb");
|
|
|
+ }catch (Exception e){
|
|
|
+ log.error("上传三维模型失败", e);
|
|
|
+ throw e;
|
|
|
+ }finally {
|
|
|
+ FileUtil.del(path);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public static void main(String[] args) {
|
|
@@ -158,6 +176,12 @@ public class BoxModelServiceImpl implements IBoxModelService {
|
|
|
//写数据库
|
|
|
this.updateBoxModels(sceneEditInfo, boxModels);
|
|
|
|
|
|
+ //删除oss文件
|
|
|
+ String glbKey = String.format(UploadFilePath.USER_EDIT_PATH, param.getNum()) + "boxModels/" + param.getSid() + ".glb";
|
|
|
+ fYunFileService.deleteFile(glbKey);
|
|
|
+ String modelPath = String.format(UploadFilePath.USER_EDIT_PATH, param.getNum()) + "boxModels/" + param.getSid();
|
|
|
+ fYunFileService.deleteFolder(modelPath);
|
|
|
+
|
|
|
return ResultData.ok();
|
|
|
}
|
|
|
|