wujianwei
7 天以前 156a530f070f41dabb89cd5934e581d83fb384c3
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
<?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.ruoyi.cwgl.mapper.ReceivableBillManagementMapper">
 
    <resultMap type="com.ruoyi.cwgl.domain.ReceivableBillManagement" id="ReceivableBillManagementResult">
        <result property="id"    column="id"    />
        <result property="systemNo"    column="system_no"    />
        <result property="billName"    column="bill_name"    />
        <result property="customerName"    column="customer_name"    />
        <result property="payee"    column="payee"    />
        <result property="responsiblePerson"    column="responsible_person"    />
        <result property="responsibleLeader"    column="responsible_leader"    />
        <result property="settlementMethod"    column="settlement_method"    />
        <result property="businessType"    column="business_type"    />
        <result property="promotionRequirement"    column="promotion_requirement"    />
        <result property="isInternalSettlement"    column="is_internal_settlement"    />
        <result property="internalSettlementUnit"    column="internal_settlement_unit"    />
        <result property="documentCount"    column="document_count"    />
        <result property="totalAmount"    column="total_amount"    />
        <result property="currency"    column="currency"    />
        <result property="discountAmount"    column="discount_amount"    />
        <result property="receivedAmount"    column="received_amount"    />
        <result property="pendingAmount"    column="pending_amount"    />
        <result property="exchangeRate"    column="exchange_rate"    />
        <result property="cnyAmount"    column="cny_amount"    />
        <result property="periodType"    column="period_type"    />
        <result property="businessStartDate"    column="business_start_date"    />
        <result property="businessEndDate"    column="business_end_date"    />
        <result property="billingStartDate"    column="billing_start_date"    />
        <result property="billingEndDate"    column="billing_end_date"    />
        <result property="billGenerateDate"    column="bill_generate_date"    />
        <result property="billSendDate"    column="bill_send_date"    />
        <result property="billDueDate"    column="bill_due_date"    />
        <result property="settlementCategory"    column="settlement_category"    />
        <result property="settlementPeriod"    column="settlement_period"    />
        <result property="ncSettlementDate"    column="nc_settlement_date"    />
        <result property="ncSettlementAmount"    column="nc_settlement_amount"    />
        <result property="accountRemark"    column="account_remark"    />
        <result property="overdueInterest"    column="overdue_interest"    />
        <result property="status"    column="status"    />
        <result property="auditStatus"    column="audit_status"    />
        <result property="remark"    column="remark"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="deleted"    column="deleted"    />
    </resultMap>
 
    <resultMap type="com.ruoyi.cwgl.domain.vo.ReceivableBillAgingAnalysisVo" id="ReceivableBillAgingAnalysisVoResult">
        <result property="id"    column="id"    />
        <result property="systemNo"    column="system_no"    />
        <result property="billName"    column="bill_name"    />
        <result property="customerName"    column="customer_name"    />
 
        <result property="responsiblePerson"    column="responsible_person"    />
        <result property="responsibleLeader"    column="responsible_leader"    />
        <result property="settlementMethod"    column="settlement_method"    />
        <result property="businessType"    column="business_type"    />
        <result property="promotionRequirement"    column="promotion_requirement"    />
        <result property="totalAmount"    column="total_amount"    />
        <result property="currency"    column="currency"    />
        <result property="receivedAmount"    column="received_amount"    />
        <result property="pendingAmount"    column="pending_amount"    />
 
 
        <result property="billingStartDate"    column="billing_start_date"    />
        <result property="billingEndDate"    column="billing_end_date"    />
 
        <result property="billDueDate"    column="bill_due_date"    />
 
        <result property="dueIn30Days"    column="due_in_30_days"    />
 
        <result property="overdue1To30Days"    column="overdue_1_to_30_days"    />
        <result property="overdue31To60Days"    column="overdue_31_to_60_days"    />
        <result property="overdue61To90Days"    column="overdue_61_to_90_days"    />
        <result property="overdue91To180Days"    column="overdue_91_to_180_days"    />
        <result property="overdue181To365Days"    column="overdue_181_to_365_days"    />
        <result property="overdueOver1Year"    column="overdue_over_1_year"    />
        <result property="overdueDays"    column="overdue_days"    />
    </resultMap>
 
    <sql id="selectReceivableBillManagementVo">
        select thisTab.id, thisTab.system_no, thisTab.bill_name, thisTab.customer_name, thisTab.payee, thisTab.responsible_person, thisTab.responsible_leader, thisTab.settlement_method, thisTab.business_type, thisTab.promotion_requirement, thisTab.is_internal_settlement, thisTab.internal_settlement_unit, thisTab.document_count, thisTab.total_amount, thisTab.currency, thisTab.discount_amount, thisTab.received_amount, thisTab.pending_amount, thisTab.exchange_rate, thisTab.cny_amount, thisTab.period_type, thisTab.business_start_date, thisTab.business_end_date, thisTab.billing_start_date, thisTab.billing_end_date, thisTab.bill_generate_date, thisTab.bill_send_date, thisTab.bill_due_date, thisTab.due_in_30_days, thisTab.overdue_amount, thisTab.overdue_1_to_30_days, thisTab.overdue_31_to_60_days, thisTab.overdue_61_to_90_days, thisTab.overdue_91_to_180_days, thisTab.overdue_181_to_365_days, thisTab.overdue_over_1_year, thisTab.overdue_days, thisTab.settlement_category, thisTab.settlement_period, thisTab.nc_settlement_date, thisTab.nc_settlement_amount, thisTab.account_remark, thisTab.overdue_interest, thisTab.status, thisTab.audit_status, thisTab.remark, thisTab.create_by, thisTab.create_time, thisTab.update_by, thisTab.update_time, thisTab.deleted from receivable_bill_management AS thisTab
    </sql>
    <sql id="selectReceivableBillManagementVoCount">
        select count(0) from receivable_bill_management as thisTab
    </sql>
 
    <sql id="whereCondition">
        <if test="systemNo != null  and systemNo != ''"> and thisTab.system_no = #{systemNo}</if>
        <if test="billName != null  and billName != ''"> and  thisTab.bill_name like concat('%', #{billName}, '%')</if>
        <if test="customerName != null  and customerName != ''"> and  thisTab.customer_name like concat('%', #{customerName}, '%')</if>
        <if test="payee != null  and payee != ''"> and  thisTab.payee like concat('%', #{payee}, '%')</if>
        <if test="responsiblePerson != null  and responsiblePerson != ''"> and  thisTab.responsible_person like concat('%', #{responsiblePerson}, '%')</if>
        <if test="responsibleLeader != null  and responsibleLeader != ''"> and  thisTab.responsible_leader like concat('%', #{responsibleLeader}, '%')</if>
        <if test="settlementMethod != null  and settlementMethod != ''"> and thisTab.settlement_method = #{settlementMethod}</if>
        <if test="businessType != null  and businessType != ''"> and thisTab.business_type = #{businessType}</if>
        <if test="promotionRequirement != null  and promotionRequirement != ''"> and thisTab.promotion_requirement like concat('%', #{promotionRequirement}, '%')</if>
        <if test="isInternalSettlement != null  and isInternalSettlement != ''"> and thisTab.is_internal_settlement = #{isInternalSettlement}</if>
        <if test="internalSettlementUnit != null  and internalSettlementUnit != ''"> and thisTab.internal_settlement_unit = #{internalSettlementUnit}</if>
        <if test="documentCount != null "> and thisTab.document_count = #{documentCount}</if>
        <if test="totalAmount != null "> and thisTab.total_amount = #{totalAmount}</if>
        <if test="currency != null  and currency != ''"> and thisTab.currency = #{currency}</if>
        <if test="discountAmount != null "> and thisTab.discount_amount = #{discountAmount}</if>
        <if test="receivedAmount != null "> and thisTab.received_amount = #{receivedAmount}</if>
        <if test="pendingAmount != null "> and thisTab.pending_amount = #{pendingAmount}</if>
        <if test="exchangeRate != null "> and thisTab.exchange_rate = #{exchangeRate}</if>
        <if test="cnyAmount != null "> and thisTab.cny_amount = #{cnyAmount}</if>
        <if test="periodType != null  and periodType != ''"> and thisTab.period_type = #{periodType}</if>
        <if test="businessStartDate != null "> and thisTab.business_start_date = #{businessStartDate}</if>
        <if test="businessEndDate != null "> and thisTab.business_end_date = #{businessEndDate}</if>
        <if test="billingStartDate != null "> and thisTab.billing_start_date = #{billingStartDate}</if>
        <if test="billingEndDate != null "> and thisTab.billing_end_date = #{billingEndDate}</if>
        <if test="billGenerateDate != null "> and thisTab.bill_generate_date = #{billGenerateDate}</if>
        <if test="billSendDate != null "> and thisTab.bill_send_date = #{billSendDate}</if>
        <if test="billDueDate != null "> and thisTab.bill_due_date = #{billDueDate}</if>
        <if test="settlementCategory != null  and settlementCategory != ''"> and thisTab.settlement_category = #{settlementCategory}</if>
        <if test="settlementPeriod != null  and settlementPeriod != ''"> and thisTab.settlement_period = #{settlementPeriod}</if>
        <if test="ncSettlementDate != null "> and thisTab.nc_settlement_date = #{ncSettlementDate}</if>
        <if test="ncSettlementAmount != null "> and thisTab.nc_settlement_amount = #{ncSettlementAmount}</if>
        <if test="accountRemark != null  and accountRemark != ''"> and thisTab.account_remark like concat('%', #{accountRemark}, '%')</if>
        <if test="overdueInterest != null "> and thisTab.overdue_interest = #{overdueInterest}</if>
        <if test="status != null and status != ''">
            <choose>
                <when test="status == -1">
                    and thisTab.status in (0, 1)
                </when>
                <when test="status > 0">
                    and thisTab.status = #{status}
                </when>
            </choose>
        </if>
        <if test="deleted != null "> and thisTab.deleted = #{deleted}</if>
    </sql>
 
    <!--查询-->
    <select id="selectReceivableBillManagementById" parameterType="Integer" resultMap="ReceivableBillManagementResult">
        <include refid="selectReceivableBillManagementVo"/>
        where id = #{id}
    </select>
 
    <select id="selectReceivableBillManagementCount" parameterType="com.ruoyi.cwgl.domain.ReceivableBillManagement" resultType="int">
        <include refid="selectReceivableBillManagementVoCount"/>
        <where>
            <include refid="whereCondition"/>
        </where>
    </select>
 
    <select id="selectReceivableBillManagementList" parameterType="com.ruoyi.cwgl.domain.ReceivableBillManagement" resultMap="ReceivableBillManagementResult">
        <include refid="selectReceivableBillManagementVo"/>
        <where>
            <include refid="whereCondition"/>
        </where>
        order by thisTab.id desc
    </select>
 
    <select id="selectReceivableBillManagementBySystemNo" parameterType="String" resultMap="ReceivableBillManagementResult">
        <include refid="selectReceivableBillManagementVo"/>
        where system_no = #{systemNo}
    </select>
 
    <!-- 新增 -->
    <insert id="insertReceivableBillManagement" parameterType="com.ruoyi.cwgl.domain.ReceivableBillManagement"  useGeneratedKeys="true" keyProperty="id">
        insert into receivable_bill_management
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="systemNo != null and systemNo != ''">system_no,</if>
            <if test="billName != null and billName != ''">bill_name,</if>
            <if test="customerName != null and customerName != ''">customer_name,</if>
            <if test="payee != null and payee != ''">payee,</if>
            <if test="responsiblePerson != null and responsiblePerson != ''">responsible_person,</if>
            <if test="responsibleLeader != null and responsibleLeader != ''">responsible_leader,</if>
            <if test="settlementMethod != null and settlementMethod != ''">settlement_method,</if>
            <if test="businessType != null and businessType != ''">business_type,</if>
            <if test="promotionRequirement != null and promotionRequirement != ''">promotion_requirement,</if>
            <if test="isInternalSettlement != null and isInternalSettlement != ''">is_internal_settlement,</if>
            <if test="internalSettlementUnit != null">internal_settlement_unit,</if>
            <if test="documentCount != null">document_count,</if>
            <if test="totalAmount != null">total_amount,</if>
            <if test="currency != null">currency,</if>
            <if test="discountAmount != null">discount_amount,</if>
            <if test="receivedAmount != null">received_amount,</if>
            <if test="pendingAmount != null">pending_amount,</if>
            <if test="exchangeRate != null">exchange_rate,</if>
            <if test="cnyAmount != null">cny_amount,</if>
            <if test="periodType != null and periodType != ''">period_type,</if>
            <if test="businessStartDate != null">business_start_date,</if>
            <if test="businessEndDate != null">business_end_date,</if>
            <if test="billingStartDate != null">billing_start_date,</if>
            <if test="billingEndDate != null">billing_end_date,</if>
            <if test="billGenerateDate != null">bill_generate_date,</if>
            <if test="billSendDate != null">bill_send_date,</if>
            <if test="billDueDate != null">bill_due_date,</if>
            <if test="settlementCategory != null and settlementCategory != ''">settlement_category,</if>
            <if test="settlementPeriod != null and settlementPeriod != ''">settlement_period,</if>
            <if test="ncSettlementDate != null">nc_settlement_date,</if>
            <if test="ncSettlementAmount != null">nc_settlement_amount,</if>
            <if test="accountRemark != null and accountRemark != ''">account_remark,</if>
            <if test="overdueInterest != null">overdue_interest,</if>
            <if test="status != null">status,</if>
            <if test="auditStatus != null">audit_status,</if>
            <if test="remark != null">remark,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="deleted != null">deleted,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="systemNo != null and systemNo != ''">#{systemNo},</if>
            <if test="billName != null and billName != ''">#{billName},</if>
            <if test="customerName != null and customerName != ''">#{customerName},</if>
            <if test="payee != null and payee != ''">#{payee},</if>
            <if test="responsiblePerson != null and responsiblePerson != ''">#{responsiblePerson},</if>
            <if test="responsibleLeader != null and responsibleLeader != ''">#{responsibleLeader},</if>
            <if test="settlementMethod != null and settlementMethod != ''">#{settlementMethod},</if>
            <if test="businessType != null and businessType != ''">#{businessType},</if>
            <if test="promotionRequirement != null and promotionRequirement != ''">#{promotionRequirement},</if>
            <if test="isInternalSettlement != null and isInternalSettlement != ''">#{isInternalSettlement},</if>
            <if test="internalSettlementUnit != null">#{internalSettlementUnit},</if>
            <if test="documentCount != null">#{documentCount},</if>
            <if test="totalAmount != null">#{totalAmount},</if>
            <if test="currency != null">#{currency},</if>
            <if test="discountAmount != null">#{discountAmount},</if>
            <if test="receivedAmount != null">#{receivedAmount},</if>
            <if test="pendingAmount != null">#{pendingAmount},</if>
            <if test="exchangeRate != null">#{exchangeRate},</if>
            <if test="cnyAmount != null">#{cnyAmount},</if>
            <if test="periodType != null and periodType != ''">#{periodType},</if>
            <if test="businessStartDate != null">#{businessStartDate},</if>
            <if test="businessEndDate != null">#{businessEndDate},</if>
            <if test="billingStartDate != null">#{billingStartDate},</if>
            <if test="billingEndDate != null">#{billingEndDate},</if>
            <if test="billGenerateDate != null">#{billGenerateDate},</if>
            <if test="billSendDate != null">#{billSendDate},</if>
            <if test="billDueDate != null">#{billDueDate},</if>
            <if test="settlementCategory != null and settlementCategory != ''">#{settlementCategory},</if>
            <if test="settlementPeriod != null and settlementPeriod != ''">#{settlementPeriod},</if>
            <if test="ncSettlementDate != null">#{ncSettlementDate},</if>
            <if test="ncSettlementAmount != null">#{ncSettlementAmount},</if>
            <if test="accountRemark != null and accountRemark != ''">#{accountRemark},</if>
            <if test="overdueInterest != null">#{overdueInterest},</if>
            <if test="status != null">#{status},</if>
            <if test="auditStatus != null">#{auditStatus},</if>
            <if test="remark != null">#{remark},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="deleted != null">#{deleted},</if>
         </trim>
    </insert>
 
    <insert id="insertReceivableBillManagementBatch" parameterType="java.util.List"  useGeneratedKeys="true" keyProperty="id">
        insert into receivable_bill_management
        <trim prefix="(" suffix=") values" suffixOverrides=",">
            system_no,bill_name,customer_name,payee,responsible_person,responsible_leader,settlement_method,business_type,promotion_requirement,is_internal_settlement,internal_settlement_unit,document_count,total_amount,currency,discount_amount,received_amount,pending_amount,exchange_rate,cny_amount,period_type,business_start_date,business_end_date,billing_start_date,billing_end_date,bill_generate_date,bill_send_date,bill_due_date,settlement_category,settlement_period,nc_settlement_date,nc_settlement_amount,account_remark,overdue_interest,status,audit_status,remark,create_by,create_time,update_by,update_time,deleted,
        </trim>
        <foreach item="item" index="index" collection="list" separator=",">
            <trim prefix="(" suffix=") " suffixOverrides=",">
                #{item.systemNo},#{item.billName},#{item.customerName},#{item.payee},#{item.responsiblePerson},#{item.responsibleLeader},#{item.settlementMethod},#{item.businessType},#{item.promotionRequirement},#{item.isInternalSettlement},#{item.internalSettlementUnit},#{item.documentCount},#{item.totalAmount},#{item.currency},#{item.discountAmount},#{item.receivedAmount},#{item.pendingAmount},#{item.exchangeRate},#{item.cnyAmount},#{item.periodType},#{item.businessStartDate},#{item.businessEndDate},#{item.billingStartDate},#{item.billingEndDate},#{item.billGenerateDate},#{item.billSendDate},#{item.billDueDate},#{item.settlementCategory},#{item.settlementPeriod},#{item.ncSettlementDate},#{item.ncSettlementAmount},#{item.accountRemark},#{item.overdueInterest},#{item.status},#{item.auditStatus},#{item.remark},#{item.createBy},#{item.createTime},#{item.updateBy},#{item.updateTime},#{item.deleted},
            </trim>
        </foreach>
    </insert>
 
    <!-- 修改 -->
    <update id="updateReceivableBillManagement" parameterType="com.ruoyi.cwgl.domain.ReceivableBillManagement">
        update receivable_bill_management
        <trim prefix="SET" suffixOverrides=",">
            <if test="systemNo != null and systemNo != ''">system_no = #{systemNo},</if>
            <if test="billName != null and billName != ''">bill_name = #{billName},</if>
            <if test="customerName != null and customerName != ''">customer_name = #{customerName},</if>
            <if test="payee != null and payee != ''">payee = #{payee},</if>
            <if test="responsiblePerson != null and responsiblePerson != ''">responsible_person = #{responsiblePerson},</if>
            <if test="responsibleLeader != null and responsibleLeader != ''">responsible_leader = #{responsibleLeader},</if>
            <if test="settlementMethod != null and settlementMethod != ''">settlement_method = #{settlementMethod},</if>
            <if test="businessType != null and businessType != ''">business_type = #{businessType},</if>
            <if test="promotionRequirement != null and promotionRequirement != ''">promotion_requirement = #{promotionRequirement},</if>
            <if test="isInternalSettlement != null and isInternalSettlement != ''">is_internal_settlement = #{isInternalSettlement},</if>
            <if test="internalSettlementUnit != null">internal_settlement_unit = #{internalSettlementUnit},</if>
            <if test="documentCount != null">document_count = #{documentCount},</if>
            <if test="totalAmount != null">total_amount = #{totalAmount},</if>
            <if test="currency != null">currency = #{currency},</if>
            <if test="discountAmount != null">discount_amount = #{discountAmount},</if>
            <if test="receivedAmount != null">received_amount = #{receivedAmount},</if>
            <if test="pendingAmount != null">pending_amount = #{pendingAmount},</if>
            <if test="exchangeRate != null">exchange_rate = #{exchangeRate},</if>
            <if test="cnyAmount != null">cny_amount = #{cnyAmount},</if>
            <if test="periodType != null and periodType != ''">period_type = #{periodType},</if>
            <if test="businessStartDate != null">business_start_date = #{businessStartDate},</if>
            <if test="businessEndDate != null">business_end_date = #{businessEndDate},</if>
            <if test="billingStartDate != null">billing_start_date = #{billingStartDate},</if>
            <if test="billingEndDate != null">billing_end_date = #{billingEndDate},</if>
            <if test="billGenerateDate != null">bill_generate_date = #{billGenerateDate},</if>
            <if test="billSendDate != null">bill_send_date = #{billSendDate},</if>
            <if test="billDueDate != null">bill_due_date = #{billDueDate},</if>
            <if test="settlementCategory != null and settlementCategory != ''">settlement_category = #{settlementCategory},</if>
            <if test="settlementPeriod != null and settlementPeriod != ''">settlement_period = #{settlementPeriod},</if>
            <if test="ncSettlementDate != null">nc_settlement_date = #{ncSettlementDate},</if>
            <if test="ncSettlementAmount != null">nc_settlement_amount = #{ncSettlementAmount},</if>
            <if test="accountRemark != null and accountRemark != ''">account_remark = #{accountRemark},</if>
            <if test="overdueInterest != null">overdue_interest = #{overdueInterest},</if>
            <if test="status != null">status = #{status},</if>
            <if test="auditStatus != null">audit_status = #{auditStatus},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="deleted != null">deleted = #{deleted},</if>
        </trim>
        where id = #{id}
    </update>
    <!-- 修改 -->
    <update id="updateReceivableBillManagementBatch" parameterType="java.util.List">
        <foreach collection="list" item="item" index="index" separator=";">
            update receivable_bill_management
            <trim prefix="SET" suffixOverrides=",">
                <if test="item.systemNo != null and item.systemNo != ''">system_no = #{item.systemNo},</if>
                <if test="item.billName != null and item.billName != ''">bill_name = #{item.billName},</if>
                <if test="item.customerName != null and item.customerName != ''">customer_name = #{item.customerName},</if>
                <if test="item.payee != null and item.payee != ''">payee = #{item.payee},</if>
                <if test="item.responsiblePerson != null and item.responsiblePerson != ''">responsible_person = #{item.responsiblePerson},</if>
                <if test="item.responsibleLeader != null and item.responsibleLeader != ''">responsible_leader = #{item.responsibleLeader},</if>
                <if test="item.settlementMethod != null and item.settlementMethod != ''">settlement_method = #{item.settlementMethod},</if>
                <if test="item.businessType != null and item.businessType != ''">business_type = #{item.businessType},</if>
                <if test="item.promotionRequirement != null and item.promotionRequirement != ''">promotion_requirement = #{item.promotionRequirement},</if>
                <if test="item.isInternalSettlement != null and item.isInternalSettlement != ''">is_internal_settlement = #{item.isInternalSettlement},</if>
                <if test="item.internalSettlementUnit != null">internal_settlement_unit = #{item.internalSettlementUnit},</if>
                <if test="item.documentCount != null">document_count = #{item.documentCount},</if>
                <if test="item.totalAmount != null">total_amount = #{item.totalAmount},</if>
                <if test="item.currency != null">currency = #{item.currency},</if>
                <if test="item.discountAmount != null">discount_amount = #{item.discountAmount},</if>
                <if test="item.receivedAmount != null">received_amount = #{item.receivedAmount},</if>
                <if test="item.pendingAmount != null">pending_amount = #{item.pendingAmount},</if>
                <if test="item.exchangeRate != null">exchange_rate = #{item.exchangeRate},</if>
                <if test="item.cnyAmount != null">cny_amount = #{item.cnyAmount},</if>
                <if test="item.periodType != null and item.periodType != ''">period_type = #{item.periodType},</if>
                <if test="item.businessStartDate != null">business_start_date = #{item.businessStartDate},</if>
                <if test="item.businessEndDate != null">business_end_date = #{item.businessEndDate},</if>
                <if test="item.billingStartDate != null">billing_start_date = #{item.billingStartDate},</if>
                <if test="item.billingEndDate != null">billing_end_date = #{item.billingEndDate},</if>
                <if test="item.billGenerateDate != null">bill_generate_date = #{item.billGenerateDate},</if>
                <if test="item.billSendDate != null">bill_send_date = #{item.billSendDate},</if>
                <if test="item.billDueDate != null">bill_due_date = #{item.billDueDate},</if>
                <if test="item.settlementCategory != null and item.settlementCategory != ''">settlement_category = #{item.settlementCategory},</if>
                <if test="item.settlementPeriod != null and item.settlementPeriod != ''">settlement_period = #{item.settlementPeriod},</if>
                <if test="item.ncSettlementDate != null">nc_settlement_date = #{item.ncSettlementDate},</if>
                <if test="item.ncSettlementAmount != null">nc_settlement_amount = #{item.ncSettlementAmount},</if>
                <if test="item.accountRemark != null and item.accountRemark != ''">account_remark = #{item.accountRemark},</if>
                <if test="item.overdueInterest != null">overdue_interest = #{item.overdueInterest},</if>
                <if test="item.status != null">status = #{item.status},</if>
                <if test="item.auditStatus != null">audit_status = #{item.auditStatus},</if>
                <if test="item.remark != null">remark = #{item.remark},</if>
                <if test="item.createBy != null">create_by = #{item.createBy},</if>
                <if test="item.createTime != null">create_time = #{item.createTime},</if>
                <if test="item.updateBy != null">update_by = #{item.updateBy},</if>
                <if test="item.updateTime != null">update_time = #{item.updateTime},</if>
                <if test="item.deleted != null">deleted = #{item.deleted},</if>
            </trim>
        where id = #{item.id}
        </foreach>
    </update>
 
    <!--删除-->
    <delete id="deleteReceivableBillManagementById" parameterType="Integer">
        delete from receivable_bill_management where id = #{id}
    </delete>
    <delete id="deleteReceivableBillManagementByIds" parameterType="Integer">
        delete from receivable_bill_management where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
 
    <!-- 查询应收账单客户汇总列表 -->
    <select id="selectReceivableBillCustomerSummaryList" parameterType="com.ruoyi.cwgl.domain.ReceivableBillManagement" resultType="com.ruoyi.cwgl.domain.ReceivableBillCustomerSummary">
        SELECT 
            customer_name as customerName,
            SUM(total_amount) as totalEstimatedAmount,
            SUM(total_amount) as totalConfirmedAmount,
            SUM(pending_amount) as totalPendingAmount
        FROM receivable_bill_management
        <where>
            <if test="customerName != null  and customerName != ''"> and  customer_name like concat('%', #{customerName}, '%')</if>
 
        </where>
        GROUP BY customer_name
        ORDER BY customer_name
    </select>
 
    <!-- 查询应收账单账龄分析列表 -->
    <select id="selectReceivableBillAgingAnalysisList" parameterType="com.ruoyi.cwgl.domain.ReceivableBillManagement" resultMap="ReceivableBillAgingAnalysisVoResult">
        SELECT 
            thisTab.*,
            rib_latest.latest_invoice_time as latestInvoiceTime,
            COALESCE(rib_total.total_invoice_amount, 0) as totalInvoiceAmount,
            CASE 
                WHEN thisTab.pending_amount > COALESCE(rib_total.total_invoice_amount, 0) 
                THEN thisTab.pending_amount - COALESCE(rib_total.total_invoice_amount, 0)
                ELSE 0 
            END as unInvoicedAmount
        FROM receivable_bill_management thisTab
        
        -- 获取最新开票日期
        LEFT JOIN (
            SELECT head_id, MAX(invoice_time) as latest_invoice_time
            FROM receivable_invoice_business
            WHERE status = 1
            GROUP BY head_id
        ) rib_latest ON thisTab.id = rib_latest.head_id
        
        -- 获取开票总金额
        LEFT JOIN (
            SELECT head_id, SUM(invoicing_amount) as total_invoice_amount
            FROM receivable_invoice_business
            WHERE status = 1
            GROUP BY head_id
        ) rib_total ON thisTab.id = rib_total.head_id
        
        <where>
            <if test="systemNo != null  and systemNo != ''"> and thisTab.system_no = #{systemNo}</if>
            <if test="customerName != null  and customerName != ''"> and  thisTab.customer_name like concat('%', #{customerName}, '%')</if>
 
        </where>
        ORDER BY customer_name, bill_due_date
    </select>
 
    <!-- 批量更新应收账单账龄分析数据 -->
    <update id="batchUpdateAgingAnalysisData">
        UPDATE receivable_bill_management 
        SET 
 
            due_in_30_days = CASE 
                WHEN pending_amount > 0 AND bill_due_date IS NOT NULL 
                     AND bill_due_date > CURDATE() 
                     AND DATEDIFF(bill_due_date, CURDATE()) &lt;= 30
                THEN pending_amount 
                ELSE due_in_30_days  
            END,
            overdue_amount = CASE 
                WHEN pending_amount > 0 AND bill_due_date IS NOT NULL 
                     AND bill_due_date &lt;= CURDATE() 
                THEN pending_amount 
                ELSE overdue_amount  
            END,
 
            overdue_1_to_30_days = CASE 
                WHEN pending_amount > 0 AND bill_due_date IS NOT NULL 
                     AND bill_due_date &lt;= CURDATE() 
                     AND DATEDIFF(CURDATE(), bill_due_date) BETWEEN 1 AND 30 
                THEN pending_amount 
                ELSE overdue_1_to_30_days  
            END,
            overdue_31_to_60_days = CASE 
                WHEN pending_amount > 0 AND bill_due_date IS NOT NULL 
                     AND bill_due_date &lt;= CURDATE() 
                     AND DATEDIFF(CURDATE(), bill_due_date) BETWEEN 31 AND 60 
                THEN pending_amount 
                ELSE overdue_31_to_60_days  
            END,
            overdue_61_to_90_days = CASE 
                WHEN pending_amount > 0 AND bill_due_date IS NOT NULL 
                     AND bill_due_date &lt;= CURDATE() 
                     AND DATEDIFF(CURDATE(), bill_due_date) BETWEEN 61 AND 90 
                THEN pending_amount 
                ELSE overdue_61_to_90_days  
            END,
            overdue_91_to_180_days = CASE 
                WHEN pending_amount > 0 AND bill_due_date IS NOT NULL 
                     AND bill_due_date &lt;= CURDATE() 
                     AND DATEDIFF(CURDATE(), bill_due_date) BETWEEN 91 AND 180 
                THEN pending_amount 
                ELSE overdue_91_to_180_days  
            END,
            overdue_181_to_365_days = CASE 
                WHEN pending_amount > 0 AND bill_due_date IS NOT NULL 
                     AND bill_due_date &lt;= CURDATE() 
                     AND DATEDIFF(CURDATE(), bill_due_date) BETWEEN 181 AND 365 
                THEN pending_amount 
                ELSE overdue_181_to_365_days  
            END,
            overdue_over_1_year = CASE 
                WHEN pending_amount > 0 AND bill_due_date IS NOT NULL 
                     AND bill_due_date &lt;= CURDATE() 
                     AND DATEDIFF(CURDATE(), bill_due_date) &gt; 365 
                THEN pending_amount 
                ELSE overdue_over_1_year  
            END,
            overdue_days = CASE 
                WHEN pending_amount > 0 AND bill_due_date IS NOT NULL 
                     AND bill_due_date &lt;= CURDATE() 
                THEN DATEDIFF(CURDATE(), bill_due_date) 
                ELSE overdue_days  
            END,
            update_time = NOW()
        WHERE pending_amount > 0
    </update>
 
    <!-- 查询应收账单账款分析列表 -->
    <select id="selectReceivableBillAccountAnalysisList" parameterType="com.ruoyi.cwgl.domain.ReceivableBillManagement" resultType="com.ruoyi.cwgl.domain.vo.ReceivableBillAccountAnalysisVo">
        SELECT 
            thisTab.id,
            thisTab.system_no as systemNo,
            thisTab.bill_name as billName,
            thisTab.customer_name as customerName,
            thisTab.payee,
            thisTab.responsible_person as responsiblePerson,
            thisTab.responsible_leader as responsibleLeader,
            thisTab.settlement_method as settlementMethod,
            thisTab.business_type as businessType,
            thisTab.promotion_requirement as promotionRequirement,
            thisTab.settlement_category as settlementCategory,
            thisTab.settlement_period as settlementPeriod,
            thisTab.total_amount as totalAmount,
            thisTab.received_amount as receivedAmount,
            thisTab.pending_amount as pendingAmount,
            thisTab.nc_settlement_date as ncSettlementDate,
            thisTab.nc_settlement_amount as ncSettlementAmount,
            thisTab.account_remark as accountRemark,
            thisTab.overdue_interest as overdueInterest,
            thisTab.bill_due_date as billDueDate,
            thisTab.overdue_days as overdueDays,
            thisTab.status,
            thisTab.create_time as createTime,
            thisTab.update_time as updateTime,
            
            -- 开票相关字段
            rib_latest.invoice_time as latestInvoiceTime,
            COALESCE(rib_total.total_invoice_amount, 0) as totalInvoiceAmount,
            CASE 
                WHEN thisTab.total_amount > COALESCE(rib_total.total_invoice_amount, 0) 
                THEN thisTab.total_amount - COALESCE(rib_total.total_invoice_amount, 0)
                ELSE 0 
            END as unInvoicedAmount,
            
            -- 还款相关字段
            rbsd_latest.latest_repayment_date as latestRepaymentDate,
            COALESCE(rbsd_latest.latest_repayment_amount, 0) as latestRepaymentAmount
 
        FROM receivable_bill_management thisTab
 
        -- 获取最新开票日期
        LEFT JOIN (
            SELECT head_id, MAX(invoice_time) as invoice_time
            FROM receivable_invoice_business
            WHERE status = 1
            GROUP BY head_id
        ) rib_latest ON thisTab.id = rib_latest.head_id
        
        -- 获取开票总金额
        LEFT JOIN (
            SELECT head_id, SUM(invoicing_amount) as total_invoice_amount
            FROM receivable_invoice_business
            WHERE status = 1
            GROUP BY head_id
        ) rib_total ON thisTab.id = rib_total.head_id
        
        -- 获取最新还款信息
        LEFT JOIN (
            SELECT 
                r1.bill_id, 
                r1.receipt_date as latest_repayment_date, 
                r1.receipt_amount as latest_repayment_amount
            FROM receivable_bill_settlement_detail r1
            INNER JOIN (
                SELECT bill_id, MAX(receipt_date) as max_receipt_date
                FROM receivable_bill_settlement_detail
                WHERE deleted = 0
                GROUP BY bill_id
            ) r2 ON r1.bill_id = r2.bill_id AND r1.receipt_date = r2.max_receipt_date
            WHERE r1.deleted = 0
            -- 如果同一天有多条记录,取金额最大的那条
            AND r1.receipt_amount = (
                SELECT MAX(receipt_amount) 
                FROM receivable_bill_settlement_detail r3 
                WHERE r3.bill_id = r1.bill_id AND r3.receipt_date = r1.receipt_date AND r3.deleted = 0
            )
        ) rbsd_latest ON thisTab.id = rbsd_latest.bill_id
        
        <where>
            <if test="systemNo != null  and systemNo != ''"> and thisTab.system_no = #{systemNo}</if>
            <if test="customerName != null  and customerName != ''"> and  thisTab.customer_name like concat('%', #{customerName}, '%')</if>
 
        </where>
        ORDER BY thisTab.customer_name, thisTab.bill_due_date
    </select>
 
</mapper>