|
|
|
@ -15,6 +15,7 @@ |
|
|
|
*/ |
|
|
|
package org.thingsboard.server.dao.sql.audit; |
|
|
|
|
|
|
|
import com.datastax.oss.driver.api.core.uuid.Uuids; |
|
|
|
import com.google.common.util.concurrent.ListenableFuture; |
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
@ -24,8 +25,10 @@ import org.springframework.jdbc.core.JdbcTemplate; |
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
import org.thingsboard.server.common.data.audit.ActionType; |
|
|
|
import org.thingsboard.server.common.data.audit.AuditLog; |
|
|
|
import org.thingsboard.server.common.data.id.AuditLogId; |
|
|
|
import org.thingsboard.server.common.data.id.CustomerId; |
|
|
|
import org.thingsboard.server.common.data.id.EntityId; |
|
|
|
import org.thingsboard.server.common.data.id.TenantId; |
|
|
|
import org.thingsboard.server.common.data.id.UserId; |
|
|
|
import org.thingsboard.server.common.data.page.PageData; |
|
|
|
import org.thingsboard.server.common.data.page.TimePageLink; |
|
|
|
@ -72,12 +75,22 @@ public class JpaAuditLogDao extends JpaAbstractDao<AuditLogEntity, AuditLog> imp |
|
|
|
@Override |
|
|
|
public ListenableFuture<Void> saveByTenantId(AuditLog auditLog) { |
|
|
|
return service.submit(() -> { |
|
|
|
partitioningRepository.createPartitionIfNotExists(TABLE_NAME, auditLog.getCreatedTime(), TimeUnit.HOURS.toMillis(partitionSizeInHours)); |
|
|
|
save(auditLog.getTenantId(), auditLog); |
|
|
|
return null; |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public AuditLog save(TenantId tenantId, AuditLog auditLog) { |
|
|
|
if (auditLog.getId() == null) { |
|
|
|
UUID uuid = Uuids.timeBased(); |
|
|
|
auditLog.setId(new AuditLogId(uuid)); |
|
|
|
auditLog.setCreatedTime(Uuids.unixTimestamp(uuid)); |
|
|
|
} |
|
|
|
partitioningRepository.createPartitionIfNotExists(TABLE_NAME, auditLog.getCreatedTime(), TimeUnit.HOURS.toMillis(partitionSizeInHours)); |
|
|
|
return super.save(tenantId, auditLog); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public PageData<AuditLog> findAuditLogsByTenantIdAndEntityId(UUID tenantId, EntityId entityId, List<ActionType> actionTypes, TimePageLink pageLink) { |
|
|
|
return DaoUtil.toPageData( |
|
|
|
|