package cn.lihongjie.coal.dataCollector.repository;

import cn.lihongjie.coal.base.dao.BaseRepository;
import cn.lihongjie.coal.dataCollector.entity.DataCollectorEntity;

import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface DataCollectorRepository extends BaseRepository<DataCollectorEntity> {
    DataCollectorEntity findByAppKey(String appKey);

    @Query("""
            select exists(
            
            
            select 1 from AcDeviceEntity e where e.dataCollector.id in :ids
            
            union all
            
            select 1 from WeightDeviceEntity e where e.dataCollector.id in :ids
            
                   union all
            
            select 1 from PdcDeviceEntity e where e.dataCollector.id in :ids
            
            
            
            )
            
            
            
            
            
            """)
    boolean isLinked(@Param("ids") List<String> ids);
}
