lrj
6 天以前 7ba080d35812e6db7bd5aa8f88161c02653eb6c1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package com.rongyichuang.judge.repository;
 
import com.rongyichuang.judge.entity.Judge;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
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 JudgeRepository extends JpaRepository<Judge, Long>, JpaSpecificationExecutor<Judge> {
 
    @Query("SELECT j FROM Judge j WHERE j.name LIKE %:name%")
    List<Judge> findByNameContaining(@Param("name") String name);
    
    boolean existsByPhone(String phone);
    
    /**
     * 根据用户ID查找评委
     */
    Optional<Judge> findByUserId(Long userId);
    
    /**
     * 检查评委是否参与指定活动
     */
    @Query("SELECT COUNT(aj) > 0 FROM ActivityJudge aj WHERE aj.judgeId = :judgeId AND aj.activityId = :activityId")
    boolean existsByIdAndActivityId(@Param("judgeId") Long judgeId, @Param("activityId") Long activityId);
}