package cn.com.qmth.stmms.biz.exam.dao;

import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

import cn.com.qmth.stmms.biz.exam.model.Exam;
import cn.com.qmth.stmms.common.enums.ExamStatus;

public interface ExamDao extends PagingAndSortingRepository<Exam, Integer>, JpaSpecificationExecutor<Exam> {

    public Page<Exam> findAll(Pageable pageable);

    List<Exam> findByStatus(ExamStatus status);

    @Query("select e from Exam e where e.creatorId=?1 and e.status=?2 order by e.examTime desc")
    public List<Exam> findByCreatorAndStatus(Integer id, ExamStatus status);

    @Modifying
    @Query("update Exam e set e.status=?2 where e.id=?1")
    public void updateStatus(int examId, ExamStatus status);

	public List<Exam> findBySchoolIdOrderByIdDesc(Integer schoolId);
}
