<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
        "http://ibatis.apache.org/dtd/sql-map-2.dtd">
<sqlMap namespace="com.house365.beans.entity.CustomerEntity">
    <typeAlias alias="customerEntity" type="com.house365.beans.entity.CustomerEntity"/>

    <resultMap id="customer" class="com.house365.beans.entity.CustomerEntity">
        <result property="id" column="id"/>
        <result property="name" column="name"/>
        <result property="phone" column="phone"/>
        <result property="bakPhone1" column="bak_phone1"/>
        <result property="bakPhone2" column="bak_phone2"/>
        <result property="bakPhone3" column="bak_phone3"/>
        <result property="sex" column="sex"/>
        <result property="customerType" column="customer_type"/>
        <result property="actSource" column="act_source"/>
        <result property="firstSource" column="first_source"/>
        <result property="latestSource" column="latest_source"/>
        <result property="crmLatestCall" column="crm_latest_call"/>
        <result property="crmLatestCallResult" column="crm_latest_call_result"/>
        <result property="status" column="status"/>
        <result property="createSource" column="create_source"/>
        <result property="createTime" column="create_time"/>
        <result property="creater" column="creater"/>
        <result property="buyIntention" column="buy_intention"/>
        <result property="lastVisitTime" column="last_visit_time"/>
        <result property="lastCallTime" column="last_call_time"/>
        <result property="managerId" column="manager_id"/>
        <result property="managerName" column="manager_name"/>
        <result property="updateTime" column="update_time"/>
        <result property="updater" column="updater"/>
        <result property="cityCode" column="cityCode"/>
        <result property="cityName" column="cityName"/>
        <result property="crmId" column="crmId"/>
        <result property="bizPort" column="biz_port"/>
        <result property="actSourceId" column="act_source_id"/>
        <result property="traceStatus" column="trace_status"/>
        <result property="remark" column="remark"/>
        <result property="crmSync" column="crm_sync"/>
        <result property="hotlineCallTime" column="hotline_call_time"/>
        <result property="hotlineCallSpend" column="hotline_call_spend"/>
        <result property="oceanDate" column="ocean_date"/>
        <result property="isDelete" column="is_delete"/>
        <result property="lastManager" column="last_manager"/>
        <result property="bindTime" column="bind_time"/>
        <result property="customerSourceType" column="customer_source_type"/>
        <result property="customerRelId" column="customer_rel_id"/>
        <result property="isWaitCall" column="isWaitCall"/>
        <result property="singupTime" column="singupTime"/>
        <result property="marketActId" column="marketActId"/>
        <result property="marketActName" column="marketActName"/>
        <result property="isPeer" column="is_peer"/>
        <result property="starCustomer" column="starCustomer"/>
        <result property="isHandover" column="isHandover"/>
        <result property="isRecycled" column="isRecycled"/>
        <result property="isActive" column="is_active"/>
        <result property="starPtCustomer" column="star_pt_customer"/>
    </resultMap>

    <!-- 用于select查询公用抽取的列 -->
    <sql id="customer.columns">
        <![CDATA[
        id, name, phone, bak_phone1, bak_phone2, bak_phone3, sex, customer_type, act_source,
        first_source, latest_source, crm_latest_call, crm_latest_call_result, status, create_source,
        create_time, creater, buy_intention, last_visit_time, last_call_time, manager_id, manager_name,
        update_time, updater, cityCode,cityName, biz_port,crmId,act_source_id, trace_status, remark, crm_sync,
        hotline_call_time,hotline_call_spend,ocean_date,is_delete,last_manager,bind_time, customer_source_type,
        customer_rel_id, isWaitCall, singupTime,marketActId, marketActName,is_peer, starCustomer, isHandover, isRecycled,is_active,star_pt_customer
        ]]>
    </sql>

    <!-- 新增记录 -->
    <insert id="save" parameterClass="customerEntity">
        <![CDATA[
	        INSERT INTO customer (
	        	id,
	        	name,
	        	phone,
	        	bak_phone1,
	        	bak_phone2,
	        	bak_phone3,
	        	sex,
	        	customer_type,
	        	act_source,
	        	first_source,
	        	latest_source,
	        	crm_latest_call,
	        	crm_latest_call_result,
	        	status,
	        	create_source,
	        	create_time,
	        	creater,
	        	buy_intention,
	        	last_visit_time,
	        	last_call_time,
	        	manager_id,
	        	manager_name,
	        	update_time,
	        	updater,
	        	cityCode,
	        	cityName,
	        	biz_port,
	        	crmId,
	        	act_source_id,
	        	trace_status,
	        	remark,
	        	crm_sync,
	        	hotline_call_time,
	        	hotline_call_spend,
	        	ocean_date,
	        	last_manager,
	        	is_delete,
	        	bind_time,
	        	customer_source_type,
	        	customer_rel_id,
	        	isWaitCall,
	        	singupTime,marketActId, marketActName,newCycle
	        ) VALUES (
	        	#id#,
	        	#name#,
	        	#phone#,
	        	#bakPhone1#,
	        	#bakPhone2#,
	        	#bakPhone3#,
	        	#sex#,
	        	#customerType#,
	        	#actSource#,
	        	#firstSource#,
	        	#latestSource#,
	        	#crmLatestCall#,
	        	#crmLatestCallResult#,
	        	#status#,
	        	#createSource#,
	        	#createTime#,
	        	#creater#,
	        	#buyIntention#,
	        	#lastVisitTime#,
	        	#lastCallTime#,
	        	#managerId#,
	        	#managerName#,
	        	#updateTime#,
	        	#updater#,
	        	#cityCode#,
	        	#cityName#,
	        	#bizPort#,
	        	#crmId#,
	        	#actSourceId#,
	        	#traceStatus#,
	        	#remark#,
	        	#crmSync#,
	        	#hotlineCallTime#,
	        	#hotlineCallSpend#,
	        	#oceanDate#,
	        	#lastManager#,
	        	#isDelete#,
	        	#bindTime#,
	        	#customerSourceType#,
	        	#customerRelId#,
	        	#isWaitCall#,
	        	#singupTime#,#marketActId#, #marketActName#, #newCycle#
	        )
	    ]]>
        <selectKey resultClass="java.lang.Integer" type="post" keyProperty="id">
            SELECT LAST_INSERT_ID()
        </selectKey>
    </insert>

    <!-- 通过ID修改 -->
    <update id="update" parameterClass="customerEntity">
        <![CDATA[

	        UPDATE customer SET
		        name = #name#,
		        phone = #phone#,
		        bak_phone1 = #bakPhone1#,
		        bak_phone2 = #bakPhone2#,
		        bak_phone3 = #bakPhone3#,
		        sex = #sex#,
		        customer_type = #customerType#,
		        act_source = #actSource#,
		        first_source = #firstSource#,
		        latest_source = #latestSource#,
		        crm_latest_call = #crmLatestCall#,
		        crm_latest_call_result = #crmLatestCallResult#,
		        status = #status#,
		        create_source = #createSource#,
		        create_time = #createTime#,
		        creater = #creater#,
		        buy_intention = #buyIntention#,
		        last_visit_time = #lastVisitTime#,
		        last_call_time = #lastCallTime#,
		        manager_id = #managerId#,
		        manager_name = #managerName#,
		        update_time = #updateTime#,
		        updater = #updater#,
		        cityCode = #cityCode#,
		        cityName = #cityName#,
		        biz_port = #bizPort#,
		        crmId = #crmId#,
		        act_source_id = #actSourceId#,
		        trace_status = #traceStatus#,
		        remark = #remark#,
		        crm_sync = #crmSync#,
		        hotline_call_time = #hotlineCallTime#,
		        hotline_call_spend = #hotlineCallSpend#,
		        ocean_date = #oceanDate#,
		        is_delete = #isDelete#,
		        last_manager = #lastManager#,
		        bind_time = #bindTime#,
		        customer_source_type = #customerSourceType#,
		        customer_rel_id = #customerRelId#,
		        isWaitCall=#isWaitCall#,
		        singupTime=#singupTime#,
		        marketActId=#marketActId#, marketActName=#marketActName#,
		        isHandover=#isHandover#,
		        isRecycled=#isRecycled#
	        WHERE
		        id = #id#

        ]]>
    </update>

    <!-- 通过ID删除 -->
    <delete id="delete">
        <![CDATA[
	        DELETE FROM customer WHERE
	        id = #id#
        ]]>
    </delete>

    <!-- 通过ID列表批量删除 -->
    <delete id="deleteByIds" parameterClass="java.lang.String">
        <![CDATA[
	        DELETE FROM customer WHERE
	        id IN ($ids$)
        ]]>
    </delete>

    <delete id="removeFromOcean">
        <![CDATA[
	        update customer set is_delete = 1 where (manager_id is null or manager_id = '') and buy_intention = '5'
	        and TIMESTAMPDIFF(MONTH,update_time,CURDATE())>5
        ]]>
    </delete>

    <!-- 通过ID查询 -->
    <select id="getById" resultMap="customer">
        SELECT
        <include refid="customer.columns"/>
        <![CDATA[
	        FROM customer
	        WHERE
		        id = #id#
	    ]]>
    </select>

    <!-- 用于分页查询抽取的公共的条件 -->
    <sql id="customer.queryPage">
        <dynamic prepend="WHERE">
            <!-- 默认不开启实体作为条件 -->
            <isNotNull property="searchFilters">
                <isNotEmpty prepend="AND" property="searchFilters.id">
                    <![CDATA[
					id $searchFilters.id.operation$ #searchFilters.id.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.typeFilter">
                    <![CDATA[
					 $searchFilters.typeFilter.value$
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.name">
                    <![CDATA[
					name $searchFilters.name.operation$ #searchFilters.name.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.phone">
                    <![CDATA[
					phone $searchFilters.phone.operation$ #searchFilters.phone.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.bakPhone1">
                    <![CDATA[
					bak_phone1 $searchFilters.bakPhone1.operation$ #searchFilters.bakPhone1.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.bakPhone2">
                    <![CDATA[
					bak_phone2 $searchFilters.bakPhone2.operation$ #searchFilters.bakPhone2.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.bakPhone3">
                    <![CDATA[
					bak_phone3 $searchFilters.bakPhone3.operation$ #searchFilters.bakPhone3.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.sex">
                    <![CDATA[
					sex $searchFilters.sex.operation$ #searchFilters.sex.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.customerType">
                    <![CDATA[
					customer_type $searchFilters.customerType.operation$ #searchFilters.customerType.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.actSource">
                    <![CDATA[
					act_source $searchFilters.actSource.operation$ #searchFilters.actSource.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.actSourceId">
                    <![CDATA[
					act_source_id $searchFilters.actSourceId.operation$ #searchFilters.actSourceId.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.firstSource">
                    <![CDATA[
					first_source $searchFilters.firstSource.operation$ #searchFilters.firstSource.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.latestSource">
                    <![CDATA[
					latest_source $searchFilters.latestSource.operation$ #searchFilters.latestSource.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.crmLatestCall">
                    <![CDATA[
					crm_latest_call $searchFilters.crmLatestCall.operation$ #searchFilters.crmLatestCall.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.crmLatestCallResult">
                    <![CDATA[
					crm_latest_call_result $searchFilters.crmLatestCallResult.operation$ #searchFilters.crmLatestCallResult.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.status">
                    <![CDATA[
					status $searchFilters.status.operation$ #searchFilters.status.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.createSource">
                    <![CDATA[
					create_source $searchFilters.createSource.operation$ #searchFilters.createSource.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.createTime">
                    <![CDATA[
					create_time $searchFilters.createTime.operation$ #searchFilters.createTime.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.creater">
                    <![CDATA[
					creater $searchFilters.creater.operation$ #searchFilters.creater.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.buyIntention">
                    <![CDATA[
					buy_intention $searchFilters.buyIntention.operation$ $searchFilters.buyIntention.value$
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.eIntention">
                    <![CDATA[
					buy_intention $searchFilters.eIntention.operation$ $searchFilters.eIntention.value$
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.buyIntentionIsNull">
                    <![CDATA[
					(buy_intention is null or buy_intention='')
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.lastVisitTime">
                    <![CDATA[
					last_visit_time $searchFilters.lastVisitTime.operation$ #searchFilters.lastVisitTime.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.lastCallTime">
                    <![CDATA[
					last_call_time $searchFilters.lastCallTime.operation$ #searchFilters.lastCallTime.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.managerId">
                    <![CDATA[
					manager_id $searchFilters.managerId.operation$ $searchFilters.managerId.value$
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.managerName">
                    <![CDATA[
					manager_name $searchFilters.managerName.operation$ #searchFilters.managerName.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.updateTime">
                    <![CDATA[
					update_time $searchFilters.updateTime.operation$ #searchFilters.updateTime.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.updater">
                    <![CDATA[
					updater $searchFilters.updater.operation$ #searchFilters.updater.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.cityCode">
                    <![CDATA[
					cityCode $searchFilters.cityCode.operation$ #searchFilters.cityCode.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.cityName">
                    <![CDATA[
					cityName $searchFilters.cityName.operation$ #searchFilters.cityName.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.cityId">
                    <![CDATA[
					cityCode = ( select descripition from department where id = #searchFilters.cityId.value#)
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.bizPort">
                    <![CDATA[
					biz_port $searchFilters.bizPort.operation$ #searchFilters.bizPort.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.crmId">
                    <![CDATA[
					crmId $searchFilters.crmId.operation$ #searchFilters.crmId.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.createTimeStart">
                    <![CDATA[
					create_time $searchFilters.createTimeStart.operation$ #searchFilters.createTimeStart.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.createTimeEnd">
                    <![CDATA[
					create_time $searchFilters.createTimeEnd.operation$ #searchFilters.createTimeEnd.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.oceanDateStart">
                    <![CDATA[
					ocean_date $searchFilters.oceanDateStart.operation$ #searchFilters.oceanDateStart.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.oceanDateEnd">
                    <![CDATA[
					ocean_date $searchFilters.oceanDateEnd.operation$ #searchFilters.oceanDateEnd.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.houseName">
                    <![CDATA[
					id in (select customer_id from customer_project where house_name $searchFilters.houseName.operation$ #searchFilters.houseName.value#)
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.recordedStatus">
                    <![CDATA[
					id in (select customer_id from customer_project where recorded_status $searchFilters.recordedStatus.operation$ #searchFilters.recordedStatus.value#)
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.recordedStatusNull">
                    <![CDATA[
					id in (select customer_id from customer_project where recorded_status is null)
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.projectStatus">
                    <![CDATA[
					id in (select customer_id from customer_project where status $searchFilters.projectStatus.operation$ #searchFilters.projectStatus.value#)
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.loanStatus">
                    <![CDATA[
					id in (select customer_id from customer_project where loan_status $searchFilters.loanStatus.operation$ #searchFilters.loanStatus.value#)
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.likephone">
                    <![CDATA[
                    (name like #searchFilters.likephone.value#  or phone like #searchFilters.likephone.value#  or bak_phone1 like #searchFilters.likephone.value#  or bak_phone2 like #searchFilters.likephone.value#  or bak_phone3 like #searchFilters.likephone.value#)
					]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.likekeyword">
                    <![CDATA[
                    (name like #searchFilters.likekeyword.value#  or phone like #searchFilters.likekeyword.value#
                    or bak_phone1 like #searchFilters.likekeyword.value#  or bak_phone2 like #searchFilters.likekeyword.value#
                    or bak_phone3 like #searchFilters.likekeyword.value#
                    or id in (select customer_id from customer_project where house_name like #searchFilters.likekeyword.value#)
                    or id in (select customer_id from customer_callback_log where content like #searchFilters.likekeyword.value#)
                    or act_source like #searchFilters.likekeyword.value#
                    )
					]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.ids">
                    <![CDATA[ id $searchFilters.ids.operation$ ]]>
                    <iterate prepend="" property="searchFilters.ids.value" open="(" close=")" conjunction=",">
                        <![CDATA[ #searchFilters.ids.value[]# ]]>
                    </iterate>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.userId">
                    <![CDATA[
					 (manager_id = $searchFilters.userId.value$ or manager_id in (select id from user where depturlpath like (select concat(depturlpath,'/%') from user where id = $searchFilters.userId.value$)))
		            ]]>
                </isNotEmpty>

                <isNotEmpty prepend="AND" property="searchFilters.userIds">
                    <![CDATA[
					 (manager_id in ($searchFilters.userIds.value$) )
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.customerIds">
                    <![CDATA[
					 (id in ($searchFilters.customerIds.value$) )
		            ]]>
                </isNotEmpty>

                <isNotEmpty prepend="AND" property="searchFilters.traceStatus">
                    <![CDATA[
					trace_status $searchFilters.traceStatus.operation$ #searchFilters.traceStatus.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.remark">
                    <![CDATA[
					remark $searchFilters.remark.operation$ #searchFilters.remark.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.crmSync">
                    <![CDATA[
					crm_sync $searchFilters.crmSync.operation$ #searchFilters.crmSync.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.hotline">
                    <![CDATA[
					status in (11,0,99)
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.lastManager">
                    <![CDATA[
					last_manager $searchFilters.lastManager.operation$ #searchFilters.lastManager.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.isDelete">
                    <![CDATA[
					is_delete $searchFilters.isDelete.operation$ #searchFilters.isDelete.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.excludeCity">
                    <![CDATA[ cityCode not in ]]>
                    <iterate prepend="" property="searchFilters.excludeCity.value" open="(" close=")" conjunction=",">
                        <![CDATA[ #searchFilters.excludeCity.value[]# ]]>
                    </iterate>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.customerSourceType">
                    <![CDATA[
					customer_source_type $searchFilters.customerSourceType.operation$ #searchFilters.customerSourceType.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.customerRelId">
                    <![CDATA[
					customer_rel_id $searchFilters.customerRelId.operation$ #searchFilters.customerRelId.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.isWaitCall">
                    <![CDATA[
					isWaitCall $searchFilters.isWaitCall.operation$ #searchFilters.isWaitCall.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.singupTime">
                    <![CDATA[
					singupTime $searchFilters.singupTime.operation$ #searchFilters.singupTime.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.type">
                    <iterate prepend="" property="searchFilters.type.value" open="(" close=")" conjunction="OR">
                        buy_intention = #searchFilters.type.value[]#
                    </iterate>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.marketActId">
                    <![CDATA[
					marketActId $searchFilters.marketActId.operation$ #searchFilters.marketActId.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.marketActName">
                    <![CDATA[
					marketActName $searchFilters.marketActName.operation$ #searchFilters.marketActName.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.starCustomer">
                    <![CDATA[
					starCustomer $searchFilters.starCustomer.operation$ #searchFilters.starCustomer.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.isStar">
                    <![CDATA[
                    starCustomer = 1
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.isNotStar">
                    <![CDATA[
                    starCustomer = 0
                    ]]>
                </isNotEmpty>
                <isNotNull prepend="AND" property="searchFilters.isHandover">
                    <![CDATA[
                    isHandover $searchFilters.isHandover.operation$ #searchFilters.isHandover.value#
                    ]]>
                </isNotNull>
                <isNotNull prepend="AND" property="searchFilters.isActive">
                    <![CDATA[
                    is_active = 1
                    ]]>
                </isNotNull>
                <isNotNull prepend="AND" property="searchFilters.isRecycled">
                    <![CDATA[
                    isRecycled $searchFilters.isRecycled.operation$ #searchFilters.isRecycled.value#
                    ]]>
                </isNotNull>
            </isNotNull>
        </dynamic>
        <dynamic prepend="ORDER BY">
            <isNotNull property="orderColumn">
                <![CDATA[
				$orderColumn$
				]]>
                <isNotNull property="orderMode">
                    $orderMode$
                </isNotNull>
            </isNotNull>
        </dynamic>
    </sql>

    <!-- 用于分页查询抽取的公共的条件 -->
    <sql id="customer.queryManagementPage">
        <dynamic prepend="WHERE">
            <!-- 默认不开启实体作为条件 -->
            <isNotNull property="searchFilters">
                <isNotEmpty prepend="AND" property="searchFilters.id">
                    <![CDATA[
                    id $searchFilters.id.operation$ #searchFilters.id.value#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.name">
                    <![CDATA[
                    name $searchFilters.name.operation$ #searchFilters.name.value#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.phone">
                    <![CDATA[
                    (
                    phone $searchFilters.phone.operation$ #searchFilters.phone.value#
                    OR bak_phone1 $searchFilters.phone.operation$ #searchFilters.phone.value#
                    OR bak_phone2 $searchFilters.phone.operation$ #searchFilters.phone.value#
                    OR bak_phone3 $searchFilters.phone.operation$ #searchFilters.phone.value#
                    )
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.bakPhone1">
                    <![CDATA[
                    bak_phone1 $searchFilters.bakPhone1.operation$ #searchFilters.bakPhone1.value#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.bakPhone2">
                    <![CDATA[
                    bak_phone2 $searchFilters.bakPhone2.operation$ #searchFilters.bakPhone2.value#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.bakPhone3">
                    <![CDATA[
                    bak_phone3 $searchFilters.bakPhone3.operation$ #searchFilters.bakPhone3.value#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.sex">
                    <![CDATA[
                    sex $searchFilters.sex.operation$ #searchFilters.sex.value#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.customerType">
                    <![CDATA[
                    customer_type $searchFilters.customerType.operation$ #searchFilters.customerType.value#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.actSource">
                    <![CDATA[
                    act_source $searchFilters.actSource.operation$ #searchFilters.actSource.value#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.actSourceId">
                    <![CDATA[
                    act_source_id $searchFilters.actSourceId.operation$ #searchFilters.actSourceId.value#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.firstSource">
                    <![CDATA[
                    first_source $searchFilters.firstSource.operation$ #searchFilters.firstSource.value#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.latestSource">
                    <![CDATA[
                    latest_source $searchFilters.latestSource.operation$ #searchFilters.latestSource.value#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.crmLatestCall">
                    <![CDATA[
                    crm_latest_call $searchFilters.crmLatestCall.operation$ #searchFilters.crmLatestCall.value#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.crmLatestCallResult">
                    <![CDATA[
                    crm_latest_call_result $searchFilters.crmLatestCallResult.operation$ #searchFilters.crmLatestCallResult.value#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.status">
                    <![CDATA[
                    status $searchFilters.status.operation$ #searchFilters.status.value#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.createSource">
                    <iterate prepend="" property="searchFilters.createSource.value" open="(" close=")" conjunction="OR">
                        create_source = #searchFilters.createSource.value[]#
                    </iterate>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.platformCreateSource">
                    create_source $searchFilters.platformCreateSource.operation$ #searchFilters.platformCreateSource.value#
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.customerSourceType">
                    <![CDATA[
                    customer_source_type $searchFilters.customerSourceType.operation$ #searchFilters.customerSourceType.value#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.isDelete">
                    <![CDATA[
                    is_delete $searchFilters.isDelete.operation$ #searchFilters.isDelete.value#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.cityCode">
                    <![CDATA[
                    cityCode $searchFilters.cityCode.operation$ #searchFilters.cityCode.value#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.createTime">
                    <![CDATA[
                    create_time $searchFilters.createTime.operation$ #searchFilters.createTime.value#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.creater">
                    <![CDATA[
                    creater $searchFilters.creater.operation$ #searchFilters.creater.value#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.buyIntention">
                    <![CDATA[
                    buy_intention $searchFilters.buyIntention.operation$ $searchFilters.buyIntention.value$
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.buyIntentionIsNull">
                    <![CDATA[
                    (buy_intention is null or buy_intention='')
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.lastVisitTime">
                    <![CDATA[
                    last_visit_time $searchFilters.lastVisitTime.operation$ #searchFilters.lastVisitTime.value#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.lastCallTime">
                    <![CDATA[
                    last_call_time $searchFilters.lastCallTime.operation$ #searchFilters.lastCallTime.value#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.managerId">
                    <![CDATA[
                    manager_id $searchFilters.managerId.operation$ $searchFilters.managerId.value$
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.managerName">
                    <![CDATA[
                    manager_name $searchFilters.managerName.operation$ #searchFilters.managerName.value#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.updateTime">
                    <![CDATA[
                    update_time $searchFilters.updateTime.operation$ #searchFilters.updateTime.value#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.updater">
                    <![CDATA[
                    updater $searchFilters.updater.operation$ #searchFilters.updater.value#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.cityName">
                    <![CDATA[
                    cityName $searchFilters.cityName.operation$ #searchFilters.cityName.value#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.cityId">
                    <![CDATA[
                    cityCode = ( select descripition from department where id = #searchFilters.cityId.value#)
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.bizPort">
                    <![CDATA[
                    biz_port $searchFilters.bizPort.operation$ #searchFilters.bizPort.value#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.crmId">
                    <![CDATA[
                    crmId $searchFilters.crmId.operation$ #searchFilters.crmId.value#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.createTimeStart">
                    <![CDATA[
                    create_time $searchFilters.createTimeStart.operation$ #searchFilters.createTimeStart.value#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.createTimeEnd">
                    <![CDATA[
                    create_time $searchFilters.createTimeEnd.operation$ #searchFilters.createTimeEnd.value#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.oceanDateStart">
                    <![CDATA[
                    (ocean_date is null or ocean_date $searchFilters.oceanDateStart.operation$ #searchFilters.oceanDateStart.value#)
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.oceanDateEnd">
                    <![CDATA[
                    (ocean_date is null or ocean_date $searchFilters.oceanDateEnd.operation$ #searchFilters.oceanDateEnd.value#)
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.houseName">
                    <![CDATA[
                    id in (select customer_id from customer_project where house_name $searchFilters.houseName.operation$ #searchFilters.houseName.value#)
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.recordedStatus">
                    <![CDATA[
                    id in (select customer_id from customer_project where recorded_status $searchFilters.recordedStatus.operation$ #searchFilters.recordedStatus.value#)
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.recordedStatusNull">
                    <![CDATA[
                    id in (select customer_id from customer_project where recorded_status is null)
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.projectStatus">
                    <![CDATA[
                    id in (select customer_id from customer_project where status $searchFilters.projectStatus.operation$ #searchFilters.projectStatus.value#)
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.platProjectStatus">
                    <![CDATA[
                    id in (select c.id
                            from customer c2
                            where c.phone=c2.phone
                            and c.manager_id=c2.manager_id
                            and c2.id in (select customer_id from customer_project where status $searchFilters.platProjectStatus.operation$ #searchFilters.platProjectStatus.value#))
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.platProjectStatus7">
                    <![CDATA[
                    id not in (select c.id
                            from customer c2
                            where c.phone=c2.phone
                            and c.manager_id=c2.manager_id
                            and c2.id in (select customer_id from customer_project))
                    ]]>
                    <![CDATA[
                      and c.manager_id is not null
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.platManager">
                    <![CDATA[
                      manager_id is null
                    ]]>
                </isNotEmpty>

                <isNotEmpty prepend="AND" property="searchFilters.loanStatus">
                    <![CDATA[
                    id in (select customer_id from customer_project where loan_status $searchFilters.loanStatus.operation$ #searchFilters.loanStatus.value#)
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.likephone">
                    <![CDATA[
                    (name like #searchFilters.likephone.value#  or phone like #searchFilters.likephone.value#  or bak_phone1 like #searchFilters.likephone.value#  or bak_phone2 like #searchFilters.likephone.value#  or bak_phone3 like #searchFilters.likephone.value#)
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.likekeyword">
                    <![CDATA[
                    (name like #searchFilters.likekeyword.value#  or phone like #searchFilters.likekeyword.value#
                    or bak_phone1 like #searchFilters.likekeyword.value#  or bak_phone2 like #searchFilters.likekeyword.value#
                    or bak_phone3 like #searchFilters.likekeyword.value# or manager_name like #searchFilters.likekeyword.value#
                    or id in (select customer_id from customer_project where house_name like #searchFilters.likekeyword.value#)
                    or id in (select customer_id from customer_callback_log where content like #searchFilters.likekeyword.value#)
                    or act_source like #searchFilters.likekeyword.value#
                    )
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.ids">
                    <![CDATA[ id $searchFilters.ids.operation$ ]]>
                    <iterate prepend="" property="searchFilters.ids.value" open="(" close=")" conjunction=",">
                        <![CDATA[ #searchFilters.ids.value[]# ]]>
                    </iterate>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.userId">
                    <![CDATA[
                     (manager_id = $searchFilters.userId.value$ or manager_id in (select id from user where depturlpath like (select concat(depturlpath,'/%') from user where id = $searchFilters.userId.value$)))
                    ]]>
                </isNotEmpty>

                <isNotEmpty prepend="AND" property="searchFilters.platformCreater">
                    <![CDATA[
                     (creater = $searchFilters.platformCreater.value$ or creater in (select id from user where depturlpath like (select concat(depturlpath,'/%') from user where id = $searchFilters.platformCreater.value$)))
                    ]]>
                </isNotEmpty>

                <isNotEmpty prepend="AND" property="searchFilters.userIds">
                    <![CDATA[
                     (manager_id in ($searchFilters.userIds.value$) )
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.deptManagerId">
                    <![CDATA[
                     (manager_id in ($searchFilters.deptManagerId.value$) )
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.customerIds">
                    <![CDATA[
                     (id in ($searchFilters.customerIds.value$) )
                    ]]>
                </isNotEmpty>

                <isNotEmpty prepend="AND" property="searchFilters.traceStatus">
                    <![CDATA[
                    trace_status $searchFilters.traceStatus.operation$ #searchFilters.traceStatus.value#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.remark">
                    <![CDATA[
                    remark $searchFilters.remark.operation$ #searchFilters.remark.value#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.crmSync">
                    <![CDATA[
                    crm_sync $searchFilters.crmSync.operation$ #searchFilters.crmSync.value#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.hotline">
                    <![CDATA[
                    status in (11,0,99)
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.lastManager">
                    <![CDATA[
                    last_manager $searchFilters.lastManager.operation$ #searchFilters.lastManager.value#
                    ]]>
                </isNotEmpty>

                <isNotEmpty prepend="AND" property="searchFilters.typeFilter">
                    <![CDATA[
                     $searchFilters.typeFilter.value$
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.summaryType1">
                    <![CDATA[
                     (id in (SELECT id from customer where status in (11,0,99)  and TIMESTAMPDIFF(DAY,date_format(create_time,'%y-%m-%d'),date_format(CURDATE(),'%y-%m-%d'))=0 and
                    (manager_id = $searchFilters.userId.value$ or manager_id in (select id from user where depturlpath like (select concat(depturlpath,'/%') from user where id = $searchFilters.userId.value$)))) )
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.summaryType2">
                    <![CDATA[
                     (id in (SELECT c.id from customer_status_log as cp,customer as c where c.status in (11,0,99)  and cp.customer_id = c.id
                    and cp.to_status_id>0
                    and TIMESTAMPDIFF(DAY,date_format(cp.create_time,'%y-%m-%d'),date_format(CURDATE(),'%y-%m-%d'))=0 and
                    (c.manager_id = $searchFilters.userId.value$ or c.manager_id in (select id from user where depturlpath like (select concat(depturlpath,'/%') from user where id = $searchFilters.userId.value$)))) )
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.summaryType3">
                    <![CDATA[
                     (id in (SELECT c.id from customer as c where c.status in (11,0,99)  and TIMESTAMPDIFF(DAY,date_format(create_time,'%y-%m-%d'),date_format(CURDATE(),'%y-%m-%d'))>7 and not exists(select 1
                    from customer_callback_log ccl where c.id = ccl.customer_id) and
                    (manager_id = $searchFilters.userId.value$ or manager_id in (select id from user where depturlpath like (select concat(depturlpath,'/%') from user where id = $searchFilters.userId.value$)))) )
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.summaryType4">
                    <![CDATA[
                     (id in (SELECT c.id from customer as c where c.status in (11,0,99)  and TIMESTAMPDIFF(DAY,date_format(c.last_call_time,'%y-%m-%d'),date_format(CURDATE(),'%y-%m-%d'))>3 and
                    (c.manager_id = $searchFilters.userId.value$ or c.manager_id in (select id from user where depturlpath like (select concat(depturlpath,'/%') from user where id = $searchFilters.userId.value$)))) )
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.summaryType5">
                    <![CDATA[
                     (id in (select c.id from customer as c,customer_project as cp where c.status in (11,0,99)  and c.id=cp.customer_id and cp.status=2 and
                    TIMESTAMPDIFF(DAY,date_format(cp.last_change_status_time,'%y-%m-%d'),date_format(CURDATE(),'%y-%m-%d'))>7 and
                    (c.manager_id = $searchFilters.userId.value$ or c.manager_id in (select id from user where depturlpath like (select concat(depturlpath,'/%') from user where id = $searchFilters.userId.value$)))) )
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.customerRelId">
                    <![CDATA[
                    customer_rel_id $searchFilters.customerRelId.operation$ #searchFilters.customerRelId.value#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.isWaitCall">
                    <![CDATA[
                    isWaitCall $searchFilters.isWaitCall.operation$ #searchFilters.isWaitCall.value#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.activeId">
                    <![CDATA[
                     (c.id in (select customerId from market_customer where active_id=$searchFilters.activeId.value$))
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.singupTime">
                    <![CDATA[
                    singupTime $searchFilters.singupTime.operation$ #searchFilters.singupTime.value#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.marketActId">
                    <![CDATA[
                    singupTime $searchFilters.marketActId.operation$ #searchFilters.marketActId.value#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.marketActName">
                    <![CDATA[
                    marketActName $searchFilters.marketActName.operation$ #searchFilters.marketActName.value#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.bindTimeStart">
                    <![CDATA[
                    bind_time $searchFilters.bindTimeStart.operation$ #searchFilters.bindTimeStart.value#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.bindTimeEnd">
                    <![CDATA[
                    bind_time $searchFilters.bindTimeEnd.operation$ #searchFilters.bindTimeEnd.value#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.singupTimeStart">
                    <![CDATA[
                    singupTime $searchFilters.singupTimeStart.operation$ #searchFilters.singupTimeStart.value#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.singupTimeEnd">
                    <![CDATA[
                    singupTime $searchFilters.singupTimeEnd.operation$ #searchFilters.singupTimeEnd.value#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.callbackLog2">
                    <![CDATA[
                          id in ( SELECT customer_id FROM customer_callback_log WHERE customer_id in (select id from customer where phone $searchFilters.phone.operation$ #searchFilters.phone.value#)
                      and content $searchFilters.callbackLog2.operation$ #searchFilters.callbackLog2.value# )
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.callbackLog">
                    <![CDATA[
	                id in
                        (SELECT t.id FROM customer_merge t WHERE t.id IN ( SELECT customer_id FROM customer_callback_log WHERE content $searchFilters.callbackLog.operation$ #searchFilters.callbackLog.value# )
                            and manager_id in ( SELECT manager_id FROM customer_callback_log WHERE content $searchFilters.callbackLog.operation$ #searchFilters.callbackLog.value# )
                        )
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.projectName">
                    <![CDATA[
                    id in (select customer_id from customer_project where house_name $searchFilters.projectName.operation$ #searchFilters.projectName.value#)
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.isBack">
                    <![CDATA[
                    exists (
                        select 1 from (
                        select
                        c.manager_id,
                        c.phone
                        from
                        customer c inner join (
                        select customer_id,count(1)
                        from customer_callback_log
                        group by customer_id
                        ) t on c.id = t.customer_id and c.is_delete='0'
                        )t where c.manager_id = t.manager_id and c.phone = t.phone
                    )
                    ]]>
                    <isNotEmpty prepend="AND" property="searchFilters.isNotBackFour">
                        <![CDATA[
                        exists (
                             SELECT
                                1
                            FROM
                                (
                                    SELECT
                                        *
                                    FROM
                                        (
                                            SELECT
                                                c.manager_id ,
                                                c.phone ,
                                                max(t.last_call_time) AS last_call_time
                                            FROM
                                                (
                                                    SELECT
                                                        t.customer_id ,
                                                        t.manager_id ,
                                                        t.last_call_time
                                                    FROM
                                                        (
                                                            SELECT
                                                                customer_id ,
                                                                manager_id ,
                                                                max(t.create_time) AS last_call_time
                                                            FROM
                                                                customer_callback_log t
                                                            WHERE
                                                                t.create_time IS NOT NULL
                                                            AND t.customer_id IS NOT NULL
                                                            AND t.manager_id IS NOT NULL
                                                            GROUP BY
                                                                customer_id ,
                                                                manager_id
                                                        ) t
                                                ) t
                                            INNER JOIN customer c ON c.id = t.customer_id and c.is_delete='0'
                                            AND c.manager_id = t.manager_id
                                            GROUP BY
                                                c.manager_id ,
                                                c.phone
                                        ) t
                                    WHERE
                                        datediff(CURRENT_DATE , t.last_call_time) >= 3
                                                        AND datediff(CURRENT_DATE , t.last_call_time) <= 7
                                ) t
                            WHERE
                                c.manager_id = t.manager_id
                            AND c.phone = t.phone                       )
                        ]]>
                    </isNotEmpty>
                    <isNotEmpty prepend="AND" property="searchFilters.isNotBackFive">
                        <![CDATA[
                        exists (
                            SELECT
                                1
                            FROM
                                (
                                    SELECT
                                        *
                                    FROM
                                        (
                                            SELECT
                                                c.manager_id ,
                                                c.phone ,
                                                max(t.last_call_time) AS last_call_time
                                            FROM
                                                (
                                                    SELECT
                                                        t.customer_id ,
                                                        t.manager_id ,
                                                        t.last_call_time
                                                    FROM
                                                        (
                                                            SELECT
                                                                customer_id ,
                                                                manager_id ,
                                                                max(t.create_time) AS last_call_time
                                                            FROM
                                                                customer_callback_log t
                                                            WHERE
                                                                t.create_time IS NOT NULL
                                                            AND t.customer_id IS NOT NULL
                                                            AND t.manager_id IS NOT NULL
                                                            GROUP BY
                                                                customer_id ,
                                                                manager_id
                                                        ) t
                                                ) t
                                            INNER JOIN customer c ON c.id = t.customer_id
                                            AND c.manager_id = t.manager_id
                                            GROUP BY
                                                c.manager_id ,
                                                c.phone
                                        ) t
                                    WHERE
                                        datediff(CURRENT_DATE , t.last_call_time) >= 7
                                                        AND datediff(CURRENT_DATE , t.last_call_time) <= 14
                                ) t
                            WHERE
                                c.manager_id = t.manager_id
                            AND c.phone = t.phone
                                                )
                        ]]>
                    </isNotEmpty>
                    <isNotEmpty prepend="AND" property="searchFilters.isNotBackSix">
                        <![CDATA[
                        exists (
                        SELECT
                            1
                        FROM
                            (
                                SELECT
                                    *
                                FROM
                                    (
                                        SELECT
                                            c.manager_id ,
                                            c.phone ,
                                            max(t.last_call_time) AS last_call_time
                                        FROM
                                            (
                                                SELECT
                                                    t.customer_id ,
                                                    t.manager_id ,
                                                    t.last_call_time
                                                FROM
                                                    (
                                                        SELECT
                                                            customer_id ,
                                                            manager_id ,
                                                            max(t.create_time) AS last_call_time
                                                        FROM
                                                            customer_callback_log t
                                                        WHERE
                                                            t.create_time IS NOT NULL
                                                        AND t.customer_id IS NOT NULL
                                                        AND t.manager_id IS NOT NULL
                                                        GROUP BY
                                                            customer_id ,
                                                            manager_id
                                                    ) t
                                            ) t
                                        INNER JOIN customer c ON c.id = t.customer_id and c.is_delete='0'
                                        AND c.manager_id = t.manager_id
                                        GROUP BY
                                            c.manager_id ,
                                            c.phone
                                    ) t
                                WHERE
                                    datediff(CURRENT_DATE , t.last_call_time) >= 14
                            ) t
                        WHERE
                            c.manager_id = t.manager_id
                        AND c.phone = t.phone
                        )
                        ]]>
                    </isNotEmpty>
                    <isNotEmpty prepend="AND" property="searchFilters.isNotBackSeven">
                        <![CDATA[
                        exists (
                        SELECT
                            1
                        FROM
                            (
                                SELECT
                                    *
                                FROM
                                    (
                                        SELECT
                                            c.manager_id ,
                                            c.phone ,
                                            max(t.last_call_time) AS last_call_time
                                        FROM
                                            (
                                                SELECT
                                                    t.customer_id ,
                                                    t.manager_id ,
                                                    t.last_call_time
                                                FROM
                                                    (
                                                        SELECT
                                                            customer_id ,
                                                            manager_id ,
                                                            max(t.create_time) AS last_call_time
                                                        FROM
                                                            customer_callback_log t
                                                        WHERE
                                                            t.create_time IS NOT NULL
                                                        AND t.customer_id IS NOT NULL
                                                        AND t.manager_id IS NOT NULL
                                                        GROUP BY
                                                            customer_id ,
                                                            manager_id
                                                    ) t
                                            ) t
                                        INNER JOIN customer c ON c.id = t.customer_id and c.is_delete='0'
                                        AND c.manager_id = t.manager_id
                                        GROUP BY
                                            c.manager_id ,
                                            c.phone
                                    ) t
                                WHERE
                                    datediff(CURRENT_DATE , t.last_call_time) >= 30
                            ) t
                        WHERE
                            c.manager_id = t.manager_id
                        AND c.phone = t.phone
                        )
                        ]]>
                    </isNotEmpty>
                    <isNotEmpty prepend="AND" property="searchFilters.isNotBackEight">
                        <![CDATA[
                        exists (
                        SELECT
                            1
                        FROM
                            (
                                SELECT
                                    *
                                FROM
                                    (
                                        SELECT
                                            c.manager_id ,
                                            c.phone ,
                                            max(t.last_call_time) AS last_call_time
                                        FROM
                                            (
                                                SELECT
                                                    t.customer_id ,
                                                    t.manager_id ,
                                                    t.last_call_time
                                                FROM
                                                    (
                                                        SELECT
                                                            customer_id ,
                                                            manager_id ,
                                                            max(t.create_time) AS last_call_time
                                                        FROM
                                                            customer_callback_log t
                                                        WHERE
                                                            t.create_time IS NOT NULL
                                                        AND t.customer_id IS NOT NULL
                                                        AND t.manager_id IS NOT NULL
                                                        GROUP BY
                                                            customer_id ,
                                                            manager_id
                                                    ) t
                                            ) t
                                        INNER JOIN customer c ON c.id = t.customer_id and c.is_delete='0'
                                        AND c.manager_id = t.manager_id
                                        GROUP BY
                                            c.manager_id ,
                                            c.phone
                                    ) t
                                WHERE
                                    datediff(CURRENT_DATE , t.last_call_time) >= 50
                            ) t
                        WHERE
                            c.manager_id = t.manager_id
                        AND c.phone = t.phone
                        )
                        ]]>
                    </isNotEmpty>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.isNotBack">
                    <![CDATA[
                    not exists (
                        select 1 from (
                        select
                        c.manager_id,
                        c.phone
                        from
                        customer c inner join (
                        select customer_id,count(1)
                        from customer_callback_log
                        group by customer_id
                        ) t on c.id = t.customer_id and c.is_delete='0'
                        )t where c.manager_id = t.manager_id and c.phone = t.phone
                    )
                    ]]>
                </isNotEmpty>

                <isNotEmpty prepend="AND" property="searchFilters.customTimeTypeOne">
                    exists (
                    select 1 from (
                    select
                    c.manager_id,
                    c.phone
                    from
                    customer c inner join (
                    select customer_id,count(1)
                    from customer_callback_log
                    where 1=1
                    <isNotEmpty prepend="AND" property="searchFilters.customTimeStart">
                        <![CDATA[
                                        create_time $searchFilters.customTimeStart.operation$ #searchFilters.customTimeStart.value#
                                    ]]>
                    </isNotEmpty>
                    <isNotEmpty prepend="AND" property="searchFilters.customTimeEnd">
                        <![CDATA[
                                        create_time $searchFilters.customTimeEnd.operation$ #searchFilters.customTimeEnd.value#
                                    ]]>
                    </isNotEmpty>
                    group by customer_id
                    ) t on c.id = t.customer_id and c.is_delete='0'
                    )t where c.manager_id = t.manager_id and c.phone = t.phone
                    )
                </isNotEmpty>

                <isNotEmpty prepend="AND" property="searchFilters.customTimeTypeTwo">
                    exists (
                    select 1 from (
                    select
                    c.manager_id,
                    c.phone
                    from
                    customer c inner join (
                    select customer_id,count(1)
                    from customer_status_log
                    where is_delete = 0 and to_status_id = 1
                    <isNotEmpty prepend="AND" property="searchFilters.customTimeStart">
                        <![CDATA[
                                    create_time $searchFilters.customTimeStart.operation$ #searchFilters.customTimeStart.value#
                                ]]>
                    </isNotEmpty>
                    <isNotEmpty prepend="AND" property="searchFilters.customTimeEnd">
                        <![CDATA[
                                    create_time $searchFilters.customTimeEnd.operation$ #searchFilters.customTimeEnd.value#
                                ]]>
                    </isNotEmpty>
                    group by customer_id
                    ) t on c.id = t.customer_id and c.is_delete='0'
                    )t where c.manager_id = t.manager_id and c.phone = t.phone
                    )
                </isNotEmpty>

                <isNotEmpty prepend="AND" property="searchFilters.customTimeTypeThree">
                    exists (
                    select 1 from (
                    select
                    c.manager_id,
                    c.phone
                    from
                    customer c inner join (
                    select customer_id,count(1)
                    from customer_status_log
                    where is_delete = 0 and to_status_id = 2
                    <isNotEmpty prepend="AND" property="searchFilters.customTimeStart">
                        <![CDATA[
                                    occur_time $searchFilters.customTimeStart.operation$ #searchFilters.customTimeStart.value#
                                ]]>
                    </isNotEmpty>
                    <isNotEmpty prepend="AND" property="searchFilters.customTimeEnd">
                        <![CDATA[
                                    occur_time $searchFilters.customTimeEnd.operation$ #searchFilters.customTimeEnd.value#
                                ]]>
                    </isNotEmpty>
                    group by customer_id
                    ) t on c.id = t.customer_id and c.is_delete='0'
                    )t where c.manager_id = t.manager_id and c.phone = t.phone
                    )
                </isNotEmpty>

                <isNotEmpty prepend="AND" property="searchFilters.customTimeTypeFour">
                    exists (
                    select 1 from (
                    select
                    c.manager_id,
                    c.phone
                    from
                    customer c inner join (
                    select customer_id,count(1)
                    from customer_status_log
                    where is_delete = 0 and to_status_id = 3
                    <isNotEmpty prepend="AND" property="searchFilters.customTimeStart">
                        <![CDATA[
                                    occur_time $searchFilters.customTimeStart.operation$ #searchFilters.customTimeStart.value#
                                ]]>
                    </isNotEmpty>
                    <isNotEmpty prepend="AND" property="searchFilters.customTimeEnd">
                        <![CDATA[
                                    occur_time $searchFilters.customTimeEnd.operation$ #searchFilters.customTimeEnd.value#
                                ]]>
                    </isNotEmpty>
                    group by customer_id
                    ) t on c.id = t.customer_id and c.is_delete='0'
                    )t where c.manager_id = t.manager_id and c.phone = t.phone
                    )
                </isNotEmpty>

                <isNotEmpty prepend="AND" property="searchFilters.customTimeTypeFive">
                    exists (
                    select 1 from (
                    select
                    c.manager_id,
                    c.phone
                    from
                    customer c inner join (
                    select customer_id,count(1)
                    from customer_status_log
                    where is_delete = 0 and to_status_id = 4
                    <isNotEmpty prepend="AND" property="searchFilters.customTimeStart">
                        <![CDATA[
                                    occur_time $searchFilters.customTimeStart.operation$ #searchFilters.customTimeStart.value#
                                ]]>
                    </isNotEmpty>
                    <isNotEmpty prepend="AND" property="searchFilters.customTimeEnd">
                        <![CDATA[
                                    occur_time $searchFilters.customTimeEnd.operation$ #searchFilters.customTimeEnd.value#
                                ]]>
                    </isNotEmpty>
                    group by customer_id
                    ) t on c.id = t.customer_id and c.is_delete='0'
                    )t where c.manager_id = t.manager_id and c.phone = t.phone
                    )
                </isNotEmpty>

                <isNotEmpty prepend="AND" property="searchFilters.customTimeTypeSix">
                    exists (
                    select 1 from (
                    select
                    c.manager_id,
                    c.phone
                    from
                    customer c inner join (
                    select customer_id,count(1)
                    from customer_status_log
                    where is_delete = 0 and to_status_id = 5
                    <isNotEmpty prepend="AND" property="searchFilters.customTimeStart">
                        <![CDATA[
                                    occur_time $searchFilters.customTimeStart.operation$ #searchFilters.customTimeStart.value#
                                ]]>
                    </isNotEmpty>
                    <isNotEmpty prepend="AND" property="searchFilters.customTimeEnd">
                        <![CDATA[
                                    occur_time $searchFilters.customTimeEnd.operation$ #searchFilters.customTimeEnd.value#
                                ]]>
                    </isNotEmpty>
                    group by customer_id
                    ) t on c.id = t.customer_id and c.is_delete='0'
                    )t where c.manager_id = t.manager_id and c.phone = t.phone
                    )
                </isNotEmpty>

                <isNotEmpty prepend="AND" property="searchFilters.isStar">
                    <![CDATA[
                    starCustomer = 1
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.isNotStar">
                    <![CDATA[
                    starCustomer = 0
                    ]]>
                </isNotEmpty>

                <isNotEmpty prepend="AND" property="searchFilters.isPtStar">
                    <![CDATA[
                    star_pt_customer = 1
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.isNotPtStar">
                    <![CDATA[
                    star_pt_customer = 0
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.isShowInPlat">
                    <![CDATA[
					c.is_show_in_plat $searchFilters.isShowInPlat.operation$ #searchFilters.isShowInPlat.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.starCustomer">
                    <![CDATA[
                    starCustomer $searchFilters.starCustomer.operation$ #searchFilters.starCustomer.value#
                    ]]>
                </isNotEmpty>
                <isNotNull prepend="AND" property="searchFilters.isHandover">
                    <![CDATA[
                    isHandover $searchFilters.isHandover.operation$ #searchFilters.isHandover.value#
                    ]]>
                </isNotNull>
                <isNotNull prepend="AND" property="searchFilters.isActive">
                    <![CDATA[
                    is_active = 1
                    ]]>
                </isNotNull>
                <isNotNull prepend="AND" property="searchFilters.isRecycled">
                    <![CDATA[
                    isRecycled $searchFilters.isRecycled.operation$ #searchFilters.isRecycled.value#
                    ]]>
                </isNotNull>
                <isNotEmpty prepend="AND" property="searchFilters.sourceName">
                    <![CDATA[
                     EXISTS
                          (SELECT
                            1
                          FROM
                            (SELECT
                              c.manager_id,
                              c.phone
                            FROM
                              customer c
                            WHERE c.is_delete = 0
                              AND manager_id IS NOT NULL
                              AND STATUS IN (0, 11, 99)
                              AND c.act_source LIKE concat('', #searchFilters.sourceName.value#, '%')) t
                          WHERE c.manager_id = t.manager_id
                            AND c.phone = t.phone)

                    ]]>
                </isNotEmpty>

                <isNotEmpty prepend="AND" property="searchFilters.customerSourceType2">
                    <![CDATA[
                      EXISTS
                          (SELECT
                            1
                          FROM
                            (SELECT
                              c.manager_id,
                              c.phone
                            FROM
                              customer c
                            WHERE c.is_delete = 0
                              AND manager_id IS NOT NULL
                              AND STATUS IN (0, 11, 99)
                              AND c.customer_source_type = #searchFilters.customerSourceType2.value#) t
                          WHERE c.manager_id = t.manager_id
                            AND c.phone = t.phone)
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.createrName">
                    <![CDATA[
					 c.creater in (select id from user u3 where u3.realName LIKE concat('', #searchFilters.createrName.value#, '%') )
		            ]]>
                </isNotEmpty>
            </isNotNull>
        </dynamic>
    </sql>

    <!-- 为分页查询符合条件的记录数 -->
    <select id="queryByPage_count" resultClass="int">
        SELECT count(*) FROM customer c
        <include refid="customer.queryPage"/>
    </select>

    <!-- 分页查询指定页记录 -->
    <select id="queryByPage" resultMap="customer">
        SELECT
        <include refid="customer.columns"/>
        FROM customer
        <include refid="customer.queryPage"/>
        <![CDATA[
		    LIMIT #paging.startRecord#, #paging.pageSize#
        ]]>
    </select>

    <!-- 分页查询指定页记录 -->
    <select id="getCustomerManagementList_count" resultClass="int">
        SELECT
        count(*)
        FROM
        customer_merge c
        <include refid="customer.queryManagementPage"/>
    </select>

    <!-- 分页查询指定页记录 -->
    <select id="getCustomerManagementList" resultMap="customer">
        SELECT
        id, name, phone, bak_phone1, bak_phone2, bak_phone3, sex, customer_type, act_source,
        first_source, latest_source, crm_latest_call, crm_latest_call_result, status, create_source,
        create_time, creater, buy_intention, last_visit_time, last_call_time, manager_id, manager_name,
        update_time, updater, cityCode,cityName, biz_port,crmId,act_source_id, trace_status, remark, crm_sync,
        hotline_call_time,hotline_call_spend,ocean_date,is_delete,last_manager,bind_time, customer_source_type,
        customer_rel_id, isWaitCall, singupTime,marketActId, marketActName,is_peer, starCustomer, isHandover,
        isRecycled,is_active,starCustomer AS star_pt_customer
        FROM customer_merge c
        <include refid="customer.queryManagementPage"/>
        <isNotEmpty prepend="ORDER BY" property="searchFilters.orderBy">
            <![CDATA[
					 $searchFilters.orderBy.value$
		            ]]>
        </isNotEmpty>
        <![CDATA[
		    LIMIT #paging.startRecord#, #paging.pageSize#
        ]]>
    </select>

    <!-- 平台客户查询 -->
    <select id="getPlatformCustomerList" resultClass="com.house365.beans.entity.CustomerEntity">
        SELECT
        min( c.id ) id,
        (IFNULL((SELECT cm.NAME FROM customer_merge cm WHERE	cm.phone = c.phone AND cm.manager_id = c.manager_id AND cm.cityCode = #searchFilters.cityCode.value# AND cm.is_delete = 0 AND cm.STATUS IN ( 11, 0, 99 )),
        ( SELECT ct.NAME FROM customer ct WHERE ct.id = c.id ))) NAME,
        c.phone,
        (select u2.realName from user u2 where u2.id = c.creater) creater,
        c.creater AS createrId,
        c.star_pt_customer AS starPtCustomer,
        (
        IFNULL((SELECT min( ct.create_time ) FROM customer ct WHERE ct.phone = c.phone AND ct.manager_id = c.manager_id AND ct.cityCode = #searchFilters.cityCode.value# AND ct.is_delete = 0 AND ct.STATUS IN ( 11, 0, 99 )),
        (SELECT ct.create_time FROM customer ct WHERE ct.id = c.id))
        ) createTime,
        min( c.buy_intention ) buyIntention,
        (
        IFNULL((SELECT
        max( ct1.last_call_time )
        FROM
        customer ct1
        WHERE
        ct1.phone = c.phone
        AND ct1.manager_id = c.manager_id
        AND ct1.cityCode = #searchFilters.cityCode.value#
        AND ct1.is_delete = 0
        AND ct1.STATUS IN ( 11, 0, 99 )),(SELECT ct11.last_call_time FROM customer ct11 WHERE ct11.id = c.id))

        ) lastCallTime,
        c.manager_id managerId,
        IFNULL(c.manager_name,c.last_manager) managerName,
        (
        IFNULL((SELECT
        min( ct2.bind_time )
        FROM
        customer ct2
        WHERE
        ct2.phone = c.phone
        AND ct2.manager_id = c.manager_id
        AND ct2.cityCode = #searchFilters.cityCode.value#
        AND ct2.is_delete = 0
        AND ct2.STATUS IN ( 11, 0, 99 )),(SELECT ct3.bind_time FROM customer ct3 WHERE ct3.id = c.id))

        ) bindTime
        FROM customer c
        <include refid="customer.queryManagementPage"/>
        group by c.manager_id, c.phone
        <isNotEmpty prepend="ORDER BY" property="searchFilters.orderBy">
            <![CDATA[
					 $searchFilters.orderBy.value$
		            ]]>
        </isNotEmpty>
        <![CDATA[
		    LIMIT #paging.startRecord#, #paging.pageSize#
        ]]>
    </select>

    <select id="getPlatformCustomerList_count" resultClass="int">
        select count(*) from (
        SELECT
        min( id ) id,
        min( NAME ) NAME,
        phone,
        sex,
        min( create_time ) createTime,
        min( buy_intention ) buyIntention,
        max( last_call_time ) lastCallTime,
        manager_id managerId,
        manager_name managerName,
        max( update_time ) updateTime,
        cityCode,
        min( act_source_id ) actSourceId,
        remark,
        trace_status traceStatus,
        max( bind_time ) bindTime
        FROM customer c
        <include refid="customer.queryManagementPage"/>
        group by manager_id, phone ) t
    </select>

    <select id="getCustomerManagementList4Label" resultMap="customer">
        SELECT
        c.*
        FROM customer_merge c
        right join (select distinct customerId from customer_label cl where cl.labelId in (#searchFilters.labelId.value#) and cl.is_delete=0) m
        on c.id=m.customerId
        <include refid="customer.queryManagementPage"/>
        <isNotEmpty prepend="ORDER BY" property="searchFilters.orderBy">
            <![CDATA[
					 $searchFilters.orderBy.value$
		            ]]>
        </isNotEmpty>
        <![CDATA[
		    LIMIT #paging.startRecord#, #paging.pageSize#
        ]]>
    </select>

    <!-- 分页查询指定页记录 -->
    <select id="getCustomerManagementList4Label_count" resultClass="int">
        SELECT
        count(*)
        FROM
        customer_merge c
        right join (select distinct customerId from customer_label cl where cl.labelId in (#searchFilters.labelId.value#) and cl.is_delete=0) m
        on c.id=m.customerId
        <include refid="customer.queryManagementPage"/>
    </select>

    <!-- 待回访分页查询指定页记录 -->
    <select id="getCustomerListFromOld_count" resultClass="int">
        SELECT
        count(*)
        FROM
        customer c
        <include refid="customer.queryManagementPage"/>
    </select>

    <!-- 待回访分页查询指定页记录 -->
    <select id="getCustomerListFromOld" resultMap="customer">
        SELECT
        c.*
        FROM
        customer c
        <include refid="customer.queryManagementPage"/>
        <isNotEmpty prepend="ORDER BY" property="searchFilters.orderBy">
            <![CDATA[
					 $searchFilters.orderBy.value$
		            ]]>
        </isNotEmpty>
        <![CDATA[
		    LIMIT #paging.startRecord#, #paging.pageSize#
        ]]>
    </select>

    <select id="getMarketInfo" resultClass="java.util.HashMap">
        SELECT distinct marketActId, marketActName FROM customer c
        <include refid="customer.queryManagementPage"/>
    </select>

    <!-- 用于分页查询抽取的公共的条件 -->
    <sql id="customer.queryWechatPage">
        <dynamic prepend="WHERE">
            <!-- 默认不开启实体作为条件 -->
            <isNotNull property="searchFilters">
                <isNotEmpty prepend="AND" property="searchFilters.id">
                    <![CDATA[
					c.id $searchFilters.id.operation$ #searchFilters.id.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.name">
                    <![CDATA[
					c.name $searchFilters.name.operation$ #searchFilters.name.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.phone">
                    <![CDATA[
					c.phone $searchFilters.phone.operation$ #searchFilters.phone.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.bakPhone1">
                    <![CDATA[
					c.bak_phone1 $searchFilters.bakPhone1.operation$ #searchFilters.bakPhone1.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.bakPhone2">
                    <![CDATA[
					c.bak_phone2 $searchFilters.bakPhone2.operation$ #searchFilters.bakPhone2.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.bakPhone3">
                    <![CDATA[
					c.bak_phone3 $searchFilters.bakPhone3.operation$ #searchFilters.bakPhone3.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.sex">
                    <![CDATA[
					c.sex $searchFilters.sex.operation$ #searchFilters.sex.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.customerType">
                    <![CDATA[
					c.customer_type $searchFilters.customerType.operation$ #searchFilters.customerType.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.actSource">
                    <![CDATA[
					c.act_source $searchFilters.actSource.operation$ #searchFilters.actSource.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.actSourceId">
                    <![CDATA[
					c.act_source_id $searchFilters.actSourceId.operation$ #searchFilters.actSourceId.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.firstSource">
                    <![CDATA[
					c.first_source $searchFilters.firstSource.operation$ #searchFilters.firstSource.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.latestSource">
                    <![CDATA[
					c.latest_source $searchFilters.latestSource.operation$ #searchFilters.latestSource.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.crmLatestCall">
                    <![CDATA[
					c.crm_latest_call $searchFilters.crmLatestCall.operation$ #searchFilters.crmLatestCall.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.crmLatestCallResult">
                    <![CDATA[
					c.crm_latest_call_result $searchFilters.crmLatestCallResult.operation$ #searchFilters.crmLatestCallResult.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.status">
                    <![CDATA[
					c.status $searchFilters.status.operation$ #searchFilters.status.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.createSource">
                    <![CDATA[
					c.create_source $searchFilters.createSource.operation$ #searchFilters.createSource.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.createTime">
                    <![CDATA[
					c.create_time $searchFilters.createTime.operation$ #searchFilters.createTime.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.creater">
                    <![CDATA[
					c.creater $searchFilters.creater.operation$ #searchFilters.creater.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.buyIntention">
                    <![CDATA[
					c.buy_intention $searchFilters.buyIntention.operation$ $searchFilters.buyIntention.value$
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.buyIntentionIsNull">
                    <![CDATA[
					(c.buy_intention is null or c.buy_intention='')
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.lastVisitTime">
                    <![CDATA[
					c.last_visit_time $searchFilters.lastVisitTime.operation$ #searchFilters.lastVisitTime.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.lastCallTime">
                    <![CDATA[
					c.last_call_time $searchFilters.lastCallTime.operation$ #searchFilters.lastCallTime.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.managerId">
                    <![CDATA[
					c.manager_id $searchFilters.managerId.operation$ $searchFilters.managerId.value$
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.managerName">
                    <![CDATA[
					c.manager_name $searchFilters.managerName.operation$ #searchFilters.managerName.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.updateTime">
                    <![CDATA[
					c.update_time $searchFilters.updateTime.operation$ #searchFilters.updateTime.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.updater">
                    <![CDATA[
					c.updater $searchFilters.updater.operation$ #searchFilters.updater.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.cityCode">
                    <![CDATA[
					c.cityCode $searchFilters.cityCode.operation$ #searchFilters.cityCode.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.cityName">
                    <![CDATA[
					c.cityName $searchFilters.cityName.operation$ #searchFilters.cityName.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.cityId">
                    <![CDATA[
					c.cityCode = ( select descripition from department where id = #searchFilters.cityId.value#)
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.bizPort">
                    <![CDATA[
					c.biz_port $searchFilters.bizPort.operation$ #searchFilters.bizPort.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.crmId">
                    <![CDATA[
					c.crmId $searchFilters.crmId.operation$ #searchFilters.crmId.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.createTimeStart">
                    <![CDATA[
					c.create_time $searchFilters.createTimeStart.operation$ #searchFilters.createTimeStart.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.createTimeEnd">
                    <![CDATA[
					c.create_time $searchFilters.createTimeEnd.operation$ #searchFilters.createTimeEnd.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.oceanDateStart">
                    <![CDATA[
					(c.ocean_date is null or c.ocean_date $searchFilters.oceanDateStart.operation$ #searchFilters.oceanDateStart.value#)
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.oceanDateEnd">
                    <![CDATA[
					(c.ocean_date is null or c.ocean_date $searchFilters.oceanDateEnd.operation$ #searchFilters.oceanDateEnd.value#)
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.houseName">
                    <![CDATA[
					c.id in (select customer_id from customer_project where house_name $searchFilters.houseName.operation$ #searchFilters.houseName.value#)
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.recordedStatus">
                    <![CDATA[
					c.id in (select customer_id from customer_project where recorded_status $searchFilters.recordedStatus.operation$ #searchFilters.recordedStatus.value#)
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.recordedStatusNull">
                    <![CDATA[
					c.id in (select customer_id from customer_project where recorded_status is null)
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.projectStatus">
                    <![CDATA[
					c.id in (select customer_id from customer_project where status $searchFilters.projectStatus.operation$ #searchFilters.projectStatus.value#)
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.loanStatus">
                    <![CDATA[
					c.id in (select customer_id from customer_project where loan_status $searchFilters.loanStatus.operation$ #searchFilters.loanStatus.value#)
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.likephone">
                    <![CDATA[
                    (c.name like #searchFilters.likephone.value#  or c.phone like #searchFilters.likephone.value#  or c.bak_phone1 like #searchFilters.likephone.value#
                     or c.bak_phone2 like #searchFilters.likephone.value#  or c.bak_phone3 like #searchFilters.likephone.value#)
					]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.likekeyword">
                    <![CDATA[
                    (c.name like #searchFilters.likekeyword.value#  or c.phone like #searchFilters.likekeyword.value#
                    or c.bak_phone1 like #searchFilters.likekeyword.value#  or c.bak_phone2 like #searchFilters.likekeyword.value#
                    or c.bak_phone3 like #searchFilters.likekeyword.value#
                    or c.manager_name like #searchFilters.likekeyword.value#
                    or id in (select customer_id from customer_project where house_name like #searchFilters.likekeyword.value#)
                    or id in (select customer_id from customer_callback_log where content like #searchFilters.likekeyword.value#)
                    or act_source like #searchFilters.likekeyword.value#
                    )
					]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.ids">
                    <![CDATA[ c.id $searchFilters.ids.operation$ ]]>
                    <iterate prepend="" property="searchFilters.ids.value" open="(" close=")" conjunction=",">
                        <![CDATA[ #searchFilters.ids.value[]# ]]>
                    </iterate>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.userId">
                    <![CDATA[
					 (c.manager_id = $searchFilters.userId.value$ or c.manager_id in (select id from user where depturlpath like (select concat(depturlpath,'/%') from user where id = $searchFilters.userId.value$)))
		            ]]>
                </isNotEmpty>

                <isNotEmpty prepend="AND" property="searchFilters.userIds">
                    <![CDATA[
					 (c.manager_id in ($searchFilters.userIds.value$) )
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.customerIds">
                    <![CDATA[
					 (c.id in ($searchFilters.customerIds.value$) )
		            ]]>
                </isNotEmpty>

                <isNotEmpty prepend="AND" property="searchFilters.traceStatus">
                    <![CDATA[
					c.trace_status $searchFilters.traceStatus.operation$ #searchFilters.traceStatus.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.remark">
                    <![CDATA[
					c.remark $searchFilters.remark.operation$ #searchFilters.remark.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.crmSync">
                    <![CDATA[
					c.crm_sync $searchFilters.crmSync.operation$ #searchFilters.crmSync.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.hotline">
                    <![CDATA[
					c.status in (11,0,99)
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.lastManager">
                    <![CDATA[
					c.last_manager $searchFilters.lastManager.operation$ #searchFilters.lastManager.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.isDelete">
                    <![CDATA[
					c.is_delete $searchFilters.isDelete.operation$ #searchFilters.isDelete.value#
		            ]]>
                </isNotEmpty>

                <isNotEmpty prepend="AND" property="searchFilters.typeFilter">
                    <![CDATA[
					 $searchFilters.typeFilter.value$
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.customerSourceType">
                    <![CDATA[
					customer_source_type $searchFilters.customerSourceType.operation$ #searchFilters.customerSourceType.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.customerRelId">
                    <![CDATA[
					customer_rel_id $searchFilters.customerRelId.operation$ #searchFilters.customerRelId.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.singupTime">
                    <![CDATA[
					singupTime $searchFilters.singupTime.operation$ #searchFilters.singupTime.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.marketActId">
                    <![CDATA[
					singupTime $searchFilters.marketActId.operation$ #searchFilters.marketActId.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.marketActName">
                    <![CDATA[
					marketActName $searchFilters.marketActName.operation$ #searchFilters.marketActName.value#
		            ]]>
                </isNotEmpty>
                <isNotNull prepend="AND" property="searchFilters.isHandover">
                    <![CDATA[
                    isHandover $searchFilters.isHandover.operation$ #searchFilters.isHandover.value#
                    ]]>
                </isNotNull>
                <isNotNull prepend="AND" property="searchFilters.isActive">
                    <![CDATA[
                    is_active = 1
                    ]]>
                </isNotNull>
                <isNotNull prepend="AND" property="searchFilters.isRecycled">
                    <![CDATA[
                    isRecycled $searchFilters.isRecycled.operation$ #searchFilters.isRecycled.value#
                    ]]>
                </isNotNull>
                <isNotNull prepend="AND" property="searchFilters.isNotRecycled">
                    <![CDATA[
                    isRecycled $searchFilters.isRecycled.operation$ #searchFilters.isRecycled.value#
                    ]]>
                </isNotNull>
            </isNotNull>
        </dynamic>
    </sql>

    <!-- 分页查询指定页记录 -->
    <select id="getWechatCustomers_count" resultClass="int">
        SELECT count(*) from
        (select c.*,(select last_change_status_time from customer_project cp where c.id = cp.customer_id
        <isNotEmpty prepend="AND" property="searchFilters.projectId">
            <![CDATA[
				  cp.project_id =#searchFilters.projectId.value#
		    ]]>
        </isNotEmpty>
        order by
        last_change_status_time desc limit 0,1) last_change_status_time from customer c
        <include refid="customer.queryWechatPage"/>
        ) as customer
    </select>

    <!-- 分页查询指定页记录 -->
    <select id="getWechatCustomers" resultMap="customer">
        SELECT * from
        (select c.*,(select last_change_status_time from customer_project cp where c.id = cp.customer_id
        <isNotEmpty prepend="AND" property="searchFilters.projectId">
            <![CDATA[
				  cp.project_id =#searchFilters.projectId.value#
		    ]]>
        </isNotEmpty>
        order by
        last_change_status_time desc limit 0,1) last_change_status_time from customer c
        <include refid="customer.queryWechatPage"/>
        ) as customer
        <isNotEmpty prepend="ORDER BY" property="searchFilters.orderBy">
            <![CDATA[
					 $searchFilters.orderBy.value$
		            ]]>
        </isNotEmpty>
        <![CDATA[
		    LIMIT #paging.startRecord#, #paging.pageSize#
        ]]>
    </select>

    <!-- 查询所有记录 -->
    <select id="queryAll" resultMap="customer">
        SELECT
        <include refid="customer.columns"/>
        <![CDATA[
		    FROM customer
	    ]]>
        <include refid="customer.queryPage"/>
    </select>

    <select id="getTotalCall" resultClass="java.lang.Integer">
        <![CDATA[
           select count(0) from customer c
        ]]>
        <include refid="customer.queryManagementPage"/>
    </select>

    <select id="getTotalCallOptimize" resultClass="java.lang.Integer">
        select count(distinct id) from customer c join (
        SELECT l.customer_id FROM
        customer_callback_log l
        <dynamic prepend="WHERE">
            <!-- 默认不开启实体作为条件 -->
            <isNotNull property="searchFilters">
                <isNotEmpty prepend="AND" property="searchFilters.totalCall">
                    <![CDATA[
                    l.source = 1 and l.call_record_id is not null
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.normalCall">
                    <![CDATA[
                    l.call_record_id is null
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.allCall">
                    <![CDATA[
                    (l.source != 1 or l.source is null) and l.call_record_id is not null
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.callTimeStart">
                    <![CDATA[
                        l.create_time $searchFilters.callTimeStart.operation$ #searchFilters.callTimeStart.value#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.callTimeEnd">
                    <![CDATA[
                        l.create_time $searchFilters.callTimeEnd.operation$ #searchFilters.callTimeEnd.value#
                    ]]>
                </isNotEmpty>
            </isNotNull>
        </dynamic>
        ) d on c.id=d.customer_id
        <include refid="customer.queryManagementPage"/>
    </select>

    <select id="getTotalAbandon" resultClass="java.lang.Integer">
        select count(0) from customer c join (
        SELECT l.customerId FROM market_customer l
        <dynamic prepend="WHERE">
            <!-- 默认不开启实体作为条件 -->
            <isNotNull property="searchFilters">
                <isNotEmpty prepend="AND" property="searchFilters.totalAbandon">
                    <![CDATA[
                    isabandon=1
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.abandonTimeStart">
                    <![CDATA[
                    abandon_time $searchFilters.abandonTimeStart.operation$ #searchFilters.abandonTimeStart.value#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.abandonTimeEnd">
                    <![CDATA[
                    abandon_time $searchFilters.abandonTimeEnd.operation$ #searchFilters.abandonTimeEnd.value#
                    ]]>
                </isNotEmpty>
            </isNotNull>
        </dynamic>
        ) d on c.id=d.customerId
        <include refid="customer.queryManagementPage"/>
    </select>

    <select id="getSummary" resultClass="java.util.HashMap">
        <![CDATA[
            SELECT (SELECT FORMAT(count(distinct c.id),0) from customer c where status in (11,0,99)
            and create_time >=DATE_FORMAT(NOW(),'%Y-%m-%d 00:00:00')
            and create_time <=DATE_FORMAT(NOW(),'%Y-%m-%d 23:59:59')
            and (manager_id in ($managerId$) )
            ) as newadd,
            (SELECT FORMAT(count(distinct c.id),0) from customer c where status in (11,0,99)  and  (manager_id in ($managerId$))
            ) as allCount,
            (SELECT FORMAT(count(distinct cp.customer_id),0) from customer_status_log as cp,customer as c where cp.customer_id = c.id
            and cp.to_status_id>0
            and cp.create_time >=DATE_FORMAT(NOW(),'%Y-%m-%d 00:00:00')
            and cp.create_time <=DATE_FORMAT(NOW(),'%Y-%m-%d 23:59:59')
            and (c.manager_id in ($managerId$))
            ) as newupdate,

            (select FORMAT(count(distinct c.id),0) from customer as c,customer_project as cp where c.id=cp.customer_id and cp.status=2 and to_days(cp.last_change_status_time) <to_days(now())-7 and
            (c.manager_id in ($managerId$))
            ) as noupdate
        ]]>
    </select>

    <select id="getNewSummary" parameterClass="java.util.HashMap" resultClass="java.util.HashMap">
        <![CDATA[
        SELECT
        (SELECT count(distinct c.id) from customer c where status != 0 and status != 99 and create_source = 'HOTLINE'
          and cityCode = #cityCode# and (manager_id = #userId# or manager_id IN (
                SELECT id FROM user WHERE depturlpath LIKE ( SELECT concat( depturlpath, '/%' ) FROM user WHERE id = #userId# ) ) )
        ) as call400Customer,
        (SELECT count(distinct c1.id) from
				(select id,manager_id from customer c where c.is_delete = 0 AND c.isWaitCall = 1 and c.cityCode = #cityCode# and c.status in (11,0,99)) c1,
				(
						SELECT id FROM user WHERE depturlpath LIKE ( SELECT concat( depturlpath, '/%' ) FROM user WHERE id = #userId# )
						union
						SELECT id FROM user WHERE id = #userId#
				) c2
				where 1=1
				and c1.manager_id=c2.id
        ) as waitVisitCustomer,
        (select count(distinct c1.id)
				from (
				select id,manager_id
				from customer c where status in (11,0,99) and cityCode = #cityCode#
				AND last_call_time > subdate( now() , interval 7 day)
				AND is_delete = 0
				AND ( isWaitCall = 0 OR isWaitCall IS NULL )) c1,(
						SELECT id FROM user WHERE depturlpath LIKE ( SELECT concat( depturlpath, '/%' ) FROM user WHERE id = #userId# )
						union
						SELECT id FROM user WHERE id = #userId#
				) c2
				where c1.manager_id=c2.id
        ) as last7ReVisit
        ]]>
    </select>

    <select id="getSummarySimple" resultClass="java.util.HashMap">
        <![CDATA[
        SELECT
        (SELECT FORMAT(count(distinct c.id),0) from customer c where status in (11,0,99)  and  (manager_id in ($managerId$))
        ) as allCount
        ]]>
    </select>

    <select id="getSummaryForCRM" resultClass="java.util.HashMap">
        <![CDATA[
        select (select count(0) signCount from customer_status_log where create_time >= date_sub(date_sub(date_format(now(),'%y-%m-%d'),interval extract(day from now())-1 day),interval 3 month) and customer_id in (select id from customer where phone like '%$phone$%') and to_status_id=5) as signCount,
        (select count(0) visitCount from customer_status_log where create_time >= date_sub(date_sub(date_format(now(),'%y-%m-%d'),interval extract(day from now())-1 day),interval 3 month) and customer_id in (select id from customer where phone like '%$phone$%') and to_status_id=2) as visitCount,
        (SELECT count(0) callCount from customer_callback_log where create_time >= date_sub(date_sub(date_format(now(),'%y-%m-%d'),interval extract(day from now())-1 day),interval 3 month) and customer_id in (select id from customer where phone like '%$phone$%')) as callCount
        ]]>
    </select>

    <select id="getSummary7ForCRM" resultClass="java.util.HashMap">
        <![CDATA[
        select (select count(0) signCount from customer_status_log where create_time >= date_sub(date_sub(date_format(now(),'%y-%m-%d'),interval extract(day from now())-1 day),interval 7 day) and customer_id in (select id from customer where phone like '%$phone$%') and to_status_id=5) as signCount,
        (select count(0) visitCount from customer_status_log where create_time >= date_sub(date_sub(date_format(now(),'%y-%m-%d'),interval extract(day from now())-1 day),interval 7 day) and customer_id in (select id from customer where phone like '%$phone$%') and to_status_id=2) as visitCount,
        (SELECT count(0) callCount from customer_callback_log where create_time >= date_sub(date_sub(date_format(now(),'%y-%m-%d'),interval extract(day from now())-1 day),interval 7 day) and customer_id in (select id from customer where phone like '%$phone$%')) as callCount
        ]]>
    </select>

    <select id="getSeaSummary" resultClass="java.util.HashMap">
        <![CDATA[
            select (select FORMAT(count(0),0) from customer where cityCode=#cityCode# and manager_id is null and is_delete = 0) as totalCount,
            (select FORMAT(count(0),0) from customer where (ocean_date>=date_sub(date_format(now(),'%y-%m-%d'),interval 7 day)) and cityCode=#cityCode# and manager_id is null and is_delete = 0) as sevenDayCount,
            (select FORMAT(count(0),0) from customer where (ocean_date>=date_format(now(),'%y-%m-%d')) and cityCode=#cityCode# and manager_id is null and is_delete = 0) as todayCount
        ]]>
    </select>

    <select id="getSeaSummary2" resultClass="java.util.HashMap">
        <![CDATA[
            SELECT
                count( 0 ) AS sevenDayCount
            FROM
                customer
            WHERE
                to_days(ocean_date) >=to_days(now())-7
                AND cityCode =#cityCode#
                AND manager_id IS NULL
                AND is_delete = 0
        ]]>
    </select>

    <select id="getSeaSummary3" resultClass="java.util.HashMap">
        <![CDATA[
            SELECT
                 count( 0 ) AS todayCount
            FROM
                customer
            WHERE
                to_days(ocean_date) >=to_days(now())
                AND cityCode =#cityCode#
                AND manager_id IS NULL
            AND is_delete = 0
        ]]>
    </select>

    <select id="statisticNoRecordByStatus" parameterClass="java.util.HashMap" resultClass="java.util.HashMap">
        <![CDATA[
            select act_source_id,act_source,count(0) num,
            d.name dept_name,d.id dept_id,d.urlPath,c.citycode,c.cityName
            from customer c,department d where c.status in (11,0,99)  and
            c.cityCode=d.descripition
            and c.create_time between #startDate# and #endDate#
            and c.id not in (select distinct customer_id from customer_project)
            group by c.act_source,c.act_source_id,c.citycode,c.cityName
        ]]>
    </select>

    <select id="statisticNoRecordByUser" parameterClass="java.util.HashMap" resultClass="java.util.HashMap">
        <![CDATA[
            select act_source_id,manager_id,manager_name,act_source,cityCode,cityName,count(0) num
            from customer c where c.status in (11,0,99)  and manager_id is not null and
            and c.create_time between #startDate# and #endDate#
            and c.id not in (select distinct customer_id from customer_project)
            group by manager_id,manager_name,act_source,act_source_id,cityCode,cityName
        ]]>
    </select>

    <select id="statisticNoRecordByDept" parameterClass="java.util.HashMap" resultClass="java.util.HashMap">
        <![CDATA[
            select 0 status_id,'未约看' status_name,c.act_source_id source_id,c.act_source,c.cityCode,c.cityName,count(0) num,
            d.name dept_name,d.id dept_id,d.name dept_name,d.urlpath
            from customer c,user u,department d where c.status in (11,0,99)  and manager_id is not null
            and c.create_time between #startDate# and #endDate#
            and c.manager_id=u.id and u.deptId = d.id
            and c.id not in (select distinct customer_id from customer_project)
            group by d.id,d.name,c.act_source,c.act_source_id,c.cityCode,c.cityName
        ]]>
    </select>

    <select id="statisticByStatus" parameterClass="java.util.HashMap" resultClass="java.util.HashMap">
        <![CDATA[
            select count(0) num, c.to_status_id status_id,c.to_status_name status_name,c.act_source_id source_id,c.act_source,
            c.cityCode,c.cityname
            from (
            select distinct a.to_status_id,a.to_status_name,a.project_id,a.customer_id,b.act_source_id,b.act_source,b.cityCode,b.cityname
            from customer_status_log a,customer b
            where b.status in (11,0,99)  and a.customer_id=b.id and a.to_status_id>0 and a.isRepeat=0 and a.nonStatistic=1
            and a.create_time between #startDate# and #endDate#
            ) c
            group by c.to_status_id,c.to_status_name,c.act_source,c.act_source_id,c.cityCode,c.cityname
        ]]>
    </select>

    <!--职员维度统计数据中城市为客户所属城市，因为查询时受当前选择的城市影响，其他维度统计仍为职员或部门所属城市，
    查询时受具体部门或职员条件影响，城市不作为查询条件，统计数据不做修改. 为了避免客户转移对统计数据造成影响，日志表中记录客户当前置业顾问，
    统计日志表中职员信息-->
    <select id="statisticByUser" parameterClass="java.util.HashMap" resultClass="java.util.HashMap">
        <![CDATA[
            select count(0) num, c.to_status_id status_id,c.to_status_name status_name,c.act_source_id source_id,c.act_source,
            c.customerManagerId manager_id,c.customerManagerName manager_name,c.cityname dept_name,d.id dept_id,d.urlPath
            from (
            select distinct a.to_status_id,a.to_status_name,a.project_id,
            a.customerManagerId,a.customerManagerName,a.customer_id,b.act_source_id,b.act_source,b.cityCode,b.cityname
            from customer_status_log a,customer b
            where b.status in (11,0,99)  and a.customer_id=b.id and a.to_status_id>0 and a.isRepeat=0 and a.nonStatistic=1
            and a.create_time between #startDate# and #endDate# and b.manager_id is not null
            ) c left join department d on c.cityCode = d.descripition
            group by c.to_status_id,c.to_status_name,c.act_source,c.act_source_id,
            c.customerManagerId,c.customerManagerName,c.cityname
        ]]>
    </select>

    <select id="statisticByDept" parameterClass="java.util.HashMap" resultClass="java.util.HashMap">
        <![CDATA[
            select count(0) num, c.to_status_id status_id,c.to_status_name status_name,c.act_source_id source_id,
            c.act_source,c.cityCode,c.cityName,d.id dept_id,d.name dept_name,d.urlpath
            from (
            select distinct a.to_status_id,a.to_status_name,a.project_id,
            a.customerManagerId,a.customerManagerName,a.customer_id,b.act_source,b.cityCode,b.cityName,b.act_source_id
            from customer_status_log a,customer b
            where  b.status in (11,0,99)  and a.customer_id=b.id and a.to_status_id>0 and a.isRepeat=0 and a.nonStatistic=1
            and a.create_time between #startDate# and #endDate# and b.manager_id is not null
            ) c,user u,department d
            where c.customerManagerId=u.id and u.deptId = d.id
            group by c.to_status_id,c.to_status_name,c.act_source,
            c.act_source_id,c.cityCode,c.cityName,d.id,d.name
        ]]>
    </select>

    <select id="statisticByProject" parameterClass="java.util.HashMap" resultClass="java.util.HashMap">
        <![CDATA[
            select count(0) num, c.to_status_id status_id,c.to_status_name status_name,c.act_source_id source_id,
               c.act_source,p.id project_id,p.projectName,c.cityCode,c.cityName
            from (
            select distinct a.to_status_id,a.to_status_name,
            b.manager_id,b.manager_name,a.project_id,a.customer_id,b.act_source,b.cityCode,b.cityname,b.act_source_id
            from customer_status_log a,customer b
            where b.status in (11,0,99)  and a.customer_id=b.id and a.to_status_id>0 and a.isRepeat=0 and a.nonStatistic=1
            and a.create_time between #startDate# and #endDate# and b.manager_id is not null
            ) c,user u,project p where c.manager_id=u.id and c.project_id=p.id
            group by c.to_status_id,c.to_status_name,c.act_source,c.act_source_id,p.id,p.projectName
        ]]>
    </select>

    <update id="updateName" parameterClass="java.util.HashMap">
        <![CDATA[
	        UPDATE customer SET
		        act_source = #name#
	        WHERE
		        act_source_id = #id#
        ]]>
    </update>

    <update id="updateManager" parameterClass="java.util.HashMap">
        <![CDATA[
	        UPDATE customer SET
		        manager_name=#managerName#
	        WHERE
		        manager_id = #managerId#
        ]]>
    </update>

    <!--我的客户统计信息-->
    <!--今日新增客户-->
    <select id="getNewCustomerIds" resultClass="java.util.HashMap">
        <![CDATA[
        SELECT id from customer where status in (11,0,99)  and TIMESTAMPDIFF(DAY,date_format(create_time,'%y-%m-%d'),date_format(CURDATE(),'%y-%m-%d'))=0 and
        (manager_id in ($managerId$)) and is_delete = 0
        ]]>
    </select>

    <!--今日驻场信息有更新-->
    <select id="getTodayUpdateIds" resultClass="java.util.HashMap">
        <![CDATA[
        SELECT c.id from customer_status_log as cp,customer as c where c.status in (11,0,99)  and cp.customer_id = c.id
        and cp.to_status_id>0
        and TIMESTAMPDIFF(DAY,date_format(cp.create_time,'%y-%m-%d'),date_format(CURDATE(),'%y-%m-%d'))=0 and
        (c.manager_id in ($managerId$)) and c.is_delete = 0
        ]]>
    </select>

    <!--超过7天未回访的新增客户-->
    <select id="getNocallSevenDayIds" resultClass="java.util.HashMap">
        <![CDATA[
        SELECT c.id from customer as c where c.status in (11,0,99)
        and TIMESTAMPDIFF(DAY,date_format(c.create_time,'%y-%m-%d'),date_format(CURDATE(),'%y-%m-%d'))>7
        and not exists(select 1 from customer_callback_log ccl where c.id = ccl.customer_id)
        and (c.manager_id in ($managerId$)) and c.is_delete = 0
        ]]>
    </select>

    <!--超过3天未回访的客户-->
    <select id="getNocallThreeDayIds" resultClass="java.util.HashMap">
        <![CDATA[
        SELECT c.id from customer as c where c.status in (11,0,99)
        and TIMESTAMPDIFF(DAY,date_format(c.last_call_time,'%y-%m-%d'),date_format(CURDATE(),'%y-%m-%d'))>3
        and (c.manager_id in ($managerId$)) and c.is_delete = 0
        ]]>
    </select>

    <!--已到访后超过7天状态未更新的客户-->
    <select id="getNoStatusUpdateIds" resultClass="java.util.HashMap">
        <![CDATA[
        select c.id from customer as c,customer_project as cp where c.status in (11,0,99)
        and c.id=cp.customer_id and cp.status=2
        and TIMESTAMPDIFF(DAY,date_format(cp.last_change_status_time,'%y-%m-%d'),date_format(CURDATE(),'%y-%m-%d'))>7 and
        (c.manager_id in ($managerId$)) and c.is_delete = 0
        ]]>
    </select>

    <!--已约见后超过N天未到访的客户-->
    <select id="getNoVisitIdsByDays" resultClass="java.util.HashMap">
        <![CDATA[
        select c.id,c.phone,c.manager_id managerId from customer_merge as c,customer_project as cp
        where c.status in (11,0,99)
        and (
        select count(1) from customer_merge as cc,customer_project as ccp where cc.id = ccp.customer_id and ccp.status != 1
        and cc.status in (11,0,99)
        and ccp.last_change_status_time>cc.bind_time and cc.id = c.id)=0
        and c.manager_id is not null
         and c.is_delete = 0
        and c.bind_time is not null
        and c.id=cp.customer_id
        and c.cityCode= #city#
        and TIMESTAMPDIFF(DAY,date_format(c.bind_time,'%y-%m-%d'),date_format(CURDATE(),'%y-%m-%d')) >= $days$
        ]]>
    </select>

    <!--已到访后超过N天未认筹的客户-->
    <select id="getNoPledgedIdsByDays" resultClass="java.util.HashMap">
        <![CDATA[
        select c.id,c.phone,c.manager_id from customer_merge as c,customer_project as cp
        where c.status in (11,0,99)
        and c.manager_id is not null
        and c.bind_time is not null
        and c.id=cp.customer_id
        and c.cityCode= #city#
         and c.is_delete = 0
        and cp.id = (select MAX(id) from customer_project cpa where cpa.status = #status# and c.id = cpa.customer_id)
        and TIMESTAMPDIFF(DAY,date_format(cp.last_change_status_time,'%y-%m-%d'),date_format(CURDATE(),'%y-%m-%d')) >= $days$

        ]]>
    </select>

    <!--待回访中超过限定时间未回访的客户-->
    <select id="getNoCallByHours" resultClass="java.util.HashMap">
        <![CDATA[
        select id from customer where TIMESTAMPDIFF(HOUR,bind_time,NOW()) >= $hours$
        and customer_source_type=3 and is_delete = 0 and isWaitCall=1 and citycode=#city#
        and manager_id is not null
        ]]>
    </select>

    <!-- wechat -->

    <!--今日新增客户-->
    <select id="getNewAddCustomerIds" resultClass="java.lang.Integer">
        <![CDATA[
        SELECT id from customer where status in (11,0,99)  and TIMESTAMPDIFF(DAY,date_format(create_time,'%y-%m-%d'),date_format(CURDATE(),'%y-%m-%d'))=0 and
        (manager_id in ($managerId$))
        ]]>
    </select>

    <!-- 7日新增客户-->
    <select id="getSevenDayNewCustomerIds" resultClass="java.lang.Integer">
        <![CDATA[
        SELECT id from customer where status in (11,0,99)  and TIMESTAMPDIFF(DAY,date_format(create_time,'%y-%m-%d'),date_format(CURDATE(),'%y-%m-%d'))<=7 and
        (manager_id in ($managerId$))
        ]]>
    </select>

    <!--3天内回访的客户-->
    <select id="getCallInThreeDayIds" resultClass="java.lang.Integer">
        <![CDATA[
        SELECT c.id from customer as c where c.status in (11,0,99)  and TIMESTAMPDIFF(DAY,date_format(c.last_call_time,'%y-%m-%d'),date_format(CURDATE(),'%y-%m-%d'))<=3 and
        (c.manager_id in ($managerId$))
        ]]>
    </select>

    <!-- 星标客户-->
    <select id="getStarCustomerIds" resultClass="java.lang.Integer">
        <![CDATA[
            SELECT distinct c.customer_id from customer_user as c,customer as cu
            where c.customer_id = cu.id and (c.user_id in ($managerId$)) and star = 1 and cu.manager_id in($managerId$)
        ]]>
    </select>

    <!-- 微信我的客户概要 -->
    <select id="getWechatMyCucstomerSummary" resultClass="java.util.HashMap">
        <![CDATA[
            SELECT (SELECT FORMAT(count(0),0) from customer where status in (11,0,99)  and TIMESTAMPDIFF(DAY,date_format(create_time,'%y-%m-%d'),date_format(CURDATE(),'%y-%m-%d'))=0 and
            (manager_id in ($managerId$))
            ) as newadd,
            (SELECT FORMAT(count(0),0) from customer where status in (11,0,99)  and (manager_id in ($managerId$))
            ) as allCount,
            (SELECT FORMAT(count(0),0) from customer where status in (11,0,99)  and TIMESTAMPDIFF(DAY,date_format(create_time,'%y-%m-%d'),date_format(CURDATE(),'%y-%m-%d'))<=7 and
            (manager_id in ($managerId$))
            ) as add7,
            (SELECT FORMAT(count(0),0) from customer as c where status in (11,0,99)  and TIMESTAMPDIFF(DAY,date_format(c.last_call_time,'%y-%m-%d'),date_format(CURDATE(),'%y-%m-%d'))<=3 and
            (c.manager_id in ($managerId$))
            ) as call3,
            (SELECT FORMAT(count(0),0) from customer_user as c,customer as cu where c.customer_id = cu.id and
            (c.user_id in ($managerId$)) and star = 1 and cu.manager_id in($managerId$)
            ) as star
        ]]>
    </select>

    <!-- 微信我的客户置业顾问视图 -->
    <select id="getWechatMyCucstomerUserView" resultClass="java.util.HashMap">
        <![CDATA[
            select u1.id,u1.name,u1.realName,u1.mobile,u1.position,
            (SELECT FORMAT(count(0),0) from customer where status in (11,0,99)  and  TIMESTAMPDIFF(DAY,date_format(create_time,'%y-%m-%d'),date_format(CURDATE(),'%y-%m-%d'))=0 and
            (manager_id = u1.id or manager_id in (select id from user where depturlpath like (select concat(depturlpath,'/%') from user where id = u1.id)))) as newadd,
            (SELECT FORMAT(count(0),0) from customer where status in (11,0,99)  and
            (manager_id = u1.id or manager_id in (select id from user where depturlpath like (select concat(depturlpath,'/%') from user where id = u1.id)))) as allcustomer,
            (SELECT FORMAT(count(0),0) from customer as c where status in (11,0,99)  and  TIMESTAMPDIFF(DAY,date_format(c.last_call_time,'%y-%m-%d'),date_format(CURDATE(),'%y-%m-%d'))<=3 and
            (manager_id = u1.id or manager_id in (select id from user where depturlpath like (select concat(depturlpath,'/%') from user where id = u1.id)))) as callin3,
            (select FORMAT(count(0),0) from customer as cu,customer_status_log as cp where cu.status in (11,0,99)  and
            (cu.manager_id = u1.id or cu.manager_id in (select id from user where depturlpath like (select concat(depturlpath,'/%') from user where id = u1.id)))
            and cu.id=cp.customer_id and cp.to_status_id=2 and
            TIMESTAMPDIFF(DAY,date_format(cp.create_time,'%y-%m-%d'),date_format(CURDATE(),'%y-%m-%d'))<=7) as visitin7
            FROM
                user u1
            WHERE
                u1.id in ($managerId$)
                LIMIT #startRecord#, #pageSize#
        ]]>
    </select>

    <select id="getLastestCallback" resultClass="java.util.HashMap">
        <![CDATA[
            SELECT
	          customer_id,
	          (select create_time from customer_callback_log where customer_id in ($customerIds$) order by create_time desc limit 1) create_time,
	          (select content from customer_callback_log where customer_id in ($customerIds$) order by create_time desc limit 1) content
            FROM
	          customer_callback_log t1
            WHERE t1.customer_id IN ( $customerIds$ ) limit 1
        ]]>
    </select>

    <!--CRM 统计数据  https://doc.qmail.com/docs/p/v2_5ddce2508469751b6d5c6ea1f71d2?proxy=1&docsid=715E12E67AF759A9836715268763E4AF&op=view&from=3rd-->
    <select id="crmVisitAndSignCustomer" resultClass="com.house365.beans.vo.CrmVisitAndSignCustomer">
        <!--
        <![CDATA[
            select b.*,p.buildingId,p.contractCode,
            (case c.create_source when 'CRM' then 2 else 1 end) as source_form
            ,c.act_source as source_name,c.crmId
            ,c.phone,c.cityCode as city from (
            SELECT a.customer_id, a.project_id,
            a.to_status_id as state
            ,date_format(a.create_time ,'%y-%m') as month
            FROM customer_status_log a where a.project_id is not null and a.to_status_id IN ]]>
            <isNotEmpty property="state">
                <iterate prepend="" property="state" open="(" close=")" conjunction=",">
                    <![CDATA[ #state[]# ]]>
                </iterate>
            </isNotEmpty>
        <![CDATA[
             and a.create_time = (select max(create_time) from customer_status_log z where
            z.customer_id=a.customer_id and z.project_id=a.project_id and z.to_status_id IN ]]>
        <isNotEmpty property="state">
            <iterate prepend="" property="state" open="(" close=")" conjunction=",">
                <![CDATA[ #state[]# ]]>
            </iterate>
        </isNotEmpty>
        <![CDATA[
            )
            order by project_id
            ) b left join customer c on b.customer_id =c.id
            left join project p on b.project_id=p.id
        ]]>
            where month=#month#
        <isNotEmpty prepend="AND" property="city">
            <![CDATA[ city = #city# ]]>
        </isNotEmpty>
        -->

        <![CDATA[
            SELECT
                a.customer_id,a.project_id,a.to_status_id AS `state`,
                date_format(a.occur_time, '%y-%m') AS `MONTH`,p.buildingId,p.contractCode,
                (CASE c.create_source WHEN 'CRM' THEN 2 ELSE 1 END) AS source_form,
                c.act_source AS source_name, c.crmId, c.phone, c.cityCode AS city
            FROM
                customer_status_log a
            LEFT JOIN customer c ON a.customer_id = c.id
            LEFT JOIN project p ON a.project_id = p.id
            WHERE
                a.project_id IS NOT NULL
            AND	date_format(a.occur_time, '%y-%m') = #month# ]]>
        <isNotEmpty prepend="AND" property="city">
            <![CDATA[ city = #city# ]]>
        </isNotEmpty>
        <![CDATA[
            AND a.to_status_id IN ]]>
        <isNotEmpty property="state">
            <iterate prepend="" property="state" open="(" close=")" conjunction=",">
                <![CDATA[ #state[]# ]]>
            </iterate>
        </isNotEmpty>
        <![CDATA[
            GROUP BY
                a.customer_id, a.project_id, a.to_status_id
        ]]>
    </select>

    <!-- 通过ID删除 -->
    <delete id="delDynamic">
        <![CDATA[
	        DELETE FROM base_attachment WHERE
	        resourceId = #id#
        ]]>
    </delete>

    <sql id="customer.newColumns">
        <![CDATA[
        id, name, phone, bak_phone1, bak_phone2, bak_phone3, sex, customer_type, act_source,
        first_source, latest_source, crm_latest_call, crm_latest_call_result, status, create_source,
        create_time, creater, buy_intention, last_visit_time, last_call_time, manager_id, manager_name,
        update_time, updater, cityCode,cityName, biz_port,crmId,act_source_id, trace_status, remark, crm_sync,
        hotline_call_time,hotline_call_spend,ocean_date,is_delete,last_manager,bind_time, customer_source_type,
         customer_rel_id, isWaitCall, singupTime,marketActId, marketActName, isHandover, isRecycled,is_active
        ]]>
    </sql>

    <!-- 通过ID修改 -->
    <update id="updateOldCustomers" parameterClass="customerEntity">
        <![CDATA[
	        UPDATE customer SET
		        buy_intention = '',
		        manager_id = #managerId#,
		        manager_name = #managerName#,
		        update_time = #updateTime#,
		        updater = #updater#,
		        bind_time = #bindTime#,
		        isRecycled=#isRecycled#
	        WHERE 1=1
		        and phone = #phone#
		        and last_manager = #managerName#
		        and manager_id is NULL
		        and cityCode = #cityCode#
		        and is_delete = #isDelete#
        ]]>
    </update>
</sqlMap>
