package com.zy.asrs.task; import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.zy.asrs.entity.ApiLog; import com.zy.asrs.entity.WrkMast; import com.zy.asrs.service.ApiLogService; import com.zy.asrs.task.core.ReturnT; import com.zy.asrs.task.handler.LogClearHandler; import com.zy.system.entity.OperateLog; import com.zy.system.service.OperateLogService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; import java.time.LocalDateTime; import java.time.temporal.ChronoUnit; import java.util.Date; import java.util.List; @Component public class LogClearScheduler { @Autowired private ApiLogService apiLogService; @Autowired private OperateLogService operateLogService; @Autowired private LogClearHandler logClearHandler; // 每天0点开始 // @Scheduled(cron = "0/1 * * * * ? ") @Scheduled(cron = "* * 0 * * ? ") private void apiLogExecute(){ LocalDateTime oneMonthAgo = LocalDateTime.now().minus(1, ChronoUnit.MONTHS); List apiLogs = apiLogService.selectList(new EntityWrapper().lt("create_time", oneMonthAgo)); for(ApiLog apiLog : apiLogs){ ReturnT returnT = logClearHandler.startClearApiLog(apiLog); } } @Scheduled(cron = "* * 0 * * ? ") private void sysOperateLogExecute(){ LocalDateTime oneMonthAgo = LocalDateTime.now().minus(2, ChronoUnit.MONTHS); List operateLogs = operateLogService.selectList(new EntityWrapper().lt("create_time", oneMonthAgo)); for(OperateLog operateLog : operateLogs){ ReturnT returnT = logClearHandler.startClearOperateLog(operateLog); } } }