package com.rongyichuang.employee.repository; import com.rongyichuang.employee.entity.Employee; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import java.util.List; import java.util.Optional; /** * 员工数据访问层 */ @Repository public interface EmployeeRepository extends JpaRepository { /** * 根据名称模糊查询员工列表 */ @Query("SELECT e FROM Employee e WHERE e.name LIKE %:name%") List findByNameContaining(@Param("name") String name); /** * 分页查询员工列表,支持名称模糊搜索 */ @Query("SELECT e FROM Employee e WHERE (:name IS NULL OR e.name LIKE %:name%) ORDER BY e.createTime DESC") Page findByNameContainingOrderByCreateTimeDesc(@Param("name") String name, Pageable pageable); /** * 根据手机号查询员工 */ Optional findByPhone(String phone); /** * 检查手机号是否已存在 */ boolean existsByPhone(String phone); /** * 检查手机号是否已存在(排除指定ID) */ @Query("SELECT COUNT(e) > 0 FROM Employee e WHERE e.phone = :phone AND e.id != :id") boolean existsByPhoneAndIdNot(@Param("phone") String phone, @Param("id") Long id); /** * 根据角色ID查询员工列表 */ List findByRoleId(String roleId); }