Przeglądaj źródła

场景批量下载

dsx 1 rok temu
rodzic
commit
c475ea4ba5

+ 5 - 1
src/main/java/com/fdkankan/download/config/MyConfiguration.java

@@ -1,10 +1,13 @@
 package com.fdkankan.download.config;
 
+import com.alibaba.fastjson.JSON;
 import com.mybatisflex.core.FlexGlobalConfig;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.core.annotation.Order;
 
+import java.util.concurrent.ConcurrentHashMap;
+
 @Configuration
 public class MyConfiguration {
 
@@ -14,7 +17,7 @@ public class MyConfiguration {
 
         FlexGlobalConfig globalConfig = FlexGlobalConfig.getDefaultConfig();
 
-        globalConfig.setLogicDeleteColumn("recStatus");
+        globalConfig.setLogicDeleteColumn("rec_status");
 
         //设置数据库正常时的值
         globalConfig.setNormalValueOfLogicDelete("A");
@@ -24,6 +27,7 @@ public class MyConfiguration {
 
 
         return globalConfig;
+
     }
 
 }

+ 1 - 1
src/main/java/com/fdkankan/download/entity/DownloadLog.java

@@ -33,7 +33,7 @@ public class DownloadLog implements Serializable {
      * 逻辑删除,0-否,1-是
      */
     @Column(isLogicDelete = true)
-    private Integer isDelete;
+    private String recStatus;
 
     /**
      * -1失败,1成功

+ 1 - 1
src/main/java/com/fdkankan/download/entity/Sn.java

@@ -33,7 +33,7 @@ public class Sn implements Serializable {
      * 0-否,1-是
      */
     @Column(isLogicDelete = true)
-    private Integer isDelete;
+    private String recStatus;
 
     private Timestamp createTime;
 

+ 1 - 1
src/main/java/com/fdkankan/download/service/IDownloadService.java

@@ -1,7 +1,7 @@
 package com.fdkankan.download.service;
 
 public interface IDownloadService {
-    void downloadHandler(String num) throws Exception;
+    String downloadHandler(String num) throws Exception;
 
     /**
      *

+ 4 - 3
src/main/java/com/fdkankan/download/service/impl/DownloadLogServiceImpl.java

@@ -1,10 +1,11 @@
 package com.fdkankan.download.service.impl;
 
-import com.mybatisflex.core.query.QueryWrapper;
-import com.mybatisflex.spring.service.impl.ServiceImpl;
+import com.fdkankan.common.constant.CommonSuccessStatus;
 import com.fdkankan.download.entity.DownloadLog;
 import com.fdkankan.download.mapper.DownloadLogMapper;
 import com.fdkankan.download.service.IDownloadLogService;
+import com.mybatisflex.core.query.QueryWrapper;
+import com.mybatisflex.spring.service.impl.ServiceImpl;
 import org.springframework.stereotype.Service;
 
 import java.util.List;
@@ -20,7 +21,7 @@ public class DownloadLogServiceImpl extends ServiceImpl<DownloadLogMapper, Downl
 
     @Override
     public List<DownloadLog> getByNum(String num) {
-        return this.list(QueryWrapper.create().eq(DownloadLog::getNum, num));
+        return this.list(QueryWrapper.create().eq(DownloadLog::getNum, num).eq(DownloadLog::getStatus, CommonSuccessStatus.SUCCESS.code()));
     }
 
     @Override

+ 69 - 35
src/main/java/com/fdkankan/download/service/impl/DownloadServiceImpl.java

@@ -36,7 +36,11 @@ import org.springframework.stereotype.Service;
 
 import java.io.File;
 import java.io.FileInputStream;
+import java.io.IOException;
 import java.net.URLEncoder;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
 import java.util.*;
 import java.util.concurrent.Callable;
 import java.util.concurrent.ExecutorService;
@@ -105,7 +109,7 @@ public class DownloadServiceImpl implements IDownloadService {
 
 
     @Override
-    public void downloadHandler(String num) throws Exception {
+    public String downloadHandler(String num) throws Exception {
 
         //zip包路径
         String zipPath = null;
@@ -168,6 +172,8 @@ public class DownloadServiceImpl implements IDownloadService {
             //打压缩包
             ZipUtil.zip(String.format(this.sourceLocal, num, ""), zipPath);
 
+            return zipPath;
+
             // TODO: 2024/1/4 生成的压缩包放哪里待定
 //            String uploadPath = String.format(this.zipOssFormat, num);
 //            fYunFileService.uploadFileByCommand(bucket, zipPath, uploadPath);
@@ -175,11 +181,7 @@ public class DownloadServiceImpl implements IDownloadService {
         }catch (Exception e){
             //更新进度为下载失败
             throw e;
-        }finally {
-            FileUtil.del(zipPath);
-            FileUtil.del(String.format(this.sourceLocal, num, ""));
         }
-
     }
 
     private void zipBat(String num, String version) throws Exception{
@@ -201,7 +203,12 @@ public class DownloadServiceImpl implements IDownloadService {
 
     private void zipOssFiles(String num, String resolution, int imagesVersion, Set<String> cacheKeys, String version) throws Exception{
 
-        fYunFileService.downloadFileByCommand(String.format(sourceLocal, num, this.wwwroot), String.format(UploadFilePath.VIEW_PATH, num));
+//        fYunFileService.downloadFileByCommand(String.format(sourceLocal, num, this.wwwroot), String.format(UploadFilePath.VIEW_PATH, num));
+        final List<String> strings = fYunFileService.listRemoteFiles(String.format(UploadFilePath.VIEW_PATH, num));
+        strings.stream().forEach(str->{
+            fYunFileService.downloadFile(str, String.format(sourceLocal, num, this.wwwroot).concat(str));
+        });
+//        fYunFileService.downloadFile(String.format(UploadFilePath.VIEW_PATH, num), String.format(sourceLocal, num, this.wwwroot));
 
         //特殊文件处理
         this.reWriteFile(num);
@@ -211,7 +218,32 @@ public class DownloadServiceImpl implements IDownloadService {
         this.cutImg(num, filePath, resolution, "tiles");
 
         //切图-场景关联
+        String panoramaPath = String.format(sourceLocal, num, this.wwwroot + String.format(UploadFilePath.IMG_VIEW_PATH, num) + "panorama/");
+        if(FileUtil.exist(panoramaPath)){
+            Path directoryPath = Paths.get(panoramaPath); // 替换为你要查询的目录路径
+            // 获取目录下的第一层子目录
+            List<String> panoramaIdList = Files.list(directoryPath).filter(Files::isDirectory).map(file -> file.getFileName().toString()).collect(Collectors.toList());
+            if(CollUtil.isNotEmpty(panoramaIdList)){
+                for (String panoramaId : panoramaIdList) {
+                    this.cutImg(num, panoramaPath.concat(panoramaId).concat("/tiles/"), resolution, "panorama/".concat(panoramaId).concat("/tiles"));
+                }
+            }
+        }
+    }
 
+    public static void main(String[] args) {
+        Path directoryPath = Paths.get("D:\\test"); // 替换为你要查询的目录路径
+
+        try {
+            // 获取目录下的第一层子目录
+            Files.list(directoryPath)
+                    .filter(Files::isDirectory)
+                    .forEach(file -> {
+                        System.out.println(file.getFileName().toString());
+                    });
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
     }
     @Override
     public void cutImg(String num, String path, String resolution, String subPath) throws Exception {
@@ -268,35 +300,35 @@ public class DownloadServiceImpl implements IDownloadService {
 //
 //    }
 
-    public void ProcessFiles(String num, String key, String prefix, Set<String> cacheKeys) throws Exception{
-        if(cacheKeys.contains(key)){
-            return;
-        }
-        if(key.equals(String.format(UploadFilePath.DATA_VIEW_PATH, num) + "scene.json")){
-            return;
-        }
-        cacheKeys.add(key);
-        String fileName = key.substring(key.lastIndexOf("/") + 1);
-        String url = this.resourceUrl + key.replace(fileName, URLEncoder.encode(fileName, "UTF-8")) + "?t=" + Calendar.getInstance().getTimeInMillis();
-        if(key.contains("hot.json") || key.contains("link-scene.json")){
-            String content = fYunFileService.getFileContent(key);
-            if(StrUtil.isEmpty(content)){
-                return;
-            }
-            content = content.replace(publicUrl, "")
-//                .replace(publicUrl+"v3/", "")
-                    .replace("https://spc.html","spc.html")
-                    .replace("https://smobile.html", "smobile.html");
-
-            FileUtil.writeUtf8String(content, String.format(sourceLocal, num, prefix + key));
-        }else{
-            try {
-                this.downloadFile(url, String.format(sourceLocal, num, prefix + key));
-            }catch (Exception e){
-                log.info("下载文件报错,path:{}", String.format(sourceLocal, num, prefix + key));
-            }
-        }
-    }
+//    public void ProcessFiles(String num, String key, String prefix, Set<String> cacheKeys) throws Exception{
+//        if(cacheKeys.contains(key)){
+//            return;
+//        }
+//        if(key.equals(String.format(UploadFilePath.DATA_VIEW_PATH, num) + "scene.json")){
+//            return;
+//        }
+//        cacheKeys.add(key);
+//        String fileName = key.substring(key.lastIndexOf("/") + 1);
+//        String url = this.resourceUrl + key.replace(fileName, URLEncoder.encode(fileName, "UTF-8")) + "?t=" + Calendar.getInstance().getTimeInMillis();
+//        if(key.contains("hot.json") || key.contains("link-scene.json")){
+//            String content = fYunFileService.getFileContent(key);
+//            if(StrUtil.isEmpty(content)){
+//                return;
+//            }
+//            content = content.replace(publicUrl, "")
+////                .replace(publicUrl+"v3/", "")
+//                    .replace("https://spc.html","spc.html")
+//                    .replace("https://smobile.html", "smobile.html");
+//
+//            FileUtil.writeUtf8String(content, String.format(sourceLocal, num, prefix + key));
+//        }else{
+//            try {
+//                this.downloadFile(url, String.format(sourceLocal, num, prefix + key));
+//            }catch (Exception e){
+//                log.info("下载文件报错,path:{}", String.format(sourceLocal, num, prefix + key));
+//            }
+//        }
+//    }
 
     private void reWriteFile(String num){
         String filePath = String.format(sourceLocal, num, this.wwwroot + String.format(UploadFilePath.USER_VIEW_PATH, num) + "hot.json");
@@ -449,4 +481,6 @@ public class DownloadServiceImpl implements IDownloadService {
 
         return map;
     }
+
+
 }

+ 7 - 6
src/main/java/com/fdkankan/download/service/impl/GenSceneRunnerImpl.java

@@ -73,7 +73,7 @@ public class GenSceneRunnerImpl implements CommandLineRunner {
                 String key = "download:tool:" + scenePlus.getNum();
                 String lockVal = hostInfo.getAddress();
                 try {
-                    boolean lock = redisLockUtil.lock(key, lockVal, 24 * 60 * 60 * 100);
+                    boolean lock = redisLockUtil.lock(key, lockVal, 24 * 60 * 60);
                     if(!lock){
                         continue;
                     }
@@ -107,11 +107,12 @@ public class GenSceneRunnerImpl implements CommandLineRunner {
                         if(!types.contains("kankan")) {
                             threadPoolExecutor.submit(() -> {
                                 try {
-                                    downloadService.downloadHandler(scenePlus.getNum());
+                                    String zipPath = downloadService.downloadHandler(scenePlus.getNum());
+                                    send(zipPath);
                                     downloadLogService.saveLog(scenePlus.getNum(), "kankan", CommonSuccessStatus.SUCCESS.code(), null);
                                 } catch (Exception e) {
-                                    downloadLogService.saveLog(scenePlus.getNum(), "kankan", CommonSuccessStatus.FAIL.code(), ExceptionUtil.stacktraceToString(e, 3000));
                                     log.error("看看场景打包失败,num:{}", scenePlus.getNum(), e);
+                                    downloadLogService.saveLog(scenePlus.getNum(), "kankan", CommonSuccessStatus.FAIL.code(), ExceptionUtil.stacktraceToString(e, 3000));
                                 }
                             });
                         }
@@ -123,8 +124,8 @@ public class GenSceneRunnerImpl implements CommandLineRunner {
         }
     }
 
-//    private void send(String zipPath){
-//        mqProducer.sendByWorkQueue("rsync-scene", );
-//    }
+    private void send(String zipPath){
+        mqProducer.sendByWorkQueue("rsync-scene", zipPath);
+    }
 
 }

+ 2 - 2
src/main/resources/application-dev.yml

@@ -100,8 +100,8 @@ download:
   id: ${download.dir}id.txt
   config:
     public-url: https://4dkk.4dage.com/
-    resource-url: https://4dkankan.oss-cn-shenzhen-internal.aliyuncs.com/
-    # resource-url: https://4dkankan.oss-cn-shenzhen.aliyuncs.com/
+#    resource-url: https://4dkankan.oss-cn-shenzhen-internal.aliyuncs.com/
+    resource-url: https://4dkankan.oss-cn-shenzhen.aliyuncs.com/
     exe-name: start-browser.bat
     exe-content: | # | 表示不转义特殊字符
       taskkill /f /t /im http.exe