huminmin
2026-04-29 ea25a4d9db55901a861b4ff22737fcf24c7bb26c
src/main/resources/mapper/sales/SalesLedgerProductMapper.xml
@@ -99,6 +99,10 @@
            <if test="req.status != null and req.status ">
                AND slp.pending_tickets_total &gt; 0
            </if>
            <if test="req.supplierNameOrContractNo != null and req.supplierNameOrContractNo != ''">
                AND (sl.supplier_name like concat('%',#{req.supplierNameOrContractNo},'%') or
                sl.purchase_contract_number like concat('%',#{req.supplierNameOrContractNo},'%'))
            </if>
        </where>
        order by slp.register_date desc
    </select>
@@ -114,10 +118,14 @@
        <!-- 平均单价 = 总采购金额/总采购数量,保留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
        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
        <!-- 关联台账主表:获取录入日期entry_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 <!-- 固定筛选:采购台账(type=2) -->
        <!-- 采购日期筛选:可选条件 -->
        <if test="req.entryDateStart != null and req.entryDateEnd != null">
@@ -127,9 +135,7 @@
        <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>
    <select id="selectProductBomStructure" resultType="com.ruoyi.sales.dto.LossProductModelDto">