<?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.dsk.system.mapper.CustomerFollowRecordMapper">

    <sql id="Base_Bean">
        cfr.id, cfr.customer_id, cfr.user_id, cfr.visit_mode, cfr.visit_time, cfr.next_visit_time, cfr.name, cfr.position,
        cfr.content, cfr.create_time
    </sql>

    <select id="selectAuthList" resultType="com.dsk.system.domain.customer.vo.CustomerFollowRecordListVo">
        select
            ct.company_id, ct.uip_id, ct.company_name, u.nick_name,
            <include refid="Base_Bean"></include>
        from customer_follow_record cfr
        join customer ct on ct.customer_id = cfr.customer_id
        join sys_user u on u.user_id = cfr.user_id
        left join sys_dept d on d.dept_id = u.dept_id
        <where>
            <if test="userId != null "> and cfr.user_id = #{userId} </if>
            <if test="customerId != null and customerId != '' "> and cfr.customer_id = #{customerId} </if>
            <if test="startTime != null and startTime != '' "> and cfr.visit_time &gt;= #{startTime} </if>
            <if test="endTime != null and endTime != '' "> and cfr.visit_time &lt;= #{endTime} </if>
            <!-- 数据范围过滤 -->
            <if test="params.dataScope != null and params.dataScope != '' "> ${params.dataScope} </if>
        </where>
        order by cfr.create_time desc
    </select>

</mapper>

