package com.ssj.dao.sys.parent.dao;
import com.ssj.bean.sys.parent.domain.SSJTermtrainQuestion;
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 SSJTermtrainQuestionDao extends JpaRepository<SSJTermtrainQuestion, String> {

    @Query(nativeQuery = true, value = "select DISTINCT book_name from ssj_termtrain_question where course_name = ?1 and grade = ?2")
    List<String> findDistinctBookName(String courseName, String grade);

    @Query(nativeQuery = true, value = "select * from ssj_termtrain_question where course_name = ?1 and grade = ?2 and book_name = ?3 group by province")
    List<SSJTermtrainQuestion> findDistinctProvince(String courseName, String grade, String bookName);

    @Query(nativeQuery = true, value = "select * from ssj_termtrain_question " +
            "where course_name = ?1 and grade = ?2 and book_name = ?3 and province = ?4 group by city")
    List<SSJTermtrainQuestion> findDistinctCity(String courseName, String grade, String bookName, String province);

    @Query(nativeQuery = true, value = "select * from ssj_termtrain_question " +
            "where course_name = ?1 and grade = ?2 and book_name = ?3 and province = ?4 and city = ?5 group by area")
    List<SSJTermtrainQuestion> findDistinctArea(String courseName, String grade, String bookName, String province, String city);

    @Query(nativeQuery = true, value = "select * from ssj_termtrain_question " +
            "where course_name = ?1 and grade = ?2 and book_name = ?3 and province = ?4 and city = ?5 and area = ?6 group by `year`")
    List<SSJTermtrainQuestion> findDistinctYear(String courseName, String grade, String bookName, String province, String city, String area);

    List<SSJTermtrainQuestion> findByCourseNameAndGradeAndBookNameAndProvinceAndCityAndAreaAndYear(String courseName, String grade, String bookName, String province, String city, String area, String year);


    Page<SSJTermtrainQuestion> findAll(Specification<SSJTermtrainQuestion> specification, Pageable page);
}
