1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- package com.yihu.jw.util;
- import com.yihu.jw.hospital.prescription.service.YkyyPrescriptionService;
- import com.yihu.jw.hospital.prescription.service.entrance.YkyyEntranceService;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.context.annotation.Lazy;
- import org.springframework.scheduling.Trigger;
- import org.springframework.scheduling.TriggerContext;
- import org.springframework.scheduling.annotation.EnableScheduling;
- import org.springframework.scheduling.annotation.SchedulingConfigurer;
- import org.springframework.scheduling.config.ScheduledTaskRegistrar;
- import org.springframework.scheduling.support.CronTrigger;
- import org.springframework.stereotype.Component;
- import java.util.Date;
- @Lazy(false)
- @Component
- @EnableScheduling
- public class DownLoadYxJob implements SchedulingConfigurer {
- private static final Logger logger = LoggerFactory.getLogger(DownLoadYxJob.class);
- private static String cron = "0 0 0 * * ?";//"0 0 0 * * ?";0 */5 * * * ?
- @Autowired
- private YkyyPrescriptionService ykyyPrescriptionService;
- @Override
- public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
- taskRegistrar.addTriggerTask(new Runnable() {
- @Override
- public void run() {
- logger.info("START========OverdueJob========");
- try {
- ykyyPrescriptionService.findYxVideoList();
- logger.info("END========OverdueJob========");
- } catch (Exception e) {
- e.printStackTrace();
- logger.error("END===ERROE===OverdueJob,message:"+e.getMessage());
- }
- }
- }, new Trigger() {
- @Override
- public Date nextExecutionTime(TriggerContext triggerContext) {
- // 任务触发,可修改任务的执行周期
- CronTrigger trigger = new CronTrigger(cron);
- System.out.println("OverdueJob任务触发,可修改任务的执行周期"+cron);
- Date nextExec = trigger.nextExecutionTime(triggerContext);
- return nextExec;
- }
- });
- }
- }
|