mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-20 11:05:18 +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.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -258,6 +258,100 @@
|
||||
#{item.id,jdbcType=INTEGER}
|
||||
</foreach>
|
||||
</update>
|
||||
<update id="updateBatchSelective" parameterType="java.util.List">
|
||||
<!--@mbg.generated-->
|
||||
update pile_reserved_info
|
||||
<trim prefix="set" suffixOverrides=",">
|
||||
<trim prefix="member_id = case" suffix="end,">
|
||||
<foreach collection="list" index="index" item="item">
|
||||
<if test="item.memberId != null">
|
||||
when id = #{item.id,jdbcType=INTEGER} then #{item.memberId,jdbcType=VARCHAR}
|
||||
</if>
|
||||
</foreach>
|
||||
</trim>
|
||||
<trim prefix="pile_sn = case" suffix="end,">
|
||||
<foreach collection="list" index="index" item="item">
|
||||
<if test="item.pileSn != null">
|
||||
when id = #{item.id,jdbcType=INTEGER} then #{item.pileSn,jdbcType=VARCHAR}
|
||||
</if>
|
||||
</foreach>
|
||||
</trim>
|
||||
<trim prefix="`status` = case" suffix="end,">
|
||||
<foreach collection="list" index="index" item="item">
|
||||
<if test="item.status != null">
|
||||
when id = #{item.id,jdbcType=INTEGER} then #{item.status,jdbcType=VARCHAR}
|
||||
</if>
|
||||
</foreach>
|
||||
</trim>
|
||||
<trim prefix="reserved_type = case" suffix="end,">
|
||||
<foreach collection="list" index="index" item="item">
|
||||
<if test="item.reservedType != null">
|
||||
when id = #{item.id,jdbcType=INTEGER} then #{item.reservedType,jdbcType=VARCHAR}
|
||||
</if>
|
||||
</foreach>
|
||||
</trim>
|
||||
<trim prefix="start_time = case" suffix="end,">
|
||||
<foreach collection="list" index="index" item="item">
|
||||
<if test="item.startTime != null">
|
||||
when id = #{item.id,jdbcType=INTEGER} then #{item.startTime,jdbcType=TIME}
|
||||
</if>
|
||||
</foreach>
|
||||
</trim>
|
||||
<trim prefix="end_time = case" suffix="end,">
|
||||
<foreach collection="list" index="index" item="item">
|
||||
<if test="item.endTime != null">
|
||||
when id = #{item.id,jdbcType=INTEGER} then #{item.endTime,jdbcType=TIME}
|
||||
</if>
|
||||
</foreach>
|
||||
</trim>
|
||||
<trim prefix="freq = case" suffix="end,">
|
||||
<foreach collection="list" index="index" item="item">
|
||||
<if test="item.freq != null">
|
||||
when id = #{item.id,jdbcType=INTEGER} then #{item.freq,jdbcType=VARCHAR}
|
||||
</if>
|
||||
</foreach>
|
||||
</trim>
|
||||
<trim prefix="create_by = case" suffix="end,">
|
||||
<foreach collection="list" index="index" item="item">
|
||||
<if test="item.createBy != null">
|
||||
when id = #{item.id,jdbcType=INTEGER} then #{item.createBy,jdbcType=VARCHAR}
|
||||
</if>
|
||||
</foreach>
|
||||
</trim>
|
||||
<trim prefix="create_time = case" suffix="end,">
|
||||
<foreach collection="list" index="index" item="item">
|
||||
<if test="item.createTime != null">
|
||||
when id = #{item.id,jdbcType=INTEGER} then #{item.createTime,jdbcType=TIMESTAMP}
|
||||
</if>
|
||||
</foreach>
|
||||
</trim>
|
||||
<trim prefix="update_by = case" suffix="end,">
|
||||
<foreach collection="list" index="index" item="item">
|
||||
<if test="item.updateBy != null">
|
||||
when id = #{item.id,jdbcType=INTEGER} then #{item.updateBy,jdbcType=VARCHAR}
|
||||
</if>
|
||||
</foreach>
|
||||
</trim>
|
||||
<trim prefix="update_time = case" suffix="end,">
|
||||
<foreach collection="list" index="index" item="item">
|
||||
<if test="item.updateTime != null">
|
||||
when id = #{item.id,jdbcType=INTEGER} then #{item.updateTime,jdbcType=TIMESTAMP}
|
||||
</if>
|
||||
</foreach>
|
||||
</trim>
|
||||
<trim prefix="del_flag = case" suffix="end,">
|
||||
<foreach collection="list" index="index" item="item">
|
||||
<if test="item.delFlag != null">
|
||||
when id = #{item.id,jdbcType=INTEGER} then #{item.delFlag,jdbcType=CHAR}
|
||||
</if>
|
||||
</foreach>
|
||||
</trim>
|
||||
</trim>
|
||||
where id in
|
||||
<foreach close=")" collection="list" item="item" open="(" separator=", ">
|
||||
#{item.id,jdbcType=INTEGER}
|
||||
</foreach>
|
||||
</update>
|
||||
<insert id="batchInsert" keyColumn="id" keyProperty="id" parameterType="map" useGeneratedKeys="true">
|
||||
<!--@mbg.generated-->
|
||||
insert into pile_reserved_info
|
||||
@@ -458,4 +552,23 @@
|
||||
</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<select id="findByMemberIdAndPileSnAndStatus" resultMap="BaseResultMap">
|
||||
select
|
||||
<include refid="Base_Column_List" />
|
||||
from pile_reserved_info
|
||||
where del_flag = '0'
|
||||
and member_id = #{memberId,jdbcType=VARCHAR}
|
||||
and pile_sn = #{pileSn,jdbcType=VARCHAR}
|
||||
and status = #{status,jdbcType=VARCHAR}
|
||||
</select>
|
||||
|
||||
<select id="findByMemberIdAndPileSn" resultMap="BaseResultMap">
|
||||
select
|
||||
<include refid="Base_Column_List" />
|
||||
from pile_reserved_info
|
||||
where del_flag = '0'
|
||||
and member_id = #{memberId,jdbcType=VARCHAR}
|
||||
and pile_sn = #{pileSn,jdbcType=VARCHAR}
|
||||
</select>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user