HSScheduleTask.java 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package com.malk.hangshi.schedule;
  2. import com.malk.hangshi.service.HSService;
  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 HSScheduleTask {
  17. @Autowired
  18. private HSService hsService;
  19. /**
  20. * 每天凌晨4点同步
  21. */
  22. @Scheduled(cron = "0 0 4 * * ? ")
  23. public void syncDingTalkFailedList() {
  24. try {
  25. hsService.getDeptInfo(true);
  26. } catch (Exception e) {
  27. // 记录错误信息
  28. e.printStackTrace();
  29. }
  30. }
  31. /**
  32. * 每天8点同步
  33. */
  34. @Scheduled(cron = "0 30 9 * * ? ")
  35. public void syncHangShiInfo() {
  36. try {
  37. hsService.syncHangShiInfo();
  38. } catch (Exception e) {
  39. // 记录错误信息
  40. e.printStackTrace();
  41. }
  42. }
  43. }