From 875adbd59a28453cdf443c3244e2691ad1dd02ac Mon Sep 17 00:00:00 2001
From: gongchunyi <deslre0381@gmail.com>
Date: 星期四, 17 九月 2026 00:13:08 +0800
Subject: [PATCH] fix: 产品父类名称适配
---
src/main/resources/mapper/sales/SalesLedgerProductMapper.xml | 25 +++++++++++++++++++------
1 files changed, 19 insertions(+), 6 deletions(-)
diff --git a/src/main/resources/mapper/sales/SalesLedgerProductMapper.xml b/src/main/resources/mapper/sales/SalesLedgerProductMapper.xml
index 711c961..92cd95f 100644
--- a/src/main/resources/mapper/sales/SalesLedgerProductMapper.xml
+++ b/src/main/resources/mapper/sales/SalesLedgerProductMapper.xml
@@ -187,6 +187,14 @@
</select>
<select id="selectRawMaterialPurchaseAnalysis" resultType="java.util.Map">
+ WITH RECURSIVE product_tree AS (SELECT id
+ FROM product
+ WHERE parent_id IS NULL
+ AND product_name LIKE '%鍘熸潗鏂�%'
+ UNION ALL
+ SELECT p.id
+ FROM product p
+ INNER JOIN product_tree pt ON p.parent_id = pt.id)
SELECT
pr.product_name AS name,
SUM( slp.tax_inclusive_total_price ) AS value
@@ -195,7 +203,7 @@
JOIN product pr ON slp.product_id = pr.id
WHERE
slp.type = 2
- AND pr.parent_id = ( SELECT id FROM product WHERE product_name = '鍘熸潗鏂�' )
+ AND pr.id IN ( SELECT id FROM product_tree )
GROUP BY
pr.id,
pr.product_name
@@ -206,20 +214,25 @@
<select id="selectProductCountByTypeAndDate" resultType="int">
SELECT IFNULL(COUNT(*), 0)
- FROM sales_ledger_product
- WHERE type = #{type}
+ FROM sales_ledger_product slp
+ LEFT JOIN sales_ledger sl
+ ON slp.type = 1 AND sl.id = slp.sales_ledger_id
+ LEFT JOIN purchase_ledger pl
+ ON slp.type = 2 AND pl.id = slp.sales_ledger_id
+ WHERE slp.type = #{type}
<if test="startDate != null">
- AND register_date >= #{startDate}
+ AND IFNULL(IF(slp.type = 1, sl.entry_date, pl.entry_date), slp.register_date) >= #{startDate}
</if>
<if test="endDate != null">
- AND register_date <= #{endDate}
+ AND IFNULL(IF(slp.type = 1, sl.entry_date, pl.entry_date), slp.register_date) <= #{endDate}
</if>
</select>
<select id="selectRawMaterialExpense" resultType="java.math.BigDecimal">
WITH RECURSIVE product_tree AS (SELECT id
FROM product
- WHERE product_name = '鍘熸潗鏂�'
+ WHERE parent_id IS NULL
+ AND product_name LIKE '%鍘熸潗鏂�%'
UNION ALL
--
Gitblit v1.9.3