package com.hertz.modules.system.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hertz.modules.system.entity.SysRole;
import java.util.List;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface SysRoleMapper extends BaseMapper<SysRole> {
  @Select("""
      SELECT r.role_key
      FROM sys_role r
      INNER JOIN sys_user_role ur ON ur.role_id = r.id
      WHERE ur.user_id = #{userId} AND r.status = 1
      """)
  List<String> selectRoleKeysByUserId(@Param("userId") long userId);

  @Select("""
      SELECT r.*
      FROM sys_role r
      INNER JOIN sys_user_role ur ON ur.role_id = r.id
      WHERE ur.user_id = #{userId} AND r.status = 1
      ORDER BY r.id ASC
      """)
  List<SysRole> selectRolesByUserId(@Param("userId") long userId);
}

