浏览代码

切换方式

xiewj 1 年之前
父节点
当前提交
701ca8eee1

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

@@ -69,6 +69,8 @@ public class DownloadServiceImpl implements IDownloadService {
 //        imageTypes.add(ImageType.builder().name("1k_face").size("1024").ranges(new String[]{"0", "511"}).build());
 //        imageTypes.add(ImageType.builder().name("512_face").size("512").ranges(new String[]{"0"}).build());
 //    }
+    @Autowired
+    DownloadUtil downloadUtil;
 
     @Value("${path.v4school}")
     private String v4localPath;
@@ -417,7 +419,7 @@ public class DownloadServiceImpl implements IDownloadService {
                 //key.split("/" + resolution + "/")[0] + "/" +
                 var fky = dir + "/" + imageType.getName() +  num + "_" + item.getI()  + "_" + item.getJ() + ext;
 
-                DownloadUtil.downloadFile(url, path + fky,1);
+                    downloadUtil.downloadFile(url, path + fky,1);
 //                this.downloadFile(url, path);
                 });
 //            }

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

@@ -52,7 +52,8 @@ import java.util.Map;
 @Service
 @Slf4j
 public class LaserService  implements ILaserService {
-
+    @Autowired
+    DownloadUtil downloadUtil;
     @Value("${laserhost}")
     private String host;
     @Resource
@@ -105,7 +106,7 @@ public class LaserService  implements ILaserService {
                                         if (!key.startsWith("/")) {
                                             srcPath = "/" + key;
                                         }
-                                        DownloadUtil.downloadFile(laserResourceUrl + key, sourceLocal +
+                                        downloadUtil.downloadFile(laserResourceUrl + key, sourceLocal +
                                                 File.separator + num +
                                                 File.separator + "www" +
                                                 File.separator + num + srcPath,1);
@@ -129,7 +130,7 @@ public class LaserService  implements ILaserService {
                                     if (StrUtil.isEmpty(FileUtil.extName(key)) || FileUtil.extName(key).equalsIgnoreCase("ply")) {
                                         continue;
                                     }
-                                    DownloadUtil.downloadFile(laserResourceUrl + key, sourceLocal +
+                                    downloadUtil.downloadFile(laserResourceUrl + key, sourceLocal +
                                             File.separator + num +
                                             File.separator + "www" +
                                             File.separator + num +

+ 17 - 4
src/main/java/com/fdkankan/download/util/DownloadUtil.java

@@ -6,33 +6,46 @@ import cn.hutool.core.util.RuntimeUtil;
 import cn.hutool.http.HttpUtil;
 import com.fdkankan.common.exception.BusinessException;
 import com.fdkankan.common.util.CmdUtils;
+import com.fdkankan.fyun.face.FYunFileServiceInterface;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Component;
 import lombok.extern.slf4j.Slf4j;
 
+import javax.annotation.Resource;
 import java.io.File;
 
 /**
  * @author Xiewj
  * @date 2024/1/12
  */
+@Component
 @Slf4j
 public class DownloadUtil {
+    @Resource
+    private FYunFileServiceInterface fYunFileService;
+    @Value("${download.config.resource-url}")
+    private String resourceUrl;
+    @Value("${download.config.laser-resource-url}")
+    private String laserResourceUrl;
+
     public final static String WGET_CMD = "wget -t 10 -N -O @out @url";
 
-    public static void downFile(String url, String path) throws Exception {
+    public  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){
+    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){
                 while (index<=50){
                     index++;
-                    DownloadUtil.downFile(url,path);
+                    HttpUtil.downloadFileFromUrl(url,path);
                     if (FileUtil.size(new File(path))>0){
                         log.info("文件第{}次下载成功:{}", index, path);
                         return;