From 279366f14d6e1361b6caf7c05b74f0cea4227a36 Mon Sep 17 00:00:00 2001
From: wujianwei <wjw@11.com>
Date: 星期五, 27 三月 2026 10:53:28 +0800
Subject: [PATCH] 新增推送

---
 service/src/main/resources/mapper/cwgl/ReceivableBillManagementMapper.xml |   50 ++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 44 insertions(+), 6 deletions(-)

diff --git a/service/src/main/resources/mapper/cwgl/ReceivableBillManagementMapper.xml b/service/src/main/resources/mapper/cwgl/ReceivableBillManagementMapper.xml
index 291b4e8..69350f7 100644
--- a/service/src/main/resources/mapper/cwgl/ReceivableBillManagementMapper.xml
+++ b/service/src/main/resources/mapper/cwgl/ReceivableBillManagementMapper.xml
@@ -388,9 +388,36 @@
 
     <!-- 鏌ヨ搴旀敹璐﹀崟璐﹂緞鍒嗘瀽鍒楄〃 -->
     <select id="selectReceivableBillAgingAnalysisList" parameterType="com.ruoyi.cwgl.domain.ReceivableBillManagement" resultMap="ReceivableBillAgingAnalysisVoResult">
-        <include refid="selectReceivableBillManagementVo"/>
+        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
@@ -528,19 +555,30 @@
         
         -- 鑾峰彇鏈�鏂拌繕娆句俊鎭�
         LEFT JOIN (
-            SELECT bill_id, receipt_date as latest_repayment_date, receipt_amount as latest_repayment_amount
-            FROM receivable_bill_settlement_detail
-            WHERE deleted = 0
-            AND (bill_id, receipt_date) IN (
-                SELECT bill_id, MAX(receipt_date)
+            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
+            -- 濡傛灉鍚屼竴澶╂湁澶氭潯璁板綍锛屽彇閲戦鏈�澶х殑閭f潯
+            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>

--
Gitblit v1.8.0