<?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.UserEntity">
    <typeAlias alias="userEntity" type="com.house365.beans.entity.UserEntity" />
    <typeAlias alias="userSimpleEntity" type="com.house365.beans.entity.UserSimpleEntity" />
    <typeAlias alias="VersionEntity" type="com.house365.beans.entity.VersionEntity" />
    <typeAlias alias="RequestLoginEntity" type="com.house365.beans.entity.RequestLoginEntity" />
    <typeAlias alias="userEvaluateEntity" type="com.house365.beans.entity.UserEvaluateEntity" />

    <resultMap id="user" class="com.house365.beans.entity.UserEntity">
        <result property="id" column="id" />
        <result property="name" column="name" />
        <result property="realName" column="realName" />
        <result property="password" column="password" />
        <result property="weiXinId" column="weiXinId" />
        <result property="mediaId" column="mediaId" />
        <result property="mobile" column="mobile" />
        <result property="cornet" column="cornet"/>
        <result property="deptId" column="deptId" />
        <result property="deptUrlPath" column="deptUrlPath" />
        <result property="position" column="position" />
        <result property="gender" column="gender" />
        <result property="email" column="email" />
        <result property="extattr" column="extattr" />
        <result property="status" column="status" />
        <result property="enabled" column="enabled" />
        <result property="createUserid" column="createUserid" />
        <result property="createUsername" column="createUsername" />
        <result property="createTime" column="createTime" />
        <result property="createIp" column="createIp" />
        <result property="updateUserid" column="updateUserid" />
        <result property="updateUsername" column="updateUsername" />
        <result property="updateTime" column="updateTime" />
        <result property="updateIp" column="updateIp" />
        <result property="preLoginTime" column="preLoginTime" />
        <result property="lastLoginTime" column="lastLoginTime" />
        <result property="score" column="score"/>
        <result property="evaluateCount" column="evaluateCount"/>
        <result property="hotlinephone" column="hotlinephone" />
        <result property="goodat" column="goodat" />
        <result property="description" column="description" />
        <result property="headImgURL" column="headImgURL" />
        <result property="fullImgURL" column="fullImgURL" />
        <result property="isFreeMan" column="isFreeMan" />
        <result property="defaultVisit" column="defaultVisit" />
        <result property="accId" column="accid"/>
        <result property="identityType" column="identityType"/>
        <result property="token" column="token"/>
        <result property="limitLogin" column="limitLogin"/>
        <result property="wxNumber" column="wx_number"/>
        <result property="wxCodeImgUrl" column="wx_code_imgUrl"/>
        <result property="promoteId" column="promote_id"/>
        <result property="onlineStatus" column="online_status"/>
    </resultMap>

    <!-- 用于select查询公用抽取的列 -->
    <sql id="user.columns">
        <![CDATA[
        id, name,realName, password, weiXinId, mediaId, mobile, cornet, deptId, deptUrlPath, position, gender,
        email, extattr, status, enabled, createUserid, createUsername, createTime, createIp, updateUserid,
        updateUsername, updateTime, updateIp, preLoginTime, lastLoginTime, hotlinephone, goodat,
        description, headImgURL, fullImgURL,isFreeMan,defaultVisit,accid,identityType,token,limitLogin,
        wx_number as wxNumber,wx_code_imgUrl as wxCodeImgUrl,promote_id AS promoteId,online_status AS onlineStatus
	    ]]>
    </sql>

    <insert id="saveUnbindLog" parameterClass="userEntity">
        insert into user_unbind_log (name,realName,mobile,createUserid,createUsername,createTime,cornet,hotlinephone,accid,identityType) VALUES
        (#name#,#realName#,#mobile#,#createUserid#,#createUsername#,#createTime#,#cornet#,#hotlinephone#,#accId#,#identityType#)
    </insert>

    <!-- 新增记录 -->
    <insert id="save" parameterClass="userEntity">
        <![CDATA[
	        INSERT INTO user (
	        	id,
	        	name,
	        	realName,
	        	password,
	        	weiXinId,
	        	mediaId,
	        	mobile,
	        	cornet,
	        	deptId,
	        	deptUrlPath,
	        	position,
	        	gender,
	        	email,
	        	extattr,
	        	status,
	        	enabled,
	        	createUserid,
	        	createUsername,
	        	createTime,
	        	createIp,
	        	updateUserid,
	        	updateUsername,
	        	updateTime,
	        	updateIp,
	        	preLoginTime,
	        	lastLoginTime,
	        	hotlinephone, goodat, description, headImgURL, fullImgURL,isFreeMan,limitLogin,promote_id
	        ) VALUES (
	        	#id#,
	        	#name#,
	        	#realName#,
	        	#password#,
	        	#weiXinId#,
	        	#mediaId#,
	        	#mobile#,
	        	#cornet#,
	        	#deptId#,
	        	#deptUrlPath#,
	        	#position#,
	        	#gender#,
	        	#email#,
	        	#extattr#,
	        	#status#,
	        	#enabled#,
	        	#createUserid#,
	        	#createUsername#,
	        	#createTime#,
	        	#createIp#,
	        	#updateUserid#,
	        	#updateUsername#,
	        	#updateTime#,
	        	#updateIp#,
	        	#preLoginTime#,
	        	#lastLoginTime#,
	        	#hotlinephone#, #goodat#, #description#, #headImgURL#, #fullImgURL#,#isFreeMan#,#limitLogin#,#promoteId#
	        )
	    ]]>
        <selectKey resultClass="java.lang.Integer" type="post" keyProperty="id">
            SELECT LAST_INSERT_ID()
        </selectKey>
    </insert>

    <!-- 通过ID修改 -->
    <update id="update" parameterClass="userEntity">
        UPDATE user
        <dynamic prepend="SET">
            <isNotEmpty prepend="," property="limitLogin">
                <![CDATA[
					limitLogin = #limitLogin#
		            ]]>
            </isNotEmpty>
            <isNotEmpty prepend="," property="name">
                <![CDATA[
					name = #name#
		            ]]>
            </isNotEmpty>
            <isNotEmpty prepend="," property="realName">
                <![CDATA[
					realName = #realName#
		            ]]>
            </isNotEmpty>
            <isNotEmpty prepend="," property="password">
                <![CDATA[
					password = #password#
		            ]]>
            </isNotEmpty>
            <isNotEmpty prepend="," property="weiXinId">
                <![CDATA[
					weiXinId = #weiXinId#
		            ]]>
            </isNotEmpty>
            <isNotEmpty prepend="," property="mediaId">
                <![CDATA[
					mediaId = #mediaId#
		            ]]>
            </isNotEmpty>
            <isNotEmpty prepend="," property="mobile">
                <![CDATA[
					mobile = #mobile#
		            ]]>
            </isNotEmpty>
            <isNotEmpty prepend="," property="cornet">
                <![CDATA[
					cornet = #cornet#
		            ]]>
            </isNotEmpty>
            <isNotEmpty prepend="," property="deptId">
                <![CDATA[
					deptId = #deptId#
		            ]]>
            </isNotEmpty>
            <isNotEmpty prepend="," property="deptUrlPath">
                <![CDATA[
					deptUrlPath = #deptUrlPath#
		            ]]>
            </isNotEmpty>
            <isNotEmpty prepend="," property="position">
                <![CDATA[
					position = #position#
		            ]]>
            </isNotEmpty>
            <isNotEmpty prepend="," property="gender">
                <![CDATA[
					gender = #gender#
		            ]]>
            </isNotEmpty>
            <isNotEmpty prepend="," property="email">
                <![CDATA[
					email = #email#
		            ]]>
            </isNotEmpty>
            <isNotEmpty prepend="," property="extattr">
                <![CDATA[
					extattr = #extattr#
		            ]]>
            </isNotEmpty>
            <isNotEmpty prepend="," property="status">
                <![CDATA[
					status = #status#
		            ]]>
            </isNotEmpty>
            <isNotEmpty prepend="," property="enabled">
                <![CDATA[
					enabled = #enabled#
		            ]]>
            </isNotEmpty>
            <isNotEmpty prepend="," property="createUserid">
                <![CDATA[
					createUserid = #createUserid#
		            ]]>
            </isNotEmpty>
            <isNotEmpty prepend="," property="createUsername">
                <![CDATA[
					createUsername = #createUsername#
		            ]]>
            </isNotEmpty>
            <isNotEmpty prepend="," property="createTime">
                <![CDATA[
					createTime = #createTime#
		            ]]>
            </isNotEmpty>
            <isNotEmpty prepend="," property="createIp">
                <![CDATA[
					createIp = #createIp#
		            ]]>
            </isNotEmpty>
            <isNotEmpty prepend="," property="updateUserid">
                <![CDATA[
					updateUserid = #updateUserid#
		            ]]>
            </isNotEmpty>
            <isNotEmpty prepend="," property="updateUsername">
                <![CDATA[
					updateUsername = #updateUsername#
		            ]]>
            </isNotEmpty>
            <isNotEmpty prepend="," property="updateTime">
                <![CDATA[
					updateTime = #updateTime#
		            ]]>
            </isNotEmpty>
            <isNotEmpty prepend="," property="updateIp">
                <![CDATA[
					updateIp = #updateIp#
		            ]]>
            </isNotEmpty>
            <isNotEmpty prepend="," property="preLoginTime">
                <![CDATA[
					preLoginTime = #preLoginTime#
		            ]]>
            </isNotEmpty>
            <isNotEmpty prepend="," property="lastLoginTime">
                <![CDATA[
					lastLoginTime = #lastLoginTime#
		            ]]>
            </isNotEmpty>
            <isNotEmpty prepend="," property="hotlinephone">
                <![CDATA[
					hotlinephone = #hotlinephone#
		            ]]>
            </isNotEmpty>
            <isEmpty prepend="," property="hotlinephone">
                <![CDATA[
					hotlinephone = ''
		            ]]>
            </isEmpty>
            <isNotEmpty prepend="," property="goodat">
                <![CDATA[
					goodat = #goodat#
		            ]]>
            </isNotEmpty>
            <isNotEmpty prepend="," property="description">
                <![CDATA[
					description = #description#
		            ]]>
            </isNotEmpty>
            <isNotEmpty prepend="," property="headImgURL">
                <![CDATA[
					headImgURL = #headImgURL#
		            ]]>
            </isNotEmpty>
            <isNotEmpty prepend="," property="fullImgURL">
                <![CDATA[
					fullImgURL = #fullImgURL#
		            ]]>
            </isNotEmpty>
            <isNotEmpty prepend="," property="isFreeMan">
                <![CDATA[
					isFreeMan = #isFreeMan#
		            ]]>
            </isNotEmpty>
            <isEmpty prepend="," property="isFreeMan">
                <![CDATA[
					isFreeMan = 0
		            ]]>
            </isEmpty>
            <isNotEmpty prepend="," property="defaultVisit">
                <![CDATA[
					defaultVisit = #defaultVisit#
		            ]]>
            </isNotEmpty>

            <isNotEmpty prepend="," property="accId">
                <![CDATA[
					accid = #accId#
		            ]]>
            </isNotEmpty>
            <isNotEmpty prepend="," property="identityType">
                <![CDATA[
					identityType = #identityType#
		            ]]>
            </isNotEmpty>
            <isNotEmpty prepend="," property="token">
                <![CDATA[
					token = #token#
		            ]]>
            </isNotEmpty>
            <isNotEmpty prepend="," property="wxNumber">
                <![CDATA[
					wx_number = #wxNumber#
		            ]]>
            </isNotEmpty>
            <isNotEmpty prepend="," property="wxCodeImgUrl">
                <![CDATA[
					wx_code_imgUrl = #wxCodeImgUrl#
		            ]]>
            </isNotEmpty>
            <isNotEmpty prepend="," property="promoteId">
                <![CDATA[
					promote_id = #promoteId#
		            ]]>
            </isNotEmpty>
        </dynamic>
        WHERE
        id = #id#
    </update>

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

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

    <!-- 通过ID查询 -->
    <select id="getById" resultClass="userEntity">
        SELECT
        <include refid="user.columns" />
        ,(select name from department d where d.id = u.deptId) deptName
        ,(select ifnull(format(AVG(eucl.score),1),0) from evaluate_user_customer_log eucl where eucl.user_id = #id# and
        eucl.check_status =1 and eucl.is_deleted = 0)
        score
        ,(select count(1) from evaluate_user_customer_log eucl where eucl.user_id = #id# and eucl.check_status =1 and
        eucl.is_deleted = 0)
        evaluateCount
        <![CDATA[
	        FROM user u
	        WHERE
		        id = #id#
	    ]]>
    </select>

    <!-- 通过姓名查询ACCID -->
    <select id="getAccidByName" resultClass="userSimpleEntity">
        SELECT
        accid,realName
        <![CDATA[
	        FROM user u
	        WHERE 1=1
	        and u.deptUrlPath REGEXP (select urlpath from city_urlpath p where p.city=#cityCode#)
		    and realName LIKE concat(#realName#,'%')
		    and accid is not null
	    ]]>
    </select>

    <select id="getRemotePath" resultClass="userEntity">
        SELECT
        remotePath
        <![CDATA[
	        FROM base_attachment
	        WHERE
		        resourceid = #resourceId#
		        and resourceType='hgs_user_headImg'
	    ]]>
    </select>

    <select id="getCityName" resultClass="userEntity">
        SELECT
        cityName
        <![CDATA[
	        FROM city
	        WHERE
		        cityId = #city#
	    ]]>
    </select>

    <select id="getByCity" resultClass="userEntity">
        SELECT
        id,imshow
        <![CDATA[
	        FROM im_show_window
	        WHERE
		        city = #city#
	    ]]>
    </select>

    <select id="getUserEvaluation" resultClass="userEntity">
        SELECT
        goodat,id,description,realName,cornet,accid as accId,hotlinephone,defaultVisit,
        (select ifnull(format(AVG(eucl.score),1),0) from evaluate_user_customer_log eucl where eucl.user_id = u.id and
        eucl.check_status =1 and eucl.is_deleted = 0)
        score
        ,(select count(1) from evaluate_user_customer_log eucl where eucl.user_id = u.id and eucl.check_status =1 and
        eucl.is_deleted = 0)
        evaluateCount
        <![CDATA[
	        FROM user u
	        WHERE
		        accid = #accId#
	    ]]>
    </select>

    <!-- 用于分页查询抽取的公共的条件 -->
    <sql id="user.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.name">
                    <![CDATA[
					name $searchFilters.name.operation$ #searchFilters.name.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.realName">
                    <![CDATA[
					realName $searchFilters.realName.operation$ #searchFilters.realName.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.password">
                    <![CDATA[
					password $searchFilters.password.operation$ #searchFilters.password.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.weiXinId">
                    <![CDATA[
					weiXinId $searchFilters.weiXinId.operation$ #searchFilters.weiXinId.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.mediaId">
                    <![CDATA[
					mediaId $searchFilters.mediaId.operation$ #searchFilters.mediaId.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.mobile">
                    <![CDATA[
					mobile $searchFilters.mobile.operation$ #searchFilters.mobile.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.cornet">
                    <![CDATA[
					cornet $searchFilters.cornet.operation$ #searchFilters.cornet.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.deptId">
                    <![CDATA[
					deptId $searchFilters.deptId.operation$ #searchFilters.deptId.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.deptUrlPath">
                    <![CDATA[
					(deptUrlPath $searchFilters.deptUrlPath.operation$ #searchFilters.deptUrlPath.value# or deptUrlPath = #searchFilters.deptUrlPath.value#)
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.deptUrlPath2">
                    <![CDATA[
					(deptUrlPath like CONCAT(#searchFilters.deptUrlPath2.value#,'/%') or deptUrlPath = #searchFilters.deptUrlPath3.value#)
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.position">
                    <![CDATA[
					position $searchFilters.position.operation$ #searchFilters.position.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.gender">
                    <![CDATA[
					gender $searchFilters.gender.operation$ #searchFilters.gender.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.email">
                    <![CDATA[
					email $searchFilters.email.operation$ #searchFilters.email.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.extattr">
                    <![CDATA[
					extattr $searchFilters.extattr.operation$ #searchFilters.extattr.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.status">
                    <![CDATA[
					status $searchFilters.status.operation$ #searchFilters.status.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.enabled">
                    <![CDATA[
					enabled $searchFilters.enabled.operation$ #searchFilters.enabled.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.createUserid">
                    <![CDATA[
					createUserid $searchFilters.createUserid.operation$ #searchFilters.createUserid.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.createUsername">
                    <![CDATA[
					createUsername $searchFilters.createUsername.operation$ #searchFilters.createUsername.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.createTime">
                    <![CDATA[
					createTime $searchFilters.createTime.operation$ #searchFilters.createTime.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.createIp">
                    <![CDATA[
					createIp $searchFilters.createIp.operation$ #searchFilters.createIp.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.updateUserid">
                    <![CDATA[
					updateUserid $searchFilters.updateUserid.operation$ #searchFilters.updateUserid.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.updateUsername">
                    <![CDATA[
					updateUsername $searchFilters.updateUsername.operation$ #searchFilters.updateUsername.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.updateTime">
                    <![CDATA[
					updateTime $searchFilters.updateTime.operation$ #searchFilters.updateTime.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.updateIp">
                    <![CDATA[
					updateIp $searchFilters.updateIp.operation$ #searchFilters.updateIp.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.preLoginTime">
                    <![CDATA[
					preLoginTime $searchFilters.preLoginTime.operation$ #searchFilters.preLoginTime.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.lastLoginTime">
                    <![CDATA[
					lastLoginTime $searchFilters.lastLoginTime.operation$ #searchFilters.lastLoginTime.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.urlPathLike">
                    <![CDATA[
					deptUrlPath like CONCAT(#searchFilters.urlPathLike.value#,'%')
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.goodatNotnull">
                    <![CDATA[
					goodat is not null
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.headImgNotnull">
                    <![CDATA[
					exists ((SELECT 1 FROM base_attachment as b where b.resourceid=u.id and b.resourceType='hgs_user_headImg'))
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.fullImgNotnull">
                    <![CDATA[
					exists ((SELECT 1 FROM base_attachment as b where b.resourceid=u.id and b.resourceType='hgs_user_fullImg'))
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.goodat">
                    <![CDATA[
					goodat $searchFilters.goodat.operation$ #searchFilters.goodat.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.descriptionNotnull">
                    <![CDATA[
					description is not null
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.description">
                    <![CDATA[
					description $searchFilters.description.operation$ #searchFilters.description.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.headImgURL">
                    <![CDATA[
					headImgURL $searchFilters.headImgURL.operation$ #searchFilters.headImgURL.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.fullImgURL">
                    <![CDATA[
					fullImgURL $searchFilters.fullImgURL.operation$ #searchFilters.fullImgURL.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.hotlinephone">
                    <![CDATA[
					hotlinephone $searchFilters.hotlinephone.operation$ #searchFilters.hotlinephone.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.isFreeMan">
                    <![CDATA[
					isFreeMan $searchFilters.isFreeMan.operation$ #searchFilters.isFreeMan.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.hotlinephoneNotnull">
                    <![CDATA[
					hotlinephone is not null
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.identityType">
                    <![CDATA[
					identityType $searchFilters.identityType.operation$ #searchFilters.identityType.value#
		            ]]>
                </isNotEmpty>

            </isNotNull>
        </dynamic>
        <dynamic prepend="ORDER BY">
            <isNotNull property="orderColumn">
                <![CDATA[
				$orderColumn$
				]]>
                <isNotNull property="orderMode">
                    $orderMode$
                </isNotNull>
            </isNotNull>
        </dynamic>
    </sql>

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

    <!-- 分页查询指定页记录 -->
    <select id="queryByPage" resultClass="userEntity">
        SELECT
        <include refid="user.columns"/>
        ,(select name from department d where d.id = u.deptId) deptName
        ,(select distinct city from dept_source_statistics where projectId=u.deptId limit 1) city
        ,(select ifnull(format(AVG(eucl.score),1),0) from evaluate_user_customer_log eucl where eucl.user_id = u.id and
        eucl.check_status =1 and eucl.is_deleted = 0)
        score
        ,(select count(1) from evaluate_user_customer_log eucl where eucl.user_id = u.id and eucl.check_status =1 and
        eucl.is_deleted = 0)
        evaluateCount
        <![CDATA[
	        FROM user u
	    ]]>
        <include refid="user.queryPage" />
        <![CDATA[
		    LIMIT #paging.startRecord#, #paging.pageSize#
        ]]>
    </select>

    <!-- 查询所有记录 -->
    <select id="queryAll" resultClass="userEntity">
        SELECT
        <include refid="user.columns"/>
        ,(select name from department d where d.id = u.deptId) deptName
        ,(select ifnull(format(AVG(eucl.score),1),0) from evaluate_user_customer_log eucl where eucl.user_id = u.id and
        eucl.check_status =1 and eucl.is_deleted = 0)
        score
        ,(select count(1) from evaluate_user_customer_log eucl where eucl.user_id = u.id and eucl.check_status =1 and
        eucl.is_deleted = 0)
        evaluateCount
        <![CDATA[
		    FROM user u
	    ]]>
        <include refid="user.queryPage" />
    </select>

    <!-- 给CRM提供所有短号绑定的人员-->
    <select id="queryShortNum4Crm" resultClass="userEntity">
        select id, name,realName,cornet,hotlinephone,  mobile,  deptId,deptUrlPath,accid,
        case when identityType=1 then '安家顾问' when identityType=3 then '房博士' end as identityType,deptName
        ,(select name from department d where d.urlPath = t.deptUrlPath) cityName
        from (
        SELECT
        id, name,realName,cornet,hotlinephone,  mobile,  deptId, substring_index(deptUrlPath,'/',3) deptUrlPath,accid,identityType
        ,(select name from department d where d.id = u.deptId) deptName
        FROM user u) t
    </select>

    <select id="getMobilesByProject" resultClass="java.lang.String">
        select distinct u.mobile from user u,project_user pu where u.id=pu.userId and u.enabled=1 and pu.projectId=#projectId#
    </select>

    <select id="getIdsByProject" resultClass="java.lang.String">
        select distinct u.id from user u,project_user pu where u.id=pu.userId and u.enabled=1 and pu.projectId=#projectId#
    </select>

    <select id="getUserIdOnPath" resultClass="java.lang.Integer">
        select id from user c where c.id = $parentId$ or c.id in (select id from user where depturlpath like (select concat(depturlpath,'/%') from user where id = $parentId$))
    </select>

    <select id="getSummaryOld" 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 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 callin3,
        (SELECT FORMAT(count(0),0) from customer as c where STATUS in(11,0,99)  and  TIMESTAMPDIFF(DAY,date_format(c.last_visit_time,'%y-%m-%d'),date_format(CURDATE(),'%y-%m-%d'))<=7 and
        (c.manager_id in ($managerId$))
        ) as visitin7
        ]]>
    </select>

    <select id="getSummary" resultClass="java.util.HashMap">
        <![CDATA[
        SELECT (
        SELECT FORMAT(count(distinct id),0) from customer as c where STATUS in(11,0,99)  and isWaitCall = 1 and c.is_delete = 0 and (manager_id in ($managerId$))) as waitCount,
        (SELECT FORMAT(count(distinct id),0) from customer as c where STATUS in(11,0,99) and  (manager_id in ($managerId$))) as allCount,
        (select FORMAT(count(distinct id),0) from customer as c join ( SELECT l.customer_id FROM customer_callback_log l where  TIMESTAMPDIFF(DAY,date_format(create_time,'%y-%m-%d'),date_format(CURDATE(),'%y-%m-%d'))=0 and l.source = 1 and l.call_record_id is not null) d on c.id=d.customer_id and c.is_delete = 0 and (c.manager_id in ($managerId$))) as callToday,
        (select FORMAT(count(distinct id),0) from customer as c join ( SELECT l.customer_id FROM customer_callback_log l where  TIMESTAMPDIFF(DAY,date_format(create_time,'%y-%m-%d'),date_format(CURDATE(),'%y-%m-%d'))=1 and l.source = 1 and l.call_record_id is not null) d on c.id=d.customer_id and c.is_delete = 0 and (c.manager_id in ($managerId$))) as callYesterday,
        (select FORMAT(count(distinct id),0) from customer as c join ( SELECT l.customer_id FROM customer_callback_log l where  TIMESTAMPDIFF(DAY,date_format(create_time,'%y-%m-%d'),date_format(CURDATE(),'%y-%m-%d'))=0  ) d on c.id=d.customer_id and c.is_delete = 0 and (c.manager_id in ($managerId$))) as allCallToday,
        (select FORMAT(count(distinct id),0) from customer as c join ( SELECT l.customer_id FROM customer_callback_log l where  TIMESTAMPDIFF(DAY,date_format(create_time,'%y-%m-%d'),date_format(CURDATE(),'%y-%m-%d'))=1  ) d on c.id=d.customer_id and c.is_delete = 0 and (c.manager_id in ($managerId$))) as allCallYesterday
        ]]>
    </select>

    <select id="getUserByPorjectShort" resultClass="userEntity">
        <![CDATA[
            SELECT b.* FROM project_saler a,user b where a.userId=b.id and a.projectId in (
              select buildingId from project where city=#city# and (shorttel=#short# or updateIp=#short#)
            )
        ]]>
    </select>

    <select id="queryEvaluateListById" resultClass="UserEvaluateEntity" parameterClass="UserEvaluateEntity">
        <![CDATA[
           SELECT
            id, user_id as userId,user_name as userName,project_name as projectName, customer_name as customerName,
            score,content,check_status as checkStatus,channel,contentTags,evaluate_time as evaluateTime
	          FROM evaluate_user_customer_log
            WHERE
		        user_id = #userId#
		        and check_status = #checkStatus#
                and is_deleted = #isDeleted#
                and is_evaluated = #isEvaluated#
            order by evaluateTime desc
		    LIMIT #startPage#,  #pageSize#
        ]]>
    </select>

    <update id="reviewStatus" parameterClass="UserEvaluateEntity">
        update evaluate_user_customer_log set
        check_status = #checkStatus#
        where id = #id#
    </update>

    <update id="delEvaluationById" parameterClass="UserEvaluateEntity">
        update evaluate_user_customer_log set
        is_deleted = #isDeleted#
        where id = #id#
    </update>

    <update id="bindAccid" parameterClass="userEntity">
        update user set
        accid = #accId#,
        token = #token#
        where id = #id#
    </update>

    <select id="getAppVersionList" resultClass="VersionEntity">
        SELECT
        id,name,version,updateUrl,description,forceUpdate,type as channel,versionCode
        <![CDATA[
	        FROM app_version u
	    ]]>
    </select>

    <select id="getAuthorizationList" resultClass="RequestLoginEntity">
        SELECT
              id,name,realName,loginIp,loginCity,loginTime,status,authorizationTime,userId
	    FROM request_login
        <!--<include refid="authorization.queryPage"/>-->
        <dynamic prepend="WHERE">
            <!-- 默认不开启实体作为条件 -->
            <isNotNull property="searchFilters">
                <isNotNull prepend="AND" property="searchFilters.userId">
                    <![CDATA[
					 (userId = $searchFilters.userId.value$ or userId in (select id from user where depturlpath like (select concat(depturlpath,'/%') from user where id = $searchFilters.userId.value$)))
		         ]]>
                </isNotNull>
            </isNotNull>
        </dynamic>
        <dynamic prepend="ORDER BY">
            <isNotNull property="orderColumn">
                <![CDATA[
				$orderColumn$
			  ]]>
                <isNotNull property="orderMode">
                    $orderMode$
                </isNotNull>
            </isNotNull>
        </dynamic>
        <![CDATA[
		    LIMIT #paging.startRecord#, #paging.pageSize#
        ]]>
    </select>

    <select id="countAuthorizationList" resultClass="int">
        SELECT
        count(*)
        FROM request_login
        <!--<include refid="authorization.queryPage"/>-->
        <dynamic prepend="WHERE">
            <!-- 默认不开启实体作为条件 -->
            <isNotNull property="searchFilters">
                <isNotNull prepend="AND" property="searchFilters.userId">
                    <![CDATA[
					 (userId = $searchFilters.userId.value$ or userId in (select id from user where depturlpath like (select concat(depturlpath,'/%') from user where id = $searchFilters.userId.value$)))
		         ]]>
                </isNotNull>
            </isNotNull>
        </dynamic>
        <dynamic prepend="ORDER BY">
            <isNotNull property="orderColumn">
                <![CDATA[
				$orderColumn$
			  ]]>
                <isNotNull property="orderMode">
                    $orderMode$
                </isNotNull>
            </isNotNull>
        </dynamic>
    </select>

    <select id="queryByName" resultClass="userEntity" parameterClass="java.util.Map">
        SELECT NAME,realName,mobile,id,deptId,accid
        FROM user
        where enabled = 1 AND
        realName LIKE  concat('%', #realName#, '%')
    </select>

    <select id="countSubordinate" resultClass="java.lang.Integer" parameterClass="java.lang.Integer">
        SELECT
        count(1)
        FROM
        user
        WHERE
        depturlpath LIKE(
        SELECT
        concat(depturlpath , '/%')
        FROM
        user
        WHERE
        id = #userId#
        )
    </select>
</sqlMap>