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

import java.util.List;

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.AnswerCardSubject;

public interface AnswerCardSubjectDao
        extends PagingAndSortingRepository<AnswerCardSubject, Integer>, JpaSpecificationExecutor<AnswerCardSubject> {

    @Query("select s from AnswerCardSubject s where s.examId=?1 and s.cardNumber=?2 and s.subjectCode=?3 ")
    AnswerCardSubject findByExamIdAndCardNumberAndSubjectCode(Integer examId, Integer number, String subjectCode);

    @Query("select q from AnswerCardSubject q where q.examId=?1 and q.cardNumber=?2")
    List<AnswerCardSubject> findByExamIdAndCardNumber(Integer examId, Integer number);

    @Modifying
    @Query("delete AnswerCardSubject s where s.examId=?1 and s.cardNumber=?2 ")
    void deleteByExamIdAndCardNumber(Integer examId, Integer number);

    AnswerCardSubject findByExamIdAndSubjectCode(Integer examId, String subjectCode);

    @Query("select s from AnswerCardSubject s where s.examId=?1 and s.subjectCode=?2 ")
    List<AnswerCardSubject> findByExamIdAndSubjectCode(int examId, String subjectCode);

}
