package cn.com.qmth.stmms.biz.basic.dao;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

import cn.com.qmth.stmms.biz.basic.model.RolePrivilege;
import cn.com.qmth.stmms.common.enums.Role;

public interface RolePrivilegeDao extends PagingAndSortingRepository<RolePrivilege, Integer>, JpaSpecificationExecutor<RolePrivilege>,
        JpaRepository<RolePrivilege, Integer> {

	List<RolePrivilege> findBySchoolIdAndRoleCodeAndEnable(Integer schoolId, Role role, boolean b);

	@Modifying
    @Query("update RolePrivilege t set t.enable=0 where t.schoolId=?1 and t.roleCode=?2")
	void disable(Integer schoolId, Role  role);

	@Modifying
    @Query("update RolePrivilege t set t.enable=1 where t.schoolId=?1 and t.roleCode=?2 and t.privilegeCode in(?3)")
	void enable(Integer schoolId, Role role,List<String> codes);
}
