wujianwei
2026-03-27 279366f14d6e1361b6caf7c05b74f0cea4227a36
service/src/main/resources/mapper/cwgl/ReceivableBillManagementMapper.xml
@@ -388,7 +388,33 @@
    <!-- 查询应收账单账龄分析列表 -->
    <select id="selectReceivableBillAgingAnalysisList" parameterType="com.ruoyi.cwgl.domain.ReceivableBillManagement" resultMap="ReceivableBillAgingAnalysisVoResult">
        <include refid="selectReceivableBillManagementVo"/>
        SELECT
            thisTab.*,
            rib_latest.latest_invoice_time as latestInvoiceTime,
            COALESCE(rib_total.total_invoice_amount, 0) as totalInvoiceAmount,
            CASE
                WHEN thisTab.pending_amount > COALESCE(rib_total.total_invoice_amount, 0)
                THEN thisTab.pending_amount - COALESCE(rib_total.total_invoice_amount, 0)
                ELSE 0
            END as unInvoicedAmount
        FROM receivable_bill_management thisTab
        -- 获取最新开票日期
        LEFT JOIN (
            SELECT head_id, MAX(invoice_time) as latest_invoice_time
            FROM receivable_invoice_business
            WHERE status = 1
            GROUP BY head_id
        ) rib_latest ON thisTab.id = rib_latest.head_id
        -- 获取开票总金额
        LEFT JOIN (
            SELECT head_id, SUM(invoicing_amount) as total_invoice_amount
            FROM receivable_invoice_business
            WHERE status = 1
            GROUP BY head_id
        ) rib_total ON thisTab.id = rib_total.head_id
        <where>
            <if test="systemNo != null  and systemNo != ''"> and thisTab.system_no = #{systemNo}</if>
            <if test="customerName != null  and customerName != ''"> and  thisTab.customer_name like concat('%', #{customerName}, '%')</if>