<?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="org.springblade.system.user.mapper.UserMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="userResultMap" type="org.springblade.system.user.entity.User">
        <result column="id" property="id"/>
        <result column="create_user" property="createUser"/>
        <result column="create_time" property="createTime"/>
        <result column="update_user" property="updateUser"/>
        <result column="update_time" property="updateTime"/>
        <result column="status" property="status"/>
        <result column="is_deleted" property="isDeleted"/>
        <result column="account" property="account"/>
        <result column="password" property="password"/>
        <result column="name" property="name"/>
        <result column="real_name" property="realName"/>
        <result column="email" property="email"/>
        <result column="phone" property="phone"/>
        <result column="birthday" property="birthday"/>
        <result column="sex" property="sex"/>
        <result column="role_id" property="roleId"/>
        <result column="dept_id" property="deptId"/>
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="baseColumnList">
        select id,
        create_user AS createUser,
        create_time AS createTime,
        update_user AS updateUser,
        update_time AS updateTime,
        status,
        is_deleted AS isDeleted,
        account, password, name, real_name, email, phone, birthday, sex, role_id, dept_id
    </sql>

    <select id="selectUserPage" resultMap="userResultMap">
        select * from blade_user where is_deleted = 0
    </select>

    <select id="getUser" resultMap="userResultMap">
        SELECT
            *
        FROM
            blade_user
        WHERE
            account = #{account} AND password = #{password}
    </select>

    <select id="getRoleName" resultType="java.lang.String">
        SELECT
        role_name
        FROM
        blade_role
        WHERE
        id IN
        <foreach collection="array" item="ids" index="index" open="(" close=")" separator=",">
            #{ids}
        </foreach>
    </select>

    <select id="getRoleAlias" resultType="java.lang.String">
        SELECT
            role_alias
        FROM
            blade_role
        WHERE
            id IN
        <foreach collection="array" item="ids" index="index" open="(" close=")" separator=",">
            #{ids}
        </foreach>
    </select>

    <select id="getDeptName" resultType="java.lang.String">
        SELECT
            dept_name
        FROM
            blade_dept
        WHERE
            id IN
        <foreach collection="array" item="ids" index="index" open="(" close=")" separator=",">
            #{ids}
        </foreach>
    </select>

</mapper>
