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

import com.ssj.bean.kmt.kmt.domain.KmtQuestionKnow;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface KmtQuestionKnowDao extends JpaRepository<KmtQuestionKnow, String> {
	
	@Query(nativeQuery = true, value = " SELECT * from kmt_question_know t where t.question_id=?1 AND t.how_details_id=?2 ")
	public List<KmtQuestionKnow> findQuestionByTitle(String questionId, String howDetailsId);
	
	@Query(nativeQuery = true, value = " SELECT * from kmt_question_know t where t.question_id=?1 ")
	public List<KmtQuestionKnow> findQuByList(String questionId);
	
	@Query(nativeQuery = true, value = " SELECT * from kmt_question_know t where t.how_details_id=?1 AND t.question_id=?2 AND t.how_details_kd_id=?3 LIMIT 1 ")
	public KmtQuestionKnow findQuByHowKdList(String howDetailsId, String questionId, String howDetailsKdId);
	
	@Query(nativeQuery = true, value = " SELECT * from kmt_question_know t where t.how_details_id=?1 AND t.question_id=?2 LIMIT 1 ")
	public KmtQuestionKnow findQuByHowKdList(String howDetailsId, String questionId);
	
	@Modifying
	@Query(nativeQuery = true, value = " UPDATE kmt_question_know t SET t.is_load=1 where t.course_name='数学' and t.last_update_time = current_timestamp ()")
	public void updateFULLIsLoad();
	
	@Modifying
	@Query(nativeQuery = true, value = " UPDATE kmt_question_know t SET t.is_load=?1 where t.course_name='数学' and t.id in (?2) and t.last_update_time = current_timestamp()")
	public void updateFULLNotIsLoadByIds(Integer isLoad, List<String> ids);
	
	
	@Query(nativeQuery = true, value = "  SELECT * from kmt_question_know t where  t.how_details_kd_id=?1 ORDER BY t.create_time asc ")
	public List<KmtQuestionKnow> findHowDetailsKdId(String howDetailsKdId);
	
	
	@Query(nativeQuery = true, value = "  SELECT * from kmt_question_know t where t.how_details_kd_id=?1 AND  t.question_id=?2  ORDER BY t.create_time asc ")
	public List<KmtQuestionKnow> findHowDetailsKdIdAndQuestionId(String howDetailsKdId, String questionId);
	

}
