From ddcf6abb3e0c6dd58203068a63d3fd88b709859e Mon Sep 17 00:00:00 2001 From: jsowell <123@jsowell.com> Date: Fri, 26 Jun 2026 14:55:07 +0800 Subject: [PATCH] =?UTF-8?q?update=20=E9=A2=84=E7=BA=A6=E5=85=85=E7=94=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pile/service/PileRemoteService.java | 103 +++++++++++++++++- 1 file changed, 101 insertions(+), 2 deletions(-) diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/PileRemoteService.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/PileRemoteService.java index 4005dd5c4..05a1eee1e 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/service/PileRemoteService.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/PileRemoteService.java @@ -22,7 +22,6 @@ import com.jsowell.pile.domain.ykcCommond.*; import com.jsowell.pile.dto.PublishBillingTemplateDTO; import com.jsowell.pile.dto.RemoteAccountBalanceUpdateDTO; import com.jsowell.pile.dto.UpdateFirmwareDTO; -import com.jsowell.pile.vo.base.ConnectorInfoVO; import com.jsowell.pile.vo.web.BillingTemplateVO; import com.jsowell.pile.vo.web.PileDetailVO; import com.jsowell.wxpay.service.WxAppletRemoteService; @@ -520,11 +519,86 @@ public class PileRemoteService { /** * 羽信预约充电指令 + * * @return result: 1-成功; 0-失败 */ public String yuxinReservationCharging(YuxinReservationChargingCommand command) { byte[] bytes = ykcPushCommandService.pushYuxinReservationChargingCommand(command); - return parseReservationChargingResponse(bytes); + return parseYuxinReservationChargingResponse(bytes); + } + + private String parseYuxinReservationChargingResponse(byte[] bytes) { + String result = "0"; + if (Objects.isNull(bytes)) { + log.warn("羽信预约启动充电回复为空, 原始报文:null"); + return result; + } + + String rawMessage = BytesUtil.bin2HexStr(bytes); + try { + YKCDataProtocol ykcDataProtocol = new YKCDataProtocol(bytes); + String responseFrameType = YKCUtils.frameType2Str(ykcDataProtocol.getFrameType()); + byte[] msgBody = ykcDataProtocol.getMsgBody(); + if (!StringUtils.equals(responseFrameType, + YKCUtils.frameType2Str(YKCFrameTypeCode.YUXIN_RESERVATION_CHARGING_SETUP_ANSWER_CODE.getBytes()))) { + log.warn("羽信预约启动充电回复帧类型异常, 帧类型:{}, 原始报文:{}", responseFrameType, rawMessage); + return result; + } + if (Objects.isNull(msgBody) || msgBody.length < 27) { + log.warn("羽信预约启动充电回复长度异常, 帧类型:{}, 报文体长度:{}, 原始报文:{}", + responseFrameType, Objects.isNull(msgBody) ? null : msgBody.length, rawMessage); + return result; + } + + int startIndex = 0; + int length = 16; + byte[] transactionCodeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String transactionCode = BytesUtil.bcd2Str(transactionCodeByteArr); + + 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 = parseYuxinConnectorCode(connectorCodeByteArr); + + startIndex += length; + length = 1; + byte[] reservationTypeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String reservationType = BytesUtil.bin2HexStr(reservationTypeByteArr); + + startIndex += length; + length = 1; + byte[] resultCodeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String resultCode = BytesUtil.bin2HexStr(resultCodeByteArr); + + startIndex += length; + length = 1; + byte[] failedReasonByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); + String failedReason = BytesUtil.bin2HexStr(failedReasonByteArr); + String failedReasonMsg = getYuxinFailedReasonMsg(failedReason); + + if (StringUtils.equals(resultCode, "01")) { + result = "1"; + } + + log.info("{}羽信预约启动充电回复sync, 交易流水号:{}, 桩SN:{}, 枪口号:{}({}), 预约方式:{}({}), 设置结果:{}({}), 失败原因:{}({}), 原始报文:{}", + responseFrameType, transactionCode, pileSn, connectorCode, getYuxinConnectorCodeMsg(connectorCode), + reservationType, getYuxinReservationTypeMsg(reservationType), + resultCode, getYuxinSetupResultMsg(resultCode), failedReason, failedReasonMsg, rawMessage); + if (!StringUtils.equals(resultCode, "01")) { + log.warn("羽信预约启动充电设置失败, 交易流水号:{}, 桩SN:{}, 枪口号:{}({}), 失败原因:{}({}), 原始报文:{}", + transactionCode, pileSn, connectorCode, getYuxinConnectorCodeMsg(connectorCode), + failedReason, failedReasonMsg, rawMessage); + } + } catch (Exception e) { + log.warn("羽信预约启动充电回复解析异常, 原始报文:{}", rawMessage, e); + } + + return result; } private String parseReservationChargingResponse(byte[] bytes) { @@ -601,6 +675,31 @@ public class PileRemoteService { return String.format("%02d", connectorCodeByteArr[0] & 0xFF); } + private String getYuxinConnectorCodeMsg(String connectorCode) { + if (StringUtils.equals(connectorCode, "00")) { + return "所有枪"; + } + return Integer.parseInt(connectorCode) + "号枪"; + } + + private String getYuxinReservationTypeMsg(String reservationType) { + if (StringUtils.equals(reservationType, "00")) { + return "立即预约"; + } else if (StringUtils.equals(reservationType, "01")) { + return "取消预约"; + } + return reservationType; + } + + private String getYuxinSetupResultMsg(String resultCode) { + if (StringUtils.equals(resultCode, "00")) { + return "失败"; + } else if (StringUtils.equals(resultCode, "01")) { + return "成功"; + } + return resultCode; + } + private String getYuxinFailedReasonMsg(String failedReason) { if (StringUtils.equals(failedReason, "00")) { return "无";