#####1.创建TimedServiceImp,类前加上@EnableScheduling 方法上加上@Scheduled注解
@Slf4j
@Service
@EnableScheduling
public class TimedServiceImpl implements TimedService{
@Autowired
private PcrAllProportionMapper pcrAllProportionMapper;
@Autowired
private PcrPrdAllProportionMapper pcrPrdAllProportionMapper;
@Override
@Scheduled(cron = "0 4 0 ? * MON")
public void creatPlantMonitorJob() {
String queryAll = pcrPrdAllProportionMapper.selectAll(parameterMap);
pcrAllProportion.setCreateTime(new Date());
pcrAllProportion.setupdateTime(new Date());
int insertResult = pcrAllProportionMapper.insertSelective(pcrAllProportion);
if (insertResult!=0) {
log.info("success");
} else {
log.info("fail");
}
}
}
@Scheduling(cron=“0 4 0 ? * MON”) 中的cron配置的时间
从左往右的含义是:
1.秒(0~59)
2.分钟(0~59)
3.小时(0~23)
4.天(月0~31)
5.月(0~11)
6.天(星期1~7 或 SUN,MON,TUE,WED,THU,FRI,SA)
7.年(1970-2099)