package com.sf.dangbao.core.TimeTask;
import cn.hutool.core.date.DateUtil;
import com.sf.dangbao.core.service.DistributionTaskService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.JobExecutionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.QuartzJobBean;
@DisallowConcurrentExecution
public class DistributeTaskJob extends QuartzJobBean {
private static Logger LOGGER = LogManager.getLogger(DistributeTaskJob.class);
@Autowired
private DistributionTaskService distributionTaskService;
/**
* 凌晨四点创建今日的配送任务
* @param jobExecutionContext
*/
@Override
protected void executeInternal(JobExecutionContext jobExecutionContext) {
long start = System.currentTimeMillis();
LOGGER.info("开始生成今日配送任务");
String today = DateUtil.today();
distributionTaskService.createTask(today);
long internal = System.currentTimeMillis() - start;
LOGGER.info("生成今日配送任务完成,耗时:{}", internal);
}
}
—————————————————————————————————————
package com.sf.dangbao.core.TimeTask;
import cn.hutool.core.date.DateUtil;
import com.sf.dangbao.core.service.DistributionTaskService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.JobExecutionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.QuartzJobBean;
@DisallowConcurrentExecution
public class TomorrowTaskJob extends QuartzJobBean {
private static Logger LOGGER = LogManager.getLogger(DistributeTaskJob.class);
@Autowired
private DistributionTaskService distributionTaskService;
/**
* 晚上九点创建明日的配送任务
* @param jobExecutionContext
*/
@Override
protected void executeInternal(JobExecutionContext jobExecutionContext) {
long start = System.currentTimeMillis();
LOGGER.info("开始生成明日配送任务");
String tomorrow = DateUtil.format(DateUtil.tomorrow(),"yyyy-MM-dd");
distributionTaskService.createTask(tomorrow);
long internal = System.currentTimeMillis() - start;
LOGGER.info("生成明日配送任务完成,耗时:{}", internal);
}
}