package com.huimv.eartag.dao.repo;

import com.huimv.eartag.dao.entity.EartarFarmAllStatusEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface EartarFarmAllStatusRepo extends JpaRepository<EartarFarmAllStatusEntity, Integer>, JpaSpecificationExecutor<EartarFarmAllStatusEntity> {

    @Query(nativeQuery = true,value = "SELECT * FROM eartar_farm_all_status WHERE farm_id=?1 AND DATE_FORMAT(create_date,'%Y-%m-%d')=DATE_FORMAT(?2,'%Y-%m-%d')")
    EartarFarmAllStatusEntity getOneByFarmIdAndCreateDate(String farmId, String todayDateText);

    @Query(nativeQuery = true,value = "SELECT * FROM eartar_farm_all_status WHERE farm_id=?1 AND create_date BETWEEN DATE_FORMAT(?2,'%Y-%m-%d') AND DATE_FORMAT(?3,'%Y-%m-%d') ORDER BY create_date ASC")
    List<EartarFarmAllStatusEntity> getOneByFarmIdAndCreateDateAndPastDate(String farmId, String pastDate, String todayDate);
}