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 ade1db50f..5f688ecbe 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 @@ -174,8 +174,15 @@ public class PileReservationInfoServiceImpl implements PileReservationInfoServic private boolean sendReservationCommand(PileReservationInfo pileReservationInfo, String memberId, String operation) { ReservationChargingCommand command = buildReservationChargingCommand(pileReservationInfo, memberId, operation); + log.info("预约充电指令下发, reservedId:{}, memberId:{}, pileSn:{}, connectorCode:{}, operation:{}, status:{}, reservationType:{}, verifyIdentity:{}, startTime:{}, endTime:{}", + pileReservationInfo.getId(), memberId, command.getPileSn(), command.getConnectorCode(), operation, + pileReservationInfo.getStatus(), command.getReservationType(), command.getVerifyIdentity(), + command.getReservedStartTime(), command.getReservedEndTime()); String result = pileRemoteService.reservationCharging(command); - return StringUtils.equals(result, Constants.ONE); + boolean success = StringUtils.equals(result, Constants.ONE); + log.info("预约充电指令返回, reservedId:{}, memberId:{}, pileSn:{}, connectorCode:{}, operation:{}, result:{}, success:{}", + pileReservationInfo.getId(), memberId, command.getPileSn(), command.getConnectorCode(), operation, result, success); + return success; } private void throwReservationCommandFailed() { @@ -341,7 +348,11 @@ public class PileReservationInfoServiceImpl implements PileReservationInfoServic reservedInfo.getStartTime(), reservedInfo.getEndTime(), reservedInfo.getId())) { throw new BusinessException(ReturnCodeEnum.CODE_UPDATE_RESERVED_STATUS_REFUSED); } - if (activeBeforeUpdate && isYuxinMainboard(reservedInfo.getPileSn())) { + boolean yuxinMainboard = activeBeforeUpdate && isYuxinMainboard(reservedInfo.getPileSn()); + log.info("创建/覆盖预约充电下发决策, memberId:{}, activeBeforeUpdate:{}, yuxinMainboard:{}, oldReservation:{}, newReservation:{}", + dto.getMemberId(), activeBeforeUpdate, yuxinMainboard, + reservationLogText(oldReservationInfo), reservationLogText(reservedInfo)); + if (activeBeforeUpdate && yuxinMainboard) { if (!replaceYuxinReservation(dto.getMemberId(), oldReservationInfo, reservedInfo)) { throwReservationCommandFailed(); } @@ -460,7 +471,13 @@ public class PileReservationInfoServiceImpl implements PileReservationInfoServic 发送指令 */ if (sendFlag) { - if (shouldReplaceYuxinReservation(operation, modifyReservationSetting, oldReservationInfo, pileReservationInfo.getPileSn())) { + boolean yuxinMainboard = isYuxinMainboard(pileReservationInfo.getPileSn()); + boolean replaceYuxinReservation = shouldReplaceYuxinReservation(operation, modifyReservationSetting, oldReservationInfo, yuxinMainboard); + log.info("修改预约充电下发决策, reservedId:{}, memberId:{}, operation:{}, sendFlag:{}, modifyReservationSetting:{}, yuxinMainboard:{}, replaceYuxinReservation:{}, oldReservation:{}, newReservation:{}", + pileReservationInfo.getId(), dto.getMemberId(), operation, sendFlag, modifyReservationSetting, + yuxinMainboard, replaceYuxinReservation, + reservationLogText(oldReservationInfo), reservationLogText(pileReservationInfo)); + if (replaceYuxinReservation) { sendResult = replaceYuxinReservation(dto.getMemberId(), oldReservationInfo, pileReservationInfo); } else { sendResult = sendReservationCommand(pileReservationInfo, dto.getMemberId(), operation); @@ -481,8 +498,8 @@ public class PileReservationInfoServiceImpl implements PileReservationInfoServic } private boolean shouldReplaceYuxinReservation(String operation, boolean modifyReservationSetting, - PileReservationInfo oldReservationInfo, String pileSn) { - if (!modifyReservationSetting || !isYuxinMainboard(pileSn)) { + PileReservationInfo oldReservationInfo, boolean yuxinMainboard) { + if (!modifyReservationSetting || !yuxinMainboard) { return false; } if (StringUtils.equals(operation, "03")) { @@ -494,14 +511,29 @@ public class PileReservationInfoServiceImpl implements PileReservationInfoServic } private boolean replaceYuxinReservation(String memberId, PileReservationInfo oldReservationInfo, PileReservationInfo newReservationInfo) { - if (!sendReservationCommand(oldReservationInfo, memberId, "02")) { + if (oldReservationInfo == null) { + log.error("羽信预约替换失败, 旧预约为空, memberId:{}, newReservation:{}", memberId, reservationLogText(newReservationInfo)); return false; } - if (sendReservationCommand(newReservationInfo, memberId, "01")) { + log.info("羽信预约替换开始, memberId:{}, oldReservation:{}, newReservation:{}", + memberId, reservationLogText(oldReservationInfo), reservationLogText(newReservationInfo)); + boolean cancelOldResult = sendReservationCommand(oldReservationInfo, memberId, "02"); + log.info("羽信预约替换取消旧预约结果, reservedId:{}, pileConnectorCode:{}, result:{}", + oldReservationInfo.getId(), oldReservationInfo.getPileConnectorCode(), cancelOldResult); + if (!cancelOldResult) { + return false; + } + boolean createNewResult = sendReservationCommand(newReservationInfo, memberId, "01"); + log.info("羽信预约替换新预约结果, reservedId:{}, pileConnectorCode:{}, result:{}", + newReservationInfo.getId(), newReservationInfo.getPileConnectorCode(), createNewResult); + if (createNewResult) { return true; } try { - if (!sendReservationCommand(oldReservationInfo, memberId, "01")) { + boolean restoreOldResult = sendReservationCommand(oldReservationInfo, memberId, "01"); + log.info("羽信预约替换恢复旧预约结果, reservedId:{}, pileConnectorCode:{}, result:{}", + oldReservationInfo.getId(), oldReservationInfo.getPileConnectorCode(), restoreOldResult); + if (!restoreOldResult) { log.error("羽信主板修改预约失败后恢复旧预约失败, reservedId:{}, pileConnectorCode:{}", oldReservationInfo.getId(), oldReservationInfo.getPileConnectorCode()); } @@ -516,13 +548,27 @@ public class PileReservationInfoServiceImpl implements PileReservationInfoServic try { PileBasicInfo pileBasicInfo = pileBasicInfoService.selectPileBasicInfoBySN(pileSn); String programVersion = pileBasicInfo == null ? null : pileBasicInfo.getProgramVersion(); - return PileProgramVersionUtils.getMainboardManufacturer(programVersion) == PileMainboardManufacturerEnum.YUXIN; + PileMainboardManufacturerEnum manufacturer = PileProgramVersionUtils.getMainboardManufacturer(programVersion); + boolean yuxinMainboard = manufacturer == PileMainboardManufacturerEnum.YUXIN; + log.info("预约充电主板识别, pileSn:{}, programVersion:{}, manufacturer:{}, yuxinMainboard:{}", + pileSn, programVersion, manufacturer.getValue(), yuxinMainboard); + return yuxinMainboard; } catch (Exception e) { log.warn("判断羽信主板失败, pileSn:{}", pileSn, e); return false; } } + private String reservationLogText(PileReservationInfo reservationInfo) { + if (reservationInfo == null) { + return "null"; + } + return String.format("reservedId=%s,pileSn=%s,pileConnectorCode=%s,status=%s,reservationType=%s,verifyIdentity=%s,startTime=%s,endTime=%s", + reservationInfo.getId(), reservationInfo.getPileSn(), reservationInfo.getPileConnectorCode(), + reservationInfo.getStatus(), reservationInfo.getReservationType(), reservationInfo.getVerifyIdentity(), + reservationInfo.getStartTime(), reservationInfo.getEndTime()); + } + private PileReservationInfo copyReservationInfo(PileReservationInfo source) { PileReservationInfo target = new PileReservationInfo(); target.setId(source.getId());