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 MgAdminsRoleRelsRepository extends PagingAndSortingRepository<MgAdminRoleRels, Integer> {


    /**
     * 判断表中是否有引用mg_admdin对应的id
     * @param id
     * @return
     */
    @Query(value = " SELECT count(1) FROM mg_admin_role_rels WHERE admin_id = ? ",nativeQuery = true)
    int checkAdminCount(int id);

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

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

    /**
     * 根据admin_id得到所有的对象
     * @param id
     * @return
     */
    @Query(value = " SELECT * FROM mg_admin_role_rels WHERE admin_id = ? ",nativeQuery = true)
    List<MgAdminRoleRels> findAllByAdminId(int id);

}
