shinnosuke
2026-08-21 bc2efbdb52190fe2e7be9920bbed6902d4ee28aa
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
package com.talentcard.server.mapper;
 
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.talentcard.server.entity.MerchantCouponClaim;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
 
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
 
@Mapper
public interface MerchantCouponClaimMapper extends BaseMapper<MerchantCouponClaim> {
    @Select("""
            <script>
            select cc.*, c.coupon_name as couponName, c.coupon_type as couponType, c.coupon_amount as couponAmount,
                   m.merchant_name as merchantName, u.name as talentName, u.mobile as talentMobile, tc.card_no as cardNo
            from merchant_coupon_claim cc
            join merchant_coupon c on c.id = cc.coupon_id and c.deleted = 0
            join merchant m on m.id = cc.merchant_id and m.deleted = 0
            left join talent_user u on u.id = cc.talent_id and u.deleted = 0
            left join talent_card tc on tc.id = cc.card_id and tc.deleted = 0
            where cc.deleted = 0
              <if test="couponId != null">and cc.coupon_id = #{couponId}</if>
              <if test="merchantId != null">and cc.merchant_id = #{merchantId}</if>
              <if test="batchNo != null and batchNo != ''">and cc.batch_no = #{batchNo}</if>
              <if test="claimStatus != null">and cc.claim_status = #{claimStatus}</if>
              <if test="useStatus != null">and cc.use_status = #{useStatus}</if>
              <if test="keyword != null and keyword != ''">and (cc.claim_no like concat('%', #{keyword}, '%') or u.name like concat('%', #{keyword}, '%') or u.mobile like concat('%', #{keyword}, '%') or tc.card_no like concat('%', #{keyword}, '%'))</if>
              <if test="startTime != null">and cc.claimed_at &gt;= #{startTime}</if>
              <if test="endTime != null">and cc.claimed_at &lt; #{endTime}</if>
            order by cc.claimed_at desc, cc.id desc
            limit #{size} offset #{offset}
            </script>
            """)
    List<Map<String, Object>> selectClaimPage(@Param("couponId") Long couponId,
                                              @Param("merchantId") Long merchantId,
                                              @Param("batchNo") String batchNo,
                                              @Param("claimStatus") Integer claimStatus,
                                              @Param("useStatus") Integer useStatus,
                                              @Param("keyword") String keyword,
                                              @Param("startTime") LocalDateTime startTime,
                                              @Param("endTime") LocalDateTime endTime,
                                              @Param("size") int size,
                                              @Param("offset") int offset);
 
    @Select("""
            <script>
            select count(*) from merchant_coupon_claim cc
            left join talent_user u on u.id = cc.talent_id and u.deleted = 0
            left join talent_card tc on tc.id = cc.card_id and tc.deleted = 0
            where cc.deleted = 0
              <if test="couponId != null">and cc.coupon_id = #{couponId}</if>
              <if test="merchantId != null">and cc.merchant_id = #{merchantId}</if>
              <if test="batchNo != null and batchNo != ''">and cc.batch_no = #{batchNo}</if>
              <if test="claimStatus != null">and cc.claim_status = #{claimStatus}</if>
              <if test="useStatus != null">and cc.use_status = #{useStatus}</if>
              <if test="keyword != null and keyword != ''">and (cc.claim_no like concat('%', #{keyword}, '%') or u.name like concat('%', #{keyword}, '%') or u.mobile like concat('%', #{keyword}, '%') or tc.card_no like concat('%', #{keyword}, '%'))</if>
              <if test="startTime != null">and cc.claimed_at &gt;= #{startTime}</if>
              <if test="endTime != null">and cc.claimed_at &lt; #{endTime}</if>
            </script>
            """)
    Long countClaimPage(@Param("couponId") Long couponId,
                        @Param("merchantId") Long merchantId,
                        @Param("batchNo") String batchNo,
                        @Param("claimStatus") Integer claimStatus,
                        @Param("useStatus") Integer useStatus,
                        @Param("keyword") String keyword,
                        @Param("startTime") LocalDateTime startTime,
                        @Param("endTime") LocalDateTime endTime);
}