SceneFileController.java 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. package com.fdkankan.contro.controller;
  2. import com.alibaba.fastjson.JSON;
  3. import com.alibaba.fastjson.JSONArray;
  4. import com.alibaba.fastjson.JSONObject;
  5. import com.fdkankan.common.constant.ErrorCode;
  6. import com.fdkankan.common.exception.BusinessException;
  7. import com.fdkankan.contro.service.ISceneFileBuildService;
  8. import com.fdkankan.contro.vo.ResponseSceneFile;
  9. import com.fdkankan.fyun.face.FYunFileServiceInterface;
  10. import com.fdkankan.web.response.ResultData;
  11. import lombok.extern.log4j.Log4j2;
  12. import org.apache.commons.lang3.StringUtils;
  13. import org.springframework.beans.factory.annotation.Autowired;
  14. import org.springframework.web.bind.annotation.*;
  15. import java.io.IOException;
  16. import java.util.ArrayList;
  17. import java.util.HashMap;
  18. import java.util.List;
  19. import java.util.Map;
  20. /**
  21. * 场景文件上传模块
  22. */
  23. @Log4j2
  24. @RestController
  25. @RequestMapping("/api/scene/file")
  26. public class SceneFileController{
  27. @Autowired
  28. private ISceneFileBuildService sceneFileBuildService;
  29. @Autowired
  30. private FYunFileServiceInterface fYunFileService;
  31. /**
  32. * 场景文件上传之前先获取fileId
  33. * @param params
  34. * @return
  35. * @throws Exception
  36. */
  37. @PostMapping("preUpload")
  38. public ResponseSceneFile preUpload(String params) throws Exception {
  39. return sceneFileBuildService.preUpload(params);
  40. }
  41. /**
  42. * 更新fileid文件的上传状态 - 后端八目上传逻辑
  43. *
  44. * @param params
  45. * @return
  46. */
  47. @PostMapping("uploadSuccessBuild")
  48. public ResultData uploadSuccessBuild(String params) throws Exception {
  49. return sceneFileBuildService.uploadSuccessBuild(params);
  50. }
  51. /**
  52. *
  53. *
  54. * @param params
  55. * @return
  56. */
  57. @PostMapping("turntableUploadSuccess")
  58. public ResultData turntableUploadSuccess(String params) throws Exception {
  59. return sceneFileBuildService.turntableUploadSuccess(params);
  60. }
  61. @GetMapping("rebuildScene")
  62. public ResultData rebuildScene(@RequestParam(value = "num") String num,@RequestParam(value = "force",defaultValue = "false") Boolean force ,@RequestParam(value = "deleteExtras",defaultValue = "true") Boolean deleteExtras) throws IOException {
  63. return sceneFileBuildService.rebuildScene(num,force,deleteExtras);
  64. }
  65. /**
  66. * 国际八目相机调用
  67. * @param params
  68. * @return
  69. * @throws Exception
  70. */
  71. @PostMapping("getS3UploadUrl")
  72. public ResultData getS3UploadUrl(String params) throws Exception {
  73. log.info("getS3UploadUrl 参数:{}",params);
  74. if (StringUtils.isEmpty(params)) {
  75. throw new BusinessException(ErrorCode.PARAM_ERROR,"params为空。");
  76. }
  77. JSONObject jsonObject = JSON.parseObject(params);
  78. if(jsonObject == null){
  79. throw new BusinessException(ErrorCode.PARAM_ERROR,"params为空。");
  80. }
  81. JSONArray files = jsonObject.getJSONArray("Files");
  82. if(files == null){
  83. throw new BusinessException(ErrorCode.PARAM_ERROR,"params为空。");
  84. }
  85. List<String> urls = new ArrayList<>();
  86. for(int i = 0, len = files.size(); i < len; i++){
  87. urls.add(files.getJSONObject(i).getString("filename"));
  88. }
  89. Map<String, String> uploadS3Url = getUploadS3Url(urls);
  90. return ResultData.ok(uploadS3Url);
  91. }
  92. private Map<String, String> getUploadS3Url(List<String> urls) {
  93. if(urls == null || urls.size() <= 0){
  94. return null;
  95. }
  96. Map<String, String> map = new HashMap();
  97. for(String path : urls){
  98. map.put(path, fYunFileService.getPresignedUrl(path).toString());
  99. }
  100. return map;
  101. }
  102. @GetMapping("copyDataAndBuild")
  103. public ResultData copyDataAndBuild(@RequestParam(value = "num") String num,@RequestParam(value = "dataSource") String dataSource,
  104. @RequestParam(value = "sceneVer") String sceneVer,
  105. @RequestParam(value = "sourceBucket",required = false) String sourceBucket) throws Exception {
  106. return sceneFileBuildService.copyDataAndBuild(sourceBucket,dataSource ,num,sceneVer);
  107. }
  108. }