package com.yihu.wlyy.repository.template;

import com.yihu.wlyy.entity.template.DoctorGuidanceTemp;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

import java.util.List;

/**
 * Created by lyr-pc on 2017/2/3.
 */
public interface DoctorGuidanceTempDao extends PagingAndSortingRepository<DoctorGuidanceTemp, Long> {

    DoctorGuidanceTemp findByCode(String code);

    int deleteByCode(String code);

    @Query("select t from DoctorGuidanceTemp t where t.owner = ?1 order by t.sendTimes desc")
    Page<DoctorGuidanceTemp> findByOwner(String owner, Pageable pageRequest);
//    Page<List<DoctorGuidanceTemp>> findByOwner(String owner, Pageable pageRequest);

    @Query("select t from DoctorGuidanceTemp t where t.owner = ?1 or t.owner = 'system' order by t.sendTimes desc")
    Page<DoctorGuidanceTemp> findByOwnerAndSystem(String owner, Pageable pageRequest);
    //    Page<List<DoctorGuidanceTemp>> findByOwnerAndSystem(String owner, Pageable pageRequest);

    //验证医生健康指导模板标题是否重复
    @Query("select t from DoctorGuidanceTemp t where t.owner = ?1 and t.modelName = ?2 ")
    List<DoctorGuidanceTemp> findByTitle(String owner,String title);
}
