chengf
2025-08-27 074caee550216dfd4bb676677ae33cbd837c5710
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
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
<?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="feeServiceDaoImpl">
 
    <!-- 保存费用信息 add by wuxw 2018-07-03 -->
    <insert id="saveBusinessFeeInfo" parameterType="Map">
        insert into business_pay_fee(amount, operate, income_obj_id, fee_type_cd, start_time, end_time, community_id,
                                     b_id, fee_id, user_id, payer_obj_id, fee_flag, state, config_id, payer_obj_type,
                                     batch_id)
        values (#{amount}, #{operate}, #{incomeObjId}, #{feeTypeCd}, #{startTime}, #{endTime}, #{communityId}, #{bId},
                #{feeId}, #{userId}, #{payerObjId},
                #{feeFlag}, #{state}, #{configId}, #{payerObjType}, #{batchId})
    </insert>
 
    <!-- 查询费用信息(Business) add by wuxw 2018-07-03 -->
    <select id="getBusinessFeeInfo" parameterType="Map" resultType="Map">
        select t.amount,t.operate,t.income_obj_id,t.income_obj_id incomeObjId,t.fee_type_cd,t.fee_type_cd
        feeTypeCd,s.secondary_fee_type_cd_name,s.secondary_fee_type_cd_name secondaryFeeTypeCdName,t.start_time,t.start_time startTime,t.end_time,t.end_time endTime,t.community_id,t.community_id
        communityId,t.b_id,t.b_id bId,t.fee_id,t.fee_id feeId,t.user_id,t.user_id userId,t.payer_obj_id,t.payer_obj_id
        payerObjId,t.fee_flag,t.fee_flag feeFlag,t.state,t.config_id,t.config_id
        configId,t.payer_obj_type,t.payer_obj_type payerObjType,t.batch_id,t.batch_id batchId
        from business_pay_fee t
        left join secondary_fee_type_cd_tb s on t.secondary_fee_type_cd = s.secondary_fee_type_cd
        where 1 =1
        <if test="amount !=null and amount != ''">
            and t.amount= #{amount}
        </if>
        <if test="operate !=null and operate != ''">
            and t.operate= #{operate}
        </if>
        <if test="incomeObjId !=null and incomeObjId != ''">
            and t.income_obj_id= #{incomeObjId}
        </if>
        <if test="feeTypeCd !=null and feeTypeCd != ''">
            and t.fee_type_cd= #{feeTypeCd}
        </if>
        <if test="startTime !=null ">
            and t.start_time= #{startTime}
        </if>
        <if test="endTime !=null ">
            and t.end_time= #{endTime}
        </if>
        <if test="communityId !=null and communityId != ''">
            and t.community_id= #{communityId}
        </if>
        <if test="bId !=null and bId != ''">
            and t.b_id= #{bId}
        </if>
        <if test="feeId !=null and feeId != ''">
            and t.fee_id= #{feeId}
        </if>
        <if test="payerObjId !=null and payerObjId != ''">
            and t.payer_obj_id= #{payerObjId}
        </if>
        <if test="state !=null and state != ''">
            and t.state= #{state}
        </if>
        <if test="feeFlag !=null and feeFlag != ''">
            and t.fee_flag= #{feeFlag}
        </if>
        <if test="configId !=null and configId != ''">
            and t.config_id= #{configId}
        </if>
        <if test="payerObjType !=null and payerObjType != ''">
            and t.payer_obj_type = #{payerObjType}
        </if>
    </select>
 
    <!-- 保存费用信息至 instance表中 add by wuxw 2018-07-03 -->
    <insert id="saveFeeInfoInstance" parameterType="Map">
        insert into pay_fee(
        amount,income_obj_id,fee_type_cd,start_time,status_cd,end_time,community_id,b_id,fee_id,user_id,payer_obj_id,fee_flag,state,config_id,payer_obj_type,batch_id
        ) select
        t.amount,t.income_obj_id,t.fee_type_cd,t.start_time,'0',t.end_time,t.community_id,t.b_id,t.fee_id,t.user_id,t.payer_obj_id
        ,t.fee_flag,t.state,t.config_id,t.payer_obj_type,t.batch_id
        from business_pay_fee t where 1=1
        <if test="amount !=null and amount != ''">
            and t.amount= #{amount}
        </if>
        and t.operate= 'ADD'
        <if test="incomeObjId !=null and incomeObjId != ''">
            and t.income_obj_id= #{incomeObjId}
        </if>
        <if test="feeTypeCd !=null and feeTypeCd != ''">
            and t.fee_type_cd= #{feeTypeCd}
        </if>
        <if test="startTime !=null ">
            and t.start_time= #{startTime}
        </if>
        <if test="endTime !=null ">
            and t.end_time= #{endTime}
        </if>
        <if test="communityId !=null and communityId != ''">
            and t.community_id= #{communityId}
        </if>
        <if test="bId !=null and bId != ''">
            and t.b_id= #{bId}
        </if>
        <if test="feeId !=null and feeId != ''">
            and t.fee_id= #{feeId}
        </if>
        <if test="payerObjId !=null and payerObjId != ''">
            and t.payer_obj_id= #{payerObjId}
        </if>
        <if test="state !=null and state != ''">
            and t.state= #{state}
        </if>
        <if test="feeFlag !=null and feeFlag != ''">
            and t.fee_flag= #{feeFlag}
        </if>
        <if test="configId !=null and configId != ''">
            and t.config_id= #{configId}
        </if>
        <if test="payerObjType !=null and payerObjType != ''">
            and t.payer_obj_type = #{payerObjType}
        </if>
    </insert>
 
    <!-- 查询费用信息 add by wuxw 2018-07-03 -->
    <select id="getFeeInfo" parameterType="Map" resultType="Map">
        select t.amount,t.income_obj_id,t.income_obj_id incomeObjId,t.fee_type_cd,t.fee_type_cd
        feeTypeCd,s.secondary_fee_type_cd_name,s.secondary_fee_type_cd_name secondaryFeeTypeCdName,t.start_time,t.start_time startTime,t.status_cd,t.status_cd statusCd,t.end_time,t.end_time
        endTime,t.community_id,t.community_id communityId,t.b_id,t.b_id bId,t.fee_id,t.fee_id feeId,t.user_id,t.user_id
        userId,t.payer_obj_id,t.payer_obj_id payerObjId,pfc.square_price squarePrice,pfc.additional_amount
        additionalAmount,t.fee_flag,t.fee_flag feeFlag,t.state,t.config_id,t.config_id configId,
        pfc.fee_name feeName,td1.name feeTypeCdName,td2.name stateName,td3.name feeFlagName,pfc.computing_formula
        computingFormula,pfc.computing_formula_text computingFormulaText,
        pfc.bill_type billType,t.payer_obj_type,t.payer_obj_type payerObjType,pfc.is_default isDefault,pfc.start_time
        configStartTime,pfc.end_time configEndTime,pfc.payment_cd paymentCd,pfc.payment_cycle paymentCycle,td4.name
        billTypeName,pfa.value importFeeName,ifd.end_time importFeeEndTime,mw.cur_degrees curDegrees,mw.pre_degrees
        preDegrees,
        mw.pre_reading_time preReadingTime,mw.cur_reading_time curReadingTime,pfa1.`value` deadlineTime,pfa1.`value`
        maxEndTime,mw.price
        mwPrice,
        pfa2.`value` ownerName,t.batch_id,t.batch_id batchId,
        pfc.pay_online payOnline,pfc.scale,pfc.decimal_place decimalPlace,pfc.units,pfc.prepayment_period
        prepaymentPeriod,
        pfrb.rule_id ruleId,pfrb.month_cycle monthCycle,t.is_contract_fee isContractFee,t.contract_fee contractFee
        from pay_fee t
        INNER join pay_fee_config pfc on t.config_id = pfc.config_id and
        pfc.status_cd = '0'
        left join t_dict td1 on pfc.fee_type_cd = td1.status_cd and td1.table_name = 'pay_fee_config' and
        td1.table_columns = 'fee_type_cd'
        left join t_dict td2 on t.state = td2.status_cd and td2.table_name = 'pay_fee' and td2.table_columns = 'state'
        left join t_dict td3 on t.fee_flag = td3.status_cd and td3.table_name = 'pay_fee' and td3.table_columns =
        'fee_flag'
        left join t_dict td4 on pfc.bill_type = td4.status_cd and td4.table_name = 'pay_fee_config' and
        td4.table_columns = 'bill_type'
        LEFT JOIN pay_fee_attrs pfa on t.fee_id = pfa.fee_id and pfa.spec_cd = '390002' and pfa.status_cd = '0'
        LEFT JOIN pay_fee_attrs pfa1 on t.fee_id = pfa1.fee_id and pfa1.spec_cd = '390010' and pfa1.status_cd = '0'
        LEFT JOIN pay_fee_attrs pfa2 on t.fee_id = pfa2.fee_id and pfa2.spec_cd = '390008' and pfa2.status_cd = '0'
        left join import_fee_detail ifd on t.fee_id = ifd.fee_id and ifd.status_cd = '0' and t.fee_flag = '2006012'
        LEFT JOIN meter_water mw on t.fee_id = mw.fee_id and mw.status_cd = '0' and mw.community_id = t.community_id
        LEFT JOIN pay_fee_rule_bill pfrb on t.fee_id = pfrb.fee_id and pfrb.status_cd = '0' and pfrb.community_id =
        t.community_id
        left join secondary_fee_type_cd_tb s on t.secondary_fee_type_cd = s.secondary_fee_type_cd
        <if test="ownerId != null and ownerId != ''">
            LEFT JOIN pay_fee_attrs pfao on t.fee_id = pfao.fee_id and pfao.spec_cd = '390007' and pfao.status_cd = '0'
        </if>
        where 1 =1
        <if test="amount !=null and amount != ''">
            and t.amount= #{amount}
        </if>
        <if test="ownerId !=null and ownerId != ''">
            and pfao.value= #{ownerId}
        </if>
        <if test="incomeObjId !=null and incomeObjId != ''">
            and t.income_obj_id= #{incomeObjId}
        </if>
          <if test="feeName != null and feeName != ''">
              and pfc.fee_name = #{feeName}
          </if>
        <if test="feeTypeCd !=null and feeTypeCd != ''">
            and t.fee_type_cd= #{feeTypeCd}
        </if>
        <if test="feeTypeCds != null ">
            and t.fee_type_cd in
            <foreach collection="feeTypeCds" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        <if test="startTime !=null ">
            and t.start_time= #{startTime}
        </if>
        <if test="statusCd !=null and statusCd != ''">
            and t.status_cd= #{statusCd}
        </if>
        <if test="endTime !=null ">
            and t.end_time= #{endTime}
        </if>
        <if test="arrearsEndTime != null">
            and t.end_time &lt; #{arrearsEndTime}
        </if>
        <if test="nowDate != null">
            and t.end_time &gt; #{nowDate}
        </if>
        <if test="communityId !=null and communityId != ''">
            and t.community_id= #{communityId}
            and pfc.community_id in (#{communityId},'9999')
        </if>
        <if test="bId !=null and bId != ''">
            and t.b_id= #{bId}
        </if>
        <if test="feeId !=null and feeId != ''">
            and t.fee_id= #{feeId}
        </if>
        <if test="payerObjId !=null and payerObjId != ''">
            and (t.payer_obj_id= #{payerObjId} or t.contract_fee = #{payerObjId})
        </if>
        <if test="payerObjIds != null and payerObjIds.length > 0">
            and t.payer_obj_id in
            <foreach collection="payerObjIds" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        <if test="state !=null and state != ''">
            and t.state= #{state}
        </if>
        <if test="feeFlag !=null and feeFlag != ''">
            and t.fee_flag= #{feeFlag}
        </if>
        <if test="configId !=null and configId != ''">
            and t.config_id= #{configId}
        </if>
        <if test="configIds != null and configIds.length > 0">
            and t.config_id in
            <foreach collection="configIds" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        <if test="payerObjType !=null and payerObjType != ''">
            and t.payer_obj_type = #{payerObjType}
        </if>
        <if test="deductFrom !=null and deductFrom != ''">
            and pfc.deduct_from = #{deductFrom}
        </if>
        <if test="curYear !=null and curYear != ''">
            and DATE_FORMAT(t.end_time,'%Y') = #{curYear}
        </if>
        <if test="contractFee != null">
            and t.contract_fee = ${contractFee}
        </if>
        <if test="useStart != null">
            and t.start_time &lt;= #{useStart}
        </if>
        <if test="useEnd != null">
            and DATE_ADD(STR_TO_DATE(pfa1.`value`, '%Y-%m-%d 23:59:59.%f'), INTERVAL 2 DAY) >= #{useEnd}
        </if>
        order by t.create_time desc
        <if test="page != -1 and page != null ">
            limit #{page}, #{row}
        </if>
    </select>
 
    <select id="getFeeInfoBus" resultType="Map" parameterType="Map">
        select count(1) count
        from pay_fee t
            INNER join pay_fee_config pfc on t.config_id = pfc.config_id and pfc.status_cd = '0'
            left join t_dict td1 on pfc.fee_type_cd = td1.status_cd and td1.table_name = 'pay_fee_config' and td1.table_columns = 'fee_type_cd'
            left join t_dict td2 on t.state = td2.status_cd and td2.table_name = 'pay_fee' and td2.table_columns = 'state'
            left join t_dict td3 on pfc.fee_flag = td3.status_cd and td3.table_name = 'pay_fee' and td3.table_columns = 'fee_flag'
            left join t_dict td4 on pfc.bill_type = td4.status_cd and td4.table_name = 'pay_fee_config' and td4.table_columns = 'bill_type'
            LEFT JOIN pay_fee_attrs pfa on t.fee_id = pfa.fee_id and pfa.spec_cd = '390002' and pfa.status_cd = '0'
            LEFT JOIN pay_fee_attrs pfa1 on t.fee_id = pfa1.fee_id and pfa1.spec_cd = '390010' and pfa1.status_cd = '0'
            LEFT JOIN pay_fee_attrs pfa2 on t.fee_id = pfa2.fee_id and pfa2.spec_cd = '390008' and pfa2.status_cd = '0'
            left join import_fee_detail ifd on t.fee_id = ifd.fee_id and ifd.status_cd = '0' and t.fee_flag = '2006012'
            LEFT JOIN meter_water mw on t.fee_id = mw.fee_id and mw.status_cd = '0' and mw.community_id = t.community_id
        where 1 = 1
        <if test="feeTypeCd != null and feeTypeCd != ''">
            and t.fee_type_cd = #{feeTypeCd}
        </if>
        <if test="startTime != null">  <!-- 修正原条件中的变量错误 -->
            and t.start_time = #{startTime}
        </if>
        <if test="statusCd != null and statusCd != ''">  <!-- 修正原条件中的变量错误 -->
            and t.status_cd = #{statusCd}
        </if>
        <if test="endTime != null">
            and STR_TO_DATE(pfa1.`value`, '%Y-%m-%d %H:%i:%s.%f') = #{endTime}
        </if>
        <if test="community_id != null and community_id != ''">  <!-- 修正原条件中的变量错误 -->
            and t.community_id = #{communityId}
            and pfc.community_id in (#{communityId}, '9999')
        </if>
        <if test="payerObjId != null and payerObjId != ''">  <!-- 修正原条件中的变量错误 -->
            and t.payer_obj_id = #{payerObjId}
        </if>
        <if test="isContractFee != null">
            and t.is_contract_fee = #{isContractFee}
        </if>
        <if test="isContractFee == null">
            and t.is_contract_fee IS NULL
        </if>
        <if test="contractFee != null">
            and t.contract_fee = ${contractFee}
        </if>
 
    </select>
 
    <!-- 修改费用信息 add by wuxw 2018-07-03 -->
    <update id="updateFeeInfoInstance" parameterType="Map">
        update pay_fee t set t.status_cd = #{statusCd}
        <if test="newBId != null and newBId != ''">
            ,t.b_id = #{newBId}
        </if>
        <if test="amount !=null and amount != ''">
            , t.amount= #{amount}
        </if>
        <if test="incomeObjId !=null and incomeObjId != ''">
            , t.income_obj_id= #{incomeObjId}
        </if>
        <if test="feeTypeCd !=null and feeTypeCd != ''">
            , t.fee_type_cd= #{feeTypeCd}
        </if>
        <if test="secondaryFeeTypeCd !=null and secondaryFeeTypeCd != ''">
            , t.secondary_fee_type_cd= #{secondaryFeeTypeCd}
        </if>
        <if test="startTime !=null ">
            , t.start_time= #{startTime}
        </if>
        <if test="endTime !=null">
            , t.end_time= #{endTime}
        </if>
        <if test="communityId !=null and communityId != ''">
            , t.community_id= #{communityId}
        </if>
        <if test="userId !=null and userId != ''">
            , t.user_id= #{userId}
        </if>
        <if test="payerObjId !=null and payerObjId != ''">
            , t.payer_obj_id= #{payerObjId}
        </if>
        <if test="state !=null and state != ''">
            , t.state= #{state}
        </if>
        <if test="feeFlag !=null and feeFlag != ''">
            , t.fee_flag= #{feeFlag}
        </if>
        <if test="isContractFee !=null and isContractFee != ''">
            , t.is_contract_fee = #{isContractFee}
        </if>
        where 1=1
        <if test="bId !=null and bId != ''">
            and t.b_id= #{bId}
        </if>
        <if test="feeId !=null and feeId != ''">
            and t.fee_id= #{feeId}
        </if>
        <if test="contractFee != null">
            and t.contract_fee = ${contractFee}
        </if>
    </update>
 
    <!-- 查询费用数量 add by wuxw 2018-07-03 -->
    <select id="queryFeesCount" parameterType="Map" resultType="Map">
        select count(1) count
        from pay_fee t
        INNER join pay_fee_config pfc on t.config_id = pfc.config_id and
        pfc.status_cd = '0'
        left join t_dict td1 on pfc.fee_type_cd = td1.status_cd and td1.table_name = 'pay_fee_config' and
        td1.table_columns = 'fee_type_cd'
        left join t_dict td2 on t.state = td2.status_cd and td2.table_name = 'pay_fee' and td2.table_columns = 'state'
        left join t_dict td3 on pfc.fee_flag = td3.status_cd and td3.table_name = 'pay_fee' and td3.table_columns =
        'fee_flag'
        left join t_dict td4 on pfc.bill_type = td4.status_cd and td4.table_name = 'pay_fee_config' and
        td4.table_columns = 'bill_type'
        LEFT JOIN pay_fee_attrs pfa on t.fee_id = pfa.fee_id and pfa.spec_cd = '390002' and pfa.status_cd = '0'
        LEFT JOIN pay_fee_attrs pfa1 on t.fee_id = pfa1.fee_id and pfa1.spec_cd = '390010' and pfa1.status_cd = '0'
        LEFT JOIN pay_fee_attrs pfa2 on t.fee_id = pfa2.fee_id and pfa2.spec_cd = '390008' and pfa2.status_cd = '0'
        left join import_fee_detail ifd on t.fee_id = ifd.fee_id and ifd.status_cd = '0' and t.fee_flag = '2006012'
        LEFT JOIN meter_water mw on t.fee_id = mw.fee_id and mw.status_cd = '0' and mw.community_id = t.community_id
        <if test="ownerId != null and ownerId != ''">
            LEFT JOIN pay_fee_attrs pfao on t.fee_id = pfao.fee_id and pfao.spec_cd = '390007' and pfao.status_cd = '0'
        </if>
        where 1 =1
        <if test="amount !=null and amount != ''">
            and t.amount= #{amount}
        </if>
        <if test="ownerId !=null and ownerId != ''">
            and pfao.value= #{ownerId}
        </if>
        <if test="incomeObjId !=null and incomeObjId != ''">
            and t.income_obj_id= #{incomeObjId}
        </if>
        <if test="feeTypeCd !=null and feeTypeCd != ''">
            and t.fee_type_cd= #{feeTypeCd}
        </if>
        <if test="feeTypeCds != null ">
            and t.fee_type_cd in
            <foreach collection="feeTypeCds" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        <if test="startTime !=null ">
            and t.start_time= #{startTime}
        </if>
        <if test="statusCd !=null and statusCd != ''">
            and t.status_cd= #{statusCd}
        </if>
        <if test="endTime !=null ">
            and t.end_time= #{endTime}
        </if>
        <if test="arrearsEndTime != null">
            and t.end_time &lt; #{arrearsEndTime}
        </if>
        <if test="nowDate != null">
            and t.end_time &gt; #{nowDate}
        </if>
        <if test="communityId !=null and communityId != ''">
            and t.community_id= #{communityId}
            and pfc.community_id in (#{communityId},'9999')
        </if>
 
        <if test="bId !=null and bId != ''">
            and t.b_id= #{bId}
        </if>
        <if test="feeId !=null and feeId != ''">
            and t.fee_id= #{feeId}
        </if>
        <if test="payerObjId !=null and payerObjId != ''">
            and t.payer_obj_id= #{payerObjId}
        </if>
        <if test="payerObjIds != null and payerObjIds.length > 0">
            and t.payer_obj_id in
            <foreach collection="payerObjIds" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        <if test="state !=null and state != ''">
            and t.state= #{state}
        </if>
        <if test="feeFlag !=null and feeFlag != ''">
            and t.fee_flag= #{feeFlag}
        </if>
        <if test="configId !=null and configId != ''">
            and t.config_id= #{configId}
        </if>
        <if test="payerObjType !=null and payerObjType != ''">
            and t.payer_obj_type = #{payerObjType}
        </if>
        <if test="deductFrom !=null and deductFrom != ''">
            and pfc.deduct_from = #{deductFrom}
        </if>
        <if test="contractFee != null">
            and t.contract_fee = ${contractFee}
        </if>
        <if test="curYear !=null and curYear != ''">
            and DATE_FORMAT(t.end_time,'%Y') = #{curYear}
        </if>
    </select>
 
    <!-- 查询账期 -->
    <select id="queryBills" parameterType="Map" resultType="Map">
        select
        t.bill_id billId,
        t.bill_name billName,
        t.receivable,
        t.cur_receivable curReceivable,
        t.receipts,
        t.bill_time billTime,
        t.community_id communityId,
        t.config_id configId,
        t.cur_bill curBill,
        td.name curBillName,
        c.fee_name feeName
        from bill t
        left join pay_fee_config c on t.config_id = c.config_id and c.community_id = t.community_id and c.status_cd =
        '0'
        left join t_dict td on td.table_name = 'bill' and td.table_columns = 'cur_bill' and t.cur_bill = td.status_cd
        where 1 = 1
        <if test="billId !=null and billId != ''">
            and t.bill_id= #{billId}
        </if>
        <if test="billName !=null and billName != ''">
            and t.bill_name like '%${billName}%'
        </if>
        <if test="receivable !=null and receivable != ''">
            and t.receivable= #{receivable}
        </if>
        <if test="receipts !=null">
            and t.receipts= #{receipts}
        </if>
        <if test="billTime !=null">
            and t.bill_time= #{billTime}
        </if>
        <if test="curBillTime !=null">
            and t.bill_time &gt; #{curBillTime}
        </if>
        <if test="communityId !=null and communityId != ''">
            and t.community_id= #{communityId}
        </if>
        <if test="configId != null and configId != ''">
            and t.config_id = #{configId}
        </if>
        <if test="curBill != null and curBill != ''">
            and t.cur_bill = #{curBill}
        </if>
        order by t.create_time desc
        <if test="page != -1 and page != null ">
            limit #{page}, #{row}
        </if>
    </select>
 
    <!-- 查询账期 -->
    <select id="queryBillCount" parameterType="Map" resultType="Map">
        select count(1) count
        from bill t
        left join pay_fee_config c on t.config_id = c.config_id and c.community_id = t.community_id and c.status_cd =
        '0'
        where 1 =1
        <if test="billId !=null and billId != ''">
            and t.bill_id= #{billId}
        </if>
        <if test="billName !=null and billName != ''">
            and t.bill_name like '%${billName}%'
        </if>
        <if test="receivable !=null and receivable != ''">
            and t.receivable= #{receivable}
        </if>
        <if test="curReceivable !=null and curReceivable != ''">
            and t.cur_receivable= #{curReceivable}
        </if>
        <if test="receipts !=null">
            and t.receipts= #{receipts}
        </if>
        <if test="billTime !=null">
            and t.bill_time= #{billTime}
        </if>
        <if test="communityId !=null and communityId != ''">
            and t.community_id= #{communityId}
        </if>
        <if test="configId != null and configId != ''">
            and t.config_id = #{configId}
        </if>
        <if test="curBill != null and curBill != ''">
            and t.cur_bill = #{curBill}
        </if>
    </select>
 
    <!-- 查询账期 -->
    <select id="queryBillOweFees" parameterType="Map" resultType="Map">
        select
        t.owe_id oweId,
        t.bill_id billId,
        t.fee_id feeId,
        t.bill_amount_owed billAmountOwed,
        t.amount_owed amountOwed,
        t.fee_end_time feeEndTime,
        t.owner_id ownerId,
        t.owner_name ownerName,
        t.owner_tel ownerTel,
        t.payer_obj_name payerObjName,
        t.payer_obj_type payerObjType,
        t.community_id communityId,
        t.state,
        t.create_time createTime,
        t.deadline_time deadlineTime,
        pf.payer_obj_id payObjId,
        td.name feeTypeName,
        td2.name stateName
        from bill_owe_fee t
        <if test="curBill !=null and curBill != ''">
            inner join bill b on t.bill_id = b.bill_id and b.community_id = t.community_id and b.cur_bill = #{curBill}
        </if>
        left join pay_fee pf on t.fee_id = pf.fee_id and t.community_id = pf.community_id and pf.status_cd = '0'
        left join t_dict td on pf.fee_type_cd = td.status_cd and td.table_name = 'pay_fee_config' and td.table_columns =
        'fee_type_cd'
        left join t_dict td2 on t.state = td2.status_cd and td2.table_name = 'bill_owe_fee' and td2.table_columns =
        'state'
        where 1 = 1
        <if test="oweId !=null and oweId != ''">
            and t.owe_id= #{oweId}
        </if>
        <if test="billId !=null and billId != ''">
            and t.bill_id= #{billId}
        </if>
        <if test="feeId !=null and feeId != ''">
            and t.fee_id= #{feeId}
        </if>
        <if test="billAmountOwed !=null and billAmountOwed != ''">
            and t.bill_amount_owed= #{billAmountOwed}
        </if>
        <if test="amountOwed !=null and amountOwed != ''">
            and t.amount_owed= #{amountOwed}
        </if>
        <if test="feeEndTime != null">
            and t.fee_end_time = #{feeEndTime}
        </if>
        <if test="ownerId != null and ownerId != ''">
            and t.owner_id = #{ownerId}
        </if>
        <if test="ownerIds !=null">
            and t.owner_id in
            <foreach collection="ownerIds" open="(" close=")"
                     separator="," item="item">
                #{item}
            </foreach>
        </if>
        <if test="ownerName != null and ownerName != ''">
            and t.owner_name like '%${ownerName}%'
        </if>
        <if test="communityId !=null and communityId != ''">
            and t.community_id= #{communityId}
        </if>
        <if test="state !=null and state != ''">
            and t.state= #{state}
        </if>
        order by t.create_time desc
        <if test="page != -1 and page != null ">
            limit #{page}, #{row}
        </if>
    </select>
 
    <!-- 查询账期 -->
    <select id="queryBillOweFeeCount" parameterType="Map" resultType="Map">
        select count(1) count
        from bill_owe_fee t
        where 1 =1
        <if test="oweId !=null and oweId != ''">
            and t.owe_id= #{oweId}
        </if>
        <if test="billId !=null and billId != ''">
            and t.bill_id= #{billId}
        </if>
        <if test="feeId !=null and feeId != ''">
            and t.fee_id= #{feeId}
        </if>
        <if test="billAmountOwed !=null and billAmountOwed != ''">
            and t.bill_amount_owed= #{billAmountOwed}
        </if>
        <if test="amountOwed !=null and amountOwed != ''">
            and t.amount_owed= #{amountOwed}
        </if>
        <if test="feeEndTime != null">
            and t.fee_end_time = #{feeEndTime}
        </if>
        <if test="ownerId != null and ownerId != ''">
            and t.owner_id = #{ownerId}
        </if>
        <if test="ownerName != null and ownerName != ''">
            and t.owner_name like '%${ownerName}%'
        </if>
        <if test="communityId !=null and communityId != ''">
            and t.community_id= #{communityId}
        </if>
        <if test="state !=null and state != ''">
            and t.state= #{state}
        </if>
    </select>
 
    <insert id="insertBillOweFees" parameterType="Map">
        INSERT INTO bill_owe_fee
        (`owe_id`, `bill_id`, `fee_id`, `bill_amount_owed`, `amount_owed`, `fee_end_time`, `owner_id`, `owner_name`,
         `owner_tel`, `payer_obj_name`, `payer_obj_type`, `community_id`, `state`, deadline_time)
        VALUES (#{oweId}, #{billId}, #{feeId}, #{billAmountOwed}, #{amountOwed}, #{feeEndTime}, #{ownerId},
                #{ownerName},
                #{ownerTel}, #{payerObjName}, #{payerObjType}, #{communityId}, #{state}, #{deadlineTime})
    </insert>
 
    <update id="updateBillOweFees" parameterType="Map">
        update bill_owe_fee t
        set t.state = #{state}
        where t.fee_id = #{feeId}
          and t.community_id = #{communityId}
          and t.bill_id = #{billId}
    </update>
 
    <insert id="insertBill" parameterType="Map">
        INSERT INTO bill (`bill_id`, `bill_name`, `receivable`, `receipts`, `bill_time`, `community_id`, `config_id`,
                          `remark`, `cur_bill`, `cur_receivable`)
        VALUES (#{billId}, #{billName}, #{receivable}, #{receipts}, #{billTime}, #{communityId}, #{configId},
                #{remark}, #{curBill}, #{curReceivable})
    </insert>
 
    <update id="updateBill" parameterType="Map">
        update bill
        set cur_bill= 'F'
        where config_id = #{configId}
    </update>
 
    <!-- 查询费用数量 add by wuxw 2018-07-03 -->
    <select id="queryFeeByAttrCount" parameterType="Map" resultType="Map">
        select count(1) count
        from pay_fee t
        left join pay_fee_config pfc on t.fee_type_cd = pfc.fee_type_cd and t.config_id = pfc.config_id and
        pfc.status_cd = '0'
        left join t_dict td1 on pfc.fee_type_cd = td1.status_cd and td1.table_columns = 'fee_type_cd' and td1.table_name
        = 'pay_fee_config'
        left join t_dict td2 on t.state = td2.status_cd and td2.table_name = 'pay_fee' and td2.table_columns = 'state'
        left join t_dict td3 on t.fee_flag = td3.status_cd and td3.table_name = 'pay_fee' and td3.table_columns =
        'fee_flag'
        left join pay_fee_attrs pfa on t.fee_id = pfa.fee_id and pfa.status_cd='0'
        where pfa.spec_cd = #{specCd}
        and pfa.value = #{value}
        <if test="amount !=null and amount != ''">
            and t.amount= #{amount}
        </if>
        <if test="incomeObjId !=null and incomeObjId != ''">
            and t.income_obj_id= #{incomeObjId}
        </if>
        <if test="feeTypeCd !=null and feeTypeCd != ''">
            and t.fee_type_cd= #{feeTypeCd}
        </if>
        <if test="feeTypeCds != null ">
            and t.fee_type_cd in
            <foreach collection="feeTypeCds" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        <if test="startTime !=null">
            and t.start_time= #{startTime}
        </if>
        <if test="statusCd !=null and statusCd != ''">
            and t.status_cd= #{statusCd}
        </if>
        <if test="endTime !=null ">
            and t.end_time= #{endTime}
        </if>
        <if test="arrearsEndTime != null">
            and t.end_time &lt; #{arrearsEndTime}
        </if>
        <if test="noArrearsEndTime != null">
            and t.end_time &gt; #{noArrearsEndTime}
        </if>
        <if test="communityId !=null and communityId != ''">
            and t.community_id= #{communityId}
            and pfc.community_id= #{communityId}
        </if>
        <if test="bId !=null and bId != ''">
            and t.b_id= #{bId}
        </if>
        <if test="feeId !=null and feeId != ''">
            and t.fee_id= #{feeId}
        </if>
        <if test="payerObjId !=null and payerObjId != ''">
            and t.payer_obj_id= #{payerObjId}
        </if>
        <if test="payerObjIds != null ">
            and t.payer_obj_id in
            <foreach collection="payerObjIds" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        <if test="state !=null and state != ''">
            and t.state= #{state}
        </if>
        <if test="feeFlag !=null and feeFlag != ''">
            and t.fee_flag= #{feeFlag}
        </if>
        <if test="configId !=null and configId != ''">
            and t.config_id= #{configId}
        </if>
        <if test="payerObjType !=null and payerObjType != ''">
            and t.payer_obj_type = #{payerObjType}
        </if>
        <if test="contractFee != null">
            and t.contract_fee = ${contractFee}
        </if>
    </select>
 
    <!-- 查询费用信息 add by wuxw 2018-07-03 -->
    <select id="queryFeeByAttr" parameterType="Map" resultType="Map">
        select t.amount,t.income_obj_id,t.income_obj_id incomeObjId,t.fee_type_cd,t.fee_type_cd
        feeTypeCd,s.secondary_fee_type_cd_name,s.secondary_fee_type_cd_name secondaryFeeTypeCdName,t.start_time,t.start_time startTime,t.status_cd,t.status_cd statusCd,t.end_time,t.end_time
        endTime,t.community_id,t.community_id communityId,t.b_id,t.b_id bId,t.fee_id,t.fee_id feeId,t.user_id,t.user_id
        userId,t.payer_obj_id,t.payer_obj_id payerObjId,pfc.square_price squarePrice,pfc.additional_amount
        additionalAmount,t.fee_flag,t.fee_flag feeFlag,t.state,t.config_id,t.config_id configId,
        pfc.fee_name feeName,td1.name feeTypeCdName,td2.name stateName,td3.name feeFlagName,pfc.computing_formula
        computingFormula,pfc.computing_formula_text computingFormulaText,
        t.payer_obj_type,t.payer_obj_type payerObjType,pfc.is_default isDefault,pfc.start_time
        configStartTime,pfc.end_time configEndTime,pfc.payment_cd paymentCd,pfc.payment_cycle paymentCycle
        from pay_fee t
        left join pay_fee_config pfc on t.fee_type_cd = pfc.fee_type_cd and t.config_id = pfc.config_id and
        pfc.status_cd = '0'
        left join t_dict td1 on pfc.fee_type_cd = td1.status_cd and td1.table_columns = 'fee_type_cd' and td1.table_name
        = 'pay_fee_config'
        left join t_dict td2 on t.state = td2.status_cd and td2.table_name = 'pay_fee' and td2.table_columns = 'state'
        left join t_dict td3 on t.fee_flag = td3.status_cd and td3.table_name = 'pay_fee' and td3.table_columns =
        'fee_flag'
        left join pay_fee_attrs pfa on t.fee_id = pfa.fee_id and pfa.status_cd='0'
        left join secondary_fee_type_cd_tb s on t.secondary_fee_type_cd = s.secondary_fee_type_cd
        where pfa.spec_cd = #{specCd}
        and pfa.value = #{value}
        <if test="amount !=null and amount != ''">
            and t.amount= #{amount}
        </if>
        <if test="incomeObjId !=null and incomeObjId != ''">
            and t.income_obj_id= #{incomeObjId}
        </if>
        <if test="feeTypeCd !=null and feeTypeCd != ''">
            and t.fee_type_cd= #{feeTypeCd}
        </if>
        <if test="feeTypeCds != null ">
            and t.fee_type_cd in
            <foreach collection="feeTypeCds" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        <if test="startTime !=null ">
            and t.start_time= #{startTime}
        </if>
        <if test="statusCd !=null and statusCd != ''">
            and t.status_cd= #{statusCd}
        </if>
        <if test="endTime !=null ">
            and t.end_time= #{endTime}
        </if>
        <if test="arrearsEndTime != null">
            and t.end_time &lt; #{arrearsEndTime}
        </if>
        <if test="communityId !=null and communityId != ''">
            and t.community_id= #{communityId}
            and pfc.community_id= #{communityId}
        </if>
        <if test="bId !=null and bId != ''">
            and t.b_id= #{bId}
        </if>
        <if test="feeId !=null and feeId != ''">
            and t.fee_id= #{feeId}
        </if>
        <if test="payerObjId !=null and payerObjId != ''">
            and t.payer_obj_id= #{payerObjId}
        </if>
        <if test="payerObjIds != null ">
            and t.payer_obj_id in
            <foreach collection="payerObjIds" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        <if test="state !=null and state != ''">
            and t.state= #{state}
        </if>
        <if test="feeFlag !=null and feeFlag != ''">
            and t.fee_flag= #{feeFlag}
        </if>
        <if test="configId !=null and configId != ''">
            and t.config_id= #{configId}
        </if>
        <if test="payerObjType !=null and payerObjType != ''">
            and t.payer_obj_type = #{payerObjType}
        </if>
        order by t.create_time desc
        <if test="page != -1 and page != null ">
            limit #{page}, #{row}
        </if>
    </select>
 
    <!-- 批量插入费用 -->
    <insert id="insertFees" parameterType="Map">
        insert into pay_fee (amount,status_cd,income_obj_id,fee_type_cd,secondary_fee_type_cd,start_time,end_time,community_id,b_id,fee_id,
        user_id,payer_obj_id,fee_flag,state,config_id,payer_obj_type,batch_id,is_contract_fee,contract_fee,create_time)
        VALUES
        <foreach collection="payFeePos" item="item" separator=",">
            (#{item.amount},'0',#{item.incomeObjId},#{item.feeTypeCd},#{item.secondaryFeeTypeCd},#{item.startTime},#{item.endTime},#{item.communityId},
            '-1',#{item.feeId},#{item.userId},#{item.payerObjId},#{item.feeFlag},#{item.state},#{item.configId},#{item.payerObjType},#{item.batchId},#{item.isContractFee},#{item.contractFee}
 
            <if test="item.createTime != null and item.createTime != ''">
                ,#{item.createTime}
            </if>
            <if test="item.createTime == null or item.createTime == ''">
                ,now()
            </if>
            )
        </foreach>
    </insert>
 
    <select id="computeBillOweFeeCount" parameterType="Map" resultType="Map">
        select count(1) count
        from pay_fee pf
        INNER JOIN pay_fee_config pfc on pf.config_id = pfc.config_id and pfc.bill_type in ('001','002','003') and
        pfc.status_cd = '0' and pf.community_id = pfc.community_id
        inner join bill_owe_fee bof on pf.fee_id = bof.fee_id and bof.community_id = pf.community_id and bof.state
        ='1000' and bof.amount_owed &gt; 0
        inner join bill b on bof.bill_id = b.bill_id and b.community_id = bof.community_id and b.cur_bill = 'T'
        where pf.status_cd = '0'
        and pf.state = '2008001'
        and pf.community_id = #{communityId}
        <if test="payerObjId !=null and payerObjId != ''">
            and pf.payer_obj_id= #{payerObjId}
        </if>
        <if test="payerObjType !=null and payerObjType != ''">
            and pf.payer_obj_type = #{payerObjType}
        </if>
    </select>
 
    <select id="computeBillOweFee" parameterType="Map" resultType="Map">
        select pfc.fee_name feeName,pf.fee_id feeId,pf.end_time endTime,bof.amount_owed amountOwed,bof.payer_obj_name
        roomName,bof.owner_name ownerName,bof.owner_tel ownerTel,pf.payer_obj_id payerObjId,pf.payer_obj_type
        payerObjType,
        pf.community_id communityId
        from pay_fee pf
        INNER JOIN pay_fee_config pfc on pf.config_id = pfc.config_id and pfc.bill_type in ('001','002','003') and
        pfc.status_cd = '0' and pf.community_id = pfc.community_id
        inner join bill_owe_fee bof on pf.fee_id = bof.fee_id and bof.community_id = pf.community_id and bof.state
        ='1000' and bof.amount_owed &gt; 0
        inner join bill b on bof.bill_id = b.bill_id and b.community_id = bof.community_id and b.cur_bill = 'T'
        where pf.status_cd = '0'
        and pf.state = '2008001'
        and pf.community_id = #{communityId}
        <if test="payerObjId !=null and payerObjId != ''">
            and pf.payer_obj_id= #{payerObjId}
        </if>
        <if test="payerObjType !=null and payerObjType != ''">
            and pf.payer_obj_type = #{payerObjType}
        </if>
        <if test="page != -1 and page != null ">
            limit #{page}, #{row}
        </if>
    </select>
 
    <select id="computeEveryOweFeeCount" parameterType="Map" resultType="Map">
        select count(1) count
        from pay_fee pf
        INNER JOIN pay_fee_config pfc on pf.config_id = pfc.config_id and pfc.bill_type = '004' and pfc.status_cd = '0'
        and pf.community_id = pfc.community_id
        where pf.end_time &lt; NOW()
        and pf.status_cd = '0'
        and pf.state = '2008001'
        and pf.community_id = #{communityId}
        <if test="payerObjId !=null and payerObjId != ''">
            and pf.payer_obj_id= #{payerObjId}
        </if>
        <if test="payerObjType !=null and payerObjType != ''">
            and pf.payer_obj_type = #{payerObjType}
        </if>
    </select>
 
    <select id="computeEveryOweFee" parameterType="Map" resultType="Map">
        select pfc.fee_name feeName,pf.fee_id feeId,pf.end_time endTime,pf.payer_obj_id payerObjId,pf.payer_obj_type
        payerObjType,
        pf.community_id communityId,pfc.computing_formula computingFormula,pfc.computing_formula_text
        computingFormulaText,
        pfc.square_price
        squarePrice,pfc.additional_amount additionalAmount
        from pay_fee pf
        INNER JOIN pay_fee_config pfc on pf.config_id = pfc.config_id and pfc.bill_type = '004' and pfc.status_cd = '0'
        and pf.community_id = pfc.community_id
        where pf.end_time &lt; NOW()
        and pf.status_cd = '0'
        and pf.state = '2008001'
        and pf.community_id = #{communityId}
        <if test="payerObjId !=null and payerObjId != ''">
            and pf.payer_obj_id= #{payerObjId}
        </if>
        <if test="payerObjType !=null and payerObjType != ''">
            and pf.payer_obj_type = #{payerObjType}
        </if>
        <if test="page != -1 and page != null ">
            limit #{page}, #{row}
        </if>
    </select>
 
    <!-- 根据批次删除费用 add by wuxw 2018-07-03 -->
    <update id="deleteFeesByBatch" parameterType="Map">
        update pay_fee t
        set t.status_cd = '1'
        where 1 = 1
          and t.batch_id = #{batchId}
          and t.community_id = #{communityId}
    </update>
 
    <select id="countValidPayFeeByConfigId" parameterType="Map" resultType="Map">
        select count(1) count from pay_fee where config_id = #{configId} and status_cd = 0
    </select>
</mapper>