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:
@@ -16,7 +16,7 @@ import lombok.experimental.SuperBuilder;
|
||||
@SuperBuilder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class PileReservedInfo {
|
||||
public class PileReservationInfo {
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.jsowell.pile.mapper;
|
||||
|
||||
import com.jsowell.pile.domain.PileReservationInfo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
public interface PileReservationInfoMapper {
|
||||
int deleteByPrimaryKey(Integer id);
|
||||
|
||||
int insert(PileReservationInfo record);
|
||||
|
||||
int insertOrUpdate(PileReservationInfo record);
|
||||
|
||||
int insertOrUpdateSelective(PileReservationInfo record);
|
||||
|
||||
int insertSelective(PileReservationInfo record);
|
||||
|
||||
PileReservationInfo selectByPrimaryKey(Integer id);
|
||||
|
||||
int updateByPrimaryKeySelective(PileReservationInfo record);
|
||||
|
||||
int updateByPrimaryKey(PileReservationInfo record);
|
||||
|
||||
int updateBatch(List<PileReservationInfo> list);
|
||||
|
||||
int updateBatchSelective(List<PileReservationInfo> list);
|
||||
|
||||
int batchInsert(@Param("list") List<PileReservationInfo> list);
|
||||
|
||||
List<PileReservationInfo> findByMemberIdAndPileSnAndStatus(@Param("memberId") String memberId, @Param("pileSn") String pileSn, @Param("status") String status);
|
||||
|
||||
List<PileReservationInfo> findByMemberIdAndPileSn(@Param("memberId") String memberId, @Param("pileSn") String pileSn);
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
package com.jsowell.pile.mapper;
|
||||
|
||||
import com.jsowell.pile.domain.PileReservedInfo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
public interface PileReservedInfoMapper {
|
||||
int deleteByPrimaryKey(Integer id);
|
||||
|
||||
int insert(PileReservedInfo record);
|
||||
|
||||
int insertOrUpdate(PileReservedInfo record);
|
||||
|
||||
int insertOrUpdateSelective(PileReservedInfo record);
|
||||
|
||||
int insertSelective(PileReservedInfo record);
|
||||
|
||||
PileReservedInfo selectByPrimaryKey(Integer id);
|
||||
|
||||
int updateByPrimaryKeySelective(PileReservedInfo record);
|
||||
|
||||
int updateByPrimaryKey(PileReservedInfo record);
|
||||
|
||||
int updateBatch(List<PileReservedInfo> list);
|
||||
|
||||
int updateBatchSelective(List<PileReservedInfo> list);
|
||||
|
||||
int batchInsert(@Param("list") 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);
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package com.jsowell.pile.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.jsowell.pile.dto.PileReservedDTO;
|
||||
import com.jsowell.pile.domain.PileReservationInfo;
|
||||
|
||||
public interface PileReservationInfoService {
|
||||
int deleteByPrimaryKey(Integer id);
|
||||
|
||||
int insert(PileReservationInfo record);
|
||||
|
||||
int insertOrUpdate(PileReservationInfo record);
|
||||
|
||||
int insertOrUpdateSelective(PileReservationInfo record);
|
||||
|
||||
int insertSelective(PileReservationInfo record);
|
||||
|
||||
PileReservationInfo selectByPrimaryKey(Integer id);
|
||||
|
||||
int updateByPrimaryKeySelective(PileReservationInfo record);
|
||||
|
||||
int updateByPrimaryKey(PileReservationInfo record);
|
||||
|
||||
int updateBatch(List<PileReservationInfo> list);
|
||||
|
||||
int batchInsert(List<PileReservationInfo> list);
|
||||
|
||||
int updateBatchSelective(List<PileReservationInfo> list);
|
||||
|
||||
List<PileReservationInfo> getReservationsByMemberIdAndPileSn(String memberId, String pileSn);
|
||||
|
||||
/**
|
||||
* 启动预约
|
||||
* @param dto
|
||||
*/
|
||||
void activateReserved(PileReservedDTO dto);
|
||||
|
||||
/**
|
||||
* 关闭预约
|
||||
* @param dto
|
||||
*/
|
||||
void deactivateReserved(PileReservedDTO dto);
|
||||
|
||||
/**
|
||||
* 根据充电枪口编号发送预约指令
|
||||
* @param pileConnectorCode
|
||||
*/
|
||||
void pushReservedByPileConnectorCode(String pileConnectorCode);
|
||||
|
||||
/**
|
||||
* 拔枪时,根据充电桩枪口编号关闭仅一次的预约
|
||||
* @param pileConnectorCode
|
||||
*/
|
||||
void cancelOneTimeReservation(String pileConnectorCode);
|
||||
}
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
package com.jsowell.pile.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.jsowell.pile.dto.PileReservedDTO;
|
||||
import com.jsowell.pile.domain.PileReservedInfo;
|
||||
|
||||
public interface PileReservedInfoService {
|
||||
|
||||
|
||||
int deleteByPrimaryKey(Integer id);
|
||||
|
||||
int insert(PileReservedInfo record);
|
||||
|
||||
int insertOrUpdate(PileReservedInfo record);
|
||||
|
||||
int insertOrUpdateSelective(PileReservedInfo record);
|
||||
|
||||
int insertSelective(PileReservedInfo record);
|
||||
|
||||
PileReservedInfo selectByPrimaryKey(Integer id);
|
||||
|
||||
int updateByPrimaryKeySelective(PileReservedInfo record);
|
||||
|
||||
int updateByPrimaryKey(PileReservedInfo record);
|
||||
|
||||
int updateBatch(List<PileReservedInfo> list);
|
||||
|
||||
int batchInsert(List<PileReservedInfo> list);
|
||||
|
||||
int updateBatchSelective(List<PileReservedInfo> list);
|
||||
|
||||
List<PileReservedInfo> getReservationsByMemberIdAndPileSn(String memberId, String pileSn);
|
||||
|
||||
/**
|
||||
* 启动预约
|
||||
* @param dto
|
||||
*/
|
||||
void activateReserved(PileReservedDTO dto);
|
||||
|
||||
/**
|
||||
* 关闭预约
|
||||
* @param dto
|
||||
*/
|
||||
void deactivateReserved(PileReservedDTO dto);
|
||||
|
||||
/**
|
||||
* 根据充电枪口编号发送预约指令
|
||||
* @param pileConnectorCode
|
||||
*/
|
||||
void pushReservedByPileConnectorCode(String pileConnectorCode);
|
||||
|
||||
void cancelOneTimeReservation(String pileConnectorCode);
|
||||
}
|
||||
|
||||
@@ -25,8 +25,6 @@ import com.jsowell.pile.dto.IndexQueryDTO;
|
||||
import com.jsowell.pile.dto.QueryPileDTO;
|
||||
import com.jsowell.pile.dto.ReplaceMerchantStationDTO;
|
||||
import com.jsowell.pile.mapper.PileBasicInfoMapper;
|
||||
import com.jsowell.pile.mapper.PileMerchantInfoMapper;
|
||||
import com.jsowell.pile.mapper.PileSimInfoMapper;
|
||||
import com.jsowell.pile.service.*;
|
||||
import com.jsowell.pile.thirdparty.ConnectorInfo;
|
||||
import com.jsowell.pile.thirdparty.EquipmentInfo;
|
||||
@@ -89,7 +87,7 @@ public class PileBasicInfoServiceImpl implements PileBasicInfoService {
|
||||
private String BASE_URL_PREFIX;
|
||||
|
||||
@Autowired
|
||||
private PileReservedInfoService pileReservedInfoService;
|
||||
private PileReservationInfoService pileReservationInfoService;
|
||||
|
||||
/**
|
||||
* 查询设备管理
|
||||
@@ -465,7 +463,7 @@ public class PileBasicInfoServiceImpl implements PileBasicInfoService {
|
||||
@Override
|
||||
public void firstPlugInCharger(String pileConnectorCode) {
|
||||
// 下发预约指令
|
||||
pileReservedInfoService.pushReservedByPileConnectorCode(pileConnectorCode);
|
||||
pileReservationInfoService.pushReservedByPileConnectorCode(pileConnectorCode);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -476,7 +474,7 @@ public class PileBasicInfoServiceImpl implements PileBasicInfoService {
|
||||
@Override
|
||||
public void firstUnplugCharger(String pileConnectorCode) {
|
||||
// 关闭仅执行一次的预约
|
||||
pileReservedInfoService.cancelOneTimeReservation(pileConnectorCode);
|
||||
pileReservationInfoService.cancelOneTimeReservation(pileConnectorCode);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,173 @@
|
||||
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.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.List;
|
||||
|
||||
import com.jsowell.pile.mapper.PileReservationInfoMapper;
|
||||
import com.jsowell.pile.domain.PileReservationInfo;
|
||||
import com.jsowell.pile.service.PileReservationInfoService;
|
||||
|
||||
@Service
|
||||
public class PileReservationInfoServiceImpl implements PileReservationInfoService {
|
||||
|
||||
@Resource
|
||||
private PileReservationInfoMapper pileReservationInfoMapper;
|
||||
|
||||
@Override
|
||||
public int deleteByPrimaryKey(Integer id) {
|
||||
return pileReservationInfoMapper.deleteByPrimaryKey(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int insert(PileReservationInfo record) {
|
||||
return pileReservationInfoMapper.insert(record);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int insertOrUpdate(PileReservationInfo record) {
|
||||
return pileReservationInfoMapper.insertOrUpdate(record);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int insertOrUpdateSelective(PileReservationInfo record) {
|
||||
return pileReservationInfoMapper.insertOrUpdateSelective(record);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int insertSelective(PileReservationInfo record) {
|
||||
return pileReservationInfoMapper.insertSelective(record);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PileReservationInfo selectByPrimaryKey(Integer id) {
|
||||
return pileReservationInfoMapper.selectByPrimaryKey(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateByPrimaryKeySelective(PileReservationInfo record) {
|
||||
return pileReservationInfoMapper.updateByPrimaryKeySelective(record);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateByPrimaryKey(PileReservationInfo record) {
|
||||
return pileReservationInfoMapper.updateByPrimaryKey(record);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateBatch(List<PileReservationInfo> list) {
|
||||
return pileReservationInfoMapper.updateBatch(list);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int batchInsert(List<PileReservationInfo> list) {
|
||||
return pileReservationInfoMapper.batchInsert(list);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateBatchSelective(List<PileReservationInfo> list) {
|
||||
return pileReservationInfoMapper.updateBatchSelective(list);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PileReservationInfo> getReservationsByMemberIdAndPileSn(String memberId, String pileSn) {
|
||||
return pileReservationInfoMapper.findByMemberIdAndPileSn(memberId, pileSn);
|
||||
}
|
||||
|
||||
/**
|
||||
* 启用预约
|
||||
*/
|
||||
@Override
|
||||
public void activateReserved(PileReservedDTO dto) {
|
||||
PileReservationInfo pileReservationInfo = pileReservationInfoMapper.selectByPrimaryKey(Integer.parseInt(dto.getReservedId()));
|
||||
if (pileReservationInfo == null) {
|
||||
return;
|
||||
}
|
||||
if (!StringUtils.equals(dto.getMemberId(), pileReservationInfo.getMemberId())) {
|
||||
return;
|
||||
}
|
||||
pileReservationInfo.setStatus(Constants.ONE);
|
||||
// 保存之前,校验时间是否重叠
|
||||
saveReservation(pileReservationInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 禁用预约
|
||||
*/
|
||||
@Override
|
||||
public void deactivateReserved(PileReservedDTO dto) {
|
||||
PileReservationInfo pileReservationInfo = pileReservationInfoMapper.selectByPrimaryKey(Integer.parseInt(dto.getReservedId()));
|
||||
if (pileReservationInfo == null) {
|
||||
return;
|
||||
}
|
||||
if (!StringUtils.equals(dto.getMemberId(), pileReservationInfo.getMemberId())) {
|
||||
return;
|
||||
}
|
||||
// 校验通过可以修改预约
|
||||
pileReservationInfo.setStatus(Constants.ZERO);
|
||||
pileReservationInfoMapper.updateByPrimaryKeySelective(pileReservationInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验时间是否重叠
|
||||
* @param memberId
|
||||
* @param pileSn
|
||||
* @param startTime
|
||||
* @param endTime
|
||||
* @param reservationId
|
||||
* @return
|
||||
*/
|
||||
public boolean isTimeSlotAvailable(String memberId, String pileSn, Time startTime, Time endTime, Integer reservationId) {
|
||||
List<PileReservationInfo> reservations = pileReservationInfoMapper.findByMemberIdAndPileSnAndStatus(memberId, pileSn, "1");
|
||||
LocalTime newStartTime = startTime.toLocalTime();
|
||||
LocalTime newEndTime = endTime.toLocalTime();
|
||||
|
||||
for (PileReservationInfo res : reservations) {
|
||||
if (res.getId().equals(reservationId)) {
|
||||
continue; // Skip the current reservation if updating
|
||||
}
|
||||
LocalTime existingStartTime = res.getStartTime().toLocalTime();
|
||||
LocalTime existingEndTime = res.getEndTime().toLocalTime();
|
||||
|
||||
if (newStartTime.isBefore(existingEndTime) && newEndTime.isAfter(existingStartTime)) {
|
||||
return false; // Time slot overlaps
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void saveReservation(PileReservationInfo reservation) {
|
||||
if (isTimeSlotAvailable(reservation.getMemberId(), reservation.getPileSn(), reservation.getStartTime(), reservation.getEndTime(), reservation.getId())) {
|
||||
this.updateByPrimaryKeySelective(reservation);
|
||||
} else {
|
||||
throw new BusinessException(ReturnCodeEnum.CODE_UPDATE_RESERVED_STATUS_REFUSED);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据充电枪口编号发送指令
|
||||
* @param pileConnectorCode
|
||||
*/
|
||||
@Override
|
||||
public void pushReservedByPileConnectorCode(String pileConnectorCode) {
|
||||
// 根据充电枪口编号查询正在生效中的预约
|
||||
}
|
||||
|
||||
/**
|
||||
* 拔枪时,根据充电桩枪口编号关闭仅一次的预约
|
||||
* @param pileConnectorCode
|
||||
*/
|
||||
@Override
|
||||
public void cancelOneTimeReservation(String pileConnectorCode) {
|
||||
// 根据充电枪口编号查询仅一次正在生效中的预约
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,164 +0,0 @@
|
||||
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.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.List;
|
||||
|
||||
import com.jsowell.pile.mapper.PileReservedInfoMapper;
|
||||
import com.jsowell.pile.domain.PileReservedInfo;
|
||||
import com.jsowell.pile.service.PileReservedInfoService;
|
||||
|
||||
@Service
|
||||
public class PileReservedInfoServiceImpl implements PileReservedInfoService {
|
||||
|
||||
@Resource
|
||||
private PileReservedInfoMapper pileReservedInfoMapper;
|
||||
|
||||
@Override
|
||||
public int deleteByPrimaryKey(Integer id) {
|
||||
return pileReservedInfoMapper.deleteByPrimaryKey(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int insert(PileReservedInfo record) {
|
||||
return pileReservedInfoMapper.insert(record);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int insertOrUpdate(PileReservedInfo record) {
|
||||
return pileReservedInfoMapper.insertOrUpdate(record);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int insertOrUpdateSelective(PileReservedInfo record) {
|
||||
return pileReservedInfoMapper.insertOrUpdateSelective(record);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int insertSelective(PileReservedInfo record) {
|
||||
return pileReservedInfoMapper.insertSelective(record);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PileReservedInfo selectByPrimaryKey(Integer id) {
|
||||
return pileReservedInfoMapper.selectByPrimaryKey(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateByPrimaryKeySelective(PileReservedInfo record) {
|
||||
return pileReservedInfoMapper.updateByPrimaryKeySelective(record);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateByPrimaryKey(PileReservedInfo record) {
|
||||
return pileReservedInfoMapper.updateByPrimaryKey(record);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateBatch(List<PileReservedInfo> list) {
|
||||
return pileReservedInfoMapper.updateBatch(list);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int batchInsert(List<PileReservedInfo> list) {
|
||||
return pileReservedInfoMapper.batchInsert(list);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateBatchSelective(List<PileReservedInfo> list) {
|
||||
return pileReservedInfoMapper.updateBatchSelective(list);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PileReservedInfo> getReservationsByMemberIdAndPileSn(String memberId, String pileSn) {
|
||||
return pileReservedInfoMapper.findByMemberIdAndPileSn(memberId, pileSn);
|
||||
}
|
||||
|
||||
/**
|
||||
* 启用预约
|
||||
*/
|
||||
@Override
|
||||
public void activateReserved(PileReservedDTO dto) {
|
||||
PileReservedInfo pileReservedInfo = pileReservedInfoMapper.selectByPrimaryKey(Integer.parseInt(dto.getReservedId()));
|
||||
if (pileReservedInfo == null) {
|
||||
return;
|
||||
}
|
||||
if (!StringUtils.equals(dto.getMemberId(), pileReservedInfo.getMemberId())) {
|
||||
return;
|
||||
}
|
||||
pileReservedInfo.setStatus(Constants.ONE);
|
||||
// 保存之前,校验时间是否重叠
|
||||
saveReservation(pileReservedInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 禁用预约
|
||||
*/
|
||||
@Override
|
||||
public void deactivateReserved(PileReservedDTO dto) {
|
||||
PileReservedInfo pileReservedInfo = pileReservedInfoMapper.selectByPrimaryKey(Integer.parseInt(dto.getReservedId()));
|
||||
if (pileReservedInfo == null) {
|
||||
return;
|
||||
}
|
||||
if (!StringUtils.equals(dto.getMemberId(), pileReservedInfo.getMemberId())) {
|
||||
return;
|
||||
}
|
||||
// 校验通过可以修改预约
|
||||
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, Time startTime, Time endTime, Integer reservationId) {
|
||||
List<PileReservedInfo> reservations = pileReservedInfoMapper.findByMemberIdAndPileSnAndStatus(memberId, pileSn, "1");
|
||||
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 = res.getStartTime().toLocalTime();
|
||||
LocalTime existingEndTime = res.getEndTime().toLocalTime();
|
||||
|
||||
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 BusinessException(ReturnCodeEnum.CODE_UPDATE_RESERVED_STATUS_REFUSED);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据充电枪口编号发送指令
|
||||
* @param pileConnectorCode
|
||||
*/
|
||||
@Override
|
||||
public void pushReservedByPileConnectorCode(String pileConnectorCode) {
|
||||
// 根据充电枪口编号查询正在生效中的预约
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user