修改代码
This commit is contained in:
parent
39f423dd28
commit
c08855a3b5
|
|
@ -17,6 +17,10 @@ import org.thingsboard.server.common.data.id.EntityId;
|
||||||
import org.thingsboard.server.common.data.kv.AttributeKvEntry;
|
import org.thingsboard.server.common.data.kv.AttributeKvEntry;
|
||||||
import org.thingsboard.server.common.data.kv.TsKvEntry;
|
import org.thingsboard.server.common.data.kv.TsKvEntry;
|
||||||
import org.thingsboard.server.common.data.relation.EntityRelation;
|
import org.thingsboard.server.common.data.relation.EntityRelation;
|
||||||
|
import org.thingsboard.server.common.data.relation.EntityRelationInfo;
|
||||||
|
import org.thingsboard.server.common.data.relation.EntityRelationsQuery;
|
||||||
|
import org.thingsboard.server.common.data.relation.EntitySearchDirection;
|
||||||
|
import org.thingsboard.server.common.data.relation.RelationsSearchParameters;
|
||||||
import org.thingsboard.server.common.data.relation.RelationTypeGroup;
|
import org.thingsboard.server.common.data.relation.RelationTypeGroup;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
@ -243,21 +247,30 @@ public class ThingsBoardDomainImpl implements IThingsBoardDomain {
|
||||||
try {
|
try {
|
||||||
DeviceId gatewayId = new DeviceId(UUID.fromString(gatewayDeviceId));
|
DeviceId gatewayId = new DeviceId(UUID.fromString(gatewayDeviceId));
|
||||||
|
|
||||||
// 查询从网关出发的 "Contains" 关系(网关 -> 子设备)
|
// 构建查询参数:从网关出发查询子设备
|
||||||
List<EntityRelation> relations = client.findByFrom(
|
// direction = FROM 表示从 rootId 出发的关系(网关 -> 子设备)
|
||||||
gatewayId,
|
RelationsSearchParameters parameters = new RelationsSearchParameters(
|
||||||
EntityRelation.CONTAINS_TYPE,
|
gatewayId, // rootId: 网关设备ID
|
||||||
RelationTypeGroup.COMMON
|
EntitySearchDirection.FROM, // direction: 从网关出发
|
||||||
|
1, // maxLevel: 查询深度为1(直接子设备)
|
||||||
|
RelationTypeGroup.COMMON, // relationTypeGroup: COMMON
|
||||||
|
false // fetchLastLevelOnly: false
|
||||||
);
|
);
|
||||||
|
|
||||||
if (relations == null || relations.isEmpty()) {
|
EntityRelationsQuery query = new EntityRelationsQuery();
|
||||||
|
query.setParameters(parameters);
|
||||||
|
|
||||||
|
// 调用 findInfoByQuery 查询关系信息
|
||||||
|
List<EntityRelationInfo> relationInfos = client.findInfoByQuery(query);
|
||||||
|
|
||||||
|
if (relationInfos == null || relationInfos.isEmpty()) {
|
||||||
log.debug("网关 {} 没有子设备", gatewayDeviceId);
|
log.debug("网关 {} 没有子设备", gatewayDeviceId);
|
||||||
return childDeviceIds;
|
return childDeviceIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 提取所有子设备的ID
|
// 提取所有子设备的ID
|
||||||
for (EntityRelation relation : relations) {
|
for (EntityRelationInfo relationInfo : relationInfos) {
|
||||||
EntityId childEntityId = relation.getTo();
|
EntityId childEntityId = relationInfo.getTo();
|
||||||
String childDeviceId = childEntityId.getId().toString();
|
String childDeviceId = childEntityId.getId().toString();
|
||||||
childDeviceIds.add(childDeviceId);
|
childDeviceIds.add(childDeviceId);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue