shinnosuke
2026-08-11 7aa1d7b9f9ad0b95b24d0c18fe04d326630d7dc2
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
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 MerchantDisplayPolicyMerchantMapper extends BaseMapper<MerchantDisplayPolicyMerchant> {
 
    @Select("""
            <script>
            select m.id as merchantId,
                   m.merchant_name as merchantName,
                   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,
                   m.created_at as createdAt,
                   m.updated_at as updatedAt,
                   (select count(*) from merchant_card_benefit b where b.merchant_id = m.id) as policyCount
            from merchant m
            where m.deleted = 0
              <if test="merchantId != null">and m.id = #{merchantId}</if>
              <if test="merchantType != null and merchantType != ''">and m.merchant_type = #{merchantType}</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>
              <if test="cardLevelAliases != null and cardLevelAliases.size() > 0">
                and exists (
                    select 1
                    from merchant_card_benefit b
                    where b.merchant_id = m.id
                      and b.card_level in
                      <foreach collection="cardLevelAliases" item="level" open="(" separator="," close=")">
                        #{level}
                      </foreach>
                )
              </if>
            order by m.sort_no desc, m.id desc
            limit #{size} offset #{offset}
            </script>
            """)
    List<Map<String, Object>> selectAdminPage(@Param("merchantId") Long merchantId,
                                              @Param("keyword") String keyword,
                                              @Param("merchantType") String merchantType,
                                              @Param("cardLevelAliases") List<String> cardLevelAliases,
                                              @Param("status") Integer status,
                                              @Param("size") int size,
                                              @Param("offset") int offset);
 
    @Select("""
            <script>
            select count(*)
            from merchant m
            where m.deleted = 0
              <if test="merchantId != null">and m.id = #{merchantId}</if>
              <if test="merchantType != null and merchantType != ''">and m.merchant_type = #{merchantType}</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>
              <if test="cardLevelAliases != null and cardLevelAliases.size() > 0">
                and exists (
                    select 1
                    from merchant_card_benefit b
                    where b.merchant_id = m.id
                      and b.card_level in
                      <foreach collection="cardLevelAliases" item="level" open="(" separator="," close=")">
                        #{level}
                      </foreach>
                )
              </if>
            </script>
            """)
    Long countAdminPage(@Param("merchantId") Long merchantId,
                        @Param("keyword") String keyword,
                        @Param("merchantType") String merchantType,
                        @Param("cardLevelAliases") List<String> cardLevelAliases,
                        @Param("status") Integer status);
 
    @Select("""
            select m.id as merchantId,
                   m.merchant_name as merchantName,
                   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,
                   m.created_at as createdAt,
                   m.updated_at as updatedAt
            from merchant m
            where m.deleted = 0 and m.id = #{merchantId}
            limit 1
            """)
    Map<String, Object> selectAdminDetail(@Param("merchantId") Long merchantId);
 
    @Select("""
            <script>
            select m.id as merchantId,
                   m.merchant_name as merchantName,
                   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.longitude,
                   m.latitude,
                   m.usage_instructions as handlingInstructions,
                   m.rights_text as rightsText,
                   m.service_label as serviceLabel,
                   m.sort_no as sortNo,
                   m.status,
                   b.id as benefitId,
                   b.card_level as cardLevel,
                   b.card_name as cardName,
                   b.benefit_text as policyText,
                   b.theme,
                   b.sort_no as benefitSortNo,
                   b.updated_at as policyUpdatedAt
            from merchant m
            join merchant_card_benefit b on b.id = (
                select bb.id
                from merchant_card_benefit bb
                where bb.merchant_id = m.id
                  and bb.status = 1
                  and bb.card_level in
                  <foreach collection="cardLevelAliases" item="level" open="(" separator="," close=")">
                    #{level}
                  </foreach>
                order by bb.sort_no desc, bb.id desc
                limit 1
            )
            where m.deleted = 0
              and m.status = 1
              <if test="merchantType != null and merchantType != ''">and m.merchant_type = #{merchantType}</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 b.sort_no desc, m.sort_no desc, m.id desc
            limit #{size} offset #{offset}
            </script>
            """)
    List<Map<String, Object>> selectPortalPage(@Param("cardLevelAliases") List<String> cardLevelAliases,
                                               @Param("merchantType") String merchantType,
                                               @Param("keyword") String keyword,
                                               @Param("size") int size,
                                               @Param("offset") int offset);
 
    @Select("""
            <script>
            select count(*)
            from merchant m
            where m.deleted = 0
              and m.status = 1
              <if test="merchantType != null and merchantType != ''">and m.merchant_type = #{merchantType}</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>
              and exists (
                select 1
                from merchant_card_benefit b
                where b.merchant_id = m.id
                  and b.status = 1
                  and b.card_level in
                  <foreach collection="cardLevelAliases" item="level" open="(" separator="," close=")">
                    #{level}
                  </foreach>
              )
            </script>
            """)
    Long countPortalPage(@Param("cardLevelAliases") List<String> cardLevelAliases,
                         @Param("merchantType") String merchantType,
                         @Param("keyword") String keyword);
 
    @Select("""
            <script>
            select m.id as merchantId,
                   m.merchant_name as merchantName,
                   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.longitude,
                   m.latitude,
                   m.usage_instructions as handlingInstructions,
                   m.rights_text as rightsText,
                   m.service_label as serviceLabel,
                   m.sort_no as sortNo,
                   m.status,
                   b.id as benefitId,
                   b.card_level as cardLevel,
                   b.card_name as cardName,
                   b.benefit_text as policyText,
                   b.theme,
                   b.sort_no as benefitSortNo,
                   b.updated_at as policyUpdatedAt
            from merchant m
            join merchant_card_benefit b on b.id = (
                select bb.id
                from merchant_card_benefit bb
                where bb.merchant_id = m.id
                  and bb.status = 1
                  and bb.card_level in
                  <foreach collection="cardLevelAliases" item="level" open="(" separator="," close=")">
                    #{level}
                  </foreach>
                order by bb.sort_no desc, bb.id desc
                limit 1
            )
            where m.deleted = 0
              and m.status = 1
              and m.id = #{merchantId}
            limit 1
            </script>
            """)
    Map<String, Object> selectPortalDetail(@Param("merchantId") Long merchantId,
                                           @Param("cardLevelAliases") List<String> cardLevelAliases);
 
    @Select("""
            <script>
            select e.id,
                   e.merchant_id as merchantId,
                   m.merchant_name as merchantName,
                   m.merchant_type as merchantType,
                   e.talent_id as talentId,
                   e.card_id as cardId,
                   e.primary_card_id as primaryCardId,
                   e.card_level as cardLevel,
                   e.event_type as eventType,
                   e.remark,
                   e.created_at as createdAt
            from merchant_display_policy_event e
            left join merchant m on m.id = e.merchant_id and m.deleted = 0
            where e.deleted = 0
              <if test="merchantId != null">and e.merchant_id = #{merchantId}</if>
              <if test="eventType != null and eventType != ''">and e.event_type = #{eventType}</if>
              <if test="cardLevelAliases != null and cardLevelAliases.size() > 0">
                and e.card_level in
                <foreach collection="cardLevelAliases" item="level" open="(" separator="," close=")">
                  #{level}
                </foreach>
              </if>
              <if test="keyword != null and keyword != ''">
                and (m.merchant_name like concat('%', #{keyword}, '%') or e.remark like concat('%', #{keyword}, '%'))
              </if>
            order by e.created_at desc, e.id desc
            limit #{size} offset #{offset}
            </script>
            """)
    List<Map<String, Object>> selectEventPage(@Param("merchantId") Long merchantId,
                                              @Param("eventType") String eventType,
                                              @Param("cardLevelAliases") List<String> cardLevelAliases,
                                              @Param("keyword") String keyword,
                                              @Param("size") int size,
                                              @Param("offset") int offset);
 
    @Select("""
            <script>
            select count(*)
            from merchant_display_policy_event e
            left join merchant m on m.id = e.merchant_id and m.deleted = 0
            where e.deleted = 0
              <if test="merchantId != null">and e.merchant_id = #{merchantId}</if>
              <if test="eventType != null and eventType != ''">and e.event_type = #{eventType}</if>
              <if test="cardLevelAliases != null and cardLevelAliases.size() > 0">
                and e.card_level in
                <foreach collection="cardLevelAliases" item="level" open="(" separator="," close=")">
                  #{level}
                </foreach>
              </if>
              <if test="keyword != null and keyword != ''">
                and (m.merchant_name like concat('%', #{keyword}, '%') or e.remark like concat('%', #{keyword}, '%'))
              </if>
            </script>
            """)
    Long countEventPage(@Param("merchantId") Long merchantId,
                        @Param("eventType") String eventType,
                        @Param("cardLevelAliases") List<String> cardLevelAliases,
                        @Param("keyword") String keyword);
}