|
@@ -102,7 +102,6 @@ public class CommonUploadServiceImpl extends ServiceImpl<ICommonUploadMapper, Co
|
|
|
}
|
|
|
String format = extName.replace(".", "");
|
|
|
CommonUpload commonUpload = commonUploadService.add(originalFilename.replace(extName, ""), url, String.valueOf(file.getSize()), uuid, fileTypeEnum, format,format,1,null,dictId);
|
|
|
- tempFile.delete();
|
|
|
return ResultData.ok(commonUpload);
|
|
|
}catch ( BusinessException e){
|
|
|
log.info("upload-file-error:{}",e);
|
|
@@ -110,83 +109,94 @@ public class CommonUploadServiceImpl extends ServiceImpl<ICommonUploadMapper, Co
|
|
|
}catch (Exception e){
|
|
|
log.info("upload-file-error:{}",e);
|
|
|
throw new BusinessException(ResultCode.UPLOAD_ERROR);
|
|
|
+ }finally {
|
|
|
+ if(tempFile != null){
|
|
|
+ tempFile.delete();
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private ResultData uploadModelZip(String oldName,File file,Integer dictId) {
|
|
|
- Long fileSize = file.length();
|
|
|
- String ossZipPath = String.format(OssPath.MANAGE_MODEL_FILE_PATH, UUID.randomUUID().toString().replace("-", ""));
|
|
|
- String unzipPath = CacheUtil.basePath + ossZipPath;
|
|
|
- ShellUtil.unZip(file.getPath(),unzipPath);
|
|
|
+ File unZipFile = null;
|
|
|
try {
|
|
|
- Thread.sleep(1000L);
|
|
|
- FileUtil.del(file.getPath());
|
|
|
- }catch (Exception e){
|
|
|
- log.info("删除文件失败:{}",e);
|
|
|
- }
|
|
|
+ Long fileSize = file.length();
|
|
|
+ String ossZipPath = String.format(OssPath.MANAGE_MODEL_FILE_PATH, UUID.randomUUID().toString().replace("-", ""));
|
|
|
+ String unzipPath = CacheUtil.basePath + ossZipPath;
|
|
|
+ ShellUtil.unZip(file.getPath(),unzipPath);
|
|
|
|
|
|
- //FileUtil.copyContent(file,new File(unzipPath),true);
|
|
|
- File unZipFile = new File(unzipPath);
|
|
|
-
|
|
|
- if(!unZipFile.exists() || !unZipFile.isDirectory() ){
|
|
|
- throw new BusinessException(ResultCode.UNZIP_ERROR);
|
|
|
- }
|
|
|
- List<File> fileList = new ArrayList<>();
|
|
|
- FileWriterUtil.getCanRunList(fileList,unZipFile);
|
|
|
- if(fileList.size() <=0){
|
|
|
- throw new BusinessException(ResultCode.UPLOAD_FILE_ERROR);
|
|
|
- }
|
|
|
- File modelFile = fileList.get(0);
|
|
|
- String modelFileFormat = modelFile.getName().split("\\.")[1].toLowerCase();
|
|
|
-
|
|
|
- FileTypeEnum fileTypeEnum = FileTypeEnum.getByType(modelFileFormat);
|
|
|
- if(fileTypeEnum == null){
|
|
|
- throw new BusinessException(ResultCode.FILE_TYPE_ERROR2);
|
|
|
- }
|
|
|
+ //FileUtil.copyContent(file,new File(unzipPath),true);
|
|
|
+ unZipFile = new File(unzipPath);
|
|
|
|
|
|
- if(dictId != null){
|
|
|
- Dict dict = dictService.getById(dictId);
|
|
|
- if(dict == null ){
|
|
|
- throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
|
|
|
+ if(!unZipFile.exists() || !unZipFile.isDirectory() ){
|
|
|
+ throw new BusinessException(ResultCode.UNZIP_ERROR);
|
|
|
}
|
|
|
- if("animation".equals(dict.getUseType()) && !(modelFileFormat.equals("glb") || modelFileFormat.equals("obj"))){
|
|
|
+ List<File> fileList = new ArrayList<>();
|
|
|
+ FileWriterUtil.getCanRunList(fileList,unZipFile);
|
|
|
+ if(fileList.size() <=0){
|
|
|
+ throw new BusinessException(ResultCode.UPLOAD_FILE_ERROR);
|
|
|
+ }
|
|
|
+ File modelFile = fileList.get(0);
|
|
|
+ String modelFileFormat = modelFile.getName().split("\\.")[1].toLowerCase();
|
|
|
+
|
|
|
+ FileTypeEnum fileTypeEnum = FileTypeEnum.getByType(modelFileFormat);
|
|
|
+ if(fileTypeEnum == null){
|
|
|
throw new BusinessException(ResultCode.FILE_TYPE_ERROR2);
|
|
|
}
|
|
|
|
|
|
- }
|
|
|
+ if(dictId != null){
|
|
|
+ Dict dict = dictService.getById(dictId);
|
|
|
+ if(dict == null ){
|
|
|
+ throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
|
|
|
+ }
|
|
|
+ if("animation".equals(dict.getUseType()) && !(modelFileFormat.equals("glb") || modelFileFormat.equals("obj"))){
|
|
|
+ throw new BusinessException(ResultCode.FILE_TYPE_ERROR2);
|
|
|
+ }
|
|
|
|
|
|
- if(FileWriterUtil.isChinese(modelFile.getName())){
|
|
|
- throw new BusinessException(ResultCode.FILE_TYPE_ERROR23);
|
|
|
- }
|
|
|
- if(FileWriterUtil.isChinese(modelFile.getPath())){
|
|
|
- throw new BusinessException(ResultCode.FILE_TYPE_ERROR23);
|
|
|
- }
|
|
|
- String url = null;
|
|
|
- String resultFormat = modelFileFormat;
|
|
|
- switch (modelFileFormat){
|
|
|
- case "obj" : resultFormat = "obj";
|
|
|
- url = uploadObjOss(unzipPath,modelFile);break;
|
|
|
- case "glb" : url = uploadOss(unzipPath,modelFile);break;
|
|
|
- case "laz" : url = uploadLazOss(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":
|
|
|
+ }
|
|
|
+
|
|
|
+ if(FileWriterUtil.isChinese(modelFile.getName())){
|
|
|
+ throw new BusinessException(ResultCode.FILE_TYPE_ERROR23);
|
|
|
+ }
|
|
|
+ if(FileWriterUtil.isChinese(modelFile.getPath())){
|
|
|
+ throw new BusinessException(ResultCode.FILE_TYPE_ERROR23);
|
|
|
+ }
|
|
|
+ String url = null;
|
|
|
+ String resultFormat = modelFileFormat;
|
|
|
+ switch (modelFileFormat){
|
|
|
+ case "obj" : resultFormat = "obj";
|
|
|
+ url = uploadObjOss(unzipPath,modelFile);break;
|
|
|
+ case "glb" : url = uploadOss(unzipPath,modelFile);break;
|
|
|
+ case "laz" : url = uploadLazOss(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";
|
|
|
- break;
|
|
|
- default: break;
|
|
|
- }
|
|
|
+ break;
|
|
|
+ default: break;
|
|
|
+ }
|
|
|
|
|
|
- Integer status = StringUtils.isNotBlank(url) ?1:-1;
|
|
|
- url = StringUtils.isNotBlank(url) ?ossUrlPrefix + url:null;
|
|
|
- CommonUpload commonUpload = commonUploadService.add(oldName,url, String.valueOf(fileSize),
|
|
|
- null, fileTypeEnum, modelFileFormat,resultFormat,status,unZipFile.getPath(),dictId);
|
|
|
- if("osgb".equals(modelFileFormat)){
|
|
|
- //commonUploadService.updateStatus(commonUpload.getId(),0);
|
|
|
- uploadOsgb(commonUpload.getId()) ;
|
|
|
+ Integer status = StringUtils.isNotBlank(url) ?1:-1;
|
|
|
+ url = StringUtils.isNotBlank(url) ?ossUrlPrefix + url:null;
|
|
|
+ CommonUpload commonUpload = commonUploadService.add(oldName,url, String.valueOf(fileSize),
|
|
|
+ null, fileTypeEnum, modelFileFormat,resultFormat,status,unZipFile.getPath(),dictId);
|
|
|
+ if("osgb".equals(modelFileFormat)){
|
|
|
+ //commonUploadService.updateStatus(commonUpload.getId(),0);
|
|
|
+ uploadOsgb(commonUpload.getId()) ;
|
|
|
+ }
|
|
|
+ return ResultData.ok(commonUpload);
|
|
|
+ } catch (BusinessException e){
|
|
|
+ throw e;
|
|
|
+ }catch (Exception e){
|
|
|
+ log.info("上传失败:{}",e);
|
|
|
+ throw new BusinessException(ResultCode.UPLOAD_ERROR);
|
|
|
+ }finally {
|
|
|
+ if(unZipFile != null){
|
|
|
+ unZipFile.delete();
|
|
|
+ }
|
|
|
}
|
|
|
- return ResultData.ok(commonUpload);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
private String uploadObjOss(String unzipPath, File modelFile) {
|
|
@@ -198,7 +208,6 @@ public class CommonUploadServiceImpl extends ServiceImpl<ICommonUploadMapper, Co
|
|
|
if(!uploadToOssUtil.fileExist(localGlbPath.replace(OssPath.localPath,""))){
|
|
|
throw new BusinessException(ResultCode.UPLOAD_FILE_ERROR);
|
|
|
}
|
|
|
- FileUtil.del(unzipPath);
|
|
|
return localGlbPath.replace(OssPath.localPath,"");
|
|
|
}
|
|
|
|
|
@@ -212,7 +221,6 @@ public class CommonUploadServiceImpl extends ServiceImpl<ICommonUploadMapper, Co
|
|
|
if(!uploadToOssUtil.fileExist(ossPath)){
|
|
|
throw new BusinessException(ResultCode.UPLOAD_FILE_ERROR);
|
|
|
}
|
|
|
- FileUtil.del(unzipPath);
|
|
|
return ossPath;
|
|
|
}
|
|
|
|
|
@@ -230,7 +238,6 @@ public class CommonUploadServiceImpl extends ServiceImpl<ICommonUploadMapper, Co
|
|
|
if(!uploadToOssUtil.fileExist(modelOssPath)){
|
|
|
throw new BusinessException(ResultCode.UPLOAD_FILE_ERROR);
|
|
|
}
|
|
|
- FileUtil.del(unzipPath);
|
|
|
return ossPath;
|
|
|
}
|
|
|
|
|
@@ -241,7 +248,6 @@ public class CommonUploadServiceImpl extends ServiceImpl<ICommonUploadMapper, Co
|
|
|
if(!uploadToOssUtil.existKey(modelOssPath)){
|
|
|
throw new BusinessException(ResultCode.UPLOAD_FILE_ERROR);
|
|
|
}
|
|
|
- FileUtil.del(unzipPath);
|
|
|
return modelOssPath;
|
|
|
}
|
|
|
|
|
@@ -252,7 +258,6 @@ public class CommonUploadServiceImpl extends ServiceImpl<ICommonUploadMapper, Co
|
|
|
if(!uploadToOssUtil.existKey(ossPath+"/webcloud/cloud.js")){
|
|
|
throw new BusinessException(-1,"缺少cloud.js文件");
|
|
|
}
|
|
|
- FileUtil.del(unzipPath);
|
|
|
return ossPath + "/webcloud";
|
|
|
}
|
|
|
|