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

import java.util.List;
import java.util.Set;

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

import cn.com.qmth.stmms.biz.mark.model.ArbitrateHistory;
import cn.com.qmth.stmms.common.enums.LibraryStatus;

public interface ArbitrateHistoryDao extends JpaRepository<ArbitrateHistory, Integer>,
        JpaSpecificationExecutor<ArbitrateHistory> {

    List<ArbitrateHistory> findByExamIdAndSubjectCodeAndGroupNumber(Integer examId, String subjectCode,
            Integer groupNumber, Pageable page);

    List<ArbitrateHistory> findByExamIdAndSubjectCodeAndGroupNumberAndStatus(Integer examId, String subjectCode,
            Integer groupNumber, LibraryStatus status, Pageable page);

    List<ArbitrateHistory> findByExamIdAndSubjectCodeAndGroupNumberAndStatusIn(Integer examId, String subjectCode,
            Integer groupNumber, Set<LibraryStatus> statusSet, Pageable page);

    @Modifying
    @Query("delete ArbitrateHistory m where m.examId=?1 and m.subjectCode=?2 and m.groupNumber=?3")
    void deleteByExamIdAndSubjectCodeAndGroupNumber(Integer examId, String subjectCode, Integer groupNumber);

    @Modifying
    @Query("delete ArbitrateHistory m where m.studentId=?1")
    void deleteByStudentId(Integer studentId);

    @Modifying
    @Query("delete ArbitrateHistory m where m.studentId=?1 and m.groupNumber=?2")
    void deleteByStudentIdAndGroupNumber(Integer id, Integer groupNumber);

}
