CouponMapper.xml
28.0 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
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
<?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.sibu.orderHelper.integral.web.dao.IMCouponDao">
<resultMap id="couponDirectResponse" type="com.sibu.orderHelper.integral.reponse.CouponDirectResponse">
<id property="id" column="id" javaType="java.lang.Long" jdbcType="BIGINT"/>
<result property="couponName" column="coupon_name" javaType="java.lang.String" jdbcType="VARCHAR"/>
<result property="productId" column="product_id" javaType="java.lang.String" jdbcType="VARCHAR"/>
<result property="rangeName" column="range_name" javaType="java.lang.String" jdbcType="VARCHAR"/>
<result property="productRange" column="product_range" javaType="java.lang.Short" jdbcType="TINYINT"/>
<result property="couponMoney" column="coupon_money" javaType="java.math.BigDecimal" jdbcType="DECIMAL"/>
<result property="couponNum" column="coupon_num" javaType="java.lang.Integer" jdbcType="INTEGER"/>
<result property="directCutInstruction" column="direct_cut_instruction" javaType="java.lang.String" jdbcType="VARCHAR"/>
<result property="couponType" column="coupon_type" javaType="java.lang.Short" jdbcType="TINYINT"/>
<result property="receiveStartDate" column="receive_start_date" javaType="java.util.Date" jdbcType="TIMESTAMP"/>
<result property="receiveEndDate" column="receive_end_date" javaType="java.util.Date" jdbcType="TIMESTAMP"/>
<result property="useStartDate" column="use_start_date" javaType="java.util.Date" jdbcType="TIMESTAMP"/>
<result property="useEndDate" column="use_end_date" javaType="java.util.Date" jdbcType="TIMESTAMP"/>
<result property="status" column="status" javaType="java.lang.Short" jdbcType="TINYINT"/>
<result property="getSource" column="get_source" javaType="java.lang.Short" jdbcType="TINYINT"/>
<result property="supplierId" column="supplier_id" javaType="java.lang.String" jdbcType="VARCHAR"/>
<result property="supplierName" column="supplier_name" javaType="java.lang.String" jdbcType="VARCHAR"/>
<result property="platformType" column="platform_type" javaType="java.lang.Integer" jdbcType="INTEGER"/>
<result property="receiveNum" column="receive_num" javaType="java.lang.Integer" jdbcType="INTEGER"/>
</resultMap>
<resultMap id="couponFullCutResponse" type="com.sibu.orderHelper.integral.reponse.CouponFullCutResponse">
<id property="id" column="id" javaType="java.lang.Long" jdbcType="BIGINT"/>
<result property="couponName" column="coupon_name" javaType="java.lang.String" jdbcType="VARCHAR"/>
<result property="fullMoney" column="full_money" javaType="java.math.BigDecimal" jdbcType="DECIMAL"/>
<result property="cutMoney" column="cut_money" javaType="java.math.BigDecimal" jdbcType="DECIMAL"/>
<result property="couponNum" column="coupon_num" javaType="java.lang.Integer" jdbcType="INTEGER"/>
<result property="fullCutInstruction" column="full_cut_instruction" javaType="java.lang.String" jdbcType="VARCHAR"/>
<result property="receiveStartDate" column="receive_start_date" javaType="java.util.Date" jdbcType="TIMESTAMP"/>
<result property="receiveEndDate" column="receive_end_date" javaType="java.util.Date" jdbcType="TIMESTAMP"/>
<result property="useStartDate" column="use_start_date" javaType="java.util.Date" jdbcType="TIMESTAMP"/>
<result property="useEndDate" column="use_end_date" javaType="java.util.Date" jdbcType="TIMESTAMP"/>
<result property="status" column="status" javaType="java.lang.Short" jdbcType="TINYINT"/>
<result property="receiveNum" column="receive_num" javaType="java.lang.Integer" jdbcType="INTEGER"/>
<result property="getSource" column="get_source" javaType="java.lang.Short" jdbcType="TINYINT"/>
<result property="supplierId" column="supplier_id" javaType="java.lang.String" jdbcType="VARCHAR"/>
<result property="supplierName" column="supplier_name" javaType="java.lang.String" jdbcType="VARCHAR"/>
<result property="platformType" column="platform_type" javaType="java.lang.Integer" jdbcType="INTEGER"/>
</resultMap>
<resultMap id="couponFullCutLimitResponse" type="com.sibu.orderHelper.integral.reponse.CouponFullCutLimitResponse">
<id property="id" column="id" javaType="java.lang.Integer" jdbcType="BIGINT"/>
<result property="fullCutId" column="full_cut_id" javaType="java.lang.Integer" jdbcType="BIGINT"/>
<result property="fullCutRange" column="full_cut_range" javaType="java.lang.Short" jdbcType="TINYINT"/>
<result property="fullCutRangeId" column="full_cut_range_id" javaType="java.lang.String" jdbcType="VARCHAR"/>
<result property="rangeName" column="range_name" javaType="java.lang.String" jdbcType="VARCHAR"/>
</resultMap>
<resultMap id="couponFullCutLimitCountResponse" type="com.sibu.orderHelper.integral.reponse.CouponFullCutLimitCountResponse">
<result property="fullCutRange" column="full_cut_range" javaType="java.lang.Short" jdbcType="TINYINT"/>
<result property="countLimit" column="count_limit" javaType="java.lang.Integer" jdbcType="BIGINT"/>
</resultMap>
<resultMap id="couponUserResponse" type="com.sibu.orderHelper.integral.reponse.CouponUserResponse">
<id property="id" column="id" javaType="java.lang.Long" jdbcType="BIGINT"/>
<result property="memberId" column="member_id" javaType="java.lang.String" jdbcType="VARCHAR"/>
<result property="couponName" column="coupon_name" javaType="java.lang.String" jdbcType="VARCHAR"/>
<result property="couponType" column="coupon_type" javaType="java.lang.Short" jdbcType="TINYINT"/>
<result property="useDate" column="use_dt" javaType="java.util.Date" jdbcType="TIMESTAMP"/>
<result property="useorderCode" column="use_order_code" javaType="java.lang.String" jdbcType="VARCHAR"/>
<result property="getSource" column="get_source" javaType="java.lang.Short" jdbcType="TINYINT"/>
<result property="createDt" column="create_dt" javaType="java.util.Date" jdbcType="TIMESTAMP"/>
<result property="couponCode" column="coupon_code" javaType="java.lang.String" jdbcType="VARCHAR"/>
<result property="supplierId" column="supplier_id" javaType="java.lang.String" jdbcType="VARCHAR"/>
<result property="supplierName" column="supplier_name" javaType="java.lang.String" jdbcType="VARCHAR"/>
</resultMap>
<resultMap id="supplierCouponResponse" type="com.sibu.orderHelper.integral.reponse.SupplierCouponResponse">
<id property="id" column="id" javaType="java.lang.Integer" jdbcType="INTEGER"/>
<result property="couponName" column="coupon_name" javaType="java.lang.String" jdbcType="VARCHAR"/>
<result property="couponNum" column="coupon_num" javaType="java.lang.Integer" jdbcType="INTEGER"/>
<result property="receiveNum" column="receive_num" javaType="java.lang.Integer" jdbcType="INTEGER"/>
<result property="supplierId" column="supplier_id" javaType="java.lang.String" jdbcType="VARCHAR"/>
<result property="supplierName" column="supplier_name" javaType="java.lang.String" jdbcType="VARCHAR"/>
<result property="couponType" column="coupon_type" javaType="java.lang.Integer" jdbcType="INTEGER"/>
</resultMap>
<resultMap id="supplier" type="com.sibu.orderHelper.integral.reponse.SupplierCouponResponse">
<id property="supplierId" column="supplier_id" javaType="java.lang.String" jdbcType="VARCHAR"/>
<result property="couponName" column="coupon_name" javaType="java.lang.String" jdbcType="VARCHAR"/>
<result property="couponNum" column="coupon_num" javaType="java.lang.Integer" jdbcType="INTEGER"/>
<result property="receiveNum" column="receive_num" javaType="java.lang.Integer" jdbcType="INTEGER"/>
<result property="payNum" column="pay_num" javaType="java.lang.Integer" jdbcType="INTEGER"/>
<result property="notPayNum" column="notPay_num" javaType="java.lang.Integer" jdbcType="INTEGER"/>
<result property="supplierName" column="supplier_name" javaType="java.lang.String" jdbcType="VARCHAR"/>
<result property="conversionRate" column="conversion_rate" javaType="java.math.BigDecimal" jdbcType="DECIMAL"/>
</resultMap>
<resultMap id="couponDetail" type="com.sibu.orderHelper.integral.reponse.SupplierCouponDetailResponse">
<id property="id" column="id" javaType="java.lang.String" jdbcType="VARCHAR"/>
<result property="couponId" column="coupon_id" javaType="java.lang.Integer" jdbcType="INTEGER"/>
<result property="couponName" column="coupon_name" javaType="java.lang.String" jdbcType="VARCHAR"/>
<result property="couponNum" column="coupon_num" javaType="java.lang.Integer" jdbcType="INTEGER"/>
<result property="receiveNum" column="receive_num" javaType="java.lang.Integer" jdbcType="INTEGER"/>
<result property="payNum" column="pay_num" javaType="java.lang.Integer" jdbcType="INTEGER"/>
<result property="notPayNum" column="notPay_num" javaType="java.lang.Integer" jdbcType="INTEGER"/>
<result property="supplierName" column="supplier_name" javaType="java.lang.String" jdbcType="VARCHAR"/>
<result property="conversionRate" column="conversion_rate" javaType="java.math.BigDecimal" jdbcType="DECIMAL"/>
<result property="supplierId" column="supplier_id" javaType="java.lang.String" jdbcType="VARCHAR"/>
</resultMap>
<!-- 保存对象-->
<insert id="addDirectCoupon" parameterType="com.sibu.orderHelper.integral.request.CouponDirectRequest">
INSERT INTO coupon_direct_cut (
product_id,range_name,product_range,coupon_money,coupon_num,direct_cut_instruction,coupon_name,coupon_type,receive_start_date,receive_end_date
,use_start_date,use_end_date,status,get_source,supplier_id,supplier_name,platform_type
) VALUES (
#{productId},#{rangeName},#{productRange},#{couponMoney},#{couponNum},#{directCutInstruction},#{couponName},#{couponType},#{receiveStartDate},#{receiveEndDate}
,#{useStartDate},#{useEndDate},#{status},#{getSource},#{supplierId},#{supplierName},#{platformType}
)
</insert>
<insert id="addFullCutCoupon" parameterType="com.sibu.orderHelper.integral.request.CouponFullCutRequest">
INSERT INTO coupon_full_cut (
full_money,cut_money,coupon_num,full_cut_instruction,coupon_name,receive_start_date,receive_end_date,use_start_date,use_end_date,status,get_source,supplier_id,supplier_name,platform_type
) VALUES (
#{fullMoney},#{cutMoney},#{couponNum},#{fullCutInstruction},#{couponName},#{receiveStartDate},#{receiveEndDate}
,#{useStartDate},#{useEndDate},#{status},#{getSource},#{supplierId},#{supplierName},#{platformType}
)
</insert>
<insert id="addFullCutLimitCoupon" parameterType="com.sibu.orderHelper.integral.request.CouponFullCutLimitRequest">
INSERT INTO coupon_full_cut_range (
full_cut_id,range_name,full_cut_range,full_cut_range_id
) VALUES (
#{fullCutId},#{rangeName},#{fullCutRange},#{fullCutRangeId}
)
</insert>
<!--查询列表-->
<sql id="couponDirectSql">
id,product_id,range_name,product_range,coupon_money,coupon_num,direct_cut_instruction,coupon_name,coupon_type,receive_start_date,receive_end_date
,use_start_date,use_end_date,status,receive_num,get_source,supplier_id,supplier_name,platform_type
</sql>
<select id="pagerCouponDirect" parameterType="com.sibu.orderHelper.integral.request.CouponDirectPageRequest" resultMap="couponDirectResponse">
select <include refid="couponDirectSql"/>
from coupon_direct_cut
where 1=1
<if test="couponName != ''">
and coupon_name like concat('%',#{couponName},'%')
</if>
<if test="rangeName != ''">
and range_name like concat('%',#{rangeName},'%')
</if>
<if test="status != null">
and status = #{status}
</if>
<if test="productRange != null">
and product_range = #{productRange}
</if>
<if test="supplierId != null and supplierId !=''">
and supplier_id = #{supplierId}
</if>
order by id desc
LIMIT
${pageNow}, ${pageSize}
</select>
<select id="totalCouponDirect" parameterType="com.sibu.orderHelper.integral.request.CouponDirectPageRequest" resultType="int">
select count(*)
from coupon_direct_cut
where 1=1
<if test="couponName != ''">
and coupon_name like concat('%',#{couponName},'%')
</if>
<if test="rangeName != ''">
and range_name like concat('%',#{rangeName},'%')
</if>
<if test="status != null">
and status = #{status}
</if>
<if test="productRange != null">
and product_range = #{productRange}
</if>
<if test="supplierId != null and supplierId !=''">
and supplier_id = #{supplierId}
</if>
</select>
<sql id="couponFullCutSql">
id,full_money,cut_money,coupon_num,full_cut_instruction,coupon_name,receive_start_date,receive_end_date
,use_start_date,use_end_date,status,receive_num,get_source,supplier_id,supplier_name,platform_type
</sql>
<select id="pagerCouponFullCut" parameterType="com.sibu.orderHelper.integral.request.CouponDirectPageRequest" resultMap="couponFullCutResponse">
select <include refid="couponFullCutSql"/>
from coupon_full_cut
where 1=1
<if test="couponName != ''">
and coupon_name like concat('%',#{couponName},'%')
</if>
<if test="supplierId !=null and supplierId != ''">
and supplier_id = #{supplierId}
</if>
<if test="status !=null and status != ''">
and status = #{status}
</if>
<if test="pastStatus !=null and pastStatus != '' and pastStatus == 0">
and use_end_date >= now()
</if>
<if test="pastStatus !=null and pastStatus != '' and pastStatus == 1">
<![CDATA[
and use_end_date < now()
]]>
</if>
order by id desc
LIMIT
${pageNow}, ${pageSize}
</select>
<select id="totalCouponFullCut" parameterType="com.sibu.orderHelper.integral.request.CouponDirectPageRequest" resultType="int">
select count(*)
from coupon_full_cut
where 1=1
<if test="couponName != ''">
and coupon_name like concat('%',#{couponName},'%')
</if>
<if test="supplierId != '' and supplierId != null">
and supplier_id = #{supplierId}
</if>
<if test="status !=null and status != ''">
and status = #{status}
</if>
<if test="pastStatus !=null and pastStatus != '' and pastStatus == 0">
and use_end_date >= now()
</if>
<if test="pastStatus !=null and pastStatus != '' and pastStatus == 1">
<![CDATA[
and use_end_date < now()
]]>
</if>
</select>
<sql id="couponFullCutLimitSql">
id,full_cut_id,range_name,full_cut_range,full_cut_range_id
</sql>
<select id="pagerFullCutLimitCoupon" parameterType="com.sibu.orderHelper.integral.request.CouponFullCutLimitPageRequest" resultMap="couponFullCutLimitResponse">
select <include refid="couponFullCutLimitSql"/>
from coupon_full_cut_range
where delete_flag = 0 and full_cut_id = #{fullCutId}
<if test="productRange != ''">
and product_range = #{productRange}
</if>
order by id desc
LIMIT
${pageNow}, ${pageSize}
</select>
<select id="totalFullCutLimitCoupon" parameterType="com.sibu.orderHelper.integral.request.CouponFullCutLimitPageRequest" resultType="int">
select count(*)
from coupon_full_cut_range
where delete_flag = 0 and full_cut_id = #{fullCutId}
<if test="productRange != ''">
and product_range = #{productRange}
</if>
</select>
<select id="countCouponFullCutLimit" parameterType="java.lang.Integer" resultMap="couponFullCutLimitCountResponse">
select count(*) count_limit, full_cut_range from coupon_full_cut_range where full_cut_id = #{id} and delete_flag = 0 GROUP by full_cut_range
</select>
<select id="pagerUserCoupon" parameterType="com.sibu.orderHelper.integral.request.CouponUserPageRequest" resultMap="couponUserResponse">
select id,member_id,coupon_name,coupon_id,coupon_type,use_dt,use_order_code,get_source,create_dt,coupon_code from user_coupons
<where>
<if test="useOrderCode != '' and useOrderCode != null">
use_order_code = #{useOrderCode}
</if>
<if test="couponCode != '' and couponCode != null">
and coupon_code = #{couponCode}
</if>
<if test="getSource != '' and getSource != null or 0 == getSource">
and get_source = #{getSource}
</if>
<if test="isUse != '' and isUse != null">
<if test="isUse == 1">
and (use_order_code is null or use_order_code = '')
</if>
<if test="isUse == 2">
and (use_order_code is not null or use_order_code != '')
</if>
</if>
<if test="isExpire != '' and isExpire != null">
<if test="isExpire == 1">
and use_end_dt >= now()
</if>
<if test="isExpire == 2">
<![CDATA[
and use_end_dt <= now()
]]>
</if>
</if>
<if test="startDate != null and startDate !=''">
and create_dt >= #{startDate}
</if>
<if test="endDate != null and endDate != ''">
<![CDATA[
and create_dt <= #{endDate}
]]>
</if>
</where>
order by id desc
LIMIT
${pageNow}, ${pageSize}
</select>
<select id="totalUserCoupon" parameterType="com.sibu.orderHelper.integral.request.CouponUserPageRequest" resultType="int">
select count(*)
from user_coupons
<where>
<if test="useOrderCode != '' and useOrderCode != null">
use_order_code = #{useOrderCode}
</if>
<if test="couponCode != '' and couponCode != null">
and coupon_code = #{couponCode}
</if>
<if test="getSource != '' and getSource != null or 0 == getSource">
and get_source = #{getSource}
</if>
<if test="isUse != '' and isUse != null">
<if test="isUse == 1">
and (use_order_code is null or use_order_code = '')
</if>
<if test="isUse == 2">
and (use_order_code is not null or use_order_code != '')
</if>
</if>
<if test="isExpire != '' and isExpire != null">
<if test="isExpire == 1">
and use_end_dt >= now()
</if>
<if test="isExpire == 2">
<![CDATA[
and use_end_dt <= now()
]]>
</if>
</if>
<if test="startDate != null and startDate !=''">
and create_dt >= #{startDate}
</if>
<if test="endDate != null and endDate != ''">
<![CDATA[
and create_dt <= #{endDate}
]]>
</if>
</where>
</select>
<!--获取对象-->
<select id="getCouponDirectById" parameterType="java.lang.Integer" resultMap="couponDirectResponse">
SELECT <include refid="couponDirectSql"/>
from coupon_direct_cut
where id = #{id}
limit 1
</select>
<select id="getCouponFullCutById" parameterType="java.lang.Integer" resultMap="couponFullCutResponse">
SELECT <include refid="couponFullCutSql"/>
from coupon_full_cut
where id = #{id}
limit 1
</select>
<select id="getCouponFullCutLimitByRangeId" parameterType="java.util.Map" resultMap="couponFullCutLimitResponse">
select <include refid="couponFullCutLimitSql"/>
from coupon_full_cut_range
where delete_flag = 0 and full_cut_id = #{fullCutId} and full_cut_range_id = #{rangeId} limit 1
</select>
<select id="getCouponFullCutLimitById" parameterType="java.util.Map" resultMap="couponFullCutLimitResponse">
select <include refid="couponFullCutLimitSql"/>
from coupon_full_cut_range
where delete_flag = 0 and full_cut_id = #{fullCutId} and id= #{id} limit 1
</select>
<!--编辑对象-->
<update id="editDirectCoupon" parameterType="com.sibu.orderHelper.integral.request.CouponDirectEditRequest">
update coupon_direct_cut
set coupon_name = #{couponName},
coupon_num = ${couponNum},
coupon_money = #{couponMoney},
receive_start_date = #{receiveStartDate},
receive_end_date = #{receiveEndDate},
use_start_date = #{useStartDate},
use_end_date = #{useEndDate},
status = #{status},
direct_cut_instruction = #{directCutInstruction}
where id = ${id}
limit 1
</update>
<update id="editFullCutCoupon" parameterType="com.sibu.orderHelper.integral.request.CouponFullCutEditRequest">
update coupon_full_cut
set coupon_name = #{couponName},
coupon_num = ${couponNum},
full_money = #{fullMoney},
cut_money = #{cutMoney},
receive_start_date = #{receiveStartDate},
receive_end_date = #{receiveEndDate},
use_start_date = #{useStartDate},
use_end_date = #{useEndDate},
status = #{status},
full_cut_instruction = #{fullCutInstruction}
where id = ${id}
limit 1
</update>
<delete id="deleteFullCutLimitCoupon" parameterType="com.sibu.orderHelper.integral.request.CouponFullCutLimitDeleteRequest">
update coupon_full_cut_range set delete_flag = 1 where id=#{id} and full_cut_id=#{fullCutId} limit 1
</delete>
<select id="pagerUserCouponBySupplierId" parameterType="com.sibu.orderHelper.integral.request.CouponUserPageRequest" resultMap="couponUserResponse">
select id,member_id,coupon_name,coupon_id,coupon_type,use_dt,use_order_code,get_source,create_dt,coupon_code,supplier_name,supplier_id,use_end_dt
FROM
(
select u.id,u.member_id,u.coupon_name,u.coupon_id,u.coupon_type,u.use_dt,u.use_order_code,u.get_source,u.create_dt,u.coupon_code,t.supplier_name,t.supplier_id,u.use_end_dt
FROM user_coupons u ,coupon_direct_cut t
WHERE
t.id = u.coupon_id
<if test="supplierId != '' and supplierId != null">
and supplier_id = #{supplierId}
</if>
and u.coupon_type = 0
UNION
ALL
select u.id,u.member_id,u.coupon_name,u.coupon_id,u.coupon_type,u.use_dt,u.use_order_code,u.get_source,u.create_dt,u.coupon_code,f.supplier_name,f.supplier_id,u.use_end_dt
FROM user_coupons u ,coupon_full_cut f
WHERE
f.id = u.coupon_id
<if test="supplierId != '' and supplierId != null">
and supplier_id = #{supplierId}
</if>
and u.coupon_type = 1
) cu
<where>
<if test="useOrderCode != '' and useOrderCode != null">
use_order_code = #{useOrderCode}
</if>
<if test="couponCode != '' and couponCode != null">
and coupon_code = #{couponCode}
</if>
<if test="getSource != '' and getSource != null or 0 == getSource">
and get_source = #{getSource}
</if>
<if test="isUse != '' and isUse != null">
<if test="isUse == 1">
and (use_order_code is null or use_order_code = '')
</if>
<if test="isUse == 2">
and (use_order_code is not null or use_order_code != '')
</if>
</if>
<if test="isExpire != '' and isExpire != null">
<if test="isExpire == 1">
and use_end_dt > now()
</if>
<if test="isExpire == 2">
<![CDATA[
and use_end_dt <= now()
]]>
</if>
</if>
<if test="startDate != null and startDate !=''">
and create_dt >= #{startDate}
</if>
<if test="endDate != null and endDate != ''">
<![CDATA[
and create_dt <= #{endDate}
]]>
</if>
</where>
order by id desc
limit
${pageNow}, ${pageSize}
</select>
<select id="getAllCouponListBySupplierId" parameterType="com.sibu.orderHelper.integral.reponse.SupplierCouponResponse" resultMap="supplierCouponResponse">
SELECT c.id,c.coupon_name,c.coupon_num,c.receive_num,c.supplier_id,c.supplier_name,1 coupon_type FROM coupon_full_cut c
WHERE 1=1
<if test="supplierId != null and supplierId !=''">
and supplier_id = #{supplierId}
</if>
UNION ALL
SELECT d.id,d.coupon_name,d.coupon_num,d.receive_num,d.supplier_id,d.supplier_name,0 coupon_type FROM coupon_direct_cut d
WHERE 1=1
<if test="supplierId != null and supplierId !=''">
and supplier_id = #{supplierId}
</if>
</select>
<select id="pagerCouponListBySupplierCouponDetailRequest" parameterType="com.sibu.orderHelper.integral.request.SupplierCouponDetailRequest" resultMap="supplierCouponResponse">
SELECT c.id,c.coupon_name,c.coupon_num,c.receive_num,c.supplier_id,c.supplier_name,1 coupon_type FROM coupon_full_cut c
WHERE 1=1
<if test="supplierId != null and supplierId !=''">
and supplier_id = #{supplierId}
</if>
<if test="couponName != null and couponName !=''">
and coupon_name like concat('%',#{couponName},'%')
</if>
UNION ALL
SELECT d.id,d.coupon_name,d.coupon_num,d.receive_num,d.supplier_id,d.supplier_name,0 coupon_type FROM coupon_direct_cut d
WHERE 1=1
<if test="supplierId != null and supplierId !=''">
and supplier_id = #{supplierId}
</if>
<if test="couponName != null and couponName !=''">
and coupon_name like concat('%',#{couponName},'%')
</if>
</select>
<select id="totalPagerCouponListBySupplierCouponDetailRequest" resultType="java.lang.Integer" parameterType="com.sibu.orderHelper.integral.request.SupplierCouponDetailRequest">
select COUNT(*) from
(
SELECT c.id,c.coupon_name,c.coupon_num,c.receive_num,c.supplier_id,c.supplier_name,1 coupon_type FROM
coupon_full_cut c
WHERE 1=1
<if test="supplierId != null and supplierId !=''">
and supplier_id = #{supplierId}
</if>
<if test="couponName != null and couponName !=''">
and coupon_name like concat('%',#{couponName},'%')
</if>
UNION ALL
SELECT d.id,d.coupon_name,d.coupon_num,d.receive_num,d.supplier_id,d.supplier_name,0 coupon_type FROM
coupon_direct_cut d
WHERE 1=1
<if test="supplierId != null and supplierId !=''">
and supplier_id = #{supplierId}
</if>
<if test="couponName != null and couponName !=''">
and coupon_name like concat('%',#{couponName},'%')
</if>
) a
</select>
<select id="pagerCouponUserResponseList" parameterType="com.sibu.orderHelper.integral.reponse.SupplierCouponResponse" resultMap="couponUserResponse">
SELECT id,member_id,coupon_name,coupon_id,coupon_type,use_dt,use_order_code,get_source,create_dt,coupon_code from user_coupons
WHERE coupon_id = #{id} AND coupon_type = #{couponType}
</select>
<!-- 插入中间表数据-->
<insert id="addCouponList">
INSERT INTO statistics_couponList(supplier_id,supplier_name,coupon_num,receive_num,pay_num,notPay_num,conversion_rate)
VALUES
<foreach collection="couponList" item="c" separator=",">
(#{c.supplierId},#{c.supplierName},#{c.couponNum},#{c.receiveNum},#{c.payNum},#{c.notPayNum},#{c.conversionRate})
</foreach>
</insert>
<!--读取中间表数据 -->
<select id="pagerStatisticsCoupList" parameterType="com.sibu.orderHelper.integral.request.SupplierCouponRequest" resultMap="supplier">
SELECT supplier_id,supplier_name,coupon_num,receive_num,pay_num,notPay_num,conversion_rate,coupon_type FROM statistics_couponList where 1=1
<if test="supplierId != null and supplierId !=''">
and supplier_id = #{supplierId}
</if>
ORDER BY conversion_rate DESC,supplier_id DESC
limit ${pageNow}, ${pageSize}
</select>
<select id="totalStatisticsCoupList" parameterType="com.sibu.orderHelper.integral.request.SupplierCouponRequest" resultType="java.lang.Integer">
SELECT COUNT(*) FROM statistics_couponList where 1=1
<if test="supplierId != null and supplierId !=''">
and supplier_id = #{supplierId}
</if>
</select>
<!-- 删除中间表数据-->
<delete id="deleteStatisticsCoupList" >
DELETE FROM statistics_couponList
<if test="supplierId != null and supplierId !=''">
and supplier_id = #{supplierId}
</if>
</delete>
<!-- 插入中间表数据(明细)-->
<insert id="addCouponDetailList">
INSERT INTO statistics_couponDetailList(id,coupon_id,coupon_name,supplier_id,supplier_name,coupon_num,receive_num,pay_num,notPay_num,conversion_rate,coupon_type)
VALUES
<foreach collection="couponDetailResponseList" item="c" separator=",">
(#{c.id},#{c.couponId},#{c.couponName},#{c.supplierId},#{c.supplierName},#{c.couponNum},#{c.receiveNum},#{c.payNum},#{c.notPayNum},#{c.conversionRate},#{c.couponType})
</foreach>
</insert>
<!-- 删除中间表数据(明细)-->
<delete id="deleteStatisticsCouponDetailList" parameterType="com.sibu.orderHelper.integral.request.SupplierCouponDetailRequest">
DELETE FROM statistics_couponDetailList where supplier_id = #{supplierId}
</delete>
<!--读取中间表数据 -->
<select id="pagerStatisticsCouponDetailList" parameterType="com.sibu.orderHelper.integral.request.SupplierCouponDetailRequest" resultMap="couponDetail">
SELECT id,coupon_id,coupon_name,supplier_id,supplier_name,coupon_num,receive_num,pay_num,notPay_num,conversion_rate,coupon_type FROM statistics_couponDetailList where 1=1
<if test="supplierId != null and supplierId !=''">
and supplier_id = #{supplierId}
</if>
ORDER BY conversion_rate DESC
limit ${pageNow}, ${pageSize}
</select>
<select id="totalStatisticsCouponDetailList" parameterType="com.sibu.orderHelper.integral.request.SupplierCouponDetailRequest" resultType="java.lang.Integer">
SELECT COUNT(*) FROM statistics_couponDetailList where 1=1
<if test="supplierId != null and supplierId !=''">
and supplier_id = #{supplierId}
</if>
</select>
<delete id="deleteDirectCoupon">
DELETE FROM coupon_direct_cut WHERE id = #{id}
</delete>
<delete id="deleteFullCoupon">
DELETE FROM coupon_full_cut WHERE id = #{id}
</delete>
<delete id="deleteFullCouponRange">
DELETE FROM coupon_full_cut_range WHERE full_cut_id = #{id}
</delete>
<select id="totalFullCouponRange" parameterType="java.lang.Integer" resultType="java.lang.Integer">
SELECT COUNT(*) FROM coupon_full_cut_range WHERE full_cut_id = #{id}
</select>
</mapper>