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

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 org.springframework.data.repository.PagingAndSortingRepository;

import cn.com.qmth.stmms.biz.exam.model.SelectiveStudent;
import org.springframework.transaction.annotation.Transactional;

public interface SelectiveStudentDao extends JpaRepository<SelectiveStudent, Integer>,
        PagingAndSortingRepository<SelectiveStudent, Integer>, JpaSpecificationExecutor<SelectiveStudent> {

    @Modifying(clearAutomatically = true)
    @Query("delete SelectiveStudent s where s.examId=?1 and s.subjectCode=?2")
    void deleteByExamIdAndSubjectCode(Integer examId, String subjectCode);

    @Modifying(clearAutomatically = true)
    @Transactional
    @Query("delete SelectiveStudent s where s.studentId=?1")
    void deleteByStudentId(Integer studentId);
    @Query("select count(s) from SelectiveStudent s where s.examId=?1 and s.subjectCode=?2 and (s.lessSelective=?3 or s.notSelective=?4)")
    int countByExamIdAndSubjectCodeAndLessSelectiveOrNotSelective(Integer examId, String subjectCode,boolean lessSelective,boolean noSelective);
}
