update 卡启动结算逻辑

This commit is contained in:
Lemon
2023-04-06 08:43:14 +08:00
parent 5acf8489cd
commit 5ecc3c3c2b
2 changed files with 99 additions and 57 deletions

View File

@@ -63,15 +63,17 @@ public class TransactionRecordsRequestHandler extends AbstractHandler {
@Autowired
private IPileAuthCardService pileAuthCardService;
/*public static void main(String[] args) {
String msgBodyStr = "880000000000040122121516483531998800000000000401000030100f0c16a8003b011a0368100f0400000000000000000000000000c891050000000000000000000000000080140700a406000000000000d01e000090170d0000000000000000000000000010b0390b0078f2390b00a406000000000000781e0000ffffffffffffffffffffffffffffffffff01a8003b011a0368830000000000000000" ;
byte[] msgBody = BytesUtil.str2Bcd(msgBodyStr);
public static void main(String[] args) {
// 获取消息体
String msg = "000000000000000000000000000000008823000000030601a08c2e0d0404170000380d0404170000000000000000000000000000000000000000000000000000000000000000400d0300ee250000ee250000c84b000000000000000000000000000000000000e0bb040000cee1040000ee250000ee250000c84b00000000000000000000000000000000000000010000380d04041745a511101970000000";
byte[] msgBody = BytesUtil.str2Bcd(msg);
int startIndex = 0;
int length = 16;
// 交易流水号
byte[] orderCodeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String orderCode = BytesUtil.bcd2Str(orderCodeByteArr);
String transactionCode = BytesUtil.bcd2Str(orderCodeByteArr);
// 桩编码
startIndex += length;
@@ -84,19 +86,22 @@ public class TransactionRecordsRequestHandler extends AbstractHandler {
length = 1;
byte[] connectorCodeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String connectorCode = BytesUtil.bcd2Str(connectorCodeByteArr);
// 根据不同程序版本获取工具类
String programVersion = redisCache.getCacheMapValue(CacheConstants.PILE_PROGRAM_VERSION, pileSn);
AbsCp56Time2aUtil cp56Time2aUtil = Cp56Time2aFactory.getInvokeStrategy(programVersion);
// 开始时间 CP56Time2a 格式
startIndex += length;
length = 7;
byte[] startTimeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String startTime = cp56Time2aUtil.toDateString(startTimeByteArr);
// String binary = BytesUtil.binary(startTimeByteArr, 16);
Date startDate = Cp56Time2aUtil.byte2Hdate(startTimeByteArr);
String startTime = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, startDate);
// 结束时间 CP56Time2a 格式
startIndex += length;
byte[] endTimeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String endTime = cp56Time2aUtil.toDateString(endTimeByteArr);
Date endDate = Cp56Time2aUtil.byte2Hdate(endTimeByteArr);
String endTime = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, endDate);
// 尖单价 精确到小数点后五位(尖电费+尖服务费,见费率帧)
startIndex += length;
@@ -113,7 +118,7 @@ public class TransactionRecordsRequestHandler extends AbstractHandler {
// 计损尖电量
startIndex += length;
byte[] sharpPlanLossElectricityByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String sharpPlanLossElectric = YKCUtils.convertDecimalPoint(sharpPlanLossElectricityByteArr, 4);
String sharpPlanLossElectricity = YKCUtils.convertDecimalPoint(sharpPlanLossElectricityByteArr, 4);
// 尖金额
startIndex += length;
@@ -213,47 +218,89 @@ public class TransactionRecordsRequestHandler extends AbstractHandler {
byte[] vinCodeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String vinCode = BytesUtil.ascii2Str(vinCodeByteArr);
*//**
/**
* 交易标识
* 0x01 app 启动
* 0x02卡启动
* 0x04离线卡启动
* 0x05: vin 码启动充电
*//*
startIndex += length;
length = 1;
byte[] transactionIdentifierByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String transactionIdentifier = BytesUtil.bcd2Str(transactionIdentifierByteArr);
*/
startIndex += length;
length = 1;
byte[] transactionIdentifierByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String transactionIdentifier = BytesUtil.bcd2Str(transactionIdentifierByteArr);
// 交易时间 CP56Time2a 格式
startIndex += length;
length = 7;
byte[] transactionTimeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String transactionTime = cp56Time2aUtil.toDateString(transactionTimeByteArr);
// 交易时间 CP56Time2a 格式
startIndex += length;
length = 7;
byte[] transactionTimeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
Date transactionDate = Cp56Time2aUtil.byte2Hdate(transactionTimeByteArr);
String transactionTime = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, transactionDate);
// 停止原因
startIndex += length;
length = 1;
byte[] stopReasonByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String stopReason = BytesUtil.bin2HexStr(stopReasonByteArr);
String stopReasonMsg = YKCChargingStopReasonEnum.getMsgByCode(Integer.parseInt(stopReason, 16));
// 停止原因
startIndex += length;
length = 1;
byte[] stopReasonByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String stopReason = BytesUtil.bin2HexStr(stopReasonByteArr);
String stopReasonMsg = YKCChargingStopReasonEnum.getMsgByCode(Integer.parseInt(stopReason, 16));
// 物理卡号 不足 8 位补 0
startIndex += length;
length = 8;
byte[] cardNumByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
byte[] logicCardNum = BytesUtil.checkLengthAndBehindAppendZero(cardNumByteArr, 16);
String logicCard = BytesUtil.binary(logicCardNum, 10);
// 物理卡号 不足 8 位补 0
startIndex += length;
length = 8;
byte[] cardNumByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
// byte[] logicCardNum = BytesUtil.checkLengthAndBehindAppendZero(cardNumByteArr, 16);
String logicCard = BytesUtil.binary(cardNumByteArr, 16);
log.info("桩号:{}发送交易记录物理卡号:{}", pileSn, logicCard);
log.info("交易流水号:{}, 桩编号:{}, 枪号:{}, 开始时间:{}, 结束时间:{}, 尖单价:{}, 尖电量:{}, 计损尖电量:{}, 尖金额:{}, " +
"峰单价:{}, 峰电量:{}, 计损峰电量:{}, 峰金额:{}, 平单价:{}, 平电量:{}, 计损平电量:{}, 平金额:{}, " +
"谷单价:{}, 谷电量:{}, 计损谷电量:{}, 谷金额:{}, 电表总起值:{}, 电表总止值:{}, 总电量:{}, 计损总电量:{}, 消费金额:{}, " +
"电动汽车唯一标识:{}, 交易标识:{}, 交易时间:{}, 停止原因码:{}, 停止原因描述:{}, 物理卡号:{}",
orderCode, pileSn, connectorCode, startTime, endTime, sharpPrice, sharpUsedElectricity, sharpPlanLossElectric, sharpAmount,
peakPrice, peakUsedElectricity, peakPlanLossElectricity, peakAmount, flatPrice, flatUsedElectricity, flatPlanLossElectricity, flatAmount,
valleyPrice, valleyUsedElectricity, valleyPlanLossElectricity, valleyAmount, ammeterTotalStart, ammeterTotalEnd, totalElectricity, planLossTotalElectricity,
consumptionAmount, vinCode, transactionIdentifier, transactionTime, stopReason, stopReasonMsg, logicCard);
}*/
log.info("[===交易记录===]交易流水号:{}, 桩编号:{}, 枪号:{}, 开始时间:{}, 结束时间:{}, 尖单价:{}, 尖电量:{}, 计损尖电量:{}, 尖金额:{}, " +
"峰单价:{}, 峰电量:{}, 计损峰电量:{}, 峰金额:{}, 平单价:{}, 平电量:{}, 计损平电量:{}, 平金额:{}, " +
"谷单价:{}, 谷电量:{}, 计损谷电量:{}, 谷金额:{}, 电表总起值:{}, 电表总止值:{}, 总电量:{}, 计损总电量:{}, 消费金额:{}, " +
"电动汽车唯一标识:{}, 交易标识:{}, 交易日期、时间:{}, 停止原因码:{}, 停止原因描述:{}, 物理卡号:{}",
transactionCode, pileSn, connectorCode, startTime, endTime, sharpPrice, sharpUsedElectricity, sharpPlanLossElectricity, sharpAmount,
peakPrice, peakUsedElectricity, peakPlanLossElectricity, peakAmount, flatPrice, flatUsedElectricity, flatPlanLossElectricity, flatAmount,
valleyPrice, valleyUsedElectricity, valleyPlanLossElectricity, valleyAmount, ammeterTotalStart, ammeterTotalEnd, totalElectricity, planLossTotalElectricity,
consumptionAmount, vinCode, transactionIdentifier, transactionTime, stopReason, stopReasonMsg, logicCard);
// 交易记录封装到对象里
TransactionRecordsData data = TransactionRecordsData.builder()
// .orderCode(transactionCode)
.transactionCode(transactionCode)
.pileSn(pileSn)
.connectorCode(connectorCode)
.startTime(startTime)
.endTime(endTime)
.sharpPrice(sharpPrice)
.sharpUsedElectricity(sharpUsedElectricity)
.sharpPlanLossElectricity(sharpPlanLossElectricity)
.sharpAmount(sharpAmount)
.peakPrice(peakPrice)
.peakUsedElectricity(peakUsedElectricity)
.peakPlanLossElectricity(peakPlanLossElectricity)
.peakAmount(peakAmount)
.flatPrice(flatPrice)
.flatUsedElectricity(flatUsedElectricity)
.flatPlanLossElectricity(flatPlanLossElectricity)
.flatAmount(flatAmount)
.valleyPrice(valleyPrice)
.valleyUsedElectricity(valleyUsedElectricity)
.valleyPlanLossElectricity(valleyPlanLossElectricity)
.valleyAmount(valleyAmount)
.ammeterTotalStart(ammeterTotalStart)
.ammeterTotalEnd(ammeterTotalEnd)
.totalElectricity(totalElectricity)
.planLossTotalElectricity(planLossTotalElectricity)
.consumptionAmount(consumptionAmount)
.vinCode(vinCode)
.transactionIdentifier(transactionIdentifier)
.transactionTime(transactionTime)
.stopReasonMsg(stopReasonMsg)
.logicCard(logicCard)
.build();
boolean flag = !StringUtils.equals("0000000000000000", "a511101970000000");
System.out.println(flag);
}
@Override
public byte[] supplyProcess(YKCDataProtocol ykcDataProtocol, Channel channel) {
@@ -538,7 +585,6 @@ public class TransactionRecordsRequestHandler extends AbstractHandler {
if (StringUtils.equals(OrderStatusEnum.ABNORMAL.getValue(), orderBasicInfo.getOrderStatus())) {
orderBasicInfo.setOrderStatus(OrderStatusEnum.STAY_SETTLEMENT.getValue());
}
// 校验一下开始时间和结束时间,防止充电中桩离线,时间不准确
if (Objects.isNull(orderBasicInfo.getChargeStartTime())) { // 开始时间
orderBasicInfo.setChargeStartTime(DateUtils.parseDate(data.getStartTime()));
@@ -547,23 +593,14 @@ public class TransactionRecordsRequestHandler extends AbstractHandler {
orderBasicInfo.setChargeEndTime(DateUtils.parseDate(data.getEndTime()));
}
if (!StringUtils.equals("0000000000000000", data.getLogicCard())) {
// 将此订单启动方式改为卡启动
orderBasicInfo.setStartMode(StartModeEnum.CARD.getValue());
// 将卡号存入订单表
orderBasicInfo.setLogicCard(data.getLogicCard());
// 根据物理卡号查出所属用户
PileAuthCard cardInfo = pileAuthCardService.selectCardInfoByLogicCard(data.getLogicCard());
// 根据物理卡号查出当前为锁定状态的卡
PileAuthCard cardInfo = pileAuthCardService.selectSomeStatusCardInfo("2", orderBasicInfo.getLogicCard());
if (cardInfo != null) {
orderBasicInfo.setMemberId(cardInfo.getMemberId());
// orderBasicInfo.setMemberId(cardInfo.getMemberId());
// 将此卡状态改为正常
PileAuthCard pileAuthCard = PileAuthCard.builder()
.logicCard(data.getLogicCard())
.id(cardInfo.getId())
.status("1")
.build();
pileAuthCardService.updatePileAuthCard(pileAuthCard);
cardInfo.setStatus("1");
pileAuthCardService.updatePileAuthCard(cardInfo);
}
}
orderBasicInfoService.updateOrderBasicInfo(orderBasicInfo);