Replaced GeofencingZoneIdProto with EntityTypeProto and msb and lsb

This commit is contained in:
dshvaika 2025-08-12 19:55:21 +03:00
parent 67f08da7a0
commit dd18359c54
3 changed files with 16 additions and 23 deletions

View File

@ -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()));
}
}

View File

@ -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;

View File

@ -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 {