package com.yihu.wlyy.repository.patient;

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.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

import com.yihu.wlyy.entity.patient.PatientHealthRecordDiet;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.Date;

public interface PatientHealthRecordDietDao extends PagingAndSortingRepository<PatientHealthRecordDiet, Long>, JpaSpecificationExecutor<PatientHealthRecordDiet> {

    // 查询患者标识健康记录
    @Query("select a from PatientHealthRecordDiet a where a.patient = ?1 and a.del = '1'")
    Iterable<PatientHealthRecordDiet> findByPatient(String patient);

    // 查询最近的健康记录
    @Query("SELECT a FROM PatientHealthRecordDiet a WHERE a.patient = ?1 and a.del = '1' ORDER BY a.czrq DESC")
    Page<PatientHealthRecordDiet> findRecentByPatient(String patient, Pageable pageRequest);

    @Query("SELECT a FROM PatientHealthRecordDiet a WHERE a.patient = ?1 and a.recordDate >= ?2 and a.recordDate <= ?3 and a.del = '1' ORDER BY a.recordDate DESC")
    Page<PatientHealthRecordDiet> findDietByPatient(String patient, Date start, Date end, Pageable pageRequest);

    //	修改饮食记录
    @Modifying
    @Query("update PatientHealthRecordDiet a set a.recordDate = ?2,a.content = ?3,a.images= ?4 where a.id= ?1 ")
    void modifyDiet(long id,Date value1, String value2, String value3);

    //	删除饮食记录
    @Modifying
    @Query("update PatientHealthRecordDiet a set a.del = 0 where a.id= ?1 ")
    void deleteDiet(long id);
}
