update 0xA1双枪并充逻辑

This commit is contained in:
Lemon
2025-08-05 16:17:46 +08:00
parent 5fddbd8e8c
commit 9adc5761bf
3 changed files with 105 additions and 33 deletions

View File

@@ -1,14 +1,17 @@
package com.jsowell.netty.handler.yunkuaichong;
import com.alibaba.fastjson2.JSON;
import com.google.common.primitives.Bytes;
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.util.BytesUtil;
import com.jsowell.common.util.StringUtils;
import com.jsowell.common.util.YKCUtils;
import com.jsowell.netty.factory.YKCOperateFactory;
import com.jsowell.pile.dto.VerifyMergeChargeOrderDTO;
import com.jsowell.pile.service.OrderBasicInfoService;
import com.jsowell.pile.service.PileMsgRecordService;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
@@ -31,6 +34,8 @@ public class PileApplyMergeChargeHandler extends AbstractYkcHandler{
@Autowired
private OrderBasicInfoService orderBasicInfoService;
@Autowired
private PileMsgRecordService pileMsgRecordService;
@Override
public void afterPropertiesSet() throws Exception {
@@ -38,7 +43,7 @@ public class PileApplyMergeChargeHandler extends AbstractYkcHandler{
}
@Override
public byte[] supplyProcess(YKCDataProtocol ykcDataProtocol, ChannelHandlerContext channel) {
public byte[] supplyProcess(YKCDataProtocol ykcDataProtocol, ChannelHandlerContext channel){
// 获取消息体
byte[] msgBody = ykcDataProtocol.getMsgBody();
@@ -118,34 +123,47 @@ public class PileApplyMergeChargeHandler extends AbstractYkcHandler{
.mergeChargeNumber(mergeChargeNumber)
.build();
Map<String, Object> map = new LinkedHashMap<>();
Map<String, String> map = new LinkedHashMap<>();
String transactionCode = Constants.ILLEGAL_TRANSACTION_CODE;
byte[] authenticationFlagByteArr = Constants.zeroByteArray; // 鉴权成功标识
byte[] accountBalanceByteArr = Constants.zeroByteArray; // 账户余额
byte[] defeatReasonByteArr = Constants.zeroByteArray;
try {
map = orderBasicInfoService.verifyMergeChargeOrder(dto);
log.info("桩号:{}, 并充订单鉴权成功, 结果map:{}", pileSn, map);
} catch (Exception e) {
log.error("桩号:{}, 并充订单鉴权失败, ", pileSn, e);
}
if (map != null) {
transactionCode = (String) map.get("transactionCode");
accountBalanceByteArr = YKCUtils.getPriceByte(String.valueOf(map.get("accountBalance")), 2);
String transactionCode = map.get("transactionCode");
// 如果交易流水号不等于Constants.ILLEGAL_TRANSACTION_CODE, 表示鉴权通过
if (!StringUtils.equals(transactionCode, Constants.ILLEGAL_TRANSACTION_CODE)) {
authenticationFlagByteArr = Constants.oneByteArray;
} else {
// 鉴权失败
authenticationFlagByteArr = Constants.zeroByteArray;
}
accountBalanceByteArr = YKCUtils.getPriceByte(String.valueOf(map.get("accountBalance")), 2);
// 应答
// 交易流水号
byte[] serialNumByteArr = BytesUtil.str2Bcd(transactionCode);
// 桩编号
// 枪号
// 逻辑卡号
// 账户余额
// 鉴权成功标志
// 失败原因
if (map.get("defeatReasonCode") != null) {
defeatReasonByteArr = BytesUtil.str2Bcd(map.get("defeatReasonCode"));
}
// 并充序号
byte[] defeatReasonByteArr = Constants.zeroByteArray; // 失败原因
byte[] msgBodyByteArr = Bytes.concat(BytesUtil.str2Bcd(transactionCode), pileSnByteArr, connectorNumByteArr, cardNumByteArr,
// 保存报文
String jsonMsg = JSON.toJSONString(dto);
pileMsgRecordService.save(pileSn, pileSn, type, jsonMsg, ykcDataProtocol.getHEXString());
byte[] msgBodyByteArr = Bytes.concat(serialNumByteArr, pileSnByteArr, connectorNumByteArr, cardNumByteArr,
accountBalanceByteArr, authenticationFlagByteArr, defeatReasonByteArr, mergeChargeNumberByteArr);
return getResult(ykcDataProtocol, msgBodyByteArr);