羽信主板取消预约充电

This commit is contained in:
Guoqs
2026-07-02 16:22:18 +08:00
parent 17b19ab0da
commit 46df35e4f1
3 changed files with 58 additions and 3 deletions

View File

@@ -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

View File

@@ -5,4 +5,6 @@ import com.jsowell.pile.dto.YuxinReservationChargingDTO;
public interface YuxinReservationChargingService {
void createReservation(YuxinReservationChargingDTO dto);
void cancelReservation(YuxinReservationChargingDTO dto);
}

View File

@@ -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();