From 9e097fb25f494424ad79800c78b635fc94175f37 Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期四, 13 八月 2026 13:53:20 +0800
Subject: [PATCH] feat(stock): 添加库存查询按型号过滤功能

---
 src/main/resources/mapper/sales/SalesLedgerProductMapper.xml |   25 ++++++++++++++++---------
 1 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/src/main/resources/mapper/sales/SalesLedgerProductMapper.xml b/src/main/resources/mapper/sales/SalesLedgerProductMapper.xml
index 73026c8..10b87f9 100644
--- a/src/main/resources/mapper/sales/SalesLedgerProductMapper.xml
+++ b/src/main/resources/mapper/sales/SalesLedgerProductMapper.xml
@@ -78,8 +78,9 @@
         left join purchase_ledger sl on slp.sales_ledger_id = sl.id
         <where>
             slp.type = 2
-            <if test="req.purchaseContractNumber != null and req.purchaseContractNumber != '' ">
-                AND sl.purchase_contract_number like concat('%',#{req.purchaseContractNumber},'%')
+            <if test="req.supplierNameOrContractNo != null and req.supplierNameOrContractNo != '' ">
+                AND sl.purchase_contract_number like concat('%',#{req.supplierNameOrContractNo},'%')
+                or sl.supplier_name like concat('%',#{req.supplierNameOrContractNo},'%')
             </if>
             <if test="req.approvalStatus != null and req.approvalStatus != ''">
                 and sl.approval_status = #{req.approvalStatus}
@@ -90,15 +91,19 @@
             <if test="req.projectName != null and req.projectName != '' ">
                 AND sl.project_name like concat('%',#{req.projectName},'%')
             </if>
-            <if test="req.customerName != null and req.customerName != '' ">
-                AND sl.customer_name like concat('%',#{req.customerName},'%')
-            </if>
             <if test="req.productCategory != null and req.productCategory != '' ">
                 AND slp.product_category like concat('%',#{req.productCategory},'%')
             </if>
             <if test="req.status != null and req.status ">
                 AND slp.pending_tickets_total &gt; 0
             </if>
+            <if test="req.ticketsTotal != null and req.ticketsTotal.doubleValue() != 0.0">
+                AND slp.tickets_total = #{req.ticketsTotal}
+            </if>
+            <if test="req.registrationtDate != null and req.registrationtDate != ''">
+                AND DATE(slp.register_date) = #{req.registrationtDate}
+            </if>
+
         </where>
         order by slp.register_date desc
     </select>
@@ -114,10 +119,14 @@
         <!-- 骞冲潎鍗曚环 = 鎬婚噰璐噾棰�/鎬婚噰璐暟閲忥紝淇濈暀2浣嶅皬鏁帮紝閬垮厤闄�0 -->
         ROUND(IF(SUM(slp.quantity) = 0, 0, SUM(slp.tax_inclusive_total_price) / SUM(slp.quantity)), 2) AS averagePrice,
         <!-- 璇ヤ骇鍝佸ぇ绫讳笅鏈�鍚庝竴涓綍鍏ユ棩鏈燂紙鍙栧彴璐︿富琛ㄧ殑entry_date锛� -->
-        MAX(sl.entry_date) AS entryDate
+        MAX(sl.entry_date) AS entryDate,
+        COALESCE(NULLIF(SUM(t1.return_quantity), 0), 0) AS return_quantity,
+        COALESCE(SUM(t2.total_amount), 0) AS return_amount
         FROM sales_ledger_product slp
         <!-- 鍏宠仈鍙拌处涓昏〃锛氳幏鍙栧綍鍏ユ棩鏈焑ntry_date -->
         LEFT JOIN purchase_ledger sl ON slp.sales_ledger_id = sl.id
+        left join purchase_return_order_products as t1 on t1.sales_ledger_product_id = slp.id
+        left join purchase_return_orders as t2 on t2.id = t1.purchase_return_order_id
         WHERE slp.type = 2 <!-- 鍥哄畾绛涢�夛細閲囪喘鍙拌处锛坱ype=2锛� -->
         <!-- 閲囪喘鏃ユ湡绛涢�夛細鍙�夋潯浠� -->
         <if test="req.entryDateStart != null and req.entryDateEnd != null">
@@ -127,9 +136,7 @@
         <if test="req.productCategory != null and req.productCategory != ''">
             AND slp.product_category = #{req.productCategory}
         </if>
-        <!-- 鎸変骇鍝佸ぇ绫诲垎缁勮仛鍚� -->
-        GROUP BY slp.product_category
-        <!-- 鎸変骇鍝佸ぇ绫绘帓搴� -->
+        GROUP BY slp.product_category, slp.specification_model, sl.supplier_name
         ORDER BY slp.product_category
     </select>
     <select id="selectProductBomStructure" resultType="com.ruoyi.sales.dto.LossProductModelDto">

--
Gitblit v1.9.3