更新事件
parent
ee09c901c2
commit
3a9f1a7ef1
|
@ -8,7 +8,7 @@ import lombok.NoArgsConstructor;
|
|||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* @description: 车辆报文接收对象
|
||||
* 车辆报文接收对象
|
||||
* @Author fst
|
||||
* @date 2023/11/23 14:33
|
||||
*/
|
||||
|
|
|
@ -33,7 +33,7 @@ public class ElePoint {
|
|||
private Integer fenceStatus;
|
||||
|
||||
/**
|
||||
* 电子围栏判断状态 1驶出 2驶离
|
||||
* 电子围栏判断状态 1驶入 2驶出
|
||||
*/
|
||||
private Integer driveStatus;
|
||||
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
package com.god.data.config;
|
||||
|
||||
import com.god.common.redis.service.RedisService;
|
||||
import com.god.data.common.domain.ElePoint;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Configurable;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* @description: 测试缓存
|
||||
* @Author fst
|
||||
* @date 2023/11/30 11:03
|
||||
*/
|
||||
@Configuration
|
||||
public class RedisInitTest {
|
||||
@Autowired
|
||||
private RedisService redisService;
|
||||
|
||||
|
||||
|
||||
public void redisInit()
|
||||
{
|
||||
redisService.deleteObject("Fence" + "VIN12345678912345");
|
||||
ArrayList<ElePoint> elePoints = new ArrayList<>();
|
||||
ElePoint e1 = ElePoint.builder().fenceLocation("116.357183,39.926512;116.394348,39.909989;116.34757,39.90617;").driveStatus(1).build();
|
||||
ElePoint e2 = ElePoint.builder().fenceLocation("116.36199,39.927921;116.411171,39.921207;116.378126,39.900798;").driveStatus(2).build();
|
||||
ElePoint e3 = ElePoint.builder().fenceLocation("116.357133,39.927258;116.391552,39.90685;116.358078,39.906587;116.345718,39.922387;").driveStatus(1).build();
|
||||
elePoints.add(e1);
|
||||
elePoints.add(e2);
|
||||
elePoints.add(e3);
|
||||
redisService.setCacheList("Fence" + "VIN12345678912345", elePoints);
|
||||
}
|
||||
|
||||
|
||||
public void parseInit()
|
||||
{
|
||||
redisService.deleteObject("event" + "VIN12345678912345");
|
||||
ArrayList<String> strings = new ArrayList<>();
|
||||
// strings.add("fence");
|
||||
strings.add("FaultAlarm");
|
||||
strings.add("RealTimeTrajectory");
|
||||
redisService.setCacheList("event" + "VIN12345678912345", strings);
|
||||
}
|
||||
}
|
|
@ -15,6 +15,7 @@ import org.springframework.stereotype.Component;
|
|||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.time.Duration;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
@ -34,6 +35,8 @@ public class ParseDataService {
|
|||
@Autowired
|
||||
private KafkaConsumer<String, String> consumer;
|
||||
|
||||
|
||||
|
||||
@PostConstruct
|
||||
public void start(){
|
||||
|
||||
|
@ -46,6 +49,7 @@ public class ParseDataService {
|
|||
//死循环拉取kafka数据
|
||||
records = consumer.poll(Duration.ofMillis(1000));
|
||||
for (ConsumerRecord<String, String> record : records) {
|
||||
System.out.println(record.value());
|
||||
//把报文解析成对象
|
||||
CarMessage carMessage = AnalyzeUtils.parseVehicleData(record.value());
|
||||
//根据对象车辆vin获取事件集合,从redis中获取
|
||||
|
@ -57,6 +61,7 @@ public class ParseDataService {
|
|||
eventService.execute(carMessage);
|
||||
}
|
||||
}
|
||||
// System.out.println("======="+carMessage+"====================");
|
||||
|
||||
System.out.println(record.offset() +" - "+ record.key() +" - "+ record.value());
|
||||
}
|
||||
|
|
|
@ -7,9 +7,12 @@ import com.god.data.common.domain.ElePoint;
|
|||
import com.god.data.common.domain.Point;
|
||||
import com.god.data.service.EventService;
|
||||
import com.god.data.utils.GeofencingUtils;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
@ -21,6 +24,7 @@ import java.util.stream.Collectors;
|
|||
* @date 2023/11/27 20:43
|
||||
*/
|
||||
@Service(value = "Fence")
|
||||
@Log4j2
|
||||
public class ElectronicFenceEvent implements EventService {
|
||||
|
||||
@Autowired
|
||||
|
@ -29,12 +33,14 @@ public class ElectronicFenceEvent implements EventService {
|
|||
@Autowired
|
||||
private RabbitTemplate rabbitTemplate;
|
||||
|
||||
|
||||
@Override
|
||||
public void insert() {
|
||||
|
||||
}
|
||||
@Override
|
||||
public void execute(CarMessage carMessage) {
|
||||
log.info("电子围栏数据解析事件执行");
|
||||
//从redis中获取当前车辆的电子围栏数据
|
||||
List<ElePoint> list = redisService.getCacheList("Fence" + carMessage.getVin());
|
||||
//根据当前经纬度和电子围栏数据进行判断,调用算法工具类
|
||||
|
@ -60,7 +66,7 @@ public class ElectronicFenceEvent implements EventService {
|
|||
//判断当前车辆是驶入/驶出围栏
|
||||
if (elePoint.getDriveStatus().equals(1)){
|
||||
//如果不在围栏范围内则,触发驶出电子围栏事件 ,存入rabbitmq中
|
||||
if (!inPolygon){
|
||||
if (inPolygon){
|
||||
rabbitTemplate.convertAndSend("OUT_FENCE", JSON.toJSON(elePoint), message -> {
|
||||
message.getMessageProperties().setMessageId(UUID.randomUUID().toString());
|
||||
return message;
|
||||
|
|
|
@ -30,16 +30,17 @@ public class FaultAlarmEvent implements EventService {
|
|||
|
||||
@Override
|
||||
public void execute(CarMessage carMessage) {
|
||||
//创建集合存故障码
|
||||
ArrayList<String> strings = new ArrayList<>();
|
||||
//判断车辆目前的报错故障,添加对应的故障码
|
||||
if (carMessage.getBatteryStatus()==1){
|
||||
strings.add("111");
|
||||
}
|
||||
//把对应的故障码集合存入rabbitmq
|
||||
if (strings.size()>0){
|
||||
rabbitTemplate.convertAndSend("god.car.fault.alarm",strings);
|
||||
}
|
||||
System.out.println("孙继哲大傻逼");
|
||||
// //创建集合存故障码
|
||||
// ArrayList<String> strings = new ArrayList<>();
|
||||
// //判断车辆目前的报错故障,添加对应的故障码
|
||||
// if (carMessage.getBatteryStatus()==1){
|
||||
// strings.add("111");
|
||||
// }
|
||||
// //把对应的故障码集合存入rabbitmq
|
||||
// if (strings.size()>0){
|
||||
// rabbitTemplate.convertAndSend("god.car.fault.alarm",strings);
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -32,8 +32,7 @@ public class RealTimeTrajectoryEvent implements EventService {
|
|||
|
||||
@Override
|
||||
public void execute(CarMessage carMessage) {
|
||||
//实时轨迹只需要把当前车辆的经纬度发送到redis集合即可
|
||||
// redisTemplate.opsForList().set("Trajectory",1,carMessage);
|
||||
System.out.println("冯凯牛魔王");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -16,20 +16,20 @@ public class AnalyzeUtils {
|
|||
* 解析报文获取报文对象
|
||||
*/
|
||||
public static CarMessage parseVehicleData(String input) {
|
||||
//把数据处理成java对象
|
||||
CarMessage carMessage = new CarMessage();
|
||||
CarMessage.builder()
|
||||
.vin(input.substring(1, 17))
|
||||
.timeString(Long.valueOf(input.substring(17, 30)))
|
||||
.longitude(BigDecimal.valueOf(Double.parseDouble(input.substring(30, 41))))
|
||||
.latitude(BigDecimal.valueOf(Double.parseDouble(input.substring(41, 51))))
|
||||
.speed(BigDecimal.valueOf(Double.parseDouble(input.substring(51, 57))))
|
||||
.sumMileage(BigDecimal.valueOf(Double.parseDouble(input.substring(57, 68))))
|
||||
.sumVoltage(BigDecimal.valueOf(Double.parseDouble(input.substring(68, 74))))
|
||||
.sumElectricity(BigDecimal.valueOf(Double.parseDouble(input.substring(74, 79))))
|
||||
.sumResistance(BigDecimal.valueOf(Double.parseDouble(input.substring(79, 88))))
|
||||
.gear(input.substring(88, 89))
|
||||
.acceleratorPedal(BigDecimal.valueOf(Double.parseDouble(input.substring(89, 91))))
|
||||
System.out.println(input);
|
||||
//把数据处理成java对象,返回解析完的对象.
|
||||
return CarMessage.builder()
|
||||
.vin(input.substring(1, 18))
|
||||
.timeString(Long.valueOf(input.substring(18, 31)))
|
||||
.longitude(BigDecimal.valueOf(Double.parseDouble(input.substring(31, 42))))
|
||||
.latitude(BigDecimal.valueOf(Double.parseDouble(input.substring(42, 52))))
|
||||
.speed(BigDecimal.valueOf(Double.parseDouble(input.substring(52, 58))))
|
||||
.sumMileage(BigDecimal.valueOf(Double.parseDouble(input.substring(58, 69))))
|
||||
.sumVoltage(BigDecimal.valueOf(Double.parseDouble(input.substring(69, 75))))
|
||||
.sumElectricity(BigDecimal.valueOf(Double.parseDouble(input.substring(75, 80))))
|
||||
.sumResistance(BigDecimal.valueOf(Double.parseDouble(input.substring(80, 89))))
|
||||
.gear(input.substring(89, 90))
|
||||
.acceleratorPedal(BigDecimal.valueOf(Double.parseDouble(input.substring(90, 91))))
|
||||
.brakePedal(BigDecimal.valueOf(Double.parseDouble(input.substring(91, 93))))
|
||||
.specificFuelConsumption(BigDecimal.valueOf(Double.parseDouble(input.substring(93, 98))))
|
||||
.motorControllerTemperature(BigDecimal.valueOf(Double.parseDouble(input.substring(98, 104))))
|
||||
|
@ -65,13 +65,18 @@ public class AnalyzeUtils {
|
|||
.batteryStatus(Integer.valueOf(input.substring(202, 203)))
|
||||
.batteryInsulationStatus(Integer.valueOf(input.substring(203, 204)))
|
||||
.dcdcStatus(Integer.valueOf(input.substring(204, 205)))
|
||||
.chgStatus(Integer.valueOf(input.substring(205, 206)));
|
||||
//返回解析完的对象
|
||||
return carMessage;
|
||||
.chgStatus(Integer.valueOf(input.substring(205, 206)))
|
||||
.build();
|
||||
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
CarMessage carMessage = parseVehicleData("~VIN12345678912345170124349622700000000000000000000000000012.5000000000000000000000000000P000000000000000000000000000000000000000000045000000000000000000000000000000000000000000000000000000011111111111111111©~");
|
||||
CarMessage carMessage = parseVehicleData(
|
||||
"~VIN123456789123451701309761024116." +
|
||||
"670799039.536898072.00012.9400000016000" +
|
||||
"028000879100000D707011.6047000060152600011900024000" +
|
||||
"7960000044970.230000310000601000023500030003000" +
|
||||
"47000026000025000011111111111111111Í~");
|
||||
System.out.println(carMessage);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue