package com.ssj.dao.kmt.kmt.dao;



import com.ssj.bean.kmt.kmt.domain.KmtExampaperArea;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface IKmtExampaperAreaDao extends JpaRepository<KmtExampaperArea, String> {


	Page<KmtExampaperArea> findAll(Specification<KmtExampaperArea> specification, Pageable sp);

	
	
	@Query(nativeQuery = true, value = " SELECT * from kmt_exampaper_area t where t.`subject`=?1 AND t.grade=?2 ORDER BY t.create_time asc ")
	public List<KmtExampaperArea> findByCourseNameAndGrad(String courseName, String grad);


	@Query(nativeQuery = true, value = " SELECT * from kmt_exampaper_area t where t.year=?1 AND t.city=?2 and t.area=?3 and t.school=?4 and t.semester=?5 and t.type=?6 and t.subject=?7 and t.grade = ?8 and t.add_str=?9 ")
	KmtExampaperArea findBeanByAnyThings(String year, String city, String area, String school, Integer semester,
                                         Integer type, String subject, String grade, String addStr);


	@Query(nativeQuery = true, value = "SELECT * from kmt_exampaper_area t where t.year=?1 AND t.city=?2 and t.area=?3 and t.school=?4 and t.semester=?5 and t.type=?6 and t.subject=?7 and t.grade = ?8  and t.add_str=?9  and t.id<>?10")
	KmtExampaperArea findBeanByAnyThings(String year, String city, String area, String school, Integer semester,
                                         Integer type, String subject, String grade, String addStr, String id);

	@Query(nativeQuery = true, value = "SELECT * from kmt_exampaper_area t where t.year=?1 AND  t.area=?2  and t.semester=?3 and t.type=?4 and t.subject=?5 and t.grade = ?6  ")
	List<KmtExampaperArea> findByCourseNameAndGradAndArea(String year, String area, String semester,
                                                          Integer type, String subject, String grade);
	@Query(nativeQuery = true, value = "SELECT * from kmt_exampaper_area t where t.year=?1 AND  t.area=?2  and t.semester=?3 and t.type=?4 and t.subject=?5 and t.grade = ?6 and  id not in (?7) ")
	List<KmtExampaperArea> findByCourseNameAndGradAndArea(String year, String area, String semester,
                                                          Integer type, String subject, String grade, List<String> ids);
	
	@Query(nativeQuery = true, value = "SELECT * from kmt_exampaper_area t where t.year=?1 AND  t.area=?2  and t.semester=?3 and t.type=?4 and t.subject=?5 and t.grade = ?6 and  id<>?7 ")
	List<KmtExampaperArea> findByCourseNameAndGradAndArea(String year, String area, String semester,
                                                          Integer type, String subject, String grade, String areaId);

	@Query(nativeQuery = true, value = "select t1.* from kmt_exampaper_area t1 left join kmt_exampaper t2 on t1.id=t2.area_id where question_id= ?1 limit 1")
	KmtExampaperArea findByQuestionId(String questionId);
}
