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

import com.ssj.bean.kmt.kmt.domain.KmtExampaperDetail;
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.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;


@Repository
public interface KmtExampaperDetailDao extends JpaRepository<KmtExampaperDetail, String>{

	@Query(nativeQuery = true, value = " SELECT * from kmt_exampaper_detail t where t.`status`=1 AND t.area_id=?1 ORDER BY t.sort_no asc ")
	public List<KmtExampaperDetail> findKmtExampaperDetails(String areaId);
	
	 @Query(nativeQuery = true, value = "select  *  from kmt_exampaper_detail  where p_id =?1 AND area_id=?2  order by  sort_no desc ")
	 List<KmtExampaperDetail>  getPidAndCodes(String pid, String areaId);
	 public Page<KmtExampaperDetail> findAll(Specification<KmtExampaperDetail> specification, Pageable page);
	 
	 @Query(nativeQuery = true, value = "update kmt_exampaper_detail set sort_no = ?2 where id =?1 ")
	 @Modifying
	 Integer updateSortNo(String id, int sortNo);
	 
	 @Query(nativeQuery = true, value = " SELECT * from kmt_exampaper_detail t where t.area_id=?1 AND t.question_id=?2  ")
	 List<KmtExampaperDetail> findKmtExampaperDetailsByQuId(String areaId, String quId);
	 
}
