Administrator
2024-07-15 68dc36abcf72f5830695b43fed0e50d82993fba9
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
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
<?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.dy.pipIrrGlobal.daoSe.SeCardOperateMapper">
  <resultMap id="BaseResultMap" type="com.dy.pipIrrGlobal.pojoSe.SeCardOperate">
    <!--@mbg.generated-->
    <!--@Table se_card_operate-->
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="card_id" jdbcType="BIGINT" property="cardId" />
    <result column="client_id" jdbcType="BIGINT" property="clientId" />
    <result column="money" jdbcType="FLOAT" property="money" />
    <result column="system_balance" jdbcType="FLOAT" property="systemBalance" />
    <result column="trade_amount" jdbcType="FLOAT" property="tradeAmount" />
    <result column="price" jdbcType="FLOAT" property="price" />
    <result column="card_cost" jdbcType="INTEGER" property="cardCost" />
    <result column="gift" jdbcType="FLOAT" property="gift" />
    <result column="refund_amount" jdbcType="FLOAT" property="refundAmount" />
    <result column="no_trade_amount" jdbcType="FLOAT" property="noTradeAmount" />
    <result column="operate_type" jdbcType="TINYINT" property="operateType" />
    <result column="payment_id" jdbcType="BIGINT" property="paymentId" />
    <result column="remarks" jdbcType="VARCHAR" property="remarks" />
    <result column="operator" jdbcType="BIGINT" property="operator" />
    <result column="operate_dt" jdbcType="TIMESTAMP" property="operateDt" />
  </resultMap>
  <sql id="Base_Column_List">
    <!--@mbg.generated-->
    id, card_id, client_id, money, system_balance, trade_amount, price, card_cost, gift, 
    refund_amount, no_trade_amount, operate_type, payment_id, remarks, `operator`, operate_dt
  </sql>
  <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
    <!--@mbg.generated-->
    select 
    <include refid="Base_Column_List" />
    from se_card_operate
    where id = #{id,jdbcType=BIGINT}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
    <!--@mbg.generated-->
    delete from se_card_operate
    where id = #{id,jdbcType=BIGINT}
  </delete>
  <insert id="insert" parameterType="com.dy.pipIrrGlobal.pojoSe.SeCardOperate">
    <!--@mbg.generated-->
    insert into se_card_operate (id, card_id, client_id, 
      money, system_balance, trade_amount, 
      price, card_cost, gift, 
      refund_amount, no_trade_amount, operate_type, 
      payment_id, remarks, `operator`, 
      operate_dt)
    values (#{id,jdbcType=BIGINT}, #{cardId,jdbcType=BIGINT}, #{clientId,jdbcType=BIGINT}, 
      #{money,jdbcType=FLOAT}, #{systemBalance,jdbcType=FLOAT}, #{tradeAmount,jdbcType=FLOAT}, 
      #{price,jdbcType=FLOAT}, #{cardCost,jdbcType=INTEGER}, #{gift,jdbcType=FLOAT}, 
      #{refundAmount,jdbcType=FLOAT}, #{noTradeAmount,jdbcType=FLOAT}, #{operateType,jdbcType=TINYINT}, 
      #{paymentId,jdbcType=BIGINT}, #{remarks,jdbcType=VARCHAR}, #{operator,jdbcType=BIGINT}, 
      #{operateDt,jdbcType=TIMESTAMP})
  </insert>
  <insert id="insertSelective" parameterType="com.dy.pipIrrGlobal.pojoSe.SeCardOperate">
    <!--@mbg.generated-->
    insert into se_card_operate
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      <if test="cardId != null">
        card_id,
      </if>
      <if test="clientId != null">
        client_id,
      </if>
      <if test="money != null">
        money,
      </if>
      <if test="systemBalance != null">
        system_balance,
      </if>
      <if test="tradeAmount != null">
        trade_amount,
      </if>
      <if test="price != null">
        price,
      </if>
      <if test="cardCost != null">
        card_cost,
      </if>
      <if test="gift != null">
        gift,
      </if>
      <if test="refundAmount != null">
        refund_amount,
      </if>
      <if test="noTradeAmount != null">
        no_trade_amount,
      </if>
      <if test="operateType != null">
        operate_type,
      </if>
      <if test="paymentId != null">
        payment_id,
      </if>
      <if test="remarks != null">
        remarks,
      </if>
      <if test="operator != null">
        `operator`,
      </if>
      <if test="operateDt != null">
        operate_dt,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id,jdbcType=BIGINT},
      </if>
      <if test="cardId != null">
        #{cardId,jdbcType=BIGINT},
      </if>
      <if test="clientId != null">
        #{clientId,jdbcType=BIGINT},
      </if>
      <if test="money != null">
        #{money,jdbcType=FLOAT},
      </if>
      <if test="systemBalance != null">
        #{systemBalance,jdbcType=FLOAT},
      </if>
      <if test="tradeAmount != null">
        #{tradeAmount,jdbcType=FLOAT},
      </if>
      <if test="price != null">
        #{price,jdbcType=FLOAT},
      </if>
      <if test="cardCost != null">
        #{cardCost,jdbcType=INTEGER},
      </if>
      <if test="gift != null">
        #{gift,jdbcType=FLOAT},
      </if>
      <if test="refundAmount != null">
        #{refundAmount,jdbcType=FLOAT},
      </if>
      <if test="noTradeAmount != null">
        #{noTradeAmount,jdbcType=FLOAT},
      </if>
      <if test="operateType != null">
        #{operateType,jdbcType=TINYINT},
      </if>
      <if test="paymentId != null">
        #{paymentId,jdbcType=BIGINT},
      </if>
      <if test="remarks != null">
        #{remarks,jdbcType=VARCHAR},
      </if>
      <if test="operator != null">
        #{operator,jdbcType=BIGINT},
      </if>
      <if test="operateDt != null">
        #{operateDt,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.dy.pipIrrGlobal.pojoSe.SeCardOperate">
    <!--@mbg.generated-->
    update se_card_operate
    <set>
      <if test="cardId != null">
        card_id = #{cardId,jdbcType=BIGINT},
      </if>
      <if test="clientId != null">
        client_id = #{clientId,jdbcType=BIGINT},
      </if>
      <if test="money != null">
        money = #{money,jdbcType=FLOAT},
      </if>
      <if test="systemBalance != null">
        system_balance = #{systemBalance,jdbcType=FLOAT},
      </if>
      <if test="tradeAmount != null">
        trade_amount = #{tradeAmount,jdbcType=FLOAT},
      </if>
      <if test="price != null">
        price = #{price,jdbcType=FLOAT},
      </if>
      <if test="cardCost != null">
        card_cost = #{cardCost,jdbcType=INTEGER},
      </if>
      <if test="gift != null">
        gift = #{gift,jdbcType=FLOAT},
      </if>
      <if test="refundAmount != null">
        refund_amount = #{refundAmount,jdbcType=FLOAT},
      </if>
      <if test="noTradeAmount != null">
        no_trade_amount = #{noTradeAmount,jdbcType=FLOAT},
      </if>
      <if test="operateType != null">
        operate_type = #{operateType,jdbcType=TINYINT},
      </if>
      <if test="paymentId != null">
        payment_id = #{paymentId,jdbcType=BIGINT},
      </if>
      <if test="remarks != null">
        remarks = #{remarks,jdbcType=VARCHAR},
      </if>
      <if test="operator != null">
        `operator` = #{operator,jdbcType=BIGINT},
      </if>
      <if test="operateDt != null">
        operate_dt = #{operateDt,jdbcType=TIMESTAMP},
      </if>
    </set>
    where id = #{id,jdbcType=BIGINT}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.dy.pipIrrGlobal.pojoSe.SeCardOperate">
    <!--@mbg.generated-->
    update se_card_operate
    set card_id = #{cardId,jdbcType=BIGINT},
      client_id = #{clientId,jdbcType=BIGINT},
      money = #{money,jdbcType=FLOAT},
      system_balance = #{systemBalance,jdbcType=FLOAT},
      trade_amount = #{tradeAmount,jdbcType=FLOAT},
      price = #{price,jdbcType=FLOAT},
      card_cost = #{cardCost,jdbcType=INTEGER},
      gift = #{gift,jdbcType=FLOAT},
      refund_amount = #{refundAmount,jdbcType=FLOAT},
      no_trade_amount = #{noTradeAmount,jdbcType=FLOAT},
      operate_type = #{operateType,jdbcType=TINYINT},
      payment_id = #{paymentId,jdbcType=BIGINT},
      remarks = #{remarks,jdbcType=VARCHAR},
      `operator` = #{operator,jdbcType=BIGINT},
      operate_dt = #{operateDt,jdbcType=TIMESTAMP}
    where id = #{id,jdbcType=BIGINT}
  </update>
 
  <!--根据指定条件获取充值记录数量-->
  <select id="getRecordCount" parameterType="java.util.Map" resultType="java.lang.Long">
    select
        COUNT(*) AS recordCount
    FROM se_card_operate ope
    INNER JOIN se_client_card card ON ope.card_id = card.id
    INNER JOIN se_client cli ON ope.client_id = cli.id
    INNER JOIN ba_user us ON ope.operator = us.id
    Left JOIN se_payment_method pay ON ope.payment_id = pay.id
    <where>
      AND ope.operate_type in(1, 2, 5)
      <if test = "clientName != null and clientName !=''">
        AND cli.name like CONCAT('%',#{clientName},'%')
      </if>
 
      <if test = "clientNum != null and clientNum > 0">
        AND cli.clientNum like CONCAT('%',#{clientNum},'%')
      </if>
 
      <if test = "cardNum != null and cardNum !=''">
        AND card.cardNum like CONCAT('%',#{cardNum},'%')
      </if>
 
      <!--      <if test = "paymentId != null and paymentId > 0">-->
      <!--        AND ope.payment_id = ${paymentId}-->
      <!--      </if>-->
 
      <!--      <if test = "rechargeTimeStart != null and rechargeTimeStop != null">-->
      <!--        AND ope.operate_dt BETWEEN #{rechargeTimeStart} AND #{rechargeTimeStop}-->
      <!--      </if>-->
    </where>
  </select>
 
  <!--根据指定条件获取充值记录-->
  <select id="getRecharges" resultType="com.dy.pipIrrGlobal.voSe.VoRecharge">
    SELECT
      ope.id AS opeId,
      card.id AS cardId,
      cli.name AS clientName,
      cli.phone,
      cli.idCard,
      cli.clientNum,
      cli.address,
      card.money,
      cardNum,
<!--      CASE-->
<!--        WHEN card.cardNum LIKE '10%' THEN CONCAT(SUBSTRING(card.cardNum, 7, 6),SUBSTRING(card.cardNum, 14, 4))-->
<!--        ELSE card.cardNum-->
<!--      END AS cardNum,-->
      IFNULL(ope.card_cost,0) AS cardCost,
      IFNULL(ope.trade_amount, 0) AS amount,
      IFNULL(ope.refund_amount, 0) AS refundAmount,
      (IFNULL(ope.money, 0) + IFNULL(ope.trade_amount, 0)) AS afterRecharge,
      pay.name AS paymentName,
      ope.price,
      us.name AS opr,
      (CASE
        WHEN ope.operate_type = 1 THEN "开卡"
        WHEN ope.operate_type = 2 THEN "充值"
        WHEN ope.operate_type = 5 THEN "返还"
      END) AS operateType,
      ope.operate_dt
    FROM se_card_operate ope
    INNER JOIN se_client_card card ON ope.card_id = card.id
    INNER JOIN se_client cli ON ope.client_id = cli.id
    INNER JOIN ba_user us ON ope.operator = us.id
    Left JOIN se_payment_method pay ON ope.payment_id = pay.id
    <where>
      AND ope.operate_type in(1, 2, 5)
      <if test = "clientName != null and clientName !=''">
        AND cli.name like CONCAT('%',#{clientName},'%')
      </if>
 
      <if test = "clientNum != null and clientNum > 0">
        AND cli.clientNum like CONCAT('%',#{clientNum},'%')
      </if>
 
      <if test = "cardNum != null and cardNum !=''">
        AND card.cardNum like CONCAT('%',#{cardNum},'%')
      </if>
 
<!--      <if test = "paymentId != null and paymentId > 0">-->
<!--        AND ope.payment_id = ${paymentId}-->
<!--      </if>-->
 
<!--      <if test = "rechargeTimeStart != null and rechargeTimeStop != null">-->
<!--        AND ope.operate_dt BETWEEN #{rechargeTimeStart} AND #{rechargeTimeStop}-->
<!--      </if>-->
    </where>
    ORDER BY ope.operate_dt DESC
    <trim prefix="limit " >
      <if test="start != null and count != null">
        #{start,javaType=Integer,jdbcType=INTEGER}, #{count,javaType=Integer,jdbcType=INTEGER}
      </if>
    </trim>
  </select>
 
  <!--根据指定条件获取交易记录数-->
  <select id="getTransactionRecordCount" parameterType="java.util.Map" resultType="java.lang.Long">
    SELECT
        COUNT(*) AS recordCount
    FROM v_trade_details
    <where>
      <if test = "villageId != null and villageId > 0">
        AND villageId = ${villageId}
      </if>
 
      <if test = "operateTimeStart != null and operateTimeStop != null">
        AND tradeTime BETWEEN #{operateTimeStart} AND #{operateTimeStop}
      </if>
 
      <if test = "cashierId != null and cashierId > 0">
        AND cashierId = ${cashierId}
      </if>
 
      <if test = "tradeTime != null">
        AND tradeTime = #{tradeTime}
      </if>
    </where>
  </select>
 
  <!--根据指定条件获取交易记录-->
  <select id="getTransactions" resultType="com.dy.pipIrrGlobal.voSe.VoTradeDetails">
    SELECT * FROM v_trade_details
    <where>
      <if test = "villageId != null and villageId > 0">
        AND villageId = ${villageId}
      </if>
 
      <if test = "operateTimeStart != null and operateTimeStop != null">
        AND tradeTime BETWEEN #{operateTimeStart} AND #{operateTimeStop}
      </if>
 
      <if test = "cashierId != null and cashierId > 0">
        AND cashierId = ${cashierId}
      </if>
    </where>
    ORDER BY tradeTime
    <if test="pageCurr != null and pageSize != null">
      LIMIT ${pageCurr}, ${pageSize}
    </if>
  </select>
 
  <!--根据指定条件获取开卡记录数量-->
  <select id="getActiveCardRecordCount" parameterType="java.util.Map" resultType="java.lang.Long">
    select
    COUNT(*) AS recordCount
    FROM se_card_operate ope
    INNER JOIN se_client_card card ON ope.card_id = card.id
    INNER JOIN se_client cli ON ope.client_id = cli.id
    <where>
      AND ope.operate_type = 1
      <if test = "clientName != null and clientName !=''">
        AND cli.name like CONCAT('%',#{clientName},'%')
      </if>
 
      <if test = "cardNum != null and cardNum !=''">
        AND card.cardNum like CONCAT('%',#{cardNum},'%')
      </if>
 
      <if test = "state != null and state > 0">
        AND card.state = ${state}
      </if>
 
      <if test = "activeTimeStart != null and activeTimeStop != null">
        AND ope.operate_dt BETWEEN #{activeTimeStart} AND #{activeTimeStop}
      </if>
    </where>
  </select>
 
  <!--根据指定条件获取开卡记录-->
  <select id="getActiveCards" resultType="com.dy.pipIrrGlobal.voSe.VoActiveCard">
    SELECT
    CAST(ope.id AS char) AS id ,
    cli.name AS clientName,
    cli.clientNum AS clientNum,
    card.cardNum AS cardNum,
    card.state AS state,
    (CASE
    WHEN card.state = 1 THEN "正常"
    WHEN card.state = 2 THEN "已注销"
    WHEN card.state = 3 THEN "已挂失"
    END) AS stateName,
    ope.card_cost AS cardCost,
    ope.payment_id AS paymentId,
    (SELECT `name` FROM ba_user WHERE id =  ope.operator) AS operator,
    ope.operate_dt AS operateDt
    FROM se_card_operate ope
    INNER JOIN se_client_card card ON ope.card_id = card.id
    INNER JOIN se_client cli ON ope.client_id = cli.id
    <where>
      AND ope.operate_type = 1
      <if test = "clientName != null and clientName !=''">
        AND cli.name like CONCAT('%',#{clientName},'%')
      </if>
 
      <if test = "cardNum != null and cardNum !=''">
        AND card.cardNum like CONCAT('%',#{cardNum},'%')
      </if>
 
      <if test = "state != null and state > 0">
        AND card.state = ${state}
      </if>
 
      <if test = "activeTimeStart != null and activeTimeStop != null">
        AND ope.operate_dt BETWEEN #{activeTimeStart} AND #{activeTimeStop}
      </if>
    </where>
    ORDER BY ope.operate_dt DESC
    <trim prefix="limit " >
      <if test="start != null and count != null">
        #{start,javaType=Integer,jdbcType=INTEGER}, #{count,javaType=Integer,jdbcType=INTEGER}
      </if>
    </trim>
  </select>
 
  <!--根据指定条件获取补卡记录数量-->
  <select id="getReissueCardRecordCount" parameterType="java.util.Map" resultType="java.lang.Long">
    select
    COUNT(*) AS recordCount
    FROM se_card_operate ope
    INNER JOIN se_client_card card ON ope.card_id = card.id
    INNER JOIN se_client cli ON ope.client_id = cli.id
    <where>
      AND ope.operate_type = 4
      <if test = "clientName != null and clientName !=''">
        AND cli.name like CONCAT('%',#{clientName},'%')
      </if>
 
      <if test = "cardNum != null and cardNum !=''">
        AND card.cardNum like CONCAT('%',#{cardNum},'%')
      </if>
 
      <if test = "activeTimeStart != null and activeTimeStop != null">
        AND ope.operate_dt BETWEEN #{reissueCardTimeStart} AND #{reissueCardTimeStop}
      </if>
    </where>
  </select>
 
  <!--根据指定条件获取补卡记录-->
  <select id="getReissueCards" resultType="com.dy.pipIrrGlobal.voSe.VoReissueCard">
    SELECT
    CAST(ope.id AS char) AS id ,
    cli.name AS clientName,
    cli.clientNum AS clientNum,
    card.cardNum AS cardNum,
    ope.card_cost AS cardCost,
    IFNULL(ope.no_trade_amount,0) AS reissueAmount,
    (SELECT `name` FROM ba_user WHERE id =  ope.operator) AS operator,
    ope.operate_dt AS operateDt
    FROM se_card_operate ope
    INNER JOIN se_client_card card ON ope.card_id = card.id
    INNER JOIN se_client cli ON ope.client_id = cli.id
    <where>
      AND ope.operate_type = 4
      <if test = "clientName != null and clientName !=''">
        AND cli.name like CONCAT('%',#{clientName},'%')
      </if>
 
      <if test = "cardNum != null and cardNum !=''">
        AND card.cardNum like CONCAT('%',#{cardNum},'%')
      </if>
 
      <if test = "activeTimeStart != null and activeTimeStop != null">
        AND ope.operate_dt BETWEEN #{reissueCardTimeStart} AND #{reissueCardTimeStop}
      </if>
    </where>
    ORDER BY ope.operate_dt DESC
    <trim prefix="limit " >
      <if test="start != null and count != null">
        #{start,javaType=Integer,jdbcType=INTEGER}, #{count,javaType=Integer,jdbcType=INTEGER}
      </if>
    </trim>
  </select>
 
  <!--根据指定条件获取通用操作记录数量-->
  <select id="getCommonOperationRecordCount" parameterType="java.util.Map" resultType="java.lang.Long">
    select
        COUNT(*) AS recordCount
    FROM se_card_operate ope
        INNER JOIN se_client cli ON ope.client_id = cli.id
        INNER JOIN se_client_card card ON ope.card_id = card.id
        INNER JOIN ba_user us ON ope.operator = us.id
    <where>
      <if test = "operateType != null and operateType > 0">
        AND ope.operate_type = ${operateType}
      </if>
 
      <if test = "clientName != null and clientName !=''">
        AND cli.name like CONCAT('%',#{clientName},'%')
      </if>
 
      <if test = "cardNum != null and cardNum !=''">
        AND card.cardNum like CONCAT('%',#{cardNum},'%')
      </if>
 
      <if test = "timeStart != null and timeStop != null">
        AND ope.operate_dt BETWEEN #{timeStart} AND #{timeStop}
      </if>
    </where>
  </select>
 
  <!--根据指定条件获取通用操作记录-->
  <select id="getCommonOperations" resultType="com.dy.pipIrrGlobal.voSe.VoOperate">
    SELECT
        cli.name AS clientName,
        cli.clientNum,
        CAST(card.cardNum AS char) AS cardNum,
        us.name AS operator,
        ope.operate_dt AS operateDt,
        IFNULL(ope.trade_amount,0) AS refund,
        (CASE
            WHEN ope.payment_id = 1 THEN "现金"
        END) AS refundTypeName,
        card.money,
        IFNULL(ope.system_balance,0) AS systemBalance
    FROM se_card_operate ope
        INNER JOIN se_client cli ON ope.client_id = cli.id
        INNER JOIN se_client_card card ON ope.card_id = card.id
        INNER JOIN ba_user us ON ope.operator = us.id
    <where>
      <if test = "operateType != null and operateType > 0">
        AND ope.operate_type = ${operateType}
      </if>
 
      <if test = "clientName != null and clientName !=''">
        AND cli.name like CONCAT('%',#{clientName},'%')
      </if>
 
      <if test = "cardNum != null and cardNum !=''">
        AND card.cardNum like CONCAT('%',#{cardNum},'%')
      </if>
 
      <if test = "timeStart != null and timeStop != null">
        AND ope.operate_dt BETWEEN #{timeStart} AND #{timeStop}
      </if>
    </where>
    ORDER BY ope.operate_dt DESC
    <trim prefix="limit " >
      <if test="start != null and count != null">
        #{start,javaType=Integer,jdbcType=INTEGER}, #{count,javaType=Integer,jdbcType=INTEGER}
      </if>
    </trim>
  </select>
 
  <!--根据指定条件获取收据列表数-->
  <select id="getReceiptsRecordCount" parameterType="java.util.Map" resultType="java.lang.Long">
    SELECT
    COUNT(*) AS recordCount
    FROM se_card_operate ope
    INNER JOIN se_client cli ON ope.client_id = cli.id
    INNER JOIN se_client_card card ON ope.card_id = card.id
    INNER JOIN se_payment_method pay ON ope.payment_id = pay.id
    INNER JOIN ba_user us ON ope.operator = us.id
    INNER JOIN ba_district vil ON cli.villageId = vil.id
    INNER JOIN ba_district tow ON cli.townId = tow.id
    <where>
      AND ope.operate_type IN(1,2)
      <if test = "operateId != null and operateId > 0">
        AND ope.id = ${operateId}
      </if>
 
      <if test = "clientName != null and clientName !=''">
        AND cli.name like CONCAT('%',#{clientName},'%')
      </if>
 
      <if test = "timeStart != null and timeStop != null">
        AND ope.operate_dt BETWEEN #{timeStart} AND #{timeStop}
      </if>
    </where>
  </select>
 
  <!--根据指定条件获取收据列表-->
  <select id="getReceipts" resultType="com.dy.pipIrrGlobal.voSe.VoReceipt">
    SELECT
    CAST(ope.id AS char) AS orderNumber,
    tow.name AS townName,
    vil.name AS villageName,
    cli.`name`,
    cli.phone,
    CAST(cli.clientNum AS char) AS clientNum,
    CAST(card.cardNum AS char) AS cardNum,
    (CASE
    WHEN ope.operate_type = 1 THEN '开卡'
    WHEN ope.operate_type = 2 THEN '充值'
    END) AS operateType,
    IFNULL(ope.trade_amount,0) AS waterCost,
    IFNULL(ope.card_cost,0) AS cardCost,
    (IFNULL(ope.trade_amount,0) + IFNULL(ope.card_cost,0)) AS amount,
    card.money,
    pay.`name` AS paymentName,
    us.`name` AS operatorName,
    ope.operate_dt AS operateTime,
    NOW() AS currentTime
    FROM se_card_operate ope
    INNER JOIN se_client cli ON ope.client_id = cli.id
    INNER JOIN se_client_card card ON ope.card_id = card.id
    INNER JOIN se_payment_method pay ON ope.payment_id = pay.id
    INNER JOIN ba_user us ON ope.operator = us.id
    INNER JOIN ba_district vil ON cli.villageId = vil.id
    INNER JOIN ba_district tow ON cli.townId = tow.id
    <where>
      AND ope.operate_type IN(1,2)
      <if test = "operateId != null and operateId > 0">
        AND ope.id = ${operateId}
      </if>
 
      <if test = "clientName != null and clientName !=''">
        AND cli.name like CONCAT('%',#{clientName},'%')
      </if>
 
      <if test = "timeStart != null and timeStop != null">
        AND ope.operate_dt BETWEEN #{timeStart} AND #{timeStop}
      </if>
    </where>
    ORDER BY ope.operate_dt DESC
    <trim prefix="limit " >
      <if test="start != null and count != null">
        #{start,javaType=Integer,jdbcType=INTEGER}, #{count,javaType=Integer,jdbcType=INTEGER}
      </if>
    </trim>
  </select>
 
  <!--根据指定条件获取收据收费金额合计-->
  <select id="getTotalAmount" parameterType="java.util.Map" resultType="java.lang.Double">
    SELECT
    SUM(IFNULL(ope.trade_amount,0) + IFNULL(ope.card_cost,0)) AS totalAmount
    FROM se_card_operate ope
    INNER JOIN se_client cli ON ope.client_id = cli.id
    INNER JOIN se_client_card card ON ope.card_id = card.id
    INNER JOIN se_payment_method pay ON ope.payment_id = pay.id
    INNER JOIN ba_user us ON ope.operator = us.id
    INNER JOIN ba_district vil ON cli.villageId = vil.id
    INNER JOIN ba_district tow ON cli.townId = tow.id
    <where>
      AND ope.operate_type IN(1,2)
      <if test = "operateId != null and operateId > 0">
        AND ope.id = ${operateId}
      </if>
 
      <if test = "clientName != null and clientName !=''">
        AND cli.name like CONCAT('%',#{clientName},'%')
      </if>
 
      <if test = "timeStart != null and timeStop != null">
        AND ope.operate_dt BETWEEN #{timeStart} AND #{timeStop}
      </if>
    </where>
  </select>
 
  <!--根据水卡编号获取其挂失时退款金额(补卡时判断使用)-->
  <select id="getTradeAmountByCardNo" resultType="java.lang.Double">
    SELECT
    ope.trade_amount AS tradeAmount
    FROM se_client_card card
    INNER JOIN se_card_operate ope ON ope.card_id = card.id
    <where>
      AND ope.operate_type = 6
      AND card.cardNum = #{cardNum}
    </where>
    ORDER BY ope.operate_dt DESC
    LIMIT 0,1
  </select>
</mapper>