From ccc9d4533bc7b696f6d539720a6052abc44ff7a5 Mon Sep 17 00:00:00 2001
From: yuan <123@>
Date: 星期日, 11 十月 2026 23:46:17 +0800
Subject: [PATCH] fix: 添加设备名称字段并修复多个查询的排序和分组问题

---
 src/main/resources/mapper/purchase/PaymentRegistrationMapper.xml |   69 +++++++++++++++++++++++++++++++---
 1 files changed, 62 insertions(+), 7 deletions(-)

diff --git a/src/main/resources/mapper/purchase/PaymentRegistrationMapper.xml b/src/main/resources/mapper/purchase/PaymentRegistrationMapper.xml
index 9cdc5a3..8de052d 100644
--- a/src/main/resources/mapper/purchase/PaymentRegistrationMapper.xml
+++ b/src/main/resources/mapper/purchase/PaymentRegistrationMapper.xml
@@ -151,20 +151,22 @@
 
     <select id="paymentHistoryListPage" resultType="com.ruoyi.purchase.dto.PaymentRegistrationDto">
         SELECT
+        T1.id,
         T1.payment_date,
         T2.supplier_name,
         T1.current_payment_amount,
         T1.payment_method,
         T3.nick_name AS registrant,
         T1.registrationt_date,
-        t4.purchase_contract_number
+        t4.purchase_contract_number,
+        t5.invoice_amount,
+        t5.invoice_number
         FROM
         payment_registration T1
-            LEFT JOIN purchase_ledger t4 ON t4.id = T1.purchase_ledger_id
-        LEFT JOIN
-        supplier_manage T2 ON T1.supplier_id = T2.id
-        LEFT JOIN
-        sys_user T3 ON T3.user_id = T1.registrant_id
+        LEFT JOIN purchase_ledger t4 ON t4.id = T1.purchase_ledger_id
+        LEFT JOIN supplier_manage T2 ON T1.supplier_id = T2.id
+        LEFT JOIN sys_user T3 ON T3.user_id = T1.registrant_id
+        left join ticket_registration t5 on t5.id = T1.ticket_registration_id
         <where>
             <if test="params.searchText != null and params.searchText != '' ">
                 AND T2.supplier_name LIKE CONCAT('%',#{params.searchText},'%')
@@ -175,8 +177,61 @@
             <if test="params.paymentDateEnd != null and params.paymentDateEnd !='' ">
                 AND T1.payment_date &lt;= date_format(#{params.paymentDateEnd},'%Y-%m-%d')
             </if>
+            <if test="params.purchaseContractNumber != null and params.purchaseContractNumber !='' ">
+                AND t4.purchase_contract_number LIKE CONCAT('%',#{params.purchaseContractNumber},'%')
+            </if>
         </where>
-        ORDER BY T1.payment_date,T1.create_time DESC
+        <!-- 2026-10-13 闇�姹傦細浠樻娴佹按鎸変粯娆炬棩鏈熷�掑簭锛堝師鏉ュ彧鍐欎簡 payment_date 娌″啓鏂瑰悜锛岄粯璁ゅ崌搴忥紝鏈�鏃╃殑鍦ㄦ渶涓婇潰锛� -->
+        ORDER BY T1.payment_date DESC, T1.id DESC
+    </select>
+    <select id="supplierNameListPage" resultType="com.ruoyi.purchase.dto.PaymentRegistrationDto">
+        SELECT
+        T1.supplier_id,
+        T1.supplier_name,
+        IFNULL(SUM(T1.contract_amount), 0) AS invoiceAmount,
+        IFNULL(SUM(T2.paid), 0)            AS paymentAmount,
+        IFNULL(SUM(T1.contract_amount), 0) - IFNULL(SUM(T2.paid), 0) AS payableAmount
+        FROM purchase_ledger T1
+        <!-- 2026-10-13 淇锛氬師鏉ョ洿鎺� LEFT JOIN payment_registration 鍐� SUM(contract_amount)锛�
+             涓�绗旈噰璐悎鍚屾湁鍑犵瑪浠樻锛屽悎鍚岄灏辫閲嶅绱姞鍑犳锛堜緵搴斿晢寰�鏉ラ〉銆屽悎鍚岄噾棰�/搴斾粯閲戦銆嶅洜姝よ櫄楂橈級銆�
+             鏀规垚鍏堟寜鍙拌处姹囨�讳粯娆惧啀 JOIN銆� -->
+        LEFT JOIN (
+            SELECT purchase_ledger_id, SUM(current_payment_amount) AS paid
+            FROM payment_registration WHERE purchase_ledger_id IS NOT NULL GROUP BY purchase_ledger_id
+        ) T2 ON T2.purchase_ledger_id = T1.id
+        <where>
+            <if test="req.supplierName != null and req.supplierName != '' ">
+                T1.supplier_name LIKE CONCAT ('%',#{req.supplierName},'%')
+            </if>
+        </where>
+        GROUP BY T1.supplier_id, T1.supplier_name
+    </select>
+
+    <select id="supplierNameListPageDetails" resultType="com.ruoyi.purchase.dto.PaymentRegistrationDto">
+        SELECT
+        T1.supplier_id,
+        T1.supplier_name,
+        T1.contract_amount AS invoiceAmount,
+        IFNULL(SUM(T2.current_payment_amount), 0) AS paymentAmount,
+        <!-- 2026-10-13 淇锛氬師鏉ュ啓鐨勬槸銆屽悎鍚岄 鈭� 鏈棩鏈熻繖涓�绗斾粯娆俱�嶏紝鍐嶅彔鍔� GROUP BY payment_date锛�
+             涓�绗斿悎鍚屾湁鍑犵瑪浠樻灏辨媶鎴愬嚑琛屻�佹瘡琛屼竴涓亣鐨�"搴斾粯"锛堜緥濡� CG20260523002 宸插叏棰濅粯娆撅紝
+             鍗存樉绀哄簲浠� 18524.07锛夈�傚簲浠橀噾棰濆簲褰撴槸**璇ュ悎鍚屽綋鍓嶇湡姝g殑鏈粯娆鹃 = 鍚堝悓棰� 鈭� 鍏ㄩ儴浠樻**銆� -->
+        GREATEST(T1.contract_amount - IFNULL((
+            SELECT SUM(T3.current_payment_amount) FROM payment_registration T3
+            WHERE T3.purchase_ledger_id = T1.id
+        ), 0), 0) AS payableAmount,
+        T1.purchase_contract_number,
+        T2.payment_date
+        FROM purchase_ledger T1
+        INNER JOIN payment_registration T2 ON T1.id = T2.purchase_ledger_id
+        <where>
+            T1.supplier_id = #{req.supplierId}
+            <if test="req.supplierName != null and req.supplierName != '' ">
+                T1.supplier_name LIKE CONCAT ('%',#{req.supplierName},'%')
+            </if>
+        </where>
+        GROUP BY T1.id, T1.supplier_id, T1.supplier_name, T1.contract_amount, T1.purchase_contract_number, T2.payment_date
+        ORDER BY T1.entry_date ASC, T2.payment_date ASC
     </select>
 
 </mapper>
\ No newline at end of file

--
Gitblit v1.9.3