SceneFileController.java 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. package com.fdkankan.contro.controller;
  2. import cn.hutool.core.collection.CollUtil;
  3. import cn.hutool.core.io.FileUtil;
  4. import cn.hutool.core.util.StrUtil;
  5. import com.alibaba.fastjson.JSON;
  6. import com.alibaba.fastjson.JSONArray;
  7. import com.alibaba.fastjson.JSONObject;
  8. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  9. import com.fdkankan.common.constant.ErrorCode;
  10. import com.fdkankan.common.constant.RecStatus;
  11. import com.fdkankan.common.exception.BusinessException;
  12. import com.fdkankan.common.util.CmdUtils;
  13. import com.fdkankan.common.util.DateExtUtil;
  14. import com.fdkankan.contro.entity.SceneFileBuild;
  15. import com.fdkankan.contro.service.GzZcdjzxService;
  16. import com.fdkankan.contro.service.ISceneFileBuildService;
  17. import com.fdkankan.contro.vo.ResponseSceneFile;
  18. import com.fdkankan.fyun.config.FYunFileConfig;
  19. import com.fdkankan.fyun.face.FYunFileServiceInterface;
  20. import com.fdkankan.fyun.local.constant.LocalConstants;
  21. import com.fdkankan.model.constants.ConstantFilePath;
  22. import com.fdkankan.model.utils.SceneUtil;
  23. import com.fdkankan.web.response.ResultData;
  24. import com.fdkankan.web.util.RSAEncrypt;
  25. import lombok.extern.log4j.Log4j2;
  26. import org.apache.commons.codec.binary.Base64;
  27. import org.apache.commons.lang3.StringUtils;
  28. import org.springframework.beans.factory.annotation.Autowired;
  29. import org.springframework.web.bind.annotation.*;
  30. import org.springframework.web.multipart.MultipartFile;
  31. import javax.annotation.Resource;
  32. import java.io.IOException;
  33. import java.nio.charset.StandardCharsets;
  34. import java.util.*;
  35. /**
  36. * 场景文件上传模块
  37. */
  38. @Log4j2
  39. @RestController
  40. @RequestMapping("/api/scene/file")
  41. public class SceneFileController{
  42. @Autowired
  43. private ISceneFileBuildService sceneFileBuildService;
  44. @Autowired
  45. private FYunFileServiceInterface fYunFileService;
  46. /**
  47. * 场景文件上传之前先获取fileId
  48. * @param params
  49. * @return
  50. * @throws Exception
  51. */
  52. @PostMapping("preUpload")
  53. public ResponseSceneFile preUpload(String params) throws Exception {
  54. return sceneFileBuildService.preUpload(params);
  55. }
  56. /**
  57. * 更新fileid文件的上传状态 - 后端八目上传逻辑
  58. *
  59. * @param params
  60. * @return
  61. */
  62. @PostMapping("uploadSuccessBuild")
  63. public ResultData uploadSuccessBuild(String params) throws Exception {
  64. return sceneFileBuildService.uploadSuccessBuild(params);
  65. }
  66. /**
  67. *
  68. *
  69. * @param params
  70. * @return
  71. */
  72. @PostMapping("turntableUploadSuccess")
  73. public ResultData turntableUploadSuccess(String params) throws Exception {
  74. return sceneFileBuildService.turntableUploadSuccess(params);
  75. }
  76. /**
  77. *
  78. *
  79. * @param params
  80. * @return
  81. */
  82. @PostMapping("reverseScene")
  83. public ResultData reverseScene(@RequestBody JSONObject params) throws Exception {
  84. return sceneFileBuildService.reverseScene(params);
  85. }
  86. @GetMapping("rebuildScene")
  87. public ResultData rebuildScene(@RequestParam(value = "num") String num,@RequestParam(value = "force",defaultValue = "false") Boolean force ,@RequestParam(value = "deleteExtras",defaultValue = "true") Boolean deleteExtras) throws IOException {
  88. return sceneFileBuildService.rebuildScene(num,force,deleteExtras);
  89. }
  90. /**
  91. * 单个文件上传
  92. * @param file
  93. * @param params
  94. * @return
  95. */
  96. @PostMapping("upload")
  97. public ResultData upload(@RequestParam(value = "file",required = false) MultipartFile file,
  98. String params) throws Exception {
  99. return sceneFileBuildService.uploadFile(file, params);
  100. }
  101. /**
  102. * 国际八目相机调用
  103. * @param params
  104. * @return
  105. * @throws Exception
  106. */
  107. @PostMapping("getS3UploadUrl")
  108. public ResultData getS3UploadUrl(String params) throws Exception {
  109. log.info("getS3UploadUrl 参数:{}",params);
  110. if (StringUtils.isEmpty(params)) {
  111. throw new BusinessException(ErrorCode.PARAM_ERROR,"params为空。");
  112. }
  113. JSONObject jsonObject = JSON.parseObject(params);
  114. if(jsonObject == null){
  115. throw new BusinessException(ErrorCode.PARAM_ERROR,"params为空。");
  116. }
  117. JSONArray files = jsonObject.getJSONArray("Files");
  118. if(files == null){
  119. throw new BusinessException(ErrorCode.PARAM_ERROR,"params为空。");
  120. }
  121. List<String> urls = new ArrayList<>();
  122. for(int i = 0, len = files.size(); i < len; i++){
  123. urls.add(files.getJSONObject(i).getString("filename"));
  124. }
  125. Map<String, String> uploadS3Url = getUploadS3Url(urls);
  126. return ResultData.ok(uploadS3Url);
  127. }
  128. private Map<String, String> getUploadS3Url(List<String> urls) {
  129. if(urls == null || urls.size() <= 0){
  130. return null;
  131. }
  132. Map<String, String> map = new HashMap();
  133. for(String path : urls){
  134. map.put(path, fYunFileService.getPresignedUrl(path).toString());
  135. }
  136. return map;
  137. }
  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. @Autowired
  144. private GzZcdjzxService gzZcdjzxService;
  145. @GetMapping("bd")
  146. public ResultData test(){
  147. gzZcdjzxService.bd();
  148. return ResultData.ok();
  149. }
  150. @Resource
  151. private FYunFileConfig fYunFileConfig;
  152. @GetMapping("bd2")
  153. public ResultData bd2(String taskId, String kNo, String fileId, String snCode, String unicode) throws Exception {
  154. String dataSource = ConstantFilePath.BUILD_MODEL_PATH + snCode + "/" + fileId + "/" + unicode;
  155. String ossHomePath = SceneUtil.getHomePath(dataSource);
  156. String ossHomeAbsolutePath = LocalConstants.BASE_PATH + fYunFileConfig.getBucket() + "/" + ossHomePath;
  157. LambdaQueryWrapper<SceneFileBuild> wrapper = new LambdaQueryWrapper<>();
  158. if(StrUtil.isNotEmpty(taskId)){
  159. wrapper.eq(SceneFileBuild::getTaskId, taskId);
  160. }
  161. if(StrUtil.isNotEmpty(kNo)){
  162. wrapper.eq(SceneFileBuild::getKNo, kNo);
  163. }
  164. SceneFileBuild sceneFileBuild = sceneFileBuildService.getOne(wrapper);
  165. String realFileId = null;
  166. if(Objects.isNull(sceneFileBuild)){
  167. realFileId = fileId + "_" + DateExtUtil.format(new Date(), "yyyyMMddHHmmss");
  168. sceneFileBuild = new SceneFileBuild();
  169. sceneFileBuild.setFileId(realFileId);
  170. sceneFileBuild.setUnicode(unicode);
  171. sceneFileBuild.setChildName(snCode);
  172. sceneFileBuild.setCreateTime(new Date());
  173. sceneFileBuild.setRecStatus(RecStatus.VALID.code());
  174. sceneFileBuild.setTaskId(taskId);
  175. sceneFileBuild.setKNo(kNo);
  176. sceneFileBuildService.save(sceneFileBuild);
  177. }else{
  178. realFileId = sceneFileBuild.getFileId();
  179. }
  180. String realDataSource = ConstantFilePath.BUILD_MODEL_PATH + snCode + "/" + realFileId + "/" + unicode;
  181. String realOssHomePath = SceneUtil.getHomePath(realDataSource);
  182. String realOssHomeAbsolutePath = LocalConstants.BASE_PATH + fYunFileConfig.getBucket() + "/" + realOssHomePath;
  183. FileUtil.listFileNames(ossHomeAbsolutePath).stream().forEach(fileName -> {
  184. FileUtil.copy(ossHomeAbsolutePath + "/" + fileName, realOssHomeAbsolutePath + "/" + fileName, true);
  185. });
  186. // 私钥解密过程
  187. String paramsStr = snCode + "#" + realFileId + "#" + unicode;
  188. byte[] res = RSAEncrypt.encrypt(RSAEncrypt.loadPublicKeyByStr(RSAEncrypt.loadPublicKeyByFile()),
  189. paramsStr.getBytes(StandardCharsets.UTF_8));
  190. String params = new Base64().encodeToString(res);
  191. sceneFileBuildService.turntableUploadSuccess(params);
  192. return ResultData.ok();
  193. }
  194. }