<?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.haha.mapper.RolePermissionMapper">

    <!-- 结果映射 -->
    <resultMap id="BaseResultMap" type="com.haha.entity.RolePermission">
        <id column="id" property="id"/>
        <result column="role_id" property="roleId"/>
        <result column="permission_id" property="permissionId"/>
        <result column="create_time" property="createTime"/>
    </resultMap>

    <!-- 根据角色ID删除权限关联 -->
    <delete id="deleteByRoleId">
        DELETE FROM t_role_permission
        WHERE role_id = #{roleId}
    </delete>

    <!-- 根据角色ID查询权限ID列表 -->
    <select id="selectPermissionIdsByRoleId" resultType="java.lang.Long">
        SELECT permission_id
        FROM t_role_permission
        WHERE role_id = #{roleId}
    </select>

    <!-- 检查角色是否拥有指定权限 -->
    <select id="checkRoleHasPermission" resultType="int">
        SELECT COUNT(*)
        FROM t_role_permission
        WHERE role_id = #{roleId}
        AND permission_id = #{permissionId}
    </select>

</mapper>
