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