Browse Source

[feat]#天奥船舶

chenfangchao 2 years ago
parent
commit
d783d43a2e

+ 12 - 0
es-track-common/pom.xml

@@ -63,6 +63,18 @@
             <version>1.2.60</version>
         </dependency>
 
+        <dependency>
+            <groupId>cn.hutool</groupId>
+            <artifactId>hutool-all</artifactId>
+            <version>5.7.17</version>
+        </dependency>
+
+        <dependency>
+            <groupId>com.alibaba</groupId>
+            <artifactId>easyexcel</artifactId>
+            <version>3.0.3</version>
+        </dependency>
+
     </dependencies>
 
 

+ 1 - 0
es-track-common/src/main/java/cn/com/taiji/entity/FusionBaseEntity.java

@@ -209,3 +209,4 @@ public class FusionBaseEntity implements Serializable {
     /** 位置 **/
     private String location;
 }
+

+ 91 - 0
es-track-common/src/main/java/cn/com/taiji/utils/ExcelUtils.java

@@ -0,0 +1,91 @@
+package cn.com.taiji.utils;
+
+import lombok.extern.slf4j.Slf4j;
+import com.alibaba.excel.EasyExcel;
+import com.alibaba.excel.support.ExcelTypeEnum;
+import org.apache.poi.util.IOUtils;
+
+import javax.servlet.ServletOutputStream;
+import javax.servlet.http.HttpServletResponse;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.util.List;
+
+/**
+ * Excel工具类
+ */
+@Slf4j
+public class ExcelUtils {
+
+    /**
+     * 导出Excel(07版.xlsx)到指定路径下
+     *
+     * @param path      路径
+     * @param excelName Excel名称
+     * @param sheetName sheet页名称
+     * @param clazz     Excel要转换的类型
+     * @param data      要导出的数据
+     */
+    public static void export2File(String path, String excelName, String sheetName, Class clazz, List data) {
+        String fileName = path.concat(excelName).concat(ExcelTypeEnum.XLSX.getValue());
+        EasyExcel.write(fileName, clazz).sheet(sheetName).doWrite(data);
+    }
+
+    /**
+     * 导出Excel(07版.xlsx)到web
+     *
+     * @param response  响应
+     * @param excelName Excel名称
+     * @param sheetName sheet页名称
+     * @param clazz     Excel要转换的类型
+     * @param data      要导出的数据
+     * @throws Exception
+     */
+    public static void export2Web(HttpServletResponse response, String excelName, String sheetName, Class clazz, List data) throws Exception {
+        response.setContentType("application/vnd.ms-excel");
+        response.setCharacterEncoding("utf-8");
+        // 这里URLEncoder.encode可以防止中文乱码
+        excelName = URLEncoder.encode(excelName, "UTF-8");
+        response.setHeader("Content-disposition", "attachment;filename=" + excelName + ExcelTypeEnum.XLSX.getValue());
+        EasyExcel.write(response.getOutputStream(), clazz).sheet(sheetName).doWrite(data);
+    }
+
+    /**
+     * 将指定位置指定名称的Excel导出到web
+     *
+     * @param response  响应
+     * @param path      文件路径
+     * @param excelName 文件名称
+     * @return
+     * @throws UnsupportedEncodingException
+     */
+    public static String export2Web4File(HttpServletResponse response, String path, String excelName) throws UnsupportedEncodingException {
+        File file = new File(path.concat(excelName).concat(ExcelTypeEnum.XLSX.getValue()));
+        if (!file.exists()) {
+            return "文件不存在!";
+        }
+
+        response.setContentType("application/vnd.ms-excel");
+        response.setCharacterEncoding("utf-8");
+        // 这里URLEncoder.encode可以防止中文乱码
+        excelName = URLEncoder.encode(excelName, "UTF-8");
+        response.setHeader("Content-disposition", "attachment;filename=" + excelName + ExcelTypeEnum.XLSX.getValue());
+
+        try (
+                FileInputStream in = new FileInputStream(file);
+                ServletOutputStream out = response.getOutputStream();
+        ) {
+            IOUtils.copy(in, out);
+            return "导出成功!";
+        } catch (Exception e) {
+            log.error("导出文件异常:", e);
+        }
+
+        return "导出失败!";
+    }
+
+}
+
+

+ 14 - 2
tianao-analysis/src/main/java/cn/com/taiji/controller/TianaoRadarController.java

@@ -2,12 +2,17 @@ package cn.com.taiji.controller;
 
 import cn.com.taiji.entity.QueryVo;
 import cn.com.taiji.service.TianaoService;
+import cn.com.taiji.utils.ExcelUtils;
+import cn.com.taiji.vo.TianaoVo;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.net.URLEncoder;
 import java.util.List;
 
 /**
@@ -26,7 +31,14 @@ public class TianaoRadarController {
     private TianaoService tianaoService;
 
     @PostMapping("/export")
-    public void tianaRader(@RequestBody QueryVo query){
-       List<TianaoService> list = tianaoService.tianaRader(query);
+    public void tianaRader(HttpServletResponse response, @RequestBody QueryVo query){
+        List<TianaoVo> list = tianaoService.tianaRader(query);
+        try {
+            if(null != list && 0 < list.size()){
+                ExcelUtils.export2Web(response, "天奥", "天奥", TianaoVo.class, list);
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
     }
 }

+ 2 - 1
tianao-analysis/src/main/java/cn/com/taiji/service/TianaoService.java

@@ -1,6 +1,7 @@
 package cn.com.taiji.service;
 
 import cn.com.taiji.entity.QueryVo;
+import cn.com.taiji.vo.TianaoVo;
 
 import java.util.List;
 
@@ -13,5 +14,5 @@ import java.util.List;
  */
 public interface TianaoService {
 
-    List<TianaoService> tianaRader(QueryVo query);
+    List<TianaoVo> tianaRader(QueryVo query);
 }

+ 66 - 10
tianao-analysis/src/main/java/cn/com/taiji/service/impl/TianaoServiceImpl.java

@@ -1,10 +1,12 @@
 package cn.com.taiji.service.impl;
 
 import cn.com.taiji.constants.EsIndexConstants;
+import cn.com.taiji.entity.FusionNewShipJsonDTO;
 import cn.com.taiji.entity.QueryVo;
 import cn.com.taiji.entity.TianaoRadar;
 import cn.com.taiji.service.TianaoService;
 import cn.com.taiji.utils.DateUtils;
+import cn.com.taiji.vo.TianaoVo;
 import com.alibaba.fastjson.JSON;
 import org.elasticsearch.action.search.SearchRequest;
 import org.elasticsearch.action.search.SearchResponse;
@@ -18,9 +20,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
+import java.util.*;
 
 /**
  * @author chenfangchao
@@ -36,16 +36,18 @@ public class TianaoServiceImpl implements TianaoService {
     private RestHighLevelClient restHighLevelClient;
 
     @Override
-    public List<TianaoService> tianaRader(QueryVo query) {
-        List<String> tianaoRadarIdList = new ArrayList<>();
+    public List<TianaoVo> tianaRader(QueryVo query) {
+         List<TianaoVo> list = new ArrayList<>();
+        //天奥标识
+        Map<String, TianaoVo> tianaoRadarIdList = new HashMap<>();
         String time = DateUtils.format(new Date(),"yyyy-MM-dd");
-        SearchRequest searchRequest = new SearchRequest(EsIndexConstants.INDEX_SEAT_TRACK_RADAR + time);
+//        SearchRequest searchRequest = new SearchRequest(EsIndexConstants.INDEX_SEAT_TRACK_RADAR + time);
+        SearchRequest searchRequest = new SearchRequest("index_seat_tianao_radar_fusion_ship_track_2022-11-24");
         // 构建查询条件
         BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
         SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
-        boolQueryBuilder.filter(QueryBuilders.rangeQuery("mergeTime").gte(query.getStartTime()).lte(query.getEndTime()));
+        boolQueryBuilder.filter(QueryBuilders.rangeQuery("fusionTime").gte(query.getStartTime()).lte(query.getEndTime()));
         searchSourceBuilder.query(boolQueryBuilder);
-
         searchRequest.source(searchSourceBuilder);
         try {
             SearchResponse search = restHighLevelClient.search(searchRequest, RequestOptions.DEFAULT);
@@ -53,13 +55,67 @@ public class TianaoServiceImpl implements TianaoService {
             for (SearchHit hit : hits) {
                 String sourceAsString = hit.getSourceAsString();
                 TianaoRadar object= JSON.parseObject(sourceAsString,TianaoRadar.class);
-                tianaoRadarIdList.add(object.getRadarCode());
+                //存储天奥
+                tianaoRadarIdList.put(object.getFusionBatchNum(),null);
             }
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        //融合
+        SearchRequest fusionSearchRequest = new SearchRequest((EsIndexConstants.INDEX_SEAT_REALTIMETRAJECTORY + "2023-02-01"));
+        // 构建查询条件
+        BoolQueryBuilder  fusionBoolQueryBuilder = QueryBuilders.boolQuery();
+        SearchSourceBuilder fusionSearchSourceBuilder = new SearchSourceBuilder();
+        boolQueryBuilder.filter(QueryBuilders.rangeQuery("mergeTime").gte(query.getStartTime()).lte(query.getEndTime()));
+        fusionSearchSourceBuilder.query(fusionBoolQueryBuilder);
+        fusionSearchRequest.source(fusionSearchSourceBuilder);
+        try {
+            SearchResponse fusionSearch = restHighLevelClient.search(fusionSearchRequest, RequestOptions.DEFAULT);
+            SearchHit[] hits = fusionSearch.getHits().getHits();
+            //通过融合数据匹配天奥数据
+            for (SearchHit hit : hits) {
+                Map<String, Object> sourceAsMap = hit.getSourceAsMap();
 
+                String mergeTarget = (String) sourceAsMap.get("merge_target");
+                String mergeTime = (String) sourceAsMap.get("merge_time");
 
+                String targetSource = (String) sourceAsMap.get("targetSource");
+
+                List<FusionNewShipJsonDTO> targetSourceList = JSON.parseArray(targetSource,FusionNewShipJsonDTO.class);
+                //融合子源信息匹配天奥、有两条相同的存储mergeTarget
+                for (FusionNewShipJsonDTO item : targetSourceList) {
+                    if(null != item){
+                        if(null != item.getType() && "TA_RADAR".equals(item.getType())){
+                            //判断天奥数据里面是否包含融合数据
+                            if(tianaoRadarIdList.containsKey(item.getTrackId())){
+                                TianaoVo tianaoVo = tianaoRadarIdList.get(item.getTrackId());
+                                //判断值是否为空
+                                if(null != tianaoVo){
+                                    //判断值是否相等
+                                    if(!tianaoVo.getMergeTarget().equals(mergeTarget)){
+                                        TianaoVo obj = new TianaoVo();
+                                        obj.setStartTime(mergeTime);
+                                        obj.setMergeTarget(mergeTarget);
+                                        obj.setTargetSource(targetSource);
+                                        list.add(tianaoVo);
+                                        list.add(obj);
+                                        tianaoRadarIdList.remove(item.getTrackId());
+                                    }else {
+                                        TianaoVo obj = new TianaoVo();
+                                        obj.setStartTime(mergeTime);
+                                        obj.setMergeTarget(mergeTarget);
+                                        obj.setTargetSource(targetSource);
+                                        tianaoRadarIdList.put(item.getTrackId(),obj);
+                                    }
+                                }
+                            }
+                        }
+                    }
+                }
+            }
         } catch (IOException e) {
             e.printStackTrace();
         }
-        return null;
+        return list;
     }
 }

+ 28 - 0
tianao-analysis/src/main/java/cn/com/taiji/vo/TianaoVo.java

@@ -0,0 +1,28 @@
+package cn.com.taiji.vo;
+
+import com.alibaba.excel.annotation.ExcelProperty;
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ * @author chenfangchao
+ * @title: TianaoVo
+ * @projectName es-track-analysis
+ * @description: TODO
+ * @date 2023/2/7 10:29 AM
+ */
+@Data
+public class TianaoVo implements Serializable {
+
+    @ExcelProperty(value = {"批次号"}, index = 0)
+    private String mergeTarget;
+
+    @ExcelProperty(value = {"批次开始时间"}, index = 1)
+    private String startTime;
+
+    private String endTime;
+
+    @ExcelProperty(value = {"相同子源标识"}, index = 2)
+    private String targetSource;
+}