Browse Source

[update]修改pom文件

xiahailong 2 years ago
parent
commit
080d311181

+ 2 - 14
.idea/workspace.xml

@@ -6,12 +6,7 @@
   <component name="ChangeListManager">
     <list default="true" id="3bf79822-fe13-41ea-bc8f-858fbea129e7" name="Changes" comment="[update]修改pom文件">
       <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/es-track-common/pom.xml" beforeDir="false" afterPath="$PROJECT_DIR$/es-track-common/pom.xml" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/es-track-common/src/main/java/cn/com/taiji/config/EsClientConfiguration.java" beforeDir="false" afterPath="$PROJECT_DIR$/es-track-common/src/main/java/cn/com/taiji/config/EsClientConfiguration.java" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/fusion-analysis/pom.xml" beforeDir="false" afterPath="$PROJECT_DIR$/fusion-analysis/pom.xml" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/fusion-analysis/src/main/java/cn/com/taiji/domain/FusionQuery.java" beforeDir="false" afterPath="$PROJECT_DIR$/fusion-analysis/src/main/java/cn/com/taiji/domain/FusionQuery.java" 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" />
-      <change beforePath="$PROJECT_DIR$/fusion-analysis/src/main/resources/application.yml" beforeDir="false" afterPath="$PROJECT_DIR$/fusion-analysis/src/main/resources/application.yml" afterDir="false" />
     </list>
     <option name="SHOW_DIALOG" value="false" />
     <option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -162,6 +157,7 @@
       <workItem from="1675666106206" duration="7273000" />
       <workItem from="1675730151616" duration="2482000" />
       <workItem from="1675751880629" duration="13334000" />
+      <workItem from="1675788186214" duration="4218000" />
     </task>
     <task id="LOCAL-00001" summary="[insert]新增prod环境配置,完善es连接配置">
       <created>1675652041715</created>
@@ -232,18 +228,10 @@
     <option name="LAST_COMMIT_MESSAGE" value="[update]修改pom文件" />
   </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>197</line>
-          <option name="timeStamp" value="3" />
-        </line-breakpoint>
-      </breakpoints>
-    </breakpoint-manager>
     <pin-to-top-manager>
       <pinned-members>
         <PinnedItemInfo parentTag="org.elasticsearch.search.aggregations.Aggregations" memberName="aggregations" />
+        <PinnedItemInfo parentTag="java.util.HashMap$Node" memberName="value" />
       </pinned-members>
     </pin-to-top-manager>
   </component>

+ 135 - 48
fusion-analysis/src/main/java/cn/com/taiji/service/impl/FusionAnalysisServiceImpl.java

@@ -9,6 +9,8 @@ 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.JSON;
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.http.client.config.RequestConfig;
@@ -42,10 +44,7 @@ import java.io.IOException;
 import java.lang.reflect.Field;
 import java.net.URLEncoder;
 import java.text.ParseException;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 
 import static cn.com.taiji.constants.EsIndexConstants.*;
 
@@ -86,57 +85,109 @@ 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.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.topHits("ship_field_agg_top1")
+//                                .size(100)
+//                                .sort(
+//                                        SortBuilders.fieldSort("mergeTime").order(SortOrder.ASC)
+//                                )
+//                );
         searchSourceBuilder
                 .trackTotalHits(true)
-                .aggregation(aggBuilder)
+                .sort(SortBuilders.fieldSort("mergeTime").order(SortOrder.ASC))
+//                .aggregation(aggBuilder)
                 .size(query.getPageSize())
                 .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()) {
-            FusionData data = new FusionData();
-            ParsedTopHits topHits = bucket.getAggregations().get("ship_field_agg_top1");
-            SearchHits searchHits = topHits.getHits();
-            Long value = searchHits.getTotalHits().value;
-            SearchHit[] hits = searchHits.getHits();
-            Integer num = 0;
-            for (int i = 0; i < hits.length; i++) {
-                if (i != hits.length-1){
-                    Map<String, Object> map = hits[i].getSourceAsMap();
-                    Map<String, Object> map2 = hits[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++;
+        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));
+//            }
+            JSONArray jsonArray =JSONArray.parseArray(maps.getString("array"));
+            if (jsonArray.size()>0){
+                FusionData data = new FusionData();
+                Integer num = 0;
+                for (int i = 0; i < jsonArray.size(); i++) {
+                    if (i<jsonArray.size()-1){
+                        JSONObject job = jsonArray.getJSONObject(i);
+                        JSONObject job2 = jsonArray.getJSONObject(i+1);
+                        Date date = null;
+                        Date date2 = null;
+                        try {
+                            date = DateUtils.parse(job.get("mergeTime").toString(),"yyyy-MM-dd");
+                            date2 = DateUtils.parse(job2.get("mergeTime").toString(),"yyyy-MM-dd");
+                        } catch (ParseException e) {
+                            e.printStackTrace();
+                        }
+                        Long interval = date2.getTime()-date.getTime();
+                        if (interval>6500L){
+                            num++;
+                        }
                     }
                 }
+                if (num>0){
+                    JSONObject sourceItem = jsonArray.getJSONObject(0);
+                    JSONObject sourceItem2 = jsonArray.getJSONObject(jsonArray.size()-1);
+                    data.setMergeTarget(sourceItem.getString("mergeTarget"));
+                    data.setTrackCount((long) jsonArray.size());
+                    data.setStartTime(sourceItem.getString("mergeTime"));
+                    data.setEndTime(sourceItem2.getString("mergeTime"));
+                    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);
-            }
-        }
+        });
+//        Aggregations aggregations = search.getAggregations();
+//        ParsedStringTerms aggregation = aggregations.get("ship_field_agg");
+//        for (Terms.Bucket bucket : aggregation.getBuckets()) {
+//            FusionData data = new FusionData();
+//            ParsedTopHits topHits = bucket.getAggregations().get("ship_field_agg_top1");
+//            SearchHits searchHits = topHits.getHits();
+//            Long value = searchHits.getTotalHits().value;
+//            SearchHit[] hits = searchHits.getHits();
+//            Integer num = 0;
+//            for (int i = 0; i < hits.length; i++) {
+//                if (i != hits.length-1){
+//                    Map<String, Object> map = hits[i].getSourceAsMap();
+//                    Map<String, Object> map2 = hits[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 (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");
             response.setCharacterEncoding("utf-8");
@@ -250,13 +301,14 @@ public class FusionAnalysisServiceImpl implements FusionAnalysisService {
         SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
         boolQueryBuilder.filter(QueryBuilders.rangeQuery("receiveTime").gte(query.getStartTime()).lte(query.getEndTime()));
         searchSourceBuilder.query(boolQueryBuilder);
-        TermsAggregationBuilder aggBuilder = AggregationBuilders.terms("ship_field_agg")
-                .field("fusionBatchNum")
-                .size(query.getPageSize());
+//        TermsAggregationBuilder aggBuilder = AggregationBuilders.terms("ship_field_agg")
+//                .field("fusionBatchNum")
+//                .size(query.getPageSize());
         searchSourceBuilder
                 .trackTotalHits(true)
-                .aggregation(aggBuilder)
+//                .aggregation(aggBuilder)
                 .size(query.getPageSize())
+                .sort(SortBuilders.fieldSort("receiveTime").order(SortOrder.ASC))
                 .timeout(TimeValue.timeValueHours(1L))
                 .timeout(TimeValue.timeValueMinutes(30L))
                 .timeout(TimeValue.timeValueSeconds(500L));
@@ -560,4 +612,39 @@ public class FusionAnalysisServiceImpl implements FusionAnalysisService {
             System.out.println("导出天奥静态数据与动态轨迹融合excel失败:{}" + e.getMessage() + e);
         }
     }
+
+    /**
+     * 按照List<Map<String,Object>>里面map的某个value重新封装成多个不同的list, 原始数据类型List<Map<String,Object>>, 转换后数据类型Map<String,List<Map<String,Object>>>
+     * @param inList
+     * @param oneMapKey
+     * @param outList
+     * @return
+     */
+    private static List<Map<String, Object>> change(List<Map<String, Object>> inList, String oneMapKey,
+                                                    List<Map<String, Object>> outList) {
+        // 1.将某个key的值存在set中
+        Set<Object> setTmp = new HashSet<Object>();
+        for (Map<String, Object> tmp : inList) {
+            setTmp.add(tmp.get(oneMapKey));
+        }
+        // 2.遍历set
+        Iterator<Object> it = setTmp.iterator();
+        while (it.hasNext()) {
+            String oneMapValueStr = "";
+            String oneSetTmpStr = (String) it.next();
+            Map<String, Object> oneSetTmpMap = new HashMap<String, Object>();
+            List<Map<String, Object>> oneSetTmpList = new ArrayList<Map<String, Object>>();
+
+            for (Map<String, Object> tmp : inList) {
+                oneMapValueStr = (String) tmp.get(oneMapKey);
+                if (oneSetTmpStr.equals(oneMapValueStr)) {
+                    oneSetTmpMap.put("text", oneSetTmpStr);
+                    oneSetTmpList.add(tmp);
+                }
+            }
+            oneSetTmpMap.put("array", oneSetTmpList);
+            outList.add(oneSetTmpMap);
+        }
+        return outList;
+    }
 }