gongchunyi
3 天以前 875adbd59a28453cdf443c3244e2691ad1dd02ac
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 &gt;= #{startDate}
            AND IFNULL(IF(slp.type = 1, sl.entry_date, pl.entry_date), slp.register_date) &gt;= #{startDate}
        </if>
        <if test="endDate != null">
            AND register_date &lt;= #{endDate}
            AND IFNULL(IF(slp.type = 1, sl.entry_date, pl.entry_date), slp.register_date) &lt;= #{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