package com.crm.manager.dao.repository;

import com.crm.rely.backend.core.pojo.table.UserDepartmentTable;
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;

/**
 * @author houn
 */
@Repository
public interface UserDepartmentRepository extends BaseRepository<UserDepartmentTable> {

    /**
     * 根据名称判断部门是否存在
     *
     * @param name
     * @return
     */
    boolean existsByName(String name);

    /**
     * 根据id查询部门 加行锁
     *
     * @param id 主键id
     * @return
     */
    @Lock(LockModeType.PESSIMISTIC_WRITE)
    UserDepartmentTable findFirstById(Long id);

    /**
     * 根据id查询部门列表 加行锁
     *
     * @param ids
     * @return
     */
    @Lock(LockModeType.PESSIMISTIC_WRITE)
    List<UserDepartmentTable> findByIdIn(Iterable<Long> ids);

    List<UserDepartmentTable> getAllByOrderBySubIndex();
}
