HKScheduleTask.java 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. package com.malk.hake.schedule;
  2. import com.malk.hake.service.HKClient;
  3. import com.malk.utils.UtilDateTime;
  4. import lombok.extern.slf4j.Slf4j;
  5. import org.springframework.beans.factory.annotation.Autowired;
  6. import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
  7. import org.springframework.context.annotation.Configuration;
  8. import org.springframework.scheduling.annotation.EnableScheduling;
  9. import org.springframework.scheduling.annotation.Scheduled;
  10. import java.util.Date;
  11. /**
  12. * @EnableScheduling 开启定时任务 [配置参考McScheduleTask]
  13. */
  14. @Slf4j
  15. @Configuration
  16. @EnableScheduling
  17. @ConditionalOnProperty(name = {"spel.scheduling"})
  18. public class HKScheduleTask {
  19. @Autowired
  20. private HKClient hkClient;
  21. /**
  22. * 同步通讯录: 早上6:00, 下午16:00
  23. */
  24. @Scheduled(cron = "0 0 6,16 * * ? ")
  25. public void timer_1() {
  26. try {
  27. hkClient.syncContact(false);
  28. } catch (Exception e) {
  29. // 记录错误信息
  30. e.printStackTrace();
  31. }
  32. }
  33. /**
  34. * 同步通讯录: 中午11:30, 下午19:30
  35. */
  36. @Scheduled(cron = "0 30 11,19 * * ? ")
  37. public void timer_2() {
  38. try {
  39. hkClient.syncContact(false);
  40. } catch (Exception e) {
  41. // 记录错误信息
  42. e.printStackTrace();
  43. }
  44. }
  45. /**
  46. * 同步付款: 每次凌晨1点
  47. */
  48. @Scheduled(cron = "0 0 1 * * ? ")
  49. public void timer_3() {
  50. try {
  51. hkClient.syncMonitor("FKSQ", null);
  52. } catch (Exception e) {
  53. // 记录错误信息
  54. e.printStackTrace();
  55. }
  56. }
  57. /**
  58. * 同步预付款: 每次凌晨2点
  59. */
  60. @Scheduled(cron = "0 0 2 * * ? ")
  61. public void timer_4() {
  62. try {
  63. hkClient.syncMonitor("YFKSQ", null);
  64. } catch (Exception e) {
  65. // 记录错误信息
  66. e.printStackTrace();
  67. }
  68. }
  69. /**
  70. * 清理打卡标记位: 每天早晨7点 [废弃, 通过全量同步处理]
  71. */
  72. @Scheduled(cron = "0 0 7 * * ? ")
  73. public void timer_5() {
  74. //hkClient.clearClockStatus();
  75. }
  76. /**
  77. * 同步前一日全量考勤数据
  78. */
  79. @Scheduled(cron = "0 50 7 * * ? ")
  80. public void timer_6() {
  81. hkClient.syncAttendance(UtilDateTime.formatDate(new Date(new Date().getTime() - 24 * 60 * 60 * 1000)), null);
  82. }
  83. }