liding
3 天以前 3841d6424d6cb9cfeb4221435c137628b9f7442d
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}