feat: Implement bidirectional synchronization utilities for Advoware and EspoCRM communications
- Added KommunikationSyncManager class to handle synchronization logic. - Implemented methods for loading data, computing diffs, and applying changes between Advoware and EspoCRM. - Introduced 3-way diffing mechanism to intelligently resolve conflicts. - Added helper methods for creating empty slots and detecting changes in communications. - Enhanced logging for better traceability during synchronization processes.
This commit is contained in:
@@ -178,6 +178,51 @@ results = await asyncio.gather(*tasks, return_exceptions=True)
|
||||
```
|
||||
- ✅ 90% schneller bei 100 Entities
|
||||
|
||||
## Kommunikation-Sync Integration
|
||||
|
||||
### Base64-Marker Strategie ✅
|
||||
|
||||
Die Kommunikation-Synchronisation (Telefon, Email) ist in den Beteiligte-Sync integriert.
|
||||
|
||||
**Marker-Format**:
|
||||
```
|
||||
[ESPOCRM:bWF4QGV4YW1wbGUuY29t:4] Geschäftlich
|
||||
[ESPOCRM-SLOT:4] # Leerer Slot nach Löschung
|
||||
```
|
||||
|
||||
**Base64-Encoding statt Hash**:
|
||||
- **Vorteil**: Bidirektional! Marker enthält den **tatsächlichen Wert** (Base64-kodiert)
|
||||
- **Matching**: Selbst wenn Wert in Advoware ändert, kann alter Wert aus Marker dekodiert werden
|
||||
- **Beispiel**:
|
||||
```python
|
||||
# Advoware: old@example.com → new@example.com
|
||||
# Alter Marker: [ESPOCRM:b2xkQGV4YW1wbGUuY29t:4]
|
||||
# Sync dekodiert: "old@example.com" → Findet Match in EspoCRM ✅
|
||||
# Update: EspoCRM-Eintrag + Marker mit neuem Base64-Wert
|
||||
```
|
||||
|
||||
**Async/Await Architektur** ⚡:
|
||||
- Alle Sync-Methoden sind **async** für Non-Blocking I/O
|
||||
- AdvowareService: Native async (kein `asyncio.run()` mehr)
|
||||
- KommunikationSyncManager: Vollständig async mit proper await
|
||||
- Integration im Webhook-Handler: Seamless async/await flow
|
||||
|
||||
**4-Stufen Typ-Erkennung**:
|
||||
1. **Marker** (höchste Priorität) → `[ESPOCRM:...:3]` = kommKz 3
|
||||
2. **Top-Level Felder** → `beteiligte.mobil` = kommKz 3
|
||||
3. **Wert-Pattern** → `@` in Wert = Email (kommKz 4)
|
||||
4. **Default** → Fallback (TelGesch=1, MailGesch=4)
|
||||
|
||||
**Bidirektionale Sync**:
|
||||
- **Advoware → EspoCRM**: Komplett (inkl. Marker-Update bei Wert-Änderung)
|
||||
- **EspoCRM → Advoware**: Vollständig (CREATE/UPDATE/DELETE via Slots)
|
||||
- **Slot-Wiederverwendung**: Gelöschte Einträge werden als `[ESPOCRM-SLOT:kommKz]` markiert
|
||||
|
||||
**Implementation**:
|
||||
- [kommunikation_mapper.py](../services/kommunikation_mapper.py) - Base64 encoding/decoding
|
||||
- [kommunikation_sync_utils.py](../services/kommunikation_sync_utils.py) - Sync-Manager
|
||||
- Tests: [test_kommunikation_sync_implementation.py](../scripts/test_kommunikation_sync_implementation.py)
|
||||
|
||||
## Performance
|
||||
|
||||
| Operation | API Calls | Latency |
|
||||
|
||||
2536
bitbylaw/docs/KOMMUNIKATION_SYNC_ANALYSE.md
Normal file
2536
bitbylaw/docs/KOMMUNIKATION_SYNC_ANALYSE.md
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user