Browse Source

[add]#模拟轨迹

chenfangchao 2 years ago
parent
commit
962ae64660

+ 15 - 0
es-track-common/src/main/java/cn/com/taiji/constants/TopicConstants.java

@@ -0,0 +1,15 @@
+package cn.com.taiji.constants;
+
+/**
+ * @author chenfangchao
+ * @title: TopicConstans
+ * @projectName es-track-analysis
+ * @description: TODO
+ * @date 2023/2/7 5:22 PM
+ */
+public class TopicConstants {
+
+    public static final String BEIDOU_TOPIC = "taiji_ax_beidou_dynamic_ship";
+
+    public static final String GLOBAL_AIS = "taiji_ax_ztpt_dynamic_ais";
+}

+ 0 - 15
beidou-analysis/src/main/java/cn/com/taiji/entity/BeidouShipTrackDTO.java

@@ -29,19 +29,4 @@ public class BeidouShipTrackDTO implements Serializable {
     private Double speed;
     private Integer kwh;
     private String shipName;
-    //船籍港
-    private String gisShipPort = "";
-    //船舶材质
-    private String gisShipMaterial = "";
-    //船舶用途
-    private String gisShipUse = "";
-    //是否被关注 0未关注 1已关注
-    private Integer focus = 0;
-    //是否为重点 0否 1是
-    private Integer fokey = 0;
-    //关注颜色
-    private String focusColor = "";
-    //用户id
-    private String focusUserId = "";
-    private String location;
 }

+ 25 - 0
es-track-common/src/main/java/cn/com/taiji/entity/GlobalAisTrackDTO.java

@@ -0,0 +1,25 @@
+package cn.com.taiji.entity;
+
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+@Data
+public class GlobalAisTrackDTO implements Serializable {
+
+    private static final long serialVersionUID = 7817585048163272316L;
+    private String userid;
+    private String receiveTime;
+    private String messageid;
+    private String navStatus;
+    private String rot;
+    private String sog;
+    private Double longitude;
+    private Double latitude;
+    private String cog;
+    private String trueHeading;
+    private String dsource;
+
+    private String location;
+}

+ 25 - 0
es-track-common/src/main/java/cn/com/taiji/entity/Location.java

@@ -0,0 +1,25 @@
+package cn.com.taiji.entity;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.io.Serializable;
+
+/**
+ * @author chenfangchao
+ * @title: Location
+ * @projectName es-track-analysis
+ * @description: TODO
+ * @date 2023/2/7 5:45 PM
+ */
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+public class Location implements Serializable {
+    private static final long serialVersionUID = 7635781718824272160L;
+
+    private Double log;
+
+    private Double lat;
+}

+ 92 - 0
es-track-common/src/main/java/cn/com/taiji/utils/LocationUtils.java

@@ -0,0 +1,92 @@
+package cn.com.taiji.utils;
+
+import cn.com.taiji.entity.Location;
+import cn.hutool.core.date.DateUnit;
+import cn.hutool.core.date.DateUtil;
+
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+
+/**
+ * @author chenfangchao
+ * @title: LocationUtils
+ * @projectName es-track-analysis
+ * @description: TODO
+ * @date 2023/2/7 5:40 PM
+ */
+public class LocationUtils {
+
+    public static List<Location> generateLogLat(String startTime, String endTime, Double startLog, Double startLat, Double endLog, Double endLat) {
+        List<Location> list = new ArrayList<>();
+        try {
+            final int seconds = 1000;
+            //经纬度差
+            Double difflog = Math.abs(startLog - endLog);
+            Double difflat = Math.abs(startLat - endLat);
+            //相差秒数
+            long diffSeconds = diffSeconds(startTime, endTime);
+            //平均经纬度差
+            Double avgLog = difflog / diffSeconds;
+            Double avgLat = difflat / diffSeconds;
+            //开始时间时间戳
+            long startTimeStamp = dateToStamp(startTime);
+            long endTimeStamp = dateToStamp(endTime);
+            Double resLog = startLog;
+            Double resLat = startLat;
+            long startTimeStampNew = startTimeStamp + seconds;
+            //判断时间大小关系
+            if (startTimeStampNew < endTimeStamp) {
+                for (long i = startTimeStamp + seconds; i < endTimeStamp; i += seconds) {
+                    resLog = avgLog + resLog;
+                    resLat = avgLat + resLat;
+                    double bdLog = doubleDown(resLog);
+                    double bdLat = doubleDown(resLat);
+                    Location location = new Location(bdLog,bdLat);
+                    list.add(location);
+                }
+            } else {
+                for (long i = endTimeStamp + seconds; i < startTimeStampNew; i += seconds) {
+                    resLog = avgLog + resLog;
+                    resLat = avgLat + resLat;
+                    double bdLog = doubleDown(resLog);
+                    double bdLat = doubleDown(resLat);
+                    Location location = new Location(bdLog,bdLat);
+                    list.add(location);
+                }
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return list;
+    }
+
+
+    public static double doubleDown(Double data) {
+        try {
+            BigDecimal bd = new BigDecimal(data);
+            double res = bd.setScale(7, BigDecimal.ROUND_DOWN).doubleValue();
+            return res;
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return 0;
+    }
+
+    public static long dateToStamp(String time) {
+        Date date = DateUtil.parse(time);
+        long ts = date.getTime();
+        return ts;
+    }
+
+    public static long diffSeconds(String startTime,String endTime){
+        Date startDate= DateUtil.parse(startTime);
+        Date endDate=DateUtil.parse(endTime);
+        long second=DateUtil.between(startDate,endDate, DateUnit.SECOND);
+        return second;
+    }
+}
+
+

+ 1 - 0
pom.xml

@@ -14,6 +14,7 @@
         <module>fusion-analysis</module>
         <module>beidou-analysis</module>
         <module>hlx-one-fusion-analysis</module>
+        <module>simulation-track</module>
     </modules>
 
     <properties>

+ 46 - 0
simulation-track/pom.xml

@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <parent>
+        <artifactId>es-track-analysis</artifactId>
+        <groupId>cn.com.taiji</groupId>
+        <version>1.0-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>simulation-track</artifactId>
+
+    <properties>
+        <maven.compiler.source>8</maven.compiler.source>
+        <maven.compiler.target>8</maven.compiler.target>
+    </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-web</artifactId>
+            <version>2.7.7</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework.kafka</groupId>
+            <artifactId>spring-kafka</artifactId>
+            <version>2.3.13.RELEASE</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.kafka</groupId>
+            <artifactId>kafka-clients</artifactId>
+            <version>2.7.1</version>
+        </dependency>
+        <dependency>
+            <groupId>cn.com.taiji</groupId>
+            <artifactId>es-track-common</artifactId>
+            <version>1.0-SNAPSHOT</version>
+            <scope>compile</scope>
+        </dependency>
+
+    </dependencies>
+
+</project>

+ 18 - 0
simulation-track/src/main/java/cn/com/taiji/SimulationTrackApplication.java

@@ -0,0 +1,18 @@
+package cn.com.taiji;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+/**
+ * @author chenfangchao
+ * @title: SimulationTrackApplication
+ * @projectName es-track-analysis
+ * @description: TODO
+ * @date 2023/2/7 5:15 PM
+ */
+@SpringBootApplication
+public class SimulationTrackApplication {
+    public static void main(String[] args) {
+        SpringApplication.run(SimulationTrackApplication.class,args);
+    }
+}

+ 34 - 0
simulation-track/src/main/java/cn/com/taiji/controller/SimulationTrackController.java

@@ -0,0 +1,34 @@
+package cn.com.taiji.controller;
+
+import cn.com.taiji.service.SimulationTrackService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * @author chenfangchao
+ * @title: SimulationTrackController
+ * @projectName es-track-analysis
+ * @description: TODO
+ * @date 2023/2/7 5:15 PM
+ */
+@RequestMapping("/track")
+@RestController
+public class SimulationTrackController {
+
+    @Autowired
+    private SimulationTrackService simulationTrackService;
+
+
+    @GetMapping("/beidou")
+    public void beidouTrack(){
+        simulationTrackService.beidouTrack();
+    }
+
+    @GetMapping("/ais")
+    public void aisTrack(){
+        simulationTrackService.aisTrack();
+    }
+
+}

+ 15 - 0
simulation-track/src/main/java/cn/com/taiji/service/SimulationTrackService.java

@@ -0,0 +1,15 @@
+package cn.com.taiji.service;
+
+/**
+ * @author chenfangchao
+ * @title: SimulationTrackService
+ * @projectName es-track-analysis
+ * @description: TODO
+ * @date 2023/2/7 5:16 PM
+ */
+public interface SimulationTrackService {
+
+    void beidouTrack();
+
+    void aisTrack();
+}

+ 84 - 0
simulation-track/src/main/java/cn/com/taiji/service/impl/SimulationTrackImpl.java

@@ -0,0 +1,84 @@
+package cn.com.taiji.service.impl;
+
+import cn.com.taiji.constants.TopicConstants;
+import cn.com.taiji.entity.BeidouShipTrackDTO;
+import cn.com.taiji.entity.GlobalAisTrackDTO;
+import cn.com.taiji.entity.Location;
+import cn.com.taiji.service.SimulationTrackService;
+import cn.com.taiji.utils.LocationUtils;
+import cn.hutool.core.date.DateUtil;
+import cn.hutool.json.JSONUtil;
+import org.springframework.kafka.core.KafkaTemplate;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.util.List;
+
+/**
+ * @author chenfangchao
+ * @title: SimulationTrackImpl
+ * @projectName es-track-analysis
+ * @description: TODO
+ * @date 2023/2/7 5:16 PM
+ */
+@Service
+public class SimulationTrackImpl implements SimulationTrackService {
+
+
+    @Resource
+    private KafkaTemplate<String, Object> kafkaTemplate;
+
+
+    public static void main(String[] args) {
+        List<Location> list = LocationUtils.generateLogLat("2023-02-03 00:00:00", "2023-02-03 00:02:00", 109.287806, 19.718716, 101.287806, 19.918716);
+    }
+
+    @Override
+    public void beidouTrack() {
+        List<Location> list = LocationUtils.generateLogLat("2023-02-03 00:00:00", "2023-02-03 00:02:00", 109.287806, 19.718716, 101.287806, 20.918716);
+        for (Location location : list) {
+            BeidouShipTrackDTO beidouShipTrackDTO = new BeidouShipTrackDTO();
+            beidouShipTrackDTO.setTrackId(20236688L);
+            beidouShipTrackDTO.setTime(DateUtil.now());
+            beidouShipTrackDTO.setDeviceId("2023111,2023222");
+            beidouShipTrackDTO.setShipType(1L);
+            beidouShipTrackDTO.setWorkType(1L);
+            beidouShipTrackDTO.setWorkWay(1);
+            beidouShipTrackDTO.setSendTime(DateUtil.now());
+            beidouShipTrackDTO.setLocationTime(DateUtil.now());
+            beidouShipTrackDTO.setOnline(1);
+            beidouShipTrackDTO.setShipLength(1);
+            beidouShipTrackDTO.setShipWidth(1);
+            beidouShipTrackDTO.setTexture(1);
+            beidouShipTrackDTO.setDirection(1D);
+            beidouShipTrackDTO.setSpeed(1D);
+            beidouShipTrackDTO.setKwh(1);
+            beidouShipTrackDTO.setShipName("模拟北斗船舶");
+            beidouShipTrackDTO.setLatitude(location.getLat());
+            beidouShipTrackDTO.setLongitude(location.getLog());
+            String data = JSONUtil.toJsonStr(beidouShipTrackDTO);
+            kafkaTemplate.send(TopicConstants.BEIDOU_TOPIC,data);
+        }
+    }
+
+    @Override
+    public void aisTrack() {
+        List<Location> list = LocationUtils.generateLogLat("2023-02-03 00:00:00", "2023-02-03 00:02:00", 101.287806, 20.718716, 101.387806, 20.818716);
+        for (Location location : list) {
+            GlobalAisTrackDTO globalAisTrackDTO = new GlobalAisTrackDTO();
+            globalAisTrackDTO.setUserid("2023111,2023222");
+            globalAisTrackDTO.setReceiveTime(DateUtil.now());
+            globalAisTrackDTO.setMessageid("2023");
+            globalAisTrackDTO.setNavStatus("1");
+            globalAisTrackDTO.setRot("1");
+            globalAisTrackDTO.setSog("1");
+            globalAisTrackDTO.setCog("1");
+            globalAisTrackDTO.setTrueHeading("1");
+            globalAisTrackDTO.setDsource("1");
+            globalAisTrackDTO.setLongitude(location.getLog());
+            globalAisTrackDTO.setLatitude(location.getLat());
+            String data = JSONUtil.toJsonStr(globalAisTrackDTO);
+            kafkaTemplate.send(TopicConstants.GLOBAL_AIS,data);
+        }
+    }
+}

+ 58 - 0
simulation-track/src/main/resources/application-prod.yml

@@ -0,0 +1,58 @@
+spring:
+  kafka:
+    bootstrap-servers: kafka67:9094,kafka68:9094,kafka69:9094,kafka70:9094,kafka71:9094
+    #ip 74.10.28.67:9094,74.10.28.68:9094,74.10.28.69:9094,74.10.28.70:9094,74.10.28.71:9094
+    #bootstrap-servers: localhost:9092
+    producer:
+      retries: 3
+      batch-size: 16384
+      buffer-memory: 33554432
+      key-serializer: org.apache.kafka.common.serialization.StringSerializer
+      value-serializer: org.apache.kafka.common.serialization.StringSerializer
+      # acks=0 : 生产者在成功写入消息之前不会等待任何来自服务器的响应。
+      # acks=1 : 只要集群的首领节点收到消息,生产者就会收到一个来自服务器成功响应。
+      # acks=all :只有当所有参与复制的节点全部收到消息时,生产者才会收到一个来自服务器的成功响应。
+      acks: 1
+    consumer:
+      # 自动提交的时间间隔 在spring boot 2.X 版本中这里采用的是值的类型为Duration 需要符合特定的格式,如1S,1M,2H,5D
+      auto-commit-interval: 1S
+      # 该属性指定了消费者在读取一个没有偏移量的分区或者偏移量无效的情况下该作何处理:
+      # latest(默认值)在偏移量无效的情况下,消费者将从最新的记录开始读取数据(在消费者启动之后生成的记录)
+      # earliest :在偏移量无效的情况下,消费者将从起始位置读取分区的记录
+      auto-offset-reset: latest
+      # 是否自动提交偏移量,默认值是true,为了避免出现重复数据和数据丢失,可以把它设置为false,然后手动提交偏移量
+      enable-auto-commit: false
+      key-deserializer: org.apache.kafka.common.serialization.StringDeserializer
+      value-deserializer: org.apache.kafka.common.serialization.StringDeserializer
+    properties:
+      security:
+        protocol: SASL_PLAINTEXT
+      sasl:
+        mechanism: SCRAM-SHA-512
+        jaas:
+          config: 'org.apache.kafka.common.security.scram.ScramLoginModule required username="user01" password="user01";'
+    listener:
+      # 在侦听器容器中运行的线程数。
+      concurrency: 5
+      #listner负责ack,每调用一次,就立即commit
+      ack-mode: manual_immediate
+      missing-topics-fatal: false
+
+taiji:
+  kafka.consumer:
+    beidou:
+      enable: false
+      expiry: 70
+      topic: taiji_ax_beidou_dynamic_ship
+      group: taiji_ax_beidou_dynamic_ship—${random.uuid}
+    global-ais:
+      enable: false
+      expiry: 10
+      topic: taiji_ax_ztpt_dynamic_ais
+    prefix:
+      trake_user_prefix: trake_user_prefix_
+      trake_dept_prefix: trake_dept_prefix_
+      ship_borne_terminal_redis_key_prefix: ship_borne_terminal_
+      static_beidou_law_enforcement_ship_redis_key_prefix: STATIC_BEIDOU_LAW_ENFORCEMENT_SHIP_
+      static_police_man_track_redis_key_prefix: STATIC_POLICE_MAN_TRACK_REDIS_
+      static_law_enforcement_car_redis_key_prefix: STATIC_LAW_ENFORCEMENT_CAR_

+ 53 - 0
simulation-track/src/main/resources/application.yml

@@ -0,0 +1,53 @@
+server:
+  port: 9003
+
+spring:
+  ##kafka
+  kafka:
+    bootstrap-servers: 120.25.232.213:9092
+    consumer:
+      auto-commit-interval: 1S
+        # 该属性指定了消费者在读取一个没有偏移量的分区或者偏移量无效的情况下该作何处理:
+        # latest(默认值)在偏移量无效的情况下,消费者将从最新的记录开始读取数据(在消费者启动之后生成的记录)
+        # earliest :在偏移量无效的情况下,消费者将从起始位置读取分区的记录
+        # 自动提交的时间间隔 在spring boot 2.X 版本中这里采用的是值的类型为Duration 需要符合特定的格式,如1S,1M,2H,5D
+        # 该属性指定了消费者在读取一个没有偏移量的分区或者偏移量无效的情况下该作何处理:
+      # latest(默认值)在偏移量无效的情况下,消费者将从最新的记录开始读取数据(在消费者启动之后生成的记录)
+      # earliest :在偏移量无效的情况下,消费者将从起始位置读取分区的记录
+      auto-offset-reset: latest
+      # 是否自动提交偏移量,默认值是true,为了避免出现重复数据和数据丢失,可以把它设置为false,然后手动提交偏移量
+      enable-auto-commit: false
+      key-deserializer: org.apache.kafka.common.serialization.StringDeserializer
+      value-deserializer: org.apache.kafka.common.serialization.StringDeserializer
+    producer:
+      retries: 3
+      batch-size: 16384
+      buffer-memory: 33554432
+      key-serializer: org.apache.kafka.common.serialization.StringSerializer
+      value-serializer: org.apache.kafka.common.serialization.StringSerializer
+      # acks=0 : 生产者在成功写入消息之前不会等待任何来自服务器的响应。
+      # acks=1 : 只要集群的首领节点收到消息,生产者就会收到一个来自服务器成功响应。
+      # acks=all :只有当所有参与复制的节点全部收到消息时,生产者才会收到一个来自服务器的成功响应。
+      acks: 1
+    properties:
+      security:
+        protocol: SASL_PLAINTEXT
+      sasl:
+        mechanism: SCRAM-SHA-512
+        jaas:
+          config: 'org.apache.kafka.common.security.scram.ScramLoginModule required username="user01" password="user01";'
+    listener:
+      # 在侦听器容器中运行的线程数。
+      concurrency: 5
+      #listner负责ack,每调用一次,就立即commit
+      ack-mode: manual_immediate
+      missing-topics-fatal: false
+
+
+taiji:
+  elasticsearch.rest:
+    uris: 120.25.233.10:9200
+    username: elastic       #如果你设置了基于x-pack的验证就要填写账号和密码
+    password: root@2022!       #没有则不用配置
+    connection-timeout: 100 #连接超时
+    max-connection: 100  #最大连接数