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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
package com.talentcard.server.mapper;
 
import java.util.List;
import java.util.Map;
 
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.talentcard.server.entity.MerchantDisplayPolicyMerchant;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
 
@Mapper
public interface DisplayServiceMapper extends BaseMapper<MerchantDisplayPolicyMerchant> {
 
    @Select("""
            <script>
            select m.id as merchantId,
                   m.merchant_name as merchantName,
                   case
                     when m.merchant_type = 'parking' then 'parking'
                     when m.merchant_type = 'medical' then 'medical'
                     when m.merchant_type = 'apartment' then 'apartment'
                     when exists (select 1 from shopping_topic_merchant s1 where s1.merchant_id = m.id and s1.deleted = 0 and s1.category_key = 'housing') then 'housing'
                     when exists (select 1 from shopping_topic_merchant s2 where s2.merchant_id = m.id and s2.deleted = 0 and s2.category_key = 'car') then 'car'
                     when exists (select 1 from shopping_topic_merchant s3 where s3.merchant_id = m.id and s3.deleted = 0 and s3.category_key = 'appliance') then 'appliance'
                     else m.merchant_type
                   end as category,
                   m.merchant_type as merchantType,
                   m.contact_name as contactName,
                   m.contact_mobile as contactMobile,
                   m.logo_url as logoUrl,
                   m.cover_url as coverUrl,
                   m.address,
                   m.business_status as businessStatus,
                   m.longitude,
                   m.latitude,
                   m.usage_instructions as handlingInstructions,
                   m.rights_text as rightsText,
                   m.service_label as serviceLabel,
                   m.is_recommend as recommend,
                   m.sort_no as sortNo,
                   m.status,
                   (select count(*) from merchant_card_benefit b where b.merchant_id = m.id) as policyCount,
                   m.created_at as createdAt,
                   m.updated_at as updatedAt
            from merchant m
            where m.deleted = 0
              and (
                    m.merchant_type in ('parking', 'medical', 'apartment')
                    or exists (
                        select 1
                        from shopping_topic_merchant sm
                        where sm.merchant_id = m.id
                          and sm.deleted = 0
                          and sm.category_key in ('housing', 'car', 'appliance')
                    )
                  )
              <if test="category != null and category != ''">
                <choose>
                  <when test="category == 'housing' or category == 'car' or category == 'appliance'">
                    and m.merchant_type = 'shopping'
                    and exists (
                        select 1
                        from shopping_topic_merchant sm
                        where sm.merchant_id = m.id
                          and sm.deleted = 0
                          and sm.category_key = #{category}
                    )
                  </when>
                  <otherwise>
                    and m.merchant_type = #{category}
                  </otherwise>
                </choose>
              </if>
              <if test="status != null">and m.status = #{status}</if>
              <if test="keyword != null and keyword != ''">
                and (m.merchant_name like concat('%', #{keyword}, '%')
                     or m.contact_mobile like concat('%', #{keyword}, '%')
                     or m.address like concat('%', #{keyword}, '%'))
              </if>
            order by m.sort_no desc, m.id desc
            limit #{size} offset #{offset}
            </script>
            """)
    List<Map<String, Object>> selectAdminPage(@Param("category") String category,
                                              @Param("keyword") String keyword,
                                              @Param("status") Integer status,
                                              @Param("size") int size,
                                              @Param("offset") int offset);
 
    @Select("""
            <script>
            select count(*)
            from merchant m
            where m.deleted = 0
              and (
                    m.merchant_type in ('parking', 'medical', 'apartment')
                    or exists (
                        select 1
                        from shopping_topic_merchant sm
                        where sm.merchant_id = m.id
                          and sm.deleted = 0
                          and sm.category_key in ('housing', 'car', 'appliance')
                    )
                  )
              <if test="category != null and category != ''">
                <choose>
                  <when test="category == 'housing' or category == 'car' or category == 'appliance'">
                    and m.merchant_type = 'shopping'
                    and exists (
                        select 1
                        from shopping_topic_merchant sm
                        where sm.merchant_id = m.id
                          and sm.deleted = 0
                          and sm.category_key = #{category}
                    )
                  </when>
                  <otherwise>
                    and m.merchant_type = #{category}
                  </otherwise>
                </choose>
              </if>
              <if test="status != null">and m.status = #{status}</if>
              <if test="keyword != null and keyword != ''">
                and (m.merchant_name like concat('%', #{keyword}, '%')
                     or m.contact_mobile like concat('%', #{keyword}, '%')
                     or m.address like concat('%', #{keyword}, '%'))
              </if>
            </script>
            """)
    Long countAdminPage(@Param("category") String category,
                        @Param("keyword") String keyword,
                        @Param("status") Integer status);
 
    @Select("""
            <script>
            select m.id as merchantId,
                   m.merchant_name as merchantName,
                   case
                     when m.merchant_type = 'parking' then 'parking'
                     when m.merchant_type = 'medical' then 'medical'
                     when m.merchant_type = 'apartment' then 'apartment'
                     when exists (select 1 from shopping_topic_merchant s1 where s1.merchant_id = m.id and s1.deleted = 0 and s1.category_key = 'housing') then 'housing'
                     when exists (select 1 from shopping_topic_merchant s2 where s2.merchant_id = m.id and s2.deleted = 0 and s2.category_key = 'car') then 'car'
                     when exists (select 1 from shopping_topic_merchant s3 where s3.merchant_id = m.id and s3.deleted = 0 and s3.category_key = 'appliance') then 'appliance'
                     else m.merchant_type
                   end as category,
                   m.merchant_type as merchantType,
                   m.contact_name as contactName,
                   m.contact_mobile as contactMobile,
                   m.logo_url as logoUrl,
                   m.cover_url as coverUrl,
                   m.address,
                   m.business_status as businessStatus,
                   m.longitude,
                   m.latitude,
                   m.usage_instructions as handlingInstructions,
                   m.rights_text as rightsText,
                   m.service_label as serviceLabel,
                   m.is_recommend as recommend,
                   m.sort_no as sortNo,
                   m.status,
                   (select count(*) from merchant_card_benefit b where b.merchant_id = m.id) as policyCount,
                   m.created_at as createdAt,
                   m.updated_at as updatedAt
            from merchant m
            where m.deleted = 0
              and m.id = #{serviceId}
              and (
                    m.merchant_type in ('parking', 'medical', 'apartment')
                    or exists (
                        select 1
                        from shopping_topic_merchant sm
                        where sm.merchant_id = m.id
                          and sm.deleted = 0
                          and sm.category_key in ('housing', 'car', 'appliance')
                    )
                  )
            limit 1
            </script>
            """)
    Map<String, Object> selectAdminDetail(@Param("serviceId") Long serviceId);
}