<?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.project.business.mapper.TcLeadMapper">

    <resultMap type="com.ruoyi.project.business.domain.vo.lead.LeadRes" id="TcLeadResult" extends="TcLeadResultBase">
        <result property="relationAccountNo" column="relationAccountNo"/>
        <result property="relationAccountName" column="relationAccountName"/>
        <result property="relationAccountAreaId" column="relationAccountAreaId"/>
        <result property="relationAccountCountryId" column="relationAccountCountryId"/>
        <result property="relationAccountAgentId" column="relationAccountAgentId"/>
        <result property="ownerName" column="owner_name"/>
        <result property="city" column="city"/>
        <result property="createByNickName" column="createByName"/>
        <!--<result property="projectNo" column="project_no"/>-->
        <result property="countryName" column="country_name"/>
        <result property="areaName" column="area_name"/>
        <result property="ownerAgentName" column="agent_name"/>
        <result property="lastFollowTime" column="lastFollowTime"/>
        <result property="lastFollowResult" column="lastFollowResult"/>
        <result property="follower" column="follower"/>
        
        
<!--        <collection property="tcLeadHistories" -->
<!--                    ofType="tcLeadHistory" -->
<!--                    column="{leadId=lead_id}"-->
<!--                    select="com.ruoyi.project.business.mapper.TcLeadHistoryMapper.selectTcLeadHistoryList"/>-->
        <association property="lastHistory" javaType="tcLeadHistory">
            <id property="id" column="hisId"/>
            <result property="leadId" column="hisLeadId"/>
            <result property="oriUser" column="hisOriUser"/>
            <result property="actionType" column="hisActionType"/>
            <result property="recoveryType" column="hisRecoveryType"/>
            <result property="recoveryReason" column="hisRecoveryReason"/>
            <result property="getUser" column="hisGetUser"/>
            <result property="delFlag" column="hisDelFlag"/>
            <result property="createBy" column="hisCreateBy"/>
            <result property="createTime" column="hisCreateTime"/>
            <result property="updateBy" column="hisUpdateBy"/>
            <result property="updateTime" column="hisUpdateTime"/>
            <result property="remark" column="hisRemark"/>
            
        </association>
    </resultMap>

    <resultMap type="TcLeadForRelated" id="TcLeadResultForRelated" >
        <result property="leadId"    column="lead_id"    />
        <result property="leadNo"    column="lead_no"    />
        <result property="countryId"    column="country_id"    />
        <result property="areaId"    column="area_id"    />
        <result property="accountName"    column="account_name"    />
        <result property="origin"    column="origin"    />
        <result property="contactPerson"    column="contact_person"    />
        <result property="contact"    column="contact"    />
        <result property="email"    column="email"    />
        <result property="address"    column="address"    />
        <result property="company"    column="company"    />
        <result property="requirement"    column="requirement"    />
        <result property="priority"    column="priority"    />
        <result property="status"    column="status"    />
        <result property="owner"    column="owner"    />
        <result property="areaName"    column="area_name"    />
        <result property="createByName"    column="createByName"    />
    </resultMap>

    <resultMap type="com.ruoyi.project.business.domain.vo.lead.LeadRes" id="TcLeadResultBase">
        <result property="leadId" column="lead_id"/>
        <result property="leadNo" column="lead_no"/>
        <result property="countryId" column="country_id"/>
        <result property="areaId" column="area_id"/>
        <result property="origin" column="origin"/>
        <result property="accountName" column="account_name"/>
        <result property="contactPerson" column="contact_person"/>
        <result property="contact" column="contact"/>
        <result property="jobTitle" column="job_title"/>
        <result property="email" column="email"/>
        <!--<result property="sector" column="sector"/>-->
        <result property="address" column="address"/>
        <result property="company" column="company"/>
        <result property="companyType" column="company_type"/>
        <result property="requirement" column="requirement"/>
        <result property="requirementType" column="requirement_type"/>
        <result property="priority" column="priority"/>
        <result property="status" column="status"/>
        <result property="intentionalProduct" column="intentional_product"/>
        <result property="segment" column="segment"/>
        <result property="group" column="group"/>
        <result property="owner" column="owner"/>
        <result property="ownerAgent" column="owner_agent"/>
        <result property="leadTime" column="lead_time"/>
        <result property="type" column="type"/>
        <result property="relativeAccount" column="relative_account"/>
        <!--<result property="relativeProject" column="relative_project"/>-->
        <!--<result property="relativeContract" column="relative_contract"/>-->
        <!--<result property="unvalidReason" column="unvalid_reason"/>-->
        <result property="background" column="background"/>
        <result property="lostRemark" column="lost_remark"/>
        <!--<result property="permissionChar" column="permission_char"/>-->
        <!--<result property="delFlag" column="del_flag"/>-->
        <result property="createTime" column="create_time"/>
        <result property="createBy" column="create_by"/>
        <result property="updateTime" column="update_time"/>
        <!--<result property="updateBy" column="update_by"/>-->
        <result property="remark" column="remark"/>
    </resultMap>

    <sql id="selectTcLeadVo">
        select lead_id,
               lead_no,
               country_id,
               area_id,
               origin,
               account_name,
               contact_person,
               contact,
               job_title,
               email,
               sector,
               address,
               company,
               company_type,
               requirement,
               requirement_type,
               priority,
               status,
               intentional_product,
               segment,
               `group`,
                      `owner`,
                      owner_agent,
                      lead_time,
                      type,
                      city,
                      relative_account,
                      relative_project,
                      relative_contract,
                      unvalid_reason,
                      background,
                      lost_remark,
                      permission_char,
                      del_flag,
                      create_time,
                      create_by,
                      update_time,
                      update_by,
                      remark
        from tc_lead
    </sql>
    
    
    <!--<sql id="selectTcLeadVo">-->
    <!--    select *-->
    <!--    from tc_lead-->
    <!--</sql>-->
    
    <select id="selectTcLeadList" parameterType="com.ruoyi.project.business.domain.vo.lead.LeadListReq" resultMap="TcLeadResult">
        select Temp.* from
        (
        select t.*, 
               an.account_no as relationAccountNo, 
               an.account_name as relationAccountName,
               an.area_id as relationAccountAreaId, 
               an.country_id as relationAccountCountryId,
               an.owner_agent as relationAccountAgentId,
               su.nick_name as owner_name, 
               /*su2.nick_name as create_by_name,*/
               su2.nick_name as createByName,
               tp.project_no,
        CASE #{lan}
        WHEN 'US' THEN tc.country_nameUS
        WHEN 'RU' THEN tc.country_nameRU
        WHEN 'ES' THEN tc.country_nameES
        ELSE tc.country_name END AS country_name,
        CASE #{lan}
        WHEN 'US' THEN tb.area_nameUS
        WHEN 'RU' THEN tb.area_nameRU
        WHEN 'ES' THEN tb.area_nameES
        ELSE tb.area_name   
        END AS area_name,
        ta.agent_name,
        tf.follow_time as lastFollowTime,
        tf.follow_desc as lastFollowResult,
        su3.nick_name as follower,
        tlh.id as hisId,
        tlh.lead_id as hisLeadId,
        tlh.ori_user as hisOriUser,
        tlh.action_type as hisActionType,
        tlh.recovery_type as hisRecoveryType,
        tlh.recovery_reason as hisRecoveryReason,
        tlh.get_user as hisGetUser,
        tlh.del_flag as hisDelFlag,
        tlh.create_by as hisCreateBy,
        tlh.create_time as hisCreateTime,
        tlh.update_by as hisUpdateBy,
        tlh.update_time as hisUpdateTime,
        tlh.remark as hisRemark
        
        from (<include refid="selectTcLeadVo"/>) t
        
        left join sys_user su on su.user_id = t.owner
        left join sys_user su2 on su2.user_id = t.create_by
        left join tc_account an on an.account_id = t.relative_account
        left join tb_agent ta on ta.agent_id = t.owner_agent
        left join tc_project tp on tp.project_id = t.relative_project
        left join tb_area tb on tb.area_id = t.area_id
        left join tb_country tc on tc.country_id = t.country_id
        /*  取最新一条 */
        left join tc_follow tf on tf.business_id = t.lead_id
            and tf.follow_id = (select max(follow_id) from tc_follow where business_id = t.lead_id and follow_type = '0' and del_flag = '0')
        /* 取最新his */
        left join tc_lead_history tlh on tlh.lead_id = t.lead_id
            and tlh.id = (select max(id) from tc_lead_history where lead_id = t.lead_id and del_flag = '0')
        left join sys_user su3 on su3.user_id = tf.create_by
        <where>
            and t.del_flag = 0
            <if test="leadIds != null and leadIds.size() > 0">
                and t.lead_id in
                <foreach collection="leadIds" item="leadId" open="(" separator="," close=")">
                    #{leadId}
                </foreach>
            </if>
            <if test="leadNo != null  and leadNo != ''">and t.lead_no like concat('%',#{leadNo},'%')</if>
            <!--<if test="countryId != null ">and t.country_id = #{countryId}</if>-->
            <if test="countryId != null and countryId.size() > 0">
                and t.country_id in
                <foreach collection="countryId" item="cId" open="(" separator="," close=")">
                    #{cId}
                </foreach>
            </if>
            <if test="areaId != null and areaId.size() > 0">
                and t.area_id in
                <foreach collection="areaId" item="aid" open="(" separator="," close=")">
                    #{aid}
                </foreach>
            </if>
            <if test="city != null and city != ''">and t.city like concat('%',#{city},'%')</if>
            <if test="origin != null and origin.size() > 0">
                and t.origin in
                <foreach collection="origin" item="ori" open="(" separator="," close=")">
                    #{ori}
                </foreach>
            </if>
            <if test="contact != null  and contact != ''">and t.contact like concat('%',#{contact},'%')</if>
            <if test="email != null  and email != ''">and t.email = #{email}</if>
            <if test="address != null  and address != ''">and t.address like concat('%',#{address},'%')</if>
            <if test="sector != null and sector.size() > 0">
                and t.sector in
                <foreach collection="sector" item="sec" open="(" separator="," close=")">
                    #{sec}
                </foreach>
            </if>

            <if test="company != null  and company != ''">and t.company like concat('%',#{company},'%')</if>
            <if test="requirement != null  and requirement != ''">and t.requirement like concat('%',#{requirement},'%')
            </if>
            <if test="priority != null and priority.size() > 0">
                and t.priority in
                <foreach collection="priority" item="pri" open="(" separator="," close=")">
                    #{pri}
                </foreach>
            </if>

            <if test="status != null and status.size() > 0">
                and t.status in
                <foreach collection="status" item="sta" open="(" separator="," close=")">
                    #{sta}
                </foreach>
            </if>
            <if test="owner != null ">and t.owner = #{owner}</if>
            <if test="ownerName != null ">and su.nick_name like concat('%',#{ownerName},'%')</if>
            <if test="ownerAgent != null and ownerAgent.size() > 0">
                and t.owner_agent in
                <foreach collection="ownerAgent" item="oa" open="(" separator="," close=")">
                    #{oa}
                </foreach>
            </if>
            <if test="createByNickName != null ">and su2.nick_name like concat('%',#{createByNickName},'%')</if>
            <if test="type != null  and type != ''">and t.type = #{type}</if>
            <if test="accountNo != null and accountNo != ''">and an.account_no like concat('%',#{accountNo},'%')</if>
            <if test="relativeAccount != null ">and t.relative_account = #{relativeAccount}</if>
            <if test="relativeProject != null ">and relative_project = #{relativeProject}</if>
            <if test="relativeContract != null ">and relative_contract = #{relativeContract}</if>
            <if test="unvalidReason != null  and unvalidReason != ''">and unvalid_reason = #{unvalidReason}</if>
            <if test="loginUserId != null  and loginUserId != ''">
                and (t.permission_char &lt;&gt; #{permission} or t.owner = #{loginUserId})
            </if>
            <if test="companyType != null and companyType.size() > 0">
                and t.company_type in
                <foreach collection="companyType" item="company" open="(" separator="," close=")">
                    #{company}
                </foreach>
            </if>
            <if test="requirementType != null and requirementType.size() > 0">
                and t.requirement_type in
                <foreach collection="requirementType" item="requirement" open="(" separator="," close=")">
                    #{requirement}
                </foreach>
            </if>
            <if test="lastFollowResult != null and lastFollowResult != ''">
                and tf.follow_desc like concat('%',#{lastFollowResult},'%')
            </if>
            <if test="follower != null and follower != ''">
                and su3.nick_name like concat('%',#{follower},'%')
            </if>
            <if test="intentionalProduct != null and intentionalProduct.size() > 0">
                and t.intentional_product in
                <foreach collection="intentionalProduct" item="product" open="(" separator="," close=")">
                    #{product}
                </foreach>
            </if>
            <if test="segment != null and segment.size() > 0">
                and t.segment in
                <foreach collection="segment" item="seg" open="(" separator="," close=")">
                    #{seg}
                </foreach>
            </if>
            <if test="accountName != null and accountName != ''">
                and t.account_name like concat('%',#{accountName},'%')
            </if>
            <if test="beginTime != null and endTime != null">
                and t.create_time between #{beginTime} and #{endTime}
            </if>
        </where>
        ) Temp inner join (
        SELECT p.premession_char FROM (SELECT @premessionStr := #{permissionChar} p) param , getpremessionview_chars p
        ) permission
        on permission.premession_char = Temp.permission_char
        order by Temp.lead_id desc
    </select>
    <select id="selectLeadListByLoginId" parameterType="java.lang.Long" resultMap="TcLeadResultForRelated">
        SELECT
        lead_id,
        lead_no,
        country_id,
        t1.area_id,
        account_name,
        origin,
        contact_person,
        contact,
        email,
        address,
        company,
        requirement,
        priority,
        OWNER,
        tb1.area_name
        FROM
        tc_lead t1
        left join tb_area tb1 on tb1.area_id = t1.area_id
        WHERE t1.del_flag = 0
          and t1.status in ('1', '2', '3', '4')
          and t1.OWNER = #{loginId}
    </select>

    <select id="selectLeadListByLeadId" parameterType="TcLeadForRelated" resultMap="TcLeadResultForRelated">
        SELECT
            lead_id,
            lead_no,
            country_id,
            t1.area_id,
            account_name,
            origin,
            contact_person,
            contact,
            email,
            address,
            company,
            requirement,
            priority,
            OWNER,
            CASE #{language}
                WHEN 'english' THEN tb1.area_nameUS
                WHEN 'russia' THEN tb1.area_nameRU
                WHEN 'spanish' THEN tb1.area_nameES
                ELSE tb1.area_name
            END AS area_name
        FROM
            tc_lead t1
            LEFT JOIN tb_area tb1 ON tb1.area_id = t1.area_id
        WHERE 1 = 1
        <if test="leadId != null  and leadId != ''"> and t1.lead_id = #{leadId} </if>
    </select>

    <select id="selectLeadListByQuery" parameterType="TcLeadForRelated" resultMap="TcLeadResultForRelated">
        SELECT
        lead_id,
        lead_no,
        country_id,
        t1.area_id,
        account_name,
        origin,
        contact_person,
        contact,
        email,
        address,
        company,
        requirement,
        priority,
        OWNER,
        CASE #{language}
            WHEN 'english' THEN tb1.area_nameUS
            WHEN 'russia' THEN tb1.area_nameRU
            WHEN 'spanish' THEN tb1.area_nameES
            ELSE tb1.area_name
        END AS area_name
        FROM
        tc_lead t1
        LEFT JOIN tb_area tb1 ON tb1.area_id = t1.area_id
        WHERE t1.del_flag = 0
        and t1.OWNER = #{loginId}
        and t1.status not in ('8')
        <if test="query != null  and query != ''">
            and  (
                t1.lead_no like concat('%',#{query},'%') or
                tb1.area_name like concat('%',#{query},'%') or
                tb1.area_nameUS like concat('%',#{query},'%') or
                tb1.area_nameRU like concat('%',#{query},'%') or
                tb1.area_nameES like concat('%',#{query},'%') or
                t1.contact_person like concat('%',#{query},'%') or
                t1.account_name like concat('%',#{query},'%')
            )
        </if>
    </select>

    <select id="selectTcLeadByLeadId" parameterType="Long" resultMap="TcLeadResult">
        select t.*, su.nick_name as owner_name, ta.agent_name, su3.nick_name as follower
        from tc_lead t
        left join sys_user su on su.user_id = t.owner
        left join tb_agent ta on ta.agent_id = t.owner_agent
        left join tc_follow tf on tf.business_id = t.lead_id
            and tf.follow_id = (select max(follow_id) from tc_follow where business_id = t.lead_id and follow_type = '0' and del_flag = '0')
        left join sys_user su3 on su3.user_id = tf.create_by
        where lead_id = #{leadId} and t.del_flag = 0
    </select>

    <select id="selectLeadListByAccount" parameterType="com.ruoyi.project.business.domain.vo.lead.LeadRelatedQueryReq" resultMap="TcLeadResultForRelated">
        select l.*, u.nick_name as createByName,
        CASE #{language}
        WHEN 'english' THEN a.area_nameUS
        WHEN 'russia' THEN a.area_nameRU
        WHEN 'spanish' THEN a.area_nameES
        ELSE a.area_name
        END AS area_name
        from tc_lead l
        left join tb_area a on a.area_id = l.area_id and a.del_flag = '0'
        left join sys_user u on u.user_id = l.create_by
        where l.relative_account = #{relativeAccount} and l.del_flag = '0'
        <if test="hasProjectFlag != null and hasProjectFlag != ''">
            and l.relative_account is null
        </if>
        order by l.lead_id desc
    </select>

    <select id="selectLeadsFromMarketAndUnassigned" resultType="TcLead">
        select t.*
        from tc_lead t
        where t.del_flag = 0
          and t.owner is null
          and t.origin = '1'
          and t.status &lt;&gt; '99'
    </select>

    <select id="selectLeadListByAccountId" resultMap="TcLeadResult">
        select l.lead_id, l.lead_no, l.company, l.contact_person, l.sector, a.area_name
        from tc_lead l
        left join tb_area a on l.area_id = a.area_id
        where l.del_flag = 0 and l.relative_account = #{accountId}
    </select>
    <select id="selectLeadListByProjectId" resultMap="TcLeadResult">
        select l.lead_id, l.lead_no, l.company, l.contact_person, l.sector, a.area_name
        from tc_lead l
        left join tb_area a on l.area_id = a.area_id
        where l.del_flag = 0 and l.relative_project = #{projectId}
    </select>
    <select id="curAgent" resultType="com.ruoyi.project.business.domain.vo.lead.LeadRes">
        select distinct Temp.ownerAgent, Temp.ownerAgentName
        from (select tl.owner_agent as ownerAgent, tl.permission_char, ta.agent_name as ownerAgentName
              from tc_lead tl
                       join tb_agent ta on tl.owner_agent = ta.agent_id and tl.del_flag = 0 and ta.del_flag = 0) Temp
                 inner join (SELECT p.premession_char
                             FROM (SELECT @premessionStr := #{permissionChar} p) param,
                                  getpremessionview_chars p) permission
                            on permission.premession_char = Temp.permission_char
    </select>
    <select id="selectLeadCountStat" resultType="com.ruoyi.project.business.domain.TcLead">
        select Temp.*
        from (select create_time, permission_char
              from tc_lead
              where del_flag = 0
                and create_time BETWEEN #{startDate} AND #{endDate}) Temp
                 inner join (SELECT p.premession_char
                             FROM (SELECT @premessionStr := #{permissionChar} p) param,
                                  getpremessionview_chars p) permission
                            on permission.premession_char = Temp.permission_char
    </select>

    <select id="selectCountByCountryIds" resultType="java.lang.Integer">
        select count(1) from tc_lead where country_id in
        <foreach collection="countryIds" item="countryId" open="(" separator="," close=")">
            #{countryId}
        </foreach>
    </select>
    <select id="listByCurUser" parameterType="com.ruoyi.project.business.domain.vo.lead.LeadForAccountReq"
            resultMap="TcLeadResult">
        select Temp.*
        from (select l.lead_id, l.lead_no, l.company, l.contact_person, l.permission_char,
        CASE #{language}
        WHEN 'english' THEN a.area_nameUS
        WHEN 'russia' THEN a.area_nameRU
        WHEN 'spanish' THEN a.area_nameES
        ELSE a.area_name
        END AS area_name,
        l.area_id, l.country_id, l.company_type, background, `group`,segment, intentional_product, l.contact, l.email, l.job_title
        from tc_lead l
        left join tb_area a on a.area_id = l.area_id
        where l.del_flag = 0
        and l.owner = #{owner}
        and l.status = '4'
        <if test="relativeAccount != null and relativeAccount != ''">
            or l.relative_account = #{relativeAccount}
        </if>
        ) Temp
        inner join (SELECT p.premession_char FROM (SELECT @premessionStr := #{permissionChar} p) param , getpremessionview_chars p) permission
        on permission.premession_char = Temp.permission_char
        <where>
            <if test="leadNo != null and leadNo != ''">
                 Temp.lead_no like concat('%',#{leadNo},'%')
                 or Temp.area_name like concat('%',#{leadNo},'%')
                 or Temp.company like concat('%',#{leadNo},'%')
                 or Temp.contact_person like concat('%',#{leadNo},'%')
            </if>
        </where>
    </select>
    <select id="curCountry" resultType="com.ruoyi.project.business.domain.vo.lead.LeadRes">
        select distinct Temp.countryId, Temp.country_name
        from (select tl.country_id as countryId, tl.permission_char, 
                     CASE #{lan}
                     WHEN 'US' THEN c.country_nameUS
                     WHEN 'RU' THEN c.country_nameRU
                     WHEN 'ES' THEN c.country_nameES
                     ELSE c.country_name
                     END AS country_name
              from tc_lead tl
                       join tb_country c on c.country_id = tl.country_id and tl.del_flag = 0 and c.del_flag = 0) Temp 
                 inner join (SELECT p.premession_char FROM (SELECT @premessionStr := #{permissionChar} p) param , getpremessionview_chars p) permission
                            on permission.premession_char = Temp.permission_char
    </select>
    <select id="curCountry2" resultType="com.ruoyi.project.business.domain.vo.lead.LeadRes">
        select distinct tl.country_id as countryId, tl.permission_char,
               CASE #{lan}
                   WHEN 'US' THEN c.country_nameUS
                   WHEN 'RU' THEN c.country_nameRU
                   WHEN 'ES' THEN c.country_nameES
                   ELSE c.country_name
                   END AS country_name
        from tc_lead tl
                 join tb_country c on c.country_id = tl.country_id and tl.del_flag = 0 and c.del_flag = 0
    </select>


    <!--<update id="updateFollowStatusByLeadId">-->
    <!--    update tc_lead set  status = '4'-->
    <!--    where status in ('1', '2', '3', '4')-->
    <!--          and lead_id = #{leadId}-->
    <!--</update>-->

    <update id="resetAccountId">
        update tc_lead set relative_account = null, status = '4', update_time = now()
        where relative_account = #{accountId}
    </update>

    <update id="resetAccountIds">
        update tc_lead set relative_account = null, status = '4', update_time = now()
        where relative_account in
        <foreach item="accountId" collection="accountIds" open="(" separator="," close=")">
            #{accountId}
        </foreach>
    </update>

    <delete id="deleteTcLeadByLeadId" parameterType="Long">
        update tc_lead set del_flag = 1 where lead_id = #{leadId}
    </delete>

    <select id="selectAreaIdsByCurUser" resultType="java.lang.Long">
        select distinct a.area_id
        from tc_lead a
                 inner join (SELECT p.premession_char
                             FROM (SELECT @premessionStr := #{permissionChar} p) param,
                                  getpremessionview_chars p) permission
                            on permission.premession_char = a.permission_char
        where a.del_flag = '0'
    </select>
    
    <select id="selectCountryIdsByCurUser" resultType="java.lang.Long">
        select distinct a.country_id
        from tc_lead a
                 inner join (SELECT p.premession_char
                             FROM (SELECT @premessionStr := #{permissionChar} p) param,
                                  getpremessionview_chars p) permission
                            on permission.premession_char = a.permission_char
        where a.del_flag = '0'
    </select>

    <select id="suppleProjectExportVO" parameterType="com.ruoyi.project.business.domain.vo.lead.LeadRelatedQueryReq" resultMap="TcLeadResultForRelated">
        select l.*, u.nick_name as createByName,
        CASE #{language}
        WHEN 'english' THEN a.area_nameUS
        WHEN 'russia' THEN a.area_nameRU
        WHEN 'spanish' THEN a.area_nameES
        ELSE a.area_name
        END AS area_name
        from tc_lead l
        left join tb_area a on a.area_id = l.area_id and a.del_flag = '0'
        left join sys_user u on u.user_id = l.create_by
        where l.del_flag = '0'
          and l.relative_account  in
          <foreach collection="accountIdList" item="item" open="(" separator="," close=")">
              #{item}
          </foreach>
        order by l.lead_id desc
    </select>

</mapper>