ProjectChangeSyncTimer.java 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package com.malk.timer;
  2. import com.malk.service.workhours.WorkHoursCalcService;
  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. * 项目变更审批增量同步定时器
  11. * <p>
  12. * 启用后每天 2 次错峰扫描项目变更审批表单最近 7 天 gmtModified 的实例,
  13. * 对涉及员工的应报工时按「变更生效日之后」重算 Manager (仅外部员工受影响; 内部员工 Manager 走钉钉主管不受本任务影响)。
  14. * <p>
  15. * cron 时点故意错开 WorkHoursCalcTimer 的 03:30/12:45, 避免宜搭 QPS 突发叠加。
  16. */
  17. @Slf4j
  18. @Configuration
  19. @EnableScheduling
  20. // fixme 审批表 Schema 未核验前默认不注册定时器,避免按错误字段映射回写 Manager
  21. @ConditionalOnProperty(prefix = "workhours", name = "projectChangeSyncEnabled", havingValue = "true")
  22. public class ProjectChangeSyncTimer {
  23. @Autowired
  24. private WorkHoursCalcService workHoursCalcService;
  25. // 每天 03:15 / 12:30 两次错峰 (均早于 WorkHoursCalcTimer 的 03:30 / 12:45 15 分钟, 避免 QPS 叠加)
  26. @Scheduled(cron = "0 15 3 * * ?")
  27. @Scheduled(cron = "0 30 12 * * ?")
  28. public void syncProjectChanges() {
  29. log.info("开始执行项目变更审批增量同步任务");
  30. try {
  31. workHoursCalcService.syncProjectChanges(7);
  32. log.info("项目变更审批增量同步任务执行完成");
  33. } catch (Exception e) {
  34. log.error("项目变更审批增量同步任务执行失败", e);
  35. }
  36. }
  37. }