ScheduleTask.java 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package com.malk.yibaoju.schedule;
  2. import com.malk.yibaoju.service.YBJService;
  3. import lombok.extern.slf4j.Slf4j;
  4. import org.springframework.beans.factory.annotation.Autowired;
  5. import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
  6. import org.springframework.context.annotation.Configuration;
  7. import org.springframework.scheduling.annotation.EnableScheduling;
  8. import org.springframework.scheduling.annotation.Scheduled;
  9. /**
  10. * @EnableScheduling 开启定时任务 [配置参考McScheduleTask]
  11. */
  12. @Slf4j
  13. @Configuration
  14. @EnableScheduling
  15. @ConditionalOnProperty(name = {"spel.scheduling"})
  16. public class ScheduleTask {
  17. @Autowired
  18. private YBJService ybjService;
  19. /**
  20. * 每月25日0点5分执行定时任务
  21. */
  22. @Scheduled(cron = "0 30 0 25 * ?")
  23. public void syncDingTalkFailedList() {
  24. try {
  25. ybjService.syncCreatePlan();
  26. } catch (Exception e) {
  27. // 记录错误信息
  28. e.printStackTrace();
  29. }
  30. }
  31. /**
  32. * 每天凌晨1-4点更新计划护理的任务状态
  33. */
  34. @Scheduled(cron = " 0 5 0 * * ? ")
  35. public void syncDingTalkStatus() {
  36. try {
  37. ybjService.syncUpdatePlanStatus();
  38. } catch (Exception e) {
  39. // 记录错误信息
  40. e.printStackTrace();
  41. }
  42. }
  43. }