CouponBindUserDao.xml
24.3 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
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
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
<?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.diligrp.etrade.coupon.dao.CouponBindUserDao">
<resultMap id="BaseResultMap" type="com.diligrp.etrade.coupon.model.CouponBindUserDo">
<id column="id" property="id"/>
<result column="coupon_no" property="couponNo"/>
<result column="template_no" property="templateNo"/>
<result column="state" property="state"/>
<result column="apply_start_time" property="applyStartTime"/>
<result column="apply_end_time" property="applyEndTime"/>
<result column="actual_amount" property="actualAmount"/>
<result column="customer_id" property="customerId"/>
<result column="customer_code" property="customerCode"/>
<result column="customer_name" property="customerName"/>
<result column="customer_certificate_type" property="customerCertificateType"/>
<result column="customer_certificate_no" property="customerCertificateNo"/>
<result column="customer_phone" property="customerPhone"/>
<result column="use_time" property="useTime"/>
<result column="creater_id" property="createrId"/>
<result column="creater_code" property="createrCode"/>
<result column="creater_name" property="createrName"/>
<result column="created_time" property="createdTime"/>
<result column="version" property="version"/>
<result column="market_id" property="marketId"/>
</resultMap>
<sql id="Base_Column_List">
id, coupon_no, template_no, `state`, apply_start_time, apply_end_time, actual_amount,
customer_id, customer_code, customer_name, customer_certificate_type, customer_certificate_no,
customer_phone, use_time, creater_id, creater_code, creater_name, created_time, version,
market_id
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from coupon_bind_user
where id = #{id}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
delete
from coupon_bind_user
where id = #{id}
</delete>
<insert id="insert" keyColumn="id" keyProperty="id"
parameterType="com.diligrp.etrade.coupon.model.CouponBindUserDo">
insert into coupon_bind_user (coupon_no, template_no, `state`, apply_start_time, apply_end_time,
actual_amount, customer_id, customer_code,
customer_name, customer_certificate_type,
customer_certificate_no, customer_phone, use_time,
creater_id, creater_code, creater_name,
created_time, version, market_id,active)
values (#{couponNo}, #{templateNo}, #{state},
#{applyStartTime}, #{applyEndTime},
#{actualAmount}, #{customerId}, #{customerCode},
#{customerName}, #{customerCertificateType},
#{customerCertificateNo}, #{customerPhone}, #{useTime},
#{createrId}, #{createrCode}, #{createrName},
#{createdTime}, #{version}, #{marketId},1)
</insert>
<insert id="insertSelective" keyColumn="id" keyProperty="id"
parameterType="com.diligrp.etrade.coupon.model.CouponBindUserDo">
insert into coupon_bind_user
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="couponNo != null">
coupon_no,
</if>
<if test="templateNo != null">
template_no,
</if>
<if test="state != null">
`state`,
</if>
<if test="applyStartTime != null">
apply_start_time,
</if>
<if test="applyEndTime != null">
apply_end_time,
</if>
<if test="actualAmount != null">
actual_amount,
</if>
<if test="customerId != null">
customer_id,
</if>
<if test="customerCode != null">
customer_code,
</if>
<if test="customerName != null">
customer_name,
</if>
<if test="customerCertificateType != null">
customer_certificate_type,
</if>
<if test="customerCertificateNo != null">
customer_certificate_no,
</if>
<if test="customerPhone != null">
customer_phone,
</if>
<if test="useTime != null">
use_time,
</if>
<if test="createrId != null">
creater_id,
</if>
<if test="createrCode != null">
creater_code,
</if>
<if test="createrName != null">
creater_name,
</if>
<if test="createdTime != null">
created_time,
</if>
<if test="version != null">
version,
</if>
<if test="marketId != null">
market_id,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="couponNo != null">
#{couponNo},
</if>
<if test="templateNo != null">
#{templateNo},
</if>
<if test="state != null">
#{state},
</if>
<if test="effectiveStartTime != null">
#{applyStartTime},
</if>
<if test="effectiveEndTime != null">
#{applyEndTime},
</if>
<if test="actualAmount != null">
#{actualAmount},
</if>
<if test="customerId != null">
#{customerId},
</if>
<if test="customerCode != null">
#{customerCode},
</if>
<if test="customerName != null">
#{customerName,jdbcType=VARCHAR},
</if>
<if test="customerCertificateType != null">
#{customerCertificateType},
</if>
<if test="customerCertificateNo != null">
#{customerCertificateNo},
</if>
<if test="customerPhone != null">
#{customerPhone},
</if>
<if test="useTime != null">
#{useTime},
</if>
<if test="createrId != null">
#{createrId},
</if>
<if test="createrCode != null">
#{createrCode},
</if>
<if test="createrName != null">
#{createrName},
</if>
<if test="createdTime != null">
#{createdTime},
</if>
<if test="version != null">
#{version},
</if>
<if test="marketId != null">
#{marketId},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.diligrp.etrade.coupon.model.CouponBindUserDo">
update coupon_bind_user
<set>
<if test="couponNo != null">
coupon_no = #{couponNo},
</if>
<if test="templateNo != null">
template_no = #{templateNo},
</if>
<if test="state != null">
`state` = #{state},
</if>
<if test="applyStartTime != null">
apply_start_time = #{applyStartTime},
</if>
<if test="applyEndTime != null">
apply_end_time = #{applyEndTime},
</if>
<if test="actualAmount != null">
actual_amount = #{actualAmount},
</if>
<if test="customerId != null">
customer_id = #{customerId},
</if>
<if test="customerCode != null">
customer_code = #{customerCode},
</if>
<if test="customerName != null">
customer_name = #{customerName},
</if>
<if test="customerCertificateType != null">
customer_certificate_type = #{customerCertificateType},
</if>
<if test="customerCertificateNo != null">
customer_certificate_no = #{customerCertificateNo},
</if>
<if test="customerPhone != null">
customer_phone = #{customerPhone},
</if>
<if test="useTime != null">
use_time = #{useTime},
</if>
<if test="createrId != null">
creater_id = #{createrId},
</if>
<if test="createrCode != null">
creater_code = #{createrCode},
</if>
<if test="createrName != null">
creater_name = #{createrName},
</if>
<if test="createdTime != null">
created_time = #{createdTime},
</if>
<if test="version != null">
version = #{version} +1,
</if>
<if test="marketId != null">
market_id = #{marketId},
</if>
</set>
where id = #{id} and version = #{version}
</update>
<update id="updateByPrimaryKey" parameterType="com.diligrp.etrade.coupon.model.CouponBindUserDo">
update coupon_bind_user
set coupon_no = #{couponNo},
template_no = #{templateNo},
`state` = #{state},
apply_start_time = #{applyStartTime},
apply_end_time = #{applyEndTime},
actual_amount = #{actualAmount},
customer_id = #{customerId},
customer_code = #{customerCode},
customer_name = #{customerName},
customer_certificate_type = #{customerCertificateType},
customer_certificate_no = #{customerCertificateNo},
customer_phone = #{customerPhone},
use_time = #{useTime},
creater_id = #{createrId},
creater_code = #{createrCode},
creater_name = #{createrName},
created_time = #{createdTime},
version = #{version} + 1,
market_id = #{marketId}
where id = #{id}
and version = #{version}
</update>
<select id="selectForTask" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from coupon_bind_user
where state in (0,1) AND active = 1
</select>
<update id="batchUpdateCoupon" parameterType="java.util.List">
<foreach collection="list" item="couponBindUserDo" separator=";">
UPDATE coupon_bind_user
SET state = #{couponBindUserDo.state}, version = #{couponBindUserDo.version}+1
WHERE id = #{couponBindUserDo.id} and version = #{couponBindUserDo.version}
</foreach>
</update>
<update id="batchUpdateCouponNo" parameterType="java.util.List">
<foreach collection="list" item="couponBindUserDo" separator=";">
UPDATE coupon_bind_user
SET coupon_no = #{couponBindUserDo.couponNo}, version = #{couponBindUserDo.version}+1
WHERE coupon_no = #{couponBindUserDo.oldCouponNo} and version = #{couponBindUserDo.version}
</foreach>
</update>
<select id="selectByTemplateNo" parameterType="java.lang.String" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from coupon_bind_user
WHERE template_no = #{templateNo} AND active = 1 ORDER BY id DESC
</select>
<select id="selectByTemplateNoWithOut" parameterType="java.lang.String" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from coupon_bind_user
WHERE template_no = #{templateNo} AND active = 0 ORDER BY id DESC
</select>
<insert id="insertBatch" parameterType="java.util.List">
insert into coupon_bind_user (
coupon_no, template_no, `state`,apply_start_time, apply_end_time,
actual_amount, customer_id, customer_code,
customer_name, customer_certificate_type,
customer_certificate_no, customer_phone, use_time,
creater_id, creater_code, creater_name,
created_time, version, market_id,active
)
values
<foreach collection="list" item="item" separator=",">
(#{item.couponNo}, #{item.templateNo}, #{item.state},
#{item.applyStartTime}, #{item.applyEndTime},
#{item.actualAmount}, #{item.customerId}, #{item.customerCode},
#{item.customerName}, #{item.customerCertificateType},
#{item.customerCertificateNo}, #{item.customerPhone}, #{item.useTime},
#{item.createrId}, #{item.createrCode}, #{item.createrName},
now(), 1, #{item.marketId},0
)
</foreach>
</insert>
<select id="page" parameterType="com.diligrp.etrade.coupon.domain.CouponQueryDto"
resultType="com.diligrp.etrade.coupon.model.CouponQueryDo">
SELECT
cbu.coupon_no as couponNo,
cbu.state as state,
cbu.created_time as createdTime,
CASE
WHEN cbu.`apply_end_time` = '9999-12-31 23:59:59' THEN
NULL ELSE cbu.`apply_end_time`
END AS applyEndTime,
cbu.use_time as useTime,
ct.discount_amount as discountAmount,
cud.actual_discount_amount as actualAmount,
cbu.customer_name as customerName,
cbu.customer_phone as customerPhone,
cud.phone as phone,
cud.seller_name as sellerName,
cud.transaction_code as transactionCode
FROM
coupon_bind_user cbu
LEFT JOIN coupon_use_detail cud ON cbu.coupon_no = cud.coupon_no
LEFT JOIN coupon_template ct ON cbu.template_no = ct.template_no
WHERE
1 = 1
AND cbu.active = 1
<if test="marketId != null">
<![CDATA[ AND cbu.market_id = #{marketId}]]>
</if>
<if test="templateNo != null and templateNo != ''">
AND ct.template_no = #{templateNo}
</if>
<if test="couponNo != null and couponNo != ''">
AND cbu.coupon_no LIKE concat('%',#{couponNo},'%')
</if>
<if test="state != null">
<![CDATA[ AND cbu.state = #{state}]]>
</if>
<if test="useTimeStart != null and useTimeStart != ''">
AND cbu.use_time >= #{useTimeStart}
</if>
<if test="useTimeEnd != null and useTimeEnd != ''">
AND cbu.use_time <= #{useTimeEnd}
</if>
order by cbu.coupon_no desc
</select>
<update id="updateByCustomerId" parameterType="com.diligrp.etrade.coupon.model.CouponBindUserDo">
UPDATE `coupon_bind_user`
SET `customer_name` = #{customerName},
`customer_certificate_type` = #{customerCertificateType},
`customer_certificate_no` = #{customerCertificateNo},
`customer_phone` = #{customerPhone},
`version` = #{version} + 1
WHERE
`customer_id` = #{customerId}
and `version` = #{version}
</update>
<select id="findCouponList" parameterType="com.diligrp.etrade.coupon.domain.CouponQueryDto" resultType="com.diligrp.etrade.coupon.model.CouponResponseDo">
SELECT
cbu.id,
cbu.coupon_no,
ct.type ,
ct.id as templateId ,
ct.template_no ,
ct.template_name ,
ct.discount_amount ,
cr.satisfied_amount ,
CASE
WHEN cbu.`apply_end_time` = '9999-12-31 23:59:59' THEN
NULL ELSE cbu.`apply_end_time` END AS applyEndTime,
cbu.market_id
FROM
coupon_bind_user cbu
JOIN coupon_template ct ON cbu.template_no = ct.template_no
JOIN coupon_ruler cr ON cr.template_no = ct.template_no
WHERE
1=1
AND cbu.active = 1
<if test="marketId != null">
<![CDATA[ AND cbu.market_id = #{marketId}]]>
</if>
AND cbu.customer_id = #{customerId}
<if test="state != null and state == 1">
AND cbu.apply_start_time <= now() AND cbu.apply_end_time >= NOW() AND ISNULL(actual_amount)
</if>
<if test="state != null and state == 2">
AND (cbu.apply_end_time < now() OR cbu.state = 3)
</if>
ORDER BY
ct.discount_amount DESC,cbu.apply_end_time ASC
</select>
<select id="findCoupon4OrderChange" parameterType="com.diligrp.etrade.coupon.domain.CouponQueryDto" resultType="com.diligrp.etrade.coupon.model.CouponResponseDo">
SELECT
cbu.id,
cbu.coupon_no,
ct.type ,
ct.discount_amount ,
cr.satisfied_amount ,
CASE
WHEN cbu.`apply_end_time` = '9999-12-31 23:59:59' THEN
NULL ELSE cbu.`apply_end_time` END AS applyEndTime,
cbu.market_id
FROM
coupon_bind_user cbu
JOIN coupon_template ct ON cbu.template_no = ct.template_no
JOIN coupon_ruler cr ON cr.template_no = ct.template_no
WHERE
1=1
AND cbu.active = 1
AND cbu.market_id = #{couponQueryDto.marketId}
AND cbu.customer_id = #{couponQueryDto.customerId}
<if test="couponQueryDto.state != null and couponQueryDto.state == 1">
AND cbu.apply_start_time <= now() AND cbu.apply_end_time >= NOW() AND ISNULL(actual_amount)
</if>
<if test="couponQueryDto.couponNos!=null and couponQueryDto.couponNos.size>0">
OR cbu.coupon_no IN
<foreach item="item" collection="couponQueryDto.couponNos" separator="," open="(" close=")" index="">
#{item}
</foreach>
</if>
ORDER BY
ct.discount_amount DESC,cbu.apply_end_time ASC
</select>
<select id="findCoupon4Order" parameterType="com.diligrp.etrade.coupon.domain.CouponBindUserDto" resultType="com.diligrp.etrade.coupon.model.CouponBindUserDo">
SELECT
cbu.id id,
cbu.coupon_no couponNo,
cbu.state state,
cbu.actual_amount actualAmount,
ct.type type,
ct.discount_amount discountAmount,
cr.satisfied_amount satisfiedAmount,
cbu.`apply_start_time` applyStartTime,
cbu.`apply_end_time` applyEndTime,
cbu.market_id marketId,
cbu.version version,
cbu.customer_id customerId
FROM
coupon_bind_user cbu
JOIN coupon_template ct ON cbu.template_no = ct.template_no
JOIN coupon_ruler cr ON cr.template_no = ct.template_no
WHERE
1=1
AND cbu.active = 1
<if test="couponBindUserDtoList !=null and couponBindUserDtoList.size>0">
AND cbu.coupon_no IN
<foreach item="item" collection="couponBindUserDtoList" separator="," open="(" close=")" index="">
#{item.couponNo}
</foreach>
</if>
ORDER BY
ct.discount_amount DESC,cbu.apply_end_time ASC
</select>
<select id="findCouponByNos" parameterType="com.diligrp.etrade.coupon.domain.CouponBindUserDto" resultType="com.diligrp.etrade.coupon.model.CouponBindUserDo">
SELECT
cbu.id id,
cbu.coupon_no couponNo,
cbu.template_no templateNo,
cbu.state state,
cbu.actual_amount actualAmount,
cbu.`apply_start_time` applyStartTime,
cbu.`apply_end_time` applyEndTime,
cbu.market_id marketId,
cbu.version version,
cbu.customer_id customerId
FROM
coupon_bind_user cbu
WHERE
1=1
AND cbu.active = 1
<if test="couponBindUserDtoList !=null and couponBindUserDtoList.size>0">
AND cbu.coupon_no IN
<foreach item="item" collection="couponBindUserDtoList" separator="," open="(" close=")" index="">
#{item.couponNo}
</foreach>
</if>
ORDER BY
cbu.apply_end_time ASC
</select>
<update id="batchUpdateCoupon4Order" parameterType="java.util.List">
<foreach collection="list" item="couponBindUserDo" separator=";">
UPDATE coupon_bind_user
SET state = #{couponBindUserDo.state},
use_time = #{couponBindUserDo.useTime},
actual_amount = #{couponBindUserDo.actualAmount},
version = #{couponBindUserDo.version}+1
WHERE coupon_no = #{couponBindUserDo.couponNo} and version = #{couponBindUserDo.version}
</foreach>
</update>
<update id="update" parameterType="com.diligrp.etrade.coupon.model.CouponBindUserDo">
UPDATE coupon_bind_user
SET state = #{couponBindUserDo.state},
use_time = #{couponBindUserDo.useTime},
actual_amount = #{couponBindUserDo.actualAmount},
version = #{couponBindUserDo.version}+1
WHERE coupon_no = #{couponBindUserDo.couponNo} and version = #{couponBindUserDo.version}
</update>
<update id="update4Bind" parameterType="com.diligrp.etrade.coupon.domain.CouponTemplateDto">
UPDATE `coupon_bind_user` u
JOIN (
SELECT MIN( id ) id,coupon_no FROM `coupon_bind_user`
WHERE template_no = #{templateNo}
GROUP BY customer_id
ORDER BY id ASC
<if test="extendCount != 0">
limit #{extendCount}
</if> ) s
ON u.coupon_no = s.coupon_no
SET u.active = 1
</update>
<delete id="del4Unbind" parameterType="com.diligrp.etrade.coupon.domain.CouponTemplateDto">
DELETE
FROM
coupon_bind_user
WHERE
template_no = #{templateNo}
AND active = 0
</delete>
<select id="selectCountByTemplateNo" parameterType="java.lang.String" resultType="com.diligrp.etrade.coupon.model.CouponBindUserQueryDo">
SELECT count(id) count,
IFNULL(CAST(RIGHT (MAX(coupon_no), 6) AS SIGNED), 0) AS maxCouponNo
FROM coupon_bind_user
WHERE template_no = #{templateNo}
AND active = 1
</select>
<select id="getCount" resultType="int">
SELECT
COUNT( id )
FROM
( SELECT id FROM coupon_bind_user WHERE template_no = #{templateNo} GROUP BY customer_id ) a
</select>
<select id="findCouponByNo" parameterType="com.diligrp.etrade.coupon.domain.CouponQueryDto" resultType="com.diligrp.etrade.coupon.model.CouponResponseDo">
SELECT cbu.id,
cbu.coupon_no,
ct.type,
ct.discount_amount,
cr.satisfied_amount,
CASE
WHEN cbu.`apply_end_time` = '9999-12-31 23:59:59' THEN
NULL
ELSE cbu.`apply_end_time` END AS applyEndTime,
cbu.market_id
FROM coupon_bind_user cbu
JOIN coupon_template ct ON cbu.template_no = ct.template_no
JOIN coupon_ruler cr ON cr.template_no = ct.template_no
WHERE 1 = 1
AND cbu.active = 1
AND cbu.coupon_no = #{couponNo}
</select>
<select id="findCouponsByNos" parameterType="com.diligrp.etrade.coupon.domain.CouponQueryDto" resultType="com.diligrp.etrade.coupon.model.CouponResponseDo">
SELECT cbu.id,
cbu.coupon_no,
ct.type,
ct.discount_amount,
cr.satisfied_amount,
CASE
WHEN cbu.`apply_end_time` = '9999-12-31 23:59:59' THEN
NULL
ELSE cbu.`apply_end_time` END AS applyEndTime,
cbu.market_id
FROM coupon_bind_user cbu
JOIN coupon_template ct ON cbu.template_no = ct.template_no
JOIN coupon_ruler cr ON cr.template_no = ct.template_no
WHERE 1 = 1
AND cbu.active = 1
<if test="couponNo != null and couponNo != ''">
AND cbu.coupon_no = #{couponNo}
</if>
<if test="couponNos !=null and couponNos.size>0">
AND cbu.coupon_no IN
<foreach item="item" collection="couponNos" separator="," open="(" close=")" index="">
#{item}
</foreach>
</if>
</select>
</mapper>