xuhy
2 天以前 9e9e116bcda20d4ac6dfa9313a097046da35bdff
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
<?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.stylefeng.guns.modular.system.dao.UserCouponRecordMapper">
 
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.stylefeng.guns.modular.system.model.UserCouponRecord">
        <id column="id" property="id"/>
        <result column="money" property="money"/>
        <result column="fullMoney" property="fullMoney"/>
        <result column="expirationTime" property="expirationTime"/>
        <result column="insertTime" property="insertTime"/>
        <result column="companyId" property="companyId"/>
        <result column="state" property="state"/>
        <result column="endTime" property="endTime"/>
        <result column="couponUseType" property="couponUseType"/>
        <result column="couponType" property="couponType"/>
        <result column="userId" property="userId"/>
        <result column="couponId" property="couponId"/>
        <result column="couponActivityId" property="couponActivityId"/>
        <result column="activityType" property="activityType"/>
        <result column="paymentRecordId" property="paymentRecordId"/>
    </resultMap>
 
 
 
    <select id="queryAvailable" resultType="int">
        select
        count(a.id)
        from t_user_coupon_record a
        left join t_company b on (a.companyId = b.id)
        where a.expirationTime >= now()
        <if test="null != uid">
            and a.userId = #{uid}
        </if>
        <if test="null != companyId">
            and a.companyId = #{companyId}
        </if>
        <if test="null != state">
            and a.state = #{state}
        </if>
        <if test="null != couponUseType">
            and a.couponUseType = #{couponUseType}
        </if>
    </select>
 
    <select id="queryCoupon" resultType="map">
        select
        a.id as id,
        a.money as money,
        a.couponUseType as userType,
        DATE_FORMAT(a.expirationTime, '%Y-%m-%d') as time,
        a.couponType as `type`,
        a.fullMoney as fullMoney,
        a.state as state,
        b.`name` as `name`,
        c.citys
        from t_user_coupon_record a
        left join t_company b on (a.companyId = b.id)
        left join t_sys_coupon_record c on (a.couponId = c.id)
        where a.expirationTime >= now()
        <if test="null != uid">
            and a.userId = #{uid}
        </if>
        <if test="null != companyId">
            and a.companyId = #{companyId}
        </if>
        <if test="null != state">
            and a.state = #{state}
        </if>
        <if test="null != couponUseType">
            and a.couponUseType = #{couponUseType}
        </if>
        order by a.insertTime desc
    </select>
    
    
    
    
    <select id="queryCoupon1" resultType="map">
        select
        a.id as id,
        a.money as money,
        a.couponUseType as userType,
        DATE_FORMAT(a.expirationTime, '%Y-%m-%d') as time,
        a.couponType as `type`,
        a.fullMoney as fullMoney,
        a.state as state,
        b.`name` as `name`,
        c.citys
        from t_user_coupon_record a
        left join t_company b on (a.companyId = b.id)
        left join t_sys_coupon_record c on (a.couponId = c.id)
        where a.expirationTime >= now()
        <if test="null != uid">
            and a.userId = #{uid}
        </if>
        <if test="null != cityCode and '' != cityCode">
            and JSON_OVERLAPS(c.citys, #{cityCode})
        </if>
        <if test="null != state">
            and a.state = #{state}
        </if>
        <if test="null != couponUseType">
            and a.couponUseType = #{couponUseType}
        </if>
        <if test="null != money">
            and if(a.couponType = 1, a.money &lt;= #{money}, a.fullMoney &lt;= #{money})
        </if>
        order by a.insertTime desc
        <if test="null != pageNum and null != size">
            limit #{pageNum}, #{size}
        </if>
    </select>
 
 
 
    <select id="queryMyCoupons" resultType="map">
        select
        a.id as id,
        a.money as money,
        a.couponUseType as userType,
        DATE_FORMAT(a.expirationTime, '%Y-%m-%d') as time,
        a.couponType as `type`,
        a.fullMoney as fullMoney,
        a.state as state,
        b.`name` as `name`,
        c.citys
        from t_user_coupon_record a
        left join t_company b on (a.companyId = b.id)
        left join t_sys_coupon_record c on (a.couponId = c.id)
        where 1 = 1
        <if test="null != uid">
            and a.userId = #{uid}
        </if>
        <if test="null != state">
            <if test="state == 1">
                and a.state = 1
            </if>
            <if test="state == 2">
                and a.state in (2,3)
            </if>
        </if>
        order by a.insertTime desc
        <if test="null != pageNum and null != size">
            limit #{pageNum}, #{size}
        </if>
    </select>
    <select id="queryAvailable_" resultType="map">
        select
        a.id as id,
        a.money as money,
        a.couponUseType as userType,
        DATE_FORMAT(a.expirationTime, '%Y-%m-%d') as time,
        a.couponType as `type`,
        a.fullMoney as fullMoney,
        a.state as state,
        b.`name` as `name`
        from t_user_coupon_record a
        left join t_company b on (a.companyId = b.id)
        where a.expirationTime >= now()
        <if test="null != uid">
            and a.userId = #{uid}
        </if>
        <if test="null != companyId">
            and a.companyId = #{companyId}
        </if>
        <if test="null != state">
            and a.state = #{state}
        </if>
        <if test="null != couponUseType">
            and a.couponUseType = #{couponUseType}
        </if>
        order by a.insertTime desc
    </select>
 
 
    <update id="updateTimeOut">
        update t_user_coupon_record set state = 3,endTime = now() where now() > expirationTime and state = 1
    </update>
 
 
    <select id="queryCouponCrossCity" resultType="map">
        select
        a.id as id,
        a.money as money,
        a.couponUseType as userType,
        DATE_FORMAT(a.expirationTime, '%Y-%m-%d') as time,
        a.couponType as `type`,
        a.fullMoney as fullMoney,
        a.state as state,
        b.`name` as `name`
        from t_user_coupon_record a
        left join t_company b on (a.companyId = b.id)
        <where>
            <if test="ids != null and ids.size()>0">
                and a.id in
                <foreach collection="ids" item="id" index="index" open="(" close=")" separator=",">
                    #{id}
                </foreach>
            </if>
        </where>
        order by a.insertTime desc
        <if test="null != pageNum and null != size">
            limit #{pageNum}, #{size}
        </if>
    </select>
</mapper>