Browse Source

Updated queries

pull/8090/head
zbeacon 4 years ago
parent
commit
37bc889f11
  1. 21
      dao/src/main/java/org/thingsboard/server/dao/sql/alarm/AlarmRepository.java
  2. 8
      dao/src/main/java/org/thingsboard/server/dao/sql/alarm/JpaAlarmDao.java

21
dao/src/main/java/org/thingsboard/server/dao/sql/alarm/AlarmRepository.java

@ -15,7 +15,6 @@
*/ */
package org.thingsboard.server.dao.sql.alarm; package org.thingsboard.server.dao.sql.alarm;
import org.hibernate.type.UUIDCharType;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
@ -51,7 +50,7 @@ public interface AlarmRepository extends JpaRepository<AlarmEntity, UUID> {
"AND (:startTime IS NULL OR (a.createdTime >= :startTime AND ea.createdTime >= :startTime)) " + "AND (:startTime IS NULL OR (a.createdTime >= :startTime AND ea.createdTime >= :startTime)) " +
"AND (:endTime IS NULL OR (a.createdTime <= :endTime AND ea.createdTime <= :endTime)) " + "AND (:endTime IS NULL OR (a.createdTime <= :endTime AND ea.createdTime <= :endTime)) " +
"AND ((:alarmStatuses) IS NULL OR a.status in (:alarmStatuses)) " + "AND ((:alarmStatuses) IS NULL OR a.status in (:alarmStatuses)) " +
"AND (cast(:assigneeId as org.hibernate.type.UUIDCharType) IS NULL OR a.assigneeId = (:assigneeId)) " + "AND (:assigneeId IS NULL OR a.assigneeId = uuid(:assigneeId)) " +
"AND (LOWER(a.type) LIKE LOWER(CONCAT('%', :searchText, '%')) " + "AND (LOWER(a.type) LIKE LOWER(CONCAT('%', :searchText, '%')) " +
" OR LOWER(a.severity) LIKE LOWER(CONCAT('%', :searchText, '%')) " + " OR LOWER(a.severity) LIKE LOWER(CONCAT('%', :searchText, '%')) " +
" OR LOWER(a.status) LIKE LOWER(CONCAT('%', :searchText, '%'))) " " OR LOWER(a.status) LIKE LOWER(CONCAT('%', :searchText, '%'))) "
@ -67,7 +66,7 @@ public interface AlarmRepository extends JpaRepository<AlarmEntity, UUID> {
"AND (:startTime IS NULL OR (a.createdTime >= :startTime AND ea.createdTime >= :startTime)) " + "AND (:startTime IS NULL OR (a.createdTime >= :startTime AND ea.createdTime >= :startTime)) " +
"AND (:endTime IS NULL OR (a.createdTime <= :endTime AND ea.createdTime <= :endTime)) " + "AND (:endTime IS NULL OR (a.createdTime <= :endTime AND ea.createdTime <= :endTime)) " +
"AND ((:alarmStatuses) IS NULL OR a.status in (:alarmStatuses)) " + "AND ((:alarmStatuses) IS NULL OR a.status in (:alarmStatuses)) " +
"AND (cast(:assigneeId as org.hibernate.type.UUIDCharType) IS NULL OR a.assigneeId = (:assigneeId)) " + "AND (:assigneeId IS NULL OR a.assigneeId = uuid(:assigneeId)) " +
"AND (LOWER(a.type) LIKE LOWER(CONCAT('%', :searchText, '%')) " + "AND (LOWER(a.type) LIKE LOWER(CONCAT('%', :searchText, '%')) " +
" OR LOWER(a.severity) LIKE LOWER(CONCAT('%', :searchText, '%')) " + " OR LOWER(a.severity) LIKE LOWER(CONCAT('%', :searchText, '%')) " +
" OR LOWER(a.status) LIKE LOWER(CONCAT('%', :searchText, '%'))) ") " OR LOWER(a.status) LIKE LOWER(CONCAT('%', :searchText, '%'))) ")
@ -77,7 +76,7 @@ public interface AlarmRepository extends JpaRepository<AlarmEntity, UUID> {
@Param("startTime") Long startTime, @Param("startTime") Long startTime,
@Param("endTime") Long endTime, @Param("endTime") Long endTime,
@Param("alarmStatuses") Set<AlarmStatus> alarmStatuses, @Param("alarmStatuses") Set<AlarmStatus> alarmStatuses,
@Param("assigneeId") UUID assigneeId, @Param("assigneeId") String assigneeId,
@Param("searchText") String searchText, @Param("searchText") String searchText,
Pageable pageable); Pageable pageable);
@ -88,7 +87,7 @@ public interface AlarmRepository extends JpaRepository<AlarmEntity, UUID> {
"AND (:startTime IS NULL OR a.createdTime >= :startTime) " + "AND (:startTime IS NULL OR a.createdTime >= :startTime) " +
"AND (:endTime IS NULL OR a.createdTime <= :endTime) " + "AND (:endTime IS NULL OR a.createdTime <= :endTime) " +
"AND ((:alarmStatuses) IS NULL OR a.status in (:alarmStatuses)) " + "AND ((:alarmStatuses) IS NULL OR a.status in (:alarmStatuses)) " +
"AND (cast(:assigneeId as org.hibernate.type.UUIDCharType) IS NULL OR a.assigneeId = (:assigneeId)) " + "AND (:assigneeId IS NULL OR a.assigneeId = uuid(:assigneeId)) " +
"AND (LOWER(a.type) LIKE LOWER(CONCAT('%', :searchText, '%')) " + "AND (LOWER(a.type) LIKE LOWER(CONCAT('%', :searchText, '%')) " +
" OR LOWER(a.severity) LIKE LOWER(CONCAT('%', :searchText, '%')) " + " OR LOWER(a.severity) LIKE LOWER(CONCAT('%', :searchText, '%')) " +
" OR LOWER(a.status) LIKE LOWER(CONCAT('%', :searchText, '%'))) ", " OR LOWER(a.status) LIKE LOWER(CONCAT('%', :searchText, '%'))) ",
@ -99,7 +98,7 @@ public interface AlarmRepository extends JpaRepository<AlarmEntity, UUID> {
"AND (:startTime IS NULL OR a.createdTime >= :startTime) " + "AND (:startTime IS NULL OR a.createdTime >= :startTime) " +
"AND (:endTime IS NULL OR a.createdTime <= :endTime) " + "AND (:endTime IS NULL OR a.createdTime <= :endTime) " +
"AND ((:alarmStatuses) IS NULL OR a.status in (:alarmStatuses)) " + "AND ((:alarmStatuses) IS NULL OR a.status in (:alarmStatuses)) " +
"AND (cast(:assigneeId as org.hibernate.type.UUIDCharType) IS NULL OR a.assigneeId = (:assigneeId)) " + "AND (:assigneeId IS NULL OR a.assigneeId = uuid(:assigneeId)) " +
"AND (LOWER(a.type) LIKE LOWER(CONCAT('%', :searchText, '%')) " + "AND (LOWER(a.type) LIKE LOWER(CONCAT('%', :searchText, '%')) " +
" OR LOWER(a.severity) LIKE LOWER(CONCAT('%', :searchText, '%')) " + " OR LOWER(a.severity) LIKE LOWER(CONCAT('%', :searchText, '%')) " +
" OR LOWER(a.status) LIKE LOWER(CONCAT('%', :searchText, '%'))) ") " OR LOWER(a.status) LIKE LOWER(CONCAT('%', :searchText, '%'))) ")
@ -107,7 +106,7 @@ public interface AlarmRepository extends JpaRepository<AlarmEntity, UUID> {
@Param("startTime") Long startTime, @Param("startTime") Long startTime,
@Param("endTime") Long endTime, @Param("endTime") Long endTime,
@Param("alarmStatuses") Set<AlarmStatus> alarmStatuses, @Param("alarmStatuses") Set<AlarmStatus> alarmStatuses,
@Param("assigneeId") UUID assigneeId, @Param("assigneeId") String assigneeId,
@Param("searchText") String searchText, @Param("searchText") String searchText,
Pageable pageable); Pageable pageable);
@ -118,7 +117,7 @@ public interface AlarmRepository extends JpaRepository<AlarmEntity, UUID> {
"AND (:startTime IS NULL OR a.createdTime >= :startTime) " + "AND (:startTime IS NULL OR a.createdTime >= :startTime) " +
"AND (:endTime IS NULL OR a.createdTime <= :endTime) " + "AND (:endTime IS NULL OR a.createdTime <= :endTime) " +
"AND ((:alarmStatuses) IS NULL OR a.status in (:alarmStatuses)) " + "AND ((:alarmStatuses) IS NULL OR a.status in (:alarmStatuses)) " +
"AND (cast(:assigneeId as org.hibernate.type.UUIDCharType) IS NULL OR a.assigneeId = (:assigneeId)) " + "AND (:assigneeId IS NULL OR a.assigneeId = uuid(:assigneeId)) " +
"AND (LOWER(a.type) LIKE LOWER(CONCAT('%', :searchText, '%')) " + "AND (LOWER(a.type) LIKE LOWER(CONCAT('%', :searchText, '%')) " +
" OR LOWER(a.severity) LIKE LOWER(CONCAT('%', :searchText, '%')) " + " OR LOWER(a.severity) LIKE LOWER(CONCAT('%', :searchText, '%')) " +
" OR LOWER(a.status) LIKE LOWER(CONCAT('%', :searchText, '%'))) " " OR LOWER(a.status) LIKE LOWER(CONCAT('%', :searchText, '%'))) "
@ -130,7 +129,7 @@ public interface AlarmRepository extends JpaRepository<AlarmEntity, UUID> {
"AND (:startTime IS NULL OR a.createdTime >= :startTime) " + "AND (:startTime IS NULL OR a.createdTime >= :startTime) " +
"AND (:endTime IS NULL OR a.createdTime <= :endTime) " + "AND (:endTime IS NULL OR a.createdTime <= :endTime) " +
"AND ((:alarmStatuses) IS NULL OR a.status in (:alarmStatuses)) " + "AND ((:alarmStatuses) IS NULL OR a.status in (:alarmStatuses)) " +
"AND (cast(:assigneeId as org.hibernate.type.UUIDCharType) IS NULL OR a.assigneeId = (:assigneeId)) " + "AND (:assigneeId IS NULL OR a.assigneeId = uuid(:assigneeId)) " +
"AND (LOWER(a.type) LIKE LOWER(CONCAT('%', :searchText, '%')) " + "AND (LOWER(a.type) LIKE LOWER(CONCAT('%', :searchText, '%')) " +
" OR LOWER(a.severity) LIKE LOWER(CONCAT('%', :searchText, '%')) " + " OR LOWER(a.severity) LIKE LOWER(CONCAT('%', :searchText, '%')) " +
" OR LOWER(a.status) LIKE LOWER(CONCAT('%', :searchText, '%'))) ") " OR LOWER(a.status) LIKE LOWER(CONCAT('%', :searchText, '%'))) ")
@ -139,7 +138,7 @@ public interface AlarmRepository extends JpaRepository<AlarmEntity, UUID> {
@Param("startTime") Long startTime, @Param("startTime") Long startTime,
@Param("endTime") Long endTime, @Param("endTime") Long endTime,
@Param("alarmStatuses") Set<AlarmStatus> alarmStatuses, @Param("alarmStatuses") Set<AlarmStatus> alarmStatuses,
@Param("assigneeId") UUID assigneeId, @Param("assigneeId") String assigneeId,
@Param("searchText") String searchText, @Param("searchText") String searchText,
Pageable pageable); Pageable pageable);
@ -150,7 +149,7 @@ public interface AlarmRepository extends JpaRepository<AlarmEntity, UUID> {
"AND ea.entityId = :affectedEntityId " + "AND ea.entityId = :affectedEntityId " +
"AND ea.entityType = :affectedEntityType " + "AND ea.entityType = :affectedEntityType " +
"AND ((:alarmStatuses) IS NULL OR a.status in (:alarmStatuses)) " + "AND ((:alarmStatuses) IS NULL OR a.status in (:alarmStatuses)) " +
"AND (cast(:assigneeId as org.hibernate.type.UUIDCharType) IS NULL OR a.assigneeId = (:assigneeId))") "AND (:assigneeId IS NULL OR a.assigneeId = uuid(:assigneeId))")
Set<AlarmSeverity> findAlarmSeverities(@Param("tenantId") UUID tenantId, Set<AlarmSeverity> findAlarmSeverities(@Param("tenantId") UUID tenantId,
@Param("affectedEntityId") UUID affectedEntityId, @Param("affectedEntityId") UUID affectedEntityId,
@Param("affectedEntityType") String affectedEntityType, @Param("affectedEntityType") String affectedEntityType,

8
dao/src/main/java/org/thingsboard/server/dao/sql/alarm/JpaAlarmDao.java

@ -115,9 +115,9 @@ public class JpaAlarmDao extends JpaAbstractDao<AlarmEntity, Alarm> implements A
} else if (query.getStatus() != null) { } else if (query.getStatus() != null) {
statusSet = Collections.singleton(query.getStatus()); statusSet = Collections.singleton(query.getStatus());
} }
UUID assigneeId = null; String assigneeId = null;
if (query.getAssigneeId() != null) { if (query.getAssigneeId() != null) {
assigneeId = query.getAssigneeId().getId(); assigneeId = query.getAssigneeId().toString();
} }
if (affectedEntity != null) { if (affectedEntity != null) {
return DaoUtil.toPageData( return DaoUtil.toPageData(
@ -157,9 +157,9 @@ public class JpaAlarmDao extends JpaAbstractDao<AlarmEntity, Alarm> implements A
} else if (query.getStatus() != null) { } else if (query.getStatus() != null) {
statusSet = Collections.singleton(query.getStatus()); statusSet = Collections.singleton(query.getStatus());
} }
UUID assigneeId = null; String assigneeId = null;
if (query.getAssigneeId() != null) { if (query.getAssigneeId() != null) {
assigneeId = query.getAssigneeId().getId(); assigneeId = query.getAssigneeId().toString();
} }
return DaoUtil.toPageData( return DaoUtil.toPageData(
alarmRepository.findCustomerAlarms( alarmRepository.findCustomerAlarms(

Loading…
Cancel
Save