优化更新:车辆动态绑定事件

vehicle-xiaofan
黄大举 2024-04-08 21:20:55 +08:00
parent 4c4d5f5fbc
commit d0c2928c8e
6 changed files with 41 additions and 15 deletions

View File

@ -36,14 +36,14 @@ public class Consumer {
private VehicleEventCache vehicleEventCache;
List<String> list = new ArrayList<>();
// List<String> list = new ArrayList<>();
{
list.add("breakdown");
list.add("realTime");
list.add("storedEvent");
list.add("fenceAlarm");
}
// {
// list.add("breakdown");
// list.add("realTime");
// list.add("storedEvent");
// list.add("fenceAlarm");
// }
/**
* kafka-- kafka test
@ -53,12 +53,15 @@ public class Consumer {
@KafkaListener(topics = "test")
public void getMessage(String msg) {
VehicleData analyze = AnalyzeUtils.analyze(msg);
Set<String> eventList = vehicleEventCache.getEventList(analyze.getVin());
List<Fence> fenceVin=vehicleMapper.selectFenceList();
for (Fence fence : fenceVin) {
if (analyze.getVin().equals(fence.getCarVin())){
for (String s : list) {
for (String s : eventList) {
VehicleService vehicleService = SpringUtils.getBean(s);
vehicleService.eventResolution(analyze);
}

View File

@ -2,6 +2,8 @@ package com.muyu.analyze.controller;
import com.muyu.analyze.service.impl.RealTimeDataEventImpl;
import com.muyu.common.event.cache.VehicleEventCache;
import com.muyu.common.event.constants.VehicleEventConstants;
import com.muyu.system.common.domain.VehicleData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
@ -19,7 +21,8 @@ import org.springframework.web.bind.annotation.RestController;
*/
@RestController
public class RealTimeDataController {
@Autowired
private VehicleEventCache vehicleEventCache;
@Autowired
private RealTimeDataEventImpl realTimeDataEvent;
// 定义一个接口,用于获取实时数据
@ -36,6 +39,9 @@ public class RealTimeDataController {
@PostMapping("/realTimeDataTwo/{vin}")
public ResponseEntity<VehicleData> getRealTimeDataByVin(@PathVariable String vin) {
vehicleEventCache.addEvent(vin, VehicleEventConstants.SHI_SHI);
// 假设这里调用实时数据处理服务的某个方法来根据 VIN 获取实时数据
VehicleData realTimeData = realTimeDataEvent.getRealTimeDataByVin(vin);
System.out.println("VIN为" + vin + "的实时数据为:" + realTimeData);

View File

@ -31,6 +31,7 @@ public class FenceAlarmImpl implements VehicleService {
@Autowired
private RedisService redisService;
@Autowired
private VehicleMapper vehicleMapper;
@ -81,6 +82,8 @@ public class FenceAlarmImpl implements VehicleService {
redisService.setCacheSet(key,hashSet);
redisService.expire(key, 20, TimeUnit.MINUTES); // 设置过期时间
}
}

View File

@ -187,6 +187,7 @@ public class RedisService
setOperation.add(setValue);
return setOperation;
}
/**
* Set
*

View File

@ -24,6 +24,7 @@ import com.muyu.system.common.domain.req.CarInfoAddReq;
import com.muyu.system.common.domain.vo.CarVo;
import com.muyu.system.mapper.CarMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import com.muyu.system.service.CarService;
@ -125,22 +126,25 @@ public class CarServiceImpl extends ServiceImpl<CarMapper,Car> implements CarSer
vehicleCreateAddReq.setVinStr(car.getCarVin());
//构建请求的URL
String url="http://127.0.0.1:81/vehicle/create";
//使用RestTemplate发送post请求
Result<String> result=restTemplate.postForObject(url,vehicleCreateAddReq,Result.class);
if (null!=car.getCarFenceId()){
ArrayList<Long> arrayList = new ArrayList<>();
if (arrayList!=null && !arrayList.isEmpty()){
// redisTemplate.opsForSet().add(car.getCarVin(),"fenceAlarm");
vehicleEventCache.addEvent(car.getCarVin(), VehicleEventConstants.WEI_LAN);
vehicleEventCache.addEvent(car.getCarVin(), VehicleEventConstants.CUN_CU);
}else {
vehicleEventCache.removeEvent(car.getCarVin(), VehicleEventConstants.WEI_LAN);
}
carMapper.insert(car);
}
/**
@ -156,6 +160,15 @@ public class CarServiceImpl extends ServiceImpl<CarMapper,Car> implements CarSer
car.setUpdateTime(DateUtils.getNowDate());
if (null!=car.getCarFenceId()){
vehicleEventCache.addEvent(car.getCarVin(), VehicleEventConstants.WEI_LAN);
}else {
vehicleEventCache.removeEvent(car.getCarVin(), VehicleEventConstants.WEI_LAN);
}
carMapper.updateById(car);
}

View File

@ -14,12 +14,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</sql>
<insert id="insertCarInfo">
insert into car_info(
car_vin,
vin,
info_openDate,
info_closeDate
) values
(
#{carVin},
#{vin},
#{infoOpenDate},
#{infoCloseDate}
)