mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-21 11:35:12 +08:00
充电桩预约功能
This commit is contained in:
@@ -25,7 +25,11 @@ public interface PileReservedInfoMapper {
|
||||
|
||||
int updateBatch(List<PileReservedInfo> list);
|
||||
|
||||
int updateBatchSelective(List<PileReservedInfo> list);
|
||||
|
||||
int batchInsert(@Param("list") List<PileReservedInfo> list);
|
||||
|
||||
int updateBatchSelective(List<PileReservedInfo> list);
|
||||
List<PileReservedInfo> findByMemberIdAndPileSnAndStatus(@Param("memberId") String memberId, @Param("pileSn") String pileSn, @Param("status") String status);
|
||||
|
||||
List<PileReservedInfo> findByMemberIdAndPileSn(@Param("memberId") String memberId, @Param("pileSn") String pileSn);
|
||||
}
|
||||
@@ -28,5 +28,12 @@ public interface PileReservedInfoService {
|
||||
int batchInsert(List<PileReservedInfo> list);
|
||||
|
||||
int updateBatchSelective(List<PileReservedInfo> list);
|
||||
|
||||
List<PileReservedInfo> getReservationsByMemberIdAndPileSn(String memberId, String pileSn);
|
||||
|
||||
void activateReservation(int reservationId);
|
||||
|
||||
void deactivateReservation(int reservationId);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
package com.jsowell.pile.service.impl;
|
||||
|
||||
import com.jsowell.common.constant.Constants;
|
||||
import com.jsowell.common.util.DateUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.time.LocalTime;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import com.jsowell.pile.mapper.PileReservedInfoMapper;
|
||||
@@ -69,5 +73,74 @@ public class PileReservedInfoServiceImpl implements PileReservedInfoService {
|
||||
public int updateBatchSelective(List<PileReservedInfo> list) {
|
||||
return pileReservedInfoMapper.updateBatchSelective(list);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PileReservedInfo> getReservationsByMemberIdAndPileSn(String memberId, String pileSn) {
|
||||
return pileReservedInfoMapper.findByMemberIdAndPileSn(memberId, pileSn);
|
||||
}
|
||||
|
||||
/**
|
||||
* 启用预约
|
||||
* @param reservationId
|
||||
*/
|
||||
@Override
|
||||
public void activateReservation(int reservationId) {
|
||||
PileReservedInfo pileReservedInfo = pileReservedInfoMapper.selectByPrimaryKey(reservationId);
|
||||
if (pileReservedInfo != null) {
|
||||
pileReservedInfo.setStatus(Constants.ONE);
|
||||
// pileReservedInfoMapper.updateByPrimaryKeySelective(pileReservedInfo);
|
||||
saveReservation(pileReservedInfo);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 禁用预约
|
||||
* @param reservationId
|
||||
*/
|
||||
@Override
|
||||
public void deactivateReservation(int reservationId) {
|
||||
PileReservedInfo pileReservedInfo = pileReservedInfoMapper.selectByPrimaryKey(reservationId);
|
||||
if (pileReservedInfo != null) {
|
||||
pileReservedInfo.setStatus(Constants.ZERO);
|
||||
pileReservedInfoMapper.updateByPrimaryKeySelective(pileReservedInfo);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 校验时间是否重叠
|
||||
* @param memberId
|
||||
* @param pileSn
|
||||
* @param startTime
|
||||
* @param endTime
|
||||
* @param reservationId
|
||||
* @return
|
||||
*/
|
||||
public boolean isTimeSlotAvailable(String memberId, String pileSn, Date startTime, Date 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));
|
||||
|
||||
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()));
|
||||
|
||||
if (newStartTime.isBefore(existingEndTime) && newEndTime.isAfter(existingStartTime)) {
|
||||
return false; // Time slot overlaps
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void saveReservation(PileReservedInfo reservation) {
|
||||
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.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user