77 lines
3.0 KiB
Java
77 lines
3.0 KiB
Java
package com.parseSystem.event.impl;
|
||
|
||
import com.alibaba.fastjson.JSONObject;
|
||
import com.dragon.common.redis.service.RedisService;
|
||
import com.parseSystem.event.EventHandlerService;
|
||
import com.parseSystem.event.VehicleEventService;
|
||
import com.parseSystem.utils.eventRuleJudge.PolygonUtil;
|
||
import com.parseSystem.vehicle.FenceData;
|
||
import com.parseSystem.vehicle.VehicleData;
|
||
import lombok.extern.log4j.Log4j2;
|
||
import org.springframework.beans.factory.annotation.Autowired;
|
||
import org.springframework.stereotype.Service;
|
||
|
||
import java.awt.geom.Point2D;
|
||
import java.util.ArrayList;
|
||
import java.util.Arrays;
|
||
import java.util.List;
|
||
import java.util.stream.Collectors;
|
||
|
||
/**
|
||
*
|
||
* 电子围栏事件
|
||
* @author 冯凯
|
||
* @version 1.0
|
||
*
|
||
* @date 2023/11/27 20:57
|
||
*/
|
||
@Service("fenceEvent")
|
||
@Log4j2
|
||
public class FenceEvent extends EventHandlerService implements VehicleEventService {
|
||
|
||
@Autowired
|
||
private RedisService redisService;
|
||
/**
|
||
* 电子围栏事件执行逻辑
|
||
* @param vehicleData
|
||
*/
|
||
@Override
|
||
public void executeEvent(VehicleData vehicleData) {
|
||
//获取报文解析的车辆vin
|
||
String vin = vehicleData.getVin();
|
||
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 longitude = Double.valueOf(vehicleData.getLongitude());
|
||
//创建工具类使用所需要的对象变量类赋值
|
||
Point2D.Double point = new Point2D.Double();
|
||
//赋值
|
||
point.setLocation(longitude,latitude);
|
||
//循环切割redis中拿到的电子围栏数据
|
||
fenceList.stream().forEach(item -> {
|
||
//将围栏存放的信息转型拿到每个对象的属性
|
||
FenceData fenceData = JSONObject.parseObject(item, FenceData.class);
|
||
//循环得到每个电子围栏的坐标拼接的一个以;为分割点表示多边形的一个字符串
|
||
List<Point2D.Double> locationPts = Arrays.stream(item.split(";"))
|
||
.map(s -> s.split(","))
|
||
.map(arr -> new Point2D.Double(Double.valueOf(arr[0]), Double.valueOf(arr[1])))
|
||
.collect(Collectors.toList());
|
||
boolean inPolygon = PolygonUtil.isInPolygon(point, locationPts);
|
||
//判断如果在围栏平面内,则判断围栏的报警状态 0-驶入警告 1-驶出警告
|
||
if (inPolygon == true && fenceData.getAlarmType()==0){
|
||
log.info("----当前车辆已驶入围栏 警告!!!");
|
||
}else if(inPolygon == false && fenceData.getAlarmType()==1){
|
||
log.info("----当前车辆已驶出围栏 警告!!!");
|
||
}else {
|
||
log.info("----该车辆为绑定围栏");
|
||
}
|
||
});
|
||
}
|
||
|
||
|
||
}
|