Merge branch 'server_five' of https://gitea.qinmian.online/five-groups/five-groups-couplet into server_five_liuyunhu

# Conflicts:
#	couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/resources/bootstrap.yml
#	couplet-modules/couplet-modules-onLine/src/main/resources/bootstrap.yml
server_five_liuyunhu
liuyunhu 2024-04-08 13:22:41 +08:00
commit b44d92b599
11 changed files with 249 additions and 171 deletions

View File

@ -63,6 +63,13 @@ public interface RemoteVehicleService {
*/
@PostMapping("/vehicleAndLogo/queryByLogoIds/{vehicleId}")
public Result<List<Long>> queryByLogoIds(@PathVariable("vehicleId") Long vehicleId);
/**
* id
* @param
* @return
*/
// @PostMapping("/vehicleAndLogo/queryByLogoIds/{vehicleId}")
// public Result<List<Long>> queryByLogoIds(@PathVariable("vehicleId") Long vehicleId);
@PostMapping("/list")
public Result list(@RequestBody VehicleListParams listParams);

View File

@ -1,27 +1,31 @@
package com.couplet.analyze.common.contents;
import org.springframework.stereotype.Component;
/**
* @Author: LiJiaYao
* @Date: 2024/4/7
* @Description:
*/
@Component
public class AnalyzeEventContents {
/**
*
*/
String BREAKDOWN = "breakdown";
static final String BREAKDOWN = "breakdown";
/**
*
*/
String ELECTRONIC_FENCE = "electronic-fence";
static final String ELECTRONIC_FENCE = "electronic-fence";
/**
*
*/
String REAL_TIME_DATA = "real-time-data";
static final String REAL_TIME_DATA = "real-time-data";
/**
*
*/
String STORED_EVENT = "stored-event";
static final String STORED_EVENT = "stored-event";
}

View File

@ -43,8 +43,7 @@ public class AnalyzeEventCache {
*
* @return
*/
public Set<Object> getEventList(String vin){
public Set<String> getEventList(String vin){
return redisService.getCacheSet(encode(vin));
}

View File

@ -182,7 +182,32 @@ public class RedisService {
}
return setOperation;
}
/**
* Set
*
* @param key
* @param setValue
*
* @return
*/
public <T> BoundSetOperations<String, T> setCacheSet (final String key, final T setValue) {
BoundSetOperations<String, T> setOperation = redisTemplate.boundSetOps(key);
setOperation.add(setValue);
return setOperation;
}
/**
* Set
*
* @param key
* @param setValue
*
* @return
*/
public <T> void deleteSet(String key, String setValue) {
BoundSetOperations setOperations = redisTemplate.boundSetOps(key);
setOperations.remove(setValue);
}
/**
* set
*
@ -194,6 +219,8 @@ public class RedisService {
return redisTemplate.opsForSet().members(key);
}
/**
* Map
*
@ -277,7 +304,13 @@ public class RedisService {
}
public void setVinAndUserId(RealTimeDataRequest realTimeDataRequest) {
String key = "vin:"+realTimeDataRequest.getVin()+"userId:"+realTimeDataRequest.getUserId();
String key = "vin:"+realTimeDataRequest.getVin();
redisTemplate.opsForValue().set(key, realTimeDataRequest);
}
public void stopViewingData(String vin) {
String key = "vin:"+vin;
redisTemplate.delete(key);
}
}

View File

@ -96,6 +96,10 @@
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka</artifactId>
</dependency>
<dependency>
<groupId>com.couplet</groupId>
<artifactId>couplet-common-business</artifactId>
</dependency>
</dependencies>

View File

@ -1,150 +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 {
//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 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);
}
}
}
// 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,6 +1,7 @@
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.service.IncidentService;
import com.couplet.common.core.exception.vehicle.VehicleException;
@ -34,19 +35,16 @@ public class ModelsKafkaMessage {
private static final String TOPIC_NAME = "online";
private static final String BOOTSTRAP_SERVERS = "39.103.133.136:9092";
static ArrayList<String> strings = new ArrayList<>() {
{
add("breakdown");
add("electronic-fence");
add("real-time-data");
add("stored-event");
}
};
@Autowired
private AnalyzeEventContents analyzeEventContents;
@Autowired
private AnalyzeEventCache analyzeEventCache;
// @Autowired
// private RabbitTemplate rabbitTemplate;
/**
*
*
* @return
*/
@Scheduled(fixedDelay = 50)
@ -64,7 +62,6 @@ public class ModelsKafkaMessage {
//订阅主题
consumer.subscribe(Collections.singletonList(TOPIC_NAME));
//持续消费消息
while (true) {
ConsumerRecords<String, String> records = consumer.poll(Duration.ofMillis(100));
@ -74,11 +71,12 @@ public class ModelsKafkaMessage {
List<CoupletMsgData> coupletMsgDataList = sendMsg(str);
for (CoupletMsgData msgData : coupletMsgDataList) {
log.info("解析到车辆数据:{}", msgData);
for (String string : strings) {
Set<String> eventList = analyzeEventCache.getEventList(msgData.getVin());
for (String string : eventList) {
IncidentService incidentService = SpringUtils.getBean(string);
incidentService.incident(msgData);
}
//发送消息
// 发送消息
// rabbitTemplate.convertAndSend("couplet-code-queue",msgData,message -> {
// message.getMessageProperties().setMessageId(UUID.randomUUID().toString());
// return message;
@ -87,7 +85,7 @@ public class ModelsKafkaMessage {
try {
sleep(100);
} catch (Exception e) {
throw new VehicleException("睡眠失败"+e);
throw new VehicleException("睡眠失败" + e);
}
}
});

View File

@ -4,6 +4,9 @@ import com.couplet.analyze.msg.domain.CoupletMsgData;
import com.couplet.analyze.msg.mapper.IncidentMapper;
import com.couplet.analyze.msg.service.IncidentService;
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.redis.service.RedisService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
@ -25,7 +28,7 @@ public class RealTimeDataServiceImpl implements IncidentService {
private IncidentMapper incidentMapper;
@Autowired
private StringRedisTemplate redisTemplate;
private RedisService redisService;
/**
*
@ -37,6 +40,11 @@ public class RealTimeDataServiceImpl implements IncidentService {
log.info("实时数据事件开始.....");
RealTimeDataRequest cacheObject = redisService.getCacheObject("vin:" + coupletMsgData.getVin());
if (StringUtils.isArray(cacheObject)){
log.info("[{}]有缓存数据,值为:[{}]", coupletMsgData.getVin(), cacheObject);
}
if (RealTimeJudge.isJudge(coupletMsgData.getVin())){
log.info("有实时数据,值为:[{}]开始传输实时数据", coupletMsgData.getVin());
}

View File

@ -59,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();
@ -68,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,9 @@ public class VehicleDetectionServiceImpl implements VehicleDetectionService{
}
@Override
public void stopViewingData(String vin) {
redisService.stopViewingData(vin);
}
}