UploadController.java 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. package com.fdkankan.manage_jp.controller;
  2. import cn.hutool.core.io.FileUtil;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.fdkankan.fyun.face.FYunFileServiceInterface;
  5. import com.fdkankan.manage_jp.common.Constant;
  6. import com.fdkankan.manage_jp.common.Result;
  7. import com.fdkankan.manage_jp.common.ResultCode;
  8. import com.fdkankan.manage_jp.exception.BusinessException;
  9. import com.fdkankan.manage_jp.httpClient.client.FdKKClient;
  10. import com.fdkankan.manage_jp.httpClient.param.UploadEditSceneParam;
  11. import lombok.extern.slf4j.Slf4j;
  12. import org.springframework.beans.factory.annotation.Autowired;
  13. import org.springframework.web.bind.annotation.PostMapping;
  14. import org.springframework.web.bind.annotation.RequestMapping;
  15. import org.springframework.web.bind.annotation.RequestParam;
  16. import org.springframework.web.bind.annotation.RestController;
  17. import org.springframework.web.multipart.MultipartFile;
  18. import java.io.File;
  19. import java.io.IOException;
  20. import java.util.UUID;
  21. @RestController
  22. @RequestMapping("/manage_jp/file")
  23. @Slf4j
  24. public class UploadController extends BaseController{
  25. @Autowired
  26. FYunFileServiceInterface fYunFileServiceInterface;
  27. @PostMapping("/uploadImg")
  28. public Result uploadImg(@RequestParam("file") MultipartFile file) throws IOException {
  29. Long date = System.currentTimeMillis();
  30. String fileName = date + file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
  31. String filePath = Constant.AGENT_PATH + "company" + File.separator + fileName;
  32. File targetFile = new File(filePath);
  33. if(!targetFile.getParentFile().exists()){
  34. targetFile.getParentFile().mkdirs();
  35. }
  36. file.transferTo(targetFile);
  37. String url = fYunFileServiceInterface.uploadFile(filePath,"img/".concat(fileName));
  38. return Result.success("",url);
  39. }
  40. @Autowired
  41. FdKKClient fdKKClient;
  42. @PostMapping("/uploadE57")
  43. public Result uploadE57(@RequestParam("file") MultipartFile file,Integer isObj) {
  44. String originalFilename = file.getOriginalFilename();
  45. String suffix = originalFilename.substring(originalFilename.lastIndexOf("."));
  46. if(!suffix.equals(".e57")){
  47. throw new BusinessException(ResultCode.UPLOAD_ERROR2);
  48. }
  49. try {
  50. String newFileName = UUID.randomUUID().toString().replace("-","");
  51. String filePath = Constant.MANAGE_PATH + "e57" + File.separator + newFileName +suffix;
  52. File targetFile = new File(filePath);
  53. if(!targetFile.getParentFile().exists()){
  54. targetFile.getParentFile().mkdirs();
  55. }
  56. file.transferTo(targetFile);
  57. fYunFileServiceInterface.uploadFile(filePath,filePath.replace(Constant.MANAGE_PATH,"manage/"));
  58. FileUtil.del(targetFile);
  59. UploadEditSceneParam editSceneParam = new UploadEditSceneParam();
  60. editSceneParam.setTitle(originalFilename.replace(suffix,""));
  61. editSceneParam.setUserId(getUser().getId());
  62. editSceneParam.setPath(filePath.replace(Constant.MANAGE_PATH,"manage/"));
  63. editSceneParam.setIsObj(isObj);
  64. editSceneParam.setOtherType("E57_V4");
  65. JSONObject jsonObject = fdKKClient.reverseScene(editSceneParam);
  66. Integer code = jsonObject.getInteger("code");
  67. if(code != 0){
  68. log.info("调用失败-toFdCreateScene:{}",jsonObject);
  69. throw new BusinessException(ResultCode.UPLOAD_ERROR);
  70. }
  71. }catch (Exception e){
  72. log.info("调用失败-toFdCreateScene:",e);
  73. throw new BusinessException(ResultCode.UPLOAD_ERROR);
  74. }
  75. return Result.success();
  76. }
  77. }