gongchunyi
2 天以前 e4ea49cc868574662794e5bc9c338614337f728d
src/main/resources/mapper/sales/SalesLedgerProductMapper.xml
@@ -8,30 +8,30 @@
        SELECT
        T1.*,
        CASE
        WHEN t2.qualitity > T1.quantity THEN 1
        WHEN (IFNULL(t2.qualitity, 0) - IFNULL(t2.locked_quantity, 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
        <where>
            1=1
            <if test="salesLedgerProduct.salesLedgerId != null and salesLedgerProduct.salesLedgerId != '' ">
            <if test="salesLedgerProduct.salesLedgerId != null">
                AND T1.sales_ledger_id = #{salesLedgerProduct.salesLedgerId}
            </if>
            <if test="salesLedgerProduct.type != null and salesLedgerProduct.type != '' ">
            <if test="salesLedgerProduct.type != null">
                AND T1.type = #{salesLedgerProduct.type}
            </if>
        </where>
        ORDER BY T1.register_date DESC
    </select>
    <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 product_work_order pwo on ppm.work_order_id = pwo.id
                 left join product_order po on pwo.product_order_id = po.id
                 left join sales_ledger_product slp on po.product_model_id = slp.id
                 left join sales_ledger_product slp on po.sale_ledger_product_id = slp.id
        where qi.product_main_id = #{productMainId}
@@ -81,6 +81,9 @@
            <if test="req.purchaseContractNumber != null and req.purchaseContractNumber != '' ">
                AND sl.purchase_contract_number like concat('%',#{req.purchaseContractNumber},'%')
            </if>
            <if test="req.approvalStatus != null and req.approvalStatus != ''">
                and sl.approval_status = #{req.approvalStatus}
            </if>
            <if test="req.customerContractNo != null and req.customerContractNo != '' ">
                AND sl.customer_contract_no like concat('%',#{req.customerContractNo},'%')
            </if>
@@ -94,7 +97,7 @@
                AND slp.product_category like concat('%',#{req.productCategory},'%')
            </if>
            <if test="req.status != null and req.status ">
                AND slp.pending_invoice_total &gt; 0
                AND slp.pending_tickets_total &gt; 0
            </if>
        </where>
        order by slp.register_date desc
@@ -159,7 +162,7 @@
        left join product p on pm.product_id = p.id
    </select>
    <select id="selectProductSalesAnalysis" resultType="java.util.LinkedHashMap">
    <select id="selectProductSalesAnalysis" resultType="java.util.Map">
        SELECT
            product_category as name,
            SUM( tax_inclusive_total_price ) AS value
@@ -174,7 +177,7 @@
        LIMIT 5
    </select>
    <select id="selectRawMaterialPurchaseAnalysis" resultType="java.util.LinkedHashMap">
    <select id="selectRawMaterialPurchaseAnalysis" resultType="java.util.Map">
        SELECT
            pr.product_name AS name,
            SUM( slp.tax_inclusive_total_price ) AS value
@@ -200,4 +203,21 @@
        AND register_date &lt;= #{endDate}
    </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>