<?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.community.huiju.dao.TpBillOrderMapper">

    <select id="getBillOrderAll" resultType="com.community.huiju.model.TpBillOrder">
        SELECT
        tbo.*,
        tbs.pay_remark as payRemark,
        tbs.pay_type as payType
        FROM
        tp_bill_order tbo LEFT JOIN tp_bill_statement tbs on tbo.tp_bill_invoice_id = tbs.bill_invoice_id
        LEFT JOIN tp_bill tb on tbo.tp_bill_id = tb.id
        <where>
            <trim prefixOverrides="and | or">
                <if test="map.orderBumber != null">
                    and tbo.order_bumber like CONCAT('%',#{map.orderBumber},'%')
                </if>
                <if test="map.billId != null">
                    and tbo.tp_bill_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 tbo.tp_bill_invoice_id like CONCAT('%',#{map.billInvoiceId},'%')
                </if>
                <if test="map.payPhone != null and map.payPhone != ''">
                    and tbo.pay_phone like CONCAT('%', #{map.payPhone},'%')
                </if>
                <if test="map.communityId != null">
                    and tbo.community_id = #{map.communityId}
                </if>
            </trim>
        </where>
        group by tbo.order_bumber
        order by tbo.create_date DESC
    </select>

</mapper>
