mirror of
https://gitee.com/pan648540858/wvp-GB28181-pro.git
synced 2026-05-06 06:06:08 +08:00
添加自动清理过期报警记录功能,允许用户设置报警记录保留天数
This commit is contained in:
parent
d1de343167
commit
4e54db42da
@ -239,12 +239,16 @@ public class UserSetting {
|
||||
/**
|
||||
* 是否使用拉流的方式获取快照,默认false,避免流量大规模消耗,开启后则使用拉流的方式获取快照
|
||||
*/
|
||||
private boolean snapByPullStream = false;
|
||||
private boolean alarmSnapByStream = false;
|
||||
|
||||
/**
|
||||
* 报警订阅白名单,设置后只有在此列表中的上级平台才会接收报警订阅消息,默认不设置则不限制
|
||||
*/
|
||||
private List<AlarmType> allowedAlarmType = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* 报警记录保留天数,超过此天数的报警记录将在每天凌晨自动清理,默认30天,设置为0则不自动清理
|
||||
*/
|
||||
private int alarmKeepDays = 7;
|
||||
|
||||
}
|
||||
|
||||
@ -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> alarmType, String beginTime, String endTime) {
|
||||
Long beginTimeLong = null;
|
||||
Long endTimeLong = null;
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user