From dd18359c54776cd0090166ed358c26fd07e4b83a Mon Sep 17 00:00:00 2001 From: dshvaika Date: Tue, 12 Aug 2025 19:55:21 +0300 Subject: [PATCH] Replaced GeofencingZoneIdProto with EntityTypeProto and msb and lsb --- .../cf/ctx/state/GeofencingZoneState.java | 8 ++++++-- .../server/utils/CalculatedFieldUtils.java | 15 ++++----------- common/proto/src/main/proto/queue.proto | 16 ++++++---------- 3 files changed, 16 insertions(+), 23 deletions(-) diff --git a/application/src/main/java/org/thingsboard/server/service/cf/ctx/state/GeofencingZoneState.java b/application/src/main/java/org/thingsboard/server/service/cf/ctx/state/GeofencingZoneState.java index 3182a342e8..12493152dc 100644 --- a/application/src/main/java/org/thingsboard/server/service/cf/ctx/state/GeofencingZoneState.java +++ b/application/src/main/java/org/thingsboard/server/service/cf/ctx/state/GeofencingZoneState.java @@ -25,6 +25,7 @@ import org.thingsboard.server.common.data.id.EntityId; import org.thingsboard.server.common.data.id.EntityIdFactory; import org.thingsboard.server.common.data.kv.AttributeKvEntry; import org.thingsboard.server.common.data.kv.KvEntry; +import org.thingsboard.server.common.util.ProtoUtils; import org.thingsboard.server.gen.transport.TransportProtos.GeofencingZoneProto; import java.util.UUID; @@ -52,8 +53,7 @@ public class GeofencingZoneState { } public GeofencingZoneState(GeofencingZoneProto proto) { - this.zoneId = EntityIdFactory.getByTypeAndUuid(proto.getZoneId().getType(), - new UUID(proto.getZoneId().getZoneIdMSB(), proto.getZoneId().getZoneIdLSB())); + this.zoneId = toZoneId(proto); this.ts = proto.getTs(); this.version = proto.getVersion(); this.perimeterDefinition = JacksonUtil.fromString(proto.getPerimeterDefinition(), PerimeterDefinition.class); @@ -94,4 +94,8 @@ public class GeofencingZoneState { return inside ? GeofencingEvent.INSIDE : GeofencingEvent.OUTSIDE; } + private EntityId toZoneId(GeofencingZoneProto proto) { + return EntityIdFactory.getByTypeAndUuid(ProtoUtils.fromProto(proto.getZoneType()), new UUID(proto.getZoneIdMSB(), proto.getZoneIdLSB())); + } + } diff --git a/application/src/main/java/org/thingsboard/server/utils/CalculatedFieldUtils.java b/application/src/main/java/org/thingsboard/server/utils/CalculatedFieldUtils.java index eeb5318104..7658409662 100644 --- a/application/src/main/java/org/thingsboard/server/utils/CalculatedFieldUtils.java +++ b/application/src/main/java/org/thingsboard/server/utils/CalculatedFieldUtils.java @@ -24,11 +24,11 @@ import org.thingsboard.server.common.data.id.EntityIdFactory; import org.thingsboard.server.common.data.id.TenantId; import org.thingsboard.server.common.data.kv.BasicKvEntry; import org.thingsboard.server.common.util.KvProtoUtil; +import org.thingsboard.server.common.util.ProtoUtils; import org.thingsboard.server.gen.transport.TransportProtos.CalculatedFieldEntityCtxIdProto; import org.thingsboard.server.gen.transport.TransportProtos.CalculatedFieldIdProto; import org.thingsboard.server.gen.transport.TransportProtos.CalculatedFieldStateProto; import org.thingsboard.server.gen.transport.TransportProtos.GeofencingArgumentProto; -import org.thingsboard.server.gen.transport.TransportProtos.GeofencingZoneIdProto; import org.thingsboard.server.gen.transport.TransportProtos.GeofencingZoneProto; import org.thingsboard.server.gen.transport.TransportProtos.SingleValueArgumentProto; import org.thingsboard.server.gen.transport.TransportProtos.TsDoubleValProto; @@ -132,7 +132,9 @@ public class CalculatedFieldUtils { private static GeofencingZoneProto toGeofencingZoneProto(EntityId entityId, GeofencingZoneState zoneState) { GeofencingZoneProto.Builder builder = GeofencingZoneProto.newBuilder() - .setZoneId(toGeofencingZoneIdProto(entityId)) + .setZoneType(ProtoUtils.toProto(entityId.getEntityType())) + .setZoneIdMSB(entityId.getId().getMostSignificantBits()) + .setZoneIdLSB(entityId.getId().getLeastSignificantBits()) .setTs(zoneState.getTs()) .setVersion(zoneState.getVersion()) .setPerimeterDefinition(JacksonUtil.toString(zoneState.getPerimeterDefinition())); @@ -142,15 +144,6 @@ public class CalculatedFieldUtils { return builder.build(); } - private static GeofencingZoneIdProto toGeofencingZoneIdProto(EntityId zoneId) { - return GeofencingZoneIdProto.newBuilder() - .setType(zoneId.getEntityType().name()) - .setZoneIdLSB(zoneId.getId().getLeastSignificantBits()) - .setZoneIdMSB(zoneId.getId().getMostSignificantBits()) - .build(); - } - - public static CalculatedFieldState fromProto(CalculatedFieldStateProto proto) { if (StringUtils.isEmpty(proto.getType())) { return null; diff --git a/common/proto/src/main/proto/queue.proto b/common/proto/src/main/proto/queue.proto index 2b6e0701d5..2ea1db2a0a 100644 --- a/common/proto/src/main/proto/queue.proto +++ b/common/proto/src/main/proto/queue.proto @@ -894,18 +894,14 @@ message TsRollingArgumentProto { repeated TsDoubleValProto tsValue = 4; } -message GeofencingZoneIdProto { - string type = 1; +message GeofencingZoneProto { + EntityTypeProto zoneType = 1; int64 zoneIdMSB = 2; int64 zoneIdLSB = 3; -} - -message GeofencingZoneProto { - GeofencingZoneIdProto zoneId = 1; - int64 ts = 2; - string perimeterDefinition = 3; - int64 version = 4; - optional bool inside = 5; + int64 ts = 4; + string perimeterDefinition = 5; + int64 version = 6; + optional bool inside = 7; } message GeofencingArgumentProto {