From 4e54db42da2d28e6b99c77050b347d018b247bee Mon Sep 17 00:00:00 2001 From: lin <648540858@qq.com> Date: Tue, 7 Apr 2026 10:54:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=87=AA=E5=8A=A8=E6=B8=85?= =?UTF-8?q?=E7=90=86=E8=BF=87=E6=9C=9F=E6=8A=A5=E8=AD=A6=E8=AE=B0=E5=BD=95?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=EF=BC=8C=E5=85=81=E8=AE=B8=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E6=8A=A5=E8=AD=A6=E8=AE=B0=E5=BD=95=E4=BF=9D?= =?UTF-8?q?=E7=95=99=E5=A4=A9=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/genersoft/iot/vmp/conf/UserSetting.java | 6 +++++- .../iot/vmp/service/impl/AlarmServiceImpl.java | 16 ++++++++++++++-- src/main/resources/配置详情.yml | 2 +- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/conf/UserSetting.java b/src/main/java/com/genersoft/iot/vmp/conf/UserSetting.java index f39cd8e60..adb733384 100644 --- a/src/main/java/com/genersoft/iot/vmp/conf/UserSetting.java +++ b/src/main/java/com/genersoft/iot/vmp/conf/UserSetting.java @@ -239,12 +239,16 @@ public class UserSetting { /** * 是否使用拉流的方式获取快照,默认false,避免流量大规模消耗,开启后则使用拉流的方式获取快照 */ - private boolean snapByPullStream = false; + private boolean alarmSnapByStream = false; /** * 报警订阅白名单,设置后只有在此列表中的上级平台才会接收报警订阅消息,默认不设置则不限制 */ private List allowedAlarmType = new ArrayList<>(); + /** + * 报警记录保留天数,超过此天数的报警记录将在每天凌晨自动清理,默认30天,设置为0则不自动清理 + */ + private int alarmKeepDays = 7; } diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/AlarmServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/AlarmServiceImpl.java index 8b41a9c6a..1397438ba 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/impl/AlarmServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/AlarmServiceImpl.java @@ -27,10 +27,11 @@ import org.springframework.context.event.EventListener; import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; import java.io.File; +import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Date; import java.util.List; import java.util.concurrent.ConcurrentLinkedQueue; @@ -93,6 +94,18 @@ public class AlarmServiceImpl implements IAlarmService { } } + @Scheduled(cron = "0 0 0 * * ?") + public void cleanExpiredAlarms() { + int keepDays = userSetting.getAlarmKeepDays(); + if (keepDays <= 0) { + return; + } + String endTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss") + .format(new Date(System.currentTimeMillis() - (long) keepDays * 24 * 3600 * 1000)); + int count = clearAlarmsByCondition(null, null, endTime); + log.info("自动清理过期报警记录完成,保留天数:{},清理数量:{}", keepDays, count); + } + @Scheduled(fixedDelay = 500) public void executeAlarmQueue() { if (alarmQueue.isEmpty()) { @@ -171,7 +184,6 @@ public class AlarmServiceImpl implements IAlarmService { } @Override - @Transactional public int clearAlarmsByCondition(List alarmType, String beginTime, String endTime) { Long beginTimeLong = null; Long endTimeLong = null; diff --git a/src/main/resources/配置详情.yml b/src/main/resources/配置详情.yml index 6cb938536..29461d186 100644 --- a/src/main/resources/配置详情.yml +++ b/src/main/resources/配置详情.yml @@ -269,7 +269,7 @@ user-settings: # 建议根据实际情况调整,过大可能会占用较多内存,过小可能会增加数据库查询压力, alarm-catch-size: 10000 # 是否使用拉流的方式获取快照,默认false,避免流量大规模消耗,开启后则使用拉流的方式获取快照 - snap-by-pull-stream: true + alarm-snap-by-stream: true # 是否使用拉流的方式获取快照,默认false,避免流量大规模消耗,开启后则使用拉流的方式获取快照 allowed-alarm-type: - IntrusionDetection