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.examId=?1 ")
    void deleteByExamId(int examId);

    @Query("select count(s) from CheckStudent s where s.examId=?1 and s.checked =?2")
    long countByExamIdAndChecked(int examId, boolean checked);

    @Query("select count(s) from CheckStudent s where s.examId=?1 and s.subjectCode =?2 and s.checked =?3")
    long countByExamIdAndSubjectCodeAndChecked(int examId, String subjectCode, boolean checked);

}
