package com.ssj.dao.sys.role.dao;

import com.ssj.bean.sys.role.domain.Role;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface RoleDao extends JpaRepository<Role, String>{

	
	@Query(nativeQuery = true, value = "select count(1) from sys_role  where name = ?1 and id !=?2")
	public Integer validateRole(String name, String id);
	
	@Query(nativeQuery = true, value = "select menu_id from sys_role_menu  where role_id = ?1 ")
	List<String> getRoleMenu(String roleId);
	
	@Query(nativeQuery = true, value = "select role_id from sys_admin_role  where admin_id = ?1 ")
	List<String> getAdminRole(String adminId);
	
	@Query(nativeQuery = true, value = "delete from sys_role_menu  where role_id =?1  ")
	@Modifying
	public Integer  deleteRoleMenu(String id);
	
	@Query(nativeQuery = true, value = "delete from sys_admin_role  where admin_id =?1  ")
	@Modifying
	public Integer  deleteAdminRole(String id);

	@Query(nativeQuery = true, value="select open_id from tb_role_weixin_ref where role_id=?1")
	public List<String> getWxRole(String id);
	
	@Query(nativeQuery = true, value = "delete from tb_role_weixin_ref  where role_id =?1  ")
	@Modifying
	public void deleteWxRole(String id);
	
	
}
