新增 0x25报文数据存入缓存方法

This commit is contained in:
Lemon
2024-12-11 09:15:31 +08:00
parent 19f8aeb07a
commit 05cf609297
6 changed files with 191 additions and 114 deletions

View File

@@ -178,6 +178,11 @@ public class CacheConstants {
/**
* 0x23缓存key
*/
public static final String BMS_DEMAND_AND_CHARGER_OUTPUT_BY_TRANSACTION_CODE = "bms_demand_and_charger_output_by_transaction_code:";
/**
* 0x25缓存key
*/
public static final String BMS_CHARGE_INFO_BY_TRANSACTION_CODE = "bms_charge_info_by_transaction_code:";
/**

View File

@@ -0,0 +1,120 @@
package com.jsowell.common.core.domain.ykc;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* 0x25数据信息
*
* @author Lemon
* @Date 2024/12/10 15:45:14
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class BMSChargeInfoData {
/**
* 交易流水号
*/
private String transactionCode;
/**
* 桩编码
*/
private String pileSn;
/**
* 枪号
*/
private String connectorCode;
/**
* BMS 最高单体动力蓄电池电压所在编号
* 1/位, 1 偏移量;
* 数据范围: 1~256
*/
private String bmsMaxVoltageNum;
/**
* BMS 最高动力蓄电池温度
* 1ºC/位, -50 ºC 偏移量;
* 数据范围: -50 ºC ~+200 ºC
*/
private String bmsMaxBatteryTemperature;
/**
* 最高温度检测点编号
* 1/位, 1 偏移量;
* 数据范围: 1~128
*/
private String maxTemperatureDetectionNum;
/**
* 最低动力蓄电池温度
* 1ºC/位, -50 ºC 偏移量;
* 数据范围: -50 ºC ~+200 ºC
*/
private String minBatteryTemperature;
/**
* 最低动力蓄电池温度检测点编号
* 1/位, 1 偏移量;
* 数据范围: 1~128
*/
private String minTemperatureDetectionNum;
/**
* BMS 单体动力蓄电池电压过高 /过低
* (<00> =正常 ; <01> =过高 ; <10> =过低)
*/
private String singleBMSVoltageStatus;
/**
* BMS 整车动力蓄电池荷电状态 SOC 过高/过低
* (<00> =正常 ; <01> =过高 ; <10> =过低)
*/
private String carBMSSocStatus;
/**
* BMS 动力蓄电池充电过电流
* (<00> =正常 ; <01> =过流 ; <10> =不可信状态)
*/
private String bmsBatteryChargeCurrentStatus;
/**
* BMS 动力蓄电池温度过高
* (<00> =正常 ; <01> =过流 ; <10> =不可信状态)
*/
private String bmsBatteryTemperature;
/**
* BMS 动力蓄电池绝缘状态
* (<00> =正常 ; <01> =过流 ; <10> =不可信状态)
*/
private String bmsBatteryInsulationStatus;
/**
* BMS 动力蓄电池组输出连接器连接状态
* (<00> =正常 ; <01> =过流 ; <10> =不可信状态)
*/
private String bmsBatteryOutputStatus;
/**
* 充电禁止
* (<00> =禁止; <01> =允许)
*/
private String chargeProhibit;
/**
* 预留位
*/
private String noMeanPositionByteArr;
private String dateTime;
}

View File

@@ -1,12 +1,15 @@
package com.jsowell.netty.handler.yunkuaichong;
import com.jsowell.common.core.domain.ykc.BMSChargeInfoData;
import com.jsowell.common.core.domain.ykc.YKCDataProtocol;
import com.jsowell.common.core.domain.ykc.YKCFrameTypeCode;
import com.jsowell.common.util.BytesUtil;
import com.jsowell.common.util.YKCUtils;
import com.jsowell.netty.factory.YKCOperateFactory;
import com.jsowell.pile.service.PileBasicInfoService;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
@@ -19,6 +22,10 @@ import org.springframework.stereotype.Component;
@Slf4j
@Component
public class BMSInformationHandler extends AbstractYkcHandler {
@Autowired
private PileBasicInfoService pileBasicInfoService;
private final String type = YKCUtils.frameType2Str(YKCFrameTypeCode.CHARGING_PROCESS_BMS_INFORMATION_CODE.getBytes());
@Override
@@ -26,113 +33,6 @@ public class BMSInformationHandler extends AbstractYkcHandler {
YKCOperateFactory.register(type, this);
}
public static void main(String[] args) {
String msg = "8823000000104502241209160539911188230000001045027c45043e080010";
byte[] msgBody = BytesUtil.str2Bcd(msg);
int startIndex = 0;
int length = 16;
// 交易流水号
byte[] serialNumByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String transactionCode = BytesUtil.bcd2Str(serialNumByteArr);
// 桩编码
startIndex += length;
length = 7;
byte[] pileSnByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String pileSn = BytesUtil.bcd2Str(pileSnByteArr);
// 枪号
startIndex += length;
length = 1;
byte[] pileConnectorNumByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String connectorCode = BytesUtil.bcd2Str(pileConnectorNumByteArr);
// BMS 最高单体动力蓄电池电压所在编号 1/位, 1 偏移量; 数据范围: 1~256
startIndex += length;
byte[] BMSMaxVoltageNumByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String bmsMaxVoltageNum = String.valueOf(BytesUtil.bytesToIntLittle(BMSMaxVoltageNumByteArr));
// BMS 最高动力蓄电池温度 1ºC/位, -50 ºC 偏移量;数据范 围: -50 ºC ~+200 ºC
startIndex += length;
byte[] BMSMaxBatteryTemperatureByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String bmsMaxBatteryTemperature = String.valueOf(BytesUtil.bytesToIntLittle(BMSMaxBatteryTemperatureByteArr) - 50);
// 最高温度检测点编号 1/位, 1 偏移量; 数据范围: 1~128
startIndex += length;
byte[] maxTemperatureDetectionNumByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String maxTemperatureDetectionNum = String.valueOf(BytesUtil.bytesToIntLittle(maxTemperatureDetectionNumByteArr) + 1);
// 最低动力蓄电池温度 1ºC/位, -50 ºC 偏移量;数据范 围: -50 ºC ~+200 ºC
startIndex += length;
byte[] minBatteryTemperatureByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String minBatteryTemperature = String.valueOf(BytesUtil.bytesToIntLittle(minBatteryTemperatureByteArr) - 50);
// 最低动力蓄电池温度检测点编号 1/位, 1 偏移量; 数据范围: 1~128
startIndex += length;
byte[] minTemperatureDetectionNumByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String minTemperatureDetectionNum = String.valueOf(BytesUtil.bytesToIntLittle(minTemperatureDetectionNumByteArr) + 1);
/**
* BMS 单体动力蓄电池电压过高 /过低 (<00> =正常 ; <01> =过高 ; <10> =过低)
*/
startIndex += length;
length = 2;
byte[] singleBMSVoltageStatusByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String singleBMSVoltageStatus = BytesUtil.bcd2Str(singleBMSVoltageStatusByteArr);
/**
* BMS 整车动力蓄电池荷电状态 SOC 过高/过低 (<00> =正常 ; <01> =过高 ; <10> =过低)
*/
startIndex += length;
byte[] carBMSSocStatusByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String carBMSSocStatus = BytesUtil.bcd2Str(carBMSSocStatusByteArr);
/**
* BMS 动力蓄电池充电过电流 (<00> =正常 ; <01> =过流 ; <10> =不可信状态)
*/
startIndex += length;
byte[] BMSBatteryChargeCurrentStatusByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String bmsBatteryChargeCurrentStatus = BytesUtil.bcd2Str(BMSBatteryChargeCurrentStatusByteArr);
/**
* BMS 动力蓄电池温度过高 (<00> =正常 ; <01> =过流 ; <10> =不可信状态)
*/
startIndex += length;
byte[] BMSBatteryTemperatureByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String bmsBatteryTemperature = BytesUtil.bcd2Str(BMSBatteryTemperatureByteArr);
/**
* BMS 动力蓄电池绝缘状态 (<00> =正常 ; <01> =过流 ; <10> =不可信状态)
*/
startIndex += length;
byte[] BMSBatteryInsulationStatusByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String bmsBatteryInsulationStatus = BytesUtil.bcd2Str(BMSBatteryInsulationStatusByteArr);
/**
* BMS 动力蓄电池组输出连接器连接状态 (<00> =正常 ; <01> =过流 ; <10> =不可信状态)
*/
startIndex += length;
byte[] BMSBatteryOutputStatusByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String bmsBatteryOutputStatus = BytesUtil.bcd2Str(BMSBatteryOutputStatusByteArr);
/**
* 充电禁止 (<00> =禁止; <01> =允许)
*/
startIndex += length;
byte[] chargeProhibitByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String chargeProhibit = BytesUtil.bcd2Str(chargeProhibitByteArr);
/**
* 预留位
*/
startIndex += length;
byte[] noMeanPositionByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
}
@Override
public byte[] supplyProcess(YKCDataProtocol ykcDataProtocol, ChannelHandlerContext channel) {
// log.info("[===充电过程 BMS 信息===] param:{}, channel:{}", JSON.toJSONString(ykcDataProtocol), channel.toString());
@@ -242,6 +142,27 @@ public class BMSInformationHandler extends AbstractYkcHandler {
startIndex += length;
byte[] noMeanPositionByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
// 存入缓存缓存时间3天
BMSChargeInfoData data = BMSChargeInfoData.builder()
.transactionCode(transactionCode)
.pileSn(pileSn)
.connectorCode(connectorCode)
.bmsMaxVoltageNum(bmsMaxVoltageNum)
.bmsMaxBatteryTemperature(bmsMaxBatteryTemperature)
.maxTemperatureDetectionNum(maxTemperatureDetectionNum)
.minBatteryTemperature(minBatteryTemperature)
.minTemperatureDetectionNum(minTemperatureDetectionNum)
.singleBMSVoltageStatus(singleBMSVoltageStatus)
.carBMSSocStatus(carBMSSocStatus)
.bmsBatteryChargeCurrentStatus(bmsBatteryChargeCurrentStatus)
.bmsBatteryTemperature(bmsBatteryTemperature)
.bmsBatteryInsulationStatus(bmsBatteryInsulationStatus)
.bmsBatteryOutputStatus(bmsBatteryOutputStatus)
.chargeProhibit(chargeProhibit)
.build();
pileBasicInfoService.saveBMSChargeInfo2Redis(data);
return null;
}

View File

@@ -1,5 +1,6 @@
package com.jsowell.pile.service;
import com.jsowell.common.core.domain.ykc.BMSChargeInfoData;
import com.jsowell.common.core.domain.ykc.BMSDemandAndChargerOutputData;
import com.jsowell.common.core.domain.ykc.RealTimeMonitorData;
import com.jsowell.pile.domain.PileBasicInfo;
@@ -158,6 +159,12 @@ public interface PileBasicInfoService {
*/
void saveBMSDemandAndChargerOutputInfo2Redis(BMSDemandAndChargerOutputData bmsDemandAndChargerOutputData);
/**
* 0x25数据保存到redis
* @param bmsChargeInfoData
*/
void saveBMSChargeInfo2Redis(BMSChargeInfoData bmsChargeInfoData);
/**
* 根据交易流水号查询0x23数据时间倒序
* @param transactionCode

View File

@@ -7,10 +7,7 @@ import com.jsowell.common.YouDianUtils;
import com.jsowell.common.constant.CacheConstants;
import com.jsowell.common.constant.Constants;
import com.jsowell.common.core.domain.vo.AuthorizedDeptVO;
import com.jsowell.common.core.domain.ykc.BMSDemandAndChargerOutputData;
import com.jsowell.common.core.domain.ykc.GroundLockData;
import com.jsowell.common.core.domain.ykc.RealTimeMonitorData;
import com.jsowell.common.core.domain.ykc.YKCFrameTypeCode;
import com.jsowell.common.core.domain.ykc.*;
import com.jsowell.common.core.redis.RedisCache;
import com.jsowell.common.enums.DelFlagEnum;
import com.jsowell.common.enums.lianlian.LianLianPileStatusEnum;
@@ -674,7 +671,7 @@ public class PileBasicInfoServiceImpl implements PileBasicInfoService {
return;
}
// 保存到redis
String redisKey = CacheConstants.BMS_CHARGE_INFO_BY_TRANSACTION_CODE + data.getTransactionCode();
String redisKey = CacheConstants.BMS_DEMAND_AND_CHARGER_OUTPUT_BY_TRANSACTION_CODE + data.getTransactionCode();
// 设置接收到实时数据的时间
Date now = new Date();
data.setDateTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, now));
@@ -697,6 +694,33 @@ public class PileBasicInfoServiceImpl implements PileBasicInfoService {
}
}
/**
* 0x25数据保存到redis
* @param bmsChargeInfoData
*/
@Override
public void saveBMSChargeInfo2Redis(BMSChargeInfoData bmsChargeInfoData) {
if (StringUtils.equals(bmsChargeInfoData.getTransactionCode(), Constants.ILLEGAL_TRANSACTION_CODE)) {
return;
}
// 保存到redis
String redisKey = CacheConstants.BMS_CHARGE_INFO_BY_TRANSACTION_CODE + bmsChargeInfoData.getTransactionCode();
// 设置接收到实时数据的时间
Date now = new Date();
bmsChargeInfoData.setDateTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, now));
// 保存json字符串
String jsonMsg = JSON.toJSONString(bmsChargeInfoData);
// 0x25数据20秒发送一次1分钟3次在同一分钟内只保留最后一条实时数据
redisCache.hset(redisKey, DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:00", now), jsonMsg);
// 设置过期时间
try {
redisCache.expire(redisKey, CacheConstants.cache_expire_time_3d);
} catch (Exception e) {
log.info("0x25存入缓存设置过期时间error", e);
}
}
/**
* 根据交易流水号查询0x23数据时间倒序
* @param transactionCode
@@ -708,7 +732,7 @@ public class PileBasicInfoServiceImpl implements PileBasicInfoService {
if (StringUtils.isBlank(transactionCode)) {
return resultList;
}
String redisKey = CacheConstants.BMS_CHARGE_INFO_BY_TRANSACTION_CODE + transactionCode;
String redisKey = CacheConstants.BMS_DEMAND_AND_CHARGER_OUTPUT_BY_TRANSACTION_CODE + transactionCode;
// 拿到所有数据
Map<Object, Object> map = redisCache.hmget(redisKey);
if (map != null && !map.isEmpty()) {

View File

@@ -73,7 +73,7 @@ public class ChargeAlgorithmService {
}
RealTimeMonitorData realTimeMonitorData = chargingRealTimeDataList.get(0);
// 获取0x25
// 获取最后一条0x25
ChargeAlgorithmData data = ChargeAlgorithmData.builder()