<?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.supplierCreditLine.mapper.SupplierCreditLineMapper">

    <select id="selectSupplierCreditLineList" parameterType="map" resultType="map">
        SELECT
        zfsq_id         'zfsqId',
        zfsq_amount     'zfsqAmount',
        zfsq_status     'zfsqStatus',
        scy_name        'scyName',
        scy_social_code 'scySocialCode'
        FROM zc_finance_supplier_quota
        LEFT JOIN sys_company ON scy_id = zfsq_company_id
        WHERE 1=1
        and zfsq_core_quota_id = #{paramMap.zfsqId}
        and zfsq_status !='99'
        <if test="paramMap.scyName != null  and paramMap.scyName != ''">
            and scy_name like concat('%', #{paramMap.scyName}, '%')
        </if>
        <if test="paramMap.AmountA != null  and paramMap.AmountA != ''">
            and zfpcr_amount &gt;= #{paramMap.AmountA}
        </if>
        <if test="paramMap.AmountB != null  and paramMap.AmountB != ''">
            and zfpcr_amount &lt;=  #{paramMap.AmountB}
        </if>
        <if test="paramMap.zfpcrStatus != null  and paramMap.zfpcrStatus != ''">
            and zfpcr_status = #{paramMap.zfpcrStatus}
        </if>
        order by zc_finance_supplier_quota.create_time desc
    </select>

    <select id="selectSupplierCreditLineDetail" parameterType="map" resultType="map">
        SELECT
        zfsq_id         'zfsqId',
        zfsq_company_id 'zfsqCompanyId',
        zfsq_amount     'zfsqAmount',
        zfsq_status     'zfsqStatus',
        scy_name        'scyName',
        scy_social_code 'scySocialCode'
        FROM zc_finance_supplier_quota
        LEFT JOIN sys_company ON scy_id = zfsq_company_id
        WHERE 1=1
        and zfsq_id = #{paramMap.zfsqId}
    </select>

    <select id="listCompanyRel" parameterType="map" resultType="map">
        (SELECT
            scy_id			    'scyId',
            r.scr_status		'scrStatus',
            scy_name		    'scyName',
            scy_social_code		'scySocialCode',
            scy_address		    'scyAddress',
            scy_phone		    'scyPhone',
            scy_legal		    'scyLegal',
            scy_type		    'scyType',
            r.create_time		'createTime'
        FROM sys_company_rel r
        LEFT JOIN sys_company ON r.scr_launch_company_id = scy_id
        WHERE scy_status = '00'
        AND scr_receive_company_id = #{paramMap.companyId}
        AND scr_launch_type = '00'
        ORDER BY r.create_time DESC)
        UNION
        (SELECT
            scy_id			    'scyId',
            r.scr_status		'scrStatus',
            scy_name		    'scyName',
            scy_social_code		'scySocialCode',
            scy_address		    'scyAddress',
            scy_phone		    'scyPhone',
            scy_legal		    'scyLegal',
            scy_type		    'scyType',
            r.create_time		'createTime'
        FROM sys_company_rel r
        LEFT JOIN sys_company ON r.scr_receive_company_id = scy_id
        WHERE scy_status = '00'
        AND scr_launch_company_id = #{paramMap.companyId}
        AND scr_receive_type = '00'
        ORDER BY r.create_time DESC)
    </select>
</mapper>