Bläddra i källkod

上传bim完善

lyhzzz 2 år sedan
förälder
incheckning
02903b8ae6

+ 2 - 1
src/main/java/com/fdkankan/site/common/ResultCode.java

@@ -16,7 +16,8 @@ public enum ResultCode {
     UPLOAD_FILE_TO_LONG(7003,"文件上传过大"),
     UPLOAD_BIM_ERROR(7004,"上传调用bim失败"),
     UPLOAD_BIM_EXIST(7005,"bim已上传,删除可再次删除"),
-    UPLOAD_FILE_MSG_ERROR(7006,"文件内容错误"),
+    UPLOAD_BIM_ING(7006,"bim上传中,请稍后"),
+    UPLOAD_FILE_MSG_ERROR(7007,"文件内容错误"),
     ;
     public int code;
     public String msg;

+ 31 - 23
src/main/java/com/fdkankan/site/controller/UploadController.java

@@ -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);