feat(uns): lazy per-equipment tag + virtual-tag load
Add LoadEquipmentChildrenAsync to IUnsTreeService and UnsTreeService; returns
Tag nodes (ordered by Name) then VirtualTag nodes (ordered by Name) as leaf
nodes with ChildCount=0, HasLazyChildren=false, keys tag:{id}/vtag:{id}.
This commit is contained in:
@@ -76,4 +76,49 @@ public sealed class UnsTreeService(IDbContextFactory<OtOpcUaConfigDbContext> dbF
|
||||
|
||||
return UnsTreeAssembly.Build(clusters, areas, lines, equipment);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<IReadOnlyList<UnsNode>> LoadEquipmentChildrenAsync(
|
||||
string equipmentId,
|
||||
CancellationToken ct = default)
|
||||
{
|
||||
await using var db = await dbFactory.CreateDbContextAsync(ct);
|
||||
|
||||
var tagNodes = await db.Tags
|
||||
.AsNoTracking()
|
||||
.Where(t => t.EquipmentId == equipmentId)
|
||||
.OrderBy(t => t.Name)
|
||||
.Select(t => new UnsNode
|
||||
{
|
||||
Kind = UnsNodeKind.Tag,
|
||||
Key = $"tag:{t.TagId}",
|
||||
DisplayName = $"{t.Name} ({t.DataType})",
|
||||
EntityId = t.TagId,
|
||||
ClusterId = null,
|
||||
ChildCount = 0,
|
||||
HasLazyChildren = false,
|
||||
})
|
||||
.ToListAsync(ct);
|
||||
|
||||
var vtagNodes = await db.VirtualTags
|
||||
.AsNoTracking()
|
||||
.Where(v => v.EquipmentId == equipmentId)
|
||||
.OrderBy(v => v.Name)
|
||||
.Select(v => new UnsNode
|
||||
{
|
||||
Kind = UnsNodeKind.VirtualTag,
|
||||
Key = $"vtag:{v.VirtualTagId}",
|
||||
DisplayName = $"{v.Name} (VirtualTag)",
|
||||
EntityId = v.VirtualTagId,
|
||||
ClusterId = null,
|
||||
ChildCount = 0,
|
||||
HasLazyChildren = false,
|
||||
})
|
||||
.ToListAsync(ct);
|
||||
|
||||
var result = new List<UnsNode>(tagNodes.Count + vtagNodes.Count);
|
||||
result.AddRange(tagNodes);
|
||||
result.AddRange(vtagNodes);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user