update 预约充电逻辑

This commit is contained in:
jsowell
2026-06-26 14:28:59 +08:00
parent 944f4100ad
commit 84fc754c39
3 changed files with 40 additions and 370 deletions

View File

@@ -522,8 +522,8 @@ public class PersonPileController extends BaseController {
try { try {
String memberId = getMemberIdByAuthorization(request); String memberId = getMemberIdByAuthorization(request);
dto.setMemberId(memberId); dto.setMemberId(memberId);
int reservedId = yuxinReservationChargingService.createReservation(dto); yuxinReservationChargingService.createReservation(dto);
response = new RestApiResponse<>(ImmutableMap.of("reservedId", reservedId)); response = new RestApiResponse<>();
} catch (BusinessException e) { } catch (BusinessException e) {
logger.error("羽信添加预约充电error, params:{}", dto, e); logger.error("羽信添加预约充电error, params:{}", dto, e);
response = new RestApiResponse<>(e.getCode(), e.getMessage()); response = new RestApiResponse<>(e.getCode(), e.getMessage());
@@ -535,102 +535,6 @@ public class PersonPileController extends BaseController {
return response; return response;
} }
/**
* 羽信主板修改预约充电
* http://localhost:8080/uniapp/personalPile/yuxin/updateReservation
*/
@PostMapping("/yuxin/updateReservation")
public RestApiResponse<?> updateYuxinReservation(HttpServletRequest request, @RequestBody YuxinReservationChargingDTO dto) {
RestApiResponse<?> response = null;
try {
String memberId = getMemberIdByAuthorization(request);
dto.setMemberId(memberId);
int i = yuxinReservationChargingService.updateReservation(dto);
if (i > 0) {
response = new RestApiResponse<>();
} else {
response = new RestApiResponse<>(ReturnCodeEnum.CODE_UPDATE_RESERVED_STATUS_ERROR.getValue(), ReturnCodeEnum.CODE_UPDATE_RESERVED_STATUS_ERROR.getLabel() + ": 充电桩返回修改失败");
}
} 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/yuxin/updateReservedStatus
*/
@PostMapping("/yuxin/updateReservedStatus")
public RestApiResponse<?> cancelYuxinReservation(HttpServletRequest request, @RequestBody YuxinReservationChargingDTO dto) {
RestApiResponse<?> response = null;
try {
String memberId = getMemberIdByAuthorization(request);
dto.setMemberId(memberId);
yuxinReservationChargingService.updateReservedStatus(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/yuxin/deleteReservation
*/
@PostMapping("/yuxin/deleteReservation")
public RestApiResponse<?> deleteYuxinReservation(HttpServletRequest request, @RequestBody YuxinReservationChargingDTO dto) {
RestApiResponse<?> response = null;
try {
String memberId = getMemberIdByAuthorization(request);
dto.setMemberId(memberId);
yuxinReservationChargingService.deleteReservation(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/yuxin/queryReservationInfo
*/
@PostMapping("/yuxin/queryReservationInfo")
public RestApiResponse<?> queryYuxinReservationInfo(HttpServletRequest request, @RequestBody YuxinReservationChargingDTO dto) {
RestApiResponse<?> response = null;
try {
String memberId = getMemberIdByAuthorization(request);
dto.setMemberId(memberId);
PileReservationInfoVO vo = yuxinReservationChargingService.queryReservationInfo(dto);
response = new RestApiResponse<>(vo);
} 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_QUERY_RESERVATION_STATUS_ERROR);
}
logger.info("羽信查询预约状态params:{}, result:{}", dto, JSON.toJSONString(response));
return response;
}
/** /**
* 保存蓝牙充电记录 * 保存蓝牙充电记录
* http://localhost:8080/uniapp/personalPile/saveBluetoothChargingRecord * http://localhost:8080/uniapp/personalPile/saveBluetoothChargingRecord

View File

@@ -1,19 +1,8 @@
package com.jsowell.pile.service; package com.jsowell.pile.service;
import com.jsowell.pile.dto.YuxinReservationChargingDTO; import com.jsowell.pile.dto.YuxinReservationChargingDTO;
import com.jsowell.pile.vo.PileReservationInfoVO;
public interface YuxinReservationChargingService { public interface YuxinReservationChargingService {
int createReservation(YuxinReservationChargingDTO dto); void createReservation(YuxinReservationChargingDTO dto);
int updateReservation(YuxinReservationChargingDTO dto);
void cancelReservation(YuxinReservationChargingDTO dto);
void deleteReservation(YuxinReservationChargingDTO dto);
PileReservationInfoVO queryReservationInfo(YuxinReservationChargingDTO dto);
void updateReservedStatus(YuxinReservationChargingDTO dto);
} }

View File

@@ -1,7 +1,6 @@
package com.jsowell.pile.service.impl; package com.jsowell.pile.service.impl;
import com.jsowell.common.constant.Constants; import com.jsowell.common.constant.Constants;
import com.jsowell.common.enums.DelFlagEnum;
import com.jsowell.common.enums.ykc.PileMainboardManufacturerEnum; import com.jsowell.common.enums.ykc.PileMainboardManufacturerEnum;
import com.jsowell.common.enums.ykc.ReturnCodeEnum; import com.jsowell.common.enums.ykc.ReturnCodeEnum;
import com.jsowell.common.exception.BusinessException; import com.jsowell.common.exception.BusinessException;
@@ -10,41 +9,31 @@ import com.jsowell.common.util.PileProgramVersionUtils;
import com.jsowell.common.util.StringUtils; import com.jsowell.common.util.StringUtils;
import com.jsowell.common.util.YKCUtils; import com.jsowell.common.util.YKCUtils;
import com.jsowell.pile.domain.PileBasicInfo; import com.jsowell.pile.domain.PileBasicInfo;
import com.jsowell.pile.domain.PileReservationInfo;
import com.jsowell.pile.domain.ykcCommond.YuxinReservationChargingCommand; import com.jsowell.pile.domain.ykcCommond.YuxinReservationChargingCommand;
import com.jsowell.pile.dto.YuxinReservationChargingDTO; import com.jsowell.pile.dto.YuxinReservationChargingDTO;
import com.jsowell.pile.mapper.PileReservationInfoMapper;
import com.jsowell.pile.service.PileBasicInfoService; import com.jsowell.pile.service.PileBasicInfoService;
import com.jsowell.pile.service.PileRemoteService; import com.jsowell.pile.service.PileRemoteService;
import com.jsowell.pile.service.YuxinReservationChargingService; import com.jsowell.pile.service.YuxinReservationChargingService;
import com.jsowell.pile.vo.PileReservationInfoVO;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode;
import java.sql.Time; import java.sql.Time;
import java.time.Duration; import java.time.Duration;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.LocalTime; import java.time.LocalTime;
import java.util.Date; import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
@Slf4j @Slf4j
@Service @Service
public class YuxinReservationChargingServiceImpl implements YuxinReservationChargingService { public class YuxinReservationChargingServiceImpl implements YuxinReservationChargingService {
private static final String YUXIN_RESERVATION_TYPE_CREATE = "00"; 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 BigDecimal YUXIN_ACCOUNT_BALANCE = new BigDecimal("999.99");
private static final BigDecimal DEFAULT_CHARGING_PARAM = BigDecimal.ZERO; private static final int TIME_CONTROL_CHARGING_STRATEGY = 1;
private static final int DEFAULT_CHARGING_STRATEGY = 0; private static final int DEFAULT_RESERVATION_TIMEOUT_MINUTES = 0xFF;
@Resource
private PileReservationInfoMapper pileReservationInfoMapper;
@Autowired @Autowired
private PileRemoteService pileRemoteService; private PileRemoteService pileRemoteService;
@@ -53,203 +42,47 @@ public class YuxinReservationChargingServiceImpl implements YuxinReservationChar
private PileBasicInfoService pileBasicInfoService; private PileBasicInfoService pileBasicInfoService;
@Override @Override
public int createReservation(YuxinReservationChargingDTO dto) { public void createReservation(YuxinReservationChargingDTO dto) {
validateCreateOrUpdateParam(dto); validateCreateOrUpdateParam(dto);
normalizePileInfo(dto); normalizePileInfo(dto);
assertYuxinMainboard(dto.getPileSn()); assertYuxinMainboard(dto.getPileSn());
PileReservationInfo currentReservation = pileReservationInfoMapper.selectByPileConnectorCode(dto.getPileConnectorCode()); sendYuxinReservationCommandAndAssertSuccess(dto, YUXIN_RESERVATION_TYPE_CREATE);
PileReservationInfo oldReservation = currentReservation == null ? null : copyReservationInfo(currentReservation);
boolean oldActive = oldReservation != null && StringUtils.equals(oldReservation.getStatus(), Constants.ONE);
PileReservationInfo reservationInfo = currentReservation == null ? new PileReservationInfo() : currentReservation;
fillReservationInfo(reservationInfo, dto);
if (currentReservation == null) {
reservationInfo.setCreateBy(dto.getMemberId());
} else {
reservationInfo.setUpdateBy(dto.getMemberId());
}
if (!isTimeSlotAvailable(dto.getMemberId(), dto.getPileSn(), reservationInfo.getStartTime(),
reservationInfo.getEndTime(), reservationInfo.getId())) {
throw new BusinessException(ReturnCodeEnum.CODE_UPDATE_RESERVED_STATUS_REFUSED);
}
if (oldActive) {
cancelOldReservationBeforeCreate(dto, oldReservation);
}
sendYuxinReservationCommandAndAssertSuccess(dto, reservationInfo, YUXIN_RESERVATION_TYPE_CREATE);
pileReservationInfoMapper.insertOrUpdateSelective(reservationInfo);
return reservationInfo.getId();
}
@Override
public int updateReservation(YuxinReservationChargingDTO dto) {
if (StringUtils.isBlank(dto.getReservedId())) {
throw new BusinessException(ReturnCodeEnum.CODE_PARAM_NOT_NULL_ERROR);
}
PileReservationInfo reservationInfo = pileReservationInfoMapper.selectByPrimaryKey(Integer.valueOf(dto.getReservedId()));
if (reservationInfo == null) {
return 0;
}
dto.setPileSn(StringUtils.defaultIfBlank(dto.getPileSn(), reservationInfo.getPileSn()));
dto.setPileConnectorCode(StringUtils.defaultIfBlank(dto.getPileConnectorCode(), reservationInfo.getPileConnectorCode()));
dto.setStartTime(StringUtils.defaultIfBlank(dto.getStartTime(), reservationInfo.getStartTime().toString()));
dto.setEndTime(StringUtils.defaultIfBlank(dto.getEndTime(), reservationInfo.getEndTime().toString()));
assertYuxinMainboard(dto.getPileSn());
PileReservationInfo oldReservation = copyReservationInfo(reservationInfo);
fillReservationInfo(reservationInfo, dto);
reservationInfo.setUpdateBy(dto.getMemberId());
if (!isTimeSlotAvailable(dto.getMemberId(), dto.getPileSn(), reservationInfo.getStartTime(),
reservationInfo.getEndTime(), reservationInfo.getId())) {
throw new BusinessException(ReturnCodeEnum.CODE_UPDATE_RESERVED_STATUS_REFUSED);
}
if (StringUtils.equals(oldReservation.getStatus(), Constants.ONE)) {
cancelOldReservationBeforeCreate(dto, oldReservation);
}
sendYuxinReservationCommandAndAssertSuccess(dto, reservationInfo, YUXIN_RESERVATION_TYPE_CREATE);
return pileReservationInfoMapper.insertOrUpdateSelective(reservationInfo);
}
@Override
public void cancelReservation(YuxinReservationChargingDTO dto) {
if (StringUtils.isBlank(dto.getReservedId())) {
throw new BusinessException(ReturnCodeEnum.CODE_PARAM_NOT_NULL_ERROR);
}
PileReservationInfo reservationInfo = pileReservationInfoMapper.selectByPrimaryKey(Integer.valueOf(dto.getReservedId()));
if (reservationInfo == null) {
return;
}
assertYuxinMainboard(reservationInfo.getPileSn());
boolean cancelSuccess = true;
if (StringUtils.equals(reservationInfo.getStatus(), Constants.ONE)) {
cancelSuccess = sendYuxinReservationCommand(dto, reservationInfo, YUXIN_RESERVATION_TYPE_CANCEL);
}
if (!cancelSuccess && !isReservationTimeEnded(reservationInfo)) {
throwReservationCommandFailed();
}
if (!cancelSuccess) {
log.warn("羽信取消预约失败, 但预约时间窗已过期, 本地停用预约, memberId:{}, reservation:{}",
dto.getMemberId(), reservationLogText(reservationInfo));
}
reservationInfo.setStatus(Constants.ZERO);
reservationInfo.setUpdateBy(dto.getMemberId());
pileReservationInfoMapper.updateByPrimaryKeySelective(reservationInfo);
}
@Override
public void deleteReservation(YuxinReservationChargingDTO dto) {
if (StringUtils.isBlank(dto.getReservedId())) {
throw new BusinessException(ReturnCodeEnum.CODE_PARAM_NOT_NULL_ERROR);
}
PileReservationInfo reservationInfo = pileReservationInfoMapper.selectByPrimaryKey(Integer.valueOf(dto.getReservedId()));
if (Objects.isNull(reservationInfo)) {
return;
}
assertYuxinMainboard(reservationInfo.getPileSn());
boolean cancelSuccess = true;
if (StringUtils.equals(reservationInfo.getStatus(), Constants.ONE)) {
cancelSuccess = sendYuxinReservationCommand(dto, reservationInfo, YUXIN_RESERVATION_TYPE_CANCEL);
}
if (!cancelSuccess && !isReservationTimeEnded(reservationInfo)) {
throwReservationCommandFailed();
}
reservationInfo.setStatus(Constants.ZERO);
reservationInfo.setDelFlag(DelFlagEnum.DELETE.getValue());
reservationInfo.setUpdateBy(dto.getMemberId());
pileReservationInfoMapper.updateByPrimaryKey(reservationInfo);
}
@Override
public PileReservationInfoVO queryReservationInfo(YuxinReservationChargingDTO dto) {
if (StringUtils.isBlank(dto.getPileConnectorCode())) {
throw new BusinessException(ReturnCodeEnum.CODE_PARAM_NOT_NULL_ERROR);
}
PileReservationInfo reservationInfo = pileReservationInfoMapper.selectByPileConnectorCode(dto.getPileConnectorCode());
if (reservationInfo == null) {
return null;
}
return PileReservationInfoVO.builder()
.reservedId(reservationInfo.getId() + "")
.pileSn(reservationInfo.getPileSn())
.pileConnectorCode(reservationInfo.getPileConnectorCode())
.startTime(reservationInfo.getStartTime().toString())
.endTime(reservationInfo.getEndTime().toString())
.verifyIdentity(reservationInfo.getVerifyIdentity())
.status(reservationInfo.getStatus())
.build();
}
@Override
public void updateReservedStatus(YuxinReservationChargingDTO dto) {
}
private void fillReservationInfo(PileReservationInfo reservationInfo, YuxinReservationChargingDTO dto) {
reservationInfo.setMemberId(dto.getMemberId());
reservationInfo.setPileSn(dto.getPileSn());
reservationInfo.setPileConnectorCode(dto.getPileConnectorCode());
reservationInfo.setStatus(Constants.ONE);
reservationInfo.setDelFlag(DelFlagEnum.NORMAL.getValue());
reservationInfo.setReservationType("recurring");
reservationInfo.setFreq("daily");
reservationInfo.setVerifyIdentity(Constants.ZERO);
reservationInfo.setStartTime(parseSqlTime(dto.getStartTime()));
reservationInfo.setEndTime(parseSqlTime(dto.getEndTime()));
if (reservationInfo.getId() == null) {
reservationInfo.setCreateTime(DateUtils.getNowDate());
} else {
reservationInfo.setUpdateTime(DateUtils.getNowDate());
}
}
private void cancelOldReservationBeforeCreate(YuxinReservationChargingDTO dto, PileReservationInfo oldReservation) {
boolean cancelSuccess = sendYuxinReservationCommand(dto, oldReservation, YUXIN_RESERVATION_TYPE_CANCEL);
if (!cancelSuccess && !isReservationTimeEnded(oldReservation)) {
throwReservationCommandFailed();
}
if (!cancelSuccess) {
log.warn("羽信预约新时间前取消旧预约失败, 但旧预约时间窗已过期, 继续预约新时间, memberId:{}, oldReservation:{}",
dto.getMemberId(), reservationLogText(oldReservation));
}
} }
private void sendYuxinReservationCommandAndAssertSuccess(YuxinReservationChargingDTO dto, private void sendYuxinReservationCommandAndAssertSuccess(YuxinReservationChargingDTO dto,
PileReservationInfo reservationInfo,
String yuxinReservationType) { String yuxinReservationType) {
if (!sendYuxinReservationCommand(dto, reservationInfo, yuxinReservationType)) { if (!sendYuxinReservationCommand(dto, yuxinReservationType)) {
throwReservationCommandFailed(); throwReservationCommandFailed();
} }
} }
private boolean sendYuxinReservationCommand(YuxinReservationChargingDTO dto, private boolean sendYuxinReservationCommand(YuxinReservationChargingDTO dto,
PileReservationInfo reservationInfo,
String yuxinReservationType) { String yuxinReservationType) {
YuxinReservationChargingCommand command = buildYuxinReservationChargingCommand(dto, reservationInfo, yuxinReservationType); YuxinReservationChargingCommand command = buildYuxinReservationChargingCommand(dto, yuxinReservationType);
log.info("羽信预约充电指令下发, memberId:{}, reservedId:{}, reservationType:{}, reservation:{}", log.info("羽信预约充电指令下发, memberId:{}, reservationType:{}, command:{}",
dto.getMemberId(), reservationInfo.getId(), yuxinReservationType, reservationLogText(reservationInfo)); dto.getMemberId(), yuxinReservationType, reservationLogText(dto, command));
String result = pileRemoteService.yuxinReservationCharging(command); String result = pileRemoteService.yuxinReservationCharging(command);
boolean success = StringUtils.equals(result, Constants.ONE); boolean success = StringUtils.equals(result, Constants.ONE);
log.info("羽信预约充电指令返回, memberId:{}, reservedId:{}, reservationType:{}, result:{}, success:{}", log.info("羽信预约充电指令返回, memberId:{}, reservationType:{}, result:{}, success:{}",
dto.getMemberId(), reservationInfo.getId(), yuxinReservationType, result, success); dto.getMemberId(), yuxinReservationType, result, success);
return success; return success;
} }
private YuxinReservationChargingCommand buildYuxinReservationChargingCommand(YuxinReservationChargingDTO dto, private YuxinReservationChargingCommand buildYuxinReservationChargingCommand(YuxinReservationChargingDTO dto,
PileReservationInfo reservationInfo,
String yuxinReservationType) { String yuxinReservationType) {
LocalTime startTime = parseSqlTime(dto.getStartTime()).toLocalTime();
return YuxinReservationChargingCommand.builder() return YuxinReservationChargingCommand.builder()
.transactionCode(Constants.ILLEGAL_TRANSACTION_CODE) .transactionCode(Constants.ILLEGAL_TRANSACTION_CODE)
.pileSn(reservationInfo.getPileSn()) .pileSn(dto.getPileSn())
.connectorCode(getConnectorCode(reservationInfo)) .connectorCode(getConnectorCode(dto))
.accountBalance(YUXIN_ACCOUNT_BALANCE) .accountBalance(YUXIN_ACCOUNT_BALANCE)
.reservationType(yuxinReservationType) .reservationType(yuxinReservationType)
.chargingStrategy(dto.getChargingStrategy() == null ? DEFAULT_CHARGING_STRATEGY : dto.getChargingStrategy()) .chargingStrategy(TIME_CONTROL_CHARGING_STRATEGY)
.chargingParam(dto.getChargingParam() == null ? DEFAULT_CHARGING_PARAM : dto.getChargingParam()) .chargingParam(getChargingHours(dto))
.systemTime(new Date()) .systemTime(new Date())
.reservedStartTime(getReservedStartDate(reservationInfo.getStartTime().toLocalTime(), yuxinReservationType)) .reservedStartTime(getReservedStartDate(startTime, yuxinReservationType))
.reservationTimeout(getReservationTimeout(dto, reservationInfo, yuxinReservationType)) .reservationTimeout(getReservationTimeout(dto))
.build(); .build();
} }
@@ -263,26 +96,26 @@ public class YuxinReservationChargingServiceImpl implements YuxinReservationChar
return DateUtils.localDateTime2Date(reservedStartDateTime); return DateUtils.localDateTime2Date(reservedStartDateTime);
} }
private int getReservationTimeout(YuxinReservationChargingDTO dto, private int getReservationTimeout(YuxinReservationChargingDTO dto) {
PileReservationInfo reservationInfo,
String yuxinReservationType) {
if (StringUtils.equals(yuxinReservationType, YUXIN_RESERVATION_TYPE_CANCEL)) {
return 0;
}
if (dto.getReservationTimeout() != null) { if (dto.getReservationTimeout() != null) {
return Math.min(Math.max(dto.getReservationTimeout(), 0), 0xFF); return Math.min(Math.max(dto.getReservationTimeout(), 0), 0xFF);
} }
LocalTime startTime = reservationInfo.getStartTime().toLocalTime(); return DEFAULT_RESERVATION_TIMEOUT_MINUTES;
LocalTime endTime = reservationInfo.getEndTime().toLocalTime();
long timeout = Duration.between(startTime, endTime).toMinutes();
if (timeout <= 0) {
timeout += TimeUnit.DAYS.toMinutes(1);
}
return (int) Math.min(timeout, 0xFF);
} }
private String getConnectorCode(PileReservationInfo reservationInfo) { private BigDecimal getChargingHours(YuxinReservationChargingDTO dto) {
return reservationInfo.getPileConnectorCode().replace(reservationInfo.getPileSn(), ""); LocalTime startTime = parseSqlTime(dto.getStartTime()).toLocalTime();
LocalTime endTime = parseSqlTime(dto.getEndTime()).toLocalTime();
long timeout = Duration.between(startTime, endTime).toMinutes();
if (timeout <= 0) {
timeout += Duration.ofDays(1).toMinutes();
}
return BigDecimal.valueOf(timeout)
.divide(BigDecimal.valueOf(60), 2, RoundingMode.HALF_UP);
}
private String getConnectorCode(YuxinReservationChargingDTO dto) {
return dto.getPileConnectorCode().replace(dto.getPileSn(), "");
} }
private void normalizePileInfo(YuxinReservationChargingDTO dto) { private void normalizePileInfo(YuxinReservationChargingDTO dto) {
@@ -310,39 +143,6 @@ public class YuxinReservationChargingServiceImpl implements YuxinReservationChar
return Time.valueOf(time); return Time.valueOf(time);
} }
private boolean isTimeSlotAvailable(String memberId, String pileSn, Time startTime, Time endTime, Integer reservationId) {
List<PileReservationInfo> reservations = pileReservationInfoMapper.findByMemberIdAndPileSnAndStatus(memberId, pileSn, Constants.ONE);
LocalTime newStartTime = startTime.toLocalTime();
LocalTime newEndTime = endTime.toLocalTime();
for (PileReservationInfo res : reservations) {
if (reservationId != null && res.getId().equals(reservationId)) {
continue;
}
LocalTime existingStartTime = res.getStartTime().toLocalTime();
LocalTime existingEndTime = res.getEndTime().toLocalTime();
if (newStartTime.isBefore(existingEndTime) && newEndTime.isAfter(existingStartTime)) {
return false;
}
}
return true;
}
private boolean isReservationTimeEnded(PileReservationInfo reservationInfo) {
if (reservationInfo == null || reservationInfo.getStartTime() == null || reservationInfo.getEndTime() == null) {
return false;
}
LocalTime now = LocalTime.now();
LocalTime startTime = reservationInfo.getStartTime().toLocalTime();
LocalTime endTime = reservationInfo.getEndTime().toLocalTime();
boolean crossDay = endTime.isBefore(startTime);
boolean ended = crossDay
? !now.isBefore(endTime) && now.isBefore(startTime)
: !endTime.isAfter(now);
log.info("羽信预约过期判断, reservedId:{}, pileConnectorCode:{}, now:{}, startTime:{}, endTime:{}, crossDay:{}, ended:{}",
reservationInfo.getId(), reservationInfo.getPileConnectorCode(), now, startTime, endTime, crossDay, ended);
return ended;
}
private void assertYuxinMainboard(String pileSn) { private void assertYuxinMainboard(String pileSn) {
PileBasicInfo pileBasicInfo = pileBasicInfoService.selectPileBasicInfoBySN(pileSn); PileBasicInfo pileBasicInfo = pileBasicInfoService.selectPileBasicInfoBySN(pileSn);
String programVersion = pileBasicInfo == null ? null : pileBasicInfo.getProgramVersion(); String programVersion = pileBasicInfo == null ? null : pileBasicInfo.getProgramVersion();
@@ -357,33 +157,10 @@ public class YuxinReservationChargingServiceImpl implements YuxinReservationChar
ReturnCodeEnum.CODE_UPDATE_RESERVED_STATUS_ERROR.getLabel() + ": 充电桩返回修改失败"); ReturnCodeEnum.CODE_UPDATE_RESERVED_STATUS_ERROR.getLabel() + ": 充电桩返回修改失败");
} }
private String reservationLogText(PileReservationInfo reservationInfo) { private String reservationLogText(YuxinReservationChargingDTO dto, YuxinReservationChargingCommand command) {
if (reservationInfo == null) { return String.format("pileSn=%s,pileConnectorCode=%s,startTime=%s,endTime=%s,chargingStrategy=%s,chargingParam=%s,reservationTimeout=%s",
return "null"; dto.getPileSn(), dto.getPileConnectorCode(), dto.getStartTime(), dto.getEndTime(),
} command.getChargingStrategy(), command.getChargingParam(), command.getReservationTimeout());
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());
target.setMemberId(source.getMemberId());
target.setPileSn(source.getPileSn());
target.setPileConnectorCode(source.getPileConnectorCode());
target.setStatus(source.getStatus());
target.setReservationType(source.getReservationType());
target.setVerifyIdentity(source.getVerifyIdentity());
target.setStartTime(source.getStartTime());
target.setEndTime(source.getEndTime());
target.setFreq(source.getFreq());
target.setCreateBy(source.getCreateBy());
target.setCreateTime(source.getCreateTime());
target.setUpdateBy(source.getUpdateBy());
target.setUpdateTime(source.getUpdateTime());
target.setDelFlag(source.getDelFlag());
return target;
}
} }