Przeglądaj źródła

720添加下载热点数据功能

wuweihao 2 lat temu
rodzic
commit
0c8178545f

+ 3 - 0
gis_service/src/main/java/com/gis/entity/dto/YunDto.java

@@ -23,4 +23,7 @@ public class YunDto {
     @NotBlank(message = "作品码不能为空")
     @ApiModelProperty(value = "作品码", required = true)
     private String workId;
+
+    @ApiModelProperty(value = "下载类型", notes = "空:只下载场景(默认) | 1:只下载热点 | 2:下载场景+热点")
+    private String downLoadType;
 }

+ 210 - 5
gis_service/src/main/java/com/gis/service/impl/AliOssServiceImpl.java

@@ -59,6 +59,12 @@ public class AliOssServiceImpl implements AliOssService {
         String[] split = StrUtil.split(workIds, ",");
         log.info("需要下载作品数量:{}", split.length);
 
+        String downLoadType = param.getDownLoadType();
+        // 热点保存路径
+        String baseHotPath = configConstant.serverBasePath + "/download/720yun_fd_manage/";
+        // 每次下载热点, 清除历史热点目录
+        fileUtils.del("/download/720yun_fd_manage" );
+
         ArrayList<Object> pathList = new ArrayList<>();
         int i = 1;
         for (String workId : split) {
@@ -77,12 +83,26 @@ public class AliOssServiceImpl implements AliOssService {
             downloadGuideThumb(sceneData, workId);
 
 
-            if (!"dev".equals(configConstant.active)) {
-                // 6.下载场景
-                downloadScenes(sceneData, workId, param.getEvn());
+            // 非只下载热点都需要下载
+            if (!"dev".equals(configConstant.active) && !"1".equals(downLoadType)) {
+
+                    // 6.下载场景
+                    downloadScenes(sceneData, workId, param.getEvn());
+
+                    // 7.压缩zip
+                    zipWork(workId);
+
+            }
+
+            // 8.下载热点数据
+            if (StrUtil.isNotBlank(downLoadType)){
+                // 获取作品热点地址
+                Set<String> setUrl = getHotUrlByWorkId(workId);
+                // 下载作品热点数据
+                if(setUrl != null){
+                    downloadForUrl(setUrl, baseHotPath, true);
+                }
 
-                // 7.压缩zip
-                zipWork(workId);
             }
 
             String outPath = configConstant.serverBasePath + "/download/" + workId + ".zip";
@@ -97,6 +117,191 @@ public class AliOssServiceImpl implements AliOssService {
         return Result.success(pathList);
     }
 
+
+    /**
+     *
+     * @param list
+     * @param basePath
+     * @param hasExist true:存在不下载, false:全局下载
+     */
+    private void downloadForUrl(Set<String> list, String basePath, boolean hasExist){
+        String prefix = "https://4dkk.4dage.com";
+        int size = list.size();
+        log.info("需要下载数量为:{}", size );
+        int i = 0;
+        for (String s : list) {
+            if (StrUtil.isBlank(s)){
+                continue;
+            }
+            i ++;
+            String fileName = StrUtil.subAfter(s, prefix, true);
+            String filePath = basePath + fileName;
+            if (hasExist){
+                if (FileUtil.exist(filePath)) {
+                    continue;
+                }
+            }
+
+            log.info("文件路径-共:{}, 第:{}, url:{}",size, i, s);
+            HttpUtil.downloadFile(s, filePath);
+
+
+        }
+        log.info("实际下载数量为:{}", i );
+
+    }
+
+    /**
+     *  获取作品热点地址
+     * @param workId
+     * @return
+     */
+    private Set<String> getHotUrlByWorkId(String workId) {
+        log.info("start: {}下载热点数据", workId);
+
+        Set<String> setUrl = new HashSet<>();
+
+        String path = configConstant.serverBasePath + "/download/" + workId + "/someData.json";
+        log.info("someDataPath: {}", path);
+        String s = FileUtil.readUtf8String(path);
+        JSONObject parent = JSONObject.parseObject(s);
+        // 背景音乐
+        JSONObject backgroundMusic = parent.getJSONObject("backgroundMusic");
+        if (backgroundMusic != null){
+            String ossPath = backgroundMusic.getString("ossPath");
+            if (StrUtil.isNotBlank(ossPath)){
+                setUrl.add(addSet(ossPath));
+            }
+        }
+
+        // 封面场景firstScene
+        JSONObject firstScene = parent.getJSONObject("firstScene");
+        if (firstScene != null){
+            String icon = firstScene.getString("icon");
+            setUrl.add(addSet(icon));
+        }
+
+        // scenes
+        JSONArray scenes = parent.getJSONArray("scenes");
+        for (Object scene : scenes) {
+            JSONObject sceneJson = JSONObject.parseObject(scene.toString());
+            String icon = sceneJson.getString("icon");
+            setUrl.add(addSet(icon));
+
+            //  热点hotspots
+            JSONObject someData = sceneJson.getJSONObject("someData");
+            if (someData != null){
+                JSONArray hotspots = someData.getJSONArray("hotspots");
+                for (Object hotspot : hotspots) {
+                    JSONObject hotJson = JSONObject.parseObject(hotspot.toString());
+
+
+                    // 热点-图片
+                    JSONArray images = hotJson.getJSONArray("image");
+                    for (Object image : images) {
+                        JSONObject imageJson = JSONObject.parseObject(image.toString());
+                        String hotIcon = imageJson.getString("ossPath");
+//                        setUrl.add(hotIcon);
+                        setUrl.add(addSet(hotIcon));
+
+                    }
+                    JSONObject jsonObject = hotJson.getJSONObject("serialFrameInfo");
+                    if (jsonObject != null){
+                        String img = jsonObject.getString("img");
+                        if (StrUtil.isNotBlank(img)){
+//                            addSet(img);
+                            setUrl.add(addSet(img));
+                        }
+                    }
+
+                    // 热点-视频
+                    JSONObject videoJson = hotJson.getJSONObject("video");
+                    if (videoJson != null){
+                        String ossPath = videoJson.getString("ossPath");
+                        if (StrUtil.isNotBlank(ossPath)){
+//                            addSet(ossPath);
+                            setUrl.add(addSet(ossPath));
+                        }
+                    }
+
+                    // 热点-音频
+                    JSONObject audioJson = hotJson.getJSONObject("audio");
+                    if (audioJson != null){
+                        String ossPath = audioJson.getString("ossPath");
+                        if (StrUtil.isNotBlank(ossPath)){
+//                            addSet(ossPath);
+                            setUrl.add(addSet(ossPath));
+                        }
+                    }
+
+
+                    // 热点列表
+                    JSONObject imageTextInfoJson = hotJson.getJSONObject("imageTextInfo");
+//                    if (imageTextInfoJson.toString().contains("20230619_110053418.jpg")){
+//                        System.out.println("11111111111111111111111111111");
+//                    }
+                    if (imageTextInfoJson != null){
+                        // 热点列表-图片
+                        JSONArray imageList = imageTextInfoJson.getJSONArray("imageList");
+                        if (imageList.size() > 0){
+                            for (Object img : imageList) {
+                                JSONObject imageJson = JSONObject.parseObject(img.toString());
+                                String ossPath = imageJson.getString("ossPath");
+                                if (StrUtil.isNotBlank(ossPath)){
+//                                    addSet(ossPath);
+                                    setUrl.add(addSet(ossPath));
+
+                                }
+                            }
+                        }
+
+                        // 热点列表-音频
+                        JSONObject audioInfoJson = imageTextInfoJson.getJSONObject("audio");
+                        if (audioInfoJson != null){
+                            String ossPath = audioInfoJson.getString("ossPath");
+                            if (StrUtil.isNotBlank(ossPath)){
+//                                addSet(ossPath);
+                                setUrl.add(addSet(ossPath));
+
+                            }
+                        }
+
+                    }
+
+
+
+                }
+            }
+
+
+
+        }
+
+
+        log.info("end: {}下载热点数据", workId);
+
+        return setUrl;
+    }
+
+    private String addSet(String url){
+        if (url.contains("fd720_")){
+            return null;
+        }
+
+        if (url.contains("?")){
+            url = StrUtil.subBefore(url, "?", true);
+        }
+
+        // 处理后缀异常链接,如 xxx/.jpg
+        if (StrUtil.subAfter(url, "/", true).length() < 8){
+            return null;
+        }
+
+        return url;
+    }
+
+
+
     private void zipWork(String workId) {
         String outPath = configConstant.serverBasePath + "/download/" + workId + ".zip";