实时轨迹业务添加
parent
2cc014deb1
commit
429a07e2e3
|
@ -1,25 +1,20 @@
|
||||||
package com.parseSystem.event;
|
package com.parseSystem.event;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
|
||||||
import com.dragon.common.redis.service.RedisService;
|
import com.dragon.common.redis.service.RedisService;
|
||||||
import com.parseSystem.utils.SpringUtils;
|
import com.parseSystem.utils.SpringUtils;
|
||||||
import com.parseSystem.vehicle.VehicleData;
|
import com.parseSystem.vehicle.VehicleData;
|
||||||
import lombok.extern.log4j.Log4j2;
|
import lombok.extern.log4j.Log4j2;
|
||||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.redis.core.RedisTemplate;
|
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* 事件处理接口
|
||||||
*
|
*
|
||||||
*事件处理接口
|
|
||||||
* @author 冯凯
|
* @author 冯凯
|
||||||
* @version 1.0
|
* @version 1.0
|
||||||
* @description:
|
* @description:
|
||||||
|
@ -29,41 +24,39 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||||
@Log4j2
|
@Log4j2
|
||||||
public class EventHandlerService {
|
public class EventHandlerService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 事件处理map
|
||||||
|
*/
|
||||||
|
public static final Map<String, List<String>> eventMap = new ConcurrentHashMap<>();
|
||||||
@Autowired
|
@Autowired
|
||||||
private RedisService redisService;
|
private RedisService redisService;
|
||||||
|
|
||||||
/**
|
|
||||||
* 事件处理map
|
|
||||||
*/
|
|
||||||
public static final Map<String, List<String>> eventMap=new ConcurrentHashMap<>();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 注册事件
|
* 注册事件
|
||||||
|
*
|
||||||
* @param vin
|
* @param vin
|
||||||
* @param eventServiceName
|
* @param eventServiceName
|
||||||
*/
|
*/
|
||||||
public void registerEvent(String vin,String eventServiceName){
|
public void registerEvent(String vin, String eventServiceName) {
|
||||||
getEventList(vin).add(eventServiceName);
|
getEventList(vin).add(eventServiceName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 移除事件
|
* 移除事件
|
||||||
|
*
|
||||||
* @param vin
|
* @param vin
|
||||||
* @param eventServiceName
|
* @param eventServiceName
|
||||||
*/
|
*/
|
||||||
public void removeEvent(String vin,String eventServiceName){
|
public void removeEvent(String vin, String eventServiceName) {
|
||||||
getEventList(vin).remove(eventServiceName);
|
getEventList(vin).remove(eventServiceName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 执行事件
|
* 执行事件
|
||||||
|
*
|
||||||
* @param vehicleData
|
* @param vehicleData
|
||||||
*/
|
*/
|
||||||
public void executeEvent(VehicleData vehicleData){
|
public void executeEvent(VehicleData vehicleData) {
|
||||||
List<String> eventList = getEventList(vehicleData.getVin());
|
List<String> eventList = getEventList(vehicleData.getVin());
|
||||||
eventList.forEach(eventServiceName -> {
|
eventList.forEach(eventServiceName -> {
|
||||||
VehicleEventService vehicleEventService = SpringUtils.getBean(eventServiceName);
|
VehicleEventService vehicleEventService = SpringUtils.getBean(eventServiceName);
|
||||||
|
@ -73,16 +66,17 @@ public class EventHandlerService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取事件列表
|
* 获取事件列表
|
||||||
|
*
|
||||||
* @param vin
|
* @param vin
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public List<String> getEventList(String vin){
|
public List<String> getEventList(String vin) {
|
||||||
List<String> cacheList = redisService.getCacheList("event_VIN123456789");
|
List<String> cacheList = redisService.getCacheList("event_VIN123456789");
|
||||||
eventMap.put(vin,cacheList);
|
eventMap.put(vin, cacheList);
|
||||||
List<String> eventList = eventMap.get(vin);
|
List<String> eventList = eventMap.get(vin);
|
||||||
if (eventList==null){
|
if (eventList == null) {
|
||||||
ArrayList<String> list = new ArrayList<>();
|
ArrayList<String> list = new ArrayList<>();
|
||||||
eventMap.put(vin,list);
|
eventMap.put(vin, list);
|
||||||
}
|
}
|
||||||
return eventList;
|
return eventList;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,20 @@
|
||||||
package com.parseSystem.event.impl;
|
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.EventHandlerService;
|
||||||
import com.parseSystem.event.VehicleEventService;
|
import com.parseSystem.event.VehicleEventService;
|
||||||
import com.parseSystem.vehicle.VehicleData;
|
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 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")
|
@Service("runtimeTraceEvent")
|
||||||
public class RuntimeTraceEvent extends EventHandlerService implements VehicleEventService {
|
public class RuntimeTraceEvent extends EventHandlerService implements VehicleEventService {
|
||||||
|
@Autowired
|
||||||
|
private RedisService redisService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 实时轨迹事件执行逻辑
|
* 实时轨迹事件执行逻辑
|
||||||
|
@ -22,6 +34,6 @@ public class RuntimeTraceEvent extends EventHandlerService implements VehicleEve
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void executeEvent(VehicleData vehicleData) {
|
public void executeEvent(VehicleData vehicleData) {
|
||||||
System.out.println("你好实时轨迹");
|
redisService.setCacheObject("runtimeTraceEvent_"+vehicleData.getVin(),vehicleData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue