Browse Source

[update]0.2版本

xiahailong 2 years ago
parent
commit
7a3d1407e1

+ 12 - 23
.idea/workspace.xml

@@ -4,7 +4,7 @@
     <option name="autoReloadType" value="SELECTIVE" />
   </component>
   <component name="ChangeListManager">
-    <list default="true" id="3bf79822-fe13-41ea-bc8f-858fbea129e7" name="Changes" comment="[update]修改pom文件">
+    <list default="true" id="3bf79822-fe13-41ea-bc8f-858fbea129e7" name="Changes" comment="[update]0.2版本">
       <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
       <change beforePath="$PROJECT_DIR$/fusion-analysis/src/main/java/cn/com/taiji/service/impl/FusionAnalysisServiceImpl.java" beforeDir="false" afterPath="$PROJECT_DIR$/fusion-analysis/src/main/java/cn/com/taiji/service/impl/FusionAnalysisServiceImpl.java" afterDir="false" />
     </list>
@@ -172,7 +172,7 @@
       <workItem from="1675730151616" duration="2482000" />
       <workItem from="1675751880629" duration="13334000" />
       <workItem from="1675788186214" duration="4782000" />
-      <workItem from="1675817188436" duration="6347000" />
+      <workItem from="1675817188436" duration="9229000" />
     </task>
     <task id="LOCAL-00001" summary="[insert]新增prod环境配置,完善es连接配置">
       <created>1675652041715</created>
@@ -209,7 +209,14 @@
       <option name="project" value="LOCAL" />
       <updated>1675792903860</updated>
     </task>
-    <option name="localTasksCounter" value="6" />
+    <task id="LOCAL-00006" summary="[update]0.2版本">
+      <created>1675824149842</created>
+      <option name="number" value="00006" />
+      <option name="presentableId" value="LOCAL-00006" />
+      <option name="project" value="LOCAL" />
+      <updated>1675824149842</updated>
+    </task>
+    <option name="localTasksCounter" value="7" />
     <servers />
   </component>
   <component name="TypeScriptGeneratedFilesManager">
@@ -247,28 +254,10 @@
     <MESSAGE value="[insert]新增es索引名" />
     <MESSAGE value="[insert]新增融合解析--识别融合数据率波动问题导出" />
     <MESSAGE value="[update]修改pom文件" />
-    <option name="LAST_COMMIT_MESSAGE" value="[update]修改pom文件" />
+    <MESSAGE value="[update]0.2版本" />
+    <option name="LAST_COMMIT_MESSAGE" value="[update]0.2版本" />
   </component>
   <component name="XDebuggerManager">
-    <breakpoint-manager>
-      <breakpoints>
-        <line-breakpoint enabled="true" type="java-line">
-          <url>file://$PROJECT_DIR$/fusion-analysis/src/main/java/cn/com/taiji/service/impl/FusionAnalysisServiceImpl.java</url>
-          <line>652</line>
-          <option name="timeStamp" value="18" />
-        </line-breakpoint>
-        <line-breakpoint enabled="true" type="java-line">
-          <url>file://$PROJECT_DIR$/fusion-analysis/src/main/java/cn/com/taiji/service/impl/FusionAnalysisServiceImpl.java</url>
-          <line>670</line>
-          <option name="timeStamp" value="19" />
-        </line-breakpoint>
-        <line-breakpoint enabled="true" type="java-line">
-          <url>file://$PROJECT_DIR$/fusion-analysis/src/main/java/cn/com/taiji/service/impl/FusionAnalysisServiceImpl.java</url>
-          <line>691</line>
-          <option name="timeStamp" value="20" />
-        </line-breakpoint>
-      </breakpoints>
-    </breakpoint-manager>
     <pin-to-top-manager>
       <pinned-members>
         <PinnedItemInfo parentTag="org.elasticsearch.search.aggregations.Aggregations" memberName="aggregations" />

+ 112 - 58
fusion-analysis/src/main/java/cn/com/taiji/service/impl/FusionAnalysisServiceImpl.java

@@ -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;
+        }
     }
 }