<?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.rel.mapper.OwnCompanyRelMapper">

    <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>
        <if test="paramMap.scySocialCode != null and paramMap.scySocialCode != '' ">
            AND (s.scy_social_code LIKE CONCAT('%', #{paramMap.scySocialCode}, '%') OR p.scy_social_code LIKE CONCAT('%', #{paramMap.scySocialCode}, '%'))
        </if>
        <if test="paramMap.scrType != null and paramMap.scrType != '' and paramMap.scrType == '00' ">
            AND ((r.scr_launch_company_id = #{paramMap.companyId} AND r.scr_launch_type = '01')
            OR (r.scr_receive_company_id = #{paramMap.companyId} AND r.scr_receive_type = '01'))
        </if>
        <if test="paramMap.scrType != null and paramMap.scrType != '' and paramMap.scrType == '01' ">
            AND ((r.scr_launch_company_id = #{paramMap.companyId} AND r.scr_launch_type = '00')
            OR (r.scr_receive_company_id = #{paramMap.companyId} AND r.scr_receive_type = '00'))
        </if>
        <if test="paramMap.scrStatus != null and paramMap.scrStatus != '' ">
            AND r.scr_status = #{paramMap.scrStatus}
        </if>
        AND r.scr_status != '99'
        ORDER BY r.create_time DESC
    </select>
</mapper>
