电子围栏解析第一版完成
parent
00f08abd18
commit
2cc014deb1
|
@ -10,7 +10,7 @@ target/
|
||||||
|
|
||||||
######################################################################
|
######################################################################
|
||||||
# IDE
|
# IDE
|
||||||
|
IDEA/
|
||||||
### STS ###
|
### STS ###
|
||||||
.apt_generated
|
.apt_generated
|
||||||
.classpath
|
.classpath
|
||||||
|
|
6
pom.xml
6
pom.xml
|
@ -19,6 +19,11 @@
|
||||||
<artifactId>spring-boot-starter</artifactId>
|
<artifactId>spring-boot-starter</artifactId>
|
||||||
<version>2.7.15</version>
|
<version>2.7.15</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
|
<version>2.7.15</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-web</artifactId>
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
@ -68,6 +73,7 @@
|
||||||
<artifactId>dragon-common-redis</artifactId>
|
<artifactId>dragon-common-redis</artifactId>
|
||||||
<version>3.6.3</version>
|
<version>3.6.3</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<distributionManagement>
|
<distributionManagement>
|
||||||
<repository>
|
<repository>
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
package com.parseSystem.event.impl;
|
package com.parseSystem.event.impl;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.dragon.common.redis.service.RedisService;
|
import com.dragon.common.redis.service.RedisService;
|
||||||
import com.parseSystem.event.EventHandlerService;
|
import com.parseSystem.event.EventHandlerService;
|
||||||
import com.parseSystem.event.VehicleEventService;
|
import com.parseSystem.event.VehicleEventService;
|
||||||
import com.parseSystem.utils.eventRuleJudge.PolygonUtil;
|
import com.parseSystem.utils.eventRuleJudge.PolygonUtil;
|
||||||
|
import com.parseSystem.vehicle.FenceData;
|
||||||
import com.parseSystem.vehicle.VehicleData;
|
import com.parseSystem.vehicle.VehicleData;
|
||||||
|
import lombok.extern.log4j.Log4j2;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@ -23,6 +26,7 @@ import java.util.stream.Collectors;
|
||||||
* @date 2023/11/27 20:57
|
* @date 2023/11/27 20:57
|
||||||
*/
|
*/
|
||||||
@Service("fenceEvent")
|
@Service("fenceEvent")
|
||||||
|
@Log4j2
|
||||||
public class FenceEvent extends EventHandlerService implements VehicleEventService {
|
public class FenceEvent extends EventHandlerService implements VehicleEventService {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
@ -33,25 +37,40 @@ public class FenceEvent extends EventHandlerService implements VehicleEventServi
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void executeEvent(VehicleData vehicleData) {
|
public void executeEvent(VehicleData vehicleData) {
|
||||||
|
//获取报文解析的车辆vin
|
||||||
String vin = vehicleData.getVin();
|
String vin = vehicleData.getVin();
|
||||||
List<String> fenceList = redisService.getCacheList("fence_VIN123456789");
|
List<VehicleData> arr1 = null;
|
||||||
|
arr1.add(vehicleData);
|
||||||
|
//redis为(vin,fenceList)即vin为键,电子围栏为值存入redis
|
||||||
|
List<String> fenceList = redisService.getCacheList("fence_"+vin);
|
||||||
|
redisService.setCacheList("fence_VIN123456789",arr1);
|
||||||
|
//将报文的经纬度赋值给变量
|
||||||
Double latitude = Double.valueOf(vehicleData.getLatitude()); //实时纬度
|
Double latitude = Double.valueOf(vehicleData.getLatitude()); //实时纬度
|
||||||
Double longitude = Double.valueOf(vehicleData.getLongitude());
|
Double longitude = Double.valueOf(vehicleData.getLongitude());
|
||||||
|
//创建工具类使用所需要的对象变量类赋值
|
||||||
Point2D.Double point = new Point2D.Double();
|
Point2D.Double point = new Point2D.Double();
|
||||||
|
//赋值
|
||||||
point.setLocation(longitude,latitude);
|
point.setLocation(longitude,latitude);
|
||||||
List<Point2D.Double> pts = new ArrayList<>();
|
//循环切割redis中拿到的电子围栏数据
|
||||||
fenceList.stream().forEach(item -> {
|
fenceList.stream().forEach(item -> {
|
||||||
|
//将围栏存放的信息转型拿到每个对象的属性
|
||||||
|
FenceData fenceData = JSONObject.parseObject(item, FenceData.class);
|
||||||
//循环得到每个电子围栏的坐标拼接的一个以;为分割点表示多边形的一个字符串
|
//循环得到每个电子围栏的坐标拼接的一个以;为分割点表示多边形的一个字符串
|
||||||
List<Point2D.Double> locationPts = Arrays.stream(item.split(";"))
|
List<Point2D.Double> locationPts = Arrays.stream(item.split(";"))
|
||||||
.map(s -> s.split(","))
|
.map(s -> s.split(","))
|
||||||
.map(arr -> new Point2D.Double(Double.valueOf(arr[0]), Double.valueOf(arr[1])))
|
.map(arr -> new Point2D.Double(Double.valueOf(arr[0]), Double.valueOf(arr[1])))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
boolean inPolygon = PolygonUtil.isInPolygon(point, locationPts);
|
boolean inPolygon = PolygonUtil.isInPolygon(point, locationPts);
|
||||||
if (inPolygon){
|
//判断如果在围栏平面内,则判断围栏的报警状态 0-驶入警告 1-驶出警告
|
||||||
System.out.println("在电子围栏内");
|
if (inPolygon == true && fenceData.getAlarmType()==0){
|
||||||
}else{
|
log.info("----当前车辆已驶入围栏 警告!!!");
|
||||||
System.out.println("在电子围栏外");
|
}else if(inPolygon == false && fenceData.getAlarmType()==1){
|
||||||
|
log.info("----当前车辆已驶出围栏 警告!!!");
|
||||||
|
}else {
|
||||||
|
log.info("----该车辆为绑定围栏");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,61 @@
|
||||||
|
package com.parseSystem.vehicle;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 电子围栏实体类
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class FenceData {
|
||||||
|
/**
|
||||||
|
* 字段属性:围栏主键id
|
||||||
|
*/
|
||||||
|
@TableId(type = IdType.AUTO)
|
||||||
|
private Integer fenceId;
|
||||||
|
/**
|
||||||
|
* 字段属性:围栏名称
|
||||||
|
*/
|
||||||
|
private String fenceName;
|
||||||
|
/**
|
||||||
|
* 字段属性:围栏数据
|
||||||
|
*/
|
||||||
|
private String fenceData;
|
||||||
|
/**s
|
||||||
|
* 字段属性:围栏状态
|
||||||
|
*/
|
||||||
|
private Integer status;
|
||||||
|
/**
|
||||||
|
* 字段属性:告警类型
|
||||||
|
*/
|
||||||
|
private Integer alarmType;
|
||||||
|
/**
|
||||||
|
* 字段属性:围栏标签id
|
||||||
|
*/
|
||||||
|
private Integer fenceTagId;
|
||||||
|
/**
|
||||||
|
* 字段属性:创建人
|
||||||
|
*/
|
||||||
|
private String createdBy;
|
||||||
|
/**
|
||||||
|
* 字段属性:创建时间
|
||||||
|
*/
|
||||||
|
private Date createdTime;
|
||||||
|
/**
|
||||||
|
* 字段属性:更新人
|
||||||
|
*/
|
||||||
|
private String updatedBy;
|
||||||
|
/**
|
||||||
|
* 字段属性:更新时间
|
||||||
|
*/
|
||||||
|
private Date updatedTime;
|
||||||
|
}
|
|
@ -0,0 +1,45 @@
|
||||||
|
import com.parseSystem.ParseSystemApplication;
|
||||||
|
import com.parseSystem.event.impl.FenceEvent;
|
||||||
|
import com.parseSystem.vehicle.VehicleData;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@SpringBootTest(classes = ParseSystemApplication.class)
|
||||||
|
public class Test {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private FenceEvent fenceEvent;
|
||||||
|
@org.junit.jupiter.api.Test
|
||||||
|
public void aa(){
|
||||||
|
ArrayList<VehicleData> vehicleData = new ArrayList<>();
|
||||||
|
VehicleData vehicleData1 = new VehicleData();
|
||||||
|
//车辆当前地位
|
||||||
|
vehicleData1.setVin("1234567989000");
|
||||||
|
vehicleData1.setLongitude("116.48965348217772");
|
||||||
|
vehicleData1.setLatitude("39.90816602515441");
|
||||||
|
|
||||||
|
//车辆一分钟后的位置
|
||||||
|
VehicleData vehicleData2 = new VehicleData();
|
||||||
|
vehicleData2.setVin("1234567989000");
|
||||||
|
vehicleData2.setLongitude("117.48965348217772");
|
||||||
|
vehicleData2.setLatitude("40.90816602515441");
|
||||||
|
|
||||||
|
//车辆二分钟后的位置
|
||||||
|
VehicleData vehicleData3 = new VehicleData();
|
||||||
|
vehicleData3.setVin("1234567989000");
|
||||||
|
vehicleData3.setLongitude("118.48965348217772");
|
||||||
|
vehicleData3.setLatitude("41.90816602515441");
|
||||||
|
|
||||||
|
vehicleData.add(vehicleData1);
|
||||||
|
vehicleData.add(vehicleData2);
|
||||||
|
vehicleData.add(vehicleData3);
|
||||||
|
|
||||||
|
for (VehicleData vehicleDatum : vehicleData) {
|
||||||
|
fenceEvent.executeEvent(vehicleDatum);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue