package cn.com.qmth.stmms.ms.core.repository;

import cn.com.qmth.stmms.ms.core.domain.Student;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;
import java.util.Map;

/**
 * @author ting.yin
 * @date 2016年10月27日
 */
public interface StudentRepo extends JpaRepository<Student, Long>, JpaSpecificationExecutor<Student> {

    Student findByWorkIdAndExamNumber(Long workId, String examNumber);

    Student findByWorkIdAndExamNumberAndTest(Long workId, String examNumber, String test);

    Student findByWorkIdAndRelateExamNumberAndTest(Long workId, String examNumber, String test);

    void deleteByWorkId(Long workId);

    List<Student> findByWorkIdAndTest(Long workId, String test);

    @Query(value = "select s.exam_number, s.name, s.area_name , s.area_code, s.exam_room, s.source_name, s.school from paper p join student s on p.work_id = s.work_id and p.exam_number = s.exam_number and p.area_code = s.area_code where p.work_id = ? and p.subject = ? and p.is_missing = true", nativeQuery = true)
    List<Object[]> listMissingBySubject(Long workId, String subject);

    void deleteByWorkIdAndTest(Long workId, String test);

    List<Student> findByWorkIdAndTestAndExamRoom(Long workId, String test, String examRoom);

    Student findByWorkIdAndRelateExamNumber(Long workId, String examNumber);

//    @Query("select distinct s.areaName, s.school, s.examRoom from Student s where s.workId = ?1")
    List<Student> findByWorkId(Long workId);

    Student findByWorkIdAndAreaCodeAndExamNumber(Long workId, String areaCode, String examNumber);
}
