package com.huimv.eartag.dao.repo;

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

    @Query(nativeQuery = true,value = "SELECT COUNT(*) total FROM eartag_eartag_register WHERE farm_id=?1 AND live_status=1")
    List<Object[]> getEartagCountByFarmId(String farmId);

    @Query(nativeQuery = true,value = "SELECT COUNT(*) total FROM eartag_eartag_register WHERE farm_id=?1 AND live_status=?2")
    List<Object[]> getEartagCountByFarmId(String farmId, Integer liveStatus);

    @Query(nativeQuery = true,value = "SELECT * FROM eartag_eartag_register WHERE farm_id=?2 AND earmark=?1")
    EartagEartagRegisterEntity getOneByEarmark(String earmark, String farmId);

    @Query(nativeQuery = true,value = "SELECT * FROM eartag_eartag_register WHERE earmark=?1 LIMIT 1")
    EartagEartagRegisterEntity getEartagByEarmark(String earmark);

}