package com.yihu.wlyy.repository.doctor;

import com.yihu.wlyy.entity.doctor.survey.SurveyQuestionnaire;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

import java.util.List;

/**
 * Created by Reece on 2017/3/10.
 */
public interface SurveyQuestionnaireDao extends PagingAndSortingRepository<SurveyQuestionnaire, Long> {
    @Query("select  t from SurveyQuestionnaire t where t.surveyCode = ?1")
    List<SurveyQuestionnaire> findById(String id);

    @Query("select  t from SurveyQuestionnaire t where t.surveyCode = ?1")
    List<SurveyQuestionnaire> findById(String id, Pageable request);

    @Query("select  t from SurveyQuestionnaire t where t.surveyCode = ?1 and t.code = ?2")
    SurveyQuestionnaire findByIdAndQstId(String id, String questionId);

    @Query("select  t from SurveyQuestionnaire t where t.surveyCode = ?1 and t.sort = ?2")
    SurveyQuestionnaire findByIdAndSort(String id, int sort);

    @Query("select  max(t.sort) from SurveyQuestionnaire t where t.surveyCode = ?1 ")
    int findTotalById(String id);

    @Query("select t from SurveyQuestionnaire t where t.surveyCode = ?1 and t.sort = ?2 ")
    SurveyQuestionnaire findTotalByIdAndSort(String id, int sort);

}
