mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-20 02:55:04 +08:00
update 充电桩主动申请充电逻辑优化
This commit is contained in:
@@ -5,18 +5,13 @@ 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.enums.ykc.CardStatusEnum;
|
||||
import com.jsowell.common.enums.ykc.OrderPayModeEnum;
|
||||
import com.jsowell.common.enums.ykc.ReturnCodeEnum;
|
||||
import com.jsowell.common.enums.ykc.StartModeEnum;
|
||||
import com.jsowell.common.exception.BusinessException;
|
||||
import com.jsowell.common.util.BytesUtil;
|
||||
import com.jsowell.common.util.StringUtils;
|
||||
import com.jsowell.common.util.YKCUtils;
|
||||
import com.jsowell.common.util.id.IdUtils;
|
||||
import com.jsowell.common.util.spring.SpringUtils;
|
||||
import com.jsowell.netty.factory.YKCOperateFactory;
|
||||
import com.jsowell.pile.domain.MemberPlateNumberRelation;
|
||||
import com.jsowell.pile.domain.PileAuthCard;
|
||||
import com.jsowell.pile.domain.PileBasicInfo;
|
||||
import com.jsowell.pile.dto.ConfirmStartChargingData;
|
||||
import com.jsowell.pile.dto.GenerateOrderDTO;
|
||||
@@ -25,11 +20,13 @@ import com.jsowell.pile.vo.base.ConfirmStartChargingMemberVO;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
/**
|
||||
* 充电桩主动申请启动充电 0x31
|
||||
@@ -43,6 +40,9 @@ import java.util.Map;
|
||||
public class ConfirmStartChargingRequestHandler extends AbstractYkcHandler {
|
||||
private final String type = YKCUtils.frameType2Str(YKCFrameTypeCode.REQUEST_START_CHARGING_CODE.getBytes());
|
||||
|
||||
// 引入线程池
|
||||
private ThreadPoolTaskExecutor executor = SpringUtils.getBean("threadPoolTaskExecutor");
|
||||
|
||||
@Autowired
|
||||
private PileAuthCardService pileAuthCardService;
|
||||
|
||||
@@ -131,7 +131,7 @@ public class ConfirmStartChargingRequestHandler extends AbstractYkcHandler {
|
||||
.build();
|
||||
|
||||
// 启动充电
|
||||
this.confirmStartCharging(confirmStartChargingData);
|
||||
Map<String, String> resultMap = this.confirmStartCharging(confirmStartChargingData);
|
||||
|
||||
byte[] defeatReasonByteArr = Constants.zeroByteArray;
|
||||
/**
|
||||
@@ -139,107 +139,118 @@ public class ConfirmStartChargingRequestHandler extends AbstractYkcHandler {
|
||||
*/
|
||||
byte[] authenticationFlagByteArr = Constants.zeroByteArray; // 鉴权成功标识
|
||||
byte[] accountBalanceByteArr = Constants.zeroByteArray; // 账户余额
|
||||
String transactionCode = "";
|
||||
try {
|
||||
if (StringUtils.equals("01", startMode)) {
|
||||
log.info("桩号:{}, 申请充电物理卡号:{}", pileSn, physicsCard);
|
||||
// 查询卡信息 根据传过来的物理卡号查询数据库中此卡信息
|
||||
PileAuthCard pileAuthCardInfo = pileAuthCardService.selectCardInfoByLogicCard(physicsCard);
|
||||
if (pileAuthCardInfo == null) {
|
||||
// 未查到此卡信息
|
||||
throw new BusinessException(ReturnCodeEnum.CODE_THIS_CARD_HAS_NO_INFO);
|
||||
}
|
||||
if (StringUtils.isBlank(pileAuthCardInfo.getMemberId())) {
|
||||
// 卡未绑定用户
|
||||
throw new BusinessException(ReturnCodeEnum.CODE_THIS_CARD_NOT_BIND_USER);
|
||||
}
|
||||
// String transactionCode = resultMap.get("transactionCode");
|
||||
// try {
|
||||
// if (StringUtils.equals("01", startMode)) {
|
||||
// log.info("桩号:{}, 申请充电物理卡号:{}", pileSn, physicsCard);
|
||||
// // 查询卡信息 根据传过来的物理卡号查询数据库中此卡信息
|
||||
// PileAuthCard pileAuthCardInfo = pileAuthCardService.selectCardInfoByLogicCard(physicsCard);
|
||||
// if (pileAuthCardInfo == null) {
|
||||
// // 未查到此卡信息
|
||||
// throw new BusinessException(ReturnCodeEnum.CODE_THIS_CARD_HAS_NO_INFO);
|
||||
// }
|
||||
// if (StringUtils.isBlank(pileAuthCardInfo.getMemberId())) {
|
||||
// // 卡未绑定用户
|
||||
// throw new BusinessException(ReturnCodeEnum.CODE_THIS_CARD_NOT_BIND_USER);
|
||||
// }
|
||||
//
|
||||
// // 判断卡状态
|
||||
// if (!StringUtils.equals(CardStatusEnum.NORMAL.getCode(), pileAuthCardInfo.getStatus())) {
|
||||
// log.info("卡号:{}, 状态:{}, 非正常使用状态", physicsCard, CardStatusEnum.getCardStatus(pileAuthCardInfo.getStatus()));
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// // 刷卡生成订单 刷卡启动充电
|
||||
// GenerateOrderDTO dto = new GenerateOrderDTO();
|
||||
// dto.setPileAuthCardInfo(pileAuthCardInfo);
|
||||
// dto.setPileSn(pileSn);
|
||||
// dto.setConnectorCode(connectorCode);
|
||||
// dto.setStartMode(StartModeEnum.AUTH_CARD.getValue());
|
||||
// dto.setMemberId(pileAuthCardInfo.getMemberId());
|
||||
// Map<String, Object> map = orderBasicInfoService.generateOrderByCard(dto);
|
||||
// if (map != null) {
|
||||
// transactionCode = (String) map.get("transactionCode");
|
||||
// accountBalanceByteArr = YKCUtils.getPriceByte(String.valueOf(map.get("accountBalance")), 2);
|
||||
// // 鉴权成功标识 0x00 失败 0x01 成功
|
||||
// authenticationFlagByteArr = Constants.oneByteArray;
|
||||
// }else {
|
||||
// throw new BusinessException("", "生成刷卡订单失败");
|
||||
// }
|
||||
// }
|
||||
// } catch (BusinessException e){
|
||||
// transactionCode = Constants.ILLEGAL_TRANSACTION_CODE;
|
||||
// accountBalanceByteArr = BytesUtil.checkLengthAndBehindAppendZero(accountBalanceByteArr, 8);
|
||||
// authenticationFlagByteArr = Constants.zeroByteArray;
|
||||
// log.error("刷卡启动充电鉴权 error:{}, {}", e.getCode(), e.getMessage());
|
||||
// } catch (Exception e){
|
||||
// transactionCode = Constants.ILLEGAL_TRANSACTION_CODE;
|
||||
// accountBalanceByteArr = BytesUtil.checkLengthAndBehindAppendZero(accountBalanceByteArr, 8);
|
||||
// authenticationFlagByteArr = Constants.zeroByteArray;
|
||||
// log.error("刷卡启动充电鉴权 error", e);
|
||||
// }
|
||||
|
||||
// 判断卡状态
|
||||
if (!StringUtils.equals(CardStatusEnum.NORMAL.getCode(), pileAuthCardInfo.getStatus())) {
|
||||
log.info("卡号:{}, 状态:{}, 非正常使用状态", physicsCard, CardStatusEnum.getCardStatus(pileAuthCardInfo.getStatus()));
|
||||
return null;
|
||||
}
|
||||
// try {
|
||||
// /**
|
||||
// * VIN码启动充电
|
||||
// */
|
||||
// if (StringUtils.equals("03", startMode)) {
|
||||
// log.info("桩号:{}, 申请充电VIN码:{}, 反转后:{}", pileSn, vinCode, StringUtils.reverse(vinCode));
|
||||
// // 通过vin码查询数据库绑定用户信息
|
||||
// MemberPlateNumberRelation plateInfo = memberPlateNumberRelationService.getMemberPlateInfoByVinCode(vinCode);
|
||||
// if (plateInfo == null) {
|
||||
// // throw new BusinessException("", vinCode + "未查到绑定用户信息");
|
||||
// log.error(vinCode + "未查到绑定用户信息");
|
||||
// defeatReasonByteArr = new byte[] {0x09}; // 系统中vin 码不存在
|
||||
// transactionCode = Constants.ILLEGAL_TRANSACTION_CODE;
|
||||
// accountBalanceByteArr = BytesUtil.checkLengthAndBehindAppendZero(accountBalanceByteArr, 8);
|
||||
// authenticationFlagByteArr = Constants.zeroByteArray;
|
||||
// }
|
||||
// // vin码生成订单 vin启动充电
|
||||
// GenerateOrderDTO dto = new GenerateOrderDTO();
|
||||
// dto.setMemberPlateNumberRelation(plateInfo);
|
||||
// dto.setPileSn(pileSn);
|
||||
// dto.setConnectorCode(connectorCode);
|
||||
// dto.setStartMode(StartModeEnum.VIN_CODE.getValue());
|
||||
// dto.setMemberId(plateInfo.getMemberId());
|
||||
// Map<String, Object> map = orderBasicInfoService.generateOrderByCard(dto);
|
||||
// if (map != null) {
|
||||
// transactionCode = (String) map.get("transactionCode");
|
||||
// accountBalanceByteArr = YKCUtils.getPriceByte(String.valueOf(map.get("accountBalance")), 2);
|
||||
// // 鉴权成功标识 0x00 失败 0x01 成功
|
||||
// authenticationFlagByteArr = Constants.oneByteArray;
|
||||
// }else {
|
||||
// throw new BusinessException("", "生成vin订单失败");
|
||||
// }
|
||||
// }
|
||||
// }catch (BusinessException e){
|
||||
// transactionCode = Constants.ILLEGAL_TRANSACTION_CODE;
|
||||
// accountBalanceByteArr = BytesUtil.checkLengthAndBehindAppendZero(accountBalanceByteArr, 8);
|
||||
// authenticationFlagByteArr = Constants.zeroByteArray;
|
||||
// String code = e.getCode();
|
||||
// String message = e.getMessage();
|
||||
// if (StringUtils.length(code) == 2) {
|
||||
// defeatReasonByteArr = BytesUtil.str2Bcd(code);
|
||||
// }
|
||||
//
|
||||
// log.error("VIN码启动充电鉴权 error:{}, {}", code, message);
|
||||
// }catch (Exception e) {
|
||||
// transactionCode = Constants.ILLEGAL_TRANSACTION_CODE;
|
||||
// accountBalanceByteArr = BytesUtil.checkLengthAndBehindAppendZero(accountBalanceByteArr, 8);
|
||||
// authenticationFlagByteArr = Constants.zeroByteArray;
|
||||
//
|
||||
// log.error("VIN码启动充电鉴权 error", e);
|
||||
// }
|
||||
|
||||
// 刷卡生成订单 刷卡启动充电
|
||||
GenerateOrderDTO dto = new GenerateOrderDTO();
|
||||
dto.setPileAuthCardInfo(pileAuthCardInfo);
|
||||
dto.setPileSn(pileSn);
|
||||
dto.setConnectorCode(connectorCode);
|
||||
dto.setStartMode(StartModeEnum.AUTH_CARD.getValue());
|
||||
dto.setMemberId(pileAuthCardInfo.getMemberId());
|
||||
Map<String, Object> map = orderBasicInfoService.generateOrderByCard(dto);
|
||||
if (map != null) {
|
||||
transactionCode = (String) map.get("transactionCode");
|
||||
accountBalanceByteArr = YKCUtils.getPriceByte(String.valueOf(map.get("accountBalance")), 2);
|
||||
// 鉴权成功标识 0x00 失败 0x01 成功
|
||||
authenticationFlagByteArr = Constants.oneByteArray;
|
||||
}else {
|
||||
throw new BusinessException("", "生成刷卡订单失败");
|
||||
}
|
||||
}
|
||||
} catch (BusinessException e){
|
||||
transactionCode = Constants.ILLEGAL_TRANSACTION_CODE;
|
||||
accountBalanceByteArr = BytesUtil.checkLengthAndBehindAppendZero(accountBalanceByteArr, 8);
|
||||
//
|
||||
String transactionCode = resultMap.get("transactionCode");
|
||||
// 如果交易流水号不等于Constants.ILLEGAL_TRANSACTION_CODE, 表示鉴权通过
|
||||
if (!StringUtils.equals(transactionCode, Constants.ILLEGAL_TRANSACTION_CODE)) {
|
||||
authenticationFlagByteArr = Constants.oneByteArray;
|
||||
} else {
|
||||
// 鉴权失败
|
||||
authenticationFlagByteArr = Constants.zeroByteArray;
|
||||
log.error("刷卡启动充电鉴权 error:{}, {}", e.getCode(), e.getMessage());
|
||||
} catch (Exception e){
|
||||
transactionCode = Constants.ILLEGAL_TRANSACTION_CODE;
|
||||
accountBalanceByteArr = BytesUtil.checkLengthAndBehindAppendZero(accountBalanceByteArr, 8);
|
||||
authenticationFlagByteArr = Constants.zeroByteArray;
|
||||
log.error("刷卡启动充电鉴权 error", e);
|
||||
}
|
||||
|
||||
try {
|
||||
/**
|
||||
* VIN码启动充电
|
||||
*/
|
||||
if (StringUtils.equals("03", startMode)) {
|
||||
log.info("桩号:{}, 申请充电VIN码:{}, 反转后:{}", pileSn, vinCode, StringUtils.reverse(vinCode));
|
||||
// 通过vin码查询数据库绑定用户信息
|
||||
MemberPlateNumberRelation plateInfo = memberPlateNumberRelationService.getMemberPlateInfoByVinCode(vinCode);
|
||||
if (plateInfo == null) {
|
||||
// throw new BusinessException("", vinCode + "未查到绑定用户信息");
|
||||
log.error(vinCode + "未查到绑定用户信息");
|
||||
defeatReasonByteArr = new byte[] {0x09}; // 系统中vin 码不存在
|
||||
transactionCode = Constants.ILLEGAL_TRANSACTION_CODE;
|
||||
accountBalanceByteArr = BytesUtil.checkLengthAndBehindAppendZero(accountBalanceByteArr, 8);
|
||||
authenticationFlagByteArr = Constants.zeroByteArray;
|
||||
}
|
||||
// vin码生成订单 vin启动充电
|
||||
GenerateOrderDTO dto = new GenerateOrderDTO();
|
||||
dto.setMemberPlateNumberRelation(plateInfo);
|
||||
dto.setPileSn(pileSn);
|
||||
dto.setConnectorCode(connectorCode);
|
||||
dto.setStartMode(StartModeEnum.VIN_CODE.getValue());
|
||||
dto.setMemberId(plateInfo.getMemberId());
|
||||
Map<String, Object> map = orderBasicInfoService.generateOrderByCard(dto);
|
||||
if (map != null) {
|
||||
transactionCode = (String) map.get("transactionCode");
|
||||
accountBalanceByteArr = YKCUtils.getPriceByte(String.valueOf(map.get("accountBalance")), 2);
|
||||
// 鉴权成功标识 0x00 失败 0x01 成功
|
||||
authenticationFlagByteArr = Constants.oneByteArray;
|
||||
}else {
|
||||
throw new BusinessException("", "生成vin订单失败");
|
||||
}
|
||||
}
|
||||
}catch (BusinessException e){
|
||||
transactionCode = Constants.ILLEGAL_TRANSACTION_CODE;
|
||||
accountBalanceByteArr = BytesUtil.checkLengthAndBehindAppendZero(accountBalanceByteArr, 8);
|
||||
authenticationFlagByteArr = Constants.zeroByteArray;
|
||||
String code = e.getCode();
|
||||
String message = e.getMessage();
|
||||
if (StringUtils.length(code) == 2) {
|
||||
defeatReasonByteArr = BytesUtil.str2Bcd(code);
|
||||
}
|
||||
|
||||
log.error("VIN码启动充电鉴权 error:{}, {}", code, message);
|
||||
}catch (Exception e) {
|
||||
transactionCode = Constants.ILLEGAL_TRANSACTION_CODE;
|
||||
accountBalanceByteArr = BytesUtil.checkLengthAndBehindAppendZero(accountBalanceByteArr, 8);
|
||||
authenticationFlagByteArr = Constants.zeroByteArray;
|
||||
|
||||
log.error("VIN码启动充电鉴权 error", e);
|
||||
}
|
||||
accountBalanceByteArr = YKCUtils.getPriceByte(String.valueOf(resultMap.get("accountBalance")), 2);
|
||||
|
||||
// 应答
|
||||
// 交易流水号
|
||||
@@ -260,7 +271,10 @@ public class ConfirmStartChargingRequestHandler extends AbstractYkcHandler {
|
||||
* 0x0A 该桩存在未结账记录
|
||||
* 0x0B 该桩不支持刷卡
|
||||
*/
|
||||
// byte[] defeatReasonByteArr = Constants.zeroByteArray;
|
||||
// 如果resultMap中defeatReasonCode不为空, 则使用resultMap中的reasonCode
|
||||
if (resultMap.get("defeatReasonCode") != null) {
|
||||
defeatReasonByteArr = BytesUtil.str2Bcd(resultMap.get("defeatReasonCode"));
|
||||
}
|
||||
|
||||
// 保存报文
|
||||
String jsonMsg = JSON.toJSONString(confirmStartChargingData);
|
||||
@@ -316,15 +330,14 @@ public class ConfirmStartChargingRequestHandler extends AbstractYkcHandler {
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
// 生成交易流水号, 传递给订单使用
|
||||
String transactionCode = IdUtils.generateTransactionCode(pileSn, connectorCode);
|
||||
resultMap.put("transactionCode", transactionCode);
|
||||
/*
|
||||
鉴权通过, 生成订单并支付
|
||||
*/
|
||||
|
||||
String payMode;
|
||||
if (StringUtils.equals(Constants.ONE, memberWalletVO.getPlatformTesterFlag())
|
||||
|| StringUtils.equals(Constants.ONE, memberWalletVO.getStationWhiteListFlag())) {
|
||||
// 如果是平台测试员或者是站点白名单
|
||||
resultMap.put("transactionCode", Constants.ILLEGAL_TRANSACTION_CODE);
|
||||
accountBalance = Constants.WHITELIST_DEFAULT_AMOUNT.toString();
|
||||
payMode = OrderPayModeEnum.PAYMENT_OF_WHITELIST.getValue();
|
||||
} else {
|
||||
@@ -336,6 +349,11 @@ public class ConfirmStartChargingRequestHandler extends AbstractYkcHandler {
|
||||
payMode = OrderPayModeEnum.PAYMENT_OF_PRINCIPAL_BALANCE.getValue();
|
||||
}
|
||||
|
||||
// 生成交易流水号, 传递给订单使用
|
||||
String transactionCode = IdUtils.generateTransactionCode(pileSn, connectorCode);
|
||||
resultMap.put("transactionCode", transactionCode);
|
||||
resultMap.put("accountBalance", accountBalance);
|
||||
|
||||
// 异步创建订单
|
||||
GenerateOrderDTO dto = new GenerateOrderDTO();
|
||||
dto.setPileSn(pileSn);
|
||||
@@ -345,11 +363,14 @@ public class ConfirmStartChargingRequestHandler extends AbstractYkcHandler {
|
||||
dto.setPayMode(payMode);
|
||||
dto.setStartMode(StringUtils.equals("01", startMode) ? "2" : "5");
|
||||
dto.setMemberId(memberWalletVO.getMemberId());
|
||||
try {
|
||||
Map<String, Object> map = orderBasicInfoService.generateOrderByCard(dto);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
CompletableFuture.runAsync(() -> {
|
||||
try {
|
||||
Map<String, Object> map = orderBasicInfoService.generateOrderByCard(dto);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}, executor);
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user