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}") @PostMapping("/vehicleAndLogo/queryByLogoIds/{vehicleId}")
public Result<List<Long>> queryByLogoIds(@PathVariable("vehicleId") Long 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") @PostMapping("/list")
public Result list(@RequestBody VehicleListParams listParams); public Result list(@RequestBody VehicleListParams listParams);

View File

@ -1,27 +1,31 @@
package com.couplet.analyze.common.contents; package com.couplet.analyze.common.contents;
import org.springframework.stereotype.Component;
/** /**
* @Author: LiJiaYao * @Author: LiJiaYao
* @Date: 2024/4/7 * @Date: 2024/4/7
* @Description: * @Description:
*/ */
@Component
public class AnalyzeEventContents { 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 * @return
*/ */
public Set<Object> getEventList(String vin){ public Set<String> getEventList(String vin){
return redisService.getCacheSet(encode(vin)); return redisService.getCacheSet(encode(vin));
} }

View File

@ -182,7 +182,32 @@ public class RedisService {
} }
return setOperation; 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 * set
* *
@ -194,6 +219,8 @@ public class RedisService {
return redisTemplate.opsForSet().members(key); return redisTemplate.opsForSet().members(key);
} }
/** /**
* Map * Map
* *
@ -277,7 +304,13 @@ public class RedisService {
} }
public void setVinAndUserId(RealTimeDataRequest realTimeDataRequest) { public void setVinAndUserId(RealTimeDataRequest realTimeDataRequest) {
String key = "vin:"+realTimeDataRequest.getVin()+"userId:"+realTimeDataRequest.getUserId(); String key = "vin:"+realTimeDataRequest.getVin();
redisTemplate.opsForValue().set(key, realTimeDataRequest); 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> <groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka</artifactId> <artifactId>spring-kafka</artifactId>
</dependency> </dependency>
<dependency>
<groupId>com.couplet</groupId>
<artifactId>couplet-common-business</artifactId>
</dependency>
</dependencies> </dependencies>

View File

@ -1,150 +1,150 @@
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(); // // 检查车辆状态若为0则设置故障位置为"190"
troubleCode.setTroubleCode(faultCode); // if(msgData.getVehicleStatus() == 0) {
// troubleCode.setTroublePosition("190");
// 检查车辆状态若为0则设置故障位置为"190" // }
if(msgData.getVehicleStatus() == 0) { //
troubleCode.setTroublePosition("190"); // // 检查充电状态若为0则设置故障位置为"191"
} // if (msgData.getChargingStatus() == 0) {
// troubleCode.setTroublePosition("191");
// 检查充电状态若为0则设置故障位置为"191" // }
if (msgData.getChargingStatus() == 0) { //
troubleCode.setTroublePosition("191"); // // 检查运行状态若为0则设置故障位置为"192"
} // if (msgData.getOperatingStatus() == 0) {
// troubleCode.setTroublePosition("192");
// 检查运行状态若为0则设置故障位置为"192" // }
if (msgData.getOperatingStatus() == 0) { //
troubleCode.setTroublePosition("192"); // // 检查电池荷电状态SOC, 若为0则设置故障位置为"193"
} // if (msgData.getSocStatus() == 0) {
// troubleCode.setTroublePosition("193");
// 检查电池荷电状态SOC, 若为0则设置故障位置为"193" // }
if (msgData.getSocStatus() == 0) { //
troubleCode.setTroublePosition("193"); // // 检查充电能源存储状态若为0则设置故障位置为"194"
} // if (msgData.getChargingEnergyStorageStatus() == 0) {
// troubleCode.setTroublePosition("194");
// 检查充电能源存储状态若为0则设置故障位置为"194" // }
if (msgData.getChargingEnergyStorageStatus() == 0) { //
troubleCode.setTroublePosition("194"); // // 检查驱动电机状态若为0则设置故障位置为"195"
} // if (msgData.getDriveMotorStatus() == 0) {
// troubleCode.setTroublePosition("195");
// 检查驱动电机状态若为0则设置故障位置为"195" // }
if (msgData.getDriveMotorStatus() == 0) { //
troubleCode.setTroublePosition("195"); // // 检查定位状态若为0则设置故障位置为"196"
} // if (msgData.getPositionStatus() == 0) {
// troubleCode.setTroublePosition("196");
// 检查定位状态若为0则设置故障位置为"196" // }
if (msgData.getPositionStatus() == 0) { //
troubleCode.setTroublePosition("196"); // // 检查电子驻车系统EAS状态若为0则设置故障位置为"197"
} // if (msgData.getEasStatus() == 0) {
// troubleCode.setTroublePosition("197");
// 检查电子驻车系统EAS状态若为0则设置故障位置为"197" // }
if (msgData.getEasStatus() == 0) { //
troubleCode.setTroublePosition("197"); // // 检查PTC正温度系数热敏电阻状态若为0则设置故障位置为"198"
} // if (msgData.getPtcStatus() == 0) {
// troubleCode.setTroublePosition("198");
// 检查PTC正温度系数热敏电阻状态若为0则设置故障位置为"198" // }
if (msgData.getPtcStatus() == 0) { //
troubleCode.setTroublePosition("198"); // // 检查电动助力转向系统EPS状态若为0则设置故障位置为"199"
} // if (msgData.getEpsStatus() == 0) {
// troubleCode.setTroublePosition("199");
// 检查电动助力转向系统EPS状态若为0则设置故障位置为"199" // }
if (msgData.getEpsStatus() == 0) { //
troubleCode.setTroublePosition("199"); // // 检查防抱死制动系统ABS状态若为0则设置故障位置为"200"
} // if (msgData.getAbsStatus() == 0) {
// troubleCode.setTroublePosition("200");
// 检查防抱死制动系统ABS状态若为0则设置故障位置为"200" // }
if (msgData.getAbsStatus() == 0) { //
troubleCode.setTroublePosition("200"); // // 检查主控制器MCU状态若为0则设置故障位置为"201"
} // if (msgData.getMcuStatus() == 0) {
// troubleCode.setTroublePosition("201");
// 检查主控制器MCU状态若为0则设置故障位置为"201" // }
if (msgData.getMcuStatus() == 0) { //
troubleCode.setTroublePosition("201"); // // 检查加热状态若为0则设置故障位置为"202"
} // if (msgData.getHeatingStatus() == 0) {
// troubleCode.setTroublePosition("202");
// 检查加热状态若为0则设置故障位置为"202" // }
if (msgData.getHeatingStatus() == 0) { //
troubleCode.setTroublePosition("202"); // // 检查电池状态若为0则设置故障位置为"203"
} // if (msgData.getBatteryStatus() == 0) {
// troubleCode.setTroublePosition("203");
// 检查电池状态若为0则设置故障位置为"203" // }
if (msgData.getBatteryStatus() == 0) { //
troubleCode.setTroublePosition("203"); // // 检查电池绝缘状态若为0则设置故障位置为"204"
} // if (msgData.getBatteryInsulationStatus() == 0) {
// troubleCode.setTroublePosition("204");
// 检查电池绝缘状态若为0则设置故障位置为"204" // }
if (msgData.getBatteryInsulationStatus() == 0) { //
troubleCode.setTroublePosition("204"); // // 检查直流-直流转换器DC/DC状态若为0则设置故障位置为"205"
} // if (msgData.getDcdcStatus() == 0) {
// troubleCode.setTroublePosition("205");
// 检查直流-直流转换器DC/DC状态若为0则设置故障位置为"205" // }
if (msgData.getDcdcStatus() == 0) { //
troubleCode.setTroublePosition("205"); // // 检查充电机CHG状态若为0则设置故障位置为"206"
} // if (msgData.getChgStatus() == 0) {
// troubleCode.setTroublePosition("206");
// 检查充电机CHG状态若为0则设置故障位置为"206" // }
if (msgData.getChgStatus() == 0) { // remoteTroubleService.newFaultData(troubleCode);
troubleCode.setTroublePosition("206"); // });
} // }
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); //}
}
}
}

View File

@ -1,6 +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.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;
@ -34,19 +35,16 @@ public class ModelsKafkaMessage {
private static final String TOPIC_NAME = "online"; private static final String TOPIC_NAME = "online";
private static final String BOOTSTRAP_SERVERS = "39.103.133.136:9092"; private static final String BOOTSTRAP_SERVERS = "39.103.133.136:9092";
static ArrayList<String> strings = new ArrayList<>() { @Autowired
{ private AnalyzeEventContents analyzeEventContents;
add("breakdown"); @Autowired
add("electronic-fence"); private AnalyzeEventCache analyzeEventCache;
add("real-time-data");
add("stored-event");
}
};
// @Autowired // @Autowired
// private RabbitTemplate rabbitTemplate; // private RabbitTemplate rabbitTemplate;
/** /**
* *
*
* @return * @return
*/ */
@Scheduled(fixedDelay = 50) @Scheduled(fixedDelay = 50)
@ -64,7 +62,6 @@ public class ModelsKafkaMessage {
//订阅主题 //订阅主题
consumer.subscribe(Collections.singletonList(TOPIC_NAME)); consumer.subscribe(Collections.singletonList(TOPIC_NAME));
//持续消费消息 //持续消费消息
while (true) { while (true) {
ConsumerRecords<String, String> records = consumer.poll(Duration.ofMillis(100)); ConsumerRecords<String, String> records = consumer.poll(Duration.ofMillis(100));
@ -74,7 +71,8 @@ public class ModelsKafkaMessage {
List<CoupletMsgData> coupletMsgDataList = sendMsg(str); List<CoupletMsgData> coupletMsgDataList = sendMsg(str);
for (CoupletMsgData msgData : coupletMsgDataList) { for (CoupletMsgData msgData : coupletMsgDataList) {
log.info("解析到车辆数据:{}", msgData); log.info("解析到车辆数据:{}", msgData);
for (String string : strings) { Set<String> eventList = analyzeEventCache.getEventList(msgData.getVin());
for (String string : eventList) {
IncidentService incidentService = SpringUtils.getBean(string); IncidentService incidentService = SpringUtils.getBean(string);
incidentService.incident(msgData); incidentService.incident(msgData);
} }

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.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.redis.service.RedisService;
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.data.redis.core.StringRedisTemplate;
@ -25,7 +28,7 @@ public class RealTimeDataServiceImpl implements IncidentService {
private IncidentMapper incidentMapper; private IncidentMapper incidentMapper;
@Autowired @Autowired
private StringRedisTemplate redisTemplate; private RedisService redisService;
/** /**
* *
@ -37,6 +40,11 @@ public class RealTimeDataServiceImpl implements IncidentService {
log.info("实时数据事件开始....."); log.info("实时数据事件开始.....");
RealTimeDataRequest cacheObject = redisService.getCacheObject("vin:" + coupletMsgData.getVin());
if (StringUtils.isArray(cacheObject)){
log.info("[{}]有缓存数据,值为:[{}]", coupletMsgData.getVin(), cacheObject);
}
if (RealTimeJudge.isJudge(coupletMsgData.getVin())){ if (RealTimeJudge.isJudge(coupletMsgData.getVin())){
log.info("有实时数据,值为:[{}]开始传输实时数据", coupletMsgData.getVin()); log.info("有实时数据,值为:[{}]开始传输实时数据", coupletMsgData.getVin());
} }

View File

@ -59,8 +59,13 @@ public class VehicleDetectionController {
vehicleDetectionService.monitorinData(vin); vehicleDetectionService.monitorinData(vin);
} }
/*
* @param :
* @return Result<List<CoupletVehicleData>>
* @author
* @description
* @date
*/
@PostMapping("realData") @PostMapping("realData")
public Result<List<CoupletVehicleData>> realData(){ public Result<List<CoupletVehicleData>> realData(){
List<CoupletVehicleData> list = redisService.getList(); List<CoupletVehicleData> list = redisService.getList();
@ -68,4 +73,16 @@ public class VehicleDetectionController {
return success; 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(); List<Vehicle> detectionList();
void monitorinData(String vin); 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);
}
} }