package com.yihu.wlyy.repository.doctor;

import com.yihu.wlyy.entity.doctor.survey.SurveyTemplates;
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.Date;
import java.util.List;

/**
 * Created by Reece on 2017/3/9.
 */
public interface SurveyTemplatesDao extends PagingAndSortingRepository<SurveyTemplates, Long> {
    @Query("select  t from SurveyTemplates t where t.del = 1 ")
    List<SurveyTemplates> findAlls(Pageable request);

    @Query("select  distinct t from SurveyTemplates t where t.title like?1 ")
    List<SurveyTemplates> findByTitle(String title, Pageable request);

    @Query("select count(t.id)  from SurveyTemplates t where t.title = ?1 ")
    int distinctByTitle(String title);

    @Query("select count(t.id)  from SurveyTemplates t where t.title like ?1 ")
    int distinctLikeTitle(String title);

    @Query("select  t from SurveyTemplates t where t.code = ?1 ")
    SurveyTemplates findById(String code);

    @Modifying
    @Query("update SurveyTemplates t set t.title=?2 ,t.templateComment=?3 where t.code=?1 ")
    void modifyTemplate(String templateCode, String title, String templateComment);

}
