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


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import cn.qinys.platform.entity.upms.UpmsMenu;
import cn.qinys.platform.entity.upms.UpmsRoleMenus;
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;


/**
 * 角色菜单关系表(UpmsRoleMenus)表数据库访问层
 *
 * @author makejava
 * @since 2024-02-28 11:16:27
 */
@Repository
@Mapper
public interface UpmsRoleMenusMapper extends BaseMapper<UpmsRoleMenus> {

    /**
     * 根据角色获取菜单
     *
     * @param roleId
     * @return
     */
    @Select("SELECT m.* FROM upms_role_menus rm LEFT JOIN upms_menu m ON m.id = rm.menu_id WHERE rm.role_id = #{roleId}")
    List<UpmsMenu> selectMenusByRole(@Param("roleId") String roleId);

    /**
     * 根据角色获取菜单id
     *
     * @param roleId
     * @return
     */
    @Select("SELECT menu_id FROM upms_role_menus WHERE role_id = #{roleId}")
    List<Integer> selectMenuIdsByRole(@Param("roleId") String roleId);

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

