Merge branch 'dev-new' into dev-new-rabbitmq

# Conflicts:
#	jsowell-admin/src/test/java/PaymentTestController.java
This commit is contained in:
Guoqs
2024-12-19 13:30:11 +08:00
64 changed files with 2858 additions and 767 deletions

View File

@@ -2,11 +2,15 @@ package com.jsowell.netty.handler.yunkuaichong;
import com.jsowell.common.core.domain.ykc.YKCDataProtocol;
import com.jsowell.common.core.domain.ykc.YKCFrameTypeCode;
import com.jsowell.common.core.redis.RedisCache;
import com.jsowell.common.util.BytesUtil;
import com.jsowell.common.util.YKCUtils;
import com.jsowell.netty.factory.YKCOperateFactory;
import com.jsowell.common.core.domain.ykc.BMSDemandAndChargerOutputData;
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 +23,13 @@ import org.springframework.stereotype.Component;
@Slf4j
@Component
public class BMSDemandAndChargerOutputHandler extends AbstractYkcHandler {
@Autowired
private RedisCache redisCache;
@Autowired
private PileBasicInfoService pileBasicInfoService;
private final String type = YKCUtils.frameType2Str(YKCFrameTypeCode.CHARGING_PROCESS_BMS_DEMAND_AND_CHARGER_OUTPUT_CODE.getBytes());
@Override
@@ -26,6 +37,94 @@ public class BMSDemandAndChargerOutputHandler extends AbstractYkcHandler {
YKCOperateFactory.register(type, this);
}
public static void main(String[] args) {
String msg = "8823000000259602241208235501743088230000002596023c10ed1202d70d40037201175500e10de3120000";
// 获取消息体
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 电压需求 0.1 V/位, 0 V 偏移量
startIndex += length;
length = 2;
byte[] bmsVoltageDemandByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String bmsVoltageDemand = String.valueOf(BytesUtil.bytesToIntLittle(bmsVoltageDemandByteArr) * 0.1);
// BMS 电流需求 0.1 A/位, -400 A 偏移量
startIndex += length;
byte[] bmsCurrentDemandByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String bmsCurrentDemand = String.valueOf(BytesUtil.bytesToIntLittle(bmsCurrentDemandByteArr) * 0.1 - 400);
// BMS 充电模式 0x01恒压充电 0x02恒流充电
startIndex += length;
length = 1;
byte[] bmsChargingModelByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String bmsChargingModel = BytesUtil.bcd2Str(bmsChargingModelByteArr);
// BMS 充电电压测量值 0.1 V/位, 0 V 偏移量
startIndex += length;
length = 2;
byte[] bmsChargingVoltageByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String bmsChargingVoltage = String.valueOf(BytesUtil.bytesToIntLittle(bmsChargingVoltageByteArr) * 0.1);
// BMS 充电电流测量值 0.1 A/位, -400 A 偏移量
startIndex += length;
byte[] bmsChargingCurrentByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String bmsChargingCurrent = String.valueOf(BytesUtil.bytesToIntLittle(bmsChargingCurrentByteArr) * 0.1 - 400);
// BMS 最高单体动力蓄电池电压及组号 1-12 位:最高单体动力蓄电池电压, 数据分辨率: 0.01 V/位, 0 V 偏移量;数据范围: 0~24 V 13-16 位: 最高单体动力蓄电池电 压所在组号,数据分辨率: 1/位, 0 偏移量;数据范围: 0~15
startIndex += length;
byte[] bmsMaxVoltageAndGroupNum = BytesUtil.copyBytes(msgBody, startIndex, length);
String bmsMaxVoltageAndGroup = String.valueOf(BytesUtil.bytesToIntLittle(bmsMaxVoltageAndGroupNum) * 0.01);
// BMS 当前荷电状态 SOC % 1%/位, 0%偏移量; 数据范围: 0~100%
startIndex += length;
length = 1;
byte[] socByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String soc = BytesUtil.bcd2Str(socByteArr);
// BMS 估算剩余充电时间 1 min/位, 0 min 偏移量; 数据范围: 0~600 min
startIndex += length;
length = 2;
byte[] bmsTheRestChargingTimeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String bmsTheRestChargingTime = String.valueOf(BytesUtil.bytesToIntLittle(bmsTheRestChargingTimeByteArr));
// 电桩电压输出值 0.1 V/位, 0 V 偏移量
startIndex += length;
byte[] pileVoltageOutputByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String pileVoltageOutput = String.valueOf(BytesUtil.bytesToIntLittle(pileVoltageOutputByteArr) * 0.1);
// 电桩电流输出值 0.1 A/位, -400 A 偏移量
startIndex += length;
byte[] pileCurrentOutputByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String pileCurrentOutput = String.valueOf(BytesUtil.bytesToIntLittle(pileCurrentOutputByteArr) * 0.1 - 400);
// 累计充电时间 1 min/位, 0 min 偏移量; 数据范围: 0~600 min
startIndex += length;
byte[] chargingTimeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String chargingTime = String.valueOf(BytesUtil.bytesToIntLittle(chargingTimeByteArr));
}
@Override
public byte[] supplyProcess(YKCDataProtocol ykcDataProtocol, ChannelHandlerContext channel) {
// log.info("[===充电过程 BMS 需求与充电机输出===] param:{}, channel:{}", JSON.toJSONString(ykcDataProtocol), channel.toString());
@@ -37,6 +136,7 @@ public class BMSDemandAndChargerOutputHandler extends AbstractYkcHandler {
// 交易流水号
byte[] serialNumByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String transactionCode = BytesUtil.bcd2Str(serialNumByteArr);
// 桩编码
startIndex += length;
@@ -51,56 +151,91 @@ public class BMSDemandAndChargerOutputHandler extends AbstractYkcHandler {
startIndex += length;
length = 1;
byte[] pileConnectorNumByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String connectorCode = BytesUtil.bcd2Str(pileConnectorNumByteArr);
// BMS 电压需求 0.1 V/位, 0 V 偏移量
startIndex += length;
length = 2;
byte[] bmsVoltageDemandByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String bmsVoltageDemand = String.valueOf(BytesUtil.bytesToIntLittle(bmsVoltageDemandByteArr) * 0.1);
// BMS 电流需求 0.1 A/位, -400 A 偏移量
startIndex += length;
byte[] bmsCurrentDemandByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String bmsCurrentDemand = String.valueOf(BytesUtil.bytesToIntLittle(bmsCurrentDemandByteArr) * 0.1 - 400);
// BMS 充电模式 0x01恒压充电 0x02恒流充电
startIndex += length;
length = 1;
byte[] bmsChargingModelByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String bmsChargingModel = BytesUtil.bcd2Str(bmsChargingModelByteArr);
// BMS 充电电压测量值 0.1 V/位, 0 V 偏移量
startIndex += length;
length = 2;
byte[] bmsChargingVoltageByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String bmsChargingVoltage = String.valueOf(BytesUtil.bytesToIntLittle(bmsChargingVoltageByteArr) * 0.1);
// BMS 充电电流测量值 0.1 A/位, -400 A 偏移量
startIndex += length;
byte[] bmsChargingCurrentByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String bmsChargingCurrent = String.valueOf(BytesUtil.bytesToIntLittle(bmsChargingCurrentByteArr) * 0.1 - 400);
// BMS 最高单体动力蓄电池电压及组号 1-12 位:最高单体动力蓄电池电压, 数据分辨率: 0.01 V/位, 0 V 偏移量;数据范围: 0~24 V 13-16 位: 最高单体动力蓄电池电 压所在组号,数据分辨率: 1/位, 0 偏移量;数据范围: 0~15
startIndex += length;
byte[] bmsMaxVoltageAndGroupNum = BytesUtil.copyBytes(msgBody, startIndex, length);
String bmsMaxVoltageAndGroup = String.valueOf(BytesUtil.bytesToIntLittle(bmsMaxVoltageAndGroupNum) * 0.01);
// BMS 当前荷电状态 SOC % 1%/位, 0%偏移量; 数据范围: 0~100%
startIndex += length;
length = 1;
byte[] socByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String soc = BytesUtil.bcd2Str(socByteArr);
// BMS 估算剩余充电时间 1 min/位, 0 min 偏移量; 数据范围: 0~600 min
startIndex += length;
length = 2;
byte[] bmsTheRestChargingTimeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String bmsTheRestChargingTime = String.valueOf(BytesUtil.bytesToIntLittle(bmsTheRestChargingTimeByteArr));
// 电桩电压输出值 0.1 V/位, 0 V 偏移量
startIndex += length;
byte[] pileVoltageOutputByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String pileVoltageOutput = String.valueOf(BytesUtil.bytesToIntLittle(pileVoltageOutputByteArr) * 0.1);
// 电桩电流输出值 0.1 A/位, -400 A 偏移量
startIndex += length;
byte[] pileCurrentOutputByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String pileCurrentOutput = String.valueOf(BytesUtil.bytesToIntLittle(pileCurrentOutputByteArr) * 0.1 - 400);
// 累计充电时间 1 min/位, 0 min 偏移量; 数据范围: 0~600 min
startIndex += length;
byte[] chargingTimeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String chargingTime = String.valueOf(BytesUtil.bytesToIntLittle(chargingTimeByteArr));
// 存入缓存(过期时间 3 天)
BMSDemandAndChargerOutputData bmsDemandAndChargerOutputData = BMSDemandAndChargerOutputData.builder()
.transactionCode(transactionCode)
.pileSn(pileSn)
.connectorCode(connectorCode)
.bmsVoltageDemand(bmsVoltageDemand)
.bmsCurrentDemand(bmsCurrentDemand)
.bmsChargingModel(bmsChargingModel)
.bmsChargingVoltage(bmsChargingVoltage)
.bmsChargingCurrent(bmsChargingCurrent)
.bmsMaxVoltageAndGroup(bmsMaxVoltageAndGroup)
.soc(soc)
.bmsTheRestChargingTime(bmsTheRestChargingTime)
.pileVoltageOutput(pileVoltageOutput)
.pileCurrentOutput(pileCurrentOutput)
.chargingTime(chargingTime)
.build();
// 保存此订单的soc
YKCUtils.saveSOC(transactionCode, soc);
// 调用方法存入缓存
pileBasicInfoService.saveBMSDemandAndChargerOutputInfo2Redis(bmsDemandAndChargerOutputData);
return null;
}

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
@@ -37,6 +44,7 @@ public class BMSInformationHandler extends AbstractYkcHandler {
// 交易流水号
byte[] serialNumByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String transactionCode = BytesUtil.bcd2Str(serialNumByteArr);
// 桩编码
startIndex += length;
@@ -51,47 +59,110 @@ public class BMSInformationHandler extends AbstractYkcHandler {
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[] minBatteryTemperature = BytesUtil.copyBytes(msgBody, 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);
/**
* 9-12
* 9: BMS 单体动力蓄电池电压过高 /过低 (<00> =正常 ; <01> =过高 ; <10> =过低)
* 10: BMS 整车动力蓄电池荷电状态 SOC 过高/过低 (<00> =正常 ; <01> =过高 ; <10> =过低)
* 11: BMS 动力蓄电池充电过电流 (<00> =正常 ; <01> =过流 ; <10> =不可信状态)
* 12: BMS 动力蓄电池温度过高 (<00> =正常 ; <01> =过流 ; <10> =不可信状态)
* BMS 单体动力蓄电池电压过高 /过低 (<00> =正常 ; <01> =过高 ; <10> =过低)
*/
startIndex += length;
byte[] numNineToTwelve = BytesUtil.copyBytes(msgBody, startIndex, length);
length = 2;
byte[] singleBMSVoltageStatusByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String singleBMSVoltageStatus = BytesUtil.bcd2Str(singleBMSVoltageStatusByteArr);
/**
* 13-16
* 13: BMS 动力蓄电池绝缘状态 (<00> =正常 ; <01> =过流 ; <10> =不可信状态)
* 14: BMS 动力蓄电池组输出连接器连接状态 (<00> =正常 ; <01> =过流 ; <10> =不可信状态)
* 15: 充电禁止 (<00> =禁止; <01> =允许)
* 16: 预留位 00
* BMS 整车动力蓄电池荷电状态 SOC 过高/过低 (<00> =正常 ; <01> =过高 ; <10> =过低)
*/
startIndex += length;
byte[] numThirteenToSixteen = BytesUtil.copyBytes(msgBody, 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);
// 存入缓存缓存时间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

@@ -115,6 +115,9 @@ public class ChargeEndHandler extends AbstractYkcHandler {
}
updateOrder.setUpdateTime(nowDate);
orderBasicInfoService.updateOrderBasicInfo(updateOrder);
// 保存此订单的soc
YKCUtils.saveSOC(transactionCode, stopSoc);
}
return null;

View File

@@ -1,14 +1,20 @@
package com.jsowell.netty.handler.yunkuaichong;
import com.jsowell.common.constant.CacheConstants;
import com.jsowell.common.core.domain.ykc.ChargingHandshakeData;
import com.jsowell.common.core.domain.ykc.YKCDataProtocol;
import com.jsowell.common.core.domain.ykc.YKCFrameTypeCode;
import com.jsowell.common.core.redis.RedisCache;
import com.jsowell.common.util.BytesUtil;
import com.jsowell.common.util.YKCUtils;
import com.jsowell.netty.factory.YKCOperateFactory;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.concurrent.TimeUnit;
/**
* 充电握手
*
@@ -19,6 +25,9 @@ import org.springframework.stereotype.Component;
@Slf4j
@Component
public class ChargingHandshakeHandler extends AbstractYkcHandler {
@Autowired
private RedisCache redisCache;
private final String type = YKCUtils.frameType2Str(YKCFrameTypeCode.CHARGING_HANDSHAKE_CODE.getBytes());
@Override
@@ -37,6 +46,7 @@ public class ChargingHandshakeHandler extends AbstractYkcHandler {
// 交易流水号
byte[] serialNumByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String transactionCode = BytesUtil.bcd2Str(serialNumByteArr);
// 桩编码
startIndex += length;
@@ -57,48 +67,57 @@ public class ChargingHandshakeHandler extends AbstractYkcHandler {
startIndex += length;
length = 3;
byte[] BMSCommunicationProtocolVersionByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String bmsCommunicationVersion = "V1.1";
// BMS 电池类型 01H:铅酸电池;02H:氢 电池;03H:磷酸铁锂电池;04H:锰 酸锂电池;05H:钴酸锂电池 ;06H: 三元材料电池;07H:聚合物锂离子 电池;08H:钛酸锂电池;FFH:其他
startIndex += length;
length = 1;
byte[] BMSBatteryTypeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String bmsBatteryType = BytesUtil.bcd2Str(BMSBatteryTypeByteArr); // 03
// BMS 整车动力蓄电池系统额定容量 0.1 Ah /位, 0 Ah 偏移量
startIndex += length;
length = 2;
byte[] BMSBatteryCapacityByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String bmsBatteryCapacity = String.valueOf(BytesUtil.bytesToIntLittle(BMSBatteryCapacityByteArr) * 0.1); // 171.0
// BMS 整车动力蓄电池系统额定总电压 0.1V/位, 0V 偏移量
startIndex += length;
byte[] BMSBatteryVoltageByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String bmsBatteryVoltage = String.valueOf(BytesUtil.bytesToIntLittle(BMSBatteryVoltageByteArr) * 0.1); // 347.8
// BMS 电池生产厂商名称
startIndex += length;
length = 4;
byte[] BMSBatteryFactoryByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String bmsBatteryFactory = BytesUtil.ascii2Str(BMSBatteryFactoryByteArr); // CATL
// BMS 电池组序号
startIndex += length;
byte[] BMSBatteryNumByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String bmsBatteryNum = BytesUtil.bin2HexStr(BMSBatteryNumByteArr);
// BMS 电池组生产日期年 1985 年偏移量, 数据范围: 1985 2235 年
startIndex += length;
length = 1;
byte[] BMSProductionDateYearByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String bmsProductionDateYear = BytesUtil.bin2HexStr(BMSProductionDateYearByteArr);
// BMS 电池组生产日期月 0 月偏移量, 数据范围: 112 月
startIndex += length;
byte[] BMSProductionDateMonthByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String bmsProductionDateMonth = BytesUtil.bin2HexStr(BMSProductionDateMonthByteArr);
// BMS 电池组生产日期日 0 日偏移量, 数据范围: 131 日
startIndex += length;
byte[] BMSProductionDateDayByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String bmsProductionDateDay = BytesUtil.bin2HexStr(BMSProductionDateDayByteArr);
// BMS 电池组充电次数 1 次/位, 0 次偏移量, 以 BMS 统 计为准
startIndex += length;
length = 3;
byte[] BMSChargingTimesByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String bmsChargingTimes = BytesUtil.bin2HexStr(BMSChargingTimesByteArr);
// BMS 电池组产权标识 <0> =租赁; <1> =车自有)
startIndex += length;
@@ -112,14 +131,38 @@ public class ChargingHandshakeHandler extends AbstractYkcHandler {
// BMS 车辆识别码
startIndex += length;
length = 17;
byte[] BMSCarIdentifyCodeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
byte[] vinByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String vinCode = YKCUtils.parseVin(vinByteArr);
// BMS 软件版本号
startIndex += length;
length = 8;
byte[] BMSSoftwareVersionByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
// 保存数据到redis(缓存3天)
ChargingHandshakeData data = ChargingHandshakeData.builder()
.transactionCode(transactionCode)
.pileSn(pileSn)
.connectorCode(connectorCode)
.bmsCommunicationVersion(bmsCommunicationVersion)
.bmsBatteryType(bmsBatteryType)
.bmsBatteryCapacity(bmsBatteryCapacity)
.bmsBatteryVoltage(bmsBatteryVoltage)
.bmsBatteryFactory(bmsBatteryFactory)
.bmsBatteryNum(bmsBatteryNum)
.bmsProductionDateYear(bmsProductionDateYear)
.bmsProductionDateMonth(bmsProductionDateMonth)
.bmsProductionDateDay(bmsProductionDateDay)
.bmsChargingTimes(bmsChargingTimes)
// .BMSPropertyIdentificationByteArr(BMSPropertyIdentificationByteArr)
// .BMSReservePosition(BMSReservePosition)
.vinCode(vinCode)
// .BMSSoftwareVersionByteArr(BMSSoftwareVersionByteArr)
.build();
String redisKey = CacheConstants.CHARGING_HANDSHAKE_DATA_BY_TRANSACTION_CODE + transactionCode;
redisCache.setCacheObject(redisKey, data, 3, TimeUnit.DAYS);
return null;
}

View File

@@ -6,13 +6,17 @@ 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.common.util.spring.SpringUtils;
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.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;
import java.util.concurrent.CompletableFuture;
/**
* 充电桩心跳包
*/
@@ -25,6 +29,9 @@ public class HeartbeatRequestHandler extends AbstractYkcHandler {
@Autowired
private PileBasicInfoService pileBasicInfoService;
// 引入线程池
private ThreadPoolTaskExecutor executor = SpringUtils.getBean("threadPoolTaskExecutor");
@Override
public void afterPropertiesSet() throws Exception {
YKCOperateFactory.register(type, this);
@@ -65,11 +72,20 @@ public class HeartbeatRequestHandler extends AbstractYkcHandler {
// updateStatus(pileSn, pileConnectorNum, connectorStatus);
// 公共方法修改状态
try {
pileBasicInfoService.updateStatus(BytesUtil.bcd2Str(ykcDataProtocol.getFrameType()), pileSn, pileConnectorNum, connectorStatus, null);
} catch (Exception e) {
log.error("公共方法修改状态error", e);
}
// try {
// pileBasicInfoService.updateStatus(BytesUtil.bcd2Str(ykcDataProtocol.getFrameType()), pileSn, pileConnectorNum, connectorStatus, null);
// } catch (Exception e) {
// log.error("公共方法修改状态error", e);
// }
// 异步修改状态
CompletableFuture.runAsync(() -> {
try {
pileBasicInfoService.updateStatus(BytesUtil.bcd2Str(ykcDataProtocol.getFrameType()), pileSn, pileConnectorNum, connectorStatus, null);
} catch (Exception e) {
log.error("公共方法修改状态error", e);
}
}, executor);
// 心跳应答置0
byte[] flag = Constants.zeroByteArray;

View File

@@ -157,6 +157,9 @@ public class ParameterConfigurationHandler extends AbstractYkcHandler {
.build();
orderBasicInfoService.updateOrderBasicInfo(orderBasicInfo);
log.info("更新订单起始SOC, orderCode:{}, transactionCode:{}, startSoc:{}", orderInfo.getOrderCode(), transactionCode, soc);
// 保存此订单的soc
YKCUtils.saveSOC(transactionCode, data.getSoc());
}
return null;

View File

@@ -81,251 +81,253 @@ public class TransactionRecordsRequestHandler extends AbstractYkcHandler {
private PersonalChargingRecordService personalChargingRecordService;
/*public static void main(String[] args) {
BigDecimal totalElectricity = new BigDecimal("23.73");
if (totalElectricity.compareTo(BigDecimal.TEN) > 0) {
// 充电度数大于10度
System.out.println("123");
}
// 获取消息体
String msg = "000000000000000000000000000000008823000000030601a08c2e0d0404170000380d0404170000000000000000000000000000000000000000000000000000000000000000400d0300ee250000ee250000c84b000000000000000000000000000000000000e0bb040000cee1040000ee250000ee250000c84b00000000000000000000000000000000000000010000380d04041745a511101970000000";
byte[] msgBody = BytesUtil.str2Bcd(msg);
int startIndex = 0;
int length = 16;
// 交易流水号
byte[] orderCodeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String transactionCode = BytesUtil.bcd2Str(orderCodeByteArr);
// 桩编码
startIndex += length;
length = 7;
byte[] pileSnByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String pileSn = BytesUtil.bcd2Str(pileSnByteArr);
// 枪号
startIndex += length;
length = 1;
byte[] connectorCodeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String connectorCode = BytesUtil.bcd2Str(connectorCodeByteArr);
// 开始时间 CP56Time2a 格式
startIndex += length;
length = 7;
byte[] startTimeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
// String binary = BytesUtil.binary(startTimeByteArr, 16);
Date startDate = Cp56Time2aUtil.byte2Hdate(startTimeByteArr);
String startTime = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, startDate);
// 结束时间 CP56Time2a 格式
startIndex += length;
byte[] endTimeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
Date endDate = Cp56Time2aUtil.byte2Hdate(endTimeByteArr);
String endTime = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, endDate);
// 尖单价 精确到小数点后五位(尖电费+尖服务费,见费率帧)
startIndex += length;
length = 4;
byte[] sharpPriceByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String sharpPrice = YKCUtils.convertDecimalPoint(sharpPriceByteArr, 5);
// 尖电量 精确到小数点后四位
startIndex += length;
length = 4;
byte[] sharpUsedElectricityByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String sharpUsedElectricity = YKCUtils.convertDecimalPoint(sharpUsedElectricityByteArr, 4);
// 计损尖电量
startIndex += length;
byte[] sharpPlanLossElectricityByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String sharpPlanLossElectricity = YKCUtils.convertDecimalPoint(sharpPlanLossElectricityByteArr, 4);
// 尖金额
startIndex += length;
byte[] sharpAmountByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String sharpAmount = YKCUtils.convertDecimalPoint(sharpAmountByteArr, 4);
// 峰单价 精确到小数点后五位(峰电费+峰服务费)
startIndex += length;
byte[] peakPriceByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String peakPrice = YKCUtils.convertDecimalPoint(peakPriceByteArr, 5);
// 峰电量
startIndex += length;
byte[] peakUsedElectricityByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String peakUsedElectricity = YKCUtils.convertDecimalPoint(peakUsedElectricityByteArr, 4);
// 计损峰电量
startIndex += length;
byte[] peakPlanLossElectricityByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String peakPlanLossElectricity = YKCUtils.convertDecimalPoint(peakPlanLossElectricityByteArr, 4);
// 峰金额
startIndex += length;
byte[] peakAmountByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String peakAmount = YKCUtils.convertDecimalPoint(peakAmountByteArr, 4);
// 平单价 精确到小数点后五位(平电费+平服务费)
startIndex += length;
byte[] flatPriceByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String flatPrice = YKCUtils.convertDecimalPoint(flatPriceByteArr, 5);
// 平电量
startIndex += length;
byte[] flatUsedElectricityByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String flatUsedElectricity = YKCUtils.convertDecimalPoint(flatUsedElectricityByteArr, 4);
// 计损平电量
startIndex += length;
byte[] flatPlanLossElectricityByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String flatPlanLossElectricity = YKCUtils.convertDecimalPoint(flatPlanLossElectricityByteArr, 4);
// 平金额
startIndex += length;
byte[] flatAmountByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String flatAmount = YKCUtils.convertDecimalPoint(flatAmountByteArr, 4);
// 谷单价 精确到小数点后五位(谷电费+谷 服务费)
startIndex += length;
byte[] valleyPriceByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String valleyPrice = YKCUtils.convertDecimalPoint(valleyPriceByteArr, 5);
// 谷电量
startIndex += length;
byte[] valleyUsedElectricityByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String valleyUsedElectricity = YKCUtils.convertDecimalPoint(valleyUsedElectricityByteArr, 4);
// 计损谷电量
startIndex += length;
byte[] valleyPlanLossElectricityByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String valleyPlanLossElectricity = YKCUtils.convertDecimalPoint(valleyPlanLossElectricityByteArr, 4);
// 谷金额
startIndex += length;
byte[] valleyAmountByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String valleyAmount = YKCUtils.convertDecimalPoint(valleyAmountByteArr, 4);
// 电表总起值
startIndex += length;
length = 5;
byte[] ammeterTotalStartByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String ammeterTotalStart = YKCUtils.convertDecimalPoint(ammeterTotalStartByteArr, 4);
// 电表总止值
startIndex += length;
byte[] ammeterTotalEndByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String ammeterTotalEnd = YKCUtils.convertDecimalPoint(ammeterTotalEndByteArr, 4);
// 总电量
startIndex += length;
length = 4;
byte[] totalElectricityByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
// String totalElectricity = YKCUtils.convertDecimalPoint(totalElectricityByteArr, 4);
// 计损总电量
startIndex += length;
byte[] planLossTotalElectricityByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String planLossTotalElectricity = YKCUtils.convertDecimalPoint(planLossTotalElectricityByteArr, 4);
// 消费金额 精确到小数点后四位,包含电费、 服务费
startIndex += length;
byte[] consumptionAmountByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String consumptionAmount = YKCUtils.convertDecimalPoint(consumptionAmountByteArr, 4);
// VIN 码 VIN 码,此处 VIN 码和充电时 VIN 码不同, 正序直接上传, 无需补 0 和反序
startIndex += length;
length = 17;
byte[] vinCodeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String vinCode = BytesUtil.ascii2Str(vinCodeByteArr);
*//**
* 交易标识
* 0x01 app 启动
* 0x02卡启动
* 0x04离线卡启动
* 0x05: vin 码启动充电
*//*
startIndex += length;
length = 1;
byte[] transactionIdentifierByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String transactionIdentifier = BytesUtil.bcd2Str(transactionIdentifierByteArr);
// 交易时间 CP56Time2a 格式
startIndex += length;
length = 7;
byte[] transactionTimeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
Date transactionDate = Cp56Time2aUtil.byte2Hdate(transactionTimeByteArr);
String transactionTime = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, transactionDate);
// 停止原因
startIndex += length;
length = 1;
byte[] stopReasonByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String stopReason = BytesUtil.bin2HexStr(stopReasonByteArr);
String stopReasonMsg = YKCChargingStopReasonEnum.getMsgByCode(Integer.parseInt(stopReason, 16));
// 物理卡号 不足 8 位补 0
startIndex += length;
length = 8;
byte[] cardNumByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
// byte[] logicCardNum = BytesUtil.checkLengthAndBehindAppendZero(cardNumByteArr, 16);
String logicCard = BytesUtil.binary(cardNumByteArr, 16);
log.info("桩号:{}, 发送交易记录物理卡号:{}", pileSn, logicCard);
log.info("[===交易记录===]交易流水号:{}, 桩编号:{}, 枪号:{}, 开始时间:{}, 结束时间:{}, 尖单价:{}, 尖电量:{}, 计损尖电量:{}, 尖金额:{}, " +
"峰单价:{}, 峰电量:{}, 计损峰电量:{}, 峰金额:{}, 平单价:{}, 平电量:{}, 计损平电量:{}, 平金额:{}, " +
"谷单价:{}, 谷电量:{}, 计损谷电量:{}, 谷金额:{}, 电表总起值:{}, 电表总止值:{}, 电量:{}, 计损电量:{}, 消费金额:{}, " +
"电动汽车唯一标识:{}, 交易标识:{}, 交易日期、时间:{}, 停止原因码:{}, 停止原因描述:{}, 物理卡号:{}",
transactionCode, pileSn, connectorCode, startTime, endTime, sharpPrice, sharpUsedElectricity, sharpPlanLossElectricity, sharpAmount,
peakPrice, peakUsedElectricity, peakPlanLossElectricity, peakAmount, flatPrice, flatUsedElectricity, flatPlanLossElectricity, flatAmount,
valleyPrice, valleyUsedElectricity, valleyPlanLossElectricity, valleyAmount, ammeterTotalStart, ammeterTotalEnd, totalElectricity, planLossTotalElectricity,
consumptionAmount, vinCode, transactionIdentifier, transactionTime, stopReason, stopReasonMsg, logicCard);
// 交易记录封装到对象里
TransactionRecordsData data = TransactionRecordsData.builder()
// .orderCode(transactionCode)
.transactionCode(transactionCode)
.pileSn(pileSn)
.connectorCode(connectorCode)
.startTime(startTime)
.endTime(endTime)
.sharpPrice(sharpPrice)
.sharpUsedElectricity(sharpUsedElectricity)
.sharpPlanLossElectricity(sharpPlanLossElectricity)
.sharpAmount(sharpAmount)
.peakPrice(peakPrice)
.peakUsedElectricity(peakUsedElectricity)
.peakPlanLossElectricity(peakPlanLossElectricity)
.peakAmount(peakAmount)
.flatPrice(flatPrice)
.flatUsedElectricity(flatUsedElectricity)
.flatPlanLossElectricity(flatPlanLossElectricity)
.flatAmount(flatAmount)
.valleyPrice(valleyPrice)
.valleyUsedElectricity(valleyUsedElectricity)
.valleyPlanLossElectricity(valleyPlanLossElectricity)
.valleyAmount(valleyAmount)
.ammeterTotalStart(ammeterTotalStart)
.ammeterTotalEnd(ammeterTotalEnd)
// .totalElectricity(totalElectricity)
.planLossTotalElectricity(planLossTotalElectricity)
.consumptionAmount(consumptionAmount)
.vinCode(vinCode)
.transactionIdentifier(transactionIdentifier)
.transactionTime(transactionTime)
.stopReasonMsg(stopReasonMsg)
.logicCard(logicCard)
.build();
boolean flag = !StringUtils.equals("0000000000000000", "a511101970000000");
System.out.println(flag);
}*/
// public static void main(String[] args) {
// // BigDecimal totalElectricity = new BigDecimal("23.73");
// // if (totalElectricity.compareTo(BigDecimal.TEN) > 0) {
// // // 充电度数大于10度
// // System.out.println("123");
// // }
//
//
// // 获取消息体
// // String msg = "000000000000000000000000000000008823000000030601a08c2e0d0404170000380d0404170000000000000000000000000000000000000000000000000000000000000000400d0300ee250000ee250000c84b000000000000000000000000000000000000e0bb040000cee1040000ee250000ee250000c84b00000000000000000000000000000000000000010000380d04041745a511101970000000";
// // byte[] msgBody = BytesUtil.str2Bcd(msg);
// //
// // int startIndex = 0;
// // int length = 16;
// //
// // // 交易流水号
// // byte[] orderCodeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
// // String transactionCode = BytesUtil.bcd2Str(orderCodeByteArr);
// //
// // // 桩编码
// // startIndex += length;
// // length = 7;
// // byte[] pileSnByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
// // String pileSn = BytesUtil.bcd2Str(pileSnByteArr);
// //
// // // 枪号
// // startIndex += length;
// // length = 1;
// // byte[] connectorCodeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
// // String connectorCode = BytesUtil.bcd2Str(connectorCodeByteArr);
// //
// //
// // // 开始时间 CP56Time2a 格式
// // startIndex += length;
// // length = 7;
// // byte[] startTimeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
// // // String binary = BytesUtil.binary(startTimeByteArr, 16);
// // Date startDate = Cp56Time2aUtil.byte2Hdate(startTimeByteArr);
// // String startTime = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, startDate);
// //
// //
// // // 结束时间 CP56Time2a 格式
// // startIndex += length;
// // byte[] endTimeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
// // Date endDate = Cp56Time2aUtil.byte2Hdate(endTimeByteArr);
// // String endTime = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, endDate);
// //
// // // 尖单价 精确到小数点后五位(尖电费+尖服务费,见费率帧)
// // startIndex += length;
// // length = 4;
// // byte[] sharpPriceByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
// // String sharpPrice = YKCUtils.convertDecimalPoint(sharpPriceByteArr, 5);
// //
// // // 尖电量 精确到小数点后四位
// // startIndex += length;
// // length = 4;
// // byte[] sharpUsedElectricityByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
// // String sharpUsedElectricity = YKCUtils.convertDecimalPoint(sharpUsedElectricityByteArr, 4);
// //
// // // 计损尖电量
// // startIndex += length;
// // byte[] sharpPlanLossElectricityByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
// // String sharpPlanLossElectricity = YKCUtils.convertDecimalPoint(sharpPlanLossElectricityByteArr, 4);
// //
// // // 尖金额
// // startIndex += length;
// // byte[] sharpAmountByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
// // String sharpAmount = YKCUtils.convertDecimalPoint(sharpAmountByteArr, 4);
// //
// // // 峰单价 精确到小数点后五位(峰电费+峰服务费)
// // startIndex += length;
// // byte[] peakPriceByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
// // String peakPrice = YKCUtils.convertDecimalPoint(peakPriceByteArr, 5);
// //
// // // 峰电量
// // startIndex += length;
// // byte[] peakUsedElectricityByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
// // String peakUsedElectricity = YKCUtils.convertDecimalPoint(peakUsedElectricityByteArr, 4);
// //
// // // 计损峰电量
// // startIndex += length;
// // byte[] peakPlanLossElectricityByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
// // String peakPlanLossElectricity = YKCUtils.convertDecimalPoint(peakPlanLossElectricityByteArr, 4);
// //
// // // 峰金额
// // startIndex += length;
// // byte[] peakAmountByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
// // String peakAmount = YKCUtils.convertDecimalPoint(peakAmountByteArr, 4);
// //
// // // 平单价 精确到小数点后五位(平电费+平服务费)
// // startIndex += length;
// // byte[] flatPriceByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
// // String flatPrice = YKCUtils.convertDecimalPoint(flatPriceByteArr, 5);
// //
// // // 平电量
// // startIndex += length;
// // byte[] flatUsedElectricityByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
// // String flatUsedElectricity = YKCUtils.convertDecimalPoint(flatUsedElectricityByteArr, 4);
// //
// // // 计损平电量
// // startIndex += length;
// // byte[] flatPlanLossElectricityByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
// // String flatPlanLossElectricity = YKCUtils.convertDecimalPoint(flatPlanLossElectricityByteArr, 4);
// //
// // // 平金额
// // startIndex += length;
// // byte[] flatAmountByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
// // String flatAmount = YKCUtils.convertDecimalPoint(flatAmountByteArr, 4);
// //
// // // 谷单价 精确到小数点后五位(谷电费+谷 服务费)
// // startIndex += length;
// // byte[] valleyPriceByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
// // String valleyPrice = YKCUtils.convertDecimalPoint(valleyPriceByteArr, 5);
// //
// // // 谷电量
// // startIndex += length;
// // byte[] valleyUsedElectricityByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
// // String valleyUsedElectricity = YKCUtils.convertDecimalPoint(valleyUsedElectricityByteArr, 4);
// //
// // // 计损谷电量
// // startIndex += length;
// // byte[] valleyPlanLossElectricityByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
// // String valleyPlanLossElectricity = YKCUtils.convertDecimalPoint(valleyPlanLossElectricityByteArr, 4);
// //
// // // 谷金额
// // startIndex += length;
// // byte[] valleyAmountByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
// // String valleyAmount = YKCUtils.convertDecimalPoint(valleyAmountByteArr, 4);
// //
// // // 电表总起值
// // startIndex += length;
// // length = 5;
// // byte[] ammeterTotalStartByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
// // String ammeterTotalStart = YKCUtils.convertDecimalPoint(ammeterTotalStartByteArr, 4);
// //
// // // 电表总止值
// // startIndex += length;
// // byte[] ammeterTotalEndByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
// // String ammeterTotalEnd = YKCUtils.convertDecimalPoint(ammeterTotalEndByteArr, 4);
// //
// // // 总电量
// // startIndex += length;
// // length = 4;
// // byte[] totalElectricityByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
// // // String totalElectricity = YKCUtils.convertDecimalPoint(totalElectricityByteArr, 4);
// //
// // // 计损总电量
// // startIndex += length;
// // byte[] planLossTotalElectricityByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
// // String planLossTotalElectricity = YKCUtils.convertDecimalPoint(planLossTotalElectricityByteArr, 4);
// //
// // // 消费金额 精确到小数点后四位,包含电费、 服务费
// // startIndex += length;
// // byte[] consumptionAmountByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
// // String consumptionAmount = YKCUtils.convertDecimalPoint(consumptionAmountByteArr, 4);
// //
// // // VIN 码 VIN 码,此处 VIN 码和充电时 VIN 码不同, 正序直接上传, 无需补 0 和反序
// // startIndex += length;
// // length = 17;
// // byte[] vinCodeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
// // String vinCode = BytesUtil.ascii2Str(vinCodeByteArr);
// //
// // /**
// // * 交易标识
// // * 0x01 app 启动
// // * 0x02卡启动
// // * 0x04离线卡启动
// // * 0x05: vin 码启动充电
// // */
// // startIndex += length;
// // length = 1;
// // byte[] transactionIdentifierByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
// // String transactionIdentifier = BytesUtil.bcd2Str(transactionIdentifierByteArr);
// //
// // // 交易时间 CP56Time2a 格式
// // startIndex += length;
// // length = 7;
// // byte[] transactionTimeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
// // Date transactionDate = Cp56Time2aUtil.byte2Hdate(transactionTimeByteArr);
// // String transactionTime = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, transactionDate);
// //
// // // 停止原因
// // startIndex += length;
// // length = 1;
// // byte[] stopReasonByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
// // String stopReason = BytesUtil.bin2HexStr(stopReasonByteArr);
// // int i = Integer.parseInt(stopReason, 16);
// // String stopReasonMsg = YKCChargingStopReasonEnum.getMsgByCode(i);
//
//
// // 物理卡号 不足 8 位补 0
// // startIndex += length;
// // length = 8;
// // byte[] cardNumByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
// // // byte[] logicCardNum = BytesUtil.checkLengthAndBehindAppendZero(cardNumByteArr, 16);
// // String logicCard = BytesUtil.binary(cardNumByteArr, 16);
// // log.info("桩号:{}, 发送交易记录物理卡号:{}", pileSn, logicCard);
// //
// // log.info("[===交易记录===]交易流水号:{}, 桩编号:{}, 枪号:{}, 开始时间:{}, 结束时间:{}, 尖单价:{}, 电量:{}, 计损电量:{}, 金额:{}, " +
// // "峰单价:{}, 峰电量:{}, 计损峰电量:{}, 峰金额:{}, 平单价:{}, 平电量:{}, 计损平电量:{}, 平金额:{}, " +
// // "谷单价:{}, 谷电量:{}, 计损谷电量:{}, 谷金额:{}, 电表总起值:{}, 电表总止值:{}, 总电量:{}, 计损总电量:{}, 消费金额:{}, " +
// // "电动汽车唯一标识:{}, 交易标识:{}, 交易日期、时间:{}, 停止原因码:{}, 停止原因描述:{}, 物理卡号:{}",
// // transactionCode, pileSn, connectorCode, startTime, endTime, sharpPrice, sharpUsedElectricity, sharpPlanLossElectricity, sharpAmount,
// // peakPrice, peakUsedElectricity, peakPlanLossElectricity, peakAmount, flatPrice, flatUsedElectricity, flatPlanLossElectricity, flatAmount,
// // valleyPrice, valleyUsedElectricity, valleyPlanLossElectricity, valleyAmount, ammeterTotalStart, ammeterTotalEnd, totalElectricity, planLossTotalElectricity,
// // consumptionAmount, vinCode, transactionIdentifier, transactionTime, stopReason, stopReasonMsg, logicCard);
// //
// // // 交易记录封装到对象里
// // TransactionRecordsData data = TransactionRecordsData.builder()
// // // .orderCode(transactionCode)
// // .transactionCode(transactionCode)
// // .pileSn(pileSn)
// // .connectorCode(connectorCode)
// // .startTime(startTime)
// // .endTime(endTime)
// // .sharpPrice(sharpPrice)
// // .sharpUsedElectricity(sharpUsedElectricity)
// // .sharpPlanLossElectricity(sharpPlanLossElectricity)
// // .sharpAmount(sharpAmount)
// // .peakPrice(peakPrice)
// // .peakUsedElectricity(peakUsedElectricity)
// // .peakPlanLossElectricity(peakPlanLossElectricity)
// // .peakAmount(peakAmount)
// // .flatPrice(flatPrice)
// // .flatUsedElectricity(flatUsedElectricity)
// // .flatPlanLossElectricity(flatPlanLossElectricity)
// // .flatAmount(flatAmount)
// // .valleyPrice(valleyPrice)
// // .valleyUsedElectricity(valleyUsedElectricity)
// // .valleyPlanLossElectricity(valleyPlanLossElectricity)
// // .valleyAmount(valleyAmount)
// // .ammeterTotalStart(ammeterTotalStart)
// // .ammeterTotalEnd(ammeterTotalEnd)
// // // .totalElectricity(totalElectricity)
// // .planLossTotalElectricity(planLossTotalElectricity)
// // .consumptionAmount(consumptionAmount)
// // .vinCode(vinCode)
// // .transactionIdentifier(transactionIdentifier)
// // .transactionTime(transactionTime)
// // .stopReasonMsg(stopReasonMsg)
// // .logicCard(logicCard)
// // .build();
// //
// // boolean flag = !StringUtils.equals("0000000000000000", "a511101970000000");
// // System.out.println(flag);
//
// }
@Override
public byte[] supplyProcess(YKCDataProtocol ykcDataProtocol, ChannelHandlerContext channel) {
@@ -559,6 +561,7 @@ public class TransactionRecordsRequestHandler extends AbstractYkcHandler {
.vinCode(vinCode)
.transactionIdentifier(transactionIdentifier)
.transactionTime(transactionTime)
.stopReasonCode(stopReason)
.stopReasonMsg(stopReasonMsg)
.logicCard(logicCard)
.build();
@@ -635,6 +638,9 @@ public class TransactionRecordsRequestHandler extends AbstractYkcHandler {
orderBasicInfo.setChargeEndTime(new Date());
}
// 将停止原因码存库
orderBasicInfo.setStopReasonCode("0x" + data.getStopReasonCode());
orderBasicInfoService.updateOrderBasicInfo(orderBasicInfo);
// 重新查询订单信息

View File

@@ -288,6 +288,9 @@ public class UploadRealTimeMonitorHandler extends AbstractYkcHandler {
// 查询数据库中该订单当前信息
OrderBasicInfo orderInfo = orderBasicInfoService.getOrderInfoByTransactionCode(transactionCode);
if (Objects.nonNull(orderInfo)) {
// 保存此订单的soc
YKCUtils.saveSOC(transactionCode, realTimeMonitorData.getSOC());
if (StringUtils.equals(orderInfo.getOrderStatus(), OrderStatusEnum.ORDER_COMPLETE.getValue())
|| StringUtils.equals(orderInfo.getOrderStatus(), OrderStatusEnum.STAY_SETTLEMENT.getValue())) {
// 在订单状态为 订单完成或待结算,不保存

View File

@@ -32,6 +32,9 @@ public class NettyServerManager implements CommandLineRunner {
@Resource
private ElectricBicyclesServerChannelInitializer electricBicyclesServerChannelInitializer;
private int bossGroupSize = Runtime.getRuntime().availableProcessors();
private int workerGroupSize = bossGroupSize * 2;
@Override
public void run(String... args) throws Exception {
startNettyServer(Constants.SOCKET_IP, 9011);
@@ -41,8 +44,8 @@ public class NettyServerManager implements CommandLineRunner {
public void startNettyServer(String host, int port) {
new Thread(() -> {
EventLoopGroup bossGroup = new NioEventLoopGroup(1);
EventLoopGroup workerGroup = new NioEventLoopGroup();
EventLoopGroup bossGroup = new NioEventLoopGroup(bossGroupSize);
EventLoopGroup workerGroup = new NioEventLoopGroup(workerGroupSize);
try {
ServerBootstrap bootstrap = new ServerBootstrap()
@@ -51,14 +54,17 @@ public class NettyServerManager implements CommandLineRunner {
.handler(new LoggingHandler(LogLevel.DEBUG))
// .option(ChannelOption.SO_BACKLOG, 128) // 默认128
.option(ChannelOption.SO_BACKLOG, 1024)
.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT) // 启用池化内存分配器
// .option(ChannelOption.SO_REUSEADDR, true)
.childOption(ChannelOption.SO_KEEPALIVE, true) // 保持连接
// .childOption(ChannelOption.SO_RCVBUF, 64 * 1024) // 接收缓冲区
.childOption(ChannelOption.SO_RCVBUF, 1024 * 1024) // 接收缓冲区
// .childOption(ChannelOption.SO_SNDBUF, 64 * 1024) // 发送缓冲区
.childOption(ChannelOption.SO_SNDBUF, 1024 * 1024) // 发送缓冲区
.childOption(ChannelOption.TCP_NODELAY, true) // 禁用 Nagle 算法
.childOption(ChannelOption.SO_RCVBUF, 64 * 1024) // 接收缓冲区
.childOption(ChannelOption.SO_SNDBUF, 64 * 1024) // 发送缓冲区
.childOption(ChannelOption.WRITE_BUFFER_WATER_MARK, new WriteBufferWaterMark(32 * 1024, 64 * 1024)) // 写缓冲水位
.childOption(ChannelOption.SO_REUSEADDR, true)
.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT) // 启用池化内存分配器
// .childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT) // 启用池化内存分配器
.childHandler(nettyServerChannelInitializer)
.localAddress(new InetSocketAddress(host, port));
@@ -130,6 +136,7 @@ public class NettyServerManager implements CommandLineRunner {
.localAddress(new InetSocketAddress(host, port));
mqttBootstrap.childHandler(new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(SocketChannel ch) {
ChannelPipeline channelPipeline = ch.pipeline();
// 设置读写空闲超时时间