From 331637759f60da2281f1bdd04bfab96eff572aed Mon Sep 17 00:00:00 2001
From: huminmin <mac@MacBook-Pro.local>
Date: 星期五, 24 四月 2026 17:21:55 +0800
Subject: [PATCH] 出库管理按照原材料和成品来区分

---
 src/main/resources/mapper/stock/StockOutRecordMapper.xml |   32 +++++++++++++++++++++++++++++---
 1 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/src/main/resources/mapper/stock/StockOutRecordMapper.xml b/src/main/resources/mapper/stock/StockOutRecordMapper.xml
index 6c25aa8..3c21f33 100644
--- a/src/main/resources/mapper/stock/StockOutRecordMapper.xml
+++ b/src/main/resources/mapper/stock/StockOutRecordMapper.xml
@@ -18,6 +18,17 @@
     </resultMap>
 
     <select id="listPage" resultType="com.ruoyi.stock.dto.StockOutRecordDto">
+        WITH RECURSIVE product_tree AS (
+        SELECT id
+        FROM product
+        WHERE id = #{params.topParentProductId}
+
+        UNION ALL
+
+        SELECT p.id
+        FROM product p
+        INNER JOIN product_tree pt ON p.parent_id = pt.id
+        )
         SELECT
         sor.*,
         p.product_name as productName,
@@ -28,10 +39,8 @@
         FROM stock_out_record as sor
         LEFT JOIN product_model as pm on sor.product_model_id = pm.id
         LEFT JOIN product as p on pm.product_id = p.id
-        LEFT JOIN product p2 ON p.parent_id = p2.id
         LEFT JOIN sys_user as u on sor.create_user = u.user_id
         <where>
-            (p2.product_name != '鍗婃垚鍝�' OR p2.product_name IS NULL)
             <if test="params.timeStr != null and params.timeStr != ''">
                 and sor.create_time like concat('%',#{params.timeStr},'%')
             </if>
@@ -43,11 +52,25 @@
             </if>
             <if test="params.recordType != null and params.recordType != ''">
                 and sor.record_type = #{params.recordType}
+            </if>
+            <if test="params.topParentProductId != null and params.topParentProductId > 0">
+                and p.id in (select id from product_tree)
             </if>
         </where>
         order by sor.id desc
     </select>
     <select id="listStockOutRecordExportData" resultType="com.ruoyi.stock.execl.StockOutRecordExportData">
+        WITH RECURSIVE product_tree AS (
+        SELECT id
+        FROM product
+        WHERE id = #{params.topParentProductId}
+
+        UNION ALL
+
+        SELECT p.id
+        FROM product p
+        INNER JOIN product_tree pt ON p.parent_id = pt.id
+        )
         SELECT
         sor.*,
         p.product_name as productName,
@@ -72,8 +95,11 @@
             <if test="params.recordType != null and params.recordType != ''">
                 and sor.record_type = #{params.recordType}
             </if>
+            <if test="params.topParentProductId != null and params.topParentProductId > 0">
+                and p.id in (select id from product_tree)
+            </if>
         </where>
         order by sor.id desc
     </select>
 
-</mapper>
+</mapper>
\ No newline at end of file

--
Gitblit v1.9.3