package cn.qinys.platform.upms.api.mapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import cn.qinys.platform.entity.upms.UpmsRolePermission;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;


/**
 * 角色权限码关系表(UpmsRolePermission)表数据库访问层
 *
 * @author makejava
 * @since 2024-02-28 14:40:35
 */
@Repository
@Mapper
public interface UpmsRolePermissionMapper extends BaseMapper<UpmsRolePermission> {

    /**
     * 根据角色获取权限码 id
     *
     * @param roleId
     * @return
     */
    @Select("SELECT permission_id FROM upms_role_permission WHERE role_id = #{roleId}")
    List<Integer> selectPermissionByRole(@Param("roleId") String roleId);


    /**
     * 删除菜单
     *
     * @param menuId
     * @return
     */
    @Delete("DELETE FROM upms_role_permission WHERE menu_id = #{menuId}")
    void deleteByMenuId(@Param("menuId") Integer menuId);

    /**
     * 角色权限码
     *
     * @param roleId
     * @return
     */
    @Select("SELECT p.permission_code FROM upms_role_permission rp " +
            "LEFT JOIN upms_menu_permission p ON rp.permission_id = p.id WHERE rp.role_id = #{roleId}")
    List<String> selectPermissionCodeByRole(@Param("roleId") String roleId);
}

