<?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.youlai.boot.system.mapper.UserSocialMapper">

    <!-- 用户认证信息映射 -->
    <resultMap id="AuthCredentialsMap" type="com.youlai.boot.framework.security.model.UserAuthInfo">
        <id property="userId" column="userId" jdbcType="BIGINT"/>
        <result property="username" column="username" jdbcType="VARCHAR"/>
        <result property="nickname" column="nickname" jdbcType="VARCHAR"/>
        <result property="deptId" column="dept_id" jdbcType="BIGINT"/>
        <result property="password" column="password" jdbcType="VARCHAR"/>
        <result property="status" column="status" jdbcType="BOOLEAN"/>
        <collection property="roles" ofType="string" javaType="java.util.Set">
            <result column="code"/>
        </collection>
    </resultMap>

    <!-- 根据用户ID获取认证信息 -->
    <select id="getAuthInfoByUserId" resultMap="AuthCredentialsMap">
        SELECT
            u.id AS userId,
            u.username,
            u.nickname,
            u.dept_id,
            u.password,
            u.status,
            r.code
        FROM
            sys_user u
            LEFT JOIN sys_user_role ur ON u.id = ur.user_id
            LEFT JOIN sys_role r ON ur.role_id = r.id AND r.is_deleted = 0
        WHERE
            u.id = #{userId}
            AND u.is_deleted = 0
    </select>

</mapper>
