/*******************************************************************************
 * Copyright (c) 2005, 2014 springside.github.io
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 *******************************************************************************/
package com.yihu.wlyy.repository.followup;

import java.util.List;

import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

import com.yihu.wlyy.entity.follow.FollowUpItemRecordAnswer;

public interface FollowUpItemRecordAnswerDao extends
		PagingAndSortingRepository<FollowUpItemRecordAnswer, Long>,
		JpaSpecificationExecutor<FollowUpItemRecordAnswer> {

	List<FollowUpItemRecordAnswer> findByItemAndRecord(String item, String record);

	@Query("select a from FollowUpItemRecordAnswer a where a.question = ?1 ")
	List<FollowUpItemRecordAnswer> getFollowUpItemRecordAnswerByQuestionCode(
			String code);
	
	List<FollowUpItemRecordAnswer> findByItemOrderByCzrqDesc(String item);

	@Query("select DISTINCT(a.question) from FollowUpItemRecordAnswer a where a.record = ?1 ")
	List<FollowUpItemRecordAnswer> findByRecordDistinQuestion(String recordCode);

	@Query("select a from FollowUpItemRecordAnswer a where a.question = ?1 and a.type= 2 and a.index= ?2")
	List<FollowUpItemRecordAnswer> getFollowUpItemRecordAnswerByQuestionCodeAndTypeAndIndex(
			String code, int type);

	@Query("select a from FollowUpItemRecordAnswer a where a.question = ?1 ")
	List<FollowUpItemRecordAnswer> findbyQuestion(String question);

	@Query("select a from FollowUpItemRecordAnswer a where a.record = ?1 and a.question=?2")
	List<FollowUpItemRecordAnswer> findByRecordCodeAndQuestion(String recoredCode,String questionCode);

}
