xiewj 1 vuosi sitten
vanhempi
commit
a06f624fd5

+ 2 - 18
src/main/java/com/fdkankan/download/service/impl/DownloadServiceImpl.java

@@ -417,7 +417,7 @@ public class DownloadServiceImpl implements IDownloadService {
                 //key.split("/" + resolution + "/")[0] + "/" +
                 var fky = dir + "/" + imageType.getName() +  num + "_" + item.getI()  + "_" + item.getJ() + ext;
 
-                this.downloadFile(url, path + fky,1);
+                DownloadUtil.downloadFile(url, path + fky,1);
 //                this.downloadFile(url, path);
                 });
 //            }
@@ -425,22 +425,7 @@ public class DownloadServiceImpl implements IDownloadService {
 
     }
 
-    public void downloadFile(String url, String path,int index){
-        File file = new File(path);
-        if(!file.getParentFile().exists()){
-            file.getParentFile().mkdirs();
-        }
-        try {
-//            DownloadUtil.downFile(url,path);
-            HttpUtil.downloadFileFromUrl(url,path);
-            if(FileUtil.size(new File(path)) == 0 && index < 4){
-                index++;
-                this.downloadFile(url,path,index);
-            }
-        } catch (Exception e) {
-            log.info("下载文件报错,url{},path:{}",url, path);
-        }
-    }
+
 
     private void zipLocalFiles(String num, String version) throws Exception{
         String sourcePath = String.format(this.sourceLocal, num, "");
@@ -519,5 +504,4 @@ public class DownloadServiceImpl implements IDownloadService {
         }
     }
 
-
 }

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

@@ -53,7 +53,7 @@ public class GenSceneRunnerImpl implements CommandLineRunner {
     @Autowired
     private RabbitMqProducer mqProducer;
 
-    private final static ThreadPoolExecutor threadPoolExecutor = ExecutorBuilder.create().setWorkQueue(new LinkedBlockingQueue<>(10000)).setCorePoolSize(10).setMaxPoolSize(10).build();
+    private final static ThreadPoolExecutor threadPoolExecutor = ExecutorBuilder.create().setWorkQueue(new LinkedBlockingQueue<>(10000)).setCorePoolSize(15).setMaxPoolSize(15).build();
 
     @Autowired
     ILaserService laserService;

+ 3 - 18
src/main/java/com/fdkankan/download/service/impl/LaserService.java

@@ -9,6 +9,7 @@ import cn.hutool.http.HttpUtil;
 import cn.hutool.system.oshi.OshiUtil;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
+import com.fdkankan.common.exception.BusinessException;
 import com.fdkankan.common.util.CmdUtils;
 import com.fdkankan.common.util.DateExtUtil;
 import com.fdkankan.download.bean.ImageTypeDetail;
@@ -104,7 +105,7 @@ public class LaserService  implements ILaserService {
                                         if (!key.startsWith("/")) {
                                             srcPath = "/" + key;
                                         }
-                                        this.downloadFile(laserResourceUrl + key, sourceLocal +
+                                        DownloadUtil.downloadFile(laserResourceUrl + key, sourceLocal +
                                                 File.separator + num +
                                                 File.separator + "www" +
                                                 File.separator + num + srcPath,1);
@@ -128,7 +129,7 @@ public class LaserService  implements ILaserService {
                                     if (StrUtil.isEmpty(FileUtil.extName(key)) || FileUtil.extName(key).equalsIgnoreCase("ply")) {
                                         continue;
                                     }
-                                    this.downloadFile(laserResourceUrl + key, sourceLocal +
+                                    DownloadUtil.downloadFile(laserResourceUrl + key, sourceLocal +
                                             File.separator + num +
                                             File.separator + "www" +
                                             File.separator + num +
@@ -218,20 +219,4 @@ public class LaserService  implements ILaserService {
         return FileUtil.file(moveZipPath);
 
     }
-    public void downloadFile(String url, String path,int index){
-        File file = new File(path);
-        if(!file.getParentFile().exists()){
-            file.getParentFile().mkdirs();
-        }
-        try {
-            DownloadUtil.downFile(url,path);
-//            HttpUtil.downloadFileFromUrl(url,path);
-            if(FileUtil.size(new File(path)) == 0 && index < 4){
-                index++;
-                this.downloadFile(url,path,index);
-            }
-        } catch (Exception e) {
-            log.info("下载文件报错,url{},path:{}",url, path);
-        }
-    }
 }

+ 28 - 1
src/main/java/com/fdkankan/download/util/DownloadUtil.java

@@ -1,17 +1,44 @@
 package com.fdkankan.download.util;
 
+import cn.hutool.core.io.FileUtil;
+import cn.hutool.core.thread.ThreadUtil;
 import cn.hutool.core.util.RuntimeUtil;
+import cn.hutool.http.HttpUtil;
+import com.fdkankan.common.exception.BusinessException;
 import com.fdkankan.common.util.CmdUtils;
 
+import java.io.File;
+
 /**
  * @author Xiewj
  * @date 2024/1/12
  */
 public class DownloadUtil {
-    public final static String WGET_CMD = "wget -N -O @out @url";
+    public final static String WGET_CMD = "wget -t 10 -N -O @out @url";
 
     public static void downFile(String url, String path) throws Exception {
         String cmd = WGET_CMD.replace("@out",path).replace("@url",url);
         RuntimeUtil.exec(cmd);
     }
+    public static void downloadFile(String url, String path,int index){
+        File file = new File(path);
+        if(!file.getParentFile().exists()){
+            file.getParentFile().mkdirs();
+        }
+        try {
+            if(FileUtil.size(new File(path)) == 0 ){
+                while (index<=50){
+                    index++;
+                    ThreadUtil.safeSleep(500);
+                    DownloadUtil.downFile(url,path);
+                    if (FileUtil.size(new File(path))>0){
+                        return;
+                    }
+//                    HttpUtil.downloadFileFromUrl(url,path);
+                }
+            }
+        } catch (Exception e) {
+            throw new BusinessException(-1,"下载报错停止,"+url+","+path);
+        }
+    }
 }