liujie
2026-08-14 92a75a7b157e6fd6423df17cfd32015017bdb8c9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package com.tourguide.modules.user.mapper;
 
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tourguide.modules.user.entity.GuideReceivingSession;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import java.time.LocalDateTime;
import java.util.List;
 
public interface GuideReceivingSessionMapper extends BaseMapper<GuideReceivingSession> {
    @Select("SELECT s.* FROM guide_receiving_session s " +
            "INNER JOIN guide_realtime_status r ON r.guide_id = s.guide_id AND r.deleted = 0 " +
            "INNER JOIN guide_user g ON g.id = s.guide_id AND g.deleted = 0 AND g.status = 1 " +
            "WHERE s.deleted = 0 AND s.status = 'RECEIVING' AND r.online_status = 1 AND r.available_status = 1 " +
            "AND s.scenic_spot_id = #{scenicSpotId} AND s.meeting_point_id = #{meetingPointId} " +
            "AND s.receiving_mode = #{receivingMode} AND FIND_IN_SET(#{serviceType}, s.service_types) > 0 " +
            "AND (s.order_cutoff_at IS NULL OR s.order_cutoff_at > NOW()) " +
            "ORDER BY g.rating DESC, g.accepted_order_count DESC, g.created_at ASC LIMIT 50 FOR UPDATE")
    List<GuideReceivingSession> selectMatchCandidates(@Param("scenicSpotId") Long scenicSpotId,
                                                       @Param("meetingPointId") Long meetingPointId,
                                                       @Param("receivingMode") String receivingMode,
                                                       @Param("serviceType") String serviceType);
 
    @Update("UPDATE guide_receiving_session SET current_people_count = current_people_count + #{peopleCount}, " +
            "first_order_at = COALESCE(first_order_at, #{now}), service_start_at = COALESCE(service_start_at, #{serviceStartAt}), " +
            "order_cutoff_at = COALESCE(order_cutoff_at, #{orderCutoffAt}), updated_at = NOW() " +
            "WHERE id = #{id} AND deleted = 0 AND status = 'RECEIVING' AND current_people_count + #{peopleCount} <= #{maxPeople}")
    int reserveGroupCapacity(@Param("id") Long id, @Param("peopleCount") Integer peopleCount,
                             @Param("maxPeople") Integer maxPeople, @Param("now") LocalDateTime now,
                             @Param("serviceStartAt") LocalDateTime serviceStartAt,
                             @Param("orderCutoffAt") LocalDateTime orderCutoffAt);
 
    @Update("UPDATE guide_receiving_session SET status = 'ASSIGNED', current_people_count = #{peopleCount}, " +
            "first_order_at = #{now}, service_start_at = #{now}, order_cutoff_at = #{now}, updated_at = NOW() " +
            "WHERE id = #{id} AND deleted = 0 AND status = 'RECEIVING'")
    int assignPrivate(@Param("id") Long id, @Param("peopleCount") Integer peopleCount, @Param("now") LocalDateTime now);
 
    @Update("UPDATE guide_receiving_session SET status = 'IN_SERVICE', updated_at = NOW() " +
            "WHERE id = #{id} AND deleted = 0 AND status = 'RECEIVING' AND service_start_at <= NOW()")
    int startDueSession(Long id);
 
    @Update("UPDATE guide_receiving_session SET reminder_pushed_at = #{now}, updated_at = NOW() " +
            "WHERE id = #{id} AND deleted = 0 AND status = 'RECEIVING' AND reminder_pushed_at IS NULL")
    int claimServiceReminder(@Param("id") Long id, @Param("now") LocalDateTime now);
 
    @Update("UPDATE guide_receiving_session SET reminder_pushed_at = NULL, updated_at = NOW() " +
            "WHERE id = #{id} AND deleted = 0 AND reminder_pushed_at = #{claimedAt}")
    int releaseServiceReminder(@Param("id") Long id, @Param("claimedAt") LocalDateTime claimedAt);
 
    @Update("UPDATE guide_receiving_session SET status = 'STOPPED', updated_at = NOW() " +
            "WHERE guide_id = #{guideId} AND deleted = 0 AND status = 'RECEIVING'")
    int stopReceivingByGuide(Long guideId);
}