From 46df35e4f18c4f385d4fe2d6a2480fae26583169 Mon Sep 17 00:00:00 2001 From: Guoqs <123456@jsowell.com> Date: Thu, 2 Jul 2026 16:22:18 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BE=BD=E4=BF=A1=E4=B8=BB=E6=9D=BF=E5=8F=96?= =?UTF-8?q?=E6=B6=88=E9=A2=84=E7=BA=A6=E5=85=85=E7=94=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../uniapp/customer/PersonPileController.java | 23 ++++++++++++ .../YuxinReservationChargingService.java | 2 ++ .../YuxinReservationChargingServiceImpl.java | 36 +++++++++++++++++-- 3 files changed, 58 insertions(+), 3 deletions(-) diff --git a/jsowell-admin/src/main/java/com/jsowell/api/uniapp/customer/PersonPileController.java b/jsowell-admin/src/main/java/com/jsowell/api/uniapp/customer/PersonPileController.java index fa1975d54..dc333ea71 100644 --- a/jsowell-admin/src/main/java/com/jsowell/api/uniapp/customer/PersonPileController.java +++ b/jsowell-admin/src/main/java/com/jsowell/api/uniapp/customer/PersonPileController.java @@ -535,6 +535,29 @@ public class PersonPileController extends BaseController { return response; } + /** + * 羽信主板取消预约充电 + * http://localhost:8080/uniapp/personalPile/yuxin/cancelReserved + */ + @PostMapping("/yuxin/cancelReserved") + public RestApiResponse cancelYuxinReserved(HttpServletRequest request, @RequestBody YuxinReservationChargingDTO dto) { + RestApiResponse response = null; + try { + String memberId = getMemberIdByAuthorization(request); + dto.setMemberId(memberId); + yuxinReservationChargingService.cancelReservation(dto); + response = new RestApiResponse<>(); + } catch (BusinessException e) { + logger.error("羽信取消预约充电error, params:{}", dto, e); + response = new RestApiResponse<>(e.getCode(), e.getMessage()); + } catch (Exception e) { + logger.error("羽信取消预约充电error, params:{}", dto, e); + response = new RestApiResponse<>(ReturnCodeEnum.CODE_UPDATE_RESERVED_STATUS_ERROR); + } + logger.info("羽信取消预约充电params:{}, result:{}", dto, response); + return response; + } + /** * 保存蓝牙充电记录 * http://localhost:8080/uniapp/personalPile/saveBluetoothChargingRecord diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/YuxinReservationChargingService.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/YuxinReservationChargingService.java index 19e793d84..fe6e6e829 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/service/YuxinReservationChargingService.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/YuxinReservationChargingService.java @@ -5,4 +5,6 @@ import com.jsowell.pile.dto.YuxinReservationChargingDTO; public interface YuxinReservationChargingService { void createReservation(YuxinReservationChargingDTO dto); + + void cancelReservation(YuxinReservationChargingDTO dto); } diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/YuxinReservationChargingServiceImpl.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/YuxinReservationChargingServiceImpl.java index c26a17a97..742490105 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/YuxinReservationChargingServiceImpl.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/YuxinReservationChargingServiceImpl.java @@ -31,6 +31,7 @@ import java.util.Date; public class YuxinReservationChargingServiceImpl implements YuxinReservationChargingService { private static final String YUXIN_RESERVATION_TYPE_CREATE = "00"; + private static final String YUXIN_RESERVATION_TYPE_CANCEL = "01"; private static final BigDecimal YUXIN_ACCOUNT_BALANCE = new BigDecimal("999.99"); private static final int TIME_CONTROL_CHARGING_STRATEGY = 1; private static final int DEFAULT_RESERVATION_TIMEOUT_MINUTES = 0xFF; @@ -50,6 +51,15 @@ public class YuxinReservationChargingServiceImpl implements YuxinReservationChar sendYuxinReservationCommandAndAssertSuccess(dto, YUXIN_RESERVATION_TYPE_CREATE); } + @Override + public void cancelReservation(YuxinReservationChargingDTO dto) { + validateCancelParam(dto); + normalizePileInfo(dto); + assertYuxinMainboard(dto.getPileSn()); + + sendYuxinReservationCommandAndAssertSuccess(dto, YUXIN_RESERVATION_TYPE_CANCEL); + } + private void sendYuxinReservationCommandAndAssertSuccess(YuxinReservationChargingDTO dto, String yuxinReservationType) { if (!sendYuxinReservationCommand(dto, yuxinReservationType)) { @@ -71,7 +81,7 @@ public class YuxinReservationChargingServiceImpl implements YuxinReservationChar private YuxinReservationChargingCommand buildYuxinReservationChargingCommand(YuxinReservationChargingDTO dto, String yuxinReservationType) { - LocalTime startTime = parseSqlTime(dto.getStartTime()).toLocalTime(); + LocalTime startTime = getCommandStartTime(dto); return YuxinReservationChargingCommand.builder() .transactionCode(Constants.ILLEGAL_TRANSACTION_CODE) .pileSn(dto.getPileSn()) @@ -82,7 +92,7 @@ public class YuxinReservationChargingServiceImpl implements YuxinReservationChar .chargingParam(getChargingHours(dto)) .systemTime(new Date()) .reservedStartTime(getReservedStartDate(startTime, yuxinReservationType)) - .reservationTimeout(getReservationTimeout(dto)) + .reservationTimeout(getReservationTimeout(dto, yuxinReservationType)) .build(); } @@ -96,7 +106,10 @@ public class YuxinReservationChargingServiceImpl implements YuxinReservationChar return DateUtils.localDateTime2Date(reservedStartDateTime); } - private int getReservationTimeout(YuxinReservationChargingDTO dto) { + private int getReservationTimeout(YuxinReservationChargingDTO dto, String yuxinReservationType) { + if (StringUtils.equals(yuxinReservationType, YUXIN_RESERVATION_TYPE_CANCEL)) { + return 0; + } if (dto.getReservationTimeout() != null) { return Math.min(Math.max(dto.getReservationTimeout(), 0), 0xFF); } @@ -104,6 +117,9 @@ public class YuxinReservationChargingServiceImpl implements YuxinReservationChar } private BigDecimal getChargingHours(YuxinReservationChargingDTO dto) { + if (StringUtils.isBlank(dto.getStartTime()) || StringUtils.isBlank(dto.getEndTime())) { + return BigDecimal.ZERO; + } LocalTime startTime = parseSqlTime(dto.getStartTime()).toLocalTime(); LocalTime endTime = parseSqlTime(dto.getEndTime()).toLocalTime(); long timeout = Duration.between(startTime, endTime).toMinutes(); @@ -136,6 +152,13 @@ public class YuxinReservationChargingServiceImpl implements YuxinReservationChar } } + private void validateCancelParam(YuxinReservationChargingDTO dto) { + if (StringUtils.isBlank(dto.getMemberId()) + || StringUtils.isBlank(dto.getPileConnectorCode())) { + throw new BusinessException(ReturnCodeEnum.CODE_PARAM_NOT_NULL_ERROR); + } + } + private Time parseSqlTime(String time) { if (time.length() == 5) { return Time.valueOf(time + ":00"); @@ -143,6 +166,13 @@ public class YuxinReservationChargingServiceImpl implements YuxinReservationChar return Time.valueOf(time); } + private LocalTime getCommandStartTime(YuxinReservationChargingDTO dto) { + if (StringUtils.isBlank(dto.getStartTime())) { + return LocalTime.now(); + } + return parseSqlTime(dto.getStartTime()).toLocalTime(); + } + private void assertYuxinMainboard(String pileSn) { PileBasicInfo pileBasicInfo = pileBasicInfoService.selectPileBasicInfoBySN(pileSn); String programVersion = pileBasicInfo == null ? null : pileBasicInfo.getProgramVersion();