lrj
昨天 9f8395fab13ca4b230a0f7d62636e209745c91d4
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
32
33
34
35
36
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);
 
    /**
     * 根据状态统计评委数量
     */
    long countByState(Integer state);
}