shinnosuke
2026-08-05 971e637c2eebe93011a485ddfa99d4f19289811d
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package com.talentcard.server.mapper;
 
import java.util.Map;
 
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.talentcard.server.entity.ServiceApplication;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
 
@Mapper
public interface ServiceApplicationMapper extends BaseMapper<ServiceApplication> {
 
    @Select("""
            select c.id as cardId,
                   c.talent_id as talentId,
                   c.card_no as cardNo,
                   c.card_level as talentLevel,
                   c.card_type as cardType,
                   u.name as talentName,
                   u.mobile as talentMobile,
                   u.id_card_no as talentIdCardNo
            from talent_card c
            join talent_user u on u.id = c.talent_id and u.deleted = 0 and u.status = 1
            where c.deleted = 0
              and c.status = 1
              and (c.valid_start is null or c.valid_start <= current_date)
              and (c.valid_end is null or c.valid_end >= current_date)
              and (c.expire_time is null or c.expire_time > now())
              and ((#{cardId} is not null and c.id = #{cardId}) or (#{cardId} is null and c.talent_id = #{talentId}))
              and (#{talentId} is null or c.talent_id = #{talentId})
            order by case when c.card_type = 'PERSONAL' then 0 else 1 end, c.id desc
            limit 1
            """)
    Map<String, Object> selectActiveCardSnapshot(@Param("talentId") Long talentId, @Param("cardId") Long cardId);
 
    @Select("""
            select id as merchantId,
                   merchant_name as merchantName,
                   merchant_type as merchantType,
                   contact_mobile as contactMobile,
                   address,
                   longitude,
                   latitude
            from merchant
            where id = #{merchantId} and deleted = 0 and status = 1
            limit 1
            """)
    Map<String, Object> selectMerchantSnapshot(@Param("merchantId") Long merchantId);
 
    @Select("""
            select m.id as merchantId,
                   m.merchant_name as merchantName,
                   m.merchant_type as merchantType,
                   m.contact_mobile as contactMobile,
                   m.address,
                   m.longitude,
                   m.latitude
            from merchant m
            join premium_topic_merchant mapping on mapping.merchant_id = m.id and mapping.deleted = 0
            where m.id = #{merchantId}
              and mapping.category_key = #{categoryKey}
              and m.deleted = 0
              and m.status = 1
            limit 1
            """)
    Map<String, Object> selectPremiumMerchantSnapshot(@Param("merchantId") Long merchantId, @Param("categoryKey") String categoryKey);
 
    @Select("""
            select p.id as packageId,
                   p.merchant_id as merchantId,
                   p.package_name as packageName,
                   p.stock,
                   p.status,
                   p.unavailable_reason as unavailableReason
            from medical_package p
            where p.id = #{packageId}
              and (#{merchantId} is null or p.merchant_id = #{merchantId})
              and p.deleted = 0
            limit 1
            """)
    Map<String, Object> selectMedicalPackage(@Param("packageId") Long packageId, @Param("merchantId") Long merchantId);
 
    @Select("""
            select id as productId,
                   merchant_id as merchantId,
                   product_name as productName,
                   stock,
                   status
            from merchant_product
            where id = #{productId}
              and (#{merchantId} is null or merchant_id = #{merchantId})
              and deleted = 0
            limit 1
            """)
    Map<String, Object> selectMerchantProduct(@Param("productId") Long productId, @Param("merchantId") Long merchantId);
 
    @Select("""
            select id as schoolId,
                   school_name as schoolName,
                   address,
                   latitude,
                   longitude,
                   contact_mobile as contactMobile,
                   enabled
            from children_entrustment_school
            where id = #{schoolId} and deleted = 0
            limit 1
            """)
    Map<String, Object> selectChildrenSchool(@Param("schoolId") Long schoolId);
 
    @Select("""
            select *
            from service_application
            where id = #{id} and deleted = 0
            limit 1
            for update
            """)
    ServiceApplication selectByIdForUpdate(@Param("id") Long id);
}