<?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.common.company.mapper.CompanyMapper">

    <select id="selectCompanyList" parameterType="map" resultType="map">
        SELECT
            scy_id              'scyId',
            scy_name            'scyName',
            scy_social_code     'scySocialCode',
            CASE  WHEN scy_id= #{paramMap.scyId}  THEN 0  ELSE  1  END  'flag'
        FROM
        sys_company
        WHERE 1=1
        and scy_type = #{paramMap.scyType}
        <if test="paramMap.scyId != null  and paramMap.scyId != ''">
            AND (scy_id= #{paramMap.scyId} OR scy_status = '00')
        </if>
        <if test="paramMap.scyId == null  or paramMap.scyId == ''">
            AND scy_status = '00'
        </if>
        order by flag asc ,create_time desc
    </select>

    <select id="selectCompanyRelList" parameterType="map" resultType="map">
        SELECT
        r.scr_id                'launchScrId',
        r.scr_launch_company_id 'launchCompanyId',
        r.scr_receive_company_id'launchReceiveScrCompanyId',
        r.scr_status		    'launchScrStatus',
        r.scr_contarct          'launchScrContarct',
        r.scr_contarct_phone    'launchScrContarctPhone',
        r.scr_contarct_email    'launchScrContarctEmail',
        r.scr_launch_type       'launchScrLaunchType',
        r.scr_receive_type      'launchScrReceiveType',
        s.scy_id		        'launchScyId',
        s.scy_social_code	    'launchScySocialCode',
        s.scy_name		        'launchScyName',
        s.scy_type		        'launchScyType',
        s.scy_legal		        'launchScyLegal',
        s.scy_phone		        'launchScyPhone',
        p.scy_id		        'receiveScyId',
        p.scy_social_code	    'receiveScySocialCode',
        p.scy_name		        'receiveScyName',
        p.scy_type		        'receiveScyType',
        p.scy_legal		        'receiveScyLegal',
        p.scy_phone		        'receiveScyPhone'
        FROM sys_company_rel r
        LEFT JOIN sys_company s ON r.scr_launch_company_id = s.scy_id
        LEFT JOIN sys_company p ON r.scr_receive_company_id = p.scy_id
        WHERE 1=1
        <if test="paramMap.companyId != null and paramMap.companyId != '' ">
            AND (r.scr_launch_company_id = #{paramMap.companyId} OR r.scr_receive_company_id = #{paramMap.companyId})
        </if>
        <if test="paramMap.companyName != null and paramMap.companyName != '' ">
            AND (s.scy_name LIKE CONCAT('%', #{paramMap.companyName}, '%') OR p.scy_name LIKE CONCAT('%', #{paramMap.companyName}, '%'))
        </if>
        AND r.scr_status != '99'
        ORDER BY r.create_time DESC
    </select>
</mapper>