<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="MdeUserMapper">
    <resultMap type="com.wechat.model.dbEntity.MdeUser" id="MdeUser">
        <id column="user_code" property="userCode"/>
        <result column="UNIONID" property="unionId"/>
        <result column="OPENID" property="openId"/>
        <result column="openId_mini" property="openIdMini"/>
        <result column="linkedin_id" property="linkedinId"/>
        <result column="user_name" property="userName"/>
        <result column="password" property="password"/>
        <result column="name" property="name"/>
        <result column="hotel_brand" property="hotelBrand"/>
        <result column="hotel_brand_str" property="hotelBrandStr"/>
        <result column="ent_contacts" property="entContacts"/>
        <result column="ent_phone" property="entPhone"/>
        <result column="head_portrait" property="headPortrait"/>
        <result column="email" property="email"/>
        <result column="CHECK_STATUS" property="checkStatus"/>
        <!-- <result column="addr_country" property="addrCountry" /> -->
        <result column="addr_province" property="addrProvince"/>
        <result column="addr_city" property="addrCity"/>
        <result column="addr_area" property="addrArea"/>
        <result column="website" property="website"/>
        <result column="add_detail" property="addDetail"/>
        <result column="add_longitude" property="addLongitude"/>
        <result column="add_latitude" property="addLatitude"/>
        <result column="birthday" property="birthday"/>
        <result column="experience" property="experience"/>
        <result column="first_work" property="firstWork"/>
        <result column="phone_code" property="phoneCode"/>
        <result column="image" property="image"/>
        <result column="ON_JOB_IMAGE" property="onJobImage"/>
        <result column="identity_flag" property="identityFlag"/>
        <result column="vip_flag" property="vipFlag"/>
        <result column="due_date" property="dueDate"/>
        <result column="allow_flag" property="allowFlag"/>
        <result column="care_about" property="careAbout"/>
        <result column="fans_count" property="fansCount"/>
        <result column="like_list" property="likeList"/>
        <result column="share_list" property="shareList"/>
        <result column="position_list" property="positionList"/>
        <result column="version_no" property="versionNo"/>
        <result column="remarks" property="remarks"/>
        <result column="del_flag" property="delFlag"/>
        <result column="create_by" property="createBy"/>
        <result column="create_date" property="createDate"/>
        <result column="update_by" property="updateBy"/>
        <result column="update_date" property="updateDate"/>
        <result column="work_status" property="workStatus"/>
        <result column="international" property="international"/>
        <result column="check_status" property="checkStatus"/>
        <result column="check_remarks" property="checkRemarks"/>
        <result column="position_title" property="positionTitle"/>
        <result column="foreign_name" property="foreignName"/>
        <result column="inviter" property="inviter"/>
        <result column="INTRODUCTION" property="introduction"/>
        <result column="RECOMMEND_FLAG" property="recommendFlag"/>
        <result column="PREPARE_FLAG" property="prepareFlag"/>
        <result column="PREPARE_YEAR" property="prepareYear"/>
        <result column="PREPARE_QUARTER" property="prepareQuarter"/>
        <result column="PRIVATE_FLAG" property="privateFlag"/>
        <result column="SUBSCRIBED_FLAG" property="subscribedFlag"/>
        <result column="STUDENT_FLAG" property="studentFlag"/>
    </resultMap>

    <resultMap type="com.wechat.model.responseDto.ContactUserInfoResp" id="contactUserInfoResp">
        <result column="USER_NAME" property="phoneNo"/>
        <result column="HEAD_PORTRAIT" property="headImage"/>
        <result column="NAME" property="name"/>
        <result column="EMAIL" property="email"/>
        <result column="USER_CODE" property="userCode"/>
        <result column="FOREIGN_NAME" property="foreignName"/>
        <collection property="workExperience" ofType="com.wechat.model.responseDto.WorkExperienceResp">
            <id column="WORK_ID" property="workId"/>
            <result column="POSITION_TITLE" property="positionTitle"/>
            <result column="CO_NAME" property="coName"/>
            <result column="ENTER_DATE" property="enterDate"/>
            <result column="QUIT_DATE" property="quitDate"/>
        </collection>
    </resultMap>

    <!-- 简要的用户信息 排除敏感字段和多余字段 -->
    <sql id="mdeUserColumns">
        a.user_code AS "userCode",
		a.user_name AS "userName",
		a.name AS "name",
		a.hotel_brand AS "hotelBrand",
		a.hotel_brand_str AS "hotelBrandStr",
		a.ent_contacts AS "entContacts",
		a.ent_phone AS "entPhone",
		a.head_portrait AS "headPortrait",
		a.email AS "email",
		a.CHECK_STATUS AS "checkStatus",
		a.addr_province AS "addrProvince",
		a.addr_city AS "addrCity",
		a.addr_area AS "addrArea",
		a.phone_code AS "phoneCode",
		a.image AS "image",
		a.ON_JOB_IMAGE as "onJobImage",
		a.identity_flag AS "identityFlag",
		a.vip_flag AS "vipFlag",
		a.due_date AS "dueDate",
		a.allow_flag AS "allowFlag",
		a.care_about AS "careAbout",
		a.fans_count AS "fansCount",
		a.like_list AS "likeList",
		a.share_list AS "shareList",
		a.position_list AS "positionList",
		a.version_no AS "versionNo",
		a.remarks AS "remarks",
		a.del_flag AS "delFlag",
		a.update_by AS "updateBy",
		a.update_date AS "updateDate",
		a.foreign_name AS "foreignName",
		a.add_detail AS "addDetail",
		a.add_longitude AS "addLongitude",
		a.add_latitude AS "addLatitude",
		a.birthday AS "birthday",
		TIMESTAMPDIFF( YEAR, a.FIRST_WORK, CURDATE( ) ) AS experience,
		a.first_work as "firstWork",
		a.student_flag AS "studentFlag",
		a.website AS "website",
		a.work_status AS "workStatus",
		a.international AS "international",
		a.check_status AS "checkStatus",
		a.check_remarks AS "checkRemarks",
		a.INTRODUCTION as introduction,
		a.RECOMMEND_FLAG as recommendFlag,
		a.PREPARE_FLAG as prepareFlag,
		a.SUBSCRIBED_FLAG as subscribedFlag,
		b.position_title as "positionTitle",
		b.co_name as "coName"
    </sql>
    <!-- 敏感字段 -->
    <sql id="mdeUserColumns_other">
        ,a.unionId AS "unionId"
		,a.openId AS "openId"
		,a.openId_mini AS "openIdMini"
		,a.linkedin_id AS "linkedinId"
		,a.password AS "password"
		,a.create_date AS "createDate"
    </sql>
    <sql id="mdeFriendRelationColumn">
        , CASE t.userCode WHEN IFNULL(t.userCode,NULL) THEN 1 ELSE  0 END as isFriend
    </sql>
    <sql id="mdeUserJoins">
        left join mde_work_experience b on b.user_code = a.user_code and b.show_flag=0 and b.del_flag = 0
    </sql>
    <sql id="mdeAnotherNameJoins">
        left join MDE_POSITION_ANOTHER_NAME d on b.POSITION_TITLE = d.POSITION_NAME and b.show_flag=0 and d.del_flag = 0
    </sql>
    <!-- 按职级排序 -->
    <sql id="orderByPositionGrade">
        order by IFNULL(d.POSITION_GRADE,10),a.UPDATE_DATE
        desc
    </sql>


    <sql id="mdeFriendRelationJoin">
        LEFT JOIN (
			SELECT 
				CASE
        #{userCode}
        WHEN
        u
        .
        USER_ID_1
        THEN
        u
        .
        USER_ID_2
        WHEN
        u
        .
        USER_ID_2
        THEN
        u
        .
        USER_ID_1
        END
        AS
        userCode
        FROM
        mde_friend_relation
        u
        WHERE
        u
        .
        USER_ID_1
        =
        #{userCode}
        OR
        u
        .
        USER_ID_2
        =
        #{userCode}
        AND
        u
        .
        DEL_FLAG
        =
        0
        )
        t
        on
        t
        .
        userCode
        =
        a
        .
        USER_CODE
    </sql>
    <select id="get" resultMap="MdeUser">
        SELECT
        <include refid="mdeUserColumns"/>
        ,concat(c.name,d.name) as 'address'
        ,a.create_date as createDate
        FROM mde_user a
        <include refid="mdeUserJoins"/>
        left join sys_area c on c.code=a.addr_province
        left join sys_area d on d.code=a.addr_city
        left join sys_area e on e.code=a.addr_area
        WHERE a.user_code = #{userCode} and a.del_flag=0
    </select>
    <select id="getWithLang" resultMap="MdeUser">
        SELECT
        <include refid="mdeUserColumns"/>
        <choose>
            <when test="lang != null and lang == 'en'.toString()">
                ,concat(c.name_en,d.name_en) as 'address'
            </when>
            <otherwise>
                ,concat(c.name,d.name) as 'address'
            </otherwise>
        </choose>
        ,a.create_date as createDate
        ,a.PREPARE_YEAR as prepareYear
        ,a.PREPARE_QUARTER as prepareQuarter
        ,a.PRIVATE_FLAG as privateFlag
        ,
        CASE
        WHEN exp.EDUCATION IS NULL THEN 0
        ELSE 1
        END AS educationResumeFlag
        FROM mde_user a
        <include refid="mdeUserJoins"/>
        left join mde_education_experience exp on exp.user_code = a.user_code and exp.del_flag=0
        left join sys_area c on c.code=a.addr_province
        left join sys_area d on d.code=a.addr_city
        left join sys_area e on e.code=a.addr_area
        WHERE a.user_code = #{userCode} and a.del_flag=0
        GROUP BY a.user_code
    </select>
    <select id="getUser" resultMap="MdeUser">
        SELECT
        <include refid="mdeUserColumns"/>
        ,concat(c.name,d.name) as 'address'
        ,a.create_date as createDate
        FROM mde_user a
        <include refid="mdeUserJoins"/>
        left join sys_area c on c.code=a.addr_province
        left join sys_area d on d.code=a.addr_city
        left join sys_area e on e.code=a.addr_area
        WHERE (a.user_code = #{userCode} or a.user_name = #{userName}) and a.del_flag=0
    </select>
    <!-- 获取用户敏感信息 -->
    <select id="getUserSensitiveInfo" resultMap="MdeUser">
        SELECT
        a.user_code AS "userCode",
        a.user_name AS "userName",
        a.name AS "name"
        <include refid="mdeUserColumns_other"/>
        FROM mde_user a
        WHERE a.user_code = #{userCode} and a.del_flag=0
    </select>

    <select id="getFullInfo" resultMap="MdeUser">
        SELECT
        <include refid="mdeUserColumns"/>
        <include refid="mdeUserColumns_other"/>
        FROM mde_user a
        <include refid="mdeUserJoins"/>
        WHERE a.user_code = #{userCode} and a.del_flag=0
    </select>

    <select id="checkMobileIsRegester" resultMap="MdeUser">
        SELECT a.user_code
        FROM mde_user a
        WHERE a.DEL_FLAG = 0
          AND a.USER_NAME = #{mobile}
    </select>

    <insert id="insert">
        INSERT INTO mde_user(
        user_code,
        unionId,
        openId,
        linkedin_id,
        user_name,
        password,
        name,
        hotel_brand,
        hotel_brand_str,
        ent_contacts,
        ent_phone,
        head_portrait,
        email,
        <!-- addr_country, -->
        addr_province,
        addr_city,
        addr_area,
        phone_code,
        image,
        ON_JOB_IMAGE,
        identity_flag,
        <!-- vip_flag, -->
        due_date,
        <!-- 	allow_flag, -->
        care_about,
        <!-- fans_count, -->
        like_list,
        share_list,
        position_list,
        <!-- version_no, -->
        remarks,
        <!-- del_flag, -->
        create_by,
        create_date,
        update_by,
        update_date,
        add_detail,
        add_longitude,
        add_latitude,
        birthday,
        experience,
        FIRST_WORK,
        website,
        work_status,
        check_status,
        international,
        INVITER,
        <if test="prepareFlag !=null and prepareFlag != ''">
            PREPARE_FLAG,
        </if>
        <if test="prepareYear !=null and prepareYear != ''">
            PREPARE_YEAR,
            PREPARE_QUARTER,
        </if>
        foreign_name,
        STUDENT_FLAG
        ) VALUES (
        #{userCode},
        #{unionId},
        #{openId},
        #{linkedinId},
        #{userName},
        #{password},
        #{name},
        #{hotelBrand},
        #{hotelBrandStr},
        #{entContacts},
        #{entPhone},
        #{headPortrait},
        #{email},
        <!-- #{addrCountry}, -->
        #{addrProvince},
        #{addrCity},
        #{addrArea},
        #{phoneCode},
        #{image},
        #{onJobImage},
        #{identityFlag},
        <!-- #{vipFlag}, -->
        #{dueDate},
        <!-- 	#{allowFlag}, -->
        #{careAbout},
        <!-- #{fansCount}, -->
        #{likeList},
        #{shareList},
        #{positionList},
        <!-- #{versionNo}, -->
        #{remarks},
        <!-- #{delFlag}, -->
        #{createBy},
        #{createDate},
        #{updateBy},
        #{updateDate},

        #{addDetail},
        #{addLongitude},
        #{addLatitude},
        #{birthday},
        #{experience},
        #{firstWork},
        #{website},
        #{workStatus},
        #{checkStatus},
        #{international},
        #{inviter},
        <if test="prepareFlag !=null and prepareFlag != ''">
            #{prepareFlag},
        </if>
        <if test="prepareYear !=null and prepareYear != ''">
            #{prepareYear},
            #{prepareQuarter},
        </if>
        #{foreignName},
        #{studentFlag}
        )
    </insert>

    <update id="update">
        UPDATE mde_user SET
        <if test="unionId !=null and unionId !=''">
            unionId = #{unionId},
        </if>
        <if test="openId !=null and openId !=''">
            openId = #{openId},
        </if>
        <if test="linkedinId !=null and linkedinId !=''">
            linkedin_id = #{linkedinId},
        </if>
        <if test="userName !=null">
            user_name = #{userName},
        </if>
        <if test="password !=null">
            password = #{password},
        </if>
        <if test="name !=null">
            name = #{name},
        </if>
        <if test="hotelBrand !=null">
            hotel_brand = #{hotelBrand},
        </if>
        <if test="hotelBrandStr !=null">
            hotel_brand_str = #{hotelBrandStr},
        </if>
        <if test="entContacts!=null">
            ent_contacts = #{entContacts},
        </if>
        <if test="entPhone !=null">
            ent_phone = #{entPhone},
        </if>
        <if test="headPortrait !=null">
            head_portrait = #{headPortrait},
        </if>
        <if test="email !=null">
            email = #{email},
        </if>
        <!-- <if test="addrCountry !=null" > addr_country = #{addrCountry},             </if> -->
        <if test="addrProvince !=null">
            addr_province = #{addrProvince},
        </if>
        <if test="addrCity !=null">
            addr_city = #{addrCity},
        </if>
        <if test="addrArea !=null">
            addr_area = #{addrArea},
        </if>
        <if test="phoneCode !=null">
            phone_code = #{phoneCode},
        </if>
        <if test="image !=null">
            image = #{image},
        </if>
        <if test="onJobImage">
            ON_JOB_IMAGE=#{onJobImage},
        </if>
        <if test="identityFlag !=null">
            identity_flag = #{identityFlag},
        </if>
        <if test="vipFlag !=null and vipFlag != '0'">
            vip_flag = #{vipFlag},
        </if>
        <if test="dueDate !=null">
            due_date = #{dueDate},
        </if>
        <if test="allowFlag !=null">
            allow_flag = #{allowFlag},
        </if>
        <if test="careAbout !=null">
            care_about = #{careAbout},
        </if>
        <if test="fansCount !=null">
            fans_count = #{fansCount},
        </if>
        <!-- <if test="likeList !=null" > like_list =
            CASE find_in_set( #{likeList}, IFNULL( like_list, "" ) )
                WHEN 0 THEN concat( IFNULL( like_list, "" ), #{likeList}, "," )
                ELSE REPLACE ( IFNULL( like_list, "" ), concat( #{likeList}, "," ), "" )
            END ,
        </if>
        <if test="shareList !=null" > share_list =
            CASE find_in_set( #{shareList}, IFNULL( share_list, "" ) )
                WHEN 0 THEN concat( IFNULL( share_list, "" ), #{shareList}, "," )
                ELSE share_list
            END ,
        </if> -->
        <if test="positionList !=null">
            position_list = #{positionList},
        </if>
        <if test="remarks !=null">
            remarks = #{remarks},
        </if>
        <if test="updateBy !=null">
            update_by = #{updateBy},
        </if>
        <if test="updateDate !=null">
            update_date = #{updateDate},
        </if>

        <if test="addDetail !=null">
            add_detail = #{addDetail},
        </if>
        <if test="addLongitude !=null">
            add_longitude = #{addLongitude},
        </if>
        <if test="addLatitude !=null">
            add_latitude = #{addLatitude},
        </if>
        <if test="birthday !=null">
            birthday = #{birthday},
        </if>
        <if test="experience !=null">
            experience = #{experience},
        </if>
        <if test="website !=null">
            website = #{website},
        </if>
        <if test="foreignName != null and foreignName != ''">
            foreign_name=#{foreignName},
        </if>
        <if test="workStatus !=null">
            work_status = #{workStatus},
        </if>
        <if test="checkStatus !=null">
            check_status = #{checkStatus},
        </if>
        <if test="international !=null">
            international = #{international},
        </if>
        <if test="studentFlag != null and studentFlag != ''">
            STUDENT_FLAG = #{studentFlag},
        </if>
        version_no = version_no+1
        WHERE user_code = #{userCode}
        <if test="versionNo !=null">
            and version_no = #{versionNo}
        </if>
    </update>
    <update id="updateUserPicture">
        UPDATE mde_user SET
        <if test="headPortrait !=null">
            head_portrait = #{headPortrait},
        </if>
        <if test="image !=null">
            image = #{image},
        </if>
        <if test="onJobImage">
            ON_JOB_IMAGE=#{onJobImage},
        </if>
        <if test="updateBy !=null">
            update_by = #{updateBy},
        </if>
        <if test="updateDate !=null">
            update_date = #{updateDate},
        </if>
        version_no = version_no+1
        WHERE user_code = #{userCode}
        <if test="versionNo !=null">
            and version_no = #{versionNo}
        </if>
    </update>

    <update id="unbind">
        UPDATE mde_user SET
        <if test="linkedinId ==null or linkedinId == ''">
            unionId = null
            ,openId = null
            ,openId_mini = null
        </if>
        <if test="linkedinId !=null and linkedinId != ''">
            linkedin_id = null
        </if>
        WHERE
        user_code != #{userCode}
        <if test="linkedinId ==null or linkedinId == ''">
            and (unionId = #{unionId} or openId = #{openId} or openId_mini = #{openIdMini})
        </if>
        <if test="linkedinId !=null and linkedinId != ''">
            and linkedin_id = #{linkedinId}
        </if>
    </update>

    <update id="updateBind">
        UPDATE mde_user SET
        <if test="openId !=null and openId !=''">
            openId = #{openId},
        </if>
        <if test="openIdMini !=null and openIdMini !=''">
            openId_mini = #{openIdMini},
        </if>
        <if test="unionId !=null and unionId !=''">
            unionId = #{unionId},
        </if>
        <if test="linkedinId !=null and linkedinId !=''">
            linkedin_id = #{linkedinId},
        </if>
        version_no = version_no+1
        WHERE user_code = #{userCode}
        <if test="versionNo !=null">
            and version_no = #{versionNo}
        </if>
    </update>


    <update id="updateUser">
        UPDATE mde_user SET
        <if test="foreignName != null">
            FOREIGN_NAME = #{foreignName},
        </if>
        <if test="name != null">
            NAME = #{name},
        </if>
        <if test="identityFlag == '0'.toString()">
            FIRST_WORK = #{firstWork},
            <if test="workStatus != null">
                WORK_STATUS = #{workStatus},
            </if>
            <if test="birthday != null">
                BIRTHDAY = #{birthday},
            </if>
            <if test="image != null">
                IMAGE = #{image},
            </if>
            <if test="email != null">
                EMAIL = #{email},
            </if>
            <if test="privateFlag != null">
                PRIVATE_FLAG = #{privateFlag},
            </if>
        </if>
        <if test="identityFlag == '1'.toString()">
            <if test="entContacts != null">
                ENT_CONTACTS = #{entContacts},
            </if>
            <if test="entPhone != null">
                ENT_PHONE = #{entPhone},
            </if>
            <if test="onJobImage != null">
                ON_JOB_IMAGE = #{onJobImage},
            </if>
            <if test="website != null">
                WEBSITE = #{website},
            </if>
            <if test="addrArea != null">
                ADDR_AREA = #{addrArea},
            </if>
            PREPARE_FLAG = #{prepareFlag},
            PREPARE_YEAR = #{prepareYear},
            PREPARE_QUARTER = #{prepareQuarter},
        </if>
        <if test="addrProvince != null">
            ADDR_PROVINCE = #{addrProvince},
        </if>
        <if test="addrCity != null">
            ADDR_CITY = #{addrCity},
        </if>
        <if test="addDetail != null">
            ADD_DETAIL = #{addDetail},
        </if>
        <if test="introduction != null">
            INTRODUCTION = #{introduction},
        </if>
        <if test="studentFlag != null and studentFlag != ''">
            STUDENT_FLAG = #{studentFlag},
        </if>
        update_by = #{updateBy},
        update_date = #{updateDate},
        version_no = version_no+1
        WHERE user_code = #{userCode}
        <if test="versionNo != null">
            and version_no = #{versionNo}
        </if>
    </update>

    <update id="updatePrivateFlag">
        UPDATE mde_user SET
        <if test="privateFlag != null">
            PRIVATE_FLAG = #{privateFlag},
        </if>
        update_by = #{updateBy},
        update_date = #{updateDate},
        version_no = version_no+1
        WHERE user_code = #{userCode}
        <if test="versionNo != null">
            and version_no = #{versionNo}
        </if>
    </update>


    <update id="delete">
        UPDATE mde_user
        SET del_flag = #{DEL_FLAG_DELETE}
        WHERE user_code = #{id}
    </update>

    <select id="findByUserName" resultMap="MdeUser">
        select
        <include refid="mdeUserColumns"/>
        <include refid="mdeUserColumns_other"/>
        from mde_user a
        <include refid="mdeUserJoins"/>
        where a.USER_NAME=#{userName} and a.DEL_FLAG=0
    </select>

    <!-- 关键词搜索好友 -->
    <select id="findByKeyWord" resultMap="MdeUser">
        SELECT
        <include refid="mdeUserColumns"/>
        <include refid="mdeFriendRelationColumn">
        </include>
        FROM
        mde_user a
        <include refid="mdeUserJoins"/>
        <include refid="mdeFriendRelationJoin">
        </include>
        WHERE
        a.DEL_FLAG = '0'
        and a.ALLOW_FLAG = '0'
        and a.user_code &lt;&gt; #{userCode}
        AND concat(
        a.NAME,
        IFNULL( a.ENT_CONTACTS, '' ),
        IFNULL( a.foreign_name, '' ),
        IFNULL( a.EMAIL, '' ),
        IFNULL( b.CO_NAME, '' )
        ) LIKE concat( '%', #{keyWord}, '%' )
    </select>

    <select id="findByKeyWordCount" resultType="java.lang.Integer">
        SELECT
        count(1)
        FROM
        mde_user a
        <include refid="mdeUserJoins"/>
        WHERE
        a.DEL_FLAG = '0'
        and a.ALLOW_FLAG = '0'
        and a.user_code &lt;&gt; #{userCode}
        AND concat(
        a.NAME,
        IFNULL( a.ENT_CONTACTS, '' ),
        IFNULL( a.foreign_name, '' ),
        IFNULL( a.EMAIL, '' ),
        IFNULL( b.CO_NAME, '' )
        ) LIKE concat( '%', #{keyWord}, '%' );
    </select>

    <select id="findByUnionId" resultMap="MdeUser">
        select
        <include refid="mdeUserColumns"/>
        <include refid="mdeUserColumns_other"/>
        from mde_user a
        <include refid="mdeUserJoins"/>
        where a.unionId=#{unionId} and a.DEL_FLAG=0
    </select>

    <select id="findByLinkedId" resultMap="MdeUser">
        select
        <include refid="mdeUserColumns"/>
        <include refid="mdeUserColumns_other"/>
        from mde_user a
        <include refid="mdeUserJoins"/>
        where a.linkedin_id=#{linkedId} and a.DEL_FLAG=0
    </select>
    <!-- 可能认识的人 -->
    <!-- <select id="getMaybeFriendsOfPerson" resultMap="MdeUser">
        SELECT
        <include refid="mdeUserColumns" />
        FROM mde_user a
        <include refid="mdeUserJoins" />
        <include refid="mdeAnotherNameJoins" />
        <where>
            a.del_flag = 0 and a.identity_flag = 0 and a.ALLOW_FLAG = 0
            and a.user_code not in (
                select #{userCode}
                union all
                SELECT
                    case #{userCode}
                        when user_id_1 then user_id_2
                        when user_id_2 then user_id_1
                    end as user_code
                FROM
                    mde_friend_relation
                WHERE
                    ( USER_ID_1 = #{userCode} OR USER_ID_2 = #{userCode} ) 	AND del_flag = 0
            )
            <![CDATA[ AND d.POSITION_GRADE < 5 ]]>
            and a.user_code like CONCAT('%',(select FLOOR(RAND() * 10)),'%')
        </where>
        ORDER BY RAND()
        limit #{limitSize}
    </select> -->
    <select id="getMaybeFriendsOfPerson" resultMap="MdeUser">
        SELECT
        <include refid="mdeUserColumns"/>
        FROM mde_user a
        <include refid="mdeUserJoins"/>
        <include refid="mdeAnotherNameJoins"/>
        <where>
            a.del_flag = 0 and a.identity_flag = 0 and a.ALLOW_FLAG = '0'
            AND a.USER_CODE !=#{userCode}
            AND a.RECOMMEND_FLAG ='1'
            and NOT EXISTS (
            SELECT
            1
            FROM
            mde_friend_relation rel
            WHERE
            (
            rel.USER_ID_1 = #{userCode} and a.USER_CODE = rel.user_id_2
            )
            AND rel.del_flag = 0
            UNION ALL
            SELECT
            1
            FROM
            mde_friend_relation rel
            WHERE
            (
            rel.USER_ID_2 = #{userCode} and a.USER_CODE = rel.user_id_1
            )
            AND rel.del_flag = 0
            )
            <![CDATA[ AND d.POSITION_GRADE < 5 ]]>
            and a.user_code like CONCAT('%',(select FLOOR(RAND() * 10)),'%')
        </where>
        ORDER BY RAND()
        limit #{limitSize}
    </select>
    <!-- 在该企业工作过的，企业朋友的朋友（一级） -->
    <select id="getMaybeFriendsOfEnterprise" resultMap="MdeUser">
        SELECT
        a.user_code AS "userCode",
        a.NAME AS "name",
        a.head_portrait AS "headPortrait",
        a.email AS "email",
        a.identity_flag AS "identityFlag",
        a.vip_flag AS "vipFlag",
        a.foreign_name AS "foreignName",
        b.position_title AS "positionTitle",
        b.co_name AS "coName"
        FROM
        mde_user a
        INNER JOIN
        (
        <!-- 获取工作经历和发布中职位相关的1名人员 -->
        (SELECT DISTINCT
        a.user_code
        FROM
        MDE_JOB_ADVERTISED jobAd
        LEFT JOIN MDE_POSITION_ANOTHER_NAME pos ON jobAd.POSITION_ID = pos.POSITION_ID
        LEFT JOIN mde_work_experience a ON a.POSITION_TITLE = pos.POSITION_NAME
        WHERE
        a.del_flag = 0
        AND pos.del_flag = 0
        AND jobAd.PUBLISHER = #{userCode}
        <!-- 屏蔽本酒店人员 -->
        AND ( a.co_name != #{name} AND a.co_name != #{foreignName} )
        limit 1)
        UNION
        <!-- 获取我好友的好友 并且排除共同好友-->
        (SELECT
        CASE
        WHEN allF.user_id_1 = myF.user_code
        THEN allF.user_id_2
        WHEN allF.user_id_2 = myF.user_code
        THEN allF.user_id_1
        END AS user_code
        FROM
        mde_friend_relation allF
        INNER JOIN
        (
        SELECT
        CASE
        #{userCode}
        WHEN user_id_1 THEN
        user_id_2
        WHEN user_id_2 THEN
        user_id_1
        END AS user_code
        FROM
        mde_friend_relation
        WHERE
        ( USER_ID_1 = #{userCode} OR USER_ID_2 = #{userCode} )
        AND del_flag = 0
        AND CONFIRM_TIME IS NOT NULL
        ) myF
        ON (allF.user_id_1 = myF.user_code and allF.user_id_2 != myF.user_code)
        OR (allF.user_id_2 = myF.user_code and allF.user_id_1 != myF.user_code)
        WHERE
        allF.user_id_1 != #{userCode}
        AND allF.user_id_2 != #{userCode}
        AND allF.del_flag = 0
        AND CONFIRM_TIME IS NOT NULL )
        ) friend
        ON a.user_code = friend.user_code
        <include refid="mdeUserJoins"/>
        <include refid="mdeAnotherNameJoins"/>
        WHERE
        a.del_flag = 0
        AND a.RECOMMEND_FLAG ='1'
        <!-- 排除已添加的好友-->
        AND NOT EXISTS (
        SELECT
        1
        FROM
        mde_friend_relation rel
        WHERE
        (
        rel.USER_ID_1 = #{userCode} AND a.USER_CODE = rel.user_id_2
        )
        AND rel.del_flag = 0
        UNION ALL
        SELECT
        1
        FROM
        mde_friend_relation rel
        WHERE
        (
        rel.USER_ID_2 = #{userCode} AND a.USER_CODE = rel.user_id_1
        )
        AND rel.del_flag = 0
        )
        <!-- 屏蔽本酒店人员 -->
        AND ( b.co_name != #{name} AND b.co_name != #{foreignName} )
        AND a.identity_flag = 0
        <![CDATA[ AND d.POSITION_GRADE < 5 ]]>
        ORDER BY RAND()
        limit #{limitSize}
    </select>
    <!-- 查找全部好友 -->
    <select id="getFriendsByCode" resultMap="MdeUser">
        SELECT
        a.user_code AS "userCode",
        a.NAME AS "name",
        a.foreign_name as "foreignName",
        a.identity_flag as "identityFlag",
        a.head_portrait AS "headPortrait",
        b.POSITION_TITLE as "positionTitle",
        b.CO_NAME as coName
        FROM mde_user a
        <include refid="mdeUserJoins"/>
        <include refid="mdeAnotherNameJoins"/>
        <where>
            a.del_flag = 0 and a.user_code in (
            SELECT
            case #{userCode}
            when user_id_1 then user_id_2
            when user_id_2 then user_id_1
            end as user_code
            FROM
            mde_friend_relation
            WHERE
            ( USER_ID_1 = #{userCode} OR USER_ID_2 = #{userCode} ) AND del_flag = 0 AND CONFIRM_TIME IS NOT NULL
            )
        </where>
        <include refid="orderByPositionGrade"/>
    </select>

    <select id="getFriendsCounts" resultType="java.lang.Integer">
        SELECT
        count(1)
        FROM mde_user a
        <include refid="mdeUserJoins"/>
        <include refid="mdeAnotherNameJoins"/>
        <where>
            a.del_flag = 0 and a.user_code in (
            SELECT
            case #{userCode}
            when user_id_1 then user_id_2
            when user_id_2 then user_id_1
            end as user_code
            FROM
            mde_friend_relation
            WHERE
            ( USER_ID_1 = #{userCode} OR USER_ID_2 = #{userCode} ) AND del_flag = 0 AND CONFIRM_TIME IS NOT NULL
            )
        </where>
        <include refid="orderByPositionGrade"/>
    </select>


    <select id="getInfoByJobId" resultMap="MdeUser">
        SELECT
        a.user_code AS "userCode",
        a.user_name AS "userName",
        a.name AS "name",
        a.hotel_brand AS "hotelBrand",
        a.hotel_brand_str AS "hotelBrandStr",
        a.ent_contacts AS "entContacts",
        a.ent_phone AS "entPhone",
        a.head_portrait AS "headPortrait",
        a.email AS "email",
        a.CHECK_STATUS AS "checkStatus",
        a.addr_province AS "addrProvince",
        a.addr_city AS "addrCity",
        a.addr_area AS "addrArea",
        a.phone_code AS "phoneCode",
        a.image AS "image",
        a.ON_JOB_IMAGE as "onJobImage",
        a.identity_flag AS "identityFlag",
        a.vip_flag AS "vipFlag",
        a.due_date AS "dueDate",
        a.allow_flag AS "allowFlag",
        a.care_about AS "careAbout",
        a.fans_count AS "fansCount",
        a.like_list AS "likeList",
        a.share_list AS "shareList",
        a.position_list AS "positionList",
        a.version_no AS "versionNo",
        a.remarks AS "remarks",
        a.del_flag AS "delFlag",
        a.update_by AS "updateBy",
        a.update_date AS "updateDate",
        a.foreign_name AS "foreignName",
        a.add_detail AS "addDetail",
        a.add_longitude AS "addLongitude",
        a.add_latitude AS "addLatitude",
        a.birthday AS "birthday",
        TIMESTAMPDIFF( YEAR, a.FIRST_WORK, CURDATE( ) ) AS experience,
        a.first_work as "firstWork",
        a.website AS "website",
        a.work_status AS "workStatus",
        a.international AS "international",
        a.check_status AS "checkStatus",
        a.check_remarks AS "checkRemarks",
        a.INTRODUCTION as introduction,
        a.RECOMMEND_FLAG as recommendFlag,
        a.PREPARE_FLAG as prepareFlag,
        a.create_date AS createDate,
        a.PREPARE_YEAR as prepareYear,
        a.PREPARE_QUARTER as prepareQuarter
        FROM
        mde_user a
        inner join
        mde_job_advertised b
        on a.user_code = b.publisher
        <where>
            a.del_flag = 0
            and b.job_id=#{jobId}
        </where>
    </select>

    <select id="getUserInfoByCode" resultMap="MdeUser">
        SELECT
        <include refid="mdeUserColumns"/>
        FROM mde_user a
        <include refid="mdeUserJoins"/>
        where a.del_flag = 0 and a.user_code = #{userCode}
    </select>
    <!-- 职位收藏  与取消 -->
    <update id="updateUserPositionList">
        UPDATE mde_user
        SET position_list =
                CASE find_in_set(#{jobId}, IFNULL(position_list, ""))
                    WHEN 0 THEN concat(IFNULL(position_list, ""), #{jobId}, ",")
                    ELSE REPLACE(IFNULL(position_list, ""), concat(#{jobId}, ","), "")
                    END
        WHERE user_code = #{userCode}
          and del_flag = 0
    </update>

    <!-- 获取联系方式 -->
    <select id="getContactNumber" resultMap="contactUserInfoResp">
        SELECT u.USER_NAME,
               u.FOREIGN_NAME,
               u.identity_flag,
               e.WORK_ID,
               u.HEAD_PORTRAIT,
               u.`NAME`,
               u.EMAIL,
               u.USER_CODE,
               e.ENTER_DATE,
               e.QUIT_DATE,
               e.POSITION_TITLE,
               e.CO_NAME
        FROM mde_user u,
             mde_work_experience e
        WHERE u.USER_CODE = e.USER_CODE
          AND e.DEL_FLAG = 0
          AND u.DEL_FLAG = 0
          AND u.IDENTITY_FLAG = 0
          AND u.USER_CODE = #{userCode}
        ORDER BY e.ENTER_DATE DESC, e.QUIT_DATE DESC
    </select>

    <select id="getEducationId" resultType="java.lang.String">
        SELECT
        s.`value` as eduId
        FROM
        sys_dict s
        <where>
            s.type = 'education'
            and
            <foreach collection="keyWord" item="key" open="(" close=")" separator="or">
                s.label LIKE CONCAT('%', #{key}, '%')
            </foreach>
        </where>
        order by s.`value` desc
        limit 1
    </select>


    <!-- 人才关键词检索 -->
    <!--	<select id="searchKeyWord" resultType="com.wechat.model.dto.TalentRetrievalDto">-->
    <!--		SELECT-->
    <!--			u.USER_CODE AS userCode,-->
    <!--			e.POSITION_TITLE AS positionTitle,-->
    <!--			TIMESTAMPDIFF( YEAR, u.FIRST_WORK, CURDATE( ) ) AS experience,-->
    <!--			u.FIRST_WORK as firstWork,-->
    <!--			u.HOTEL_BRAND_STR AS brandStr,-->
    <!--			u.HEAD_PORTRAIT AS headImage,-->
    <!--			u.NAME AS NAME,-->
    <!--			u.foreign_name as foreignName,-->
    <!--			u.identity_flag as identityFlag,-->
    <!--			min( w.EDUCATION ) as education,-->
    <!--			u.VIP_FLAG as vipFlag,-->
    <!--			e.co_name as coName-->
    <!--			FROM mde_user u-->
    <!--		LEFT JOIN mde_work_experience e ON e.USER_CODE = u.USER_CODE-->
    <!--		LEFT JOIN  mde_education_experience w ON u.USER_CODE = w.USER_CODE-->
    <!--		<where>-->
    <!--			e.DEL_FLAG = 0 AND u.DEL_FLAG = 0 AND u.IDENTITY_FLAG = 0 and u.ALLOW_FLAG = 0 AND u.WORK_STATUS != 0-->
    <!--			<if test="keyWord != null">-->
    <!--				AND-->
    <!--				<foreach collection="keyWord" item="key" open="(" close=")" separator="or">-->
    <!--					e.POSITION_TITLE LIKE CONCAT('%', #{key}, '%')-->
    <!--				</foreach>-->
    <!--			</if>-->
    <!--			<if test = "experience != null and experience != ''">-->
    <!--			 	<![CDATA[  -->
    <!--					AND u.FIRST_WORK >= #{from}  AND u.FIRST_WORK <= #{to}-->
    <!--				]]>-->
    <!--			</if>-->
    <!--			and e.SHOW_FLAG = 0-->
    <!--			AND e.CO_NAME &lt;&gt; (SELECT `NAME` FROM mde_user WHERE USER_CODE = #{publisher})-->
    <!--		</where>-->
    <!--		group by u.USER_CODE-->
    <!--		order by u.VIP_FLAG desc-->
    <!--		-->
    <!--	</select>-->

    <!-- rayson-人才关键词检索 -->
    <select id="searchKeyWord" resultType="com.wechat.model.dto.TalentRetrievalDto">
        SELECT
        u.USER_CODE AS userCode,
        e.POSITION_TITLE AS positionTitle,
        TIMESTAMPDIFF( YEAR, u.FIRST_WORK, CURDATE( ) ) AS experience,
        u.FIRST_WORK as firstWork,
        u.HOTEL_BRAND_STR AS brandStr,
        u.HEAD_PORTRAIT AS headImage,
        u.NAME AS NAME,
        u.foreign_name as foreignName,
        u.identity_flag as identityFlag,
        min( w.EDUCATION ) as education,
        u.VIP_FLAG as vipFlag,
        e.co_name as coName
        FROM mde_user u
        LEFT JOIN mde_work_experience e ON e.USER_CODE = u.USER_CODE
        LEFT JOIN mde_education_experience w ON u.USER_CODE = w.USER_CODE
        LEFT JOIN mde_interested_adds adds ON u.USER_CODE = adds.USER_CODE AND adds.DEL_FLAG =0
        <where>
            e.DEL_FLAG = 0
            AND u.DEL_FLAG = 0
            AND u.IDENTITY_FLAG = 0
            AND u.ALLOW_FLAG = 0
            AND u.WORK_STATUS != 0
            <if test="keyWord != null">
                AND
                (
                MATCH(e.CO_NAME,e.POSITION_TITLE) AGAINST(#{keyWord} IN BOOLEAN MODE)
                OR
                MATCH(adds.INTD_PROVINCE_NAME,adds.INTD_CITY_NAME) AGAINST(#{keyWord} IN BOOLEAN MODE)
                )
            </if>
            and e.SHOW_FLAG = 0
            AND e.CO_NAME &lt;&gt; (SELECT `NAME` FROM mde_user WHERE USER_CODE = #{publisher})
        </where>
        group by u.USER_CODE
        order by u.VIP_FLAG desc
    </select>

    <!--	<select id="searchKeyWordCount" resultType="java.lang.Integer">-->
    <!--		SELECT -->
    <!--			count(DISTINCT u.USER_CODE)-->
    <!--		FROM mde_user u-->
    <!--		LEFT JOIN mde_work_experience e ON e.USER_CODE = u.USER_CODE-->
    <!--		LEFT JOIN  mde_education_experience w ON u.USER_CODE = w.USER_CODE-->

    <!--		<where>-->
    <!--			e.DEL_FLAG = 0 AND u.DEL_FLAG = 0 AND u.IDENTITY_FLAG = 0 and u.ALLOW_FLAG = 0 and u.WORK_STATUS != 0-->
    <!--			<if test="keyWord != null">-->
    <!--				AND-->
    <!--				<foreach collection="keyWord" item="key" open="(" close=")" separator="or">-->
    <!--					e.POSITION_TITLE LIKE CONCAT('%', #{key}, '%')-->
    <!--				</foreach>-->
    <!--			</if>-->
    <!--			<if test = "experience != null and experience != ''">-->
    <!--			 	<![CDATA[  -->
    <!--					AND u.FIRST_WORK >= #{from}  AND u.FIRST_WORK <= #{to}-->
    <!--				]]>-->
    <!--			</if>-->
    <!--			and e.SHOW_FLAG = 0-->
    <!--			AND e.CO_NAME &lt;&gt; (SELECT `NAME` FROM mde_user WHERE USER_CODE = #{publisher})-->
    <!--		</where>-->
    <!--	</select>-->

    <select id="searchKeyWordCount" resultType="java.lang.Integer">
        SELECT
        count(DISTINCT u.USER_CODE)
        FROM mde_user u
        LEFT JOIN mde_work_experience e ON e.USER_CODE = u.USER_CODE
        LEFT JOIN mde_education_experience w ON u.USER_CODE = w.USER_CODE
        LEFT JOIN mde_interested_adds adds ON u.USER_CODE = adds.USER_CODE AND adds.DEL_FLAG =0
        <where>
            e.DEL_FLAG = 0
            AND u.DEL_FLAG = 0
            AND u.IDENTITY_FLAG = 0
            AND u.ALLOW_FLAG = 0
            AND u.WORK_STATUS != 0
            <if test="keyWord != null">
                AND
                (
                MATCH(e.CO_NAME,e.POSITION_TITLE) AGAINST(#{keyWord} IN BOOLEAN MODE)
                OR
                MATCH(adds.INTD_PROVINCE_NAME,adds.INTD_CITY_NAME) AGAINST(#{keyWord} IN BOOLEAN MODE)
                )
            </if>
            and e.SHOW_FLAG = 0
            AND e.CO_NAME &lt;&gt; (SELECT `NAME` FROM mde_user WHERE USER_CODE = #{publisher})
        </where>
    </select>

    <!-- 人才筛选 -->
    <select id="filterPersonAbility" resultType="com.wechat.model.dto.TalentRetrievalDto">
        SELECT
        u.USER_CODE AS userCode,
        e.POSITION_TITLE AS positionTitle,
        TIMESTAMPDIFF( YEAR, u.FIRST_WORK, CURDATE( ) ) AS experience,
        u.FIRST_WORK as firstWork,
        u.HOTEL_BRAND_STR AS brandStr,
        u.HEAD_PORTRAIT AS headImage,
        u.NAME AS NAME,
        u.foreign_name as foreignName,
        u.identity_flag as identityFlag,
        u.VIP_FLAG as vipFlag,
        min( ee.EDUCATION ) as education,
        e.co_name as coName
        FROM mde_user u
        LEFT JOIN mde_work_experience e ON e.USER_CODE = u.USER_CODE
        LEFT JOIN mde_education_experience ee ON ee.USER_CODE = u.USER_CODE
        LEFT JOIN mde_interested_adds intadd ON intadd.USER_CODE = u.USER_CODE
        <where>
            u.DEL_FLAG = 0
            AND e.DEL_FLAG = 0
            AND u.WORK_STATUS != 0
            AND u.IDENTITY_FLAG = 0
            and u.ALLOW_FLAG = 0
            <if test="positionIdList != null">
                AND e.POSITION_TITLE IN (
                SELECT a.POSITION_NAME
                FROM mde_position_another_name a
                WHERE a.del_flag=0 AND a.POSITION_ID in
                <foreach collection="positionIdList" item="positionId" separator="," open="(" close=")">
                    #{positionId}
                </foreach>
                )
            </if>
            <if test="provinceId != null and provinceId != ''">
                AND intadd.INTD_PROVINCE = #{provinceId}
            </if>
            <if test="cityId != null and cityId != ''">
                AND intadd.INTD_CITY = #{cityId}
            </if>
            <if test="brandIdList != null">
                AND u.HOTEL_BRAND in
                <foreach collection="brandIdList" item="brandId" separator="," open="(" close=")">
                    #{brandId}
                </foreach>
            </if>
            <if test="workExperience != null and workExperience != ''">
                <![CDATA[
					AND u.FIRST_WORK >= #{from}  AND u.FIRST_WORK <= #{to}
				]]>
            </if>
            <if test="eduExperience != null and eduExperience != ''">
                <![CDATA[
					AND ee.EDUCATION <= #{eduExperience}
				]]>
            </if>
            and e.SHOW_FLAG = 0
            AND e.CO_NAME &lt;&gt; (SELECT `NAME` FROM mde_user WHERE USER_CODE = #{publisher})
        </where>
        group by u.USER_CODE
        order by u.VIP_FLAG desc
    </select>

    <!-- 人才筛选数量 -->
    <select id="filterPersonAbilityCount" resultType="java.lang.Integer">
        SELECT
        count(DISTINCT u.USER_CODE)
        FROM mde_user u
        LEFT JOIN mde_work_experience e ON e.USER_CODE = u.USER_CODE
        LEFT JOIN mde_education_experience ee ON ee.USER_CODE = u.USER_CODE
        LEFT JOIN mde_interested_adds intadd ON intadd.USER_CODE = u.USER_CODE
        <where>
            u.DEL_FLAG = 0
            AND e.DEL_FLAG = 0
            AND u.WORK_STATUS != 0
            AND u.IDENTITY_FLAG = 0
            and u.ALLOW_FLAG = 0
            <if test="positionIdList != null">
                AND e.POSITION_TITLE IN (
                SELECT a.POSITION_NAME
                FROM mde_position_another_name a
                WHERE a.del_flag=0 AND a.POSITION_ID in
                <foreach collection="positionIdList" item="positionId" separator="," open="(" close=")">
                    #{positionId}
                </foreach>
                )
            </if>
            <if test="provinceId != null and provinceId != ''">
                AND intadd.INTD_PROVINCE = #{provinceId}
            </if>
            <if test="cityId != null and cityId != ''">
                AND intadd.INTD_CITY = #{cityId}
            </if>
            <if test="brandIdList != null">
                AND u.HOTEL_BRAND in
                <foreach collection="brandIdList" item="brandId" separator="," open="(" close=")">
                    #{brandId}
                </foreach>
            </if>
            <if test="workExperience != null and workExperience != ''">
                <![CDATA[
					AND u.FIRST_WORK >= #{from}  AND u.FIRST_WORK <= #{to}
				]]>
            </if>
            <if test="eduExperience != null and eduExperience != ''">
                <![CDATA[
					AND ee.EDUCATION <= #{eduExperience}
				]]>
            </if>
            and e.SHOW_FLAG = 0
            AND e.CO_NAME &lt;&gt; (SELECT `NAME` FROM mde_user WHERE USER_CODE = #{publisher})
        </where>
        <!-- SELECT count(DISTINCT(t.userCode))
        FROM mde_work_experience p
        INNER JOIN (
            SELECT
                u.USER_CODE AS userCode,
                e.CO_NAME AS coName,
                e.POSITION_TITLE AS positionTitle,
                u.EXPERIENCE AS experience,
                u.HOTEL_BRAND_STR AS brandStr,
                u.HEAD_PORTRAIT AS headImage,
                u.name as name
            FROM
                mde_user u
            LEFT JOIN mde_work_experience e ON u.USER_CODE = e.USER_CODE
            WHERE
                u.DEL_FLAG = 0
                AND e.DEL_FLAG = 0
                AND u.WORK_STATUS != 0
                AND u.IDENTITY_FLAG = 0
                <if test="positionIdList != null">
                    AND e.POSITION_TITLE IN (
                        SELECT a.POSITION_NAME
                        FROM mde_position_another_name a
                        WHERE a.del_flag=0 AND a.POSITION_ID in
                        <foreach collection="positionIdList" item="positionId" separator="," open="(" close=")">
                            #{positionId}
                        </foreach>
                    )
                </if>
                <if test="provinceId != null and provinceId != ''">
                    AND u.ADDR_PROVINCE = #{provinceId}
                </if>
                <if test="cityId != null and cityId != ''">
                    AND u.ADDR_CITY = #{cityId}
                </if>
                 <if test="brandIdList != null">
                    AND u.HOTEL_BRAND in
                    <foreach collection="brandIdList" item="brandId" separator="," open="(" close=")">
                         #{brandId}
                    </foreach>
                 </if>
                <if test="workExperience != null and workExperience != ''">
                     <choose>
                        <when test="workExperience == 1">
                            AND u.EXPERIENCE &gt;= 1  AND u.EXPERIENCE &lt;= 3
                        </when>
                        <when test="workExperience == 3">
                            AND u.EXPERIENCE &gt;= 3 and u.EXPERIENCE &lt;= 5
                        </when>
                        <when test="workExperience == 5">
                            AND u.EXPERIENCE &gt;= 5 and u.EXPERIENCE &lt;= 10
                        </when>
                        <when test="workExperience == 10">
                            AND u.EXPERIENCE &gt;= 10
                        </when>
                    </choose>
                </if>
             GROUP BY u.USER_CODE
         ) t ON p.USER_CODE = t.userCode
        <where>
            p.SHOW_FLAG = 0
            AND p.CO_NAME &lt;&gt; (SELECT `NAME` FROM mde_user WHERE USER_CODE = #{publisher})
        </where> -->
    </select>
    <!-- 用户简历下载    用户简历附件为空时  调用 -->
    <select id="exportUserCvDoc" resultMap="MdeUser">
        SELECT a.name,
               a.user_name                             as userName,
               CAST(IFNULL(a.experience, 0) as SIGNED) AS experience,
               a.email                                 as email,
               concat(c.name, d.name)                  as address,
               a.birthday                              AS birthday,
               a.head_portrait                         as headPortrait
        FROM mde_user a
                 left join sys_area c on c.code = a.addr_province
                 left join sys_area d on d.code = a.addr_city
        where a.user_code = #{userCode}
          and a.del_flag = 0
    </select>
    <!-- 推荐酒店  （大于50）-->
    <select id="getRecommentHotelsJoinRand" resultMap="MdeUser">
        SELECT t1.USER_CODE,
               t1.HEAD_PORTRAIT,
               t1.`NAME`,
               t1.HOTEL_BRAND_STR,
               t1.ADDR_PROVINCE,
               t1.ADDR_CITY,
               t1.addr_area
        from (SELECT u.USER_CODE,
                     u.HEAD_PORTRAIT,
                     u.`NAME`,
                     u.HOTEL_BRAND_STR,
                     u.ADDR_PROVINCE,
                     u.ADDR_CITY,
                     u.addr_area
              FROM mde_user u
              where u.DEL_FLAG = 0
                AND u.IDENTITY_FLAG = 1
                AND u.VIP_FLAG != 0) AS t1
                 JOIN (SELECT ROUND(RAND() * (
                (SELECT MAX(USER_CODE) FROM mde_user) - (SELECT MIN(USER_CODE) FROM mde_user)) +
                                    (SELECT MIN(USER_CODE) FROM mde_user)) AS USER_CODE) AS t2
        WHERE t1.USER_CODE &gt;= t2.USER_CODE
        ORDER BY t1.USER_CODE
        LIMIT #{limitSize};
    </select>
    <!-- 酒店推荐  小于50 -->
    <select id="getRecommentHotelsRand" resultMap="MdeUser">
        SELECT u.USER_CODE,
               u.`NAME`,
               u.foreign_name,
               u.PREPARE_FLAG,
               u.identity_flag,
               u.HOTEL_BRAND_STR,
               u.HEAD_PORTRAIT,
               u.ADDR_PROVINCE,
               u.ADDR_CITY,
               u.addr_area
        FROM mde_user u
        WHERE u.DEL_FLAG = 0
          AND u.VIP_FLAG != 0
          AND u.IDENTITY_FLAG = 1
        ORDER BY RAND()
        LIMIT #{limitSize}
    </select>
    <!-- 相似酒店的数量 -->
    <select id="getRecommentHotelsCount" resultType="java.lang.Integer">
        SELECT count(1)
        FROM mde_user u
        WHERE u.DEL_FLAG = 0
          AND u.VIP_FLAG != 0
          AND u.IDENTITY_FLAG = 1
          AND u.user_code > 0
    </select>
    <!-- 相似酒店酒店 -->
    <select id="getSimilarHotel" resultMap="MdeUser">
        SELECT t1.USER_CODE,
               t1.HEAD_PORTRAIT,
               t1.`NAME`,
               t1.HOTEL_BRAND_STR,
               t1.ADDR_PROVINCE,
               t1.ADDR_CITY,
               t1.addr_area
        from (SELECT u.USER_CODE,
                     u.HEAD_PORTRAIT,
                     u.`NAME`,
                     u.HOTEL_BRAND_STR,
                     u.ADDR_PROVINCE,
                     u.ADDR_CITY,
                     u.addr_area
              FROM mde_user u
              where u.DEL_FLAG = 0
                AND u.IDENTITY_FLAG = 1
                AND u.VIP_FLAG != 0) AS t1
                 JOIN (SELECT ROUND(RAND() * (
                (SELECT MAX(USER_CODE) FROM mde_user) - (SELECT MIN(USER_CODE) FROM mde_user)) +
                                    (SELECT MIN(USER_CODE) FROM mde_user)) AS USER_CODE) AS t2
        WHERE t1.USER_CODE &gt;= t2.USER_CODE
        ORDER BY t1.USER_CODE
        LIMIT #{limitSize}
    </select>

    <!-- 推荐人才 -->
    <select id="getRecommentPeople" resultMap="MdeUser">
        SELECT
        <include refid="mdeUserColumns"/>
        FROM
        mde_user a,
        mde_work_experience b
        WHERE
        a.USER_CODE = b.USER_CODE
        AND b.SHOW_FLAG = 0
        AND a.DEL_FLAG = 0
        AND a.IDENTITY_FLAG = 0
        AND a.VIP_FLAG != 0
        AND a.ALLOW_FLAG = 0
        and a.user_code LIKE CONCAT( '%', ( SELECT FLOOR( RAND( ) * 10 ) ), '%' )
        order by RAND()
        LIMIT #{limitSize}
    </select>
    <update id="updateLikeOrShareList">
        UPDATE mde_user SET
        <if test="likeList !=null">
            like_list =
            CASE find_in_set( #{likeList}, IFNULL( like_list, "" ) )
            WHEN 0 THEN concat( IFNULL( like_list, "" ), #{likeList}, "," )
            ELSE REPLACE ( IFNULL( like_list, "" ), concat( #{likeList}, "," ), "" )
            END ,
        </if>
        <if test="shareList !=null">
            share_list =
            CASE find_in_set( #{shareList}, IFNULL( share_list, "" ) )
            WHEN 0 THEN concat( IFNULL( share_list, "" ), #{shareList}, "," )
            ELSE share_list
            END ,
        </if>
        <!-- <if test="likeList !=null and likeList != ''" >
            like_list = #{likeList}
        </if>
        <if test="shareList !=null and shareList != ''" >
            share_list = #{shareList}
        </if> -->
        version_no = version_no+1
        WHERE user_code = #{userCode}
        <if test="versionNo !=null">
            and version_no = #{versionNo}
        </if>
    </update>

    <!-- 查询邀请人数 -->
    <select id="getInvitationNum" resultType="com.wechat.model.dto.InvitationNumDto">
        SELECT max(totail)          as totail,
               max(qualityNum)      as qualityNum,
               max(exchangeQuality) as exchangeQuality,
               max(exchangeNormal)  as exchangeNormal
        FROM ((SELECT count(1) AS totail, 0 AS qualityNum, 0 AS exchangeQuality, 0 AS exchangeNormal
               FROM mde_user
               WHERE inviter = #{inviter}
                 and IDENTITY_FLAG = '0'
                 and DEL_FLAG = '0')
              UNION All
              (SELECT 0                AS totail,
                      count(USER_CODE) AS qualityNum,
                      0                AS exchangeQuality,
                      0                AS exchangeNormal
               FROM (SELECT a.USER_CODE
                     FROM mde_user a
                              INNER JOIN mde_work_experience b ON a.USER_CODE = b.USER_CODE
                              LEFT JOIN mde_position_another_name c ON c.POSITION_NAME = b.POSITION_TITLE
                     WHERE a.inviter = #{inviter}
                       AND c.POSITION_NAME IS NOT NULL
						<![CDATA[ AND c.POSITION_GRADE < 5 ]]> 
						and a.DEL_FLAG = '0'
                       and b.DEL_FLAG = '0'
                       and c.DEL_FLAG = '0'
                     GROUP BY a.USER_CODE) m)
              UNION All
              (SELECT 0                                                                                         AS totail,
                      0                                                                                         AS qualityNum,
                      sum(CASE `STATUS`
                              WHEN '1' THEN EXCHANGE_QUALITY
                              WHEN '2' THEN ACTUAL_QUALITY
                              ELSE 0 END)                                                                       AS exchangeQuality,
                      sum(CASE `STATUS`
                              WHEN '1' THEN EXCHANGE_NORMAL
                              WHEN '2' THEN ACTUAL_NORMAL
                              ELSE 0 END)                                                                       AS exchangeNormal
               FROM MDE_EXCHANGE_HIS
               WHERE USER_CODE = #{userCode}
                 and DEL_FLAG = '0'
				<![CDATA[ and STATUS != 9 ]]> 
					and ACT_ID = #{actId})) unionTb
    </select>

    <!-- 查询受邀详情 -->
    <select id="getBeInvitedDtl" resultType="com.wechat.model.dto.BeInvitedDtlDto">
        SELECT a.USER_NAME                       as userName,
               a.`NAME`                          as name,
               a.CREATE_DATE                     as createDate,
               IFNULL(min(c.POSITION_GRADE), 10) as positionGrade
        FROM mde_user a
                 LEFT JOIN mde_work_experience b ON a.USER_CODE = b.USER_CODE AND b.DEL_FLAG = '0'
                 LEFT JOIN mde_position_another_name c ON c.POSITION_NAME = b.POSITION_TITLE AND c.DEL_FLAG = '0'
        WHERE a.inviter = #{inviter}
          AND a.DEL_FLAG = '0'
        GROUP BY a.USER_CODE
    </select>


    <select id="getUserAndIsFriend" resultType="com.wechat.model.dto.UserAndIsFriendDto">
        SELECT
        a.user_code AS "userCode",
        a.name AS "name",
        a.foreign_name AS "foreignName",
        a.head_portrait AS "headPortrait",
        a.email AS "email",
        a.addr_province AS "addrProvince",
        a.addr_city AS "addrCity",
        a.addr_area AS "addrArea",
        a.INTRODUCTION as introduction,
        a.phone_code AS "phoneCode",
        a.identity_flag AS "identityFlag",
        a.image AS "image",
        a.vip_flag AS "vipFlag",
        a.birthday AS "birthday",
        TIMESTAMPDIFF( YEAR, a.FIRST_WORK, CURDATE( ) ) AS experience,
        a.first_work as "firstWork",
        a.add_detail AS "addDetail",
        a.PREPARE_FLAG as prepareFlag,
        a.PREPARE_YEAR as prepareYear,
        a.PREPARE_QUARTER as prepareQuarter,
        a.add_longitude AS "addLongitude",
        a.add_latitude AS "addLatitude",
        a.website AS "website",
        a.create_date AS "createDate",
        <choose>
            <when test="beViewed != null and beViewed != theSearch">
                case when rel.TO_BE_CONFIRMED is null then 0
                when rel.TO_BE_CONFIRMED is not null and rel.CONFIRM_TIME is not null then 1
                when rel.TO_BE_CONFIRMED = #{theSearch} and rel.CONFIRM_TIME is null then 2
                when rel.TO_BE_CONFIRMED = #{beViewed} and rel.CONFIRM_TIME is null then 3
                end as isFriend
            </when>
            <otherwise>
                9 as isFriend
            </otherwise>
        </choose>
        <choose>
            <when test="lang != null and lang == 'en'.toString()">
                ,concat(c.name_en,d.name_en) as 'address'
            </when>
            <otherwise>
                ,concat(c.name,d.name) as 'address'
            </otherwise>
        </choose>
        ,b.position_title as "positionTitle"
        ,b.co_name as "coName"
        FROM
        mde_user a
        <include refid="mdeUserJoins"/>
        left join sys_area c on c.code=a.addr_province
        left join sys_area d on d.code=a.addr_city
        <if test="beViewed != null and beViewed != theSearch">
            left join mde_friend_relation rel
            on rel.del_flag = 0
            AND (( rel.USER_ID_1 = #{theSearch} AND rel.USER_ID_2 = a.user_code )
            OR ( rel.USER_ID_1 = a.user_code AND rel.USER_ID_2 = #{theSearch} ) )
        </if>
        WHERE a.user_code = #{beViewed} and a.del_flag=0
    </select>

    <!-- 优选人才推荐-分页 -->
    <select id="getPagingRecommentTalent" resultType="com.wechat.model.dto.TalentRetrievalDto">
        SELECT usrs.USER_CODE                                  as userCode,
               usrs.NAME                                       as name,
               usrs.VIP_FLAG                                   as vipFlag,
               usrs.IDENTITY_FLAG                              as identityFlag,
               usrs.HEAD_PORTRAIT                              as headImage,
               base.CO_NAME                                    as coName,
               base.POSITION_TITLE                             as positionTitle,
               TIMESTAMPDIFF(YEAR, usrs.FIRST_WORK, CURDATE()) AS experience,
               min(ee.EDUCATION)                               as education
        FROM (SELECT DISTINCT we.USER_CODE,
                              we.CO_NAME,
                              we.POSITION_TITLE,
                              b.POSITION_GRADE,
                              a.WORK_EXPERIENCE
              FROM MDE_JOB_ADVERTISED a
                       INNER JOIN mde_position_another_name b ON a.POSITION_ID = b.POSITION_ID
                       INNER JOIN mde_work_experience we ON we.POSITION_TITLE = b.POSITION_NAME
              WHERE a.PUBLISHER = #{userCode}
                AND a.JOB_STATUS = '0'
                AND a.DEL_FLAG = '0'
                AND we.SHOW_FLAG = '0'
                AND we.DEL_FLAG = '0') base
                 INNER JOIN mde_user usrs ON usrs.USER_CODE = base.USER_CODE
                 LEFT JOIN mde_education_experience ee ON ee.USER_CODE = usrs.USER_CODE
        WHERE usrs.ALLOW_FLAG = '0'
          AND usrs.WORK_STATUS != '0'
        GROUP BY usrs.USER_CODE
        ORDER BY usrs.VIP_FLAG DESC,
                 IFNULL(YEAR(usrs.FIRST_WORK), '2199'),
                 ISNULL(ee.EDUCATION),
                 ee.EDUCATION
    </select>

    <select id="getPagingRecommentTalentCount" resultType="java.lang.Integer">
        SELECT count(1)
        FROM (SELECT DISTINCT we.USER_CODE
              FROM MDE_JOB_ADVERTISED a
                       INNER JOIN mde_position_another_name b ON a.POSITION_ID = b.POSITION_ID
                       INNER JOIN mde_work_experience we ON we.POSITION_TITLE = b.POSITION_NAME
              WHERE a.PUBLISHER = #{userCode}
                AND a.JOB_STATUS = '0'
                AND a.DEL_FLAG = '0'
                AND we.SHOW_FLAG = '0'
                AND we.DEL_FLAG = '0') base
                 INNER JOIN mde_user usrs ON usrs.USER_CODE = base.USER_CODE
        WHERE usrs.ALLOW_FLAG = '0'
          AND usrs.WORK_STATUS != '0'
    </select>

    <update id="modifySubscribedFlag">
        UPDATE mde_user SET
        SUBSCRIBED_FLAG = #{subscribedFlag},
        update_by = #{updateBy},
        update_date = #{updateDate},
        version_no = version_no+1
        WHERE user_code = #{userCode}
        and SUBSCRIBED_FLAG != #{subscribedFlag}
        <if test="versionNo != null">
            and version_no = #{versionNo}
        </if>
    </update>

    <update id="uploadBgImages">
        UPDATE mde_user SET
        <if test="topBackgroundPc != null and topBackgroundPc != ''">
            TOP_BACKGROUND_PC = #{topBackgroundPc},
        </if>
        <if test="topBackgroundMbl != null and topBackgroundMbl != ''">
            TOP_BACKGROUND_MBL = #{topBackgroundMbl},
        </if>
        <if test="portraitBackgroundPc != null and portraitBackgroundPc != ''">
            PORTRAIT_BACKGROUND_PC = #{portraitBackgroundPc},
        </if>
        <if test="portraitBackgroundMbl != null and portraitBackgroundMbl != ''">
            PORTRAIT_BACKGROUND_MBL = #{portraitBackgroundMbl},
        </if>
        update_by = #{updateBy},
        update_date = #{updateDate},
        version_no = version_no+1
        WHERE user_code = #{userCode}
    </update>

    <update id="deleteBgImages">
        UPDATE mde_user
        SET update_by   = #{updateBy},
            update_date = #{updateDate},
            version_no  = version_no + 1
        WHERE user_code = #{userCode}
    </update>
</mapper>