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 | 37 | private final UUID entityId; |
38 | 38 | private final String eventIdentifier; |
39 | 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 | 41 | @Column(name = EVENT_VALUE_COLUMN) |
42 | 42 | private String eventValue; |
43 | 43 | |
44 | - | |
44 | + @Column | |
45 | + private String eventName; | |
45 | 46 | @Column(name = DEVICE_DEVICE_PROFILE_ID_PROPERTY, columnDefinition = "uuid") |
46 | 47 | private UUID deviceProfileId; |
47 | 48 | |
48 | 49 | @Override |
49 | 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 | 28 | "WHERE event_type = ? and entity_id = ? and event_identifier =? and event_time = ?;"; |
29 | 29 | |
30 | 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 | 33 | "ON CONFLICT (event_type, entity_id, event_identifier, event_time) " + |
34 | 34 | "DO UPDATE SET event_value = ?,device_profile_id = ?;"; |
35 | 35 | |
... | ... | @@ -86,13 +86,14 @@ public abstract class EventKvInsertRepository { |
86 | 86 | ps.setObject(2, kvEntity.getId().getEntityId()); |
87 | 87 | ps.setString(3, kvEntity.getId().getEventIdentifier()); |
88 | 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 | 99 | @Override | ... | ... |
1 | 1 | /** |
2 | 2 | * Copyright © 2016-2022 The Thingsboard Authors |
3 | - * | |
3 | + * <p> | |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
6 | 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 | 10 | * Unless required by applicable law or agreed to in writing, software |
11 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
12 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
... | ... | @@ -20,6 +20,7 @@ import org.springframework.data.domain.Pageable; |
20 | 20 | import org.springframework.data.jpa.repository.Query; |
21 | 21 | import org.springframework.data.repository.PagingAndSortingRepository; |
22 | 22 | import org.springframework.data.repository.query.Param; |
23 | +import org.thingsboard.server.common.data.yunteng.enums.DeviceEventTypeEnum; | |
23 | 24 | import org.thingsboard.server.dao.yunteng.jpa.entity.events.TkEventKvCompositeKey; |
24 | 25 | import org.thingsboard.server.dao.yunteng.jpa.entity.events.TkEventKvEntity; |
25 | 26 | |
... | ... | @@ -27,10 +28,15 @@ import java.util.UUID; |
27 | 28 | |
28 | 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 | 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 | 41 | Pageable pageable); |
35 | 42 | } |
36 | - | ... | ... |
... | ... | @@ -106,7 +106,7 @@ public class JpaEventDao extends JpaAbstractDaoListeningExecutorService implemen |
106 | 106 | @Override |
107 | 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 | 114 | public ListenableFuture<Void> save(TenantId tenantId, DeviceProfileId profileId,EntityId entityId,DeviceEventTypeEnum eventType, String eventIdentifier, String eventData,Long eventTime) { |
115 | 115 | TkEventKvEntity entity = new TkEventKvEntity(); |
116 | 116 | entity.setId(new TkEventKvCompositeKey(eventType, entityId.getId(), eventIdentifier, eventTime)); |
117 | + entity.setEventName("test"); | |
117 | 118 | entity.setDeviceProfileId(profileId.getId()); |
118 | 119 | entity.setEventValue(eventData); |
119 | 120 | return addToQueue(entity); | ... | ... |