SceneFileController.java 9.5 KB

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