|
@@ -7,13 +7,18 @@ import cn.com.taiji.domain.StaticOrDynamicData;
|
|
|
import cn.com.taiji.domain.dto.LeaceOutDto;
|
|
|
import cn.com.taiji.service.FusionAnalysisService;
|
|
|
import cn.com.taiji.utils.DateUtils;
|
|
|
+import cn.hutool.core.io.LineHandler;
|
|
|
import com.alibaba.excel.EasyExcel;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.http.client.config.RequestConfig;
|
|
|
import org.elasticsearch.action.search.SearchRequest;
|
|
|
import org.elasticsearch.action.search.SearchResponse;
|
|
|
+import org.elasticsearch.client.HttpAsyncResponseConsumerFactory;
|
|
|
import org.elasticsearch.client.RequestOptions;
|
|
|
+import org.elasticsearch.client.RestClientBuilder;
|
|
|
import org.elasticsearch.client.RestHighLevelClient;
|
|
|
+import org.elasticsearch.core.TimeValue;
|
|
|
import org.elasticsearch.index.query.BoolQueryBuilder;
|
|
|
import org.elasticsearch.index.query.QueryBuilders;
|
|
|
import org.elasticsearch.search.SearchHit;
|
|
@@ -34,6 +39,7 @@ import org.springframework.stereotype.Service;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
+import java.lang.reflect.Field;
|
|
|
import java.net.URLEncoder;
|
|
|
import java.text.ParseException;
|
|
|
import java.util.ArrayList;
|
|
@@ -51,6 +57,21 @@ import static cn.com.taiji.constants.EsIndexConstants.*;
|
|
|
@Service
|
|
|
public class FusionAnalysisServiceImpl implements FusionAnalysisService {
|
|
|
|
|
|
+ private static final RequestOptions COMMON_OPTIONS;
|
|
|
+
|
|
|
+ static {
|
|
|
+ RequestConfig requestConfig = RequestConfig.custom()
|
|
|
+ .setConnectTimeout(5000)
|
|
|
+ .setSocketTimeout(60000)
|
|
|
+ .build();
|
|
|
+ RequestOptions.Builder builder = RequestOptions.DEFAULT.toBuilder();
|
|
|
+ builder.setRequestConfig(requestConfig).setHttpAsyncResponseConsumerFactory(
|
|
|
+ // 设置查询内容大小限制,默认100 * 1024 * 1024
|
|
|
+ new HttpAsyncResponseConsumerFactory.HeapBufferedResponseConsumerFactory(5*1024 * 1024 * 1024)
|
|
|
+ );
|
|
|
+ COMMON_OPTIONS = builder.build();
|
|
|
+ }
|
|
|
+
|
|
|
@Autowired
|
|
|
private RestHighLevelClient client;
|
|
|
|
|
@@ -67,7 +88,7 @@ public class FusionAnalysisServiceImpl implements FusionAnalysisService {
|
|
|
searchSourceBuilder.query(boolQueryBuilder);
|
|
|
TermsAggregationBuilder aggBuilder = AggregationBuilders.terms("ship_field_agg")
|
|
|
.field("mergeTarget")
|
|
|
- .size(1000000)
|
|
|
+ .size(query.getPageSize())
|
|
|
.subAggregation(
|
|
|
AggregationBuilders.topHits("ship_field_agg_top1")
|
|
|
.size(100)
|
|
@@ -78,9 +99,12 @@ public class FusionAnalysisServiceImpl implements FusionAnalysisService {
|
|
|
searchSourceBuilder
|
|
|
.trackTotalHits(true)
|
|
|
.aggregation(aggBuilder)
|
|
|
- .size(1000000);
|
|
|
+ .size(query.getPageSize())
|
|
|
+ .timeout(TimeValue.timeValueHours(1L))
|
|
|
+ .timeout(TimeValue.timeValueMinutes(30L))
|
|
|
+ .timeout(TimeValue.timeValueSeconds(500L));
|
|
|
request.source(searchSourceBuilder);
|
|
|
- SearchResponse search = client.search(request, RequestOptions.DEFAULT);
|
|
|
+ SearchResponse search = client.search(request, COMMON_OPTIONS);
|
|
|
Aggregations aggregations = search.getAggregations();
|
|
|
ParsedStringTerms aggregation = aggregations.get("ship_field_agg");
|
|
|
for (Terms.Bucket bucket : aggregation.getBuckets()) {
|
|
@@ -89,12 +113,6 @@ public class FusionAnalysisServiceImpl implements FusionAnalysisService {
|
|
|
SearchHits searchHits = topHits.getHits();
|
|
|
Long value = searchHits.getTotalHits().value;
|
|
|
SearchHit[] hits = searchHits.getHits();
|
|
|
- JSONObject sourceItem = JSONObject.parseObject(hits[0].getSourceAsString());
|
|
|
- JSONObject sourceItem2 = JSONObject.parseObject(hits[value.intValue()-1].getSourceAsString());
|
|
|
- data.setMergeTarget(sourceItem.getString("mergeTarget"));
|
|
|
- data.setTrackCount(value);
|
|
|
- data.setStartTime(sourceItem.getString("mergeTime"));
|
|
|
- data.setEndTime(sourceItem2.getString("mergeTime"));
|
|
|
Integer num = 0;
|
|
|
for (int i = 0; i < hits.length; i++) {
|
|
|
if (i != hits.length-1){
|
|
@@ -108,8 +126,16 @@ public class FusionAnalysisServiceImpl implements FusionAnalysisService {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- data.setFluctuateNumber(num);
|
|
|
- list.add(data);
|
|
|
+ if (num>0){
|
|
|
+ JSONObject sourceItem = JSONObject.parseObject(hits[0].getSourceAsString());
|
|
|
+ JSONObject sourceItem2 = JSONObject.parseObject(hits[value.intValue()-1].getSourceAsString());
|
|
|
+ data.setMergeTarget(sourceItem.getString("mergeTarget"));
|
|
|
+ data.setTrackCount(value);
|
|
|
+ data.setStartTime(sourceItem.getString("mergeTime"));
|
|
|
+ data.setEndTime(sourceItem2.getString("mergeTime"));
|
|
|
+ data.setFluctuateNumber(num);
|
|
|
+ list.add(data);
|
|
|
+ }
|
|
|
}
|
|
|
try {
|
|
|
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
|
@@ -126,6 +152,7 @@ public class FusionAnalysisServiceImpl implements FusionAnalysisService {
|
|
|
|
|
|
@Override
|
|
|
public void fusionAnalysisExcelTwo(FusionQuery query, HttpServletResponse response) throws IOException, ParseException {
|
|
|
+
|
|
|
List<FusionData> list = new ArrayList<>();
|
|
|
Date startTime = DateUtils.parse(query.getStartTime(),"yyyy-MM-dd");
|
|
|
String time = DateUtils.format(startTime,"yyyy-MM-dd");
|
|
@@ -137,15 +164,15 @@ public class FusionAnalysisServiceImpl implements FusionAnalysisService {
|
|
|
searchSourceBuilder.query(boolQueryBuilder);
|
|
|
TermsAggregationBuilder aggBuilder = AggregationBuilders.terms("ship_field_agg")
|
|
|
.field("mergeTarget")
|
|
|
- .size(1000000)
|
|
|
+ .size(query.getPageSize())
|
|
|
.subAggregation(
|
|
|
AggregationBuilders.terms("ship_field_agg_one")
|
|
|
.field("targetCourse")
|
|
|
- .size(1000000)
|
|
|
+ .size(query.getPageSize())
|
|
|
.subAggregation(
|
|
|
AggregationBuilders.terms("ship_field_agg_two")
|
|
|
.field("targetSpeed")
|
|
|
- .size(1000000)
|
|
|
+ .size(query.getPageSize())
|
|
|
.subAggregation(AggregationBuilders.topHits("ship_field_agg_top1")
|
|
|
.size(100)
|
|
|
.sort(
|
|
@@ -156,9 +183,12 @@ public class FusionAnalysisServiceImpl implements FusionAnalysisService {
|
|
|
searchSourceBuilder
|
|
|
.trackTotalHits(true)
|
|
|
.aggregation(aggBuilder)
|
|
|
- .size(1000000);
|
|
|
+ .size(query.getPageSize())
|
|
|
+ .timeout(TimeValue.timeValueHours(1L))
|
|
|
+ .timeout(TimeValue.timeValueMinutes(30L))
|
|
|
+ .timeout(TimeValue.timeValueSeconds(500L));
|
|
|
request.source(searchSourceBuilder);
|
|
|
- SearchResponse search = client.search(request, RequestOptions.DEFAULT);
|
|
|
+ SearchResponse search = client.search(request, COMMON_OPTIONS);
|
|
|
Aggregations aggregations = search.getAggregations();
|
|
|
ParsedStringTerms aggregation = aggregations.get("ship_field_agg");
|
|
|
for (Terms.Bucket bucket : aggregation.getBuckets()) {
|
|
@@ -174,6 +204,11 @@ public class FusionAnalysisServiceImpl implements FusionAnalysisService {
|
|
|
for (int i = 0; i < hit.length; i++) {
|
|
|
if (num>2){
|
|
|
data.setFluctuateNumber(data.getFluctuateNumber()+1);
|
|
|
+ data.setMergeTarget(bucket.getKeyAsString());
|
|
|
+ data.setTrackCount(bucket.getDocCount());
|
|
|
+ data.setStartTime(query.getStartTime());
|
|
|
+ data.setEndTime(query.getEndTime());
|
|
|
+ list.add(data);
|
|
|
num =0;
|
|
|
}
|
|
|
if (i != hit.length-1){
|
|
@@ -189,11 +224,6 @@ public class FusionAnalysisServiceImpl implements FusionAnalysisService {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- data.setMergeTarget(bucket.getKeyAsString());
|
|
|
- data.setTrackCount(Long.valueOf(bucket.getDocCount()));
|
|
|
- data.setStartTime(query.getStartTime());
|
|
|
- data.setEndTime(query.getEndTime());
|
|
|
- list.add(data);
|
|
|
}
|
|
|
try {
|
|
|
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
|
@@ -222,19 +252,22 @@ public class FusionAnalysisServiceImpl implements FusionAnalysisService {
|
|
|
searchSourceBuilder.query(boolQueryBuilder);
|
|
|
TermsAggregationBuilder aggBuilder = AggregationBuilders.terms("ship_field_agg")
|
|
|
.field("fusionBatchNum")
|
|
|
- .size(1000000);
|
|
|
+ .size(query.getPageSize());
|
|
|
searchSourceBuilder
|
|
|
.trackTotalHits(true)
|
|
|
.aggregation(aggBuilder)
|
|
|
- .size(1000000);
|
|
|
+ .size(query.getPageSize())
|
|
|
+ .timeout(TimeValue.timeValueHours(1L))
|
|
|
+ .timeout(TimeValue.timeValueMinutes(30L))
|
|
|
+ .timeout(TimeValue.timeValueSeconds(500L));
|
|
|
request.source(searchSourceBuilder);
|
|
|
- SearchResponse search = client.search(request, RequestOptions.DEFAULT);
|
|
|
+ SearchResponse search = client.search(request, COMMON_OPTIONS);
|
|
|
Aggregations aggregations = search.getAggregations();
|
|
|
ParsedStringTerms aggregation = aggregations.get("ship_field_agg");
|
|
|
for (Terms.Bucket bucket : aggregation.getBuckets()) {
|
|
|
LeaceOutDto dto = new LeaceOutDto();
|
|
|
dto.setBatchNumber(bucket.getKeyAsString());
|
|
|
- dto.setCount(Long.valueOf(bucket.getDocCount()));
|
|
|
+ dto.setCount(bucket.getDocCount());
|
|
|
dtos.add(dto);
|
|
|
}
|
|
|
dtos.forEach(item->{
|
|
@@ -248,10 +281,13 @@ public class FusionAnalysisServiceImpl implements FusionAnalysisService {
|
|
|
boolQueryBuilder2.filter(QueryBuilders.termsQuery("mergeType","RADAR","AIS_RADAR","BEIDOU_RADAR","AIS_BEIDOU_RADAR"));
|
|
|
searchSourceBuilder2.query(boolQueryBuilder2)
|
|
|
.trackTotalHits(true)
|
|
|
- .size(1000000);
|
|
|
+ .size(query.getPageSize())
|
|
|
+ .timeout(TimeValue.timeValueHours(1L))
|
|
|
+ .timeout(TimeValue.timeValueMinutes(30L))
|
|
|
+ .timeout(TimeValue.timeValueSeconds(500L));
|
|
|
request2.source(searchSourceBuilder2);
|
|
|
try {
|
|
|
- SearchResponse search2 = client.search(request, RequestOptions.DEFAULT);
|
|
|
+ SearchResponse search2 = client.search(request, COMMON_OPTIONS);
|
|
|
SearchHits searchHits = search2.getHits();
|
|
|
Long totalHits = searchHits.getTotalHits().value;
|
|
|
if (totalHits<5) {
|
|
@@ -298,13 +334,16 @@ public class FusionAnalysisServiceImpl implements FusionAnalysisService {
|
|
|
searchSourceBuilder.query(boolQueryBuilder);
|
|
|
TermsAggregationBuilder aggBuilder = AggregationBuilders.terms("ship_field_agg")
|
|
|
.field("devideNo")
|
|
|
- .size(1000000);
|
|
|
+ .size(query.getPageSize());
|
|
|
searchSourceBuilder
|
|
|
.trackTotalHits(true)
|
|
|
.aggregation(aggBuilder)
|
|
|
- .size(1000000);
|
|
|
+ .size(query.getPageSize())
|
|
|
+ .timeout(TimeValue.timeValueHours(1L))
|
|
|
+ .timeout(TimeValue.timeValueMinutes(30L))
|
|
|
+ .timeout(TimeValue.timeValueSeconds(500L));
|
|
|
request.source(searchSourceBuilder);
|
|
|
- SearchResponse search = client.search(request, RequestOptions.DEFAULT);
|
|
|
+ SearchResponse search = client.search(request, COMMON_OPTIONS);
|
|
|
Aggregations aggregations = search.getAggregations();
|
|
|
ParsedStringTerms aggregation = aggregations.get("ship_field_agg");
|
|
|
for (Terms.Bucket bucket : aggregation.getBuckets()) {
|
|
@@ -324,10 +363,13 @@ public class FusionAnalysisServiceImpl implements FusionAnalysisService {
|
|
|
boolQueryBuilder2.filter(QueryBuilders.termsQuery("mergeType","BEIDOU","AIS_BEIDOU","BEIDOU_RADAR","AIS_BEIDOU_RADAR"));
|
|
|
searchSourceBuilder2.query(boolQueryBuilder2)
|
|
|
.trackTotalHits(true)
|
|
|
- .size(1000000);
|
|
|
+ .size(query.getPageSize())
|
|
|
+ .timeout(TimeValue.timeValueHours(1L))
|
|
|
+ .timeout(TimeValue.timeValueMinutes(30L))
|
|
|
+ .timeout(TimeValue.timeValueSeconds(500L));
|
|
|
request2.source(searchSourceBuilder2);
|
|
|
try {
|
|
|
- SearchResponse search2 = client.search(request, RequestOptions.DEFAULT);
|
|
|
+ SearchResponse search2 = client.search(request, COMMON_OPTIONS);
|
|
|
SearchHits searchHits = search2.getHits();
|
|
|
Long totalHits = searchHits.getTotalHits().value;
|
|
|
if (totalHits<5) {
|
|
@@ -374,13 +416,16 @@ public class FusionAnalysisServiceImpl implements FusionAnalysisService {
|
|
|
searchSourceBuilder.query(boolQueryBuilder);
|
|
|
TermsAggregationBuilder aggBuilder = AggregationBuilders.terms("ship_field_agg")
|
|
|
.field("targetID")
|
|
|
- .size(1000000);
|
|
|
+ .size(query.getPageSize());
|
|
|
searchSourceBuilder
|
|
|
.trackTotalHits(true)
|
|
|
.aggregation(aggBuilder)
|
|
|
- .size(1000000);
|
|
|
+ .size(query.getPageSize())
|
|
|
+ .timeout(TimeValue.timeValueHours(1L))
|
|
|
+ .timeout(TimeValue.timeValueMinutes(30L))
|
|
|
+ .timeout(TimeValue.timeValueSeconds(500L));
|
|
|
request.source(searchSourceBuilder);
|
|
|
- SearchResponse search = client.search(request, RequestOptions.DEFAULT);
|
|
|
+ SearchResponse search = client.search(request, COMMON_OPTIONS);
|
|
|
Aggregations aggregations = search.getAggregations();
|
|
|
ParsedStringTerms aggregation = aggregations.get("ship_field_agg");
|
|
|
for (Terms.Bucket bucket : aggregation.getBuckets()) {
|
|
@@ -400,10 +445,13 @@ public class FusionAnalysisServiceImpl implements FusionAnalysisService {
|
|
|
boolQueryBuilder2.filter(QueryBuilders.termsQuery("mergeType","AIS","RADAR","AIS_BEIDOU","AIS_RADAR","BEIDOU_RADAR","AIS_BEIDOU_RADAR"));
|
|
|
searchSourceBuilder2.query(boolQueryBuilder2)
|
|
|
.trackTotalHits(true)
|
|
|
- .size(1000000);
|
|
|
+ .size(query.getPageSize())
|
|
|
+ .timeout(TimeValue.timeValueHours(1L))
|
|
|
+ .timeout(TimeValue.timeValueMinutes(30L))
|
|
|
+ .timeout(TimeValue.timeValueSeconds(500L));
|
|
|
request2.source(searchSourceBuilder2);
|
|
|
try {
|
|
|
- SearchResponse search2 = client.search(request, RequestOptions.DEFAULT);
|
|
|
+ SearchResponse search2 = client.search(request, COMMON_OPTIONS);
|
|
|
SearchHits searchHits = search2.getHits();
|
|
|
Long totalHits = searchHits.getTotalHits().value;
|
|
|
if (totalHits<5) {
|
|
@@ -451,13 +499,16 @@ public class FusionAnalysisServiceImpl implements FusionAnalysisService {
|
|
|
searchSourceBuilder.query(boolQueryBuilder);
|
|
|
TermsAggregationBuilder aggBuilder = AggregationBuilders.terms("ship_field_agg")
|
|
|
.field("fusionBatchNum")
|
|
|
- .size(1000000);
|
|
|
+ .size(query.getPageSize());
|
|
|
searchSourceBuilder
|
|
|
.trackTotalHits(true)
|
|
|
.aggregation(aggBuilder)
|
|
|
- .size(1000000);
|
|
|
+ .size(query.getPageSize())
|
|
|
+ .timeout(TimeValue.timeValueHours(1L))
|
|
|
+ .timeout(TimeValue.timeValueMinutes(30L))
|
|
|
+ .timeout(TimeValue.timeValueSeconds(500L));
|
|
|
request.source(searchSourceBuilder);
|
|
|
- SearchResponse search = client.search(request, RequestOptions.DEFAULT);
|
|
|
+ SearchResponse search = client.search(request, COMMON_OPTIONS);
|
|
|
Aggregations aggregations = search.getAggregations();
|
|
|
ParsedStringTerms aggregation = aggregations.get("ship_field_agg");
|
|
|
for (Terms.Bucket bucket : aggregation.getBuckets()) {
|
|
@@ -478,10 +529,13 @@ public class FusionAnalysisServiceImpl implements FusionAnalysisService {
|
|
|
boolQueryBuilder2.filter(QueryBuilders.termsQuery("mergeType","RADAR","AIS_RADAR","BEIDOU_RADAR","AIS_BEIDOU_RADAR"));
|
|
|
searchSourceBuilder2.query(boolQueryBuilder2)
|
|
|
.trackTotalHits(true)
|
|
|
- .size(1000000);
|
|
|
+ .size(query.getPageSize())
|
|
|
+ .timeout(TimeValue.timeValueHours(1L))
|
|
|
+ .timeout(TimeValue.timeValueMinutes(30L))
|
|
|
+ .timeout(TimeValue.timeValueSeconds(500L));
|
|
|
request2.source(searchSourceBuilder2);
|
|
|
try {
|
|
|
- SearchResponse search2 = client.search(request, RequestOptions.DEFAULT);
|
|
|
+ SearchResponse search2 = client.search(request, COMMON_OPTIONS);
|
|
|
SearchHits searchHits = search2.getHits();
|
|
|
SearchHit[] hits = searchHits.getHits();
|
|
|
if (hits.length > 0) {
|