package xyz.acmer.repository.contest;

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 org.springframework.transaction.annotation.Transactional;
import xyz.acmer.entity.contest.ContestInfo;
import xyz.acmer.entity.contest.ContestType;

import java.util.Date;
import java.util.List;

/**
 * 比赛信息DAO
 * Created by hypo on 16-2-26.
 */
@Repository
@Transactional
public interface ContestInfoRepository extends JpaRepository<ContestInfo, Long> {

    @Query("SELECT c FROM ContestInfo c ORDER BY c.beginTime DESC")
    List<ContestInfo> getAllContestByBeginTime();

    @Query("SELECT c FROM ContestInfo c WHERE c.contestType=:type ORDER BY c.beginTime DESC")
    List<ContestInfo> getContestByContestType(@Param("type")ContestType contestType);

    @Query("SELECT c FROM ContestInfo c WHERE c.beginTime>:now ORDER BY c.beginTime DESC")
    List<ContestInfo> getContestScheduled(@Param("date")Date now);

    @Query("SELECT c FROM ContestInfo c WHERE c.endTime>:now AND c.beginTime<:now ORDER BY c.beginTime DESC")
    List<ContestInfo> getContestRunning(@Param("date")Date now);

    @Query("SELECT c FROM ContestInfo c WHERE c.endTime<:now ORDER BY c.beginTime DESC")
    List<ContestInfo> getContestEnded(@Param("date")Date now);
}

@@ -797,17 +797,24 @@
 stType=:
-t
+contestT
 ype ORDE
@@ -891,17 +891,24 @@
 @Param(%22
-t
+contestT
 ype%22)Con
@@ -990,19 +990,20 @@
 inTime%3E:
-now
+date
  ORDER B
@@ -1148,19 +1148,20 @@
 ndTime%3E:
-now
+date
  AND c.b
@@ -1166,27 +1166,28 @@
 .beginTime%3C:
-now
+date
  ORDER BY c.
@@ -1326,19 +1326,20 @@
 ndTime%3C:
-now
+date
  ORDER B

update src/main/java/xyz/acmer/repository/contest/ContestInfoRepository.java