master
parent
869f4391a2
commit
dd49a1109f
|
@ -0,0 +1,17 @@
|
|||
package com.god.business.common.constant;
|
||||
|
||||
/**
|
||||
* @description: 车辆事件常量
|
||||
* @Author fst
|
||||
* @date 2023/12/5 10:48
|
||||
*/
|
||||
public class EventConstant {
|
||||
//电子围栏事件
|
||||
public static final String FENCE = "Fence";
|
||||
|
||||
//故障报警事件
|
||||
public static final String FAULT = "FaultAlarm";
|
||||
|
||||
//实时轨迹事件
|
||||
public static final String REAL = "RealTimeTrajectory";
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
package com.god.base.server.config;
|
||||
|
||||
|
||||
import com.god.common.redis.service.RedisService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import java.util.HashSet;
|
||||
|
||||
|
||||
/**
|
||||
* 车辆事件初始化
|
||||
* @Author fst
|
||||
* @date 2023/12/5 10:10
|
||||
*/
|
||||
@Component
|
||||
public class EventInit {
|
||||
@Autowired
|
||||
private RedisService redisService;
|
||||
|
||||
/**
|
||||
* 添加车辆事件
|
||||
* @param carVinId
|
||||
* @param event
|
||||
*/
|
||||
public void insertEvent(String carVinId,String event){
|
||||
//获取车辆事件集合
|
||||
HashSet<String> set = redisService.getCacheMapValue("EVENT", carVinId);
|
||||
//添加事件
|
||||
set.add(event);
|
||||
//更新事件
|
||||
redisService.setCacheMapValue("EVENT",carVinId,set);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 删除车辆事件
|
||||
* @param carVinId
|
||||
* @param event
|
||||
*/
|
||||
public void delEvent(String carVinId,String event){
|
||||
//获取车辆事件集合
|
||||
HashSet<String> set = redisService.getCacheMapValue("EVENT", carVinId);
|
||||
//添加事件
|
||||
set.remove(event);
|
||||
//更新事件
|
||||
redisService.setCacheMapValue("EVENT",carVinId,set);
|
||||
}
|
||||
}
|
|
@ -1,35 +1,44 @@
|
|||
//package com.god.base.server.consumer;
|
||||
//
|
||||
//import lombok.extern.java.Log;
|
||||
//import lombok.extern.log4j.Log4j;
|
||||
//import lombok.extern.log4j.Log4j2;
|
||||
//import org.springframework.amqp.rabbit.annotation.Queue;
|
||||
//import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
//import org.springframework.amqp.rabbit.annotation.RabbitListeners;
|
||||
//import org.springframework.stereotype.Component;
|
||||
//
|
||||
//import javax.annotation.Resource;
|
||||
//
|
||||
///**
|
||||
// * Description:
|
||||
// *
|
||||
// * @Author: sun-cool-boy
|
||||
// * @Date: 2023/11/29
|
||||
// * @info:
|
||||
// */
|
||||
//@Component
|
||||
//@Log4j2
|
||||
//public class RabbitConsumer {
|
||||
//
|
||||
// @RabbitListener(queuesToDeclare = {@Queue("OUT_FENCE")})
|
||||
// public void one(String msg){
|
||||
// log.info("监听到消息:{} , 队列名:{}",msg,"OUT_FENCE");
|
||||
// System.out.println(msg);
|
||||
// }
|
||||
//
|
||||
// @RabbitListener(queuesToDeclare = {@Queue("IN_FENCE")})
|
||||
// public void two(String msg){
|
||||
// log.info("监听到消息:{} , 队列名:{}",msg,"IN_FENCE");
|
||||
// System.out.println(msg);
|
||||
// }
|
||||
//}
|
||||
package com.god.base.server.consumer;
|
||||
|
||||
import com.rabbitmq.client.Channel;
|
||||
import lombok.extern.java.Log;
|
||||
import lombok.extern.log4j.Log4j;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.amqp.core.Message;
|
||||
import org.springframework.amqp.rabbit.annotation.Queue;
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitListeners;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Description:
|
||||
*
|
||||
* @Author: sun-cool-boy
|
||||
* @Date: 2023/11/29
|
||||
* @info:
|
||||
*/
|
||||
@Component
|
||||
@Log4j2
|
||||
public class RabbitConsumer {
|
||||
|
||||
@RabbitListener(queuesToDeclare = {@Queue("OUT_FENCE")})
|
||||
public void one(String msg, Message message, Channel channel){
|
||||
try {
|
||||
log.info("监听到消息:{} , 队列名:{}",msg,"OUT_FENCE");
|
||||
log.info("车辆驶出围栏,消息是:{}",msg);
|
||||
//手动确认
|
||||
channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@RabbitListener(queuesToDeclare = {@Queue("IN_FENCE")})
|
||||
public void two(String msg){
|
||||
log.info("监听到消息:{} , 队列名:{}",msg,"IN_FENCE");
|
||||
log.info("车辆驶入围栏,消息是:{}",msg);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,14 +1,18 @@
|
|||
package com.god.base.server.service.impl;
|
||||
|
||||
import com.god.base.server.config.EventInit;
|
||||
import com.god.business.common.constant.EventConstant;
|
||||
import com.god.common.core.domain.Result;
|
||||
import com.god.common.redis.service.RedisService;
|
||||
import com.god.base.server.service.RealTimeTrajectoryServer;
|
||||
import io.swagger.v3.oas.annotations.servers.Server;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
|
@ -23,7 +27,10 @@ import java.util.List;
|
|||
@Service
|
||||
public class RealTimeTrajectoryServerImpl implements RealTimeTrajectoryServer{
|
||||
|
||||
public static final String EVENT = "event";//事件存储前缀
|
||||
@Autowired
|
||||
private EventInit eventInit;
|
||||
|
||||
public static final String EVENT = "EVENT";//事件存储前缀
|
||||
public static final String REAL_TIME_TRAJECTORY = "RealTimeTrajectory";//实时轨迹事件
|
||||
|
||||
@Resource
|
||||
|
@ -36,18 +43,8 @@ public class RealTimeTrajectoryServerImpl implements RealTimeTrajectoryServer{
|
|||
*/
|
||||
@Override
|
||||
public Result addRealTimeTrajectoryEvent(String vin) {
|
||||
//拿到 vin对应的绑定事件
|
||||
List<Object> cacheList = redisService.getCacheList(EVENT + vin);
|
||||
//类型转换成String
|
||||
List<String> list = cacheList
|
||||
.stream()
|
||||
.map(String::valueOf).
|
||||
toList();
|
||||
//添加该事件
|
||||
list.add(REAL_TIME_TRAJECTORY);
|
||||
//重新存入
|
||||
long l = redisService.setCacheList(EVENT + vin, cacheList);
|
||||
return l > cacheList.size() ? Result.success():Result.error();
|
||||
eventInit.insertEvent(vin,EventConstant.REAL);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -57,12 +54,7 @@ public class RealTimeTrajectoryServerImpl implements RealTimeTrajectoryServer{
|
|||
*/
|
||||
@Override
|
||||
public Result delRealTimeTrajectoryEvent(String vin) {
|
||||
List<String> list = redisService.getCacheList(EVENT + vin)
|
||||
.stream()
|
||||
.filter(obj -> !REAL_TIME_TRAJECTORY.equals(String.valueOf(obj)))
|
||||
.map(String::valueOf)
|
||||
.toList();
|
||||
long l = redisService.setCacheList(EVENT + vin, list);
|
||||
return l > 0 ?Result.success():Result.error();
|
||||
eventInit.delEvent(vin,EventConstant.REAL);
|
||||
return Result.success();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue