lrj
2 天以前 c61d4fe27c97d2ecc907756aa571a4ef14a7b9b6
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
37
38
package com.rongyichuang.activity.repository;
 
import com.rongyichuang.activity.entity.Activity;
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;
 
@Repository
public interface ActivityRepository extends JpaRepository<Activity, Long> {
    
    // 查询比赛列表(pid=0表示比赛,非0表示阶段)
    Page<Activity> findByPidAndStateOrderByCreateTimeDesc(Long pid, Integer state, Pageable pageable);
    
    // 按名称模糊查询比赛列表
    Page<Activity> findByPidAndStateAndNameContainingOrderByCreateTimeDesc(Long pid, Integer state, String name, Pageable pageable);
    
    // 查询比赛的所有阶段
    List<Activity> findByPidAndStateOrderByCreateTimeAsc(Long pid, Integer state);
    
    // 查询所有有效比赛(用于下拉选择)
    List<Activity> findByPidAndStateOrderByNameAsc(Long pid, Integer state);
    
    // 临时测试:查询所有比赛(不使用state字段)
    List<Activity> findByPidOrderByNameAsc(Long pid);
    
    // 统计比赛数量
    @Query("SELECT COUNT(a) FROM Activity a WHERE a.pid = 0 AND a.state = 1")
    long countActiveCompetitions();
    
    // 查询进行中的比赛
    @Query("SELECT a FROM Activity a WHERE a.pid = 0 AND a.state = 1 AND a.matchTime <= CURRENT_TIMESTAMP AND a.signupDeadline >= CURRENT_TIMESTAMP")
    List<Activity> findOngoingCompetitions();
}