package com.ssj.dao.course.dao;

import com.ssj.bean.course.domain.CourseSeriesDetailFeedback;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;


/** 
 * @author  ZhangCaibao 
 * @version 2018年10月19日 上午10:00:18 
 * 类说明 
 */
@Repository
public interface CourseSeriesDetailFeedbackDao extends  JpaRepository<CourseSeriesDetailFeedback, String> {

	 @Query(nativeQuery = true,value="SELECT  ROUND(avg(k.pleased_score),1) ,count(1)\n" +
			 " from  tb_course_series_details_feedback  k \n" +
			 "where k.course_series_id =?1 and k.pleased_score is not null")
	List<Object[]> getCourseScore(String courseSeriesId);
	@Query(nativeQuery = true,value="SELECT  ROUND(avg(k.pleased_score),1) ,count(1)\n" +
			" from  tb_course_series_details_feedback  k \n" +
			"where k.course_series_id =?1 and k.lib_id =?2 and k.pleased_score is not null")
	List<Object[]> getCourseScore(String courseSeriesId,String libId);
	
	@Query(nativeQuery = true,value=" SELECT * from tb_course_series_details_feedback t where t.course_details_id=?1 ORDER BY t.create_time DESC LIMIT 1 ")
	CourseSeriesDetailFeedback getFeedbackByDetailsId(String courseDetailsId);

	@Query(nativeQuery = true,value=" SELECT * from tb_course_series_details_feedback t where t.course_details_id=?1 and vip_id=?2 LIMIT 1 ")
	CourseSeriesDetailFeedback findyDetailIdAndVipId(String courseDetailId, String vipId);
	
	@Query(nativeQuery = true,value=" SELECT * from tb_course_series_details_feedback t where t.lib_feedback_id=?1 and vip_id=?2 LIMIT 1 ")
	CourseSeriesDetailFeedback findyDetailIdAndLibFeedbackId(String libFeedbackId, String vipId);
	
	
}
