日志删除
This commit is contained in:
@@ -75,6 +75,7 @@ public class LogAdvice implements ApplicationListener<ContextRefreshedEvent> {
|
||||
|
||||
Object result = null;
|
||||
try {
|
||||
sysLogAuditService.scheduleRemoveLog();
|
||||
result = joinPoint.proceed();
|
||||
addLogToQueue(joinPoint, "".equals(username) ? UserConstant.UNKNOWN_USER_ID : username, LogOperationTypeEnum.OPERATE.getMsg(), 1, LogLevelEnum.INFO.getCode(), 0);
|
||||
} catch (Throwable e) {
|
||||
|
||||
@@ -51,4 +51,9 @@ public interface ISysLogAuditService extends IService<SysLogAudit> {
|
||||
* @return
|
||||
*/
|
||||
Integer getMaxSort();
|
||||
|
||||
/**
|
||||
* 按照 一定规则 清除日志
|
||||
*/
|
||||
void scheduleRemoveLog();
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.njcn.gather.system.log.service.impl;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
@@ -117,4 +118,15 @@ public class SysLogAuditServiceImpl extends ServiceImpl<SysLogAuditMapper, SysLo
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void scheduleRemoveLog() {
|
||||
QueryWrapper<SysLogAudit> wrapper = new QueryWrapper<>();
|
||||
wrapper.lt("Create_Time", LocalDateTime.now().minusDays(30*6));
|
||||
int count = this.count();
|
||||
if (count > 1e6) {
|
||||
wrapper.or().orderByAsc("Create_Time").last("limit "+(count-1e6));
|
||||
}
|
||||
this.remove(wrapper);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user