效果如图:
- 首先创建企业微信机器人
接下来会如下所示获取到消息推送url
2.基于ES查询获取库中信息进行预警:
package com.adgn.timer.timer;
import com.adgn.timer.config.Config;
import com.adgn.timer.domain.EarlyWarningVo;
import com.adgn.timer.utils.httputils.HttpUtils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import org.apache.commons.lang3.StringUtils;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.index.query.RangeQueryBuilder;
import org.elasticsearch.search.aggregations.AbstractAggregationBuilder;
import org.elasticsearch.search.aggregations.Aggregation;
import org.elasticsearch.search.aggregations.AggregationBuilders;
import org.elasticsearch.search.aggregations.bucket.terms.IncludeExclude;
import org.elasticsearch.search.aggregations.bucket.terms.ParsedStringTerms;
import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
/**
* @Author sannian
* @Date 2022/1/5 10:51
* @Version 1.0
*/
@Component
@EnableScheduling
public class EarlyWarningScheduledReady {
public final static Logger logger = LoggerFactory.getLogger(EarlyWarningScheduledReady.class);
@Autowired
public RestHighLevelClient restHighLevelClient;
@Scheduled(cron = "0 0 0/6 * * ?")
@Async("threadPoolTaskExecutor")
public void init(){
try {
logger.info("预警定时器启动");
// String url = "http://192.168.3.212:9999//v1/getInfoSource";
String resp = HttpUtils.get(url);
if (StringUtils.isBlank(resp)) {
logger.error("[domain cache] resp is empty ! url -> {}, resp -> {}", url, resp);
}
JSONArray result = JSON.parseArray(resp);
List<EarlyWarningVo> arrayList = result.toJavaList(EarlyWarningVo.class);
getData(arrayList);
}catch (Exception