Fix audit log time page link

This commit is contained in:
Igor Kulikov 2020-07-07 11:44:42 +03:00
parent 628892b35b
commit 90c7895075
5 changed files with 24 additions and 56 deletions

View File

@ -15,12 +15,10 @@
*/
package org.thingsboard.server.dao;
import com.datastax.oss.driver.api.core.uuid.Uuids;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.thingsboard.server.common.data.UUIDConverter;
import org.thingsboard.server.common.data.id.UUIDBased;
import org.thingsboard.server.common.data.page.PageData;
import org.thingsboard.server.common.data.page.PageLink;
@ -53,24 +51,6 @@ public abstract class DaoUtil {
return PageRequest.of(pageLink.getPage(), pageLink.getPageSize(), toSort(pageLink.getSortOrder(), columnMap));
}
public static String startTimeToId(Long startTime) {
if (startTime != null) {
UUID startOf = Uuids.startOf(startTime);
return UUIDConverter.fromTimeUUID(startOf);
} else {
return null;
}
}
public static String endTimeToId(Long endTime) {
if (endTime != null) {
UUID endOf = Uuids.endOf(endTime);
return UUIDConverter.fromTimeUUID(endOf);
} else {
return null;
}
}
public static Sort toSort(SortOrder sortOrder) {
return toSort(sortOrder, Collections.emptyMap());
}

View File

@ -21,7 +21,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Component;
import org.thingsboard.server.common.data.UUIDConverter;
import org.thingsboard.server.common.data.alarm.Alarm;
import org.thingsboard.server.common.data.alarm.AlarmInfo;
import org.thingsboard.server.common.data.alarm.AlarmQuery;
@ -32,10 +31,8 @@ import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.page.PageData;
import org.thingsboard.server.common.data.query.AlarmData;
import org.thingsboard.server.common.data.query.AlarmDataPageLink;
import org.thingsboard.server.common.data.query.AlarmDataQuery;
import org.thingsboard.server.dao.DaoUtil;
import org.thingsboard.server.dao.alarm.AlarmDao;
import org.thingsboard.server.dao.alarm.BaseAlarmService;
import org.thingsboard.server.dao.model.sql.AlarmEntity;
import org.thingsboard.server.dao.relation.RelationDao;
import org.thingsboard.server.dao.sql.JpaAbstractDao;
@ -47,9 +44,6 @@ import java.util.List;
import java.util.Objects;
import java.util.UUID;
import static org.thingsboard.server.dao.DaoUtil.endTimeToId;
import static org.thingsboard.server.dao.DaoUtil.startTimeToId;
/**
* Created by Valerii Sosliuk on 5/19/2017.
*/

View File

@ -31,8 +31,8 @@ public interface AuditLogRepository extends PagingAndSortingRepository<AuditLogE
@Query("SELECT a FROM AuditLogEntity a WHERE " +
"a.tenantId = :tenantId " +
"AND (:startId IS NULL OR a.id >= :startId) " +
"AND (:endId IS NULL OR a.id <= :endId) " +
"AND (:startTime IS NULL OR a.createdTime >= :startTime) " +
"AND (:endTime IS NULL OR a.createdTime <= :endTime) " +
"AND (:actionTypes IS NULL OR a.actionType in :actionTypes) " +
"AND (LOWER(a.entityType) LIKE LOWER(CONCAT(:textSearch, '%'))" +
"OR LOWER(a.entityName) LIKE LOWER(CONCAT(:textSearch, '%'))" +
@ -43,16 +43,16 @@ public interface AuditLogRepository extends PagingAndSortingRepository<AuditLogE
Page<AuditLogEntity> findByTenantId(
@Param("tenantId") UUID tenantId,
@Param("textSearch") String textSearch,
@Param("startId") String startId,
@Param("endId") String endId,
@Param("startTime") Long startTime,
@Param("endTime") Long endTime,
@Param("actionTypes") List<ActionType> actionTypes,
Pageable pageable);
@Query("SELECT a FROM AuditLogEntity a WHERE " +
"a.tenantId = :tenantId " +
"AND a.entityType = :entityType AND a.entityId = :entityId " +
"AND (:startId IS NULL OR a.id >= :startId) " +
"AND (:endId IS NULL OR a.id <= :endId) " +
"AND (:startTime IS NULL OR a.createdTime >= :startTime) " +
"AND (:endTime IS NULL OR a.createdTime <= :endTime) " +
"AND (:actionTypes IS NULL OR a.actionType in :actionTypes) " +
"AND (LOWER(a.entityName) LIKE LOWER(CONCAT(:textSearch, '%'))" +
"OR LOWER(a.userName) LIKE LOWER(CONCAT(:textSearch, '%'))" +
@ -63,16 +63,16 @@ public interface AuditLogRepository extends PagingAndSortingRepository<AuditLogE
@Param("entityType") EntityType entityType,
@Param("entityId") UUID entityId,
@Param("textSearch") String textSearch,
@Param("startId") String startId,
@Param("endId") String endId,
@Param("startTime") Long startTime,
@Param("endTime") Long endTime,
@Param("actionTypes") List<ActionType> actionTypes,
Pageable pageable);
@Query("SELECT a FROM AuditLogEntity a WHERE " +
"a.tenantId = :tenantId " +
"AND a.customerId = :customerId " +
"AND (:startId IS NULL OR a.id >= :startId) " +
"AND (:endId IS NULL OR a.id <= :endId) " +
"AND (:startTime IS NULL OR a.createdTime >= :startTime) " +
"AND (:endTime IS NULL OR a.createdTime <= :endTime) " +
"AND (:actionTypes IS NULL OR a.actionType in :actionTypes) " +
"AND (LOWER(a.entityType) LIKE LOWER(CONCAT(:textSearch, '%'))" +
"OR LOWER(a.entityName) LIKE LOWER(CONCAT(:textSearch, '%'))" +
@ -83,16 +83,16 @@ public interface AuditLogRepository extends PagingAndSortingRepository<AuditLogE
Page<AuditLogEntity> findAuditLogsByTenantIdAndCustomerId(@Param("tenantId") UUID tenantId,
@Param("customerId") UUID customerId,
@Param("textSearch") String textSearch,
@Param("startId") String startId,
@Param("endId") String endId,
@Param("startTime") Long startTime,
@Param("endTime") Long endTime,
@Param("actionTypes") List<ActionType> actionTypes,
Pageable pageable);
@Query("SELECT a FROM AuditLogEntity a WHERE " +
"a.tenantId = :tenantId " +
"AND a.userId = :userId " +
"AND (:startId IS NULL OR a.id >= :startId) " +
"AND (:endId IS NULL OR a.id <= :endId) " +
"AND (:startTime IS NULL OR a.createdTime >= :startTime) " +
"AND (:endTime IS NULL OR a.createdTime <= :endTime) " +
"AND (:actionTypes IS NULL OR a.actionType in :actionTypes) " +
"AND (LOWER(a.entityType) LIKE LOWER(CONCAT(:textSearch, '%'))" +
"OR LOWER(a.entityName) LIKE LOWER(CONCAT(:textSearch, '%'))" +
@ -102,8 +102,8 @@ public interface AuditLogRepository extends PagingAndSortingRepository<AuditLogE
Page<AuditLogEntity> findAuditLogsByTenantIdAndUserId(@Param("tenantId") UUID tenantId,
@Param("userId") UUID userId,
@Param("textSearch") String textSearch,
@Param("startId") String startId,
@Param("endId") String endId,
@Param("startTime") Long startTime,
@Param("endTime") Long endTime,
@Param("actionTypes") List<ActionType> actionTypes,
Pageable pageable);

View File

@ -36,9 +36,6 @@ import java.util.List;
import java.util.Objects;
import java.util.UUID;
import static org.thingsboard.server.dao.DaoUtil.endTimeToId;
import static org.thingsboard.server.dao.DaoUtil.startTimeToId;
@Component
@SqlDao
public class JpaAuditLogDao extends JpaAbstractDao<AuditLogEntity, AuditLog> implements AuditLogDao {
@ -73,8 +70,8 @@ public class JpaAuditLogDao extends JpaAbstractDao<AuditLogEntity, AuditLog> imp
entityId.getEntityType(),
entityId.getId(),
Objects.toString(pageLink.getTextSearch(), ""),
startTimeToId(pageLink.getStartTime()),
endTimeToId(pageLink.getEndTime()),
pageLink.getStartTime(),
pageLink.getEndTime(),
actionTypes,
DaoUtil.toPageable(pageLink)));
}
@ -87,8 +84,8 @@ public class JpaAuditLogDao extends JpaAbstractDao<AuditLogEntity, AuditLog> imp
tenantId,
customerId.getId(),
Objects.toString(pageLink.getTextSearch(), ""),
startTimeToId(pageLink.getStartTime()),
endTimeToId(pageLink.getEndTime()),
pageLink.getStartTime(),
pageLink.getEndTime(),
actionTypes,
DaoUtil.toPageable(pageLink)));
}
@ -101,8 +98,8 @@ public class JpaAuditLogDao extends JpaAbstractDao<AuditLogEntity, AuditLog> imp
tenantId,
userId.getId(),
Objects.toString(pageLink.getTextSearch(), ""),
startTimeToId(pageLink.getStartTime()),
endTimeToId(pageLink.getEndTime()),
pageLink.getStartTime(),
pageLink.getEndTime(),
actionTypes,
DaoUtil.toPageable(pageLink)));
}
@ -113,8 +110,8 @@ public class JpaAuditLogDao extends JpaAbstractDao<AuditLogEntity, AuditLog> imp
auditLogRepository.findByTenantId(
tenantId,
Objects.toString(pageLink.getTextSearch(), ""),
startTimeToId(pageLink.getStartTime()),
endTimeToId(pageLink.getEndTime()),
pageLink.getStartTime(),
pageLink.getEndTime(),
actionTypes,
DaoUtil.toPageable(pageLink)));
}

View File

@ -25,7 +25,6 @@ import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Component;
import org.thingsboard.server.common.data.Event;
import org.thingsboard.server.common.data.UUIDConverter;
import org.thingsboard.server.common.data.id.EntityId;
import org.thingsboard.server.common.data.id.EventId;
import org.thingsboard.server.common.data.id.TenantId;
@ -44,8 +43,6 @@ import java.util.Objects;
import java.util.Optional;
import java.util.UUID;
import static org.thingsboard.server.dao.DaoUtil.endTimeToId;
import static org.thingsboard.server.dao.DaoUtil.startTimeToId;
import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID;
/**