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.

48 lines
1.5 KiB
Java

5 years ago
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-12JAN-DEC) *(1-7SUN-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);
}
}
}