feat(16-automated-tasks): moduł zadań automatycznych — CRUD + watcher/executor

Reguły automatyzacji oparte na zdarzeniach (receipt.created) z warunkami
(integracja/kanał sprzedaży, AND logic) i akcjami (wyślij e-mail z 3 trybami
odbiorcy: klient / firma / klient+firma). Trigger w ReceiptController po
utworzeniu paragonu — błąd automatyzacji nie blokuje sukcesu paragonu.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-18 00:39:47 +01:00
parent a6512cbfa4
commit b9f639e037
24 changed files with 4997 additions and 32 deletions

View File

@@ -436,6 +436,43 @@ Migracje z prefiksem `ensure_` to migracje kompensujące — zostały dodane
- `created_at` DATETIME
- Indeksy: `idx_email_logs_template`, `idx_email_logs_mailbox`, `idx_email_logs_order`, `idx_email_logs_status`, `idx_email_logs_sent_at`
### `automation_rules`
- Reguly automatyzacji (zdarzenie -> warunki -> akcje).
- Kolumny:
- `id` INT UNSIGNED PK AUTO_INCREMENT
- `name` VARCHAR(128) NOT NULL — nazwa reguly
- `event_type` VARCHAR(64) NOT NULL — typ zdarzenia (np. 'receipt.created')
- `is_active` TINYINT(1) NOT NULL DEFAULT 1
- `created_at`, `updated_at` DATETIME
- Indeksy:
- `auto_rules_event_active_idx` (`event_type`, `is_active`)
### `automation_conditions`
- Warunki reguly automatyzacji (laczenie logiczne AND).
- Kolumny:
- `id` INT UNSIGNED PK AUTO_INCREMENT
- `rule_id` INT UNSIGNED NOT NULL, FK -> `automation_rules.id` ON DELETE CASCADE
- `condition_type` VARCHAR(64) NOT NULL — typ warunku (np. 'integration')
- `condition_value` JSON NOT NULL — konfiguracja warunku (np. {"integration_ids": [1, 3]})
- `sort_order` SMALLINT UNSIGNED NOT NULL DEFAULT 0
- Indeksy:
- `auto_cond_rule_idx` (`rule_id`)
- Klucze obce:
- `auto_cond_rule_fk`: `rule_id` -> `automation_rules.id` (ON DELETE CASCADE)
### `automation_actions`
- Akcje do wykonania po spelnieniu warunkow reguly.
- Kolumny:
- `id` INT UNSIGNED PK AUTO_INCREMENT
- `rule_id` INT UNSIGNED NOT NULL, FK -> `automation_rules.id` ON DELETE CASCADE
- `action_type` VARCHAR(64) NOT NULL — typ akcji (np. 'send_email')
- `action_config` JSON NOT NULL — konfiguracja akcji (np. {"template_id": 5, "recipient": "client"})
- `sort_order` SMALLINT UNSIGNED NOT NULL DEFAULT 0
- Indeksy:
- `auto_act_rule_idx` (`rule_id`)
- Klucze obce:
- `auto_act_rule_fk`: `rule_id` -> `automation_rules.id` (ON DELETE CASCADE)
## Zasady aktualizacji
- Po kazdej migracji dopisz:
- nowe/zmienione tabele i kolumny,