add xxl-job
This commit is contained in:
parent
3b4fe6810a
commit
30e8b57530
@ -109,6 +109,11 @@
|
|||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-thymeleaf</artifactId>
|
<artifactId>spring-boot-starter-thymeleaf</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.xuxueli</groupId>
|
||||||
|
<artifactId>xxl-job-core</artifactId>
|
||||||
|
<version>2.3.1</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<build>
|
<build>
|
||||||
<resources>
|
<resources>
|
||||||
|
|||||||
@ -0,0 +1,36 @@
|
|||||||
|
package top.baogutang.admin.config;
|
||||||
|
|
||||||
|
import com.xxl.job.core.executor.impl.XxlJobSpringExecutor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description:
|
||||||
|
* @author: nikooh
|
||||||
|
* @date: 2024/06/14 : 15:29
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Configuration
|
||||||
|
public class XxlJobConfig {
|
||||||
|
|
||||||
|
@Value("${xxl.job.admin.addresses}")
|
||||||
|
private String adminAddresses;
|
||||||
|
|
||||||
|
@Value("${xxl.job.executor.appName}")
|
||||||
|
private String appName;
|
||||||
|
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public XxlJobSpringExecutor xxlJobExecutor() {
|
||||||
|
log.info(">>>>>>>>>>> xxl-job config init start <<<<<<<<<<");
|
||||||
|
XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();
|
||||||
|
xxlJobSpringExecutor.setAdminAddresses(adminAddresses);
|
||||||
|
xxlJobSpringExecutor.setAppname(appName);
|
||||||
|
log.info(">>>>>>>>>>> xxl-job config init success <<<<<<<<<<");
|
||||||
|
return xxlJobSpringExecutor;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,85 +1,85 @@
|
|||||||
package top.baogutang.admin.schedule;
|
//package top.baogutang.admin.schedule;
|
||||||
|
//
|
||||||
import com.alibaba.fastjson.JSON;
|
//import com.alibaba.fastjson.JSON;
|
||||||
import com.alibaba.fastjson.TypeReference;
|
//import com.alibaba.fastjson.TypeReference;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
//import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.collections.CollectionUtils;
|
//import org.apache.commons.collections.CollectionUtils;
|
||||||
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
//import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||||
import org.springframework.data.redis.core.RedisTemplate;
|
//import org.springframework.data.redis.core.RedisTemplate;
|
||||||
import org.springframework.scheduling.annotation.Scheduled;
|
//import org.springframework.scheduling.annotation.Scheduled;
|
||||||
import org.springframework.stereotype.Component;
|
//import org.springframework.stereotype.Component;
|
||||||
import top.baogutang.admin.dao.entity.NoticeLogEntity;
|
//import top.baogutang.admin.dao.entity.NoticeLogEntity;
|
||||||
import top.baogutang.admin.domain.AnnouncementsDto;
|
//import top.baogutang.admin.domain.AnnouncementsDto;
|
||||||
import top.baogutang.admin.services.INoticeLogService;
|
//import top.baogutang.admin.services.INoticeLogService;
|
||||||
import top.baogutang.admin.services.IWxMsgPushService;
|
//import top.baogutang.admin.services.IWxMsgPushService;
|
||||||
import top.baogutang.admin.utils.DingTalkMsgPushUtils;
|
//import top.baogutang.admin.utils.DingTalkMsgPushUtils;
|
||||||
import top.baogutang.common.constants.NoticeTypeEnum;
|
//import top.baogutang.common.constants.NoticeTypeEnum;
|
||||||
import top.baogutang.common.domain.PageUtil;
|
//import top.baogutang.common.domain.PageUtil;
|
||||||
import top.baogutang.common.domain.Results;
|
//import top.baogutang.common.domain.Results;
|
||||||
import top.baogutang.common.properties.WxMsgPushProperties;
|
//import top.baogutang.common.properties.WxMsgPushProperties;
|
||||||
import top.baogutang.common.utils.OkHttpUtil;
|
//import top.baogutang.common.utils.OkHttpUtil;
|
||||||
|
//
|
||||||
import javax.annotation.Resource;
|
//import javax.annotation.Resource;
|
||||||
import java.util.Arrays;
|
//import java.util.Arrays;
|
||||||
import java.util.List;
|
//import java.util.List;
|
||||||
import java.util.Objects;
|
//import java.util.Objects;
|
||||||
|
//
|
||||||
|
//
|
||||||
/**
|
///**
|
||||||
* @description: EDGEX公告
|
// * @description: EDGEX公告
|
||||||
* @author: nikooh
|
// * @author: nikooh
|
||||||
* @date: 2023/06/16 : 11:41
|
// * @date: 2023/06/16 : 11:41
|
||||||
*/
|
// */
|
||||||
@Slf4j
|
//@Slf4j
|
||||||
@Component
|
//@Component
|
||||||
@RefreshScope
|
//@RefreshScope
|
||||||
public class NoticeSchedule {
|
//public class NoticeSchedule {
|
||||||
|
//
|
||||||
@Resource
|
// @Resource
|
||||||
private IWxMsgPushService wxMsgPushService;
|
// private IWxMsgPushService wxMsgPushService;
|
||||||
|
//
|
||||||
@Resource
|
// @Resource
|
||||||
private WxMsgPushProperties wxMsgPushProperties;
|
// private WxMsgPushProperties wxMsgPushProperties;
|
||||||
|
//
|
||||||
@Resource
|
// @Resource
|
||||||
private RedisTemplate<String, Object> redisTemplate;
|
// private RedisTemplate<String, Object> redisTemplate;
|
||||||
|
//
|
||||||
@Resource
|
// @Resource
|
||||||
private DingTalkMsgPushUtils dingTalkMsgPushUtils;
|
// private DingTalkMsgPushUtils dingTalkMsgPushUtils;
|
||||||
|
//
|
||||||
@Resource
|
// @Resource
|
||||||
private INoticeLogService noticeLogService;
|
// private INoticeLogService noticeLogService;
|
||||||
|
//
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* 每分钟查询edge公告
|
// * 每分钟查询edge公告
|
||||||
*/
|
// */
|
||||||
@Scheduled(cron = "0 0/1 * * * ? ")
|
// @Scheduled(cron = "0 0/1 * * * ? ")
|
||||||
public void edgeNotice() {
|
// public void edgeNotice() {
|
||||||
Arrays.stream(NoticeTypeEnum.values())
|
// Arrays.stream(NoticeTypeEnum.values())
|
||||||
.forEach(noticeType -> {
|
// .forEach(noticeType -> {
|
||||||
Results<PageUtil<AnnouncementsDto>> results = OkHttpUtil.get(noticeType.getListUrl(), null, null, new TypeReference<Results<PageUtil<AnnouncementsDto>>>() {
|
// Results<PageUtil<AnnouncementsDto>> results = OkHttpUtil.get(noticeType.getListUrl(), null, null, new TypeReference<Results<PageUtil<AnnouncementsDto>>>() {
|
||||||
});
|
// });
|
||||||
log.info(">>>>>>>>>>请求获取:{}公告返回数据:{}<<<<<<<<<<", noticeType.getDesc(), JSON.toJSONString(results));
|
// log.info(">>>>>>>>>>请求获取:{}公告返回数据:{}<<<<<<<<<<", noticeType.getDesc(), JSON.toJSONString(results));
|
||||||
if (Objects.isNull(results)) {
|
// if (Objects.isNull(results)) {
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
if (!Boolean.TRUE.equals(results.isSuccess())) {
|
// if (!Boolean.TRUE.equals(results.isSuccess())) {
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
if (Objects.isNull(results.getData()) || CollectionUtils.isEmpty(results.getData().getList())) {
|
// if (Objects.isNull(results.getData()) || CollectionUtils.isEmpty(results.getData().getList())) {
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
AnnouncementsDto announcementsDto = results.getData().getList().get(0);
|
// AnnouncementsDto announcementsDto = results.getData().getList().get(0);
|
||||||
List<NoticeLogEntity> noticeLogList = noticeLogService.queryLogByConditions(announcementsDto.getId(), noticeType);
|
// List<NoticeLogEntity> noticeLogList = noticeLogService.queryLogByConditions(announcementsDto.getId(), noticeType);
|
||||||
if (CollectionUtils.isNotEmpty(noticeLogList)) {
|
// if (CollectionUtils.isNotEmpty(noticeLogList)) {
|
||||||
log.info(">>>>>>>>>>notice :{} has already pushed<<<<<<<<<<", announcementsDto.getId());
|
// log.info(">>>>>>>>>>notice :{} has already pushed<<<<<<<<<<", announcementsDto.getId());
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
String content = noticeType.getTitle() + announcementsDto.getTitle() + "\n\n + ")\n\n>";
|
// String content = noticeType.getTitle() + announcementsDto.getTitle() + "\n\n + ")\n\n>";
|
||||||
dingTalkMsgPushUtils.robotMarkdownMsgPush(announcementsDto.getTitle(), "查看详情", noticeType.getDetailUrl() + announcementsDto.getId(), content);
|
// dingTalkMsgPushUtils.robotMarkdownMsgPush(announcementsDto.getTitle(), "查看详情", noticeType.getDetailUrl() + announcementsDto.getId(), content);
|
||||||
noticeLogService.saveNotice(noticeType, announcementsDto.getId(), announcementsDto.getType(), announcementsDto.getTitle(), announcementsDto.getCover(), noticeType.getDetailUrl() + announcementsDto.getId(), announcementsDto.getCreator(), announcementsDto.getCreatedAt());
|
// noticeLogService.saveNotice(noticeType, announcementsDto.getId(), announcementsDto.getType(), announcementsDto.getTitle(), announcementsDto.getCover(), noticeType.getDetailUrl() + announcementsDto.getId(), announcementsDto.getCreator(), announcementsDto.getCreatedAt());
|
||||||
});
|
// });
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
|
|||||||
@ -0,0 +1,68 @@
|
|||||||
|
package top.baogutang.admin.schedule;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.alibaba.fastjson.TypeReference;
|
||||||
|
import com.xxl.job.core.handler.annotation.XxlJob;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
|
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import top.baogutang.admin.dao.entity.NoticeLogEntity;
|
||||||
|
import top.baogutang.admin.domain.AnnouncementsDto;
|
||||||
|
import top.baogutang.admin.services.INoticeLogService;
|
||||||
|
import top.baogutang.admin.utils.DingTalkMsgPushUtils;
|
||||||
|
import top.baogutang.common.constants.NoticeTypeEnum;
|
||||||
|
import top.baogutang.common.domain.PageUtil;
|
||||||
|
import top.baogutang.common.domain.Results;
|
||||||
|
import top.baogutang.common.utils.OkHttpUtil;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description:
|
||||||
|
* @author: nikooh
|
||||||
|
* @date: 2024/06/14 : 16:18
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Component
|
||||||
|
@RefreshScope
|
||||||
|
public class NoticeScheduleHandler {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private DingTalkMsgPushUtils dingTalkMsgPushUtils;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private INoticeLogService noticeLogService;
|
||||||
|
|
||||||
|
|
||||||
|
@XxlJob("NoticeScheduleHandler")
|
||||||
|
public void noticeScheduleHandler() throws Exception {
|
||||||
|
Arrays.stream(NoticeTypeEnum.values())
|
||||||
|
.forEach(noticeType -> {
|
||||||
|
Results<PageUtil<AnnouncementsDto>> results = OkHttpUtil.get(noticeType.getListUrl(), null, null, new TypeReference<Results<PageUtil<AnnouncementsDto>>>() {
|
||||||
|
});
|
||||||
|
log.info(">>>>>>>>>>请求获取:{}公告返回数据:{}<<<<<<<<<<", noticeType.getDesc(), JSON.toJSONString(results));
|
||||||
|
if (Objects.isNull(results)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!Boolean.TRUE.equals(results.isSuccess())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (Objects.isNull(results.getData()) || CollectionUtils.isEmpty(results.getData().getList())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
AnnouncementsDto announcementsDto = results.getData().getList().get(0);
|
||||||
|
List<NoticeLogEntity> noticeLogList = noticeLogService.queryLogByConditions(announcementsDto.getId(), noticeType);
|
||||||
|
if (CollectionUtils.isNotEmpty(noticeLogList)) {
|
||||||
|
log.info(">>>>>>>>>>notice :{} has already pushed<<<<<<<<<<", announcementsDto.getId());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String content = noticeType.getTitle() + announcementsDto.getTitle() + "\n\n + ")\n\n>";
|
||||||
|
dingTalkMsgPushUtils.robotMarkdownMsgPush(announcementsDto.getTitle(), "查看详情", noticeType.getDetailUrl() + announcementsDto.getId(), content);
|
||||||
|
noticeLogService.saveNotice(noticeType, announcementsDto.getId(), announcementsDto.getType(), announcementsDto.getTitle(), announcementsDto.getCover(), noticeType.getDetailUrl() + announcementsDto.getId(), announcementsDto.getCreator(), announcementsDto.getCreatedAt());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user