package com.yihu.wlyy.repository.doctor;

import com.yihu.wlyy.entity.doctor.survey.SurveyUser;
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 Reece on 2017/3/9.
 */
public interface SurveyUserDao extends PagingAndSortingRepository<SurveyUser, Long> {
    @Query("select t.patient from SurveyUser t where t.status=?1")
    List<Object> findByStatus(int status);

    @Query("select  t.status from SurveyUser t where t.patient = ?1 and t.surveyCode = ?2 ")
    int findByPatient(String patient, String surveyId);

    @Query("select  count(t.patient) from SurveyUser t where t.surveyCode = ?1 and t.status!=0  ")
    int findBySurveyCode(String surveyId);

    @Query("select t.patient from SurveyUser t where t.surveyCode=?1 and t.status = 0 and t.isWork = 1  ")
    List<String> findBySurveyCodeAndStatus(String id);

    @Modifying
    @Query("update SurveyUser t set t.status = 1 where t.surveyCode=?1 and t.patient = ?2 ")
    void modifyStatus(String id,String  patient);

}
