<?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.huyi.service.bill.mapper.OwnBillMapper">

    <select id="selectBillInfList" parameterType="map" resultType="map">
        SELECT
            b.zbi_id		        'zbiId',
            b.zbi_number		    'zbiNumber',
            b.zbi_name		        'zbiName',
            b.zbi_contract_no	    'zbiContractNo',
            b.zbi_amount		    'zbiAmount',
            b.zbi_date		        'zbiDate',
            b.zbi_pay_date	        'zbiPayDate',
            r.scy_name		        'payerName',
            e.scy_name		        'payeeName',
            f.zfi_number            'zfiNumber',
            b.zbi_status            'zbiStatus',
            (case when b.zbi_payer_id = #{paramMap.companyId} then '00' else '01' end) 'zbiType'
        FROM
            zc_bill_inf b
        LEFT JOIN zc_finance_bill_rel rel
            ON rel.zfbr_bill_id = b.zbi_id
        LEFT JOIN zc_finance_inf f
            ON rel.zfbr_finance_id = f.zfi_id
        LEFT JOIN sys_company r
            ON r.scy_id = b.zbi_payer_id
        LEFT JOIN sys_company e
            ON e.scy_id = b.zbi_payee_id
        WHERE b.zbi_status != '99'
        <if test="paramMap.companyId != null  and paramMap.companyId != ''">
            and (b.zbi_payer_id = #{paramMap.companyId} or b.zbi_payee_id = #{paramMap.companyId})
        </if>
        <if test="paramMap.payerId != null  and paramMap.payerId != ''">
            and b.zbi_payer_id = #{paramMap.payerId}
        </if>
        <if test="paramMap.payeeId != null  and paramMap.payeeId != ''">
            and b.zbi_payee_id = #{paramMap.payeeId}
        </if>
        <if test="paramMap.zbiNumber != null  and paramMap.zbiNumber != ''">
            and b.zbi_number like concat('%', #{paramMap.zbiNumber}, '%')
        </if>

        <if test="paramMap.zbiName != null  and paramMap.zbiName != ''">
            and b.zbi_name like concat('%', #{paramMap.zbiName}, '%')
        </if>

        <if test="paramMap.payerName != null  and paramMap.payerName != ''">
            and r.scy_name like concat('%', #{paramMap.payerName}, '%')
        </if>

        <if test="paramMap.payeeName != null  and paramMap.payeeName != ''">
            and e.scy_name like concat('%', #{paramMap.payeeName}, '%')
        </if>
        <if test="paramMap.zbiStatus != null  and paramMap.zbiStatus != ''">
            and b.zbi_status = #{paramMap.zbiStatus}
        </if>
        order by b.create_time desc

    </select>




</mapper>