From 2db7fd950e7c821fc2a048b51f50c6dbfcceed29 Mon Sep 17 00:00:00 2001
From: huminmin <mac@MacBook-Pro.local>
Date: 星期三, 27 五月 2026 11:10:02 +0800
Subject: [PATCH] 修改排序
---
src/main/resources/mapper/sales/SalesLedgerProductMapper.xml | 243 ++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 233 insertions(+), 10 deletions(-)
diff --git a/src/main/resources/mapper/sales/SalesLedgerProductMapper.xml b/src/main/resources/mapper/sales/SalesLedgerProductMapper.xml
index ec8d8d4..49569de 100644
--- a/src/main/resources/mapper/sales/SalesLedgerProductMapper.xml
+++ b/src/main/resources/mapper/sales/SalesLedgerProductMapper.xml
@@ -6,20 +6,243 @@
<select id="selectSalesLedgerProductList" resultType="com.ruoyi.sales.pojo.SalesLedgerProduct">
SELECT
- T1.*,
- t3.shipping_car_number,
- t3.shipping_date
+ T1.id,
+ T1.sales_ledger_id,
+ T1.warn_num,
+ T1.quantity,
+ T1.min_stock,
+ T1.tax_rate,
+ T1.tax_inclusive_unit_price,
+ T1.tax_inclusive_total_price,
+ T1.tax_exclusive_total_price,
+ T1.invoice_type,
+ T1.type,
+ T1.product_id,
+ T1.product_model_id,
+ T1.register,
+ T1.register_date,
+ T1.approve_status,
+ T1.is_checked,
+ T1.is_production,
+ T1.create_user,
+ T1.dept_id,
+ p.product_name as product_category,
+ pm.model as specification_model,
+ pm.unit as unit,
+ CASE
+ WHEN (IFNULL(t2.qualitity, 0) - IFNULL(t2.locked_quantity, 0)) >0 THEN 1
+ ELSE 0
+ END as has_sufficient_stock,
+ (IFNULL(T1.quantity, 0) - IFNULL(t3.shipped_quantity, 0)) as no_quantity,
+ CASE
+ WHEN IFNULL(t3.shipped_quantity, 0) = 0 THEN '寰呭彂璐�'
+ WHEN (IFNULL(T1.quantity, 0) - IFNULL(t3.shipped_quantity, 0)) > 0 THEN '閮ㄥ垎鍙戣揣'
+ ELSE '宸插彂璐�'
+ END as shippingStatus,
+ CASE
+ WHEN T1.type != 2 THEN NULL
+ WHEN IFNULL(t4.approved_stock_in_num, 0) <= 0 THEN '寰呭叆搴�'
+ WHEN IFNULL(t4.approved_stock_in_num, 0) >= IFNULL(T1.quantity, 0) THEN '瀹屽叏鍏ュ簱'
+ ELSE '鍏ュ簱涓�'
+ END AS stock_in_approval_status
FROM
sales_ledger_product T1
- left join shipping_info t3 on T1.id = t3.sales_ledger_id
+ LEFT JOIN (
+ SELECT product_model_id, SUM(qualitity) as qualitity, SUM(locked_quantity) as locked_quantity
+ FROM stock_inventory
+ GROUP BY product_model_id
+ ) t2 ON T1.product_model_id = t2.product_model_id
+ LEFT JOIN (
+ SELECT sales_ledger_product_id, IFNULL(SUM(spd.quantity), 0) as shipped_quantity
+ FROM shipping_info si
+ LEFT JOIN shipping_product_detail spd ON si.id = spd.shipping_info_id
+ where si.status != '瀹℃牳鎷掔粷'
+ GROUP BY sales_ledger_product_id
+ ) t3 ON t3.sales_ledger_product_id = T1.id
+ LEFT JOIN (
+ SELECT rel.sales_ledger_product_id,
+ IFNULL(SUM(rel.stock_in_num), 0) AS approved_stock_in_num
+ FROM (
+ SELECT slp.id AS sales_ledger_product_id,
+ sir.stock_in_num
+ FROM stock_in_record sir
+ INNER JOIN sales_ledger_product slp
+ ON slp.type = 2
+ AND TRIM(sir.record_type) = '7'
+ AND sir.record_id = slp.sales_ledger_id
+ AND (
+ (sir.batch_no IS NOT NULL AND sir.batch_no LIKE CONCAT('%-', slp.id))
+ OR (sir.batch_no IS NULL AND sir.product_model_id = slp.product_model_id)
+ )
+ WHERE sir.approval_status = 1
+
+ UNION ALL
+
+ SELECT slp.id AS sales_ledger_product_id,
+ sir.stock_in_num
+ FROM stock_in_record sir
+ INNER JOIN quality_inspect qi
+ ON TRIM(sir.record_type) = '10'
+ AND sir.record_id = qi.id
+ INNER JOIN sales_ledger_product slp
+ ON slp.type = 2
+ AND slp.sales_ledger_id = qi.purchase_ledger_id
+ AND slp.product_model_id = qi.product_model_id
+ WHERE sir.approval_status = 1
+ ) rel
+ GROUP BY rel.sales_ledger_product_id
+ ) t4 ON t4.sales_ledger_product_id = T1.id
+ left join product_model pm ON T1.product_model_id = pm.id
+ left join product p ON pm.product_id = p.id
<where>
- 1=1
- <if test="salesLedgerProduct.salesLedgerId != null and salesLedgerProduct.salesLedgerId != '' ">
- AND T1.sales_ledger_id = #{salesLedgerProduct.salesLedgerId}
+ <if test="salesLedgerProduct.salesLedgerId != null">
+ AND T1.sales_ledger_id = #{salesLedgerProduct.salesLedgerId}
</if>
- <if test="salesLedgerProduct.type != null and salesLedgerProduct.type != '' ">
- AND T1.type = #{salesLedgerProduct.type}
+ <if test="salesLedgerProduct.type != null">
+ AND T1.type = #{salesLedgerProduct.type}
</if>
</where>
+ ORDER BY T1.register_date DESC
</select>
-</mapper>
\ No newline at end of file
+
+ <select id="selectSalesLedgerProductByMainId" resultType="com.ruoyi.sales.pojo.SalesLedgerProduct">
+ select slp.*
+ from quality_inspect qi
+ left join production_product_main ppm on qi.product_main_id = ppm.id
+ left join production_operation_task pot on ppm.production_operation_task_id = pot.id
+ left join production_order po on pot.production_order_id = po.id
+ left join production_plan pp_main
+ on find_in_set(pp_main.id, replace(replace(replace(po.production_plan_ids, '[', ''), ']', ''), ' ', '')) > 0
+ left join sales_ledger_product slp on slp.sales_ledger_id = pp_main.sales_ledger_id
+ and slp.product_model_id = po.product_model_id
+ and slp.type = 1
+ where qi.product_main_id = #{productMainId}
+ and slp.id is not null
+ order by slp.id desc
+ limit 1
+ </select>
+ <select id="procurementBusinessSummaryListPage"
+ resultType="com.ruoyi.purchase.dto.ProcurementBusinessSummaryDto">
+ SELECT
+ slp.product_category AS productCategory,
+ slp.specification_model AS specificationModel,
+ sl.supplier_name AS supplierName,
+ 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,
+ 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">
+ 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, slp.specification_model, sl.supplier_name
+ ORDER BY slp.product_category
+ </select>
+ <select id="selectProductBomStructure" resultType="com.ruoyi.sales.dto.LossProductModelDto">
+ select
+ a.model,
+ a.product_name,
+ a.unit,
+ sum(a.single_quantity) AS loss_num
+ from (SELECT ps.unit,
+ ps.unit_quantity,
+ pm1.model,
+ 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 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
+ LEFT JOIN product_model pm1 ON pm1.id = ps.product_model_id
+ LEFT JOIN product p ON p.id = pm1.product_id
+ WHERE sl.id = #{salesLedegerId}) A
+ group by a.model, a.product_name, a.unit
+ </select>
+ <select id="selectProduct" resultType="com.ruoyi.sales.pojo.SalesLedgerProduct">
+ select
+ p.product_name as product_category,
+ pm.model as specification_model,
+ pm.id as product_model_id
+ from product_model pm
+ left join product p on pm.product_id = p.id
+ </select>
+
+ <select id="selectProductSalesAnalysis" resultType="java.util.Map">
+ SELECT
+ product_category as name,
+ SUM( tax_inclusive_total_price ) AS value
+ FROM
+ sales_ledger_product
+ WHERE
+ type = 1
+ GROUP BY
+ product_category
+ ORDER BY
+ value DESC
+ LIMIT 5
+ </select>
+
+ <select id="selectRawMaterialPurchaseAnalysis" resultType="java.util.Map">
+ SELECT
+ pr.product_name AS name,
+ SUM( slp.tax_inclusive_total_price ) AS value
+ FROM
+ sales_ledger_product slp
+ JOIN product pr ON slp.product_id = pr.id
+ WHERE
+ slp.type = 2
+ AND pr.parent_id = ( SELECT id FROM product WHERE product_name = '鍘熸潗鏂�' )
+ GROUP BY
+ pr.id,
+ pr.product_name
+ ORDER BY
+ value DESC
+ LIMIT 5
+ </select>
+
+ <select id="selectProductCountByTypeAndDate" resultType="int">
+ SELECT IFNULL(COUNT(*), 0)
+ FROM sales_ledger_product
+ WHERE type = #{type}
+ <if test="startDate != null">
+ AND register_date >= #{startDate}
+ </if>
+ <if test="endDate != null">
+ AND register_date <= #{endDate}
+ </if>
+ </select>
+
+ <select id="selectRawMaterialExpense" resultType="java.math.BigDecimal">
+ WITH RECURSIVE product_tree AS (SELECT id
+ FROM product
+ WHERE product_name = '鍘熸潗鏂�'
+
+ UNION ALL
+
+ SELECT p.id
+ FROM product p
+ INNER JOIN product_tree pt ON p.parent_id = pt.id)
+ SELECT IFNULL(SUM(slp.tax_inclusive_total_price), 0)
+ FROM sales_ledger_product slp
+ WHERE slp.type = 2
+ AND slp.product_id IN (SELECT id
+ FROM product_tree);
+
+ </select>
+</mapper>
--
Gitblit v1.9.3