package cn.com.qmth.stmms.biz.mark.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.mark.model.HeaderTag;

public interface HeaderTagDao extends PagingAndSortingRepository<HeaderTag, Integer>,
        JpaSpecificationExecutor<HeaderTag> {

    @Modifying(clearAutomatically = true)
    @Query("delete from HeaderTag s where s.studentId = ?1 and s.groupNumber=?2 ")
    public void deleteByStudentIdAndGroupNumber(Integer studentId, Integer groupNumber);

    @Modifying(clearAutomatically = true)
    @Query("delete from HeaderTag s where s.studentId = ?1")
    public void deleteByStudentId(Integer studentId);

    public List<HeaderTag> findByStudentIdAndGroupNumberOrderByIdAsc(Integer studentId, Integer groupNumber);

    @Modifying(clearAutomatically = true)
    @Query("delete from HeaderTag s where s.groupNumber=?3 and s.studentId in (select m.id from ExamStudent m where m.examId=?1 and m.subjectCode=?2) ")
    public void deleteByExamAndSubjectAndGroup(Integer examId, String subjectCode, Integer groupNumber);

    public List<HeaderTag> findByStudentId(Integer studentId);

}
