<?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.ruoyi.web.work.mapper.RelateMapper">
    
    <select id="selectList" resultType="com.ruoyi.web.work.domain.Relate">
        SELECT
        r.*,
        c.name,c.alipay,c.phone,c.is_contract,c.id_card
        FROM tb_relate r
        LEFT JOIN tb_user c ON c.id = r.user_id
        <where>  
            <if test="companyId != null "> and r.company_id = #{companyId}</if>
            <if test="name != null  and name != ''"> and c.name like concat('%', #{name}, '%')</if>
            <if test="phone != null  and phone != ''"> and c.phone like concat('%', #{phone}, '%')</if>
            <if test="idCard != null  and idCard != ''"> and c.id_card like concat('%', #{idCard}, '%')</if>
        </where>
    </select>

    <select id="selectRelateCompanyList" resultType="com.ruoyi.web.work.domain.vo.RelateCompanyListVo">
        SELECT
        r.*,
        c.company_name
        FROM tb_relate r
        LEFT JOIN tb_company c ON c.id = r.company_id
        WHERE r.user_id =#{userId}
        ORDER BY r.id DESC
    </select>

</mapper>