DownLoadYxJob.java 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package com.yihu.jw.util;
  2. import com.yihu.jw.hospital.prescription.service.YkyyPrescriptionService;
  3. import com.yihu.jw.hospital.prescription.service.entrance.YkyyEntranceService;
  4. import org.slf4j.Logger;
  5. import org.slf4j.LoggerFactory;
  6. import org.springframework.beans.factory.annotation.Autowired;
  7. import org.springframework.scheduling.Trigger;
  8. import org.springframework.scheduling.TriggerContext;
  9. import org.springframework.scheduling.annotation.SchedulingConfigurer;
  10. import org.springframework.scheduling.config.ScheduledTaskRegistrar;
  11. import org.springframework.scheduling.support.CronTrigger;
  12. import java.util.Date;
  13. public class DownLoadYxJob implements SchedulingConfigurer {
  14. private static final Logger logger = LoggerFactory.getLogger(DownLoadYxJob.class);
  15. private static String cron = "0 0 0 * * ?";//"0 0 0 * * ?";0 */5 * * * ?
  16. @Autowired
  17. private YkyyPrescriptionService ykyyPrescriptionService;
  18. @Override
  19. public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
  20. taskRegistrar.addTriggerTask(new Runnable() {
  21. @Override
  22. public void run() {
  23. logger.info("START========OverdueJob========");
  24. try {
  25. ykyyPrescriptionService.findYxVideoList();
  26. logger.info("END========OverdueJob========");
  27. } catch (Exception e) {
  28. e.printStackTrace();
  29. logger.error("END===ERROE===OverdueJob,message:"+e.getMessage());
  30. }
  31. }
  32. }, new Trigger() {
  33. @Override
  34. public Date nextExecutionTime(TriggerContext triggerContext) {
  35. // 任务触发,可修改任务的执行周期
  36. CronTrigger trigger = new CronTrigger(cron);
  37. System.out.println("OverdueJob任务触发,可修改任务的执行周期"+cron);
  38. Date nextExec = trigger.nextExecutionTime(triggerContext);
  39. return nextExec;
  40. }
  41. });
  42. }
  43. }