充电桩预约功能

This commit is contained in:
Guoqs
2024-06-18 17:13:29 +08:00
parent 313392104a
commit f5b00e9696
6 changed files with 144 additions and 29 deletions

View File

@@ -23,6 +23,15 @@ public class PileReservedDTO {
*/
private String status;
/**
* 桩编号
*/
private String pileSn;
private Integer pageNo;
private Integer pageSize;
@Override
public String toString() {
return new ToStringBuilder(this, ToStringStyle.JSON_STYLE)

View File

@@ -1,12 +1,15 @@
package com.jsowell.pile.service.impl;
import com.jsowell.common.constant.Constants;
import com.jsowell.common.enums.ykc.ReturnCodeEnum;
import com.jsowell.common.exception.BusinessException;
import com.jsowell.common.util.DateUtils;
import com.jsowell.common.util.StringUtils;
import com.jsowell.pile.dto.PileReservedDTO;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.sql.Time;
import java.time.LocalTime;
import java.util.Date;
import java.util.List;
@@ -125,17 +128,17 @@ public class PileReservedInfoServiceImpl implements PileReservedInfoService {
* @param reservationId
* @return
*/
public boolean isTimeSlotAvailable(String memberId, String pileSn, Date startTime, Date endTime, Integer reservationId) {
public boolean isTimeSlotAvailable(String memberId, String pileSn, Time startTime, Time endTime, Integer reservationId) {
List<PileReservedInfo> reservations = pileReservedInfoMapper.findByMemberIdAndPileSnAndStatus(memberId, pileSn, "1");
LocalTime newStartTime = LocalTime.parse(DateUtils.formatDateTime(startTime));
LocalTime newEndTime = LocalTime.parse(DateUtils.formatDateTime(endTime));
LocalTime newStartTime = startTime.toLocalTime();
LocalTime newEndTime = endTime.toLocalTime();
for (PileReservedInfo res : reservations) {
if (res.getId().equals(reservationId)) {
continue; // Skip the current reservation if updating
}
LocalTime existingStartTime = LocalTime.parse(DateUtils.formatDateTime(res.getStartTime()));
LocalTime existingEndTime = LocalTime.parse(DateUtils.formatDateTime(res.getEndTime()));
LocalTime existingStartTime = res.getStartTime().toLocalTime();
LocalTime existingEndTime = res.getEndTime().toLocalTime();
if (newStartTime.isBefore(existingEndTime) && newEndTime.isAfter(existingStartTime)) {
return false; // Time slot overlaps
@@ -148,7 +151,7 @@ public class PileReservedInfoServiceImpl implements PileReservedInfoService {
if (isTimeSlotAvailable(reservation.getMemberId(), reservation.getPileSn(), reservation.getStartTime(), reservation.getEndTime(), reservation.getId())) {
this.updateByPrimaryKeySelective(reservation);
} else {
throw new RuntimeException("Time slot overlaps with an existing reservation.");
throw new BusinessException(ReturnCodeEnum.CODE_UPDATE_RESERVED_STATUS_REFUSED);
}
}
}

View File

@@ -0,0 +1,38 @@
package com.jsowell.pile.vo;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
@Builder
public class PileReservedVO {
private String reservedId;
/**
* 充电桩编号
*/
private String pileSn;
/**
* 预约开始时间
*/
private String startTime;
/**
* 预约结束时间
*/
private String endTime;
/**
* 周期性预约的频率,对于单次预约,该字段可以为 NULL。可能的值包括 daily, weekly, monthly
*/
private String freq;
/**
* 状态0-未生效1-生效)
*/
private String status;
}