msg push
This commit is contained in:
parent
127c7ed8ab
commit
03a70aeb53
@ -6,6 +6,7 @@ import com.zjiecode.wxpusher.client.bean.Message;
|
|||||||
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.scheduling.annotation.Scheduled;
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import top.baogutang.admin.domain.EdgeXAnnouncementsDto;
|
import top.baogutang.admin.domain.EdgeXAnnouncementsDto;
|
||||||
@ -17,6 +18,9 @@ import top.baogutang.common.utils.HttpUtils;
|
|||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import static top.baogutang.common.constants.CacheConstant.MSG_PUSH_PREFIX_KEY;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description: EDGEX公告
|
* @description: EDGEX公告
|
||||||
@ -34,12 +38,17 @@ public class EdgeXNoticeSchedule {
|
|||||||
@Resource
|
@Resource
|
||||||
private WxMsgPushProperties wxMsgPushProperties;
|
private WxMsgPushProperties wxMsgPushProperties;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private RedisTemplate<String, Object> redisTemplate;
|
||||||
|
|
||||||
|
private static final String REQUEST_URL = "https://art-api.edge-x.cn/api/v1/art/announcements?pageNum=1&pageSize=1";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 每分钟查询edgeX公告
|
* 每分钟查询edgeX公告
|
||||||
*/
|
*/
|
||||||
@Scheduled(cron = "0 0/1 * * * ? ")
|
@Scheduled(cron = "0 0/1 * * * ? ")
|
||||||
public void edgeXNotice() {
|
public void edgeXNotice() {
|
||||||
Results<Page<EdgeXAnnouncementsDto>> results = HttpUtils.get("https://art-api.edge-x.cn/api/v1/art/announcements?pageNum=1&pageSize=1", new TypeReference<Results<Page<EdgeXAnnouncementsDto>>>() {
|
Results<Page<EdgeXAnnouncementsDto>> results = HttpUtils.get(REQUEST_URL, new TypeReference<Results<Page<EdgeXAnnouncementsDto>>>() {
|
||||||
});
|
});
|
||||||
log.info(">>>>>>>>>>请求获取edgeX公告返回数据:{}<<<<<<<<<<", JSON.toJSONString(results));
|
log.info(">>>>>>>>>>请求获取edgeX公告返回数据:{}<<<<<<<<<<", JSON.toJSONString(results));
|
||||||
if (Objects.isNull(results)) {
|
if (Objects.isNull(results)) {
|
||||||
@ -52,7 +61,10 @@ public class EdgeXNoticeSchedule {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
EdgeXAnnouncementsDto announcementsDto = results.getData().getList().get(0);
|
EdgeXAnnouncementsDto announcementsDto = results.getData().getList().get(0);
|
||||||
if (Math.abs(announcementsDto.getCreatedAt().getTime() - System.currentTimeMillis()) <= 60000) {
|
String cacheKey = String.format(MSG_PUSH_PREFIX_KEY, announcementsDto.getId());
|
||||||
|
|
||||||
|
Boolean result = redisTemplate.opsForValue().setIfAbsent(cacheKey, 1, 5, TimeUnit.DAYS);
|
||||||
|
if (Boolean.TRUE.equals(result)) {
|
||||||
wxMsgPushService.msgPush(Message.CONTENT_TYPE_HTML, announcementsDto.getTitle(), announcementsDto.getContent(), wxMsgPushProperties.getTopicIds());
|
wxMsgPushService.msgPush(Message.CONTENT_TYPE_HTML, announcementsDto.getTitle(), announcementsDto.getContent(), wxMsgPushProperties.getTopicIds());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -27,5 +27,11 @@ public class CacheConstant {
|
|||||||
public static final String SYS_TOKEN = "top:baogutang:sys:user:token:";
|
public static final String SYS_TOKEN = "top:baogutang:sys:user:token:";
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 消息推送
|
||||||
|
*/
|
||||||
|
public static final String MSG_PUSH_PREFIX_KEY = "top:baogutang:msg:push:%d:";
|
||||||
|
|
||||||
|
|
||||||
public static final Integer ENABLE = 0;
|
public static final Integer ENABLE = 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user