|
@@ -63,39 +63,46 @@ public class UploadController extends BaseController {
|
|
|
VUtils.isTure(projectId == null).throwMessage(ResultCode.PARAM_MISS);
|
|
|
VUtils.isTure(StringUtils.isBlank(projectName)).throwMessage(ResultCode.PARAM_MISS);
|
|
|
|
|
|
- File localFile = uploadService.uploadFile(file);
|
|
|
- String newFileName = localFile.getName().substring(16);
|
|
|
-
|
|
|
- String ossKey = String.format(FilePath.OSS_BIM_PATH,projectId,newFileName);
|
|
|
- uploadToOssUtil.uploadOss(localFile.getPath(), ossKey);
|
|
|
- if(!uploadToOssUtil.existKey(ossKey)){
|
|
|
- throw new BusinessException(ResultCode.UPLOAD_BIM_ERROR);
|
|
|
- }
|
|
|
List<ProjectBim> bims = projectBimService.getByProjectId(projectId);
|
|
|
for (ProjectBim bim : bims) {
|
|
|
if(bim.getBimStatus().equals(BusinessStatus.DONE.getInfo())){
|
|
|
throw new BusinessException(ResultCode.UPLOAD_BIM_EXIST);
|
|
|
}
|
|
|
+ if(!bim.getBimStatus().equals(BusinessStatus.ERROR.getInfo())){
|
|
|
+ throw new BusinessException(ResultCode.UPLOAD_BIM_ING);
|
|
|
+ }
|
|
|
}
|
|
|
ProjectBim projectBim = new ProjectBim();
|
|
|
- projectBim.setBimName(Objects.requireNonNull(file.getOriginalFilename()).split("\\.")[0]);
|
|
|
- projectBim.setBimLocalFilePath(queryPath + ossKey);
|
|
|
- projectBim.setFileName(file.getOriginalFilename());
|
|
|
projectBim.setProjectId(projectId);
|
|
|
projectBimService.save(projectBim);
|
|
|
-
|
|
|
- BimUploadParam param = new BimUploadParam();
|
|
|
- String callBackUrl = "http://" + request.getServerName() //服务器地址
|
|
|
- + ":"
|
|
|
- + request.getServerPort() //端口号
|
|
|
- + request.getRequestURI().replace("bim","callBack");
|
|
|
- param.setTask(projectBim.getBimId().toString());
|
|
|
- param.setProjectName(projectName);
|
|
|
- param.setSource(request.getContextPath());
|
|
|
- param.setCallBack(callBackUrl);
|
|
|
- param.setFileName(projectBim.getFileName());
|
|
|
- param.setFileUrl(projectBim.getBimLocalFilePath());
|
|
|
+ File localFile = null;
|
|
|
try {
|
|
|
+ localFile = uploadService.uploadFile(file);
|
|
|
+ String newFileName = localFile.getName().substring(16);
|
|
|
+
|
|
|
+ String ossKey = String.format(FilePath.OSS_BIM_PATH,projectId,newFileName);
|
|
|
+ uploadToOssUtil.uploadOss(localFile.getPath(), ossKey);
|
|
|
+ if(!uploadToOssUtil.existKey(ossKey)){
|
|
|
+ throw new BusinessException(ResultCode.UPLOAD_BIM_ERROR);
|
|
|
+ }
|
|
|
+
|
|
|
+ projectBim.setBimName(Objects.requireNonNull(file.getOriginalFilename()).split("\\.")[0]);
|
|
|
+ projectBim.setBimLocalFilePath(queryPath + ossKey);
|
|
|
+ projectBim.setFileName(file.getOriginalFilename());
|
|
|
+ projectBimService.updateById(projectBim);
|
|
|
+
|
|
|
+ BimUploadParam param = new BimUploadParam();
|
|
|
+ String callBackUrl = "http://" + request.getServerName() //服务器地址
|
|
|
+ + ":"
|
|
|
+ + request.getServerPort() //端口号
|
|
|
+ + request.getRequestURI().replace("bim","callBack");
|
|
|
+ param.setTask(projectBim.getBimId().toString());
|
|
|
+ param.setProjectName(projectName);
|
|
|
+ param.setSource(request.getContextPath());
|
|
|
+ param.setCallBack(callBackUrl);
|
|
|
+ param.setFileName(projectBim.getFileName());
|
|
|
+ param.setFileUrl(projectBim.getBimLocalFilePath());
|
|
|
+
|
|
|
JSONObject jsonObject = bimClient.bimUpload(param);
|
|
|
if(jsonObject.getInteger("code") !=200){
|
|
|
throw new BusinessException(ResultCode.UPLOAD_BIM_ERROR);
|
|
@@ -108,6 +115,7 @@ public class UploadController extends BaseController {
|
|
|
throw new BusinessException(ResultCode.UPLOAD_BIM_ERROR);
|
|
|
} finally {
|
|
|
projectBimService.updateById(projectBim);
|
|
|
+ assert localFile != null;
|
|
|
localFile.delete();
|
|
|
}
|
|
|
return ResultData.ok(projectBim);
|