feat(config): 添加网络图标接口地址并修改图标加载方式新增 networkIconInterfaceAddress 接口地址,用于获取网络图标资源。

将原本通过本地文件读取图标的逻辑移除,改为从网络动态加载图标,提升配置灵活性。feat(page): 新增初始化网络图标功能类

创建 `InitialiNetWork` 工具类,提供 `initializeTheNetworkIcon()` 方法,用于从指定接口获取图标数据,并设置到全局配置中。

feat(model): 添加网络图标数据模型

新增 `NetWorkIconVO` 类,用于接收和解析来自接口的图标链接信息,支持动态加载不同尺寸和平台的图标资源。

fix(service): 调整等待时间以优化轮询逻辑

将 `FtbCrawlNetDy` 和 `FtbCrawlNetMt` 中的线程睡眠时间由 5000 毫秒调整为1000 毫秒,提高响应速度,避免不必要的长时间等待。
This commit is contained in:
wangchunxiang
2025-10-14 20:21:44 +08:00
parent dfa97f0a4a
commit 3d50cfcd6f
6 changed files with 56 additions and 25 deletions

View File

@@ -1,6 +1,7 @@
package com.fantaibao; package com.fantaibao;
import com.fantaibao.config.GlobalConfig; import com.fantaibao.config.GlobalConfig;
import com.fantaibao.page.InitialiNetWork;
import com.fantaibao.page.LoginView; import com.fantaibao.page.LoginView;
import javafx.application.Application; import javafx.application.Application;
import javafx.application.Platform; import javafx.application.Platform;
@@ -26,6 +27,8 @@ public class DesktopApplication extends Application {
@Override @Override
public void init() throws Exception { public void init() throws Exception {
super.init(); super.init();
// 初始化图标
InitialiNetWork.initializeTheNetworkIcon();
} }
@Override @Override

View File

@@ -2,10 +2,6 @@ package com.fantaibao.config;
import javafx.scene.image.Image; import javafx.scene.image.Image;
import javafx.stage.Stage; import javafx.stage.Stage;
import org.springframework.util.ResourceUtils;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
public class GlobalConfig { public class GlobalConfig {
/** /**
@@ -23,6 +19,10 @@ public class GlobalConfig {
* 更新cookie地址 * 更新cookie地址
*/ */
public static final String updateCookieInterfaceAddress = BASE_NET_URL+"/crawler/appraisal/update-user-cookie"; public static final String updateCookieInterfaceAddress = BASE_NET_URL+"/crawler/appraisal/update-user-cookie";
/**
* 网络图标接口地址
*/
public static final String networkIconInterfaceAddress = BASE_NET_URL+"/user/network-ico";
/** /**
* 租户Id标识 * 租户Id标识
@@ -54,24 +54,12 @@ public class GlobalConfig {
*/ */
public static String dyLoginPage; public static String dyLoginPage;
public static Image icon16 = null;
public static Image icon32 = null;
public static Image dyLogo = null;
public static Image mtLogo = null;
public static final Image icon16;
public static final Image icon32;
public static final Image dyLogo;
public static final Image mtLogo;
static {
try {
icon16 = new Image(new FileInputStream(ResourceUtils.getFile("classpath:icon16.png")));
icon32 = new Image(new FileInputStream(ResourceUtils.getFile("classpath:icon32.png")));
dyLogo = new Image(new FileInputStream(ResourceUtils.getFile("classpath:dylogo.png")));
mtLogo = new Image(new FileInputStream(ResourceUtils.getFile("classpath:mtlogo.png")));
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
}
public static void addIcon(Stage stage) { public static void addIcon(Stage stage) {
stage.getIcons().add(GlobalConfig.icon16); stage.getIcons().add(GlobalConfig.icon16);
stage.getIcons().add(GlobalConfig.icon32); stage.getIcons().add(GlobalConfig.icon32);

View File

@@ -0,0 +1,13 @@
package com.fantaibao.model;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
@Data
public class NetWorkIconVO {
private String icon16;
private String icon32;
private String dyLogo;
private String mtLogo;
}

View File

@@ -0,0 +1,30 @@
package com.fantaibao.page;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.fantaibao.config.GlobalConfig;
import com.fantaibao.model.NetWorkIconVO;
import javafx.scene.image.Image;
import lombok.experimental.UtilityClass;
@UtilityClass
public class InitialiNetWork {
/**
* 初始化网络图标
*/
public void initializeTheNetworkIcon() {
String result = HttpUtil.get(GlobalConfig.networkIconInterfaceAddress);
JSONObject parsed = JSON.parseObject(result);
if (parsed.getInteger("code") != 200) {
return;
}
NetWorkIconVO netWorkIconVO = parsed.getObject("data", NetWorkIconVO.class);
GlobalConfig.icon16 = new Image(netWorkIconVO.getIcon16());
GlobalConfig.icon32 = new Image(netWorkIconVO.getIcon32());
GlobalConfig.dyLogo = new Image(netWorkIconVO.getDyLogo());
GlobalConfig.mtLogo = new Image(netWorkIconVO.getMtLogo());
}
}

View File

@@ -40,8 +40,7 @@ public class FtbCrawlNetDy extends AbstractFtbCrawlNetBase implements FtbCrawlNe
new Page.NavigateOptions().setTimeout(6000000)); new Page.NavigateOptions().setTimeout(6000000));
while (!dyCookie.get()) { while (!dyCookie.get()) {
try { try {
Thread.sleep(5000); Thread.sleep(1000);
dyCookie.set(true);
} catch (InterruptedException e) { } catch (InterruptedException e) {
log.warn("等待过程中被中断", e); log.warn("等待过程中被中断", e);
Thread.currentThread().interrupt(); Thread.currentThread().interrupt();

View File

@@ -41,9 +41,7 @@ public class FtbCrawlNetMt extends AbstractFtbCrawlNetBase implements FtbCrawlNe
// 等待用户登录并获取所需cookie // 等待用户登录并获取所需cookie
while (!(mtCookie.get() && dzCookie.get())) { while (!(mtCookie.get() && dzCookie.get())) {
try { try {
Thread.sleep(5000); Thread.sleep(1000);
mtCookie.set(true);
dzCookie.set(true);
} catch (InterruptedException e) { } catch (InterruptedException e) {
log.warn("等待过程中被中断", e); log.warn("等待过程中被中断", e);
Thread.currentThread().interrupt(); Thread.currentThread().interrupt();