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