diff --git a/baogutang-admin/pom.xml b/baogutang-admin/pom.xml index ccb3027..7633860 100644 --- a/baogutang-admin/pom.xml +++ b/baogutang-admin/pom.xml @@ -109,6 +109,11 @@ org.springframework.boot spring-boot-starter-thymeleaf + + com.xuxueli + xxl-job-core + 2.3.1 + diff --git a/baogutang-admin/src/main/java/top/baogutang/admin/config/XxlJobConfig.java b/baogutang-admin/src/main/java/top/baogutang/admin/config/XxlJobConfig.java new file mode 100644 index 0000000..836def0 --- /dev/null +++ b/baogutang-admin/src/main/java/top/baogutang/admin/config/XxlJobConfig.java @@ -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; + } + + +} diff --git a/baogutang-admin/src/main/java/top/baogutang/admin/schedule/NoticeSchedule.java b/baogutang-admin/src/main/java/top/baogutang/admin/schedule/NoticeSchedule.java index 92fc075..ab501e6 100644 --- a/baogutang-admin/src/main/java/top/baogutang/admin/schedule/NoticeSchedule.java +++ b/baogutang-admin/src/main/java/top/baogutang/admin/schedule/NoticeSchedule.java @@ -1,85 +1,85 @@ -package top.baogutang.admin.schedule; - -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.TypeReference; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.collections.CollectionUtils; -import org.springframework.cloud.context.config.annotation.RefreshScope; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.scheduling.annotation.Scheduled; -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.services.IWxMsgPushService; -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.properties.WxMsgPushProperties; -import top.baogutang.common.utils.OkHttpUtil; - -import javax.annotation.Resource; -import java.util.Arrays; -import java.util.List; -import java.util.Objects; - - -/** - * @description: EDGEX公告 - * @author: nikooh - * @date: 2023/06/16 : 11:41 - */ -@Slf4j -@Component -@RefreshScope -public class NoticeSchedule { - - @Resource - private IWxMsgPushService wxMsgPushService; - - @Resource - private WxMsgPushProperties wxMsgPushProperties; - - @Resource - private RedisTemplate redisTemplate; - - @Resource - private DingTalkMsgPushUtils dingTalkMsgPushUtils; - - @Resource - private INoticeLogService noticeLogService; - - - /** - * 每分钟查询edge公告 - */ - @Scheduled(cron = "0 0/1 * * * ? ") - public void edgeNotice() { - Arrays.stream(NoticeTypeEnum.values()) - .forEach(noticeType -> { - Results> results = OkHttpUtil.get(noticeType.getListUrl(), null, null, new TypeReference>>() { - }); - 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 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![](" + announcementsDto.getCover() + ")\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()); - }); - - } -} +//package top.baogutang.admin.schedule; +// +//import com.alibaba.fastjson.JSON; +//import com.alibaba.fastjson.TypeReference; +//import lombok.extern.slf4j.Slf4j; +//import org.apache.commons.collections.CollectionUtils; +//import org.springframework.cloud.context.config.annotation.RefreshScope; +//import org.springframework.data.redis.core.RedisTemplate; +//import org.springframework.scheduling.annotation.Scheduled; +//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.services.IWxMsgPushService; +//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.properties.WxMsgPushProperties; +//import top.baogutang.common.utils.OkHttpUtil; +// +//import javax.annotation.Resource; +//import java.util.Arrays; +//import java.util.List; +//import java.util.Objects; +// +// +///** +// * @description: EDGEX公告 +// * @author: nikooh +// * @date: 2023/06/16 : 11:41 +// */ +//@Slf4j +//@Component +//@RefreshScope +//public class NoticeSchedule { +// +// @Resource +// private IWxMsgPushService wxMsgPushService; +// +// @Resource +// private WxMsgPushProperties wxMsgPushProperties; +// +// @Resource +// private RedisTemplate redisTemplate; +// +// @Resource +// private DingTalkMsgPushUtils dingTalkMsgPushUtils; +// +// @Resource +// private INoticeLogService noticeLogService; +// +// +// /** +// * 每分钟查询edge公告 +// */ +// @Scheduled(cron = "0 0/1 * * * ? ") +// public void edgeNotice() { +// Arrays.stream(NoticeTypeEnum.values()) +// .forEach(noticeType -> { +// Results> results = OkHttpUtil.get(noticeType.getListUrl(), null, null, new TypeReference>>() { +// }); +// 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 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![](" + announcementsDto.getCover() + ")\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()); +// }); +// +// } +//} diff --git a/baogutang-admin/src/main/java/top/baogutang/admin/schedule/NoticeScheduleHandler.java b/baogutang-admin/src/main/java/top/baogutang/admin/schedule/NoticeScheduleHandler.java new file mode 100644 index 0000000..b61e58f --- /dev/null +++ b/baogutang-admin/src/main/java/top/baogutang/admin/schedule/NoticeScheduleHandler.java @@ -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> results = OkHttpUtil.get(noticeType.getListUrl(), null, null, new TypeReference>>() { + }); + 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 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![](" + announcementsDto.getCover() + ")\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()); + }); + } +}