src/main/resources/mapper/sales/SalesLedgerProductMapper.xml
@@ -5,15 +5,22 @@
<mapper namespace="com.ruoyi.sales.mapper.SalesLedgerProductMapper">
    <select id="selectSalesLedgerProductList" resultType="com.ruoyi.sales.pojo.SalesLedgerProduct">
        WITH stock_summary AS (
        SELECT
        product_model_id,
        SUM(qualitity) AS total_quantity,
        SUM(locked_quantity) AS total_locked
        FROM stock_inventory
        GROUP BY product_model_id
        )
        SELECT
        T1.*,
        CASE
        WHEN (IFNULL(t2.qualitity, 0) - IFNULL(t2.locked_quantity, 0)) >= IFNULL(T1.quantity, 0) THEN 1
        WHEN (IFNULL(s.total_quantity, 0) - IFNULL(s.total_locked, 0)) >= IFNULL(T1.quantity, 0) THEN 1
        ELSE 0
        END as has_sufficient_stock
        FROM
        sales_ledger_product T1
        LEFT JOIN stock_inventory t2 ON T1.product_model_id = t2.product_model_id
        FROM sales_ledger_product T1
        LEFT JOIN stock_summary s ON T1.product_model_id = s.product_model_id
        <where>
            <if test="salesLedgerProduct.salesLedgerId != null">
                AND T1.sales_ledger_id = #{salesLedgerProduct.salesLedgerId}
@@ -127,8 +134,10 @@
        <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>