package com.ssj.dao.course.dao;

import java.util.List;

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 com.ssj.bean.course.domain.CourseSeriesDetail;


@Repository
public interface ICSDetailDao extends JpaRepository<CourseSeriesDetail, String> {

	Page<CourseSeriesDetail> findAll(Specification<CourseSeriesDetail> specification, Pageable initPage);
	
	@Query(nativeQuery = true, value = " SELECT * from  tb_course_series_details  s where s.series_id  =?1 and s.state=1 order by  course_index asc  ,create_time asc ")
	public List<CourseSeriesDetail> findBySeriesId(String seriesId);
	
	@Query(nativeQuery = true, value = " SELECT COUNT(1) from  tb_course_series_details  s where s.series_id  =?1 and s.state=1  ")
	public Integer findBySeriesIdCount(String seriesId);
	
	
	@Query(nativeQuery = true, value = " SELECT * from  tb_course_series_details  s where s.series_id  =?1 and s.state=1 AND s.course_index>=?2 ORDER BY s.course_index asc LIMIT 1 ")
	public CourseSeriesDetail getCourseSeriesDetailByCourseIndex(String seriesId,Integer courseIndex);

	@Query(nativeQuery = true, value = " SELECT * from  tb_course_series_details  s where s.series_id  =?1 and s.state=1 and course_index>=?2  order by  course_index asc  ,create_time asc ")
	List<CourseSeriesDetail> findBySeriesIdAndAfterIndex(String seriesId, Integer courseIndex);

}
