<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.huiju.estateagents.property.dao.BillStatementMapper">

    <select id="getBillStatementAll" resultType="com.huiju.estateagents.property.model.BillStatement">
        SELECT
            tbs.*,
            tb.id as billId,
            tb.bill_name as billName
        FROM
            tp_bill_statement tbs
        LEFT JOIN tp_bill_invoice tbi ON tbs.bill_invoice_id = tbi.id
        LEFT JOIN tp_bill tb ON tbi.bill_id = tb.id
        <where>
            <trim prefixOverrides="and | or">
                <if test="map.id != null">
                    and tbs.id like CONCAT('%',#{map.id},'%')
                </if>
                <if test="map.billId != null">
                    and tb.id like CONCAT('%',#{map.billId},'%')
                </if>
                <if test="map.billName != null and map.billName != ''">
                    and tb.bill_name like CONCAT('%',#{map.billName},'%')
                </if>
                <if test="map.billInvoiceId != null">
                    and tbs.bill_invoice_id like CONCAT('%',#{map.billInvoiceId},'%')
                </if>
                <if test="map.payName != null and map.payName != ''">
                    and tbs.pay_name like CONCAT('%', #{map.payName},'%')
                </if>
                <if test="map.orgId != null">
                    and tbs.org_id = #{map.orgId}
                </if>
            </trim>
        </where>
        order by tbs.create_time DESC
    </select>

</mapper>
