| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- package com.malk.schedule;
- import com.malk.service.dingtalk.DDClient;
- import com.malk.service.dingtalk.DDClient_Event;
- 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;
- /**
- * 定时任务ScheduleTask
- * -
- * 1. @EnableScheduling:开启定时任务,当前文件文件全局注解【也可单独成为一个控制的配置文件管控全局】
- * 2. @Scheduled:定时执行的方法,通过入参控制
- * - 1. @Scheduled(fixedDelay = 5000):单位毫秒,当任务执行完毕后5s后再执行
- * - 2. @Scheduled(fixedRate = 3000):单位毫秒,表示每隔3秒,不受执行时间影响
- * - 3. cron表达式:cron一共有7位,但是最后一位是年,可以留空,cron中,还有一些特殊的符号
- * 3. @component / @Configuration:声明定时任务为组件类。若不声明,定时器无效,因为没有注入
- */
- /**
- * @EnableScheduling 条件注入, 根据条件确定当前类是否要装载Bean: 如定时器开发环境不启动
- * -
- * 示例:注意格式 @ConditionalOnExpression(value = "${spel.scheduling}") 或者 @ConditionalOnProperty(name = "spel.scheduling", havingValue = "false")
- * *
- * @ConditionalOnExpression,可多个参数,支持与、或关系,默认匹配bool。注意若对应环境未识别到声明会报错
- * @ConditionalOnProperty,可多个参数,支持与,若获取值为空识别为false,若有值则将该值与havingValue指定的值进行比较,匹配结果为bool。不支持或
- */
- @Slf4j
- @Configuration
- @EnableScheduling
- @ConditionalOnProperty(name = {"spel.scheduling"}, havingValue = "false")
- public class McScheduleTask {
- @Autowired
- private DDClient ddClient;
- @Autowired
- private DDClient_Event ddClient_event;
- /**
- * 钉钉事件回调 3_3
- * -
- * 同步钉钉推送失败记录: 推送失败列表, 获取后记录会被清空
- */
- // @Scheduled(cron = "0 0/30 7-23 * * ?")
- public void syncDingTalkFailedList() {
- try {
- ddClient_event.syncFailedList(ddClient.getAccessToken());
- } catch (Exception e) {
- // 记录错误信息
- e.printStackTrace();
- }
- }
- }
|