update 预约充电

This commit is contained in:
Guoqs
2024-09-06 16:13:50 +08:00
parent 8123e350f2
commit 12888c5b1f
3 changed files with 39 additions and 3 deletions

View File

@@ -1,12 +1,18 @@
package com.jsowell.netty.handler.yunkuaichong;
import com.alibaba.fastjson2.JSON;
import com.jsowell.common.constant.CacheConstants;
import com.jsowell.common.core.domain.ykc.YKCDataProtocol;
import com.jsowell.common.core.domain.ykc.YKCFrameTypeCode;
import com.jsowell.common.core.redis.RedisCache;
import com.jsowell.common.util.BytesUtil;
import com.jsowell.common.util.YKCUtils;
import com.jsowell.netty.factory.YKCOperateFactory;
import com.jsowell.pile.domain.PileReservationInfo;
import com.jsowell.pile.service.PileReservationInfoService;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
@@ -18,6 +24,12 @@ public class ReservationChargingResponseHandler extends AbstractYkcHandler {
private final String type = YKCUtils.frameType2Str(YKCFrameTypeCode.RESERVATION_CHARGING_SETUP_ANSWER_CODE.getBytes());
@Autowired
private RedisCache redisCache;
@Autowired
private PileReservationInfoService pileReservationInfoService;
@Override
public void afterPropertiesSet() throws Exception {
YKCOperateFactory.register(type, this);
@@ -51,7 +63,7 @@ public class ReservationChargingResponseHandler extends AbstractYkcHandler {
byte[] connectorCodeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String connectorCode = BytesUtil.bcd2Str(connectorCodeByteArr);
// 启动结果
// 启动结果 0x00失败 0x01成功
startIndex += length;
length = 1;
byte[] resultCodeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
@@ -63,8 +75,20 @@ public class ReservationChargingResponseHandler extends AbstractYkcHandler {
byte[] failedReasonByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String failedReason = BytesUtil.bcd2Str(failedReasonByteArr);
// log.info("0x59预约充电响应, 交易流水号:{}, 桩SN:{}, 枪口号:{}, 结果:{}, 失败原因:{}",
// transactionCode, pileSn, connectorCode, resultCode, failedReason);
log.info("0x59预约充电响应, 交易流水号:{}, 桩SN:{}, 枪口号:{}, 结果:{}, 失败原因:{}",
transactionCode, pileSn, connectorCode, resultCode, failedReason);
// 如果收到成功, 从redis取值, 保存到数据库
if ("01".equals(resultCode)) {
// 预约成功, 删除redis中的预约信息
String redisKey = CacheConstants.UPDATE_RESERVATION_INFO + pileSn + connectorCode;
JSON cacheObject = redisCache.getCacheObject(redisKey);
if (cacheObject != null) {
log.debug("修改预约充电相应成功, 更新数据库");
PileReservationInfo pileReservationInfo = JSON.parseObject(cacheObject.toString(), PileReservationInfo.class);
pileReservationInfoService.insertOrUpdateSelective(pileReservationInfo);
}
}
return null;
}
}