/*******************************************************************************
 * 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.domain.Page;
import org.springframework.data.domain.Pageable;
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.FollowUpSummary;

public interface FollowUpSummaryDao extends PagingAndSortingRepository<FollowUpSummary, Long>, JpaSpecificationExecutor<FollowUpSummary> {

	@Query("select p from FollowUpSummary p where p.plan = ?1 and p.type=1 order by czrq desc")
	List<FollowUpSummary> findByPlanCode(String planCode);

	@Query("select p from FollowUpSummary p where p.item = ?1 and p.type=3 order by czrq desc")
	List<FollowUpSummary> findByItemCode(String code);

	FollowUpSummary findByRecordAndType(String record, int type);

	FollowUpSummary findByItemAndType(String item, int type);

	FollowUpSummary findByStageAndType(String stage, int type);

	FollowUpSummary findByPlanAndType(String plan, int type);

	@Query("select a from FollowUpSummary a where a.item=?1 and  a.id < ?2  order by  a.czrq desc")
	Page<FollowUpSummary> findByItemCode(String itemCode, long id, Pageable pageRequest);

	@Query("select a from FollowUpSummary a where a.item=?1  order by  a.czrq desc")
	Page<FollowUpSummary> findByItemCode(String itemCode, Pageable pageRequest);

	@Query("select p from FollowUpSummary p where p.plan = ?1 and ( p.type=1 or  p.type=2 )order by czrq desc")
	List<FollowUpSummary> findByPlanCodeAndType(String planCode);

}
