package com.mydreamjob.application; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; import java.util.Optional; import java.util.List; @Repository public interface ApplicationRepository extends JpaRepository { Optional findByJobIdAndStudentUserId(Long jobId, Long studentUserId); List findByStudentUserIdOrderByCreatedAtDesc(Long studentUserId); Page findByStudentUserIdOrderByCreatedAtDesc(Long studentUserId, Pageable pageable); Page findByStudentUserIdAndStatusOrderByCreatedAtDesc(Long studentUserId, String status, Pageable pageable); List findByJobIdOrderByCreatedAtDesc(Long jobId); Page findByJobIdOrderByCreatedAtDesc(Long jobId, Pageable pageable); Page findByJobIdAndStatusOrderByCreatedAtDesc(Long jobId, String status, Pageable pageable); boolean existsByJobIdAndStudentUserId(Long jobId, Long studentUserId); @org.springframework.data.jpa.repository.Query("select distinct a.jobId from Application a where a.studentUserId = :studentUserId") java.util.List findDistinctJobIdsByStudentUserId(@org.springframework.data.repository.query.Param("studentUserId") Long studentUserId); /** * 同岗位竞争排名:判断学生是否存在某岗位的「有效投递」(状态不在排除集合内, * 即非 WITHDRAWN/REJECTED)。与 {@link #findByJobIdAndStatusNotInOrderByCreatedAtAsc} * 共用同一排除口径,避免"曾投递但已失效"误放行导致返回 200。 */ boolean existsByJobIdAndStudentUserIdAndStatusNotIn(Long jobId, Long studentUserId, java.util.Collection statuses); /** * 同岗位 rank 用:取某岗位未排除(非 WITHDRAWN/REJECTED)的投递,按投递时间正序。 */ List findByJobIdAndStatusNotInOrderByCreatedAtAsc(Long jobId, java.util.Collection statuses); /** * V34 批量:一次取出多个岗位(page 内投递涉及的去重 jobId)未排除的候选人投递, * 按投递时间正序;用于批量计算同岗位竞争力排名,避免按岗位循环查询造成 N+1。 */ List findByJobIdInAndStatusNotInOrderByCreatedAtAsc(java.util.Collection jobIds, java.util.Collection statuses); }