package com.ywt.mg.domain.entities;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface MgAdminRightViewRepository extends JpaRepository<MgAdminRightView, Integer> {

    /**
     * 根据admminid和appid查找符合条件的数据
     * @param adminid
     * @param appId
     * @return
     */
    @Query(value = "select * from  mg_admin_right_view  WHERE admin_id = ? AND  appid = ?  group by right_id ", nativeQuery = true)
    List<MgAdminRightView> getAllByAdminIdAndAppId(int adminid, String appId);


    /**
     * @return
     */
    @Query(value = "select * from  mg_admin_right_view ; ", nativeQuery = true)
    List<MgAdminRightView> findAll();

    /**
     * 判断该用户是否有该权限点权限
     *
     * @param adminId
     * @param codeStr
     * @return
     */
    @Query(value = "select count(*) from  mg_admin_right_view where admin_id = ? and right_code = ? limit 1; ", nativeQuery = true)
    int checkRight(int adminId, String codeStr);


    /**
     * 根据admminid查找符合条件的数据
     * @param adminId
     * @return
     */
    @Query(value = "select * from  mg_admin_right_view  WHERE admin_id = ? group by right_id ", nativeQuery = true)
    List<MgAdminRightView> getAllByAdminId(int adminId);

}
