|
@@ -58,27 +58,27 @@ public class CommonUploadServiceImpl extends ServiceImpl<ICommonUploadMapper, Co
|
|
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public ResultData uploadFileNew( Integer dictId,String filePath) {
|
|
|
|
- if( StringUtils.isBlank(filePath) ){
|
|
|
|
- throw new BusinessException(ResultCode.UPLOAD_ERROR);
|
|
|
|
- }
|
|
|
|
- File file = new File(filePath);
|
|
|
|
- if(!file.exists() ){
|
|
|
|
|
|
+ public ResultData uploadFileNew( Integer dictId,MultipartFile file) {
|
|
|
|
+ if( file.isEmpty() ){
|
|
throw new BusinessException(ResultCode.UPLOAD_ERROR);
|
|
throw new BusinessException(ResultCode.UPLOAD_ERROR);
|
|
}
|
|
}
|
|
|
|
+ File tempFile = null;
|
|
|
|
+
|
|
try {
|
|
try {
|
|
- if(file.isDirectory()){
|
|
|
|
- return uploadModelZip(file.getName(),file,dictId);
|
|
|
|
- }
|
|
|
|
String uuid = UUID.randomUUID().toString().replace("-","");
|
|
String uuid = UUID.randomUUID().toString().replace("-","");
|
|
- String name = file.getName();
|
|
|
|
|
|
+ String name = file.getOriginalFilename();
|
|
String extName = name.substring(name.lastIndexOf(".")).toLowerCase();
|
|
String extName = name.substring(name.lastIndexOf(".")).toLowerCase();
|
|
String ossPath = String.format(OssPath.MANAGE_FILE_PATH, uuid + extName);
|
|
String ossPath = String.format(OssPath.MANAGE_FILE_PATH, uuid + extName);
|
|
|
|
|
|
- //file.transferTo(tempFile);
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- localToOssUtil.uploadOss(file.getPath(), ossPath);
|
|
|
|
|
|
+ tempFile = new File(OssPath.localPath + ossPath);
|
|
|
|
+ if(!tempFile.getParentFile().exists()){
|
|
|
|
+ tempFile.getParentFile().mkdirs();
|
|
|
|
+ }
|
|
|
|
+ file.transferTo(tempFile);
|
|
|
|
+ if(extName.equals(".zip")){
|
|
|
|
+ return uploadModelZip(name.replace(extName, ""),tempFile,dictId);
|
|
|
|
+ }
|
|
|
|
+ //localToOssUtil.uploadOss(tempFile.getPath(), ossPath);
|
|
String url = this.ossUrlPrefix + ossPath;
|
|
String url = this.ossUrlPrefix + ossPath;
|
|
|
|
|
|
FileTypeEnum fileTypeEnum = FileTypeEnum.getByType(extName.replace(".", ""));
|
|
FileTypeEnum fileTypeEnum = FileTypeEnum.getByType(extName.replace(".", ""));
|
|
@@ -86,7 +86,7 @@ public class CommonUploadServiceImpl extends ServiceImpl<ICommonUploadMapper, Co
|
|
throw new BusinessException(ResultCode.FILE_TYPE_ERROR2);
|
|
throw new BusinessException(ResultCode.FILE_TYPE_ERROR2);
|
|
}
|
|
}
|
|
String format = extName.replace(".", "");
|
|
String format = extName.replace(".", "");
|
|
- CommonUpload commonUpload = commonUploadService.add(name.replace(extName, ""), url, String.valueOf(file.length()), uuid, fileTypeEnum, format,format,1,null,dictId);
|
|
|
|
|
|
+ CommonUpload commonUpload = commonUploadService.add(name.replace(extName, ""), url, String.valueOf(file.getSize()), uuid, fileTypeEnum, format,format,1,null,dictId);
|
|
return ResultData.ok(commonUpload);
|
|
return ResultData.ok(commonUpload);
|
|
}catch ( BusinessException e){
|
|
}catch ( BusinessException e){
|
|
log.info("upload-file-error:{}",e);
|
|
log.info("upload-file-error:{}",e);
|
|
@@ -98,10 +98,18 @@ public class CommonUploadServiceImpl extends ServiceImpl<ICommonUploadMapper, Co
|
|
}
|
|
}
|
|
|
|
|
|
private ResultData uploadModelZip(String oldName,File file,Integer dictId) {
|
|
private ResultData uploadModelZip(String oldName,File file,Integer dictId) {
|
|
|
|
+
|
|
String ossZipPath = String.format(OssPath.MANAGE_MODEL_FILE_PATH, UUID.randomUUID().toString().replace("-", ""));
|
|
String ossZipPath = String.format(OssPath.MANAGE_MODEL_FILE_PATH, UUID.randomUUID().toString().replace("-", ""));
|
|
String unzipPath = CacheUtil.basePath + ossZipPath;
|
|
String unzipPath = CacheUtil.basePath + ossZipPath;
|
|
|
|
+ ShellUtil.unZip(file.getPath(),unzipPath);
|
|
|
|
+ try {
|
|
|
|
+ Thread.sleep(1000L);
|
|
|
|
+ FileUtil.del(file.getPath());
|
|
|
|
+ }catch (Exception e){
|
|
|
|
+ log.info("删除文件失败:{}",e);
|
|
|
|
+ }
|
|
|
|
|
|
- FileUtil.copyContent(file,new File(unzipPath),true);
|
|
|
|
|
|
+ //FileUtil.copyContent(file,new File(unzipPath),true);
|
|
File unZipFile = new File(unzipPath);
|
|
File unZipFile = new File(unzipPath);
|
|
|
|
|
|
if(!unZipFile.exists() || !unZipFile.isDirectory() ){
|
|
if(!unZipFile.exists() || !unZipFile.isDirectory() ){
|