<?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_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="dto.userId != null "> and cfr.user_id = #{dto.userId} </if>
            <if test="dto.customerId != null and dto.customerId != '' "> and cfr.customer_id = #{dto.customerId} </if>
            <!-- 数据范围过滤 -->
            <if test="dto.params.dataScope != null and dto.params.dataScope != '' "> ${dto.params.dataScope} </if>
        </where>
        order by cfr.create_time desc
    </select>

</mapper>

