陶杰
2024-09-03 74916b92e0a94053e206cd559622a671427f7d2b
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
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.mzl.flower.mapper.coupon.CouponRecordMapperCustom">
 
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.mzl.flower.entity.coupon.CouponRecordDO">
        <id column="id" property="id" />
        <result column="deleted" property="deleted" />
        <result column="create_by" property="createBy" />
        <result column="update_by" property="updateBy" />
        <result column="create_time" property="createTime" />
        <result column="update_time" property="updateTime" />
        <result column="coupon_id" property="couponId" />
        <result column="user_id" property="userId" />
        <result column="customer_id" property="customerId" />
        <result column="status" property="status" />
        <result column="effective_start" property="effectiveStart" />
        <result column="effective_end" property="effectiveEnd" />
        <result column="order_id" property="orderId" />
        <result column="used_time" property="usedTime" />
        <result column="coupon_discount_value" property="couponDiscountValue" />
        <result column="min_order_amount" property="minOrderAmount" />
        <result column="category" property="category" />
        <result column="coupon_code" property="couponCode" />
        <result column="coupon_name" property="couponName" />
        <result column="get_type" property="getType" />
        <result column="coupon_discount_type" property="couponDiscountType" />
        <result column="get_user_type" property="getUserType" />
 
        <result column="point" property="point" />
        <result column="order_no" property="orderNo" />
 
    </resultMap>
    <update id="checkCouponExpired">
        update t_coupon_record  set `status`='expired' where `status`='unused' and effective_end &lt; NOW()
        <if test="param.userId != null and param.userId != ''">
            AND user_id = #{param.userId}
        </if>
        <if test="param.customerId != null and param.customerId != ''">
            AND customer_id =  #{param.customerId}
        </if>
    </update>
 
    <select id="statisCouponTemplateCount" resultType="java.lang.Integer">
        select IFNULL(count(1),0) as cnt from t_coupon_record where deleted=false and category=#{param.category}
    </select>
    <select id="statisCouponTemplateCurMonCount" resultType="java.lang.Integer">
        select IFNULL(count(1),0) as cnt from t_coupon_record where deleted=false and category=#{param.category}  AND DATE_FORMAT(create_time, '%Y-%m') = DATE_FORMAT(CURDATE(), '%Y-%m')
    </select>
    <select id="statisCouponPointCurMonPointAmonut" resultType="java.lang.Integer">
        select IFNULL(sum(point),0) as cnt from t_coupon_record where deleted=false and category='point'  AND DATE_FORMAT(create_time, '%Y-%m') = DATE_FORMAT(CURDATE(), '%Y-%m')
    </select>
 
    <select id="getPage" resultType="com.mzl.flower.dto.response.coupon.CouponRecordVO">
        <include refid="QuerySql"/>
    </select>
    <select id="getList" resultType="com.mzl.flower.dto.response.coupon.CouponRecordVO">
        <include refid="QuerySql"/>
    </select>
    <select id="getMineCouponRecordList" resultType="com.mzl.flower.dto.response.coupon.CouponRecordVO">
        select *
        from t_coupon_record t
        where t.deleted=false
        <if test="param.userId != null and param.userId != ''">
            AND t.user_id = #{param.userId}
        </if>
        <if test="param.customerId != null and param.customerId != ''">
            AND t.customer_id =  #{param.customerId}
        </if>
        <if test="param.status != null and param.status != ''">
            AND t.status =  #{param.status}
        </if>
    </select>
 
    <sql id="QuerySql">
        select *
        from (
        select r.*,
        i.name as customerName,
        u.tel,
        o.order_no
        from t_coupon_record r
        left join t_customer_info i
        on r.customer_id=i.id
        left join t_user u
        on i.user_id=u.id
        left join t_order o
        on r.order_id=o.id
        ) t
        where t.deleted=0
        <if test="param.name != null and param.name != ''">
            AND t.coupon_name like concat('%', #{param.name},'%')
        </if>
        <if test="param.couponDiscountType != null and param.couponDiscountType != ''">
            AND t.coupon_discount_type =  #{param.couponDiscountType}
        </if>
        <if test="param.getType != null and param.getType != ''">
            AND t.get_type =  #{param.getType}
        </if>
        <if test="param.getUserType != null and param.getUserType != ''">
            AND t.get_user_type =  #{param.getUserType}
        </if>
        <if test="param.id != null and param.id != ''">
            AND t.id =  #{param.id}
        </if>
        <if test="param.orderNo != null and param.orderNo != ''">
            AND t.order_no like  concat('%', #{param.orderNo},'%')
        </if>
        <if test="param.tel != null and param.tel != ''">
            AND t.tel like  concat('%', #{param.tel},'%')
        </if>
        <if test="param.status != null and param.status != ''">
            AND t.status =  #{param.status}
        </if>
        <if test="param.keyword != null and param.keyword != ''">
            AND (t.customerName like  concat('%', #{param.keyword},'%')
                     or t.user_id like  concat('%', #{param.keyword},'%') )
        </if>
        order by t.create_time desc
    </sql>
 
 
 
</mapper>