<?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.CustomersDao">

    <resultMap type="io.renren.modules.sys.dto.CustomersDTO" id="customersMap">
        <result property="id" column="id"/>
        <result property="name" column="name"/>
        <result property="sex" column="sex"/>
        <result property="mobile" column="mobile"/>
        <result property="telLocation" column="tel_location"/>
        <result property="age" column="age"/>
        <result property="cardNo" column="card_no"/>
        <result property="operationId" column="operation_id"/>
        <result property="channelId" column="channel_id"/>
        <result property="companyId" column="company_id"/>
        <result property="pageId" column="page_id"/>
        <result property="ip" column="ip"/>
        <result property="leadsArea" column="leads_area"/>
        <result property="city" column="city"/>
        <result property="url" column="url"/>
        <result property="isPush" column="is_push"/>
        <result property="pushMsg" column="push_msg"/>
        <result property="pushDate" column="push_date"/>
        <result property="returnMsg" column="return_msg"/>
        <result property="address" column="address"/>
        <result property="bundle" column="bundle"/>
        <result property="isMarried" column="is_married"/>
        <result property="education" column="education"/>
        <result property="professional" column="professional"/>
        <result property="employmentTime" column="employment_time"/>
        <result property="monthlyIncome" column="monthly_income"/>
        <result property="payrollType" column="payroll_type"/>
        <result property="money" column="money"/>
        <result property="useFor" column="use_for"/>
        <result property="loanLongTime" column="loan_long_time"/>
        <result property="creditSituation" column="credit_situation"/>
        <result property="isCredit" column="is_credit"/>
        <result property="shebao" column="shebao"/>
        <result property="gongjijin" column="gongjijin"/>
        <result property="car" column="car"/>
        <result property="carType" column="car_type"/>
        <result property="carModel" column="car_model"/>
        <result property="carLife" column="car_life"/>
        <result property="baodanIs" column="baodan_is"/>
        <result property="zmScore" column="zm_score"/>
        <result property="weili" column="weili"/>
        <result property="businessLicense" column="business_license"/>
        <result property="house" column="house"/>
        <result property="houseType" column="house_type"/>
        <result property="houseSize" column="house_size"/>
        <result property="houseLife" column="house_life"/>
        <result property="shopName" column="shop_name"/>
        <result property="shopAddress" column="shop_address"/>
        <result property="leadsEmail" column="leads_email"/>
        <result property="leadsQq" column="leads_qq"/>
        <result property="leadsWechat" column="leads_wechat"/>
        <result property="status" column="status"/>
        <result property="remark" column="remark"/>
        <result property="accountId" column="account_id"/>
        <result property="accountName" column="account_name"/>
        <result property="adgroupId" column="adgroup_id"/>
        <result property="adgroupName" column="adgroup_name"/>
        <result property="adsId" column="ads_id"/>
        <result property="adsName" column="ads_name"/>
        <result property="creativeId" column="creative_id"/>
        <result property="creativeName" column="creative_name"/>
        <result property="creator" column="creator"/>
        <result property="createDate" column="create_date"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="deleteTime" column="delete_time"/>
        <result property="transId" column="trans_id"/>
    </resultMap>

	<select id="pageList" parameterType="map" resultMap="customersMap">
		select * from customers c 
		LEFT JOIN call_back b ON c.id = b.customer_id and c.company_id = b.company_id 
		where c.delete_time is null
		and c.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.channelId and "" != params.channelId '>
			AND c.channel_id=#{params.channelId}
		</if>
		<if test='null != params.pageId and "" != params.pageId '>
			AND c.page_id=#{params.pageId}
		</if>
		<!-- <if test='null != params.companyId and "" != params.companyId '>
			AND c.company_id=#{params.companyId}
		</if> -->
		<choose>
            <when test="1 == params.dateType">
            	AND c.create_date BETWEEN #{params.startDate} AND #{params.endDate}
            </when>
            <when test="2 == params.dateType">
            	AND c.create_date &gt;= #{params.startDate} 
            </when>
            <when test="3 == params.dateType">
            	AND c.create_date &lt;= #{params.endDate} 
            </when>
        </choose>
        <if test='null != params.callType and "" != params.callType '>
			AND b.call_type=#{params.callType}
		</if>
        <if test='null != params.isPush and "" != params.isPush '>
			AND c.is_push=#{params.isPush}
		</if>
		order by c.create_date desc
	</select>
</mapper>
