//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<String, Object> 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<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![](" + 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());
//                });
//
//    }
//}
