Commit cf7401d548b3da007a2e7467b2ba08797fae232c
Merge branch '20230222' into 'master'
20230222 See merge request yunteng/thingskit!160
Showing
5 changed files
with
28 additions
and
19 deletions
@@ -37,6 +37,6 @@ public class TkEventKvDto { | @@ -37,6 +37,6 @@ public class TkEventKvDto { | ||
37 | private final UUID entityId; | 37 | private final UUID entityId; |
38 | private final String eventIdentifier; | 38 | private final String eventIdentifier; |
39 | private final String eventName; | 39 | private final String eventName; |
40 | - private final UUID deviceProfileId; | ||
41 | - private final String deviceProfileName; | 40 | + private final UUID productId; |
41 | + private final String productName; | ||
42 | } | 42 | } |
@@ -41,12 +41,13 @@ public class TkEventKvEntity implements ToData<TkEventKvDto>, Serializable { | @@ -41,12 +41,13 @@ public class TkEventKvEntity implements ToData<TkEventKvDto>, Serializable { | ||
41 | @Column(name = EVENT_VALUE_COLUMN) | 41 | @Column(name = EVENT_VALUE_COLUMN) |
42 | private String eventValue; | 42 | private String eventValue; |
43 | 43 | ||
44 | - | 44 | + @Column |
45 | + private String eventName; | ||
45 | @Column(name = DEVICE_DEVICE_PROFILE_ID_PROPERTY, columnDefinition = "uuid") | 46 | @Column(name = DEVICE_DEVICE_PROFILE_ID_PROPERTY, columnDefinition = "uuid") |
46 | private UUID deviceProfileId; | 47 | private UUID deviceProfileId; |
47 | 48 | ||
48 | @Override | 49 | @Override |
49 | public TkEventKvDto toData() { | 50 | public TkEventKvDto toData() { |
50 | - return new TkEventKvDto(id.getEventTime(),id.getEventType(), JacksonUtil.toJsonNode(eventValue),id.getEntityId(),id.getEventIdentifier(),"",deviceProfileId,""); | 51 | + return new TkEventKvDto(id.getEventTime(),id.getEventType(), JacksonUtil.toJsonNode(eventValue),id.getEntityId(),id.getEventIdentifier(),eventName,deviceProfileId,null); |
51 | } | 52 | } |
52 | } | 53 | } |
@@ -28,8 +28,8 @@ public abstract class EventKvInsertRepository { | @@ -28,8 +28,8 @@ public abstract class EventKvInsertRepository { | ||
28 | "WHERE event_type = ? and entity_id = ? and event_identifier =? and event_time = ?;"; | 28 | "WHERE event_type = ? and entity_id = ? and event_identifier =? and event_time = ?;"; |
29 | 29 | ||
30 | private static final String INSERT_OR_UPDATE = | 30 | private static final String INSERT_OR_UPDATE = |
31 | - "INSERT INTO tk_event_kv (event_type, entity_id, event_identifier, event_time, event_value,device_profile_id) " + | ||
32 | - "VALUES(?, ?, ?, ?, ?, ?) " + | 31 | + "INSERT INTO tk_event_kv (event_type, entity_id, event_identifier, event_time, event_name, event_value,device_profile_id) " + |
32 | + "VALUES(?, ?, ?, ?, ?, ?, ?) " + | ||
33 | "ON CONFLICT (event_type, entity_id, event_identifier, event_time) " + | 33 | "ON CONFLICT (event_type, entity_id, event_identifier, event_time) " + |
34 | "DO UPDATE SET event_value = ?,device_profile_id = ?;"; | 34 | "DO UPDATE SET event_value = ?,device_profile_id = ?;"; |
35 | 35 | ||
@@ -86,13 +86,14 @@ public abstract class EventKvInsertRepository { | @@ -86,13 +86,14 @@ public abstract class EventKvInsertRepository { | ||
86 | ps.setObject(2, kvEntity.getId().getEntityId()); | 86 | ps.setObject(2, kvEntity.getId().getEntityId()); |
87 | ps.setString(3, kvEntity.getId().getEventIdentifier()); | 87 | ps.setString(3, kvEntity.getId().getEventIdentifier()); |
88 | ps.setLong(4, kvEntity.getId().getEventTime()); | 88 | ps.setLong(4, kvEntity.getId().getEventTime()); |
89 | + ps.setString(5, kvEntity.getEventName()); | ||
89 | 90 | ||
90 | - ps.setString(5, replaceNullChars(kvEntity.getEventValue())); | ||
91 | - ps.setString(7, replaceNullChars(kvEntity.getEventValue())); | 91 | + ps.setString(6, replaceNullChars(kvEntity.getEventValue())); |
92 | + ps.setString(8, replaceNullChars(kvEntity.getEventValue())); | ||
92 | 93 | ||
93 | 94 | ||
94 | - ps.setObject(6, kvEntity.getDeviceProfileId()); | ||
95 | - ps.setObject(8, kvEntity.getDeviceProfileId()); | 95 | + ps.setObject(7, kvEntity.getDeviceProfileId()); |
96 | + ps.setObject(9, kvEntity.getDeviceProfileId()); | ||
96 | } | 97 | } |
97 | 98 | ||
98 | @Override | 99 | @Override |
1 | /** | 1 | /** |
2 | * Copyright © 2016-2022 The Thingsboard Authors | 2 | * Copyright © 2016-2022 The Thingsboard Authors |
3 | - * | 3 | + * <p> |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | * you may not use this file except in compliance with the License. | 5 | * you may not use this file except in compliance with the License. |
6 | * You may obtain a copy of the License at | 6 | * You may obtain a copy of the License at |
7 | - * | ||
8 | - * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | - * | 7 | + * <p> |
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * <p> | ||
10 | * Unless required by applicable law or agreed to in writing, software | 10 | * Unless required by applicable law or agreed to in writing, software |
11 | * distributed under the License is distributed on an "AS IS" BASIS, | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
@@ -20,6 +20,7 @@ import org.springframework.data.domain.Pageable; | @@ -20,6 +20,7 @@ import org.springframework.data.domain.Pageable; | ||
20 | import org.springframework.data.jpa.repository.Query; | 20 | import org.springframework.data.jpa.repository.Query; |
21 | import org.springframework.data.repository.PagingAndSortingRepository; | 21 | import org.springframework.data.repository.PagingAndSortingRepository; |
22 | import org.springframework.data.repository.query.Param; | 22 | import org.springframework.data.repository.query.Param; |
23 | +import org.thingsboard.server.common.data.yunteng.enums.DeviceEventTypeEnum; | ||
23 | import org.thingsboard.server.dao.yunteng.jpa.entity.events.TkEventKvCompositeKey; | 24 | import org.thingsboard.server.dao.yunteng.jpa.entity.events.TkEventKvCompositeKey; |
24 | import org.thingsboard.server.dao.yunteng.jpa.entity.events.TkEventKvEntity; | 25 | import org.thingsboard.server.dao.yunteng.jpa.entity.events.TkEventKvEntity; |
25 | 26 | ||
@@ -27,10 +28,15 @@ import java.util.UUID; | @@ -27,10 +28,15 @@ import java.util.UUID; | ||
27 | 28 | ||
28 | public interface EventKvRepository extends PagingAndSortingRepository<TkEventKvEntity, TkEventKvCompositeKey> { | 29 | public interface EventKvRepository extends PagingAndSortingRepository<TkEventKvEntity, TkEventKvCompositeKey> { |
29 | 30 | ||
30 | - @Query("SELECT a FROM TkEventKvEntity a WHERE a.id.entityId = :entityId " | ||
31 | -// +"AND a.id.eventType = :eventType AND a.id.eventIdentifier = :eventIdentifier " | ||
32 | - ) | 31 | + @Query("SELECT a FROM TkEventKvEntity a WHERE a.id.entityId = :entityId " |
32 | + + "AND (:eventType IS NULL OR a.id.eventType = :eventType) " | ||
33 | + + "AND (:eventIdentifier IS NULL OR a.id.eventIdentifier = :eventIdentifier) " | ||
34 | + + "AND (:startTime IS NULL OR a.id.eventTime >= :startTime) " | ||
35 | + + "AND (:endTime IS NULL OR a.id.eventTime <= :endTime ) " ) | ||
33 | Page<TkEventKvEntity> findEvents(@Param("entityId") UUID entityId, | 36 | Page<TkEventKvEntity> findEvents(@Param("entityId") UUID entityId, |
37 | + @Param("eventType") DeviceEventTypeEnum eventType, | ||
38 | + @Param("eventIdentifier") String eventIdentifier, | ||
39 | + @Param("startTime") Long startTime, | ||
40 | + @Param("endTime") Long endTime, | ||
34 | Pageable pageable); | 41 | Pageable pageable); |
35 | } | 42 | } |
36 | - |
@@ -106,7 +106,7 @@ public class JpaEventDao extends JpaAbstractDaoListeningExecutorService implemen | @@ -106,7 +106,7 @@ public class JpaEventDao extends JpaAbstractDaoListeningExecutorService implemen | ||
106 | @Override | 106 | @Override |
107 | public PageData<TkEventKvDto> findEvents(EntityId entityId,String eventIdentifier, DeviceEventTypeEnum eventType, TimePageLink pageLink) { | 107 | public PageData<TkEventKvDto> findEvents(EntityId entityId,String eventIdentifier, DeviceEventTypeEnum eventType, TimePageLink pageLink) { |
108 | 108 | ||
109 | - return DaoUtil.toPageData(eventKvRepository.findEvents(entityId.getId(),DaoUtil.toPageable(pageLink))); | 109 | + return DaoUtil.toPageData(eventKvRepository.findEvents(entityId.getId(),eventType,eventIdentifier,pageLink.getStartTime(),pageLink.getEndTime(),DaoUtil.toPageable(pageLink))); |
110 | } | 110 | } |
111 | 111 | ||
112 | 112 | ||
@@ -114,6 +114,7 @@ public class JpaEventDao extends JpaAbstractDaoListeningExecutorService implemen | @@ -114,6 +114,7 @@ public class JpaEventDao extends JpaAbstractDaoListeningExecutorService implemen | ||
114 | public ListenableFuture<Void> save(TenantId tenantId, DeviceProfileId profileId,EntityId entityId,DeviceEventTypeEnum eventType, String eventIdentifier, String eventData,Long eventTime) { | 114 | public ListenableFuture<Void> save(TenantId tenantId, DeviceProfileId profileId,EntityId entityId,DeviceEventTypeEnum eventType, String eventIdentifier, String eventData,Long eventTime) { |
115 | TkEventKvEntity entity = new TkEventKvEntity(); | 115 | TkEventKvEntity entity = new TkEventKvEntity(); |
116 | entity.setId(new TkEventKvCompositeKey(eventType, entityId.getId(), eventIdentifier, eventTime)); | 116 | entity.setId(new TkEventKvCompositeKey(eventType, entityId.getId(), eventIdentifier, eventTime)); |
117 | + entity.setEventName("test"); | ||
117 | entity.setDeviceProfileId(profileId.getId()); | 118 | entity.setDeviceProfileId(profileId.getId()); |
118 | entity.setEventValue(eventData); | 119 | entity.setEventValue(eventData); |
119 | return addToQueue(entity); | 120 | return addToQueue(entity); |