Entity Views

Chia sẻ có kiểm soát dữ liệu thiết bị với nhiều customer — giới hạn key, thời gian, và quyền truy cập

Entity Views

Entity View hoạt động như "database view" — cho phép chia sẻ một phần dữ liệu của thiết bị hoặc asset với customer cụ thể, mà không cần cấp quyền truy cập toàn bộ.

Vấn đề Entity View giải quyết

Giả sử một thiết bị đo lường trong kho thuộc nhiều khách hàng:

Device: Temperature-Monitor-01 - temperature → Khách hàng A cần xem - humidity → Khách hàng B cần xem - battery → Chỉ admin biết (ẩn với khách hàng) - error_code → Nội bộ (ẩn với tất cả)

Với Entity View:

  • Customer A chỉ thấy temperature
  • Customer B chỉ thấy humidity
  • Cùng thiết bị vật lý, dữ liệu không bị sao chép

Tạo Entity View

Entity Views > Create new Entity View:

TrườngMô tả
NameTên view (hiển thị với customer)
TypePhân loại (tùy chọn)
Target entityDevice hoặc Asset gốc
CustomerCustomer được phép truy cập

Giới hạn thời gian truy cập

Start time: 2024-01-01 00:00:00 (optional) End time: 2024-12-31 23:59:59 (optional)

Hữu ích khi chia sẻ dữ liệu theo hợp đồng có thời hạn.

Whitelist keys

Telemetry keys: temperature, humidity Attribute keys: location, model

Chỉ các key trong whitelist mới được trả về khi customer query.


Đồng bộ Attributes

Attributes không tự động đồng bộ — cần dùng rule node Copy to View:

Rule Chain:

[Attributes Updated] → [Save Attributes] → [Copy to View]

Hoặc tick "Update attributes and telemetry" khi tạo/sửa Entity View (đồng bộ một lần).


Truy vấn từ Customer

Customer thấy Entity View giống như thiết bị thật trong danh sách. Mọi API call đều dùng Entity View ID:

GET /api/plugins/telemetry/ENTITY_VIEW/{viewId}/values/timeseries ?keys=temperature&startTs=...&endTs=...

Response chỉ trả về key trong whitelist, trong khoảng thời gian đã cấu hình.


Use cases

1. SaaS multi-tenant

Thiết bị vật lý: 1 server monitor ├── Entity View "CPU View" → Customer A (chỉ cpu_usage) ├── Entity View "Memory View" → Customer B (chỉ memory_usage) └── Entity View "Full View" → Admin (tất cả metrics)

2. Device-as-a-Service

Máy bán hàng: 1 thiết bị, 2 khách thuê ├── Entity View tháng 1 (01/2024 - 31/01/2024) → Công ty A └── Entity View tháng 2 (01/2024 - 28/02/2024) → Công ty B

3. Sensor chia sẻ

Trạm đo thời tiết công cộng: ├── Entity View → Công ty nông nghiệp (nhiệt độ, độ ẩm đất) ├── Entity View → Sân bay (gió, tầm nhìn) └── Entity View → Đài khí tượng (tất cả sensors)

API

POST /api/entityView ← Tạo entity view GET /api/entityView/{id} ← Xem chi tiết PUT /api/entityView ← Cập nhật DELETE /api/entityView/{id} ← Xóa GET /api/entityViews?pageSize=10&page=0 ← Danh sách GET /api/customer/{customerId}/entityViews ← Theo customer

JSON format

{ "name": "Customer Temperature View", "type": "temperature-monitor", "entityId": { "id": "device-uuid-here", "entityType": "DEVICE" }, "customerId": { "id": "customer-uuid-here", "entityType": "CUSTOMER" }, "startTimeMs": 1704067200000, "endTimeMs": 1735689600000, "keys": { "timeseries": ["temperature", "humidity"], "attributes": { "cs": [], "ss": ["location", "model"], "sh": [] } } }

Lưu ý

  • Dữ liệu không bị sao chép — chỉ filtered view
  • Customer không biết Entity View đến từ thiết bị nào
  • Entity View bị xóa không ảnh hưởng thiết bị gốc
  • Một thiết bị có thể có nhiều Entity View khác nhau