定时删除日志
parent
aaf76a00dc
commit
6c2eea3909
@ -0,0 +1,69 @@
|
|||||||
|
package cn.estsh.i3plus.core.apiservice.schedulejob;
|
||||||
|
|
||||||
|
import cn.estsh.i3plus.core.api.iservice.busi.ISysLogExceptionService;
|
||||||
|
import cn.estsh.i3plus.core.api.iservice.busi.ISysLogOperateService;
|
||||||
|
import cn.estsh.i3plus.core.api.iservice.busi.ISysLogSystemService;
|
||||||
|
import cn.estsh.i3plus.core.api.iservice.busi.ISysLogTaskTimeService;
|
||||||
|
import cn.estsh.i3plus.platform.common.tool.TimeTool;
|
||||||
|
import cn.estsh.impp.framework.base.schedule.BaseImppScheduleJob;
|
||||||
|
import cn.estsh.impp.framework.boot.init.ApplicationProperties;
|
||||||
|
import org.quartz.JobExecutionContext;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description :
|
||||||
|
* @Reference : 日志清除
|
||||||
|
* @Author : yunhao
|
||||||
|
* @CreateDate : 2019-07-04 19:13
|
||||||
|
* @Modify:
|
||||||
|
**/
|
||||||
|
public class CoreLogClearJob extends BaseImppScheduleJob {
|
||||||
|
public static final Logger LOGGER = LoggerFactory.getLogger(CoreLogClearJob.class);
|
||||||
|
|
||||||
|
public CoreLogClearJob() {
|
||||||
|
super(CoreLogClearJob.class,"日志清除");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Value("${impp.log.retention-time:-1}")
|
||||||
|
public Integer retentionTime;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ISysLogSystemService sysLogSystemService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ISysLogExceptionService sysLogExceptionService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ISysLogOperateService sysLogOperateService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ISysLogTaskTimeService sysLogTaskTimeService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void executeImppJob(JobExecutionContext context, ApplicationProperties applicationProperties) {
|
||||||
|
// 判断日志保留时间 -1 永久
|
||||||
|
if(getJobParam() != null && Integer.parseInt(getJobParam()) != -1){
|
||||||
|
// 计算保留日期
|
||||||
|
String dateTime = TimeTool.pareDateToString("yyyy-MM-dd HH:mm:ss",
|
||||||
|
TimeTool.timeCalc(new Date(), Calendar.DAY_OF_MONTH, -retentionTime)
|
||||||
|
);
|
||||||
|
long count;
|
||||||
|
count = sysLogSystemService.deleteSysLogSystemByDateTimeAfter(dateTime);
|
||||||
|
LOGGER.info("【日志清理】 清理系统日志 {} 条", count);
|
||||||
|
|
||||||
|
count = sysLogExceptionService.deleteSysLogExceptionByDateTimeAfter(dateTime);
|
||||||
|
LOGGER.info("【日志清理】 清理异常日志 {} 条", count);
|
||||||
|
|
||||||
|
count = sysLogOperateService.deleteSysLogOperateByDateTimeAfter(dateTime);
|
||||||
|
LOGGER.info("【日志清理】 清理操作日志 {} 条", count);
|
||||||
|
|
||||||
|
count = sysLogTaskTimeService.deleteSysLogTaskTimeByDateTimeAfter(dateTime);
|
||||||
|
LOGGER.info("【日志清理】 清理定时任务日志 {} 条", count);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue