羽信预约充电

This commit is contained in:
Guoqs
2026-06-18 13:06:06 +08:00
parent bde9d450e9
commit da1da312c7
4 changed files with 200 additions and 111 deletions

View File

@@ -5,6 +5,7 @@ import com.google.common.collect.Lists;
import com.jsowell.common.constant.CacheConstants;
import com.jsowell.common.constant.Constants;
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.enums.ebike.EBikeChargeResponseEnum;
import com.jsowell.common.enums.ykc.ChargingFailedReasonEnum;
@@ -513,13 +514,16 @@ public class PileRemoteService {
* @return result: 1-成功; 0-失败
*/
public String reservationCharging(ReservationChargingCommand command) {
String result = "1";
String result = "0";
byte[] bytes = ykcPushCommandService.pushReservationChargingCommand(command);
// 解析结果
if (Objects.isNull(bytes)) {
result = "0";
} else {
YKCDataProtocol ykcDataProtocol = new YKCDataProtocol(bytes);
String responseFrameType = YKCUtils.frameType2Str(ykcDataProtocol.getFrameType());
boolean yuxinResponse = StringUtils.equals(responseFrameType,
YKCUtils.frameType2Str(YKCFrameTypeCode.YUXIN_RESERVATION_CHARGING_SETUP_ANSWER_CODE.getBytes()));
byte[] msgBody = ykcDataProtocol.getMsgBody();
int startIndex = 0;
int length = 16;
@@ -538,17 +542,24 @@ public class PileRemoteService {
startIndex += length;
length = 1;
byte[] connectorCodeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String connectorCode = BytesUtil.bcd2Str(connectorCodeByteArr);
String connectorCode = yuxinResponse ? parseYuxinConnectorCode(connectorCodeByteArr) : BytesUtil.bcd2Str(connectorCodeByteArr);
String reservationType = null;
if (yuxinResponse) {
// 羽信0xB1在枪号后多一个预约方式字段: 0x00 立即预约, 0x01 取消预约。
startIndex += length;
length = 1;
byte[] reservationTypeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
reservationType = BytesUtil.bin2HexStr(reservationTypeByteArr);
}
// 启动结果 0x00失败 0x01成功
startIndex += length;
length = 1;
byte[] resultCodeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String resultCode = BytesUtil.bcd2Str(resultCodeByteArr);
String resultCode = yuxinResponse ? BytesUtil.bin2HexStr(resultCodeByteArr) : BytesUtil.bcd2Str(resultCodeByteArr);
if (StringUtils.equals(resultCode, "00")) {
result = "0";
} else {
if (StringUtils.equals(resultCode, "01")) {
result = "1";
}
@@ -556,15 +567,38 @@ public class PileRemoteService {
startIndex += length;
length = 1;
byte[] failedReasonByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String failedReason = BytesUtil.bcd2Str(failedReasonByteArr);
String failedReasonMsg = ChargingFailedReasonEnum.getMsgByCode(Integer.parseInt(failedReason, 16));
String failedReason = yuxinResponse ? BytesUtil.bin2HexStr(failedReasonByteArr) : BytesUtil.bcd2Str(failedReasonByteArr);
String failedReasonMsg = yuxinResponse
? getYuxinFailedReasonMsg(failedReason)
: ChargingFailedReasonEnum.getMsgByCode(Integer.parseInt(failedReason, 16));
String responseFrameType = YKCUtils.frameType2Str(ykcDataProtocol.getFrameType());
log.info("{}预约充电响应sync, 交易流水号:{}, 桩SN:{}, 枪口号:{}, 结果(00-失败; 01成功):{}, 失败原因:{}",
responseFrameType, transactionCode, pileSn, connectorCode, resultCode, failedReasonMsg);
if (yuxinResponse) {
log.info("{}预约充电响应sync, 交易流水号:{}, 桩SN:{}, 枪口号:{}, 预约方式:{}, 结果(00-失败; 01成功):{}, 失败原因:{}",
responseFrameType, transactionCode, pileSn, connectorCode, reservationType, resultCode, failedReasonMsg);
} else {
log.info("{}预约充电响应sync, 交易流水号:{}, 桩SN:{}, 枪口号:{}, 结果(00-失败; 01成功):{}, 失败原因:{}",
responseFrameType, transactionCode, pileSn, connectorCode, resultCode, failedReasonMsg);
}
}
return result;
}
private String parseYuxinConnectorCode(byte[] connectorCodeByteArr) {
return String.format("%02d", connectorCodeByteArr[0] & 0xFF);
}
private String getYuxinFailedReasonMsg(String failedReason) {
if (StringUtils.equals(failedReason, "00")) {
return "";
} else if (StringUtils.equals(failedReason, "01")) {
return "保存失败";
} else if (StringUtils.equals(failedReason, "02")) {
return "系统当前时间小于主板时间";
} else if (StringUtils.equals(failedReason, "03")) {
return "预约时间小于当前时间";
}
return failedReason;
}
}