SceneFileController.java 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. package com.fdkankan.contro.controller;
  2. import cn.hutool.core.codec.Base64;
  3. import com.alibaba.fastjson.JSON;
  4. import com.alibaba.fastjson.JSONArray;
  5. import com.alibaba.fastjson.JSONObject;
  6. import com.fdkankan.common.constant.ErrorCode;
  7. import com.fdkankan.common.constant.SceneSource;
  8. import com.fdkankan.common.exception.BusinessException;
  9. import com.fdkankan.contro.annotation.SignVerification;
  10. import com.fdkankan.contro.entity.ScenePlus;
  11. import com.fdkankan.contro.service.*;
  12. import com.fdkankan.contro.vo.ReportFailLogVO;
  13. import com.fdkankan.contro.vo.ResponseSceneFile;
  14. import com.fdkankan.contro.vo.SceneParam;
  15. import com.fdkankan.contro.vo.SceneUploadCountParamVO;
  16. import com.fdkankan.fyun.face.FYunFileServiceInterface;
  17. import com.fdkankan.web.response.ResultData;
  18. import com.fdkankan.web.util.RSAEncrypt;
  19. import lombok.extern.log4j.Log4j2;
  20. import org.apache.commons.lang3.StringUtils;
  21. import org.springframework.beans.factory.annotation.Autowired;
  22. import org.springframework.web.bind.annotation.*;
  23. import javax.annotation.Resource;
  24. import javax.validation.Valid;
  25. import java.io.IOException;
  26. import java.nio.charset.StandardCharsets;
  27. import java.util.*;
  28. /**
  29. * 场景文件上传模块
  30. */
  31. @Log4j2
  32. @RestController
  33. @RequestMapping("/api/scene/file")
  34. public class SceneFileController{
  35. @Autowired
  36. private ISceneFileBuildService sceneFileBuildService;
  37. @Resource
  38. private FYunFileServiceInterface fYunFileService;
  39. @Autowired
  40. private ISceneUploadCountService sceneUploadCountService;
  41. @Autowired
  42. private IAppCameraFailLogService appCameraFailLogService;
  43. @Autowired
  44. private IScenePlusService scenePlusService;
  45. @Autowired
  46. ISceneProService sceneProService;
  47. /**
  48. * 场景文件上传之前先获取fileId
  49. * @param params
  50. * @return
  51. * @throws Exception
  52. */
  53. @PostMapping("preUpload")
  54. public ResponseSceneFile preUpload(String params) throws Exception {
  55. return sceneFileBuildService.preUpload(params);
  56. }
  57. /**
  58. * 更新fileid文件的上传状态 - 后端八目上传逻辑
  59. *
  60. * @param params
  61. * @return
  62. */
  63. @PostMapping("uploadSuccessBuild")
  64. public ResultData uploadSuccessBuild(String params) throws Exception {
  65. return sceneFileBuildService.uploadSuccessBuild(params);
  66. }
  67. /**
  68. *
  69. *
  70. * @param params
  71. * @return
  72. */
  73. @PostMapping("turntableUploadSuccess")
  74. public ResultData turntableUploadSuccess(String params) throws Exception {
  75. return sceneFileBuildService.turntableUploadSuccess(params);
  76. }
  77. /**
  78. *
  79. *
  80. * @param params
  81. * @return
  82. */
  83. @SignVerification
  84. @PostMapping("reverseScene")
  85. public ResultData reverseScene(@RequestBody JSONObject params) throws Exception {
  86. return sceneFileBuildService.reverseScene(params);
  87. }
  88. @SignVerification
  89. @GetMapping("rebuildScene")
  90. public ResultData rebuildScene(@RequestParam(value = "num") String num,
  91. @RequestParam(value = "force",defaultValue = "false") Boolean force ,
  92. @RequestParam(value = "deleteExtras",defaultValue = "true") Boolean deleteExtras,
  93. @RequestParam(value = "from", defaultValue = "api") String from) throws IOException {
  94. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(num);
  95. if(Objects.nonNull(scenePlus) && scenePlus.getSceneSource() == SceneSource.E57.code()){
  96. return sceneFileBuildService.rebuildSceneE57(num,force,deleteExtras, from);
  97. }
  98. return sceneFileBuildService.rebuildScene(num,force,deleteExtras, from);
  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. @SignVerification
  138. @GetMapping("copyDataAndBuild")
  139. public ResultData copyDataAndBuild(@RequestParam(value = "dataSource") String dataSource,@RequestParam(value = "sceneVer") String sceneVer,
  140. @RequestParam(value = "sourceBucket") String sourceBucket) throws Exception {
  141. return sceneFileBuildService.copyDataAndBuild(sourceBucket,dataSource ,sceneVer);
  142. }
  143. /**
  144. * 记录app触发上传场景
  145. * @param param
  146. * @return
  147. */
  148. @SignVerification
  149. @PostMapping("/increSceneUploadCount")
  150. public ResultData increSceneUploadCount(@RequestBody @Valid SceneUploadCountParamVO param){
  151. sceneUploadCountService.increSceneUploadCount(param);
  152. return ResultData.ok();
  153. }
  154. @SignVerification
  155. @PostMapping("/reportFailLog")
  156. public ResultData reportFailLog(@RequestBody @Valid ReportFailLogVO param){
  157. appCameraFailLogService.reportFailLog(param);
  158. return ResultData.ok();
  159. }
  160. /**
  161. * 计算理光相机格式场景
  162. * @return
  163. */
  164. @SignVerification
  165. @PostMapping("uploadLiguang")
  166. public ResultData uploadLiguang(String num, String snCode, String ossPath) throws Exception {
  167. return sceneFileBuildService.uploadLiguang(num, snCode, ossPath);
  168. }
  169. /**
  170. *
  171. * 激光场景生成obj文件
  172. */
  173. @SignVerification
  174. @PostMapping(value = "/generateObjFile")
  175. public ResultData generateObjFile(@RequestBody SceneParam requestScene) throws Exception{
  176. String num = requestScene.getSceneNum();
  177. if (StringUtils.isEmpty(num)) {
  178. throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
  179. }
  180. sceneProService.generateObjFile(num);
  181. return ResultData.ok();
  182. }
  183. @SignVerification
  184. @PostMapping(value = "/testUpload")
  185. public ResultData testUpload(String snCode, String fileId, String uniCode) throws Exception{
  186. String params = snCode + "#" + fileId + "#" + uniCode;
  187. String encode = Base64.encode(RSAEncrypt.encrypt(RSAEncrypt.loadPublicKeyByStr(RSAEncrypt.loadPublicKeyByFile()), params.getBytes(StandardCharsets.UTF_8)));
  188. sceneFileBuildService.turntableUploadSuccess(encode);
  189. return ResultData.ok();
  190. }
  191. }