SceneFileController.java 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. package com.fdkankan.contro.controller;
  2. import cn.hutool.core.collection.CollUtil;
  3. import com.alibaba.fastjson.JSON;
  4. import com.alibaba.fastjson.JSONArray;
  5. import com.alibaba.fastjson.JSONObject;
  6. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  7. import com.fdkankan.common.constant.CommonSuccessStatus;
  8. import com.fdkankan.common.constant.ErrorCode;
  9. import com.fdkankan.common.constant.SceneSource;
  10. import com.fdkankan.common.exception.BusinessException;
  11. import com.fdkankan.contro.annotation.SignVerification;
  12. import com.fdkankan.contro.entity.ScenePlus;
  13. import com.fdkankan.contro.entity.SceneZxgd;
  14. import com.fdkankan.contro.service.*;
  15. import com.fdkankan.contro.vo.ReportFailLogVO;
  16. import com.fdkankan.contro.vo.ResponseSceneFile;
  17. import com.fdkankan.contro.vo.SceneParam;
  18. import com.fdkankan.contro.vo.SceneUploadCountParamVO;
  19. import com.fdkankan.fyun.config.FYunFileConfig;
  20. import com.fdkankan.fyun.face.FYunFileServiceInterface;
  21. import com.fdkankan.web.response.ResultData;
  22. import lombok.extern.log4j.Log4j2;
  23. import org.apache.commons.lang3.StringUtils;
  24. import org.springframework.beans.factory.annotation.Autowired;
  25. import org.springframework.web.bind.annotation.*;
  26. import javax.annotation.Resource;
  27. import javax.validation.Valid;
  28. import java.io.IOException;
  29. import java.util.*;
  30. import java.util.stream.Collectors;
  31. /**
  32. * 场景文件上传模块
  33. */
  34. @Log4j2
  35. @RestController
  36. @RequestMapping("/api/scene/file")
  37. public class SceneFileController{
  38. @Autowired
  39. private ISceneFileBuildService sceneFileBuildService;
  40. @Resource
  41. private FYunFileServiceInterface fYunFileService;
  42. @Autowired
  43. private ISceneUploadCountService sceneUploadCountService;
  44. @Autowired
  45. private IAppCameraFailLogService appCameraFailLogService;
  46. @Autowired
  47. private IScenePlusService scenePlusService;
  48. @Autowired
  49. ISceneProService sceneProService;
  50. /**
  51. * 场景文件上传之前先获取fileId
  52. * @param params
  53. * @return
  54. * @throws Exception
  55. */
  56. @PostMapping("preUpload")
  57. public ResponseSceneFile preUpload(String params) throws Exception {
  58. return sceneFileBuildService.preUpload(params);
  59. }
  60. /**
  61. * 更新fileid文件的上传状态 - 后端八目上传逻辑
  62. *
  63. * @param params
  64. * @return
  65. */
  66. @PostMapping("uploadSuccessBuild")
  67. public ResultData uploadSuccessBuild(String params) throws Exception {
  68. return sceneFileBuildService.uploadSuccessBuild(params);
  69. }
  70. /**
  71. *
  72. *
  73. * @param params
  74. * @return
  75. */
  76. @PostMapping("turntableUploadSuccess")
  77. public ResultData turntableUploadSuccess(String params) throws Exception {
  78. return sceneFileBuildService.turntableUploadSuccess(params);
  79. }
  80. /**
  81. *
  82. *
  83. * @param params
  84. * @return
  85. */
  86. @SignVerification
  87. @PostMapping("reverseScene")
  88. public ResultData reverseScene(@RequestBody JSONObject params) throws Exception {
  89. return sceneFileBuildService.reverseScene(params);
  90. }
  91. @SignVerification
  92. @GetMapping("rebuildScene")
  93. public ResultData rebuildScene(@RequestParam(value = "num") String num,
  94. @RequestParam(value = "force",defaultValue = "false") Boolean force ,
  95. @RequestParam(value = "deleteExtras",defaultValue = "true") Boolean deleteExtras,
  96. @RequestParam(value = "from", defaultValue = "api") String from) throws IOException {
  97. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(num);
  98. if(Objects.nonNull(scenePlus) && scenePlus.getSceneSource() == SceneSource.E57.code()){
  99. return sceneFileBuildService.rebuildSceneE57(num,force,deleteExtras, from);
  100. }
  101. return sceneFileBuildService.rebuildScene(num,force,deleteExtras, from);
  102. }
  103. /**
  104. * 国际八目相机调用
  105. * @param params
  106. * @return
  107. * @throws Exception
  108. */
  109. @PostMapping("getS3UploadUrl")
  110. public ResultData getS3UploadUrl(String params) throws Exception {
  111. log.info("getS3UploadUrl 参数:{}",params);
  112. if (StringUtils.isEmpty(params)) {
  113. throw new BusinessException(ErrorCode.PARAM_ERROR,"params为空。");
  114. }
  115. JSONObject jsonObject = JSON.parseObject(params);
  116. if(jsonObject == null){
  117. throw new BusinessException(ErrorCode.PARAM_ERROR,"params为空。");
  118. }
  119. JSONArray files = jsonObject.getJSONArray("Files");
  120. if(files == null){
  121. throw new BusinessException(ErrorCode.PARAM_ERROR,"params为空。");
  122. }
  123. List<String> urls = new ArrayList<>();
  124. for(int i = 0, len = files.size(); i < len; i++){
  125. urls.add(files.getJSONObject(i).getString("filename"));
  126. }
  127. Map<String, String> uploadS3Url = getUploadS3Url(urls);
  128. return ResultData.ok(uploadS3Url);
  129. }
  130. private Map<String, String> getUploadS3Url(List<String> urls) {
  131. if(urls == null || urls.size() <= 0){
  132. return null;
  133. }
  134. Map<String, String> map = new HashMap();
  135. for(String path : urls){
  136. map.put(path, fYunFileService.getPresignedUrl(path).toString());
  137. }
  138. return map;
  139. }
  140. @SignVerification
  141. @GetMapping("copyDataAndBuild")
  142. public ResultData copyDataAndBuild(@RequestParam(value = "dataSource") String dataSource,@RequestParam(value = "sceneVer") String sceneVer,
  143. @RequestParam(value = "sourceBucket") String sourceBucket) throws Exception {
  144. return sceneFileBuildService.copyDataAndBuild(sourceBucket,dataSource ,sceneVer);
  145. }
  146. /**
  147. * 记录app触发上传场景
  148. * @param param
  149. * @return
  150. */
  151. @SignVerification
  152. @PostMapping("/increSceneUploadCount")
  153. public ResultData increSceneUploadCount(@RequestBody @Valid SceneUploadCountParamVO param){
  154. sceneUploadCountService.increSceneUploadCount(param);
  155. return ResultData.ok();
  156. }
  157. @SignVerification
  158. @PostMapping("/reportFailLog")
  159. public ResultData reportFailLog(@RequestBody @Valid ReportFailLogVO param){
  160. appCameraFailLogService.reportFailLog(param);
  161. return ResultData.ok();
  162. }
  163. /**
  164. * 计算理光相机格式场景
  165. * @return
  166. */
  167. @SignVerification
  168. @PostMapping("uploadLiguang")
  169. public ResultData uploadLiguang(String num, String snCode, String ossPath) throws Exception {
  170. return sceneFileBuildService.uploadLiguang(num, snCode, ossPath);
  171. }
  172. /**
  173. *
  174. * 激光场景生成obj文件
  175. */
  176. @SignVerification
  177. @PostMapping(value = "/generateObjFile")
  178. public ResultData generateObjFile(@RequestBody SceneParam requestScene) throws Exception{
  179. String num = requestScene.getSceneNum();
  180. if (StringUtils.isEmpty(num)) {
  181. throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
  182. }
  183. sceneProService.generateObjFile(num);
  184. return ResultData.ok();
  185. }
  186. @Autowired
  187. private ISceneZxgdService sceneZxgdService;
  188. @Resource
  189. FYunFileConfig fYunFileConfig;
  190. @GetMapping("/getZxgd/{search}")
  191. public ResultData getZxgd(@PathVariable(value = "search") String search) throws Exception{
  192. LambdaQueryWrapper<SceneZxgd> wrapper = new LambdaQueryWrapper<>();
  193. wrapper.like(SceneZxgd::getTitle, search).or().like(SceneZxgd::getUnicode, search);
  194. List<SceneZxgd> list = sceneZxgdService.list(wrapper);
  195. if(CollUtil.isEmpty(list)){
  196. return ResultData.ok();
  197. }
  198. List<JSONObject> collect = list.stream().map(v -> {
  199. JSONObject jsonObject = new JSONObject();
  200. jsonObject.put("名称", v.getTitle());
  201. jsonObject.put("unicode", v.getUnicode());
  202. jsonObject.put("状态", CommonSuccessStatus.get(v.getStatus()).message());
  203. jsonObject.put("原始资源路径", "home/" + v.getUnicode().split("_")[0] + "/" + v.getFileId() + "/" + v.getUnicode());
  204. jsonObject.put("下载地址", fYunFileConfig.getHost() + "zxgd/" + v.getUnicode() + "/mesh.ply?v=" + Calendar.getInstance().getTimeInMillis());
  205. return jsonObject;
  206. }).collect(Collectors.toList());
  207. return ResultData.ok(collect);
  208. }
  209. }