TdCCouponPersonSMapper.xml
10 KB
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
<?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.zteits.pay.mapper.smapper.TdCCouponPersonSMapper">
<resultMap id="BaseResultMap" type="com.zteits.pay.domain.TdCCouponPerson">
<id column="id" jdbcType="BIGINT" property="id" />
<result column="card_no" jdbcType="VARCHAR" property="cardNo" />
<result column="cust_id" jdbcType="VARCHAR" property="custId" />
<result column="begin_time" jdbcType="TIMESTAMP" property="beginTime" />
<result column="end_time" jdbcType="TIMESTAMP" property="endTime" />
<result column="is_uesed" jdbcType="INTEGER" property="isUesed" />
<result column="used_time" jdbcType="TIMESTAMP" property="usedTime" />
<result column="order_id" jdbcType="VARCHAR" property="orderId" />
<result column="pay_order_id" jdbcType="VARCHAR" property="payOrderId" />
<result column="data_state" jdbcType="INTEGER" property="dataState" />
<result column="create_empid" jdbcType="VARCHAR" property="createEmpid" />
<result column="create_date" jdbcType="TIMESTAMP" property="createDate" />
<result column="modfiy_empid" jdbcType="VARCHAR" property="modfiyEmpid" />
<result column="modfiy_date" jdbcType="TIMESTAMP" property="modfiyDate" />
<result column="org_id" jdbcType="BIGINT" property="orgId" />
<result column="org_name" jdbcType="VARCHAR" property="orgName" />
</resultMap>
<sql id="Base_Column_List">
id, card_no, cust_id, begin_time, end_time, is_uesed, used_time, order_id, pay_order_id,
data_state, create_empid, create_date, modfiy_empid, modfiy_date, org_id, org_name
</sql>
<!-- 查询车主卡券信息 -->
<select id="getCouponPersonState" parameterType="com.zteits.clouds.api.dto.pay.param.TdCCouponPersonRequest"
resultType="com.zteits.pay.domain.TdCCouponPersonDO">
select
tp.id as id,
tp.cust_id as custId,
tp.car_num as carNum,
tp.data_state as dataState,
tr.card_no as cardNo,
tr.card_name as cardName,
tr.card_res as cardRes,
tr.card_type as cardType,
tr.coupons_type as couponsType,
tr.use_rule as useRule,
tr.disc_value as discValue,
tr.full_cut_value as fullCutValue,
tr.need_integral as needIntegral,
tr.is_superp_use as isSuperpUse,
tr.card_content as cardContent,
tr.card_state as cardState,
case when tp.is_uesed = 0 and date(#{queryDate}) > date(tp.end_time) then 1 else tp.is_uesed end as isUesed,
tp.used_time as usedTime,
tp.create_date as createDate,
tp.begin_time as beginTime,
tp.end_time as endTime,
tr.org_id as orgId
from
td_c_coupon_rule tr, td_c_coupon_person tp
where tp.cust_id = #{custId}
and tr.card_no = tp.card_no
<if test="dataState != null">
and tp.data_state = #{dataState}
</if>
<if test="orgId != null">
and tp.org_id = #{orgId}
</if>
<if test="isUesed != null and isUesed == 1">
and (tp.is_uesed = #{isUesed} or (tp.is_uesed = 0 and date(#{queryDate}) > date(tp.end_time) ))
</if>
<if test="isUesed != null and isUesed == 0">
and tp.is_uesed = #{isUesed} and date(tp.end_time) >= date(#{queryDate})
</if>
<if test="isUesed != null and isUesed == 2">
and ((tp.is_uesed = 1 or (tp.is_uesed = 0 and date(#{queryDate}) > date(tp.end_time) ))
or (tp.is_uesed = 0 and date(tp.end_time) >= date(#{queryDate})))
</if>
<if test="cardNos != null and cardNos.size > 0">
and date(tp.create_date) = date(#{queryDate}) and tp.card_no in
<foreach collection="cardNos" open="(" close=")" item="cardNo" separator=",">
#{cardNo}
</foreach>
</if>
<if test="cardTypes != null and cardTypes.size > 0 ">
and tr.card_type in
<foreach collection="cardTypes" item="cardType" open="(" close=")" separator=",">
#{cardType}
</foreach>
</if>
<if test="receiveChannelsList != null and receiveChannelsList.size > 0 ">
and tr.receive_channels in
<foreach collection="receiveChannelsList" item="receiveChannels" open="(" close=")" separator=",">
#{receiveChannels}
</foreach>
</if>
<if test="day != null">
and #{day} >= datediff(#{queryDate},tp.end_time)
</if>
order by tp.is_uesed ASC,tp.end_time desc
</select>
<!-- 查询车主卡券信息 -->
<select id="getCouponPersonStateForShare" parameterType="com.zteits.clouds.api.dto.pay.param.TdCCouponPersonRequest"
resultType="com.zteits.pay.domain.TdCCouponPersonDO">
select
tp.id as id,
tp.cust_id as custId,
tp.car_num as carNum,
tp.data_state as dataState,
tr.card_no as cardNo,
tr.card_name as cardName,
tr.card_res as cardRes,
tr.card_type as cardType,
tr.coupons_type as couponsType,
tr.use_rule as useRule,
tr.disc_value as discValue,
tr.full_cut_value as fullCutValue,
tr.need_integral as needIntegral,
tr.is_superp_use as isSuperpUse,
tr.card_content as cardContent,
tr.card_state as cardState,
tp.is_uesed as isUesed,
tp.used_time as usedTime,
tp.create_date as createDate,
tp.begin_time as beginTime,
tp.end_time as endTime,
tr.org_id as orgId
from
td_c_coupon_rule tr, td_c_coupon_person tp
where tp.cust_id = #{custId}
and tr.card_no = tp.card_no
<if test="dataState != null">
and tp.data_state = #{dataState}
</if>
<if test="orgId != null">
and tp.org_id = #{orgId}
</if>
<if test="isUesed != null and isUesed == 1">
and (tp.is_uesed = #{isUesed} or (tp.is_uesed = 0 and date(#{queryDate}) > date(tp.end_time) ))
</if>
<if test="isUesed != null and isUesed == 0">
and tp.is_uesed = #{isUesed} and date(tp.end_time) >= date(#{queryDate})
</if>
<if test="isUesed != null and isUesed == 2">
and ((tp.is_uesed = 1 or (tp.is_uesed = 0 and date(#{queryDate}) > date(tp.end_time) ))
or (tp.is_uesed = 0 and date(tp.end_time) >= date(#{queryDate})))
</if>
<if test="cardNos != null and cardNos.size > 0">
and date(tp.create_date) = date(#{queryDate}) and tp.card_no in
<foreach collection="cardNos" open="(" close=")" item="cardNo" separator=",">
#{cardNo}
</foreach>
</if>
<if test="cardTypes != null and cardTypes.size > 0 ">
and tr.card_type in
<foreach collection="cardTypes" item="cardType" open="(" close=")" separator=",">
#{cardType}
</foreach>
</if>
<if test="receiveChannelsList != null and receiveChannelsList.size > 0 ">
and tr.receive_channels in
<foreach collection="receiveChannelsList" item="receiveChannels" open="(" close=")" separator=",">
#{receiveChannels}
</foreach>
</if>
<if test="day != null">
and #{day} >= datediff(#{queryDate},tp.end_time)
</if>
<if test="owener != null">
and tp.owener = #{owener}
</if>
<if test="hideOwener != null">
and IFNULL(tp.owener, 0) != #{hideOwener}
</if>
order by tp.is_uesed ASC,tp.end_time desc
</select>
<!-- 查询车主卡券数量 -->
<select id="getCouponPersonNum" parameterType="com.zteits.clouds.api.dto.pay.param.TdCCouponPersonRequest"
resultType="java.lang.Integer">
select
count(tr.id)
from
td_c_coupon_rule tr,td_c_coupon_person tp
where tr.card_no = tp.card_no
and tp.is_uesed = 0
and date(tp.end_time) >= date(#{queryDate})
and tp.cust_id = #{custId}
and tp.data_state = 1
</select>
<!-- 车主平台查询车主卡券数量(全部、可用) -->
<select id="getPersonCouponNum" parameterType="com.zteits.clouds.api.dto.owner.param.OwnerRequest"
resultType="com.zteits.clouds.api.dto.owner.dto.OwnerBaseDTO">
select
count(id) as totalCouponNum,
SUM(CASE WHEN (date(end_time) > SYSDATE() AND is_uesed = 0) THEN 1 ELSE 0 END) AS validCouponNum
from
td_c_coupon_person
where data_state = 1
and cust_id = #{custId}
</select>
<select id="getCouponsPage" parameterType="com.zteits.clouds.api.dto.order.coupon.CouponPageRequest"
resultType="com.zteits.clouds.api.dto.order.coupon.CouponPageVO">
SELECT
c.id AS couponId,
r.card_name AS cardName,
r.disc_value AS couponValue,
IFNULL(c.order_discount_fee, 0) AS orderDiscountFee ,
p.user_phone AS userPhone,
IFNULL(c.car_num, '') AS carNum,
c.begin_time AS beginTime,
c.end_time AS endTime,
c.is_uesed AS isUsed,
c.used_time AS usedTime,
IFNULL(c.owener_name, '') AS owenerName
FROM
td_c_coupon_person c,
td_c_coupon_rule r,
td_c_cust_person p
WHERE
c.card_no = r.card_no
AND c.cust_id = p.cust_id
<if test="ruleNo != null and ruleNo != ''">
AND c.card_no = #{ruleNo}
</if>
<if test="userPhone != null and userPhone != ''">
AND p.user_phone = #{userPhone}
</if>
ORDER BY c.id
</select>
<select id="getCouponsStatistics" parameterType="com.zteits.clouds.api.dto.order.coupon.CouponPageRequest"
resultType="com.zteits.clouds.api.dto.order.coupon.CouponStatisticsVO">
SELECT
COUNT( * ) AS total,
IFNULL(SUM( c.order_discount_fee ), 0 ) AS totalDiscount,
IFNULL(SUM( c.is_uesed ), 0 ) AS totalUsed
FROM
td_c_coupon_person c,
td_c_cust_person p
WHERE
c.cust_id = p.cust_id
<if test="ruleNo != null and ruleNo != ''">
AND c.card_no = #{ruleNo}
</if>
<if test="userPhone != null and userPhone != ''">
AND p.user_phone = #{userPhone}
</if>
</select>
</mapper>