<?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.crm.manager.dao.mapper.SalesLeaderMapper">
    <select id="countList" resultType="integer"
            parameterType="com.crm.rely.backend.core.entity.sales.SalesLeaderSearchEntity">
        select count(*) from sales_leader sl
        left join user_info info on sl.sales_no = info.ib_no
        <where>
            <if test="salesNo != null and salesNo != ''">
                and sl.`sales_no` = #{salesNo}
            </if>
            <if test="cId != null">
                and info.`c_id` = #{cId}
            </if>
        </where>
    </select>

    <select id="pageList" resultType="com.crm.rely.backend.core.pojo.view.SalesLeaderListview"
            parameterType="com.crm.rely.backend.core.entity.sales.SalesLeaderSearchEntity">
        select sl.*,info.c_id,info.username,info.name,info.email
        from sales_leader sl
        left join user_info info on sl.sales_no = info.ib_no
        <where>
            <if test="salesNo != null and salesNo != ''">
                and sl.`sales_no` = #{salesNo}
            </if>
            <if test="cId != null">
                and info.`c_id` = #{cId}
            </if>
        </where>
        order by sl.id desc
        <if test="page != null">
            limit #{page.offset},#{page.row}
        </if>
    </select>

    <select id="searchExtraIbNo" resultType="com.crm.rely.backend.core.pojo.view.SalesLeaderListview">
        select extra.type,extra.sales_date,
               info.ib_no salesNo,info.c_id,info.username,info.name,info.email,info.role_id
        from sales_leader_extra extra
        left join user_info info on extra.sales_no = info.ib_no
        where extra.leader_sales_no = #{salesNo}
        order by extra.type asc
    </select>

</mapper>