Compare commits

...

7 Commits

Author SHA1 Message Date
ffr e270770029 fufanruiCommit 2024-04-08 10:55:33 +08:00
lijiayao 366d97e8d2 feat: 电子围栏报警 2024-04-08 10:02:19 +08:00
lijiayao 4ad3cfbe8e Merge branch 'server_five_dongxiaodong' of https://gitea.qinmian.online/five-groups/five-groups-couplet into server_five 2024-04-08 10:01:23 +08:00
lijiayao d0e00acaeb Merge branch 'server_five_fufanrui' of https://gitea.qinmian.online/five-groups/five-groups-couplet into server_five 2024-04-08 10:00:28 +08:00
lijiayao 325b13df58 feat: 电子围栏报警 2024-04-08 10:00:10 +08:00
dongxiaodong f104a50c27 Merge remote-tracking branch 'origin/server_five' into server_five_dongxiaodong
# Conflicts:
#	couplet-modules/couplet-modules-onLine/src/main/resources/bootstrap.yml
2024-04-08 09:21:25 +08:00
dongxiaodong 0eba9f5cfe 存储数据 2024-04-08 09:15:52 +08:00
15 changed files with 260 additions and 71 deletions

View File

@ -17,11 +17,9 @@ spring:
discovery:
# 服务注册地址
server-addr: 121.89.211.230:8848
namespace: 172469
config:
# 配置中心地址
server-addr: 121.89.211.230:8848
namespace: 172469
# 配置文件格式
file-extension: yml
# 共享配置

View File

@ -27,6 +27,19 @@ public class RedisService {
return redisTemplate.opsForList().range("coupletMsgData", 0, -1);
}
// ... 其他已有方法 ...
/**
* truefalse
*
* @param setKey
* @param value
* @return truefalse
*/
public boolean addToSetIfNotExists(String setKey, String value) {
return redisTemplate.opsForSet().add(setKey, value) == 1;
}
/**
* IntegerString
@ -267,4 +280,10 @@ public class RedisService {
String key = "vin:"+realTimeDataRequest.getVin()+"userId:"+realTimeDataRequest.getUserId();
redisTemplate.opsForValue().set(key, realTimeDataRequest);
}
public void stopViewingData(Long userId,String vin) {
String key = "vin:"+vin+"userId:"+userId;
redisTemplate.delete(key);
}
}

View File

@ -15,11 +15,9 @@ spring:
discovery:
# 服务注册地址
server-addr: 121.89.211.230:8848
namespace: 172469
config:
# 配置中心地址
server-addr: 121.89.211.230:8848
namespace: 172469
# 配置文件格式
file-extension: yml
# 共享配置

View File

@ -0,0 +1,150 @@
package com.couplet.analyze.msg.consumer;
import com.alibaba.fastjson.JSONObject;
import com.couplet.analyze.msg.domain.CoupletMsgData;
import com.couplet.analyze.msg.utils.MsgUtils;
import com.couplet.common.domain.CoupletTroubleCode;
import com.couplet.common.redis.service.RedisService;
import com.couplet.remote.RemoteTroubleService;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.amqp.core.Message;
import org.springframework.stereotype.Component;
import java.util.Date;
import java.util.concurrent.CompletableFuture;
/**
* @author DongXiaoDong
* @version 1.0
* @date 2024/4/6 15:37
* @description
*/
@Component
@Slf4j
public class CodeConsumer {
// @Autowired
// private RedisTemplate<String, String> redisTemplate;
@Autowired
private RedisService redisService;
@Autowired
private RemoteTroubleService remoteTroubleService;
@RabbitListener(queuesToDeclare = {@Queue("couplet-code-queue")})
public void sendLogQueueConsumer(Message message, CoupletMsgData msgData, Channel channel) {
log.info("日志队列:{},接收到的消息:{},开始消费...","couplet-code-queue", JSONObject.toJSONString(msgData));
long start = System.currentTimeMillis();
String messageId = message.getMessageProperties().getMessageId();
try {
boolean addToSetIfNotExists = redisService.addToSetIfNotExists("couplet-code-queue", messageId);
if (addToSetIfNotExists) {
//异步保存记录
CompletableFuture.runAsync(() -> {
CoupletTroubleCode troubleCode = new CoupletTroubleCode();
troubleCode.setTroubleStartTime(new Date());
troubleCode.setTroubleVin(msgData.getVin());
// 随机生成故障码
String faultCode = MsgUtils.generateGTA();
troubleCode.setTroubleCode(faultCode);
// 检查车辆状态若为0则设置故障位置为"190"
if(msgData.getVehicleStatus() == 0) {
troubleCode.setTroublePosition("190");
}
// 检查充电状态若为0则设置故障位置为"191"
if (msgData.getChargingStatus() == 0) {
troubleCode.setTroublePosition("191");
}
// 检查运行状态若为0则设置故障位置为"192"
if (msgData.getOperatingStatus() == 0) {
troubleCode.setTroublePosition("192");
}
// 检查电池荷电状态SOC, 若为0则设置故障位置为"193"
if (msgData.getSocStatus() == 0) {
troubleCode.setTroublePosition("193");
}
// 检查充电能源存储状态若为0则设置故障位置为"194"
if (msgData.getChargingEnergyStorageStatus() == 0) {
troubleCode.setTroublePosition("194");
}
// 检查驱动电机状态若为0则设置故障位置为"195"
if (msgData.getDriveMotorStatus() == 0) {
troubleCode.setTroublePosition("195");
}
// 检查定位状态若为0则设置故障位置为"196"
if (msgData.getPositionStatus() == 0) {
troubleCode.setTroublePosition("196");
}
// 检查电子驻车系统EAS状态若为0则设置故障位置为"197"
if (msgData.getEasStatus() == 0) {
troubleCode.setTroublePosition("197");
}
// 检查PTC正温度系数热敏电阻状态若为0则设置故障位置为"198"
if (msgData.getPtcStatus() == 0) {
troubleCode.setTroublePosition("198");
}
// 检查电动助力转向系统EPS状态若为0则设置故障位置为"199"
if (msgData.getEpsStatus() == 0) {
troubleCode.setTroublePosition("199");
}
// 检查防抱死制动系统ABS状态若为0则设置故障位置为"200"
if (msgData.getAbsStatus() == 0) {
troubleCode.setTroublePosition("200");
}
// 检查主控制器MCU状态若为0则设置故障位置为"201"
if (msgData.getMcuStatus() == 0) {
troubleCode.setTroublePosition("201");
}
// 检查加热状态若为0则设置故障位置为"202"
if (msgData.getHeatingStatus() == 0) {
troubleCode.setTroublePosition("202");
}
// 检查电池状态若为0则设置故障位置为"203"
if (msgData.getBatteryStatus() == 0) {
troubleCode.setTroublePosition("203");
}
// 检查电池绝缘状态若为0则设置故障位置为"204"
if (msgData.getBatteryInsulationStatus() == 0) {
troubleCode.setTroublePosition("204");
}
// 检查直流-直流转换器DC/DC状态若为0则设置故障位置为"205"
if (msgData.getDcdcStatus() == 0) {
troubleCode.setTroublePosition("205");
}
// 检查充电机CHG状态若为0则设置故障位置为"206"
if (msgData.getChgStatus() == 0) {
troubleCode.setTroublePosition("206");
}
remoteTroubleService.newFaultData(troubleCode);
});
}
long end = System.currentTimeMillis();
log.info("日志队列:{},接收到的消息:{},消费完成,耗时:{}毫秒","couplet-code-queue", JSONObject.toJSONString(msgData), (end-start));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}

View File

@ -1,16 +0,0 @@
package com.couplet.analyze.msg.consumer;
import org.springframework.kafka.annotation.KafkaListener;
/**
* @author DongXiaoDong
* @version 1.0
* @date 2024/4/6 15:37
* @description
*/
public class KafkaConsumer {
@KafkaListener(topics = "test", groupId = "group", properties = {"bootstrap.servers = 39.103.133.136:9092"})
public void getMessage(String msg) {
System.out.println("接收到消息:" + msg);
}
}

View File

@ -1,5 +1,6 @@
package com.couplet.analyze.msg.model;
import com.couplet.analyze.common.contents.AnalyzeEventContents;
import com.couplet.analyze.msg.domain.CoupletMsgData;
import com.couplet.analyze.msg.service.IncidentService;
import com.couplet.common.core.exception.vehicle.VehicleException;
@ -8,15 +9,13 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerConfig;
import org.apache.kafka.clients.consumer.ConsumerRecords;
import org.apache.kafka.clients.consumer.KafkaConsumer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Properties;
import java.util.*;
import static com.couplet.analyze.msg.utils.MsgUtils.hexToString;
import static com.couplet.analyze.msg.utils.MsgUtils.sendMsg;
@ -43,12 +42,15 @@ public class ModelsKafkaMessage {
add("stored-event");
}
};
// @Autowired
// private RabbitTemplate rabbitTemplate;
/**
*
* @return
*/
@Scheduled(fixedDelay = 50)
private static void consumerMessages() {
public void consumerMessages() {
Properties props = new Properties();
props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, BOOTSTRAP_SERVERS);
props.put(ConsumerConfig.GROUP_ID_CONFIG, "my-consumer-group");
@ -76,6 +78,11 @@ public class ModelsKafkaMessage {
IncidentService incidentService = SpringUtils.getBean(string);
incidentService.incident(msgData);
}
//发送消息
// rabbitTemplate.convertAndSend("couplet-code-queue",msgData,message -> {
// message.getMessageProperties().setMessageId(UUID.randomUUID().toString());
// return message;
// });
try {
sleep(100);

View File

@ -41,6 +41,7 @@ public class ElectronicFenceServiceImpl implements IncidentService {
String fenceKey="fence";
// redisService.getCacheSet()
ArrayList<Fence> fences = new ArrayList<>();
if (redisService.hasKey(fenceKey)) {
log.info("电子围栏事件redis存在.......");

View File

@ -15,6 +15,7 @@ spring:
discovery:
# 服务注册地址
server-addr: 121.89.211.230:8848
namespace: a439ce3f-2c42-4b4c-9c4d-c8db49933c15
config:
# 配置中心地址
server-addr: 121.89.211.230:8848
@ -23,6 +24,7 @@ spring:
# 共享配置
shared-configs:
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
namespace: a439ce3f-2c42-4b4c-9c4d-c8db49933c15
main:
allow-bean-definition-overriding: true
rabbitmq:

View File

@ -25,21 +25,21 @@ public class ParsingMsg {
String hexStringWithoutSpaces = substring.replaceAll("\\s+", "");
String asciiString = hexToString(hexStringWithoutSpaces);
System.out.println("16进制解析后的数据"+asciiString);
// //截取前17位
// String substring1 = asciiString.substring(0, 17);
// System.out.println("VIN"+substring1);
// String substring2 = asciiString.substring(17, 30);
// System.out.println("时间戳:"+substring2);
// String substring3 = asciiString.substring(30, 40);
// System.out.println("经度:" +substring3);
// String substring4 = asciiString.substring(41, 50);
// System.out.println("纬度:"+ substring4);
// String substring5 = asciiString.substring(51, 56);
// System.out.println("车速:"+ substring5);
// String substring6 = asciiString.substring(57, 67);
// System.out.println("总里程:"+ substring6);
// String substring7 = asciiString.substring(68, 73);
// System.out.println("总电压:"+ substring7);
//截取前17位
String substring1 = asciiString.substring(0, 17);
System.out.println("VIN"+substring1);
String substring2 = asciiString.substring(17, 30);
System.out.println("时间戳:"+substring2);
String substring3 = asciiString.substring(30, 40);
System.out.println("经度:" +substring3);
String substring4 = asciiString.substring(41, 50);
System.out.println("纬度:"+ substring4);
String substring5 = asciiString.substring(51, 56);
System.out.println("车速:"+ substring5);
String substring6 = asciiString.substring(57, 67);
System.out.println("总里程:"+ substring6);
String substring7 = asciiString.substring(68, 73);
System.out.println("总电压:"+ substring7);
String pattern = "(.{17})(.{10})(.{9})(.{8})(.{2})";
Pattern compile = Pattern.compile(pattern);
Matcher matcher = compile.matcher(asciiString);

View File

@ -10,6 +10,7 @@ import com.couplet.common.security.utils.SecurityUtils;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@ -26,8 +27,6 @@ import java.util.Objects;
@RequestMapping("detection")
public class VehicleDetectionController {
@Autowired
private VehicleDetectionService vehicleDetectionService;
@Autowired
@ -50,7 +49,7 @@ public class VehicleDetectionController {
/*
* @param vin:
* @return Result<List<Vehicle>>
* @return Result<List<Vehicle>>
* @author
* @description vin
* @date
@ -60,8 +59,13 @@ public class VehicleDetectionController {
vehicleDetectionService.monitorinData(vin);
}
/*
* @param :
* @return Result<List<CoupletVehicleData>>
* @author
* @description
* @date
*/
@PostMapping("realData")
public Result<List<CoupletVehicleData>> realData(){
List<CoupletVehicleData> list = redisService.getList();
@ -69,4 +73,16 @@ public class VehicleDetectionController {
return success;
}
/*
* @param vin:
* @return void
* @author
* @description
* @date
*/
@PostMapping("stopViewingData/{vin}")
public void stopViewingData(@PathVariable String vin){
vehicleDetectionService.stopViewingData(vin);
}
}

View File

@ -10,4 +10,7 @@ public interface VehicleDetectionService {
List<Vehicle> detectionList();
void monitorinData(String vin);
void stopViewingData(String vin);
}

View File

@ -47,4 +47,10 @@ public class VehicleDetectionServiceImpl implements VehicleDetectionService{
}
@Override
public void stopViewingData(String vin) {
Long userId = SecurityUtils.getUserId();
redisService.stopViewingData(userId,vin);
}
}

View File

@ -130,15 +130,15 @@ public class RabbitMQConfig implements RabbitTemplate.ConfirmCallback, RabbitTem
* @Return: RabbitTemplate
**/
@Primary
@Bean
public RabbitTemplate rabbitTemplate(ConnectionFactory connectionFactory) {
RabbitTemplate rabbitTempalte = new RabbitTemplate(connectionFactory);
this.rabbitTemplate = rabbitTempalte;
rabbitTempalte.setMessageConverter(messageConverter());
rabbitTempalte();
return rabbitTempalte;
}
// @Bean
// public RabbitTemplate rabbitTemplate(ConnectionFactory connectionFactory) {
// RabbitTemplate rabbitTempalte = new RabbitTemplate(connectionFactory);
// this.rabbitTemplate = rabbitTempalte;
// rabbitTempalte.setMessageConverter(messageConverter());
// rabbitTempalte();
//
// return rabbitTempalte;
// }
/*
* @Author: LiuYunHu
@ -147,10 +147,10 @@ public class RabbitMQConfig implements RabbitTemplate.ConfirmCallback, RabbitTem
* @Param: []
* @Return: void
**/
public void rabbitTempalte() {
rabbitTemplate.setConfirmCallback(this);
rabbitTemplate.setReturnsCallback(this);
}
// public void rabbitTempalte() {
// rabbitTemplate.setConfirmCallback(this);
// rabbitTemplate.setReturnsCallback(this);
// }
/*
* @Author: LiuYunHu
@ -188,14 +188,14 @@ public class RabbitMQConfig implements RabbitTemplate.ConfirmCallback, RabbitTem
* @Param: ack
* @Param: s
**/
@Override
public void confirm(CorrelationData correlationData, boolean ack, String s) {
if (ack) {
log.info("{}消息到达交换机", correlationData.getId());
} else {
log.error("{}消息丢失", correlationData.getId());
}
}
// @Override
// public void confirm(CorrelationData correlationData, boolean ack, String s) {
// if (ack) {
// log.info("{}消息到达交换机", correlationData.getId());
// } else {
// log.error("{}消息丢失", correlationData.getId());
// }
// }
/*
* @Author: LiuYunHu
@ -209,4 +209,9 @@ public class RabbitMQConfig implements RabbitTemplate.ConfirmCallback, RabbitTem
public void returnedMessage(ReturnedMessage returnedMessage) {
log.error("{}消息未到达队列", returnedMessage.getMessage().getMessageProperties().getMessageId());
}
@Override
public void confirm(CorrelationData correlationData, boolean b, String s) {
}
}

View File

@ -15,6 +15,7 @@ spring:
discovery:
# 服务注册地址
server-addr: 121.89.211.230:8848
namespace: a439ce3f-2c42-4b4c-9c4d-c8db49933c15
config:
# 配置中心地址
server-addr: 121.89.211.230:8848
@ -23,6 +24,7 @@ spring:
# 共享配置
shared-configs:
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
namespace: a439ce3f-2c42-4b4c-9c4d-c8db49933c15
main:
allow-bean-definition-overriding: true
logging:
@ -33,10 +35,10 @@ logging:
mqtt:
server:
broker: tcp://115.159.47.13:1883
# broker: mqtt://115.159.47.13:1883
# broker: mqtt://115.159.47.13:1883
username:
password:
clientId: xiaoyao
clientId: fluxMq
qos: 0
topic: xiaoyao
topic: test

View File

@ -15,11 +15,9 @@ spring:
discovery:
# 服务注册地址
server-addr: 121.89.211.230:8848
namespace: 172469
config:
# 配置中心地址
server-addr: 121.89.211.230:8848
namespace: 172469
# 配置文件格式
file-extension: yml
# 共享配置