HieraChain tích hợp với ERP doanh nghiệp (SAP, Oracle, Dynamics) qua adapter và mapping engine. SyncScheduler thăm dò adapter ERP theo interval đã cấu hình, dịch sự kiện ERP gốc thành định dạng sự kiện HieraChain qua EventTranslator, phát hiện thay đổi có ý nghĩa và gửi như sự kiện nghiệp vụ. Lượt đồng bộ lỗi được thử lại với backoff theo hàm mũ.
Quy trình này là cầu nối tiếp nhận giữa hệ thống ERP Web2 truyền thống và sổ cái HieraChain.
Biểu đồ luồng
sequenceDiagram
autonumber
participant ERP as 🏢 Hệ thống ERP (SAP / Oracle)
participant EIL as 🔗 ERPIntegrationLedger
participant ME as 🗺️ MappingEngine
participant CD as 🔄 ChangeDetector
participant ET as 🔀 EventTranslator
participant SS as ⏰ SyncScheduler
participant SC as 📦 SubChain
Note over SS: SyncScheduler kích hoạt theo chu kỳ interval_seconds
SS->>EIL: _execute_sync(profile_name, profile, adapter, chain)
EIL->>ERP: adapter.get_changes_since_last_sync()
ERP-->>EIL: [erp_event_1, erp_event_2, ...]
loop Trên từng sự kiện ERP
EIL->>ME: get_profile(profile_name)
ME-->>EIL: MappingProfile { erp_system, mapping_rules, detect_changes }
alt detect_changes=True
EIL->>CD: detect_changes(erp_event, profile)
CD->>CD: compare_states(previous_state, erp_event)
CD->>CD: Chú thích { change_detected, changes: { field: { old, new, type } } }
CD-->>EIL: Sự kiện erp_event đã được chú thích
end
EIL->>ET: translate(erp_event, mapping_rules)
ET->>ET: Áp dụng ánh xạ trường (đường dẫn đơn hoặc hàm chuyển đổi)
ET->>ET: add_blockchain_metadata()<br/>{ timestamp, event: "erp_integration", source: erp_system }
ET-->>EIL: Từ điển blockchain_event dict
EIL->>SC: add_event(blockchain_event)
Note right of SC: Đi vào đường truyền Gửi Sự kiện (Event Submission)
end
EIL->>SS: update_last_sync(profile_name, now)
SS->>SS: Lên lịch lần chạy tiếp theo (now + interval_seconds)
alt Đồng bộ thất bại
SS->>SS: schedule_retry(profile_name)<br/>Exponential backoff: min(300, 30 × 2^retry_count)
end
Biểu đồ luồng: thử lại khi lỗi
flowchart LR
SYNC["_execute_sync()"] -->|Thành công| UPD["update_last_sync()\nnext = now + interval"]
SYNC -->|Gặp ngoại lệ| RETRY["schedule_retry(profile)\nbackoff = min(300s, 30 × 2^n)"]
RETRY --> WAIT["Đợi hết khoảng chờ backoff"]
WAIT --> SYNC
RETRY -->|retry_count > max| ALERT["Cảnh báo qua Risk Alerts\nLeo thang lỗi đồng bộ"]
Ví dụ chuyển đổi sự kiện ERP
# Sự kiện thô từ SAP (trước khi chuyển đổi)erp_event={"MBLNR":"5000012345",# Số chứng từ vật tư"BUDAT":"2024-04-23",# Ngày ghi sổ"MATNR":"MAT-00789",# Mã vật tư"MENGE":150,# Số lượng"WERKS":"PLANT-01"# Nhà máy}# Sau khi qua EventTranslator.translate() với profile SAPblockchain_event={"entity_id":"MAT-00789",# ánh xạ từ MATNR"event":"erp_integration","timestamp":1714000000.0,# thêm bởi add_blockchain_metadata()"details":{"document_number":"5000012345",# ánh xạ từ MBLNR"posting_date":"2024-04-23",# ánh xạ từ BUDAT"quantity":150,# ánh xạ từ MENGE"plant":"PLANT-01",# ánh xạ từ WERKS"source":"SAP","changes":{# thêm bởi ChangeDetector nếu bật"quantity":{"old":100,"new":150,"type":"numeric_change"}}}}
Hệ thống ERP hỗ trợ
Hệ thống ERP
Lớp Adapter
Khóa cấu hình
SAP S/4HANA
SAPAdapter
erp_system: "SAP"
Oracle ERP Cloud
OracleAdapter
erp_system: "Oracle"
Microsoft Dynamics 365
DynamicsAdapter
erp_system: "Dynamics"
Generic REST
GenericERPAdapter
erp_system: "Generic"
Các bước chi tiết
Bước
Mô tả
1. Kích hoạt lịch
SyncScheduler gọi _execute_sync() cho từng profile đã đăng ký.
2. Đọc thay đổi
Adapter ERP gọi get_changes_since_last_sync() dùng timestamp lần đồng bộ trước.
3. Phát hiện thay đổi
ChangeDetector so sánh trạng thái mới với trạng thái trước, chú thích trường thay đổi.
4. Ánh xạ
EventTranslator áp dụng mapping_rules để tạo sự kiện HieraChain hợp lệ.