<?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="com.zhiqiyun.open.core.mapper.UserBaseInfoMapper">
    <delete id="deleteRoles">
        delete
        FROM user_role
        WHERE uid = #{uid,jdbcType=BIGINT}
    </delete>
    <insert id="insertRoles">
        insert into user_role (uid, role_id)
        values
        <foreach collection="listRoles" item="item" index="index" separator=",">
            (#{uid,jdbcType=BIGINT},#{item,jdbcType=BIGINT})
        </foreach>
    </insert>
    <select id="findUserAuthorities" resultType="java.lang.String">
        SELECT name
        FROM authority_info
        WHERE id IN (
            SELECT authority_id
            FROM role_authority
            WHERE role_id IN (
                SELECT role_id
                FROM user_role
                WHERE uid = #{uid,jdbcType=BIGINT}
            )
        )
    </select>
    <select id="findSelectAccounts" resultType="java.util.Map">
        select id,`nick_name` as nickName from `user_base_info`
        <where>
            <if test="searchKey != null and searchKey !=''">
                or `nick_name` like CONCAT("%",#{searchKey},"%")
                or `id` like CONCAT("%",#{searchKey},"%")
                or `id` in (select `uid` from `user_login_account` where `login_account` like
                CONCAT("%",#{searchKey},"%"))
            </if>
        </where>
        limit 10
    </select>
</mapper>
