mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-20 19:15:35 +08:00
新增 0xA1并充相关逻辑
This commit is contained in:
@@ -0,0 +1,145 @@
|
||||
package com.jsowell.netty.handler.yunkuaichong;
|
||||
|
||||
import com.google.common.primitives.Bytes;
|
||||
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.dto.VerifyMergeChargeOrderDTO;
|
||||
import com.jsowell.pile.service.OrderBasicInfoService;
|
||||
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.Map;
|
||||
|
||||
/**
|
||||
* 0xA1 充电桩主动申请并充充电
|
||||
*
|
||||
* @author Lemon
|
||||
* @Date 2025/6/12 11:37:36
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class PileApplyMergeChargeHandler extends AbstractYkcHandler{
|
||||
private final String type = YKCUtils.frameType2Str(YKCFrameTypeCode.PILE_APPLY_MERGE_CHARGE_CODE.getBytes());
|
||||
|
||||
@Autowired
|
||||
private OrderBasicInfoService orderBasicInfoService;
|
||||
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
YKCOperateFactory.register(type, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] supplyProcess(YKCDataProtocol ykcDataProtocol, ChannelHandlerContext channel) {
|
||||
|
||||
// 获取消息体
|
||||
byte[] msgBody = ykcDataProtocol.getMsgBody();
|
||||
|
||||
int startIndex = 0;
|
||||
int length = 7;
|
||||
|
||||
// 桩编号
|
||||
byte[] pileSnByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
|
||||
String pileSn = BytesUtil.binary(pileSnByteArr, 16);
|
||||
|
||||
// 保存时间
|
||||
saveLastTimeAndCheckChannel(pileSn, channel);
|
||||
|
||||
// 枪号
|
||||
startIndex += length;
|
||||
length = 1;
|
||||
byte[] connectorNumByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
|
||||
String connectorCode = BytesUtil.bcd2Str(connectorNumByteArr);
|
||||
|
||||
// 启动方式
|
||||
// 0x01 表示通过刷卡启动充电
|
||||
// 0x02 表求通过帐号启动充电 (暂不支持)
|
||||
// 0x03 表示vin码启动充电
|
||||
startIndex += length;
|
||||
byte[] startModeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
|
||||
String startMode = BytesUtil.bcd2Str(startModeByteArr);
|
||||
|
||||
// 是否需要密码 0x00 不需要 0x01 需要
|
||||
startIndex += length;
|
||||
byte[] needPasswordFlagByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
|
||||
String needPasswordFlag = BytesUtil.bcd2Str(needPasswordFlagByteArr);
|
||||
|
||||
// 物理卡号 不足 8 位补 0
|
||||
startIndex += length;
|
||||
length = 8;
|
||||
byte[] cardNumByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
|
||||
String physicsCard = BytesUtil.binary(cardNumByteArr, 16);
|
||||
|
||||
// 输入密码 对用户输入的密码进行16 位MD5 加密,采用小写上传
|
||||
startIndex += length;
|
||||
length = 16;
|
||||
byte[] inputPasswordByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
|
||||
String inputPasswordHexStr = BytesUtil.bin2HexStr(inputPasswordByteArr);
|
||||
|
||||
// VIN码
|
||||
startIndex += length;
|
||||
length = 17;
|
||||
byte[] vinCodeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
|
||||
String vinCode = BytesUtil.ascii2StrLittle(vinCodeByteArr);
|
||||
|
||||
// 主辅枪标记
|
||||
// 0x00 主枪
|
||||
// 0x01 辅枪
|
||||
startIndex += length;
|
||||
length = 1;
|
||||
byte[] connectorMarkByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
|
||||
String connectorMark = BytesUtil.bcd2Str(connectorMarkByteArr);
|
||||
|
||||
// 并充序号
|
||||
// 由桩生成:年月日时分秒,多个枪并充时上送并充序号一致,表示为同一次并充操作
|
||||
startIndex += length;
|
||||
length = 6;
|
||||
byte[] mergeChargeNumberByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
|
||||
String mergeChargeNumber = BytesUtil.bcd2Str(mergeChargeNumberByteArr);
|
||||
|
||||
// 鉴权方法(返回交易流水号、账户余额、鉴权成功标识)
|
||||
String pileConnectorCode = pileSn + connectorCode;
|
||||
VerifyMergeChargeOrderDTO dto = VerifyMergeChargeOrderDTO.builder()
|
||||
.pileSn(pileSn)
|
||||
.connectorCode(connectorCode)
|
||||
.pileConnectorCode(pileConnectorCode)
|
||||
.startMode(startMode)
|
||||
.physicsCard(physicsCard)
|
||||
.vinCode(vinCode)
|
||||
.connectorMark(connectorMark)
|
||||
.mergeChargeNumber(mergeChargeNumber)
|
||||
.build();
|
||||
|
||||
try {
|
||||
Map<String, Object> map = orderBasicInfoService.verifyMergeChargeOrder(dto);
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("桩号:{}, 并充订单鉴权失败, ", pileSn, e);
|
||||
}
|
||||
|
||||
String transactionCode = "";
|
||||
String accountAmount = "";
|
||||
String verifyFlag = "";
|
||||
|
||||
// 应答
|
||||
// 交易流水号
|
||||
// 桩编号
|
||||
// 枪号
|
||||
// 逻辑卡号
|
||||
// 账户余额
|
||||
// 鉴权成功标志
|
||||
// 失败原因
|
||||
// 并充序号
|
||||
byte[] msgBodyByteArr = Bytes.concat(BytesUtil.str2Bcd(transactionCode), pileSnByteArr, connectorNumByteArr, cardNumByteArr,
|
||||
BytesUtil.str2Bcd(accountAmount), BytesUtil.str2Bcd(verifyFlag), mergeChargeNumberByteArr);
|
||||
|
||||
|
||||
return getResult(ykcDataProtocol, msgBodyByteArr);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user