<?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="io.renren.modules.sys.dao.CallBackDao">

    <resultMap type="io.renren.modules.sys.dto.CallBackDTO" id="callBackMap">
        <result property="id" column="id"/>
        <result property="customerId" column="customer_id"/>
        <result property="customerName" column="name"/>
        <result property="mobile" column="mobile"/>
        <result property="companyId" column="company_id"/>
        <result property="callType" column="call_type"/>
        <result property="content" column="content"/>
        <result property="remark" column="remark"/>
        <result property="isPush" column="is_push"/>
        <result property="pushCode" column="push_code"/>
        <result property="pushMsg" column="push_msg"/>
        <result property="pushDate" column="push_date"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="deleteTime" column="delete_time"/>
        <result property="status" column="status"/>
    </resultMap>

	<select id="pageList" parameterType="map" resultMap="callBackMap">
		select * from call_back cb 
		LEFT JOIN customers c ON cb.customer_id = c.id 
		where cb.delete_time is null
		and cb.company_id in
		<foreach collection="params.companyIds" item="companyId" open="(" close=")" separator=",">
			#{companyId}
		</foreach>
		<if test='null != params.name and "" != params.name '>
			AND c.name=#{params.name}
		</if>
		<if test='null != params.mobile and "" != params.mobile '>
			AND c.mobile=#{params.mobile}
		</if>
		<!-- <if test='null != params.companyId and "" != params.companyId '>
			AND c.company_id=#{params.companyId}
		</if> -->
		<if test='null != params.callType and "" != params.callType '>
			AND cb.call_type=#{params.callType}
		</if>
		<if test='null != params.status and "" != params.status '>
			AND cb.status=#{params.status}
		</if>
		<choose>
            <when test="1 == params.callDateType">
            	AND cb.push_date BETWEEN #{params.callStartDate} AND #{params.callEndDate}
            </when>
            <when test="2 == params.callDateType">
            	AND cb.push_date &gt;= #{params.callStartDate} 
            </when>
            <when test="3 == params.callDateType">
            	AND cb.push_date &lt;= #{params.callEndDate} 
            </when>
        </choose>
		<choose>
            <when test="1 == params.entryDateType">
            	AND cb.create_date BETWEEN #{params.entryStartDate} AND #{params.entryEndDate}
            </when>
            <when test="2 == params.entryDateType">
            	AND cb.create_date &gt;= #{params.entryStartDate} 
            </when>
            <when test="3 == params.entryDateType">
            	AND cb.create_date &lt;= #{params.entryEndDate} 
            </when>
        </choose>
        order by cb.create_date desc
	</select>

</mapper>