From 2e8156406feba0cee7a48cfa4b5fd0d1edcf7ac4 Mon Sep 17 00:00:00 2001 From: zzp <2373064201@qq.com> Date: Fri, 6 Feb 2026 17:24:37 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/zbkj/admin/config/StartupRunner.java | 57 +++++++++++++++++++ .../service/impl/AdminLoginServiceImpl.java | 25 -------- .../src/main/resources/application.yml | 2 +- 3 files changed, 58 insertions(+), 26 deletions(-) create mode 100644 crmeb/crmeb-admin/src/main/java/com/zbkj/admin/config/StartupRunner.java diff --git a/crmeb/crmeb-admin/src/main/java/com/zbkj/admin/config/StartupRunner.java b/crmeb/crmeb-admin/src/main/java/com/zbkj/admin/config/StartupRunner.java new file mode 100644 index 00000000..f286b692 --- /dev/null +++ b/crmeb/crmeb-admin/src/main/java/com/zbkj/admin/config/StartupRunner.java @@ -0,0 +1,57 @@ +package com.zbkj.admin.config; + +import cn.hutool.core.util.StrUtil; +import cn.hutool.http.HttpUtil; +import com.alibaba.fastjson.JSONObject; +import com.zbkj.common.config.CrmebConfig; +import com.zbkj.common.constants.SysConfigConstants; +import com.zbkj.service.service.SystemConfigService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.CommandLineRunner; +import org.springframework.stereotype.Component; + +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.CompletableFuture; + +@Component +public class StartupRunner implements CommandLineRunner { + + @Autowired + private SystemConfigService systemConfigService; + @Autowired + private CrmebConfig crmebConfig; + + + + @Override + public void run(String... args) throws Exception { + // 项目启动后立即执行的代码 + System.out.println("项目启动完成,开始执行初始化任务..."); + // 异步执行,不阻塞启动 + CompletableFuture.runAsync(this::installStatistics); + System.out.println("初始化任务执行结束..."); + } + + public void installStatistics() { + try { + String version = crmebConfig.getVersion(); + if (StrUtil.isBlank(version) ) { + version = "CRMEB-JAVA-KY-EDIT"; + } + String apiUrl = systemConfigService.getValueByKey(SysConfigConstants.CONFIG_KEY_API_URL); + if (StrUtil.isBlank(apiUrl) || !(StrUtil.startWithIgnoreCase(apiUrl, "http"))) { + return; + } + Map map = new HashMap<>(); + map.put("host", apiUrl); + map.put("version", version); + map.put("https", "https"); + String result = HttpUtil.post("https://shop.crmeb.net/index.php/admin/server.upgrade_api/updatewebinfo", JSONObject.toJSONString(map)); + + } catch (Exception e) { + // 异步调用不应影响主流程 + e.printStackTrace(); + } + } +} diff --git a/crmeb/crmeb-admin/src/main/java/com/zbkj/admin/service/impl/AdminLoginServiceImpl.java b/crmeb/crmeb-admin/src/main/java/com/zbkj/admin/service/impl/AdminLoginServiceImpl.java index cd547186..7fd6bb6e 100644 --- a/crmeb/crmeb-admin/src/main/java/com/zbkj/admin/service/impl/AdminLoginServiceImpl.java +++ b/crmeb/crmeb-admin/src/main/java/com/zbkj/admin/service/impl/AdminLoginServiceImpl.java @@ -141,11 +141,6 @@ public class AdminLoginServiceImpl implements AdminLoginService { systemAdmin.setLastIp(ip); systemAdminService.updateById(systemAdmin); accountErrorNumClear(systemAdminLoginRequest.getAccount()); - // 安装统计 - // 异步调用新方法(不等待,不影响原方法) - CompletableFuture.runAsync(() -> { - installStatistics(); - }); return systemAdminResponse; } @@ -290,24 +285,4 @@ public class AdminLoginServiceImpl implements AdminLoginService { } } - public void installStatistics() { - try { - String version = crmebConfig.getVersion(); - if (StrUtil.isBlank(version) ) { - version = "CRMEB-JAVA-KY-EDIT"; - } - String apiUrl = systemConfigService.getValueByKey(SysConfigConstants.CONFIG_KEY_API_URL); - if (StrUtil.isBlank(apiUrl) || !(StrUtil.startWithIgnoreCase(apiUrl, "http"))) { - return; - } - Map map = new HashMap<>(); - map.put("host", apiUrl); - map.put("version", version); - map.put("https", "https"); - String result = HttpUtil.post("https://shop.crmeb.net/index.php/admin/server.upgrade_api/updatewebinfo", JSONObject.toJSONString(map)); - } catch (Exception e) { - // 异步调用不应影响主流程 - e.printStackTrace(); - } - } } diff --git a/crmeb/crmeb-admin/src/main/resources/application.yml b/crmeb/crmeb-admin/src/main/resources/application.yml index df2e2ae4..816f94a0 100644 --- a/crmeb/crmeb-admin/src/main/resources/application.yml +++ b/crmeb/crmeb-admin/src/main/resources/application.yml @@ -170,4 +170,4 @@ aj: # local定时清除过期缓存(单位秒),设置为0代表不执行 timing-clear: 3600 - history-data-clear-enable: false \ No newline at end of file + history-data-clear-enable: false