瀏覽代碼

全景照片下载

dengsixing 3 年之前
父節點
當前提交
3250b13c55

+ 2 - 2
4dkankan-center-scene/src/main/java/com/fdkankan/scene/controller/SceneEditController.java

@@ -703,8 +703,8 @@ public class SceneEditController extends BaseController {
      * @return java.util.List<java.lang.String>
      **/
     @PostMapping(value = "/downloadPanorama")
-    public ResultData downloadPanorama(@RequestParam(value = "num") String num) throws Exception {
-        return sceneEditInfoService.downloadPanorama(num);
+    public ResultData downloadPanorama(@RequestBody @Validated FileParamVO param) throws Exception {
+        return sceneEditInfoService.downloadPanorama(param);
     }
 
 

+ 1 - 1
4dkankan-center-scene/src/main/java/com/fdkankan/scene/service/ISceneEditInfoService.java

@@ -36,7 +36,7 @@ public interface ISceneEditInfoService extends IService<SceneEditInfo> {
 
     List<String> uploadPanorama(String num, MultipartFile file) throws Exception;
 
-    ResultData downloadPanorama(String num) throws Exception;
+    ResultData downloadPanorama(FileParamVO param) throws Exception;
 
     void saveTagsToSceneEditInfo(String num, Long sceneProId);
 

+ 30 - 12
4dkankan-center-scene/src/main/java/com/fdkankan/scene/service/impl/SceneEditInfoServiceImpl.java

@@ -514,36 +514,54 @@ public class SceneEditInfoServiceImpl extends ServiceImpl<ISceneEditInfoMapper,
     }
 
     @Override
-    public ResultData downloadPanorama(String num) throws Exception {
+    public ResultData downloadPanorama(FileParamVO param) throws Exception {
+
+        String num = param.getNum();
+        String fileName = param.getFileName();
 
         String cachePath = String.format(ConstantFilePath.SCENE_CACHE, num);
         String imgCachePath = String.format(UploadFilePath.IMG_CACHES_PATH, num);
         String localImagesPath =  String.format(ConstantFilePath.SCENE_CACHE_IMAGES, num);
-        List<String> keyList = uploadToOssUtil.listKeys(imgCachePath);
+
+        String cacheFormat = "downloads/scene/%s/caches/";
+        String cacheImageFormat = "downloads/scene/%s/caches/images/";
+        //如果入参文件名不为空,则是单个文件下载,不需要打包
+        if(StrUtil.isNotEmpty(fileName)){
+            //先下载到本地
+            if (!StorageType.LOCAL.code().equals(this.type)) {// TODO: 2022/2/15 这里有可能有问题,可能还需要考虑本地部署的情况
+                String filePath = imgCachePath + fileName;
+                String imageUrl = ossUrlPrefix + filePath + "?t=" + System.currentTimeMillis();
+                FileUtils.downLoadFromUrl(imageUrl, fileName, localImagesPath);
+            }
+            //上传
+            uploadToOssUtil.upload(localImagesPath + fileName, String.format(cacheImageFormat, num) + fileName);
+            String url = ossUrlPrefix + String.format(cacheImageFormat, num) + fileName + "?t=" + Calendar.getInstance().getTimeInMillis();
+            Map<String, Object> map = new HashMap<>();
+            map.put("fileUrl", url + "?t=" + System.currentTimeMillis());
+            map.put("fileName", fileName);
+            return ResultData.ok(map);
+        }
 
         //先下载到本地
+        List<String> keyList = uploadToOssUtil.listKeys(imgCachePath);
         if (!StorageType.LOCAL.code().equals(this.type)) {// TODO: 2022/2/15 这里有可能有问题,可能还需要考虑本地部署的情况
             keyList.stream().forEach(key->{
-                String fileName = key.substring(key.lastIndexOf("/") + 1);
-                String imageUrl = ossUrlPrefix + imgCachePath + fileName + "?t=" + System.currentTimeMillis();
-                FileUtils.downLoadFromUrl(imageUrl, fileName, localImagesPath);
+                String file = key.substring(key.lastIndexOf("/") + 1);
+                String imageUrl = ossUrlPrefix + imgCachePath + file + "?t=" + System.currentTimeMillis();
+                FileUtils.downLoadFromUrl(imageUrl, file, localImagesPath);
             });
         }
-
         //打包
         String zipName = num + "_images.zip";
         String zipPath = cachePath + zipName;
         FileUtil.zip(localImagesPath, zipPath, false);
-
         //上传压缩包
-        uploadToOssUtil.upload(zipPath, "downloads/caches/" + zipName);
-
-        String url = ossUrlPrefix + "downloads/caches/" + zipName + "?t=" + Calendar.getInstance().getTimeInMillis();
+        uploadToOssUtil.upload(zipPath, String.format(cacheFormat, num) + zipName);
+        String url = ossUrlPrefix + String.format(cacheFormat, num) + zipName + "?t=" + Calendar.getInstance().getTimeInMillis();
 
         Map<String, Object> map = new HashMap<>();
         map.put("fileUrl", url + "?t=" + System.currentTimeMillis());
-        map.put("fileName", url.substring(url.lastIndexOf("/") + 1));
-
+        map.put("fileName", zipName);
         return ResultData.ok(map);
     }