package cn.com.ty.lift.ud.appmenu.mapper;

import java.util.List;

import cn.com.ty.lift.ud.appmenu.mapper.entity.Appmenu;
import cn.com.ty.lift.ud.appmenu.mapper.entity.AppuserMenu;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;

/**
 * app角色权限-Repository
 * 
 * @author Xson
 * @date 2020-06-04
 */
public interface AppuserMenuMapper extends BaseMapper<AppuserMenu> {

    @Select("SELECT b.* FROM appuser_menu a LEFT JOIN appmenu b ON a.appmenu_id=b.id  WHERE a.user_level_id=#{id} and b.parent_id!=1")
    List<Appmenu> findMenuByUserLevelId(@Param("id") Long levelId);

    @Delete("DELETE FROM appuser_menu WHERE user_level_id=#{id}")
    void deleteByLevelId(@Param("id") Long id);
    
    @Select("SELECT b.* FROM appuser_menu a LEFT JOIN appmenu b ON a.appmenu_id=b.id  WHERE a.user_level_id=#{id} and b.parent_id!=1 limit 5")
    List<Appmenu> getMenuByLevelIdLimit5(Long levelId);
}
