|
@@ -1,9 +1,24 @@
|
|
|
package com.fdkankan.contro.controller;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.amazonaws.HttpMethod;
|
|
|
+import com.amazonaws.auth.AWSStaticCredentialsProvider;
|
|
|
+import com.amazonaws.auth.BasicAWSCredentials;
|
|
|
+import com.amazonaws.regions.Regions;
|
|
|
+import com.amazonaws.services.s3.AmazonS3;
|
|
|
+import com.amazonaws.services.s3.AmazonS3ClientBuilder;
|
|
|
+import com.amazonaws.services.s3.model.GeneratePresignedUrlRequest;
|
|
|
+import com.fdkankan.common.constant.ErrorCode;
|
|
|
+import com.fdkankan.common.exception.BusinessException;
|
|
|
+import com.fdkankan.contro.common.Result;
|
|
|
import com.fdkankan.contro.service.ISceneFileBuildService;
|
|
|
import com.fdkankan.contro.vo.ResponseSceneFile;
|
|
|
+import com.fdkankan.fyun.config.FYunFileConfig;
|
|
|
import com.fdkankan.web.response.ResultData;
|
|
|
import lombok.extern.log4j.Log4j2;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
@@ -12,6 +27,11 @@ import org.springframework.web.bind.annotation.RequestParam;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
+import java.net.URL;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* 场景文件上传模块
|
|
@@ -24,6 +44,12 @@ public class SceneFileController{
|
|
|
@Autowired
|
|
|
private ISceneFileBuildService sceneFileBuildService;
|
|
|
|
|
|
+ @Autowired(required = false)
|
|
|
+ private AmazonS3 amazonS3;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private FYunFileConfig fileConfig;
|
|
|
+
|
|
|
/**
|
|
|
* 场景文件上传之前先获取fileId
|
|
|
* @param params
|
|
@@ -61,4 +87,56 @@ public class SceneFileController{
|
|
|
public ResultData rebuildScene(@RequestParam(value = "num") String num,@RequestParam(value = "force",defaultValue = "true") Boolean force ,@RequestParam(value = "deleteExtras",defaultValue = "true") Boolean deleteExtras) throws IOException {
|
|
|
return sceneFileBuildService.rebuildScene(num,force,deleteExtras);
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 国际八目相机调用
|
|
|
+ * @param params
|
|
|
+ * @return
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ @PostMapping("getS3UploadUrl")
|
|
|
+ public Result getS3UploadUrl(String params) throws Exception {
|
|
|
+ if (StringUtils.isEmpty(params)) {
|
|
|
+ throw new BusinessException(ErrorCode.PARAM_ERROR,"params为空。");
|
|
|
+ }
|
|
|
+ JSONObject jsonObject = JSON.parseObject(params);
|
|
|
+ if(jsonObject == null){
|
|
|
+ throw new BusinessException(ErrorCode.PARAM_ERROR,"params为空。");
|
|
|
+ }
|
|
|
+ JSONArray files = jsonObject.getJSONArray("Files");
|
|
|
+ if(files == null){
|
|
|
+ throw new BusinessException(ErrorCode.PARAM_ERROR,"params为空。");
|
|
|
+ }
|
|
|
+ List<String> urls = new ArrayList<>();
|
|
|
+ for(int i = 0, len = files.size(); i < len; i++){
|
|
|
+ urls.add(files.getJSONObject(i).getString("filename"));
|
|
|
+ }
|
|
|
+ return Result.success(getUploadS3Url(urls));
|
|
|
+ }
|
|
|
+
|
|
|
+ private Map<String, String> getUploadS3Url(List<String> urls) {
|
|
|
+ if(urls == null || urls.size() <= 0){
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ java.util.Date expiration = new java.util.Date();
|
|
|
+ long expTimeMillis = expiration.getTime();
|
|
|
+ expTimeMillis += 1000 * 60 * 60 * 8;
|
|
|
+ expiration.setTime(expTimeMillis);
|
|
|
+
|
|
|
+ //生成预签名URL
|
|
|
+ log.info("生成预签名URL");
|
|
|
+ GeneratePresignedUrlRequest generatePresignedUrlRequest = null;
|
|
|
+ URL url = null;
|
|
|
+ Map<String, String> map = new HashMap();
|
|
|
+ for(String path : urls){
|
|
|
+ generatePresignedUrlRequest = new GeneratePresignedUrlRequest(fileConfig.getBucket(), path)
|
|
|
+ .withMethod(HttpMethod.PUT)
|
|
|
+ .withExpiration(expiration);
|
|
|
+ url = amazonS3.generatePresignedUrl(generatePresignedUrlRequest);
|
|
|
+ map.put(path, url.toString());
|
|
|
+ }
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
}
|