ABScheduleTask.java 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package com.malk.aipocloud.schedule;
  2. import com.malk.aipocloud.service.ABClient;
  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. import java.time.LocalDateTime;
  10. /**
  11. * @EnableScheduling 开启定时任务 [配置参考McScheduleTask]
  12. */
  13. @Slf4j
  14. @Configuration
  15. @EnableScheduling
  16. @ConditionalOnProperty(name = {"spel.scheduling"})
  17. public class ABScheduleTask {
  18. @Autowired
  19. private ABClient abClient;
  20. /**
  21. * 同步审批单: 查询5min, 避免拒绝\撤销重复推送问题
  22. */
  23. @Scheduled(cron = "0 1/5 * * * ?")
  24. public void timer_1() {
  25. try {
  26. // todo utc时间和gmt+8时间,是utc加上8小时就是gmt时间
  27. LocalDateTime now = LocalDateTime.now().minusHours(8);
  28. abClient.syncProcess(now.minusMinutes(5), now);
  29. } catch (Exception e) {
  30. // 记录错误信息
  31. e.printStackTrace();
  32. }
  33. }
  34. /**
  35. * 同步通讯录: 每小时3分执行, 错开审批单同步
  36. */
  37. @Scheduled(cron = "0 3 * * * ?")
  38. public void timer_2() {
  39. try {
  40. abClient.syncContact();
  41. } catch (Exception e) {
  42. // 记录错误信息
  43. e.printStackTrace();
  44. }
  45. }
  46. }