DownLoadYxJob.java 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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.context.annotation.Lazy;
  8. import org.springframework.scheduling.Trigger;
  9. import org.springframework.scheduling.TriggerContext;
  10. import org.springframework.scheduling.annotation.EnableScheduling;
  11. import org.springframework.scheduling.annotation.SchedulingConfigurer;
  12. import org.springframework.scheduling.config.ScheduledTaskRegistrar;
  13. import org.springframework.scheduling.support.CronTrigger;
  14. import org.springframework.stereotype.Component;
  15. import java.util.Date;
  16. @Lazy(false)
  17. @Component
  18. @EnableScheduling
  19. public class DownLoadYxJob implements SchedulingConfigurer {
  20. private static final Logger logger = LoggerFactory.getLogger(DownLoadYxJob.class);
  21. private static String cron = "0 0 0 * * ?";//"0 0 0 * * ?";0 */5 * * * ?
  22. @Autowired
  23. private YkyyPrescriptionService ykyyPrescriptionService;
  24. @Override
  25. public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
  26. taskRegistrar.addTriggerTask(new Runnable() {
  27. @Override
  28. public void run() {
  29. logger.info("START========OverdueJob========");
  30. try {
  31. ykyyPrescriptionService.findYxVideoList();
  32. logger.info("END========OverdueJob========");
  33. } catch (Exception e) {
  34. e.printStackTrace();
  35. logger.error("END===ERROE===OverdueJob,message:"+e.getMessage());
  36. }
  37. }
  38. }, new Trigger() {
  39. @Override
  40. public Date nextExecutionTime(TriggerContext triggerContext) {
  41. // 任务触发,可修改任务的执行周期
  42. CronTrigger trigger = new CronTrigger(cron);
  43. System.out.println("OverdueJob任务触发,可修改任务的执行周期"+cron);
  44. Date nextExec = trigger.nextExecutionTime(triggerContext);
  45. return nextExec;
  46. }
  47. });
  48. }
  49. }