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

import java.util.List;

import org.springframework.data.domain.Pageable;
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.Marker;

public interface MarkerDao extends PagingAndSortingRepository<Marker, Integer>, JpaSpecificationExecutor<Marker> {

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

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

    public List<Marker> findByExamId(int examId);

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

    public List<Marker> findByExamIdAndSubjectCode(int examId, String subjectCode, Pageable page);

    public List<Marker> findByExamIdAndCommon(int examId, boolean common, Pageable page);

    public List<Marker> findByLoginName(String loginName);

    public List<Marker> findByLoginNameAndPassword(String loginName, String password);

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

    @Modifying
    @Query("delete from Marker m where m.examId=?1")
    public void deleteByExamId(int examId);
    
    @Query(value="select e.* from eb_marker e,m_library m where 1=1 and e.id = m.marker_id and m.student_id =?1",nativeQuery=true)
    public Marker findByStudentId(int studentId);

    @Query("select count(m) from Marker m where m.loginName=?1")
    public long countByLoginName(String loginName);

    public List<Marker> findByCommon(boolean common);
}
