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

import java.util.List;

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

public interface InspectHistoryDao extends PagingAndSortingRepository<InspectHistory, Integer>,
        JpaSpecificationExecutor<InspectHistory>, JpaRepository<InspectHistory, Integer> {

    @Query(value = "select * from eb_inspect_history s where s.student_id=?1 order by s.inspect_time desc limit ?2 ", nativeQuery = true)
    List<InspectHistory> findByStudentIdLimit3(int studentId, int count);

    Integer countByStudentId(Integer studentId);

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

    @Modifying
    @Query("delete from InspectHistory m where m.examId=?1 and m.subjectCode=?2")
    void deleteByExamIdAndSubjectCode(int examId, String subjectCode);


//    InspectHistory findByStudentIdAndInspectRound(Integer studentId, Integer inspectRound);

//    @Modifying
//    @Query(nativeQuery = true, value = "delete from eb_inspect_history where student_id=?1 and inspect_round=(select es.inspect_round from eb_exam_subject es,eb_exam_student s where s.id=?1 and es.exam_id=s.exam_id and es.code=s.subject_code)")
//    void deleteByStudentIdAndInspectRound(Integer studentId);

//    @Modifying
//    @Query("delete from InspectHistory m where m.examId=?1 and m.subjectCode=?2 and m.inspectRound=?3")
//    void deleteByExamIdAndSubjectCodeAndInspectRound(int examId, String subjectCode, Integer inspectRound);

}
