You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
package com.manage.controller ;
import com.manage.entity.Power_Log ;
import com.manage.service.LogService ;
import com.manage.util.DateUtils ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.beans.factory.annotation.Value ;
import org.springframework.scheduling.annotation.Scheduled ;
import org.springframework.stereotype.Component ;
import java.text.SimpleDateFormat ;
import java.util.Date ;
/**
* 清除系统日志任务
* @author Mr Du
*
*/
@Component
public class MethodLogQuartz {
@Value ( "${log.days}" )
private Integer LOGDAYS ;
@Autowired
private LogService logServiceImpl ;
/**
* cron表达式: * * * * * *( 共6位, 使用空格隔开, 具体如下)
* cron表达式: *(秒0-59) *(分 钟0-59) *(小时0-23) *(日期1-31) *(月份1-12或是JAN-DEC) *(星期1-7或是SUN-SAT)
*/
@Scheduled ( cron = "0 0 0 * * ?" )
public void clearLog ( ) {
Date date = DateUtils . getDate ( DateUtils . getDate ( ) , - LOGDAYS ) ;
SimpleDateFormat fmt = new SimpleDateFormat ( "yyyy-MM-dd HH:mm:ss" ) ;
int count = logServiceImpl . delLogsByDate ( fmt . format ( date ) ) ;
if ( count ! = 0 ) {
Power_Log log = new Power_Log ( ) ;
log . setIp ( "" ) ;
log . setLogTitle ( "删除" ) ;
log . setLogContent ( "定时删除日志:" + count + "条" ) ;
log . setCreater ( "系统自动任务" ) ;
log . setRemark ( "" ) ;
logServiceImpl . autoInsert ( log ) ;
}
}
}