package com.huimv.environ.env.environ.dao.repo;

import com.huimv.environ.env.environ.dao.entity.EnvDayEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

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

public interface EnvDayRepo extends JpaRepository<EnvDayEntity, Integer>, JpaSpecificationExecutor<EnvDayEntity> {

    //
    @Query(nativeQuery = true,value ="SELECT * FROM env_day where farm_id=?1 AND  DATE_FORMAT(add_date,'%Y-%m-%d')<=DATE_FORMAT(?2,'%Y-%m-%d') ORDER BY add_date DESC LIMIT ?3")
    List<EnvDayEntity> findByFarmIdAndAddDate_0(Integer farmId, Date todayDate, Integer days);

    @Query(nativeQuery = true,value ="SELECT * FROM env_day where farm_id=?1 ORDER BY add_date DESC LIMIT ?2")
    List<EnvDayEntity> findByFarmIdAndAddDate(Integer farmId, Integer days);
}