package com.huimv.eartag.dao.repo;

import com.huimv.eartag.dao.entity.EartagEartagOnlineEntity;
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 EartagEartagOnlineRepo extends JpaRepository<EartagEartagOnlineEntity, Integer>, JpaSpecificationExecutor<EartagEartagOnlineEntity> {

    /**
     * @Method      : getOneByEarmarkAndFarmId
     * @Description : 
     * @Params      : [earmark, todayDateText, farmId]
     * @Return      : com.huimv.eartag2.common.dao.entity.EartagEartagOnlineEntity
     * 
     * @Author      : ZhuoNing
     * @Date        : 2022/3/2       
     * @Time        : 16:09
     */
    @Query(nativeQuery = true,value = "SELECT * FROM eartag_eartag_online WHERE earmark=?1 AND DATE_FORMAT(add_date,'%Y-%m-%d')=DATE_FORMAT(?2,'%Y-%m-%d') AND farm_id=?3")
    EartagEartagOnlineEntity getOneByEarmarkAndFarmId(String earmark, String todayDateText, String farmId);

    /**
     * @Method      : getEartagOnlineByEarmarkAndDate
     * @Description : 
     * @Params      : [earmark, startDateText, todayDateText]
     * @Return      : java.util.List<com.huimv.eartag2.common.dao.entity.EartagEartagOnlineEntity>
     * 
     * @Author      : ZhuoNing
     * @Date        : 2022/3/8       
     * @Time        : 18:43
     */
    @Query(nativeQuery = true,value = "SELECT * FROM eartag_eartag_online WHERE earmark=?1 AND add_date BETWEEN DATE_FORMAT(?2,'%Y-%m-%d') AND DATE_FORMAT(?3,'%Y-%m-%d') ORDER BY add_date ASC")
    List<EartagEartagOnlineEntity> getEartagOnlineByEarmarkAndDate(String earmark, String startDateText, String todayDateText);

    /**
     * @Method      : getEartagOnlineByFarmIdAndDate
     * @Description : 
     * @Params      : [farmId, addDate]
     * @Return      : java.util.List<com.huimv.eartag2.common.dao.entity.EartagEartagOnlineEntity>
     * 
     * @Author      : ZhuoNing
     * @Date        : 2022/3/10       
     * @Time        : 21:58
     */
    @Query(nativeQuery = true,value = "SELECT * FROM eartag_eartag_online WHERE farm_id=?1 AND DATE_FORMAT(add_date,'%Y-%m-%d')=DATE_FORMAT(?2,'%Y-%m-%d') ORDER BY add_date ASC")
    List<EartagEartagOnlineEntity> getEartagOnlineByFarmIdAndDate(String farmId, String addDate);

    @Query(nativeQuery = true,value = "SELECT * FROM eartag_eartag_online WHERE earmark=?1 AND add_date BETWEEN DATE_FORMAT(?2,'%Y-%m-%d') AND DATE_FORMAT(?3,'%Y-%m-%d') ORDER BY add_date DESC")
    List<EartagEartagOnlineEntity> getEartagOnlineRecordsByEarmarkAndDate(String earmark, String startDateText, String todayDateText);

//    @Query(nativeQuery = true,value = "SELECT * FROM eartag_eartag_online WHERE farm_id=?1 AND add_date = DATE_FORMAT(,'%Y-%m-%d')=DATE_FORMAT(?2,'%Y-%m-%d') ORDER BY add_date ASC")
//    List<EartagEartagOnlineEntity> getEartagOnlineByEarmarkAndStartDateAndEndDate(String earmark, String todayDateText, String startDateText);
}