Browse Source

fixed queries for get/count devices without ota

pull/11459/head
YevhenBondarenko 2 years ago
parent
commit
3eb760e648
  1. 14
      dao/src/main/java/org/thingsboard/server/dao/sql/device/DeviceRepository.java
  2. 5
      dao/src/main/java/org/thingsboard/server/dao/sql/device/JpaDeviceDao.java

14
dao/src/main/java/org/thingsboard/server/dao/sql/device/DeviceRepository.java

@ -83,33 +83,27 @@ public interface DeviceRepository extends JpaRepository<DeviceEntity, UUID>, Exp
@Query("SELECT d FROM DeviceEntity d WHERE d.tenantId = :tenantId " +
"AND d.deviceProfileId = :deviceProfileId " +
"AND d.firmwareId = null " +
"AND (:textSearch IS NULL OR ilike(d.name, CONCAT('%', :textSearch, '%')) = true " +
"OR ilike(d.label, CONCAT('%', :textSearch, '%')) = true)")
"AND d.firmwareId IS NULL")
Page<DeviceEntity> findByTenantIdAndTypeAndFirmwareIdIsNull(@Param("tenantId") UUID tenantId,
@Param("deviceProfileId") UUID deviceProfileId,
@Param("textSearch") String textSearch,
Pageable pageable);
@Query("SELECT d FROM DeviceEntity d WHERE d.tenantId = :tenantId " +
"AND d.deviceProfileId = :deviceProfileId " +
"AND d.softwareId = null " +
"AND (:textSearch IS NULL OR ilike(d.name, CONCAT('%', :textSearch, '%')) = true " +
"OR ilike(d.label, CONCAT('%', :textSearch, '%')) = true)")
"AND d.softwareId IS NULL")
Page<DeviceEntity> findByTenantIdAndTypeAndSoftwareIdIsNull(@Param("tenantId") UUID tenantId,
@Param("deviceProfileId") UUID deviceProfileId,
@Param("textSearch") String textSearch,
Pageable pageable);
@Query("SELECT count(*) FROM DeviceEntity d WHERE d.tenantId = :tenantId " +
"AND d.deviceProfileId = :deviceProfileId " +
"AND d.firmwareId = null")
"AND d.firmwareId IS NULL")
Long countByTenantIdAndDeviceProfileIdAndFirmwareIdIsNull(@Param("tenantId") UUID tenantId,
@Param("deviceProfileId") UUID deviceProfileId);
@Query("SELECT count(*) FROM DeviceEntity d WHERE d.tenantId = :tenantId " +
"AND d.deviceProfileId = :deviceProfileId " +
"AND d.softwareId = null")
"AND d.softwareId IS NULL")
Long countByTenantIdAndDeviceProfileIdAndSoftwareIdIsNull(@Param("tenantId") UUID tenantId,
@Param("deviceProfileId") UUID deviceProfileId);

5
dao/src/main/java/org/thingsboard/server/dao/sql/device/JpaDeviceDao.java

@ -179,10 +179,9 @@ public class JpaDeviceDao extends JpaAbstractDao<DeviceEntity, Device> implement
OtaPackageType type,
PageLink pageLink) {
Pageable pageable = DaoUtil.toPageable(pageLink);
String searchText = pageLink.getTextSearch();
Page<DeviceEntity> page = OtaPackageUtil.getByOtaPackageType(
() -> deviceRepository.findByTenantIdAndTypeAndFirmwareIdIsNull(tenantId, deviceProfileId, searchText, pageable),
() -> deviceRepository.findByTenantIdAndTypeAndSoftwareIdIsNull(tenantId, deviceProfileId, searchText, pageable),
() -> deviceRepository.findByTenantIdAndTypeAndFirmwareIdIsNull(tenantId, deviceProfileId, pageable),
() -> deviceRepository.findByTenantIdAndTypeAndSoftwareIdIsNull(tenantId, deviceProfileId, pageable),
type
);
return DaoUtil.toPageData(page);

Loading…
Cancel
Save