package cn.estsh.i3plus.core.apiservice.dao;

import cn.estsh.i3plus.pojo.platform.bean.SysMenu;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Description :
 * @Reference :
 * @Author : Adair Peng
 * @CreateDate : 2018-12-18 13:38
 * @Modify:
 **/
public interface ISysMenuDao {

    /**
     * 根据用户角色 ID 查询所有菜单
     * HQL:
     *     select sm.*
     *      from sys_menu as sm
     *      left join sys_ref_role_menu as srrm on sm.id = srrm.menu_id and role_id = 200001
     *      where sm.parent_id = 100003
     * @param parentId
     * @param roleId
     * @return
     */
//    @Modifying
//    @Query(" select sm from SysMenu as sm " +
//            "left join SysRefRoleMenu as srrm on sm.id = srrm.menuId and srrm.roleId =:roleId " +
//            "where sm.parentId =:parentId")
    List<SysMenu> findByParentIdAndRoleId(Long parentId, Long roleId);

    /**
     * 根据用户ID 查询所有菜单
     * HQL:
     *     select sm.*
     *      from sys_menu as sm
     *      left join sys_ref_role_menu as srrm on sm.id = srrm.menu_id
     *      left join sys_ref_user_role as srur on srur.role_id = srrm.role_id and srur.user_id = 400001
     *      where sm.parent_id = 100003
     * @param parentId
     * @param userId
     * @return
     */
//    @Query(" select sm from SysMenu as sm " +
//            "left join SysRefRoleMenu as srrm on sm.id = srrm.menuId " +
//            "left join SysRefUserRole as srur on sm.roleId = srrm.roleId and srur.userId =:userId " +
//            "where sm.parentId =:parentId")
    List<SysMenu> findByParentIdAndUserId(Long parentId, Long userId);

}
