SceneFileController.java 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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.IAppCameraFailLogService;
  8. import com.fdkankan.contro.service.ISceneFileBuildService;
  9. import com.fdkankan.contro.service.ISceneUploadCountService;
  10. import com.fdkankan.contro.vo.ReportFailLogVO;
  11. import com.fdkankan.contro.vo.ResponseSceneFile;
  12. import com.fdkankan.contro.vo.SceneUploadCountParamVO;
  13. import com.fdkankan.fyun.face.FYunFileServiceInterface;
  14. import com.fdkankan.web.response.ResultData;
  15. import lombok.extern.log4j.Log4j2;
  16. import org.apache.commons.lang3.StringUtils;
  17. import org.springframework.beans.factory.annotation.Autowired;
  18. import org.springframework.web.bind.annotation.*;
  19. import org.springframework.web.multipart.MultipartFile;
  20. import javax.validation.Valid;
  21. import java.io.IOException;
  22. import java.util.ArrayList;
  23. import java.util.HashMap;
  24. import java.util.List;
  25. import java.util.Map;
  26. /**
  27. * 场景文件上传模块
  28. */
  29. @Log4j2
  30. @RestController
  31. @RequestMapping("/api/scene/file")
  32. public class SceneFileController{
  33. @Autowired
  34. private ISceneFileBuildService sceneFileBuildService;
  35. @Autowired
  36. private FYunFileServiceInterface fYunFileService;
  37. @Autowired
  38. private ISceneUploadCountService sceneUploadCountService;
  39. @Autowired
  40. private IAppCameraFailLogService appCameraFailLogService;
  41. /**
  42. * 场景文件上传之前先获取fileId
  43. * @param params
  44. * @return
  45. * @throws Exception
  46. */
  47. @PostMapping("preUpload")
  48. public ResponseSceneFile preUpload(String params) throws Exception {
  49. return sceneFileBuildService.preUpload(params);
  50. }
  51. /**
  52. * 更新fileid文件的上传状态 - 后端八目上传逻辑
  53. *
  54. * @param params
  55. * @return
  56. */
  57. @PostMapping("uploadSuccessBuild")
  58. public ResultData uploadSuccessBuild(String params) throws Exception {
  59. return sceneFileBuildService.uploadSuccessBuild(params);
  60. }
  61. /**
  62. *
  63. *
  64. * @param params
  65. * @return
  66. */
  67. @PostMapping("turntableUploadSuccess")
  68. public ResultData turntableUploadSuccess(String params) throws Exception {
  69. return sceneFileBuildService.turntableUploadSuccess(params);
  70. }
  71. @GetMapping("rebuildScene")
  72. public ResultData rebuildScene(@RequestParam(value = "num") String num,
  73. @RequestParam(value = "force",defaultValue = "false") Boolean force ,
  74. @RequestParam(value = "deleteExtras",defaultValue = "true") Boolean deleteExtras,
  75. @RequestParam(value = "from", defaultValue = "api") String from) throws IOException {
  76. return sceneFileBuildService.rebuildScene(num,force,deleteExtras, from);
  77. }
  78. /**
  79. * 单个文件上传
  80. * @param file
  81. * @param params
  82. * @return
  83. */
  84. @PostMapping("upload")
  85. public ResultData upload(@RequestParam(value = "file",required = false) MultipartFile file,
  86. String params) throws Exception {
  87. return sceneFileBuildService.uploadFile(file, params);
  88. }
  89. /**
  90. * 自定义上传
  91. * @param file
  92. * @param params
  93. * @return
  94. */
  95. @PostMapping("uploadCustom")
  96. public ResultData uploadCustom(@RequestParam(value = "file") MultipartFile file,
  97. String path) throws Exception {
  98. return sceneFileBuildService.uploadFileCustom(file, path);
  99. }
  100. /**
  101. * 国际八目相机调用
  102. * @param params
  103. * @return
  104. * @throws Exception
  105. */
  106. @PostMapping("getS3UploadUrl")
  107. public ResultData getS3UploadUrl(String params) throws Exception {
  108. log.info("getS3UploadUrl 参数:{}",params);
  109. if (StringUtils.isEmpty(params)) {
  110. throw new BusinessException(ErrorCode.PARAM_ERROR,"params为空。");
  111. }
  112. JSONObject jsonObject = JSON.parseObject(params);
  113. if(jsonObject == null){
  114. throw new BusinessException(ErrorCode.PARAM_ERROR,"params为空。");
  115. }
  116. JSONArray files = jsonObject.getJSONArray("Files");
  117. if(files == null){
  118. throw new BusinessException(ErrorCode.PARAM_ERROR,"params为空。");
  119. }
  120. List<String> urls = new ArrayList<>();
  121. for(int i = 0, len = files.size(); i < len; i++){
  122. urls.add(files.getJSONObject(i).getString("filename"));
  123. }
  124. Map<String, String> uploadS3Url = getUploadS3Url(urls);
  125. return ResultData.ok(uploadS3Url);
  126. }
  127. private Map<String, String> getUploadS3Url(List<String> urls) {
  128. if(urls == null || urls.size() <= 0){
  129. return null;
  130. }
  131. Map<String, String> map = new HashMap();
  132. for(String path : urls){
  133. map.put(path, fYunFileService.getPresignedUrl(path).toString());
  134. }
  135. return map;
  136. }
  137. @GetMapping("copyDataAndBuild")
  138. public ResultData copyDataAndBuild(@RequestParam(value = "dataSource") String dataSource,@RequestParam(value = "sceneVer") String sceneVer,
  139. @RequestParam(value = "sourceBucket") String sourceBucket) throws Exception {
  140. return sceneFileBuildService.copyDataAndBuild(sourceBucket,dataSource ,sceneVer);
  141. }
  142. /**
  143. * 记录app触发上传场景
  144. * @param param
  145. * @return
  146. */
  147. @PostMapping("/increSceneUploadCount")
  148. public ResultData increSceneUploadCount(@RequestBody @Valid SceneUploadCountParamVO param){
  149. sceneUploadCountService.increSceneUploadCount(param);
  150. return ResultData.ok();
  151. }
  152. @PostMapping("/reportFailLog")
  153. public ResultData reportFailLog(@RequestBody @Valid ReportFailLogVO param){
  154. appCameraFailLogService.reportFailLog(param);
  155. return ResultData.ok();
  156. }
  157. /**
  158. * 计算理光相机格式场景
  159. * @return
  160. */
  161. @PostMapping("uploadLiguang")
  162. public ResultData uploadLiguang(String num, String snCode, String ossPath) throws Exception {
  163. return sceneFileBuildService.uploadLiguang(num, snCode, ossPath);
  164. }
  165. }