From 639d36e087548e7499a351737d5e6a9ce24c0407 Mon Sep 17 00:00:00 2001
From: gongchunyi <deslre0381@gmail.com>
Date: 星期一, 29 六月 2026 01:38:03 +0800
Subject: [PATCH] fix: 库存默认0

---
 src/main/resources/mapper/stock/StockInRecordMapper.xml |   22 +++++++++++++++++++++-
 1 files changed, 21 insertions(+), 1 deletions(-)

diff --git a/src/main/resources/mapper/stock/StockInRecordMapper.xml b/src/main/resources/mapper/stock/StockInRecordMapper.xml
index c9ada77..5bf1b58 100644
--- a/src/main/resources/mapper/stock/StockInRecordMapper.xml
+++ b/src/main/resources/mapper/stock/StockInRecordMapper.xml
@@ -34,6 +34,16 @@
             <if test="params.productName != null and params.productName != ''">
                 and p.product_name like concat('%',#{params.productName},'%')
             </if>
+            <if test="params.topParentProductId != null and params.topParentProductId > 0">
+                and p.id in (
+                    WITH RECURSIVE product_tree AS (
+                        SELECT id FROM product WHERE id = #{params.topParentProductId}
+                        UNION ALL
+                        SELECT p2.id FROM product p2 INNER JOIN product_tree pt ON p2.parent_id = pt.id
+                    )
+                    SELECT id FROM product_tree
+                )
+            </if>
             <if test="params.salesContractNo != null and params.salesContractNo != ''">
                 and (
                     (sir.record_type IN ('6', '7', '18', '19', '20') and pl.purchase_contract_number like concat('%',#{params.salesContractNo},'%'))
@@ -48,7 +58,7 @@
                 and sir.record_type = #{params.recordType}
             </if>
         </where>
-        order by sir.id desc
+        order by sir.inbound_batches desc
     </select>
     <select id="listStockInRecordExportData" resultType="com.ruoyi.stock.execl.StockInRecordExportData">
         SELECT
@@ -82,6 +92,16 @@
             <if test="params.productName != null and params.productName != ''">
                 and p.product_name like concat('%',#{params.productName},'%')
             </if>
+            <if test="params.topParentProductId != null and params.topParentProductId > 0">
+                and p.id in (
+                    WITH RECURSIVE product_tree AS (
+                        SELECT id FROM product WHERE id = #{params.topParentProductId}
+                        UNION ALL
+                        SELECT p2.id FROM product p2 INNER JOIN product_tree pt ON p2.parent_id = pt.id
+                    )
+                    SELECT id FROM product_tree
+                )
+            </if>
             <if test="params.salesContractNo != null and params.salesContractNo != ''">
                 and (
                     (sir.record_type IN ('6', '7', '18', '19', '20') and pl.purchase_contract_number like concat('%',#{params.salesContractNo},'%'))

--
Gitblit v1.9.3