diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/PileRemoteService.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/PileRemoteService.java index b2663e202..1bc592877 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/service/PileRemoteService.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/PileRemoteService.java @@ -26,6 +26,7 @@ import java.net.InetAddress; import java.net.UnknownHostException; import java.util.Date; import java.util.List; +import java.util.Objects; @Service public class PileRemoteService { @@ -287,9 +288,17 @@ public class PileRemoteService { /** * 预约充电指令/预约指令 + * @return result: 1-成功; 0-失败 */ - public void reservationCharging(ReservationChargingCommand command) { - ykcPushCommandService.pushReservationChargingCommand(command); + public String reservationCharging(ReservationChargingCommand command) { + String result = "1"; + byte[] bytes = ykcPushCommandService.pushReservationChargingCommand(command); + // 解析结果 + if (Objects.isNull(bytes)) { + result = "0"; + } + + return result; } } diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/YKCPushCommandService.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/YKCPushCommandService.java index 244c6b7a5..55612e72a 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/service/YKCPushCommandService.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/YKCPushCommandService.java @@ -82,6 +82,6 @@ public interface YKCPushCommandService { * 发送预约充电命令 * @param command */ - void pushReservationChargingCommand(ReservationChargingCommand command); + byte[] pushReservationChargingCommand(ReservationChargingCommand command); } diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileReservationInfoServiceImpl.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileReservationInfoServiceImpl.java index b7c15ded2..292b1910d 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileReservationInfoServiceImpl.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileReservationInfoServiceImpl.java @@ -471,12 +471,10 @@ public class PileReservationInfoServiceImpl implements PileReservationInfoServic .reservedEndTime(pileReservationInfo.getEndTime().toLocalTime()) .amount(Constants.WHITELIST_DEFAULT_AMOUNT) .build(); - pileRemoteService.reservationCharging(command); - - // 从redis中获取回复, 3秒没有获取到判为超时 - - - this.insertOrUpdateSelective(pileReservationInfo); + String result = pileRemoteService.reservationCharging(command); + if (StringUtils.equals(result, Constants.ONE)) { + this.insertOrUpdateSelective(pileReservationInfo); + } } /** diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/YKCPushCommandServiceImpl.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/YKCPushCommandServiceImpl.java index 15e8ac1ec..1f338cea2 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/YKCPushCommandServiceImpl.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/YKCPushCommandServiceImpl.java @@ -17,7 +17,6 @@ import com.jsowell.pile.vo.web.BillingTemplateVO; import com.jsowell.pile.vo.web.PileModelInfoVO; import com.jsowell.pile.vo.web.PileStationVO; import io.netty.buffer.ByteBuf; -import io.netty.channel.Channel; import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelHandlerContext; @@ -30,9 +29,7 @@ import java.math.BigDecimal; import java.time.LocalTime; import java.util.Date; import java.util.List; -import java.util.Map; import java.util.Objects; -import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; @@ -620,9 +617,10 @@ public class YKCPushCommandServiceImpl implements YKCPushCommandService { * 发送预约充电命令 * * @param command + * @return */ @Override - public void pushReservationChargingCommand(ReservationChargingCommand command) { + public byte[] pushReservationChargingCommand(ReservationChargingCommand command) { // 交易流水号 String transactionCode = command.getTransactionCode(); byte[] transactionCodeArr = BytesUtil.str2Bcd(transactionCode); @@ -678,14 +676,17 @@ public class YKCPushCommandServiceImpl implements YKCPushCommandService { reservationTypeByteArr, verifyIdentityByteArr, vin1ByteArr, vin2ByteArr, vin3ByteArr, reservedStartTimeByteArr, reservedEndTimeByteArr, amountByteArr); + byte[] response; try { - this.send(msg, pileSn, YKCFrameTypeCode.RESERVATION_CHARGING_SETUP_CODE); + response = this.send(msg, pileSn, YKCFrameTypeCode.RESERVATION_CHARGING_SETUP_CODE); } catch (Exception e) { - throw new RuntimeException(e); + log.error("发送消息异常", e); + response = null; } log.info("【=====平台下发指令=====】: 预约充电指令, 交易流水号:{}, 桩编号:{}, 枪口号:{}, 操作:{}, 身份验证:{}, 开始时间:{}, 结束时间:{}, 启动金额:{}", transactionCode, pileSn, connectorCode, operation, verifyIdentity, DateUtils.formatDateTime(reservedStartTime), DateUtils.formatDateTime(reservedEndTime), amount); + return response; } }