kafka代码

server_five_liuyunhu
dongxiaodong 2024-04-06 20:08:09 +08:00
parent 7aa223c8e4
commit d8e65c8da3
4 changed files with 121 additions and 0 deletions

View File

@ -65,4 +65,10 @@ public class CoupletTroubleCode {
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date troubleEndTime;
/**
*
*/
@Excel(name = "故障位置")
private String troublePosition;
}

View File

@ -17,5 +17,6 @@ import org.springframework.scheduling.annotation.EnableScheduling;
public class CoupletMsgApplication {
public static void main(String[] args) {
SpringApplication.run(CoupletMsgApplication.class);
System.out.println("解析系统启动成功");
}
}

View File

@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON;
import com.couplet.analyze.msg.contents.StateConstant;
import com.couplet.analyze.msg.domain.CoupletMsgData;
import com.couplet.analyze.msg.service.IncidentService;
import com.couplet.analyze.msg.utils.MsgUtils;
import com.couplet.common.domain.CoupletTroubleCode;
import com.couplet.remote.RemoteTroubleService;
import org.slf4j.Logger;
@ -70,6 +71,95 @@ public class BreakdownServiceImpl extends KeyExpirationEventMessageListener impl
|| StateConstant.DCDC_STATUS != coupletMsgData.getDcdcStatus()
|| StateConstant.CHG_STATUS != coupletMsgData.getChgStatus()){
//获取过期的key
// 定义一个CoupletTroubleCode对象用于记录故障位置信息
CoupletTroubleCode troubleCode = new CoupletTroubleCode();
// 检查车辆状态若为0则设置故障位置为"190"
if(coupletMsgData.getVehicleStatus() == 0) {
troubleCode.setTroublePosition("190");
}
// 检查充电状态若为0则设置故障位置为"191"
if (coupletMsgData.getChargingStatus() == 0) {
troubleCode.setTroublePosition("191");
}
// 检查运行状态若为0则设置故障位置为"192"
if (coupletMsgData.getOperatingStatus() == 0) {
troubleCode.setTroublePosition("192");
}
// 检查电池荷电状态SOC, 若为0则设置故障位置为"193"
if (coupletMsgData.getSocStatus() == 0) {
troubleCode.setTroublePosition("193");
}
// 检查充电能源存储状态若为0则设置故障位置为"194"
if (coupletMsgData.getChargingEnergyStorageStatus() == 0) {
troubleCode.setTroublePosition("194");
}
// 检查驱动电机状态若为0则设置故障位置为"195"
if (coupletMsgData.getDriveMotorStatus() == 0) {
troubleCode.setTroublePosition("195");
}
// 检查定位状态若为0则设置故障位置为"196"
if (coupletMsgData.getPositionStatus() == 0) {
troubleCode.setTroublePosition("196");
}
// 检查电子驻车系统EAS状态若为0则设置故障位置为"197"
if (coupletMsgData.getEasStatus() == 0) {
troubleCode.setTroublePosition("197");
}
// 检查PTC正温度系数热敏电阻状态若为0则设置故障位置为"198"
if (coupletMsgData.getPtcStatus() == 0) {
troubleCode.setTroublePosition("198");
}
// 检查电动助力转向系统EPS状态若为0则设置故障位置为"199"
if (coupletMsgData.getEpsStatus() == 0) {
troubleCode.setTroublePosition("199");
}
// 检查防抱死制动系统ABS状态若为0则设置故障位置为"200"
if (coupletMsgData.getAbsStatus() == 0) {
troubleCode.setTroublePosition("200");
}
// 检查主控制器MCU状态若为0则设置故障位置为"201"
if (coupletMsgData.getMcuStatus() == 0) {
troubleCode.setTroublePosition("201");
}
// 检查加热状态若为0则设置故障位置为"202"
if (coupletMsgData.getHeatingStatus() == 0) {
troubleCode.setTroublePosition("202");
}
// 检查电池状态若为0则设置故障位置为"203"
if (coupletMsgData.getBatteryStatus() == 0) {
troubleCode.setTroublePosition("203");
}
// 检查电池绝缘状态若为0则设置故障位置为"204"
if (coupletMsgData.getBatteryInsulationStatus() == 0) {
troubleCode.setTroublePosition("204");
}
// 检查直流-直流转换器DC/DC状态若为0则设置故障位置为"205"
if (coupletMsgData.getDcdcStatus() == 0) {
troubleCode.setTroublePosition("205");
}
// 检查充电机CHG状态若为0则设置故障位置为"206"
if (coupletMsgData.getChgStatus() == 0) {
troubleCode.setTroublePosition("206");
}
String key = "breakdown";
log.debug("失效+key is:"+ key);
String value = JSON.toJSONString(coupletMsgData);
@ -110,6 +200,9 @@ public class BreakdownServiceImpl extends KeyExpirationEventMessageListener impl
// 插入数据库
troubleCode.setTroubleTag(0);
troubleCode.setTroubleVin(code.getVin());
// 随机生成故障码
String faultCode = MsgUtils.generateGTA();
troubleCode.setTroubleCode(faultCode);
remoteTroubleService.newFaultData(troubleCode);
redisTemplate.opsForSet().add(code.getVin(), code.getVin()+":"+code);
long expireTime = 30;

View File

@ -8,6 +8,7 @@ import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Random;
/**
* @author DongXiaoDong
@ -18,6 +19,26 @@ import java.util.List;
@Slf4j
public class MsgUtils {
public static String generateGTA() {
// 生成四位以"GTA"开头的字符串
String prefix = "GTA";
// 生成三位随机数字
String randomNumber = generateRandomNumber(4);
// 拼接字符串
return prefix + randomNumber;
}
public static String generateRandomNumber(int length) {
// 生成随机数
Random random = new Random();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < length; i++) {
// 生成0到9之间的随机数字并转换为字符串
sb.append(random.nextInt(10));
}
return sb.toString();
}
/**
* 16ASCII
* @param s 16