From dc22724f61e0b792d327fa812895f6dc4fcf129d Mon Sep 17 00:00:00 2001
From: liding <756868258@qq.com>
Date: 星期三, 08 四月 2026 15:04:11 +0800
Subject: [PATCH] fix:groupBy

---
 src/main/resources/mapper/sales/SalesLedgerProductMapper.xml |   23 ++++++++++-------------
 1 files changed, 10 insertions(+), 13 deletions(-)

diff --git a/src/main/resources/mapper/sales/SalesLedgerProductMapper.xml b/src/main/resources/mapper/sales/SalesLedgerProductMapper.xml
index 671fcf5..84f04e2 100644
--- a/src/main/resources/mapper/sales/SalesLedgerProductMapper.xml
+++ b/src/main/resources/mapper/sales/SalesLedgerProductMapper.xml
@@ -31,7 +31,7 @@
                  left join production_product_main ppm on qi.product_main_id = ppm.id
                  left join product_work_order pwo on ppm.work_order_id = pwo.id
                  left join product_order po on pwo.product_order_id = po.id
-                 left join sales_ledger_product slp on po.sale_ledger_product_id = slp.id
+                 left join sales_ledger_product slp on po.sale_ledger_product_id = slp.id and slp.type = 1
         where qi.product_main_id = #{productMainId}
 
 
@@ -111,25 +111,22 @@
         SUM(slp.quantity) AS purchaseNum,
         SUM(slp.tax_inclusive_total_price) AS purchaseAmount,
         COUNT(DISTINCT slp.sales_ledger_id) AS purchaseTimes,
-        <!-- 骞冲潎鍗曚环 = 鎬婚噰璐噾棰�/鎬婚噰璐暟閲忥紝淇濈暀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
-        WHERE slp.type = 2 <!-- 鍥哄畾绛涢�夛細閲囪喘鍙拌处锛坱ype=2锛� -->
-        <!-- 閲囪喘鏃ユ湡绛涢�夛細鍙�夋潯浠� -->
+        LEFT JOIN purchase_return_order_products t1 ON t1.sales_ledger_product_id = slp.id
+        LEFT JOIN purchase_return_orders t2 ON t2.id = t1.purchase_return_order_id
+        WHERE slp.type = 2
         <if test="req.entryDateStart != null and req.entryDateEnd != null">
-            AND sl.entry_date BETWEEN #{req.entryDateStart} AND #{req.entryDateEnd} <!-- 鏃堕棿鑼冨洿锛氶潪绌烘湁鏁� -->
+            AND sl.entry_date BETWEEN #{req.entryDateStart} AND #{req.entryDateEnd}
         </if>
-        <!-- 浜у搧澶х被绛涢�夛細鍙�夋潯浠� -->
         <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">
@@ -144,7 +141,7 @@
                      p.product_name,
                      ps.unit_quantity * slp.quantity AS single_quantity
               FROM sales_ledger sl
-                       LEFT JOIN sales_ledger_product slp ON slp.sales_ledger_id = sl.id
+                       LEFT JOIN sales_ledger_product slp ON slp.sales_ledger_id = sl.id and slp.type = 1
                        LEFT JOIN product_model pm ON pm.id = slp.product_model_id
                        LEFT JOIN product_bom pb ON pb.product_model_id = pm.id
                        LEFT JOIN product_structure ps ON pb.id = ps.bom_id

--
Gitblit v1.9.3