SceneFileController.java 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. package com.fdkankan.contro.controller;
  2. import cn.hutool.core.io.FileUtil;
  3. import cn.hutool.core.util.ZipUtil;
  4. import cn.hutool.http.HttpUtil;
  5. import com.alibaba.fastjson.JSON;
  6. import com.alibaba.fastjson.JSONObject;
  7. import com.fdkankan.common.constant.ErrorCode;
  8. import com.fdkankan.common.exception.BusinessException;
  9. import com.fdkankan.common.util.FileUtils;
  10. import com.fdkankan.contro.bean.SendCallAlgorithmDetail;
  11. import com.fdkankan.contro.entity.User;
  12. import com.alibaba.fastjson.JSON;
  13. import com.alibaba.fastjson.JSONArray;
  14. import com.alibaba.fastjson.JSONObject;
  15. import com.fdkankan.common.constant.ErrorCode;
  16. import com.fdkankan.common.exception.BusinessException;
  17. import com.fdkankan.contro.service.ISceneFileBuildService;
  18. import com.fdkankan.contro.vo.ResponseSceneFile;
  19. import com.fdkankan.contro.vo.SendCallAlgorithmParam;
  20. import com.fdkankan.fyun.face.FYunFileServiceInterface;
  21. import com.fdkankan.model.constants.ConstantFilePath;
  22. import com.fdkankan.fyun.face.FYunFileServiceInterface;
  23. import com.fdkankan.web.response.ResultData;
  24. import lombok.extern.log4j.Log4j2;
  25. import org.apache.commons.lang3.ObjectUtils;
  26. import org.apache.commons.lang3.StringUtils;
  27. import org.springframework.beans.factory.annotation.Autowired;
  28. import org.springframework.validation.annotation.Validated;
  29. import org.springframework.web.bind.annotation.*;
  30. import org.springframework.web.multipart.MultipartFile;
  31. import org.springframework.web.bind.annotation.*;
  32. import java.io.File;
  33. import java.io.IOException;
  34. import java.util.Date;
  35. import java.util.Map;
  36. import java.util.concurrent.CompletableFuture;
  37. import java.util.ArrayList;
  38. import java.util.HashMap;
  39. import java.util.List;
  40. import java.util.Map;
  41. /**
  42. * 场景文件上传模块
  43. */
  44. @Log4j2
  45. @RestController
  46. @RequestMapping("/api/scene/file")
  47. public class SceneFileController{
  48. @Autowired
  49. private ISceneFileBuildService sceneFileBuildService;
  50. @Autowired
  51. private FYunFileServiceInterface fYunFileService;
  52. /**
  53. * 场景文件上传之前先获取fileId
  54. * @param params
  55. * @return
  56. * @throws Exception
  57. */
  58. @PostMapping("preUpload")
  59. public ResponseSceneFile preUpload(String params) throws Exception {
  60. return sceneFileBuildService.preUpload(params);
  61. }
  62. /**
  63. * 更新fileid文件的上传状态 - 后端八目上传逻辑
  64. *
  65. * @param params
  66. * @return
  67. */
  68. @PostMapping("uploadSuccessBuild")
  69. public ResultData uploadSuccessBuild(String params) throws Exception {
  70. return sceneFileBuildService.uploadSuccessBuild(params);
  71. }
  72. /**
  73. *
  74. *
  75. * @param params
  76. * @return
  77. */
  78. @PostMapping("turntableUploadSuccess")
  79. public ResultData turntableUploadSuccess(String params) throws Exception {
  80. return sceneFileBuildService.turntableUploadSuccess(params);
  81. }
  82. @GetMapping("rebuildScene")
  83. public ResultData rebuildScene(@RequestParam(value = "num") String num,@RequestParam(value = "force",defaultValue = "false") Boolean force ,@RequestParam(value = "deleteExtras",defaultValue = "true") Boolean deleteExtras) throws IOException {
  84. return sceneFileBuildService.rebuildScene(num,force,deleteExtras);
  85. }
  86. /**
  87. * 国际八目相机调用
  88. * @param params
  89. * @return
  90. * @throws Exception
  91. */
  92. @PostMapping("getS3UploadUrl")
  93. public ResultData getS3UploadUrl(String params) throws Exception {
  94. log.info("getS3UploadUrl 参数:{}",params);
  95. if (StringUtils.isEmpty(params)) {
  96. throw new BusinessException(ErrorCode.PARAM_ERROR,"params为空。");
  97. }
  98. JSONObject jsonObject = JSON.parseObject(params);
  99. if(jsonObject == null){
  100. throw new BusinessException(ErrorCode.PARAM_ERROR,"params为空。");
  101. }
  102. JSONArray files = jsonObject.getJSONArray("Files");
  103. if(files == null){
  104. throw new BusinessException(ErrorCode.PARAM_ERROR,"params为空。");
  105. }
  106. List<String> urls = new ArrayList<>();
  107. for(int i = 0, len = files.size(); i < len; i++){
  108. urls.add(files.getJSONObject(i).getString("filename"));
  109. }
  110. Map<String, String> uploadS3Url = getUploadS3Url(urls);
  111. return ResultData.ok(uploadS3Url);
  112. }
  113. private Map<String, String> getUploadS3Url(List<String> urls) {
  114. if(urls == null || urls.size() <= 0){
  115. return null;
  116. }
  117. Map<String, String> map = new HashMap();
  118. for(String path : urls){
  119. map.put(path, fYunFileService.getPresignedUrl(path).toString());
  120. }
  121. return map;
  122. }
  123. // @GetMapping("copyDataAndBuild")
  124. // public ResultData copyDataAndBuild(@RequestParam(value = "dataSource") String dataSource,@RequestParam(value = "sceneVer") String sceneVer,
  125. // @RequestParam(value = "sourceBucket") String sourceBucket) throws Exception {
  126. // return sceneFileBuildService.copyDataAndBuild(sourceBucket,dataSource ,sceneVer);
  127. // }
  128. /**
  129. * 单个文件上传
  130. * @param file
  131. * @param params
  132. * @return
  133. */
  134. @PostMapping("upload")
  135. public ResultData upload(@RequestParam(value = "file",required = false) MultipartFile file,
  136. String params) throws Exception {
  137. return sceneFileBuildService.uploadFile(file, params);
  138. }
  139. /**
  140. * 单个文件上传
  141. * @param file
  142. * @param params
  143. * @return
  144. */
  145. @PostMapping("testUpload")
  146. public ResultData testUpload(@RequestParam(value = "file",required = false) MultipartFile file,
  147. String params) throws Exception {
  148. file.transferTo(new File("/home/backend/tomcat/modeling-control/logs/" + file.getOriginalFilename()));
  149. return ResultData.ok();
  150. }
  151. /**
  152. * 本地上传相机原始资源压缩包,通知计算
  153. * @return
  154. * @throws Exception
  155. */
  156. @PostMapping("sendCallAlgorithm")
  157. public ResultData sendCallAlgorithm(@RequestBody @Validated SendCallAlgorithmParam param) throws Exception {
  158. return sceneFileBuildService.sendCallAlgorithm(param);
  159. }
  160. /**
  161. * 本地上传相机原始资源压缩包,通知计算
  162. * @param params
  163. * @return
  164. * @throws Exception
  165. */
  166. @PostMapping("test1")
  167. public ResultData test1(@RequestBody Map<String,Object> params) throws Exception {
  168. log.info("test1场景计算进度:{}", JSON.toJSONString(params));
  169. return ResultData.ok();
  170. }
  171. /**
  172. * 本地上传相机原始资源压缩包,通知计算
  173. * @param params
  174. * @return
  175. * @throws Exception
  176. */
  177. @PostMapping("test2")
  178. public ResultData test2(@RequestBody Map<String,Object> params) throws Exception {
  179. log.info("test2场景计算进度:{}", JSON.toJSONString(params));
  180. return ResultData.ok();
  181. }
  182. // @PostMapping("upload_bd")
  183. // public ResultData uploadBd(MultipartFile file){
  184. //
  185. // }
  186. @PostMapping("uploadFile")
  187. public ResultData uploadFile(@RequestBody @Validated SendCallAlgorithmParam param) throws Exception {
  188. return sceneFileBuildService.uploadFile(param);
  189. }
  190. @PostMapping("/noticeBuild")
  191. public ResultData noticeBuild(String uuid) throws Exception {
  192. return sceneFileBuildService.noticeBuild(uuid);
  193. }
  194. @PostMapping("/send_bd")
  195. public ResultData noticeBuildBd(String uuid) throws Exception {
  196. String prefix = "http://192.168.0.25/oss/bd_server/" + uuid + "/";
  197. String path = "/oss/4dkankan/bd_server/" + uuid;
  198. // List<String> strings = FileUtil.listFileNames(path);
  199. List<String> strings = new ArrayList<>();
  200. strings.add("asdf.jpeg");
  201. strings.parallelStream().forEach(fileName ->{
  202. String url = prefix.concat(fileName);
  203. SendCallAlgorithmDetail detail = new SendCallAlgorithmDetail();
  204. detail.setFileName(fileName);
  205. detail.setUuid(uuid);
  206. SendCallAlgorithmParam param = new SendCallAlgorithmParam();
  207. param.setFilepath(url);
  208. param.setDetails(detail);
  209. HttpUtil.post("http://localhost:8085/api/scene/file/uploadFile", JSON.toJSONString(param));
  210. });
  211. return ResultData.ok();
  212. }
  213. public static void main(String[] args) {
  214. List<String> strings = FileUtil.listFileNames("D:\\test5\\aaa");
  215. System.out.println(JSON.toJSONString(strings));
  216. }
  217. }