package com.huimv.produce.produce.repo;

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 ProdDayWeightRepo extends JpaRepository<ProdDayWeightEntity, Integer>, JpaSpecificationExecutor<ProdDayWeightEntity> {
    //
    @Query(nativeQuery = true,value = "SELECT * FROM prod_day_weight WHERE farm_id=?1 AND DATE_FORMAT(add_time,'%Y-%m-%d') >= DATE_FORMAT(?2,'%Y-%m-%d') AND DATE_FORMAT(add_time,'%Y-%m-%d') <= DATE_FORMAT(?3,'%Y-%m-%d')")
    List<ProdDayWeightEntity> findByFarmIdAndStartAndEndDate(Integer farmId, String startDate, String endDate);

    //
    @Query(nativeQuery = true,value = "SELECT * FROM prod_day_weight WHERE farm_id=?1 ORDER BY id DESC LIMIT ?2")
    List<ProdDayWeightEntity> findByFarmIdAndDays(Integer farmId, Integer days);
}