This commit is contained in:
2024-03-26 23:36:18 +08:00
parent dc83fa2be8
commit 4627a798fa
2 changed files with 4 additions and 3 deletions

View File

@@ -6,6 +6,7 @@ import cn.lihongjie.coal.emDevice.entity.EmDeviceEntity;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import java.time.LocalDateTime;
import java.util.List;
@Repository
@@ -14,7 +15,7 @@ public interface EmDeviceRepository extends BaseRepository<EmDeviceEntity> {
value =
"select d.id\n"
+ "from t_em_device d\n"
+ "where (select max(time) from t_em_device_data data where data.device_id = d.id) + (d.\"interval\" * interval '1 minute') >= now()",
+ "where (select max(time) from t_em_device_data data where data.device_id = d.id) + (d.\"interval\" * interval '1 minute') <= :now",
nativeQuery = true)
List<String> findNeedToFetchDevice();
List<String> findNeedToFetchDevice(LocalDateTime now);
}

View File

@@ -250,7 +250,7 @@ public class EmDeviceService extends BaseService<EmDeviceEntity, EmDeviceReposit
try {
List<String> ids = this.repository.findNeedToFetchDevice();
List<String> ids = this.repository.findNeedToFetchDevice(LocalDateTime.now());
if (CollectionUtils.isEmpty(ids)) {
log.info("no need to fetch data");