|
|
|
@ -16,10 +16,12 @@ |
|
|
|
package org.thingsboard.server.dao.sql.timeseries; |
|
|
|
|
|
|
|
import org.springframework.data.domain.Pageable; |
|
|
|
import org.springframework.data.jpa.repository.Modifying; |
|
|
|
import org.springframework.data.jpa.repository.Query; |
|
|
|
import org.springframework.data.repository.CrudRepository; |
|
|
|
import org.springframework.data.repository.query.Param; |
|
|
|
import org.springframework.scheduling.annotation.Async; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
import org.thingsboard.server.common.data.EntityType; |
|
|
|
import org.thingsboard.server.dao.model.sql.TsKvCompositeKey; |
|
|
|
import org.thingsboard.server.dao.model.sql.TsKvEntity; |
|
|
|
@ -41,6 +43,17 @@ public interface TsKvRepository extends CrudRepository<TsKvEntity, TsKvComposite |
|
|
|
@Param("endTs") long endTs, |
|
|
|
Pageable pageable); |
|
|
|
|
|
|
|
@Transactional |
|
|
|
@Modifying |
|
|
|
@Query("DELETE FROM TsKvEntity tskv WHERE tskv.entityId = :entityId " + |
|
|
|
"AND tskv.entityType = :entityType AND tskv.key = :entityKey " + |
|
|
|
"AND tskv.ts > :startTs AND tskv.ts < :endTs") |
|
|
|
void delete(@Param("entityId") String entityId, |
|
|
|
@Param("entityType") EntityType entityType, |
|
|
|
@Param("entityKey") String key, |
|
|
|
@Param("startTs") long startTs, |
|
|
|
@Param("endTs") long endTs); |
|
|
|
|
|
|
|
@Async |
|
|
|
@Query("SELECT new TsKvEntity(MAX(tskv.strValue), MAX(tskv.longValue), MAX(tskv.doubleValue)) FROM TsKvEntity tskv " + |
|
|
|
"WHERE tskv.entityId = :entityId AND tskv.entityType = :entityType " + |
|
|
|
@ -56,30 +69,30 @@ public interface TsKvRepository extends CrudRepository<TsKvEntity, TsKvComposite |
|
|
|
"WHERE tskv.entityId = :entityId AND tskv.entityType = :entityType " + |
|
|
|
"AND tskv.key = :entityKey AND tskv.ts > :startTs AND tskv.ts < :endTs") |
|
|
|
CompletableFuture<TsKvEntity> findMin(@Param("entityId") String entityId, |
|
|
|
@Param("entityType") EntityType entityType, |
|
|
|
@Param("entityKey") String entityKey, |
|
|
|
@Param("startTs") long startTs, |
|
|
|
@Param("endTs") long endTs); |
|
|
|
@Param("entityType") EntityType entityType, |
|
|
|
@Param("entityKey") String entityKey, |
|
|
|
@Param("startTs") long startTs, |
|
|
|
@Param("endTs") long endTs); |
|
|
|
|
|
|
|
@Async |
|
|
|
@Query("SELECT new TsKvEntity(COUNT(tskv.booleanValue), COUNT(tskv.strValue), COUNT(tskv.longValue), COUNT(tskv.doubleValue)) FROM TsKvEntity tskv " + |
|
|
|
"WHERE tskv.entityId = :entityId AND tskv.entityType = :entityType " + |
|
|
|
"AND tskv.key = :entityKey AND tskv.ts > :startTs AND tskv.ts < :endTs") |
|
|
|
CompletableFuture<TsKvEntity> findCount(@Param("entityId") String entityId, |
|
|
|
@Param("entityType") EntityType entityType, |
|
|
|
@Param("entityKey") String entityKey, |
|
|
|
@Param("startTs") long startTs, |
|
|
|
@Param("endTs") long endTs); |
|
|
|
@Param("entityType") EntityType entityType, |
|
|
|
@Param("entityKey") String entityKey, |
|
|
|
@Param("startTs") long startTs, |
|
|
|
@Param("endTs") long endTs); |
|
|
|
|
|
|
|
@Async |
|
|
|
@Query("SELECT new TsKvEntity(AVG(tskv.longValue), AVG(tskv.doubleValue)) FROM TsKvEntity tskv " + |
|
|
|
"WHERE tskv.entityId = :entityId AND tskv.entityType = :entityType " + |
|
|
|
"AND tskv.key = :entityKey AND tskv.ts > :startTs AND tskv.ts < :endTs") |
|
|
|
CompletableFuture<TsKvEntity> findAvg(@Param("entityId") String entityId, |
|
|
|
@Param("entityType") EntityType entityType, |
|
|
|
@Param("entityKey") String entityKey, |
|
|
|
@Param("startTs") long startTs, |
|
|
|
@Param("endTs") long endTs); |
|
|
|
@Param("entityType") EntityType entityType, |
|
|
|
@Param("entityKey") String entityKey, |
|
|
|
@Param("startTs") long startTs, |
|
|
|
@Param("endTs") long endTs); |
|
|
|
|
|
|
|
|
|
|
|
@Async |
|
|
|
@ -87,8 +100,8 @@ public interface TsKvRepository extends CrudRepository<TsKvEntity, TsKvComposite |
|
|
|
"WHERE tskv.entityId = :entityId AND tskv.entityType = :entityType " + |
|
|
|
"AND tskv.key = :entityKey AND tskv.ts > :startTs AND tskv.ts < :endTs") |
|
|
|
CompletableFuture<TsKvEntity> findSum(@Param("entityId") String entityId, |
|
|
|
@Param("entityType") EntityType entityType, |
|
|
|
@Param("entityKey") String entityKey, |
|
|
|
@Param("startTs") long startTs, |
|
|
|
@Param("endTs") long endTs); |
|
|
|
@Param("entityType") EntityType entityType, |
|
|
|
@Param("entityKey") String entityKey, |
|
|
|
@Param("startTs") long startTs, |
|
|
|
@Param("endTs") long endTs); |
|
|
|
} |
|
|
|
|