package com.huimv.eartag.dao.repo;

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

    //
    @Query(nativeQuery = true,value = "SELECT * FROM eartag_device_eartag_count WHERE device_code=?1 AND DATE_FORMAT(create_date,'%Y-%m-%d')=DATE_FORMAT(?2,'%Y-%m-%d')")
    List<EartagDeviceEartagCountEntity> getOnlineEartagByDeviceCode(String deviceCode, String todayDateText);

    //
    @Query(nativeQuery = true,value = "SELECT * FROM eartag_device_eartag_count WHERE earmark=?1 AND DATE_FORMAT(create_date,'%Y-%m-%d')=DATE_FORMAT(?2,'%Y-%m-%d')")
    List<EartagDeviceEartagCountEntity> getOnlineEartagDeviceByEarmarkAndAddDate(String earmark, String addDate);

    //
    @Query(nativeQuery = true,value = "SELECT * FROM eartag_device_eartag_count WHERE earmark=?1 AND device_code=?2 AND DATE_FORMAT(create_date,'%Y-%m-%d')=DATE_FORMAT(?3,'%Y-%m-%d')")
    List<EartagDeviceEartagCountEntity> getEartagDeviceCount(String earmark, String deviceCode, String todayDateText);
}