|
@@ -214,69 +214,127 @@ public class FusionAnalysisServiceImpl implements FusionAnalysisService {
|
|
|
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
|
|
|
boolQueryBuilder.filter(QueryBuilders.rangeQuery("mergeTime").gte(query.getStartTime()).lte(query.getEndTime()));
|
|
|
searchSourceBuilder.query(boolQueryBuilder);
|
|
|
- TermsAggregationBuilder aggBuilder = AggregationBuilders.terms("ship_field_agg")
|
|
|
- .field("mergeTarget")
|
|
|
- .size(query.getPageSize())
|
|
|
- .subAggregation(
|
|
|
- AggregationBuilders.terms("ship_field_agg_one")
|
|
|
- .field("targetCourse")
|
|
|
- .size(query.getPageSize())
|
|
|
- .subAggregation(
|
|
|
- AggregationBuilders.terms("ship_field_agg_two")
|
|
|
- .field("targetSpeed")
|
|
|
- .size(query.getPageSize())
|
|
|
- .subAggregation(AggregationBuilders.topHits("ship_field_agg_top1")
|
|
|
- .size(100)
|
|
|
- .sort(
|
|
|
- SortBuilders.fieldSort("mergeTime").order(SortOrder.ASC)
|
|
|
- ))
|
|
|
- )
|
|
|
- );
|
|
|
+// TermsAggregationBuilder aggBuilder = AggregationBuilders.terms("ship_field_agg")
|
|
|
+// .field("mergeTarget")
|
|
|
+// .size(query.getPageSize())
|
|
|
+// .subAggregation(
|
|
|
+// AggregationBuilders.terms("ship_field_agg_one")
|
|
|
+// .field("targetCourse")
|
|
|
+// .size(query.getPageSize())
|
|
|
+// .subAggregation(
|
|
|
+// AggregationBuilders.terms("ship_field_agg_two")
|
|
|
+// .field("targetSpeed")
|
|
|
+// .size(query.getPageSize())
|
|
|
+// .subAggregation(AggregationBuilders.topHits("ship_field_agg_top1")
|
|
|
+// .size(100)
|
|
|
+// .sort(
|
|
|
+// SortBuilders.fieldSort("mergeTime").order(SortOrder.ASC)
|
|
|
+// ))
|
|
|
+// )
|
|
|
+// );
|
|
|
searchSourceBuilder
|
|
|
.trackTotalHits(true)
|
|
|
- .aggregation(aggBuilder)
|
|
|
+// .aggregation(aggBuilder)
|
|
|
.size(query.getPageSize())
|
|
|
+ .sort(SortBuilders.fieldSort("mergeTime").order(SortOrder.ASC))
|
|
|
.timeout(TimeValue.timeValueHours(1L))
|
|
|
.timeout(TimeValue.timeValueMinutes(30L))
|
|
|
.timeout(TimeValue.timeValueSeconds(500L));
|
|
|
request.source(searchSourceBuilder);
|
|
|
SearchResponse search = client.search(request, COMMON_OPTIONS);
|
|
|
- Aggregations aggregations = search.getAggregations();
|
|
|
- ParsedStringTerms aggregation = aggregations.get("ship_field_agg");
|
|
|
- for (Terms.Bucket bucket : aggregation.getBuckets()) {
|
|
|
+ SearchHits searchHits = search.getHits();
|
|
|
+ SearchHit[] hits = searchHits.getHits();
|
|
|
+ List<Map<String, Object>> inList = new ArrayList<Map<String, Object>>();
|
|
|
+ List<Map<String, Object>> outList = new ArrayList<Map<String, Object>>();
|
|
|
+ for (SearchHit hit : hits) {
|
|
|
+ Map<String, Object> map = hit.getSourceAsMap();
|
|
|
+ inList.add(map);
|
|
|
+ }
|
|
|
+ outList = change(inList, "mergeTarget", outList);
|
|
|
+ outList.forEach(map->{
|
|
|
+ JSONObject maps = JSONObject.parseObject(JSON.toJSONString(map));
|
|
|
+// JSONObject maps = new JSONObject();
|
|
|
+// Iterator it = map.keySet().iterator();
|
|
|
+// while (it.hasNext()) {
|
|
|
+// String key = (String) it.next();
|
|
|
+// maps.put(key, map.get(key));
|
|
|
+// }
|
|
|
FusionData data = new FusionData();
|
|
|
- ParsedStringTerms terms = bucket.getAggregations().get("ship_field_agg_one");
|
|
|
+ JSONArray jsonArray = JSONArray.parseArray(maps.getString("array"));
|
|
|
Integer num = 0;
|
|
|
- for (Terms.Bucket buc : terms.getBuckets()){
|
|
|
- ParsedDoubleTerms termsTwo = buc.getAggregations().get("ship_field_agg_two");
|
|
|
- for (Terms.Bucket ket : termsTwo.getBuckets()){
|
|
|
- ParsedTopHits topHit = ket.getAggregations().get("ship_field_agg_top1");
|
|
|
- SearchHits searchHit = topHit.getHits();
|
|
|
- SearchHit[] hit = searchHit.getHits();
|
|
|
- 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){
|
|
|
- Map<String, Object> map = hit[i].getSourceAsMap();
|
|
|
- Map<String, Object> map2 = hit[i+1].getSourceAsMap();
|
|
|
- Date date = DateUtils.parse(map.get("mergeTime").toString(),"yyyy-MM-dd");
|
|
|
- Date date2 = DateUtils.parse(map2.get("mergeTime").toString(),"yyyy-MM-dd");
|
|
|
- Long interval = date2.getTime()-date.getTime();
|
|
|
- if (interval<6500L){
|
|
|
- num++;
|
|
|
+ if (jsonArray.size() > 0) {
|
|
|
+ for (int i = 0; i < jsonArray.size(); i++) {
|
|
|
+ JSONObject job = jsonArray.getJSONObject(i);
|
|
|
+ for (int j = 0; j < jsonArray.size(); j++){
|
|
|
+ JSONObject job2 = jsonArray.getJSONObject(j);
|
|
|
+ if (job.getString("targetCourse").equals(job2.getString("targetCourse"))){
|
|
|
+ if (job.getString("targetSpeed").equals(job2.getString("targetSpeed"))){
|
|
|
+ if (num==9){
|
|
|
+ if (data.getFluctuateNumber()!=null){
|
|
|
+ data.setFluctuateNumber(data.getFluctuateNumber()+1);
|
|
|
+ }else {
|
|
|
+ data.setFluctuateNumber(1);
|
|
|
+ }
|
|
|
+ data.setMergeTarget(maps.getString("text"));
|
|
|
+ data.setTrackCount((long) jsonArray.size());
|
|
|
+ data.setStartTime(jsonArray.getJSONObject(0).getString("mergeTime"));
|
|
|
+ data.setEndTime(jsonArray.getJSONObject(jsonArray.size()-1).getString("mergeTime"));
|
|
|
+ list.add(data);
|
|
|
+ }
|
|
|
+ Date date = null;
|
|
|
+ Date date2 = null;
|
|
|
+ try {
|
|
|
+ date = DateUtils.parse(job.get("mergeTime").toString(),"yyyy-MM-dd HH:mm:ss.SSS");
|
|
|
+ date2 = DateUtils.parse(job2.get("mergeTime").toString(),"yyyy-MM-dd HH:mm:ss.SSS");
|
|
|
+ } catch (ParseException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ Long interval = dateUtils(date.getTime(),date2.getTime());
|
|
|
+ if (interval<6500L){
|
|
|
+ num++;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
+ });
|
|
|
+// Aggregations aggregations = search.getAggregations();
|
|
|
+// ParsedStringTerms aggregation = aggregations.get("ship_field_agg");
|
|
|
+// for (Terms.Bucket bucket : aggregation.getBuckets()) {
|
|
|
+// FusionData data = new FusionData();
|
|
|
+// ParsedStringTerms terms = bucket.getAggregations().get("ship_field_agg_one");
|
|
|
+// Integer num = 0;
|
|
|
+// for (Terms.Bucket buc : terms.getBuckets()){
|
|
|
+// ParsedDoubleTerms termsTwo = buc.getAggregations().get("ship_field_agg_two");
|
|
|
+// for (Terms.Bucket ket : termsTwo.getBuckets()){
|
|
|
+// ParsedTopHits topHit = ket.getAggregations().get("ship_field_agg_top1");
|
|
|
+// SearchHits searchHit = topHit.getHits();
|
|
|
+// SearchHit[] hit = searchHit.getHits();
|
|
|
+// 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){
|
|
|
+// Map<String, Object> map = hit[i].getSourceAsMap();
|
|
|
+// Map<String, Object> map2 = hit[i+1].getSourceAsMap();
|
|
|
+// Date date = DateUtils.parse(map.get("mergeTime").toString(),"yyyy-MM-dd");
|
|
|
+// Date date2 = DateUtils.parse(map2.get("mergeTime").toString(),"yyyy-MM-dd");
|
|
|
+// Long interval = date2.getTime()-date.getTime();
|
|
|
+// if (interval<6500L){
|
|
|
+// num++;
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
try {
|
|
|
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
|
|
response.setCharacterEncoding("utf-8");
|
|
@@ -746,17 +804,13 @@ public class FusionAnalysisServiceImpl implements FusionAnalysisService {
|
|
|
}
|
|
|
return outList;
|
|
|
}
|
|
|
-}
|
|
|
-
|
|
|
|
|
|
-class text{
|
|
|
- @Autowired
|
|
|
- public RestHighLevelClient client;
|
|
|
-
|
|
|
- public static void main(String[] args) {
|
|
|
- String source = "[{\"track_device_no\":\"15013798\",\"track_id\":\"15013798\",\"id\":\"82717282\",\"time\":\"2023 - 02 - 07 00: 59: 30.069\",\"type\":\"BEIDOU\"}]";
|
|
|
- String json = JSON.toJSONString(source);
|
|
|
- System.out.println(json);
|
|
|
|
|
|
+ public Long dateUtils(Long oneTime,Long twoTime){
|
|
|
+ if (oneTime>twoTime){
|
|
|
+ return oneTime-twoTime;
|
|
|
+ }else {
|
|
|
+ return twoTime-oneTime;
|
|
|
+ }
|
|
|
}
|
|
|
}
|