Refactor TelemetrySubscriptionUpdate

This commit is contained in:
ViacheslavKlimov 2025-05-29 11:47:11 +03:00
parent 69c9c4616c
commit da6fa2c00b
4 changed files with 6 additions and 8 deletions

View File

@ -155,7 +155,7 @@ public abstract class TbAbstractEntityQuerySubCtx<T extends EntityCountQuery> ex
private void dynamicValueSubUpdate(String sessionId, TelemetrySubscriptionUpdate subscriptionUpdate, private void dynamicValueSubUpdate(String sessionId, TelemetrySubscriptionUpdate subscriptionUpdate,
Map<String, DynamicValueKeySub> dynamicValueKeySubMap) { Map<String, DynamicValueKeySub> dynamicValueKeySubMap) {
Map<String, TsValue> latestUpdate = new HashMap<>(); Map<String, TsValue> latestUpdate = new HashMap<>();
subscriptionUpdate.getData().forEach((key, values) -> { subscriptionUpdate.getValues().forEach((key, values) -> {
latestUpdate.put(key, getLatest(values)); latestUpdate.put(key, getLatest(values));
}); });

View File

@ -190,7 +190,7 @@ public class TbAlarmDataSubCtx extends TbAbstractDataSubCtx<AlarmDataQuery> {
EntityId entityId = subToEntityIdMap.get(subscriptionUpdate.getSubscriptionId()); EntityId entityId = subToEntityIdMap.get(subscriptionUpdate.getSubscriptionId());
if (entityId != null) { if (entityId != null) {
Map<String, TsValue> latestUpdate = new HashMap<>(); Map<String, TsValue> latestUpdate = new HashMap<>();
subscriptionUpdate.getData().forEach((key, values) -> { subscriptionUpdate.getValues().forEach((key, values) -> {
latestUpdate.put(key, getLatest(values)); latestUpdate.put(key, getLatest(values));
}); });
EntityData entityData = entitiesMap.get(entityId); EntityData entityData = entitiesMap.get(entityId);

View File

@ -93,7 +93,7 @@ public class TbEntityDataSubCtx extends TbAbstractDataSubCtx<EntityDataQuery> {
private void sendLatestWsMsg(EntityId entityId, String sessionId, TelemetrySubscriptionUpdate subscriptionUpdate, EntityKeyType keyType) { private void sendLatestWsMsg(EntityId entityId, String sessionId, TelemetrySubscriptionUpdate subscriptionUpdate, EntityKeyType keyType) {
Map<String, TsValue> latestUpdate = new HashMap<>(); Map<String, TsValue> latestUpdate = new HashMap<>();
subscriptionUpdate.getData().forEach((key, values) -> { subscriptionUpdate.getValues().forEach((key, values) -> {
latestUpdate.put(key, getLatest(values)); latestUpdate.put(key, getLatest(values));
}); });
EntityData entityData = getDataForEntity(entityId); EntityData entityData = getDataForEntity(entityId);
@ -129,7 +129,7 @@ public class TbEntityDataSubCtx extends TbAbstractDataSubCtx<EntityDataQuery> {
private void sendTsWsMsg(EntityId entityId, String sessionId, TelemetrySubscriptionUpdate subscriptionUpdate, EntityKeyType keyType) { private void sendTsWsMsg(EntityId entityId, String sessionId, TelemetrySubscriptionUpdate subscriptionUpdate, EntityKeyType keyType) {
Map<String, List<TsValue>> tsUpdate = new HashMap<>(); Map<String, List<TsValue>> tsUpdate = new HashMap<>();
subscriptionUpdate.getData().forEach((key, values) -> { subscriptionUpdate.getValues().forEach((key, values) -> {
tsUpdate.put(key, new ArrayList<>(values)); tsUpdate.put(key, new ArrayList<>(values));
}); });
Map<String, TsValue> latestCtxValues = getLatestTsValuesForEntity(entityId); Map<String, TsValue> latestCtxValues = getLatestTsValuesForEntity(entityId);

View File

@ -31,15 +31,13 @@ import java.util.Map;
import java.util.TreeMap; import java.util.TreeMap;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Getter
@AllArgsConstructor @AllArgsConstructor
public class TelemetrySubscriptionUpdate { public class TelemetrySubscriptionUpdate {
@Getter
@With @With
private final int subscriptionId; private final int subscriptionId;
@Getter
private int errorCode; private int errorCode;
@Getter
private String errorMsg; private String errorMsg;
private Map<String, List<Object>> data; private Map<String, List<Object>> data;
@ -75,7 +73,7 @@ public class TelemetrySubscriptionUpdate {
this.errorMsg = errorMsg != null ? errorMsg : errorCode.getDefaultMsg(); this.errorMsg = errorMsg != null ? errorMsg : errorCode.getDefaultMsg();
} }
public Map<String, List<TsValue>> getData() { public Map<String, List<TsValue>> getValues() {
if (data == null || data.isEmpty()) { if (data == null || data.isEmpty()) {
return Collections.emptyMap(); return Collections.emptyMap();
} }