4 changed files with 233 additions and 52 deletions
Split View
Diff Options
-
25src/main/java/com/qniao/iot/gizwits/CloudBoxData.java
-
161src/main/java/com/qniao/iot/gizwits/GizWitsIotMonitoringDataJob.java
-
82src/test/java/Demo1.java
-
17src/test/java/Demo2.java
@ -0,0 +1,25 @@ |
|||
package com.qniao.iot.gizwits; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import java.time.LocalDateTime; |
|||
|
|||
@Data |
|||
public class CloudBoxData { |
|||
|
|||
private LocalDateTime createTime; |
|||
|
|||
private Integer dataSource; |
|||
|
|||
private LocalDateTime dataTimestamp; |
|||
|
|||
private Integer dataType; |
|||
|
|||
private Long mac; |
|||
|
|||
private Long quantity; |
|||
|
|||
private Long spaceOfTime; |
|||
|
|||
private Long totalProduction; |
|||
} |
|||
@ -1,18 +1,84 @@ |
|||
import com.qniao.iot.gizwits.CloudBoxData; |
|||
import com.qniao.iot.gizwits.utils.EsRestClientUtil; |
|||
import com.qniao.iot.machine.event.MachineIotDataReceivedEvent; |
|||
import org.apache.http.HttpHost; |
|||
import org.apache.http.auth.AuthScope; |
|||
import org.apache.http.auth.UsernamePasswordCredentials; |
|||
import org.apache.http.client.CredentialsProvider; |
|||
import org.apache.http.impl.client.BasicCredentialsProvider; |
|||
import org.elasticsearch.action.search.SearchRequest; |
|||
import org.elasticsearch.action.search.SearchResponse; |
|||
import org.elasticsearch.client.RequestOptions; |
|||
import org.elasticsearch.client.RestClient; |
|||
import org.elasticsearch.client.RestClientBuilder; |
|||
import org.elasticsearch.client.RestHighLevelClient; |
|||
import org.elasticsearch.index.query.BoolQueryBuilder; |
|||
import org.elasticsearch.index.query.QueryBuilders; |
|||
import org.elasticsearch.index.query.TermQueryBuilder; |
|||
import org.elasticsearch.rest.RestStatus; |
|||
import org.elasticsearch.search.aggregations.AggregationBuilder; |
|||
import org.elasticsearch.search.aggregations.AggregationBuilders; |
|||
import org.elasticsearch.search.aggregations.Aggregations; |
|||
import org.elasticsearch.search.aggregations.metrics.ParsedStats; |
|||
import org.elasticsearch.search.builder.SearchSourceBuilder; |
|||
|
|||
import java.io.IOException; |
|||
import java.sql.Date; |
|||
import java.time.LocalDate; |
|||
import java.time.ZoneOffset; |
|||
import java.util.ArrayList; |
|||
import java.util.HashMap; |
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
public class Demo1 { |
|||
|
|||
public static void main(String[] args) { |
|||
public static void main(String[] args) throws IOException { |
|||
|
|||
String host = "120.79.137.137:9200"; |
|||
String[] nodeIpInfos = host.split(":"); |
|||
RestClientBuilder builder = RestClient.builder(new HttpHost(nodeIpInfos[0], Integer.parseInt(nodeIpInfos[1]), "http")) |
|||
.setRequestConfigCallback(requestConfigBuilder -> { |
|||
requestConfigBuilder.setConnectTimeout(10 * 60 * 1000); |
|||
requestConfigBuilder.setSocketTimeout(10 * 60 * 1000); |
|||
requestConfigBuilder.setConnectionRequestTimeout(10 * 60 * 1000); |
|||
return requestConfigBuilder; |
|||
}); |
|||
CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); |
|||
credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("elastic", "qnol26215")); |
|||
builder.setHttpClientConfigCallback(f -> f.setDefaultCredentialsProvider(credentialsProvider)); |
|||
RestHighLevelClient client = new RestHighLevelClient(builder); |
|||
|
|||
|
|||
|
|||
|
|||
Map<String, Long> workingJobMap = new HashMap<>(); |
|||
workingJobMap.put("231231", 2325443523L); |
|||
workingJobMap.put("23rwer31", 2325443523L); |
|||
workingJobMap.put("2231f3f231", 2325443523L); |
|||
workingJobMap.clear(); |
|||
workingJobMap.put("231232222231", 2325443523L); |
|||
System.out.println(workingJobMap.get("231232222231")); |
|||
AggregationBuilder aggr1 = AggregationBuilders.stats("JobDurationTotal").field("space_of_time"); |
|||
AggregationBuilder aggr2 = AggregationBuilders.stats("JobTotal").field("quantity"); |
|||
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); |
|||
BoolQueryBuilder queryBuilder = QueryBuilders.boolQuery() |
|||
.must(QueryBuilders.termQuery("mac", 861193040814411L)) |
|||
.must(QueryBuilders.termQuery("data_type", 2)) |
|||
.must(QueryBuilders.rangeQuery ("space_of_time") |
|||
.lte(60)) |
|||
.must(QueryBuilders.rangeQuery("create_time") |
|||
.gte("2022-01-01 00:00:00") |
|||
.lte("2022-12-31 23:59:59")); |
|||
searchSourceBuilder.query(queryBuilder); |
|||
searchSourceBuilder.aggregation(aggr1); |
|||
searchSourceBuilder.aggregation(aggr2); |
|||
searchSourceBuilder.size(0); |
|||
List<CloudBoxData> receivedEventList = new ArrayList<>(); |
|||
SearchRequest request = new SearchRequest("qn_cloud_box_data_history_202208"); |
|||
request.source(searchSourceBuilder); |
|||
// 执行请求 |
|||
SearchResponse response = client.search(request, RequestOptions.DEFAULT); |
|||
// 获取响应中的聚合信息 |
|||
Aggregations aggregations = response.getAggregations(); |
|||
if (RestStatus.OK.equals(response.status()) || aggregations != null) { |
|||
ParsedStats jobDurationTotal = aggregations.get("JobDurationTotal"); |
|||
ParsedStats jobTotal = aggregations.get("JobTotal"); |
|||
double max = jobDurationTotal.getSum(); |
|||
double max1 = jobTotal.getMax(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,17 @@ |
|||
import cn.hutool.http.HttpUtil; |
|||
import cn.hutool.json.JSONObject; |
|||
import cn.hutool.json.JSONUtil; |
|||
|
|||
public class Demo2 { |
|||
|
|||
public static void main(String[] args) { |
|||
|
|||
String s = HttpUtil.get("http://api-ops-yyt.qniao.cn/show-billboard/get/billboard/module/data-script?id=3&metaData=%7B%22pageNum%22:21%7D"); |
|||
|
|||
Object data = JSONUtil.getByPath(JSONUtil.parse(s), "data"); |
|||
data = JSONUtil.getByPath(JSONUtil.parse(data), "records"); |
|||
|
|||
|
|||
System.out.println(data); |
|||
} |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save