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

public interface SubjectHeaderDao extends PagingAndSortingRepository<SubjectHeader, Integer>,
        JpaSpecificationExecutor<SubjectHeader> {

    @Query("select count(ms) from SubjectHeader ms where ms.examId=?1")
    public long countByExamId(int examId);

    @Query("select count(m) from SubjectHeader m where m.examId=?1 and m.subjectCode=?2 ")
    public long countByExamIdAndSubjectCode(int examId, String subjectCode);

    public List<SubjectHeader> findByExamId(int examId);

    public List<SubjectHeader> findByExamIdAndSubjectCode(int examId, String subjectCode);

    public List<SubjectHeader> findByLoginName(String loginName);

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

}
