实时轨迹业务添加

master^2
tangwenkang 2023-12-05 09:24:16 +08:00
parent 2cc014deb1
commit 429a07e2e3
2 changed files with 29 additions and 23 deletions

View File

@ -1,25 +1,20 @@
package com.parseSystem.event;
import com.alibaba.fastjson.JSONObject;
import com.dragon.common.redis.service.RedisService;
import com.parseSystem.utils.SpringUtils;
import com.parseSystem.vehicle.VehicleData;
import lombok.extern.log4j.Log4j2;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
*
*
*
* @author
* @version 1.0
* @description:
@ -29,41 +24,39 @@ import java.util.concurrent.ConcurrentHashMap;
@Log4j2
public class EventHandlerService {
/**
* map
*/
public static final Map<String, List<String>> eventMap = new ConcurrentHashMap<>();
@Autowired
private RedisService redisService;
/**
* map
*/
public static final Map<String, List<String>> eventMap=new ConcurrentHashMap<>();
/**
*
*
* @param vin
* @param eventServiceName
*/
public void registerEvent(String vin,String eventServiceName){
public void registerEvent(String vin, String eventServiceName) {
getEventList(vin).add(eventServiceName);
}
/**
*
*
* @param vin
* @param eventServiceName
*/
public void removeEvent(String vin,String eventServiceName){
public void removeEvent(String vin, String eventServiceName) {
getEventList(vin).remove(eventServiceName);
}
/**
*
*
* @param vehicleData
*/
public void executeEvent(VehicleData vehicleData){
public void executeEvent(VehicleData vehicleData) {
List<String> eventList = getEventList(vehicleData.getVin());
eventList.forEach(eventServiceName -> {
VehicleEventService vehicleEventService = SpringUtils.getBean(eventServiceName);
@ -73,16 +66,17 @@ public class EventHandlerService {
/**
*
*
* @param vin
* @return
*/
public List<String> getEventList(String vin){
public List<String> getEventList(String vin) {
List<String> cacheList = redisService.getCacheList("event_VIN123456789");
eventMap.put(vin,cacheList);
eventMap.put(vin, cacheList);
List<String> eventList = eventMap.get(vin);
if (eventList==null){
if (eventList == null) {
ArrayList<String> list = new ArrayList<>();
eventMap.put(vin,list);
eventMap.put(vin, list);
}
return eventList;
}

View File

@ -1,10 +1,20 @@
package com.parseSystem.event.impl;
import com.alibaba.fastjson2.JSONObject;
import com.dragon.common.redis.service.RedisService;
import com.parseSystem.event.EventHandlerService;
import com.parseSystem.event.VehicleEventService;
import com.parseSystem.vehicle.VehicleData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import javax.xml.crypto.Data;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.TimeUnit;
/**
*
*
@ -15,6 +25,8 @@ import org.springframework.stereotype.Service;
*/
@Service("runtimeTraceEvent")
public class RuntimeTraceEvent extends EventHandlerService implements VehicleEventService {
@Autowired
private RedisService redisService;
/**
*
@ -22,6 +34,6 @@ public class RuntimeTraceEvent extends EventHandlerService implements VehicleEve
*/
@Override
public void executeEvent(VehicleData vehicleData) {
System.out.println("你好实时轨迹");
redisService.setCacheObject("runtimeTraceEvent_"+vehicleData.getVin(),vehicleData);
}
}