From 05626a9f0f93a042477e8bb53fe5660e5d18b134 Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期四, 27 八月 2026 10:40:06 +0800
Subject: [PATCH] feat(api): 添加数据推送配置和定时任务功能
---
ruoyi-admin/src/main/java/com/ruoyi/web/core/api/ScheduledApi.java | 29 +++++++++++++++++++++++++++--
1 files changed, 27 insertions(+), 2 deletions(-)
diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/core/api/ScheduledApi.java b/ruoyi-admin/src/main/java/com/ruoyi/web/core/api/ScheduledApi.java
index 599f692..82c21cd 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/web/core/api/ScheduledApi.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/web/core/api/ScheduledApi.java
@@ -10,6 +10,9 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.context.event.ApplicationReadyEvent;
+import org.springframework.context.event.EventListener;
+import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.text.SimpleDateFormat;
@@ -23,6 +26,15 @@
@Slf4j
//姒嗘灄甯傚伐涓氬拰淇℃伅鍖栧眬鏁版嵁鎺ㄩ��(瀹氭椂浠诲姟)
public class ScheduledApi {
+
+ @Value("${api.loggingEnabled:false}")
+ private boolean loggingEnabled;
+
+ @Value("${api.electricityEnabled:false}")
+ private boolean electricityEnabled;
+
+ @Value("${api.ip}")
+ private String apiIp;
@Value("${api.entName}")
private String entName;
@@ -48,9 +60,19 @@
private static final Random RANDOM = new Random();
+ @EventListener(ApplicationReadyEvent.class)
+ public void logPushStatus() {
+ log.info("姒嗘灄甯傚伐涓氬拰淇℃伅鍖栧眬鏁版嵁鎺ㄩ�侀厤缃細鐧诲綍鏃ュ織鎺ㄩ�亄}锛岀數閲忔暟鎹帹閫亄}锛屾帹閫佸湴鍧�锛歿}锛屼紒涓氾細{}",
+ loggingEnabled ? "宸插紑鍚�" : "宸插叧闂�",
+ electricityEnabled ? "宸插紑鍚�" : "宸插叧闂�", apiIp, entName);
+ }
+
//鎺ㄩ�佺櫥褰曟棩蹇楁瘡鍛�
-// @Scheduled(cron = "0 0 1 ? * 1")
+ @Scheduled(cron = "0 0 1 ? * 1")
public void logging(){
+ if (!loggingEnabled) {
+ return;
+ }
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:dd");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//鑾峰彇鐧诲綍鏃ュ織
@@ -80,8 +102,11 @@
}
//鎺ㄩ�佺數姣忔湀
-// @Scheduled(cron = "0 0 1 1 * ?")
+ @Scheduled(cron = "0 0 1 1 * ?")
public void electricity(){
+ if (!electricityEnabled) {
+ return;
+ }
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:dd");
//鑾峰彇鐧诲綍鏃ュ織
List<ElectricityDto> electricityDtos = new ArrayList<>();
--
Gitblit v1.9.3