2023-03-04 16:29:55 +08:00
|
|
|
package com.jsowell.netty.handler;
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
|
|
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.YKCUtils;
|
|
|
|
|
import com.jsowell.common.util.id.IdUtils;
|
|
|
|
|
import com.jsowell.netty.factory.YKCOperateFactory;
|
|
|
|
|
import com.jsowell.pile.service.impl.MemberBasicInfoServiceImpl;
|
|
|
|
|
import com.jsowell.pile.vo.uniapp.MemberVO;
|
|
|
|
|
import io.netty.channel.Channel;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 充电桩主动申请启动充电 0x31
|
|
|
|
|
*
|
|
|
|
|
* 启动充电鉴权结果
|
|
|
|
|
* @author JS-ZZA
|
|
|
|
|
* @date 2022/9/19 14:29
|
|
|
|
|
*/
|
|
|
|
|
@Slf4j
|
|
|
|
|
@Component
|
|
|
|
|
public class ConfirmStartChargingRequestHandler extends AbstractHandler{
|
|
|
|
|
private final String type = YKCUtils.frameType2Str(YKCFrameTypeCode.REQUEST_START_CHARGING_CODE.getBytes());
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private MemberBasicInfoServiceImpl memberBasicInfoService;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void afterPropertiesSet() throws Exception {
|
|
|
|
|
YKCOperateFactory.register(type, this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public byte[] supplyProcess(YKCDataProtocol ykcDataProtocol, Channel channel) {
|
|
|
|
|
log.info("[===充电桩主动申请启动充电===] param:{}, channel:{}", JSONObject.toJSONString(ykcDataProtocol), channel.toString());
|
|
|
|
|
// 获取消息体
|
|
|
|
|
byte[] msgBody = ykcDataProtocol.getMsgBody();
|
|
|
|
|
|
|
|
|
|
int startIndex = 0;
|
|
|
|
|
int length = 16;
|
|
|
|
|
|
|
|
|
|
// 桩编码
|
|
|
|
|
startIndex += length;
|
|
|
|
|
length = 7;
|
|
|
|
|
byte[] pileSnByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
|
|
|
|
|
String pileSn = BytesUtil.bcd2Str(pileSnByteArr);
|
|
|
|
|
|
|
|
|
|
// 保存时间
|
|
|
|
|
saveLastTime(pileSn);
|
|
|
|
|
|
|
|
|
|
// 枪号
|
|
|
|
|
startIndex += length;
|
|
|
|
|
length = 1;
|
|
|
|
|
byte[] pileConnectorNumByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
|
|
|
|
|
String connectorCode = BytesUtil.bcd2Str(pileConnectorNumByteArr);
|
|
|
|
|
|
|
|
|
|
// 启动方式
|
|
|
|
|
// 0x01 表示通过刷卡启动充电
|
|
|
|
|
// 0x02 表求通过帐号启动充电 (暂不支持)
|
|
|
|
|
// 0x03 表示vin码启动充电
|
|
|
|
|
startIndex += length;
|
|
|
|
|
length = 1;
|
|
|
|
|
byte[] startModeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
|
|
|
|
|
|
|
|
|
|
// 是否需要密码 0x00 不需要 0x01 需要
|
|
|
|
|
startIndex += length;
|
|
|
|
|
byte[] needPasswordFlagByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
|
|
|
|
|
|
|
|
|
|
// 物理卡号 不足 8 位补 0
|
|
|
|
|
startIndex += length;
|
|
|
|
|
length = 8;
|
|
|
|
|
byte[] cardNumByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
|
|
|
|
|
String physicsCardNum = BytesUtil.bcd2Str(cardNumByteArr);
|
|
|
|
|
|
|
|
|
|
// 输入密码 对用户输入的密码进行16 位MD5 加密,采用小写上传
|
|
|
|
|
startIndex += length;
|
|
|
|
|
length = 16;
|
|
|
|
|
byte[] inputPasswordByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
|
|
|
|
|
|
|
|
|
|
// VIN码
|
|
|
|
|
startIndex += length;
|
|
|
|
|
length = 17;
|
|
|
|
|
byte[] vinCodeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 应答
|
|
|
|
|
// 交易流水号
|
2023-03-13 15:01:36 +08:00
|
|
|
String serialNum = IdUtils.generateTransactionCode(pileSn, connectorCode);
|
2023-03-04 16:29:55 +08:00
|
|
|
byte[] serialNumByteArr = BytesUtil.str2Bcd(serialNum);
|
|
|
|
|
|
|
|
|
|
// 逻辑卡号
|
|
|
|
|
String logicCardNum = "00000000";
|
|
|
|
|
byte[] logicCardNumByteArr = BytesUtil.str2Bcd(logicCardNum); // [0, 0, 0, 0]
|
|
|
|
|
|
|
|
|
|
// 账户余额 保留两位小数
|
|
|
|
|
MemberVO memberVO = memberBasicInfoService.selectInfoByPhysicsCard(physicsCardNum);
|
|
|
|
|
BigDecimal principalBalance = memberVO.getPrincipalBalance(); // 本金金额
|
|
|
|
|
double accountBalance = principalBalance.add(memberVO.getGiftBalance()).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
|
|
|
|
|
byte[] accountBalanceByteArr = BytesUtil.str2Bcd(String.valueOf(accountBalance));
|
|
|
|
|
|
|
|
|
|
// 鉴权成功标识 0x00 失败 0x01 成功
|
|
|
|
|
byte[] authenticationFlagByteArr= Constants.oneByteArray;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 失败原因
|
|
|
|
|
* 0x01 账户不存在
|
|
|
|
|
* 0x02 账户冻结
|
|
|
|
|
* 0x03 账户余额不足
|
|
|
|
|
* 0x04 该卡存在未结账记录
|
|
|
|
|
* 0x05 桩停用
|
|
|
|
|
* 0x06 该账户不能在此桩上充电
|
|
|
|
|
* 0x07 密码错误
|
|
|
|
|
* 0x08 电站电容不足
|
|
|
|
|
* 0x09 系统中vin 码不存在
|
|
|
|
|
* 0x0A 该桩存在未结账记录
|
|
|
|
|
* 0x0B 该桩不支持刷卡
|
|
|
|
|
*/
|
|
|
|
|
byte[] defeatReasonByteArr = Constants.zeroByteArray;
|
|
|
|
|
|
|
|
|
|
// 拼装消息体
|
|
|
|
|
byte[] msgBodyByteArr = Bytes.concat(serialNumByteArr, logicCardNumByteArr, accountBalanceByteArr,
|
|
|
|
|
authenticationFlagByteArr, defeatReasonByteArr);
|
|
|
|
|
|
|
|
|
|
return getResult(ykcDataProtocol, msgBodyByteArr);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|