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.CheckStudent;
import cn.com.qmth.stmms.common.enums.CheckType;

public interface CheckStudentDao extends PagingAndSortingRepository<CheckStudent, Integer>,
        JpaSpecificationExecutor<CheckStudent> {

    List<CheckStudent> findByExamIdAndCheckedAndType(int examId, boolean checked, CheckType type);

    @Modifying
    @Query("delete CheckStudent c where c.studentId=?1 ")
    void deleteByStudentId(int examId);

    long countByExamIdAndChecked(int examId, boolean checked);

    long countByExamIdAndSubjectCodeAndChecked(int examId, String subjectCode, boolean checked);

    List<CheckStudent> findByExamIdAndSubjectCodeAndCheckedAndType(int examId, String subjectCode, boolean checked,
            CheckType type);

    @Query("select distinct c.subjectCode from CheckStudent c where c.examId=?1 and c.checked=?2 and c.type=?3")
    List<String> findCheckSubjectCodeAndCheckedAndType(int examId, boolean checked, CheckType type);

}
