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

import com.yihu.figure.model.health.HealthIndex;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

import java.util.Date;
import java.util.List;

public interface HealthIndexDao extends PagingAndSortingRepository<HealthIndex, Long> {

	@Query("select p from HealthIndex p where p.user = ?1")
	List<HealthIndex> findByUser(String user);

	@Query(value = "select * from wlyy_health_index where user=?1 and type =?2 and record_date between ?3 and ?4 order by record_date desc limit 0,1",nativeQuery = true)
	HealthIndex findByPatientAndType(String patient,String type,String startTime,String endTime);

	@Query("select p from HealthIndex p where p.user = ?1 and p.type=?2 and p.recordDate between ?3 and ?4 order by p.recordDate desc")
	List<HealthIndex> findByUserAndRecordDate(String patient,Integer type, Date startTime,Date endTime);
}
