package com.huimv.produce.warning.dao.repo;

import com.huimv.produce.warning.dao.entity.FarmDeviceEntity;
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 FarmDeviceRepo extends JpaRepository<FarmDeviceEntity, Integer>, JpaSpecificationExecutor<FarmDeviceEntity> {

    //
    @Query(nativeQuery = true,value = "SELECT COUNT(*) AS total FROM farm_device WHERE farm_id=?1")
    List<Object[]> findDeviceTotal(Integer farmId);

    //
    @Query(nativeQuery = true,value = "SELECT COUNT(*) AS num FROM farm_device WHERE farm_id=?1 AND state=?2")
    List<Object[]> findFailureDeviceTotal(Integer farmId, Integer failureState);
}