SceneFileController.java 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. package com.fdkankan.contro.controller;
  2. import cn.hutool.core.io.FileUtil;
  3. import cn.hutool.core.util.StrUtil;
  4. import cn.hutool.http.HttpUtil;
  5. import com.alibaba.fastjson.JSON;
  6. import com.alibaba.fastjson.JSONArray;
  7. import com.alibaba.fastjson.JSONObject;
  8. import com.fdkankan.common.constant.ErrorCode;
  9. import com.fdkankan.common.exception.BusinessException;
  10. import com.fdkankan.contro.bean.SendCallAlgorithmDetail;
  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.SceneUploadCountParamVO;
  15. import com.fdkankan.contro.vo.SendCallAlgorithmParam;
  16. import com.fdkankan.fyun.face.FYunFileServiceInterface;
  17. import com.fdkankan.web.response.ResultData;
  18. import lombok.extern.log4j.Log4j2;
  19. import org.apache.commons.lang3.StringUtils;
  20. import org.springframework.beans.factory.annotation.Autowired;
  21. import org.springframework.validation.annotation.Validated;
  22. import org.springframework.web.bind.annotation.*;
  23. import org.springframework.web.multipart.MultipartFile;
  24. import javax.validation.Valid;
  25. import java.io.File;
  26. import java.io.IOException;
  27. import java.util.ArrayList;
  28. import java.util.HashMap;
  29. import java.util.List;
  30. import java.util.Map;
  31. /**
  32. * 场景文件上传模块
  33. */
  34. @Log4j2
  35. @RestController
  36. @RequestMapping("/api/scene/file")
  37. public class SceneFileController{
  38. @Autowired
  39. private ISceneFileBuildService sceneFileBuildService;
  40. @Autowired
  41. private FYunFileServiceInterface fYunFileService;
  42. @Autowired
  43. private ISceneUploadCountService sceneUploadCountService;
  44. @Autowired
  45. private IAppCameraFailLogService appCameraFailLogService;
  46. @Autowired
  47. private IJmgaService jmgaService;
  48. @Autowired
  49. private UploadShootingService uploadShootingService;
  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, null);
  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, null);
  79. }
  80. @GetMapping("rebuildScene")
  81. public ResultData rebuildScene(@RequestParam(value = "num") String num,
  82. @RequestParam(value = "force",defaultValue = "false") Boolean force ,
  83. @RequestParam(value = "deleteExtras",defaultValue = "true") Boolean deleteExtras,
  84. @RequestParam(value = "from", defaultValue = "api") String from) throws IOException {
  85. return sceneFileBuildService.rebuildScene(num,force,deleteExtras, from);
  86. }
  87. /**
  88. * 国际八目相机调用
  89. * @param params
  90. * @return
  91. * @throws Exception
  92. */
  93. @PostMapping("getS3UploadUrl")
  94. public ResultData getS3UploadUrl(String params) throws Exception {
  95. log.info("getS3UploadUrl 参数:{}",params);
  96. if (StringUtils.isEmpty(params)) {
  97. throw new BusinessException(ErrorCode.PARAM_ERROR,"params为空。");
  98. }
  99. JSONObject jsonObject = JSON.parseObject(params);
  100. if(jsonObject == null){
  101. throw new BusinessException(ErrorCode.PARAM_ERROR,"params为空。");
  102. }
  103. JSONArray files = jsonObject.getJSONArray("Files");
  104. if(files == null){
  105. throw new BusinessException(ErrorCode.PARAM_ERROR,"params为空。");
  106. }
  107. List<String> urls = new ArrayList<>();
  108. for(int i = 0, len = files.size(); i < len; i++){
  109. urls.add(files.getJSONObject(i).getString("filename"));
  110. }
  111. Map<String, String> uploadS3Url = getUploadS3Url(urls);
  112. return ResultData.ok(uploadS3Url);
  113. }
  114. private Map<String, String> getUploadS3Url(List<String> urls) {
  115. if(urls == null || urls.size() <= 0){
  116. return null;
  117. }
  118. Map<String, String> map = new HashMap();
  119. for(String path : urls){
  120. map.put(path, fYunFileService.getPresignedUrl(path).toString());
  121. }
  122. return map;
  123. }
  124. // @GetMapping("copyDataAndBuild")
  125. // public ResultData copyDataAndBuild(@RequestParam(value = "dataSource") String dataSource,@RequestParam(value = "sceneVer") String sceneVer,
  126. // @RequestParam(value = "sourceBucket") String sourceBucket) throws Exception {
  127. // return sceneFileBuildService.copyDataAndBuild(sourceBucket,dataSource ,sceneVer);
  128. // }
  129. /**
  130. * 单个文件上传
  131. * @param file
  132. * @param params
  133. * @return
  134. */
  135. @PostMapping("upload")
  136. public ResultData upload(@RequestParam(value = "file",required = false) MultipartFile file,
  137. String params, @RequestParam(value = "dir", defaultValue = "") String dir) throws Exception {
  138. return sceneFileBuildService.uploadFile(file, params,dir);
  139. }
  140. /**
  141. * 单个文件上传
  142. * @param file
  143. * @param params
  144. * @return
  145. */
  146. @PostMapping("testUpload")
  147. public ResultData testUpload(@RequestParam(value = "file",required = false) MultipartFile file,
  148. String params) throws Exception {
  149. file.transferTo(new File("/home/backend/tomcat/modeling-control/logs/" + file.getOriginalFilename()));
  150. return ResultData.ok();
  151. }
  152. // /**
  153. // * 本地上传相机原始资源压缩包,通知计算
  154. // * @return
  155. // * @throws Exception
  156. // */
  157. // @PostMapping("sendCallAlgorithm")
  158. // public ResultData sendCallAlgorithm(@RequestBody @Validated SendCallAlgorithmParam param) throws Exception {
  159. // return sceneFileBuildService.sendCallAlgorithm(param);
  160. // }
  161. /**
  162. * 本地上传相机原始资源压缩包,通知计算
  163. * @param params
  164. * @return
  165. * @throws Exception
  166. */
  167. @PostMapping("test1")
  168. public ResultData test1(@RequestBody Map<String,Object> params) throws Exception {
  169. log.info("test1场景计算进度:{}", JSON.toJSONString(params));
  170. return ResultData.ok();
  171. }
  172. /**
  173. * 本地上传相机原始资源压缩包,通知计算
  174. * @param params
  175. * @return
  176. * @throws Exception
  177. */
  178. @PostMapping("test2")
  179. public ResultData test2(@RequestBody Map<String,Object> params) throws Exception {
  180. log.info("test2场景计算进度:{}", JSON.toJSONString(params));
  181. return ResultData.ok();
  182. }
  183. // @PostMapping("upload_bd")
  184. // public ResultData uploadBd(MultipartFile file){
  185. //
  186. // }
  187. @PostMapping("sendCallAlgorithm")
  188. public ResultData uploadFile(@RequestBody @Validated SendCallAlgorithmParam param) throws Exception {
  189. return sceneFileBuildService.uploadFile(param);
  190. }
  191. @PostMapping("/noticeBuild")
  192. public ResultData noticeBuild(SendCallAlgorithmDetail detail) throws Exception {
  193. if(StrUtil.isEmpty(detail.getUuid())){
  194. throw new RuntimeException("uuid不能为空");
  195. }
  196. String callType = detail.getCallType();
  197. if(StrUtil.isNotEmpty(callType) && callType.equals("UPLOAD_WHILE_SHOOTING")){
  198. uploadShootingService.build(detail);
  199. return ResultData.ok();
  200. }
  201. return sceneFileBuildService.noticeBuild(detail.getUuid(), null, null, "single");
  202. }
  203. @PostMapping("/send_bd")
  204. public ResultData noticeBuildBd(String ossHost, String uuid, String dir) throws Exception {
  205. jmgaService.noticeBuildBd(ossHost, uuid, dir);
  206. return ResultData.ok();
  207. }
  208. /**
  209. * 记录app触发上传场景
  210. * @param param
  211. * @return
  212. */
  213. @PostMapping("/increSceneUploadCount")
  214. public ResultData increSceneUploadCount(@RequestBody @Valid SceneUploadCountParamVO param){
  215. sceneUploadCountService.increSceneUploadCount(param);
  216. return ResultData.ok();
  217. }
  218. @PostMapping("/reportFailLog")
  219. public ResultData reportFailLog(@RequestBody @Valid ReportFailLogVO param){
  220. appCameraFailLogService.reportFailLog(param);
  221. return ResultData.ok();
  222. }
  223. /**
  224. * 边拍边上传文件上传
  225. */
  226. @PostMapping("uploadShooting/file")
  227. public ResultData uploadShootingFile(
  228. @RequestParam(value = "file") MultipartFile file,
  229. @RequestPart SendCallAlgorithmDetail details) throws Exception {
  230. String parentPath = "/oss/4dkankan/bd_server/upload_while_shooting/" + details.getUuid() + "/";
  231. String localPath = null;
  232. if(details.getIndex() != -1){
  233. localPath = parentPath + details.getIndex() + "/" + details.getFileName();
  234. }else{
  235. localPath = parentPath + details.getFileName();
  236. }
  237. FileUtil.mkParentDirs(localPath);
  238. String url = "https://survey.4dkankan.com" + localPath.replace("4dkankan/", "");
  239. file.transferTo(new File(localPath));
  240. SendCallAlgorithmParam param = new SendCallAlgorithmParam();
  241. param.setFilepath(url);
  242. param.setDetails(details);
  243. HttpUtil.post("http://127.0.0.1:8085/api/scene/file/sendCallAlgorithm", JSON.toJSONString(param));
  244. return ResultData.ok();
  245. }
  246. /**
  247. * 边拍边上串通知计算
  248. * @return
  249. */
  250. @PostMapping("uploadShooting/build")
  251. public ResultData uploadShootingBuild(@RequestBody SendCallAlgorithmDetail details) throws Exception {
  252. String body = "uuid=" + details.getUuid() + "&index=" + details.getIndex() + "&callType=" + details.getCallType();
  253. HttpUtil.post("http://127.0.0.1:8085/api/scene/file/noticeBuild", body);
  254. return ResultData.ok();
  255. }
  256. }