package com.crm.manager.dao.repository;

import com.crm.rely.backend.core.pojo.table.UserRoleTable;
import com.crm.rely.backend.dao.repository.BaseRepository;
import org.springframework.data.jpa.repository.Lock;
import org.springframework.stereotype.Repository;

import javax.persistence.LockModeType;
import java.util.List;

@Repository
public interface UserRoleRepository extends BaseRepository<UserRoleTable> {


    boolean existsByName(String name);

    boolean existsById(Long id);

    /**
     * 根据部门id 查询是否存在改部门下的角色
     *
     * @param departmentIds
     * @return
     */
    boolean existsByDepartmentIdIn(Iterable<Long> departmentIds);

    /**
     * 根据ids获取数据
     *
     * @param ids
     * @return
     */
    @Lock(LockModeType.PESSIMISTIC_WRITE)
    List<UserRoleTable> findAllByIdIn(List<Long> ids);

    /**
     * 根据id获取数据
     *
     * @param id
     * @return
     */
    @Lock(LockModeType.PESSIMISTIC_WRITE)
    UserRoleTable findFirstById(Long id);

    UserRoleTable getFirstById(Long id);
}
