Browse Source

add offline queue5

xiewj 3 months ago
parent
commit
e7e2fee4b4

+ 55 - 0
720yun_fd_consumer/src/main/java/com/gis/DownloadFile.java

@@ -0,0 +1,55 @@
+package com.gis;
+
+import java.io.*;
+import java.net.HttpURLConnection;
+import java.net.URL;
+
+public class DownloadFile {
+    public static void main(String[] args) {
+        String fileURL = "https://ossxiaoan.4dage.com//720yun_fd_manage/image/20250224_152717258.jpg?d=174038203732";
+
+        try {
+            URL url = new URL(fileURL);
+            // 解析URL得到路径部分,去除查询参数
+            String filePath = url.getPath();
+            // 获取查询参数部分,如果不需要可以忽略这行
+            String query = url.getQuery();
+
+            // 假设基础保存目录在C盘
+            String baseDir = "c:\\";
+            // 构建完整的保存路径
+            String saveFilePath = baseDir + filePath;
+
+            HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
+            int responseCode = httpConn.getResponseCode();
+
+            // 检查HTTP响应码是否为200表示请求成功
+            if (responseCode == HttpURLConnection.HTTP_OK) {
+                InputStream inputStream = httpConn.getInputStream();
+                // 确保目录存在
+                File file = new File(saveFilePath);
+                File dir = file.getParentFile();
+                if (!dir.exists()) {
+                    dir.mkdirs(); // 创建所有必要的父目录
+                }
+                FileOutputStream outputStream = new FileOutputStream(file);
+
+                int bytesRead;
+                byte[] buffer = new byte[4096];
+                while ((bytesRead = inputStream.read(buffer)) != -1) {
+                    outputStream.write(buffer, 0, bytesRead);
+                }
+
+                outputStream.close();
+                inputStream.close();
+
+                System.out.println("文件下载完成: " + saveFilePath);
+            } else {
+                System.out.println("无法下载文件,服务器响应码:" + responseCode);
+            }
+            httpConn.disconnect();
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
+}

+ 5 - 1
720yun_fd_consumer/src/main/java/com/gis/listener/container/WorkOfflineListener.java

@@ -37,6 +37,7 @@ import org.springframework.util.ObjectUtils;
 
 import javax.annotation.Resource;
 import java.io.File;
+import java.net.URL;
 import java.nio.charset.StandardCharsets;
 import java.util.List;
 import java.util.concurrent.TimeUnit;
@@ -188,7 +189,10 @@ public class WorkOfflineListener implements ChannelAwareMessageListener {
                         //下载icon
                         if (ObjUtil.isNotEmpty(workNavigationEntity.getIcon())) {
                             log.info("下载icon:{}", workNavigationEntity.getIcon());
-                            HttpUtil.downloadFileFromUrl(workNavigationEntity.getIcon(),basePath + File.separator );
+                            URL url = new URL(workNavigationEntity.getIcon());
+                            // 解析URL得到路径部分,去除查询参数
+                            String filePath = url.getPath();
+                            HttpUtil.downloadFileFromUrl(workNavigationEntity.getIcon(),basePath + File.separator +filePath);
                         }
 
                     }