feat: 优化代码
parent
599d89b6e4
commit
05b2baf32e
|
@ -8,7 +8,6 @@ import org.springframework.stereotype.Component;
|
||||||
* @Date: 2024/4/7
|
* @Date: 2024/4/7
|
||||||
* @Description: 事件内容
|
* @Description: 事件内容
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public interface AnalyzeEventContents {
|
public interface AnalyzeEventContents {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.couplet.analyze.common.event;
|
package com.couplet.analyze.common.event;
|
||||||
|
|
||||||
|
import com.couplet.common.domain.request.RealTimeDataRequest;
|
||||||
import com.couplet.common.redis.service.RedisService;
|
import com.couplet.common.redis.service.RedisService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
|
@ -38,6 +39,12 @@ public class AnalyzeEventCache {
|
||||||
public void removeEvent(String vin,String eventName){
|
public void removeEvent(String vin,String eventName){
|
||||||
redisService.deleteSet(encode(vin), eventName);
|
redisService.deleteSet(encode(vin), eventName);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 查询事件
|
||||||
|
*/
|
||||||
|
public void queryEvent(String vin, final RealTimeDataRequest eventName){
|
||||||
|
redisService.setCacheObject(encode(vin), eventName);
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* 获取事件集合
|
* 获取事件集合
|
||||||
*
|
*
|
||||||
|
@ -47,4 +54,5 @@ public class AnalyzeEventCache {
|
||||||
return redisService.getCacheSet(encode(vin));
|
return redisService.getCacheSet(encode(vin));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,203 +1,203 @@
|
||||||
package com.couplet.analyze.msg.consumer;
|
//package com.couplet.analyze.msg.consumer;
|
||||||
|
//
|
||||||
import com.alibaba.fastjson.JSONObject;
|
//import com.alibaba.fastjson.JSONObject;
|
||||||
import com.couplet.analyze.msg.domain.CoupletMsgData;
|
//import com.couplet.analyze.msg.domain.CoupletMsgData;
|
||||||
import com.couplet.analyze.msg.utils.MsgUtils;
|
//import com.couplet.analyze.msg.utils.MsgUtils;
|
||||||
import com.couplet.common.domain.CoupletTroubleCode;
|
//import com.couplet.common.domain.CoupletTroubleCode;
|
||||||
import com.couplet.common.redis.service.RedisService;
|
//import com.couplet.common.redis.service.RedisService;
|
||||||
import com.couplet.remote.RemoteTroubleService;
|
//import com.couplet.remote.RemoteTroubleService;
|
||||||
import com.rabbitmq.client.Channel;
|
//import com.rabbitmq.client.Channel;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
//import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.amqp.rabbit.annotation.Queue;
|
//import org.springframework.amqp.rabbit.annotation.Queue;
|
||||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
//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.data.redis.core.RedisTemplate;
|
||||||
import org.springframework.amqp.core.Message;
|
//import org.springframework.amqp.core.Message;
|
||||||
import org.springframework.stereotype.Component;
|
//import org.springframework.stereotype.Component;
|
||||||
|
//
|
||||||
import java.util.Date;
|
//import java.util.Date;
|
||||||
import java.util.concurrent.CompletableFuture;
|
//import java.util.concurrent.CompletableFuture;
|
||||||
|
//
|
||||||
/**
|
///**
|
||||||
* @author DongXiaoDong
|
// * @author DongXiaoDong
|
||||||
* @version 1.0
|
// * @version 1.0
|
||||||
* @date 2024/4/6 15:37
|
// * @date 2024/4/6 15:37
|
||||||
* @description
|
// * @description
|
||||||
*/
|
// */
|
||||||
@Component
|
//@Component
|
||||||
@Slf4j
|
//@Slf4j
|
||||||
public class CodeConsumer {
|
//public class CodeConsumer {
|
||||||
|
//// @Autowired
|
||||||
|
//// private RedisTemplate<String, String> redisTemplate;
|
||||||
|
//
|
||||||
// @Autowired
|
// @Autowired
|
||||||
// private RedisTemplate<String, String> redisTemplate;
|
// private RedisService redisService;
|
||||||
|
// @Autowired
|
||||||
@Autowired
|
// private RemoteTroubleService remoteTroubleService;
|
||||||
private RedisService redisService;
|
//
|
||||||
@Autowired
|
// @RabbitListener(queuesToDeclare = {@Queue("couplet-code-queue")})
|
||||||
private RemoteTroubleService remoteTroubleService;
|
// public void sendLogQueueConsumer(Message message, CoupletMsgData msgData, Channel channel) {
|
||||||
|
// log.info("日志队列:{},接收到的消息:{},开始消费...","couplet-code-queue", JSONObject.toJSONString(msgData));
|
||||||
@RabbitListener(queuesToDeclare = {@Queue("couplet-code-queue")})
|
// long start = System.currentTimeMillis();
|
||||||
public void sendLogQueueConsumer(Message message, CoupletMsgData msgData, Channel channel) {
|
//
|
||||||
log.info("日志队列:{},接收到的消息:{},开始消费...","couplet-code-queue", JSONObject.toJSONString(msgData));
|
// String messageId = message.getMessageProperties().getMessageId();
|
||||||
long start = System.currentTimeMillis();
|
//
|
||||||
|
// try {
|
||||||
String messageId = message.getMessageProperties().getMessageId();
|
// boolean addToSetIfNotExists = redisService.addToSetIfNotExists("couplet-code-queue", messageId);
|
||||||
|
// if (addToSetIfNotExists) {
|
||||||
try {
|
// //异步保存记录
|
||||||
boolean addToSetIfNotExists = redisService.addToSetIfNotExists("couplet-code-queue", messageId);
|
// CompletableFuture.runAsync(() -> {
|
||||||
if (addToSetIfNotExists) {
|
// CoupletTroubleCode troubleCode = new CoupletTroubleCode();
|
||||||
//异步保存记录
|
// troubleCode.setTroubleStartTime(new Date());
|
||||||
CompletableFuture.runAsync(() -> {
|
// troubleCode.setTroubleVin(msgData.getVin());
|
||||||
CoupletTroubleCode troubleCode = new CoupletTroubleCode();
|
// // 随机生成故障码
|
||||||
troubleCode.setTroubleStartTime(new Date());
|
// String faultCode = MsgUtils.generateGTA();
|
||||||
troubleCode.setTroubleVin(msgData.getVin());
|
// troubleCode.setTroubleCode(faultCode);
|
||||||
// 随机生成故障码
|
//
|
||||||
String faultCode = MsgUtils.generateGTA();
|
// switch (msgData.getVehicleStatus()) {
|
||||||
troubleCode.setTroubleCode(faultCode);
|
// case 0:
|
||||||
|
// troubleCode.setTroublePosition("190");
|
||||||
switch (msgData.getVehicleStatus()) {
|
// troubleCode.setProcessingState(0);
|
||||||
case 0:
|
// break;
|
||||||
troubleCode.setTroublePosition("190");
|
// default:
|
||||||
troubleCode.setProcessingState(0);
|
// switch (msgData.getChargingStatus()) {
|
||||||
break;
|
// case 0:
|
||||||
default:
|
// troubleCode.setTroublePosition("191");
|
||||||
switch (msgData.getChargingStatus()) {
|
// troubleCode.setProcessingState(0);
|
||||||
case 0:
|
// break;
|
||||||
troubleCode.setTroublePosition("191");
|
// default:
|
||||||
troubleCode.setProcessingState(0);
|
// switch (msgData.getOperatingStatus()) {
|
||||||
break;
|
// case 0:
|
||||||
default:
|
// troubleCode.setTroublePosition("192");
|
||||||
switch (msgData.getOperatingStatus()) {
|
// troubleCode.setProcessingState(0);
|
||||||
case 0:
|
// break;
|
||||||
troubleCode.setTroublePosition("192");
|
// default:
|
||||||
troubleCode.setProcessingState(0);
|
// switch (msgData.getSocStatus()) {
|
||||||
break;
|
// case 0:
|
||||||
default:
|
// troubleCode.setTroublePosition("193");
|
||||||
switch (msgData.getSocStatus()) {
|
// troubleCode.setProcessingState(0);
|
||||||
case 0:
|
// break;
|
||||||
troubleCode.setTroublePosition("193");
|
// default:
|
||||||
troubleCode.setProcessingState(0);
|
// switch (msgData.getChargingEnergyStorageStatus()) {
|
||||||
break;
|
// case 0:
|
||||||
default:
|
// troubleCode.setTroublePosition("194");
|
||||||
switch (msgData.getChargingEnergyStorageStatus()) {
|
// troubleCode.setProcessingState(0);
|
||||||
case 0:
|
// break;
|
||||||
troubleCode.setTroublePosition("194");
|
// default:
|
||||||
troubleCode.setProcessingState(0);
|
// switch (msgData.getDriveMotorStatus()) {
|
||||||
break;
|
// case 0:
|
||||||
default:
|
// troubleCode.setTroublePosition("195");
|
||||||
switch (msgData.getDriveMotorStatus()) {
|
// troubleCode.setProcessingState(0);
|
||||||
case 0:
|
// break;
|
||||||
troubleCode.setTroublePosition("195");
|
// default:
|
||||||
troubleCode.setProcessingState(0);
|
// switch (msgData.getPositionStatus()) {
|
||||||
break;
|
// case 0:
|
||||||
default:
|
// troubleCode.setTroublePosition("196");
|
||||||
switch (msgData.getPositionStatus()) {
|
// troubleCode.setProcessingState(0);
|
||||||
case 0:
|
// break;
|
||||||
troubleCode.setTroublePosition("196");
|
// default:
|
||||||
troubleCode.setProcessingState(0);
|
// switch (msgData.getEasStatus()) {
|
||||||
break;
|
// case 0:
|
||||||
default:
|
// troubleCode.setTroublePosition("197");
|
||||||
switch (msgData.getEasStatus()) {
|
// troubleCode.setProcessingState(0);
|
||||||
case 0:
|
// break;
|
||||||
troubleCode.setTroublePosition("197");
|
// default:
|
||||||
troubleCode.setProcessingState(0);
|
// switch (msgData.getPtcStatus()) {
|
||||||
break;
|
// case 0:
|
||||||
default:
|
// troubleCode.setTroublePosition("198");
|
||||||
switch (msgData.getPtcStatus()) {
|
// troubleCode.setProcessingState(0);
|
||||||
case 0:
|
// break;
|
||||||
troubleCode.setTroublePosition("198");
|
// default:
|
||||||
troubleCode.setProcessingState(0);
|
// switch (msgData.getEpsStatus()) {
|
||||||
break;
|
// case 0:
|
||||||
default:
|
// troubleCode.setTroublePosition("199");
|
||||||
switch (msgData.getEpsStatus()) {
|
// troubleCode.setProcessingState(0);
|
||||||
case 0:
|
// break;
|
||||||
troubleCode.setTroublePosition("199");
|
// default:
|
||||||
troubleCode.setProcessingState(0);
|
// switch (msgData.getAbsStatus()) {
|
||||||
break;
|
// case 0:
|
||||||
default:
|
// troubleCode.setTroublePosition("200");
|
||||||
switch (msgData.getAbsStatus()) {
|
// troubleCode.setProcessingState(0);
|
||||||
case 0:
|
// break;
|
||||||
troubleCode.setTroublePosition("200");
|
// default:
|
||||||
troubleCode.setProcessingState(0);
|
// switch (msgData.getMcuStatus()) {
|
||||||
break;
|
// case 0:
|
||||||
default:
|
// troubleCode.setTroublePosition("201");
|
||||||
switch (msgData.getMcuStatus()) {
|
// troubleCode.setProcessingState(0);
|
||||||
case 0:
|
// break;
|
||||||
troubleCode.setTroublePosition("201");
|
// default:
|
||||||
troubleCode.setProcessingState(0);
|
// switch (msgData.getHeatingStatus()) {
|
||||||
break;
|
// case 0:
|
||||||
default:
|
// troubleCode.setTroublePosition("202");
|
||||||
switch (msgData.getHeatingStatus()) {
|
// troubleCode.setProcessingState(0);
|
||||||
case 0:
|
// break;
|
||||||
troubleCode.setTroublePosition("202");
|
// default:
|
||||||
troubleCode.setProcessingState(0);
|
// switch (msgData.getBatteryStatus()) {
|
||||||
break;
|
// case 0:
|
||||||
default:
|
// troubleCode.setTroublePosition("203");
|
||||||
switch (msgData.getBatteryStatus()) {
|
// troubleCode.setProcessingState(0);
|
||||||
case 0:
|
// break;
|
||||||
troubleCode.setTroublePosition("203");
|
// default:
|
||||||
troubleCode.setProcessingState(0);
|
// switch (msgData.getBatteryInsulationStatus()) {
|
||||||
break;
|
// case 0:
|
||||||
default:
|
// troubleCode.setTroublePosition("204");
|
||||||
switch (msgData.getBatteryInsulationStatus()) {
|
// troubleCode.setProcessingState(0);
|
||||||
case 0:
|
// break;
|
||||||
troubleCode.setTroublePosition("204");
|
// default:
|
||||||
troubleCode.setProcessingState(0);
|
// switch (msgData.getDcdcStatus()) {
|
||||||
break;
|
// case 0:
|
||||||
default:
|
// troubleCode.setTroublePosition("205");
|
||||||
switch (msgData.getDcdcStatus()) {
|
// troubleCode.setProcessingState(0);
|
||||||
case 0:
|
// break;
|
||||||
troubleCode.setTroublePosition("205");
|
// default:
|
||||||
troubleCode.setProcessingState(0);
|
// switch (msgData.getChgStatus()) {
|
||||||
break;
|
// case 0:
|
||||||
default:
|
// troubleCode.setTroublePosition("206");
|
||||||
switch (msgData.getChgStatus()) {
|
// troubleCode.setProcessingState(0);
|
||||||
case 0:
|
// break;
|
||||||
troubleCode.setTroublePosition("206");
|
// default:
|
||||||
troubleCode.setProcessingState(0);
|
// // do nothing
|
||||||
break;
|
// break;
|
||||||
default:
|
// }
|
||||||
// do nothing
|
// break;
|
||||||
break;
|
// }
|
||||||
}
|
// break;
|
||||||
break;
|
// }
|
||||||
}
|
// break;
|
||||||
break;
|
// }
|
||||||
}
|
// break;
|
||||||
break;
|
// }
|
||||||
}
|
// break;
|
||||||
break;
|
// }
|
||||||
}
|
// break;
|
||||||
break;
|
// }
|
||||||
}
|
// break;
|
||||||
break;
|
// }
|
||||||
}
|
// break;
|
||||||
break;
|
// }
|
||||||
}
|
// break;
|
||||||
break;
|
// }
|
||||||
}
|
// break;
|
||||||
break;
|
// }
|
||||||
}
|
// break;
|
||||||
break;
|
// }
|
||||||
}
|
// break;
|
||||||
break;
|
// }
|
||||||
}
|
// break;
|
||||||
break;
|
// }
|
||||||
}
|
// break;
|
||||||
break;
|
// }
|
||||||
}
|
// break;
|
||||||
break;
|
// }
|
||||||
}
|
// break;
|
||||||
break;
|
// }
|
||||||
}
|
// remoteTroubleService.newFaultData(troubleCode);
|
||||||
break;
|
// });
|
||||||
}
|
// }
|
||||||
remoteTroubleService.newFaultData(troubleCode);
|
// long end = System.currentTimeMillis();
|
||||||
});
|
// log.info("日志队列:{},接收到的消息:{},消费完成,耗时:{}毫秒","couplet-code-queue", JSONObject.toJSONString(msgData), (end-start));
|
||||||
}
|
// } catch (Exception e) {
|
||||||
long end = System.currentTimeMillis();
|
// throw new RuntimeException(e);
|
||||||
log.info("日志队列:{},接收到的消息:{},消费完成,耗时:{}毫秒","couplet-code-queue", JSONObject.toJSONString(msgData), (end-start));
|
// }
|
||||||
} catch (Exception e) {
|
// }
|
||||||
throw new RuntimeException(e);
|
//}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -4,8 +4,6 @@ import com.couplet.analyze.msg.domain.CoupletMsgData;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author: LiJiaYao
|
* @Author: LiJiaYao
|
||||||
* @Date: 2024/4/2
|
* @Date: 2024/4/2
|
||||||
|
@ -23,6 +21,6 @@ public interface IncidentMapper {
|
||||||
* 查询是否存在该vin
|
* 查询是否存在该vin
|
||||||
*/
|
*/
|
||||||
// CoupletMsgData queryByIncident(RealTimeDataRequest realTimeDataRequest);
|
// CoupletMsgData queryByIncident(RealTimeDataRequest realTimeDataRequest);
|
||||||
CoupletMsgData queryByIncident(@Param("vin") String vin, @Param("createTime") Date createTime);
|
CoupletMsgData queryByIncident(String vin);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package com.couplet.analyze.msg.model;
|
package com.couplet.analyze.msg.model;
|
||||||
|
|
||||||
|
import com.couplet.analyze.common.contents.AnalyzeEventContents;
|
||||||
|
import com.couplet.analyze.common.event.AnalyzeEventCache;
|
||||||
import com.couplet.analyze.msg.domain.CoupletMsgData;
|
import com.couplet.analyze.msg.domain.CoupletMsgData;
|
||||||
import com.couplet.analyze.msg.service.IncidentService;
|
import com.couplet.analyze.msg.service.IncidentService;
|
||||||
import com.couplet.common.core.exception.vehicle.VehicleException;
|
import com.couplet.common.core.exception.vehicle.VehicleException;
|
||||||
|
@ -36,7 +38,6 @@ public class ModelsKafkaMessage {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private AnalyzeEventCache analyzeEventCache;
|
private AnalyzeEventCache analyzeEventCache;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 消费者配置
|
* 消费者配置
|
||||||
*
|
*
|
||||||
|
@ -52,9 +53,7 @@ public class ModelsKafkaMessage {
|
||||||
|
|
||||||
//创建消费者
|
//创建消费者
|
||||||
KafkaConsumer<String, String> consumer = new KafkaConsumer<>(props);
|
KafkaConsumer<String, String> consumer = new KafkaConsumer<>(props);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
//订阅主题
|
//订阅主题
|
||||||
consumer.subscribe(Collections.singletonList(TOPIC_NAME));
|
consumer.subscribe(Collections.singletonList(TOPIC_NAME));
|
||||||
//持续消费消息
|
//持续消费消息
|
||||||
|
|
|
@ -13,14 +13,16 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author: LiJiaYao
|
* @Author: LiJiaYao
|
||||||
* @Date: 2024/4/2
|
* @Date: 2024/4/2
|
||||||
* @Description: 电子围栏事件服务实现类
|
* @Description: 电子围栏事件服务实现类
|
||||||
*/
|
*/
|
||||||
@Service("electronic-fence")
|
@Service("electronic_fence")
|
||||||
@Log4j2
|
@Log4j2
|
||||||
public class ElectronicFenceServiceImpl implements IncidentService {
|
public class ElectronicFenceServiceImpl implements IncidentService {
|
||||||
|
|
||||||
|
@ -39,56 +41,44 @@ public class ElectronicFenceServiceImpl implements IncidentService {
|
||||||
|
|
||||||
log.info("电子围栏事件开始.......");
|
log.info("电子围栏事件开始.......");
|
||||||
|
|
||||||
String fenceKey="fence";
|
String fenceKey = "车辆vin和电子围栏:" + coupletMsgData.getVin();
|
||||||
|
|
||||||
// redisService.getCacheSet()
|
|
||||||
ArrayList<Fence> fences = new ArrayList<>();
|
|
||||||
if (redisService.hasKey(fenceKey)) {
|
if (redisService.hasKey(fenceKey)) {
|
||||||
|
Set<Fence> cacheSet = redisService.getCacheSet(fenceKey);
|
||||||
log.info("电子围栏事件redis存在.......");
|
log.info("电子围栏事件redis存在.......");
|
||||||
// redisService.getCacheObject();
|
|
||||||
// for (String s : fence) {
|
|
||||||
// Fence parseObject = JSON.parseObject(s, Fence.class);
|
|
||||||
// fences.add(parseObject);
|
|
||||||
// }
|
|
||||||
// jingdu;
|
// jingdu;
|
||||||
// longitude;
|
// longitude;
|
||||||
// weidu;
|
// weidu;
|
||||||
// latitude;
|
// latitude;
|
||||||
for (Fence data : fences) {
|
for (Fence fence : cacheSet) {
|
||||||
|
String fenceLongitudeLatitude = fence.getFenceLongitudeLatitude();
|
||||||
String fenceLongitudeLatitude = data.getFenceLongitudeLatitude();
|
|
||||||
/**
|
/**
|
||||||
* 先通过;号切割
|
* 先通过;后切割
|
||||||
*/
|
*/
|
||||||
String[] split = fenceLongitudeLatitude.split(";");
|
String[] split = fenceLongitudeLatitude.split(";");
|
||||||
for (String s : split) {
|
for (String s : split) {
|
||||||
|
|
||||||
String[] strings = s.split(",");
|
String[] strings = s.split(",");
|
||||||
if (strings.length == 2){
|
if (strings.length == 2) {
|
||||||
// 经度
|
// 经度
|
||||||
Double trim = Double.valueOf(strings[0].trim());
|
Double trim = Double.valueOf(strings[0].trim());
|
||||||
// 纬度
|
// 纬度
|
||||||
Double trim1 = Double.valueOf(strings[1].trim());
|
Double trim1 = Double.valueOf(strings[1].trim());
|
||||||
boolean a = trim <= Double.valueOf(coupletMsgData.getLongitude());
|
boolean a = trim <= Double.valueOf(coupletMsgData.getLongitude());
|
||||||
boolean b = trim1 <= Double.valueOf(coupletMsgData.getLatitude());
|
boolean b = trim1 <= Double.valueOf(coupletMsgData.getLatitude());
|
||||||
if (a && b){
|
if (a && b) {
|
||||||
log.info("电子围栏报警啦!!!!您的车驶出范围啦!!!");
|
log.info("电子围栏报警啦!!!!您的车驶出范围啦!!!");
|
||||||
}else {
|
} else {
|
||||||
log.info("电子围栏报警啦!!!!正常啦!!!");
|
log.info("电子围栏报警啦!!!!正常啦!!!");
|
||||||
}
|
}
|
||||||
log.info("经度是:"+trim);
|
log.info("经度是:" + trim);
|
||||||
log.info("纬度是:"+trim1);
|
log.info("纬度是:" + trim1);
|
||||||
}else {
|
} else {
|
||||||
throw new RuntimeException("电子围栏经纬度格式错误"+strings);
|
throw new RuntimeException("电子围栏经纬度格式错误" + strings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// log.info("更改的电子围栏内容是:"+fence);
|
|
||||||
log.info("电子围栏事件结束.......");
|
log.info("电子围栏事件结束.......");
|
||||||
}
|
}
|
||||||
|
|
||||||
log.info("电子围栏事件结束.......");
|
log.info("电子围栏事件结束.......");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -4,23 +4,21 @@ import com.couplet.analyze.msg.domain.CoupletMsgData;
|
||||||
import com.couplet.analyze.msg.mapper.IncidentMapper;
|
import com.couplet.analyze.msg.mapper.IncidentMapper;
|
||||||
import com.couplet.analyze.msg.service.IncidentService;
|
import com.couplet.analyze.msg.service.IncidentService;
|
||||||
import com.couplet.analyze.msg.service.impl.realTimeData.RealTimeJudge;
|
import com.couplet.analyze.msg.service.impl.realTimeData.RealTimeJudge;
|
||||||
import com.couplet.common.core.utils.StringUtils;
|
|
||||||
import com.couplet.common.domain.request.RealTimeDataRequest;
|
import com.couplet.common.domain.request.RealTimeDataRequest;
|
||||||
import com.couplet.common.redis.service.RedisService;
|
import com.couplet.common.redis.service.RedisService;
|
||||||
import com.couplet.remote.RemoteRealTimeService;
|
import com.couplet.remote.RemoteRealTimeService;
|
||||||
import lombok.extern.log4j.Log4j2;
|
import lombok.extern.log4j.Log4j2;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author: LiJiaYao
|
* @Author: LiJiaYao
|
||||||
* @Date: 2024/4/2
|
* @Date: 2024/4/2
|
||||||
* @Description: 实时数据事件
|
* @Description: 实时数据事件
|
||||||
*/
|
*/
|
||||||
@Service("real-time-data")
|
@Service("real_time_data")
|
||||||
@Log4j2
|
@Log4j2
|
||||||
public class RealTimeDataServiceImpl implements IncidentService {
|
public class RealTimeDataServiceImpl implements IncidentService {
|
||||||
|
|
||||||
|
@ -32,8 +30,6 @@ public class RealTimeDataServiceImpl implements IncidentService {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private RedisService redisService;
|
private RedisService redisService;
|
||||||
@Autowired
|
|
||||||
private RemoteRealTimeService remoteRealTimeService;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 实时数据事件
|
* 实时数据事件
|
||||||
|
@ -46,17 +42,20 @@ public class RealTimeDataServiceImpl implements IncidentService {
|
||||||
log.info("实时数据事件开始.....");
|
log.info("实时数据事件开始.....");
|
||||||
|
|
||||||
RealTimeDataRequest cacheObject = redisService.getCacheObject("vin:" + coupletMsgData.getVin());
|
RealTimeDataRequest cacheObject = redisService.getCacheObject("vin:" + coupletMsgData.getVin());
|
||||||
|
//判断是否有缓存数据
|
||||||
if (RealTimeJudge.addRealTime(cacheObject)) {
|
if (RealTimeJudge.isJudge(coupletMsgData.getVin())) {
|
||||||
log.info("[{}]有缓存数据,值为:[{}],且缓存数据与实时数据一致,开始传输实时数据", coupletMsgData.getVin(), cacheObject);
|
|
||||||
CoupletMsgData query = incidentMapper.queryByIncident(coupletMsgData.getVin(), new Date());
|
|
||||||
redisService.setCacheObject("vin:" + cacheObject.getVin(), query);
|
|
||||||
} else {
|
|
||||||
log.info("[{}]有缓存数据,值为:[{}],且缓存数据与实时数据不一致,开始传输实时数据", coupletMsgData.getVin(), cacheObject);
|
|
||||||
}
|
|
||||||
if (RealTimeJudge.isJudge(coupletMsgData.getVin())) {
|
|
||||||
log.info("有实时数据,值为:[{}]开始传输实时数据", coupletMsgData.getVin());
|
log.info("有实时数据,值为:[{}]开始传输实时数据", coupletMsgData.getVin());
|
||||||
|
//判断数据是否一致,
|
||||||
|
if (RealTimeJudge.addRealTime(cacheObject)) {
|
||||||
|
log.info("[{}]有缓存数据,值为:[{}],且缓存数据与实时数据一致,开始传输实时数据", coupletMsgData.getVin(), cacheObject);
|
||||||
|
CoupletMsgData query = incidentMapper.queryByIncident(coupletMsgData.getVin());
|
||||||
|
redisService.setCacheObject("vin:query:" + cacheObject.getVin(), query);
|
||||||
|
redisService.expire("vin:"+cacheObject.getVin(),10, TimeUnit.MINUTES);
|
||||||
|
} else {
|
||||||
|
log.info("[{}]有缓存数据,值为:[{}],且缓存数据与实时数据不一致,开始传输实时数据", coupletMsgData.getVin(), cacheObject);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
log.info("[{}]开始传输实时数据", coupletMsgData.getVin());
|
log.info("[{}]开始传输实时数据", coupletMsgData.getVin());
|
||||||
|
|
||||||
log.info("实时数据事件结束.....");
|
log.info("实时数据事件结束.....");
|
||||||
|
|
|
@ -12,7 +12,7 @@ import org.springframework.stereotype.Service;
|
||||||
* @Date: 2024/4/2
|
* @Date: 2024/4/2
|
||||||
* @Description: 事件存储服务
|
* @Description: 事件存储服务
|
||||||
*/
|
*/
|
||||||
@Service("stored-event")
|
@Service("stored_event")
|
||||||
@Log4j2
|
@Log4j2
|
||||||
public class StoredEventServiceImpl implements IncidentService {
|
public class StoredEventServiceImpl implements IncidentService {
|
||||||
@Autowired
|
@Autowired
|
||||||
|
|
|
@ -72,7 +72,11 @@
|
||||||
</insert>
|
</insert>
|
||||||
<select id="queryByIncident" resultType="com.couplet.analyze.msg.domain.CoupletMsgData"
|
<select id="queryByIncident" resultType="com.couplet.analyze.msg.domain.CoupletMsgData"
|
||||||
parameterType="com.couplet.common.domain.request.RealTimeDataRequest">
|
parameterType="com.couplet.common.domain.request.RealTimeDataRequest">
|
||||||
SELECT * FROM couplet_msg_data WHERE vin=#{vin} and create_time = #{createTime}
|
SELECT *
|
||||||
|
FROM couplet_msg_data
|
||||||
|
WHERE vin = #{vin}
|
||||||
|
ORDER BY create_time DESC
|
||||||
|
LIMIT 1;
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -101,6 +101,10 @@
|
||||||
<groupId>com.couplet</groupId>
|
<groupId>com.couplet</groupId>
|
||||||
<artifactId>couplet-modules-mq</artifactId>
|
<artifactId>couplet-modules-mq</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.couplet</groupId>
|
||||||
|
<artifactId>couplet-common-event</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package com.couplet.business.server.service.impl;
|
package com.couplet.business.server.service.impl;
|
||||||
|
|
||||||
|
import afu.org.checkerframework.checker.units.qual.A;
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.couplet.analyze.common.event.AnalyzeEventCache;
|
||||||
import com.couplet.business.server.mapper.VehicleDetectionMapper;
|
import com.couplet.business.server.mapper.VehicleDetectionMapper;
|
||||||
import com.couplet.business.server.service.VehicleDetectionService;
|
import com.couplet.business.server.service.VehicleDetectionService;
|
||||||
import com.couplet.business.server.service.VehicleManageService;
|
import com.couplet.business.server.service.VehicleManageService;
|
||||||
|
@ -17,6 +19,7 @@ import org.springframework.stereotype.Service;
|
||||||
import springfox.documentation.spring.web.json.Json;
|
import springfox.documentation.spring.web.json.Json;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author fufanrui
|
* @author fufanrui
|
||||||
|
@ -31,10 +34,14 @@ public class VehicleDetectionServiceImpl implements VehicleDetectionService{
|
||||||
private VehicleDetectionMapper vehicleDetectionMapper;
|
private VehicleDetectionMapper vehicleDetectionMapper;
|
||||||
@Autowired
|
@Autowired
|
||||||
private RedisService redisService;
|
private RedisService redisService;
|
||||||
|
@Autowired
|
||||||
|
private AnalyzeEventCache analyzeEventCache;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Vehicle> detectionList() {
|
public List<Vehicle> detectionList() {
|
||||||
return vehicleDetectionMapper.detectionList();
|
List<Vehicle> vehicles = vehicleDetectionMapper.detectionList();
|
||||||
|
|
||||||
|
return vehicles;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -43,8 +50,9 @@ public class VehicleDetectionServiceImpl implements VehicleDetectionService{
|
||||||
Long userId = SecurityUtils.getUserId();
|
Long userId = SecurityUtils.getUserId();
|
||||||
realTimeDataRequest.setVin(vin);
|
realTimeDataRequest.setVin(vin);
|
||||||
realTimeDataRequest.setUserId(userId);
|
realTimeDataRequest.setUserId(userId);
|
||||||
|
// analyzeEventCache.queryEvent("查询实时数据"+vin,realTimeDataRequest);
|
||||||
|
// redisService.expire("查询实时数据"+vin,4,TimeUnit.MINUTES);
|
||||||
redisService.setVinAndUserId(realTimeDataRequest);
|
redisService.setVinAndUserId(realTimeDataRequest);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -54,7 +54,7 @@ public class VehicleManageServiceImpl implements VehicleManageService {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @param middle:
|
* @param middle:
|
||||||
* @return Result
|
* @return Result
|
||||||
* @author 付凡芮
|
* @author 付凡芮
|
||||||
* @description 添加车辆
|
* @description 添加车辆
|
||||||
* @date
|
* @date
|
||||||
|
|
|
@ -16,11 +16,9 @@ spring:
|
||||||
discovery:
|
discovery:
|
||||||
# 服务注册地址
|
# 服务注册地址
|
||||||
server-addr: 121.89.211.230:8848
|
server-addr: 121.89.211.230:8848
|
||||||
namespace: a439ce3f-2c42-4b4c-9c4d-c8db49933c15
|
|
||||||
config:
|
config:
|
||||||
# 配置中心地址
|
# 配置中心地址
|
||||||
server-addr: 121.89.211.230:8848
|
server-addr: 121.89.211.230:8848
|
||||||
namespace: a439ce3f-2c42-4b4c-9c4d-c8db49933c15
|
|
||||||
# 配置文件格式
|
# 配置文件格式
|
||||||
file-extension: yml
|
file-extension: yml
|
||||||
# 共享配置
|
# 共享配置
|
||||||
|
|
|
@ -15,7 +15,6 @@ spring:
|
||||||
discovery:
|
discovery:
|
||||||
# 服务注册地址
|
# 服务注册地址
|
||||||
server-addr: 121.89.211.230:8848
|
server-addr: 121.89.211.230:8848
|
||||||
namespace: a439ce3f-2c42-4b4c-9c4d-c8db49933c15
|
|
||||||
config:
|
config:
|
||||||
# 配置中心地址
|
# 配置中心地址
|
||||||
server-addr: 121.89.211.230:8848
|
server-addr: 121.89.211.230:8848
|
||||||
|
@ -24,7 +23,6 @@ spring:
|
||||||
# 共享配置
|
# 共享配置
|
||||||
shared-configs:
|
shared-configs:
|
||||||
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||||
namespace: a439ce3f-2c42-4b4c-9c4d-c8db49933c15
|
|
||||||
main:
|
main:
|
||||||
allow-bean-definition-overriding: true
|
allow-bean-definition-overriding: true
|
||||||
logging:
|
logging:
|
||||||
|
|
Loading…
Reference in New Issue