package com.rate.system.rate_system.timeTask;
import com.rate.system.rate_system.service.LogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
/**
* @Author gaojie
* @Date 2019/8/28 10:49
* @Version 1.0
*/
@Component
@Configuration
@EnableScheduling //开启定时任务
public class Log {
@Autowired
LogService logService;
/**
* 定时删除半个月前的数据
* @author gaojie
* @date 2019/8/28 11:00
* @param
* @return void
**/
// @Scheduled(cron = "0 */1 * * * ?") //每分钟
@Scheduled(cron = "0 0 1 * * ?") //每天一点
public void delLog() {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
Calendar c = Calendar.getInstance(); //
c.setTime(new Date());
c.add(Calendar.DATE, - 15);
Date d = c.getTime();
String date = format.format(d);
//System.out.println("过去15天:"+date);
logService.delectByGmtcreatetime(date);
}
}
|