<?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.ozs.mapper.BaseUserMapper">

    <select id="getUserIdList" resultType="java.lang.String" parameterType="java.lang.String">
        select user_id
        from sys_user
        where user_id = #{userId}
          and data_permission = 1
    </select>

    <select id="getUserIdByDeptId" resultType="java.lang.String" parameterType="java.lang.Long">
        select user_id
        from sys_user
        where dept_id = #{deptId}
          and data_permission = 2
    </select>

    <select id="getDeptId" resultType="java.lang.Long" parameterType="java.lang.Long">
        select dept_id
        from sys_dept
        where dept_id = #{deptId} or find_in_set(#{deptId}, ancestors)
    </select>

    <select id="getUserIdByDeptIds" resultType="java.lang.String" parameterType="java.util.List">
        select user_id
        from sys_user
        where data_permission = 3 and dept_id in
        <foreach item="item" collection="deptList" separator="," open="(" close=")" index="">
            #{item}
        </foreach>
    </select>

    <select id="getUserIdByDeptIdAndUserId" resultType="java.lang.String">
        select user_id
        from sys_user
        where (user_id = #{userId} or dept_id = #{deptId})
          and data_permission = 4
    </select>

    <select id="getUserIdListBy5" resultType="java.lang.String" parameterType="java.lang.String">
        select user_id
        from sys_user
        where user_id = #{userId}
          and data_permission = 5
    </select>

    <select id="getUserIdByDeptIdsBy5" resultType="string" parameterType="list">
        select user_id
        from sys_user
        where dept_id in
        <foreach item="item" collection="deptList" separator="," open="(" close=")" index="">
            #{item}
        </foreach>
        and data_permission = 5
    </select>

    <select id="getUserIdList6" resultType="java.lang.String">
        select user_id
        from sys_user
        where data_permission = 6
    </select>

    <select id="getUser" resultType="com.ozs.entity.BaseUser" parameterType="java.lang.String">
        select user_id userId, dept_id deptId, data_permission dataPermission,nick_name nickName,user_name userName from sys_user where user_id = #{userId}
    </select>
    <select id="getUserName" resultType="com.ozs.entity.BaseUser" parameterType="java.lang.String">
        select user_id userId, dept_id deptId, data_permission dataPermission from sys_user where user_name = #{userName}
    </select>
    <select id="getUserIdsList" resultType="java.lang.String">
        select user_id
        from sys_user
    </select>
    <select id="getRoleName" resultType="java.lang.String" parameterType="java.lang.String">
        SELECT  r.role_key FROM `sys_user` u JOIN sys_user_role ur ON u.id=ur.user_id JOIN sys_role r 
         ON ur.role_id=r.role_id WHERE u.user_id=#{userId}
    </select>
    <select id="getUserById" resultType="com.ozs.entity.BaseUser">
    select user_id userId, dept_id deptId, data_permission dataPermission,nick_name nickName,user_name userName from sys_user where id = #{id}
    </select>
</mapper>
