package com.ywt.mg.domain.entities;

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

import java.util.List;

public interface MgRightRelsRepository extends PagingAndSortingRepository<MgRightRels, Integer> {

    /**
     * 判断表中是否有引用mg_role对应的id
     * @param id
     * @return
     */
    @Query(value = " SELECT count(1) FROM mg_right_rels WHERE role_id = ? AND `type` = 1 ",nativeQuery = true)
    int checkRoleCount(int id);

    /**
     * 判断表中是否有引用mg_menus对应的id
     * @param id
     * @return
     */
    @Query(value = " SELECT count(1) FROM mg_right_rels WHERE key_id =  ? AND `type` = 1",nativeQuery = true)
    int checkMenusCount(int id);

    /**
     * 根据role_id得到所有的mg_right_rels对象
     * @param id
     * @return
     */
    @Query(value = " SELECT * FROM mg_right_rels WHERE role_id = ? AND `type` = ?",nativeQuery = true)
    List<MgRightRels> findAllByRoleId(int id, int type);


}
