|
@@ -1,27 +1,35 @@
|
|
|
package com.fdkankan.site.controller;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.fdkankan.site.common.BaseController;
|
|
|
import com.fdkankan.site.common.FilePath;
|
|
|
import com.fdkankan.site.common.ResultCode;
|
|
|
import com.fdkankan.site.common.ResultData;
|
|
|
import com.fdkankan.site.common.util.UploadToOssUtil;
|
|
|
+import com.fdkankan.site.common.util.VUtils;
|
|
|
import com.fdkankan.site.entity.ProjectBim;
|
|
|
import com.fdkankan.site.exception.BusinessException;
|
|
|
+import com.fdkankan.site.httpClient.bim.BimCallBackDTO;
|
|
|
+import com.fdkankan.site.httpClient.bim.BimFaceVO;
|
|
|
+import com.fdkankan.site.httpClient.bim.BimUploadParam;
|
|
|
+import com.fdkankan.site.httpClient.bim.BusinessStatus;
|
|
|
+import com.fdkankan.site.httpClient.client.BimClient;
|
|
|
import com.fdkankan.site.service.IProjectBimService;
|
|
|
import com.fdkankan.site.service.impl.UploadService;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
-import org.springframework.web.bind.annotation.PostMapping;
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
-import org.springframework.web.bind.annotation.RequestParam;
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.io.File;
|
|
|
|
|
|
+@Slf4j
|
|
|
@RestController
|
|
|
@RequestMapping("/upload")
|
|
|
-public class UploadController {
|
|
|
+public class UploadController extends BaseController {
|
|
|
|
|
|
@Autowired
|
|
|
UploadService uploadService;
|
|
@@ -32,6 +40,8 @@ public class UploadController {
|
|
|
private String queryPath;
|
|
|
@Autowired
|
|
|
private IProjectBimService projectBimService;
|
|
|
+ @Resource
|
|
|
+ BimClient bimClient;
|
|
|
|
|
|
|
|
|
@PostMapping("/file")
|
|
@@ -43,11 +53,58 @@ public class UploadController {
|
|
|
}
|
|
|
|
|
|
@PostMapping("/bim")
|
|
|
- public ResultData bim(@RequestParam(required = false) MultipartFile file) {
|
|
|
+ public ResultData bim(@RequestParam(required = false) MultipartFile file,@RequestParam(required = false)String projectName) {
|
|
|
+ VUtils.isTure(file == null || file.getSize() <=0 ).throwMessage(ResultCode.PARAM_MISS);
|
|
|
+ VUtils.isTure(StringUtils.isBlank(projectName)).throwMessage(ResultCode.PARAM_MISS);
|
|
|
File localFile = uploadService.uploadFile(file);
|
|
|
ProjectBim projectBim = new ProjectBim();
|
|
|
projectBim.setBimLocalFilePath(localFile.getPath());
|
|
|
projectBimService.save(projectBim);
|
|
|
- return ResultData.ok(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);
|
|
|
+ try {
|
|
|
+ JSONObject jsonObject = bimClient.bimUpload(localFile.getPath(), JSONObject.toJSONString(param));
|
|
|
+ if(jsonObject.getInteger("code") !=200){
|
|
|
+ throw new BusinessException(ResultCode.UPLOAD_BIM_ERROR);
|
|
|
+ }
|
|
|
+ BimFaceVO faceVO = JSONObject.parseObject(jsonObject.getString("data"),BimFaceVO.class);
|
|
|
+ projectBim.setBimStatus(faceVO.getCallType());
|
|
|
+ projectBim.setBimServiceId(faceVO.getId());
|
|
|
+ }catch (Exception e){
|
|
|
+ projectBim.setBimStatus("ERROR");
|
|
|
+ throw new BusinessException(ResultCode.UPLOAD_BIM_ERROR);
|
|
|
+ } finally {
|
|
|
+ projectBimService.updateById(projectBim);
|
|
|
+ localFile.delete();
|
|
|
+ }
|
|
|
+ return ResultData.ok(projectBim);
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/callBack")
|
|
|
+ public ResultData callBack(@RequestBody BimCallBackDTO param){
|
|
|
+ log.info("bim-service-callBack:{}",param);
|
|
|
+ String task = param.getTask();
|
|
|
+ ProjectBim bim = projectBimService.getById(Integer.valueOf(task));
|
|
|
+ bim.setBimStatus(param.getCallType());
|
|
|
+ if(param.getCallType().equals(BusinessStatus.DONE.getInfo())){ //完成
|
|
|
+ JSONObject jsonObject = bimClient.fileInfoById(bim.getBimServiceId());
|
|
|
+ if(jsonObject.getInteger("code") !=200){
|
|
|
+ bim.setBimStatus("ERROR");
|
|
|
+ }else {
|
|
|
+ BimFaceVO faceVO = JSONObject.parseObject(jsonObject.getString("data"),BimFaceVO.class);
|
|
|
+ bim.setBimOssFilePath(faceVO.getOssUrl());
|
|
|
+ }
|
|
|
+ bim.setUpdateTime(null);
|
|
|
+ projectBimService.updateById(bim);
|
|
|
+ }
|
|
|
+ return ResultData.ok();
|
|
|
}
|
|
|
}
|