feat: Implement Allegro Order Sync and Status Management
- Added AllegroOrderSyncStateRepository for managing sync state with Allegro orders. - Introduced AllegroOrdersSyncService to handle the synchronization of orders from Allegro. - Created AllegroStatusDiscoveryService to discover and store order statuses from Allegro. - Developed AllegroStatusMappingRepository for managing status mappings between Allegro and OrderPro. - Implemented AllegroStatusSyncService to facilitate status synchronization. - Added CronSettingsController for managing cron job settings related to Allegro integration.
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
CREATE TABLE IF NOT EXISTS allegro_integration_settings (
|
||||
id TINYINT UNSIGNED NOT NULL PRIMARY KEY,
|
||||
environment VARCHAR(16) NOT NULL DEFAULT 'sandbox',
|
||||
client_id VARCHAR(128) NULL,
|
||||
client_secret_encrypted TEXT NULL,
|
||||
redirect_uri VARCHAR(255) NULL,
|
||||
orders_fetch_enabled TINYINT(1) NOT NULL DEFAULT 0,
|
||||
orders_fetch_start_date DATE NULL,
|
||||
access_token_encrypted MEDIUMTEXT NULL,
|
||||
refresh_token_encrypted MEDIUMTEXT NULL,
|
||||
token_type VARCHAR(32) NULL,
|
||||
token_scope VARCHAR(255) NULL,
|
||||
token_expires_at DATETIME NULL,
|
||||
connected_at DATETIME NULL,
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
KEY allegro_integration_settings_environment_idx (environment),
|
||||
KEY allegro_integration_settings_token_expires_at_idx (token_expires_at)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
INSERT INTO allegro_integration_settings (
|
||||
id, environment, client_id, client_secret_encrypted, redirect_uri, orders_fetch_enabled,
|
||||
orders_fetch_start_date, access_token_encrypted, refresh_token_encrypted, token_type, token_scope,
|
||||
token_expires_at, connected_at, created_at, updated_at
|
||||
)
|
||||
VALUES (
|
||||
1, 'sandbox', NULL, NULL, NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NOW(), NOW()
|
||||
)
|
||||
ON DUPLICATE KEY UPDATE
|
||||
updated_at = VALUES(updated_at);
|
||||
@@ -0,0 +1,74 @@
|
||||
CREATE TABLE IF NOT EXISTS cron_jobs (
|
||||
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
||||
job_type VARCHAR(80) NOT NULL,
|
||||
status ENUM('pending', 'processing', 'completed', 'failed', 'cancelled') NOT NULL DEFAULT 'pending',
|
||||
priority TINYINT UNSIGNED NOT NULL DEFAULT 100,
|
||||
payload JSON NULL,
|
||||
result JSON NULL,
|
||||
attempts SMALLINT UNSIGNED NOT NULL DEFAULT 0,
|
||||
max_attempts SMALLINT UNSIGNED NOT NULL DEFAULT 3,
|
||||
last_error VARCHAR(500) NULL,
|
||||
scheduled_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
started_at DATETIME NULL,
|
||||
completed_at DATETIME NULL,
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
KEY cron_jobs_status_priority_scheduled_idx (status, priority, scheduled_at),
|
||||
KEY cron_jobs_job_type_idx (job_type),
|
||||
KEY cron_jobs_scheduled_at_idx (scheduled_at)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS cron_schedules (
|
||||
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
||||
job_type VARCHAR(80) NOT NULL,
|
||||
interval_seconds INT UNSIGNED NOT NULL,
|
||||
priority TINYINT UNSIGNED NOT NULL DEFAULT 100,
|
||||
max_attempts SMALLINT UNSIGNED NOT NULL DEFAULT 3,
|
||||
payload JSON NULL,
|
||||
enabled TINYINT(1) NOT NULL DEFAULT 1,
|
||||
last_run_at DATETIME NULL,
|
||||
next_run_at DATETIME NULL,
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
UNIQUE KEY cron_schedules_job_type_unique (job_type),
|
||||
KEY cron_schedules_enabled_next_run_idx (enabled, next_run_at)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS app_settings (
|
||||
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
||||
setting_key VARCHAR(120) NOT NULL,
|
||||
setting_value TEXT NULL,
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
UNIQUE KEY app_settings_setting_key_unique (setting_key)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
INSERT INTO app_settings (setting_key, setting_value, created_at, updated_at)
|
||||
VALUES
|
||||
('cron_run_on_web', '0', NOW(), NOW()),
|
||||
('cron_web_limit', '5', NOW(), NOW())
|
||||
ON DUPLICATE KEY UPDATE
|
||||
setting_value = VALUES(setting_value),
|
||||
updated_at = VALUES(updated_at);
|
||||
|
||||
INSERT INTO cron_schedules (
|
||||
job_type, interval_seconds, priority, max_attempts, payload, enabled, last_run_at, next_run_at, created_at, updated_at
|
||||
) VALUES (
|
||||
'allegro_token_refresh',
|
||||
3600,
|
||||
10,
|
||||
3,
|
||||
NULL,
|
||||
1,
|
||||
NULL,
|
||||
NOW(),
|
||||
NOW(),
|
||||
NOW()
|
||||
)
|
||||
ON DUPLICATE KEY UPDATE
|
||||
interval_seconds = VALUES(interval_seconds),
|
||||
priority = VALUES(priority),
|
||||
max_attempts = VALUES(max_attempts),
|
||||
payload = VALUES(payload),
|
||||
enabled = VALUES(enabled),
|
||||
updated_at = VALUES(updated_at);
|
||||
@@ -0,0 +1,10 @@
|
||||
CREATE TABLE IF NOT EXISTS allegro_order_status_mappings (
|
||||
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
||||
allegro_status_code VARCHAR(64) NOT NULL,
|
||||
allegro_status_name VARCHAR(120) NULL,
|
||||
orderpro_status_code VARCHAR(64) NOT NULL,
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
UNIQUE KEY allegro_order_status_mappings_code_unique (allegro_status_code),
|
||||
KEY allegro_order_status_mappings_orderpro_code_idx (orderpro_status_code)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
@@ -0,0 +1,2 @@
|
||||
ALTER TABLE allegro_order_status_mappings
|
||||
MODIFY COLUMN orderpro_status_code VARCHAR(64) NULL;
|
||||
@@ -0,0 +1,39 @@
|
||||
CREATE TABLE IF NOT EXISTS integration_order_sync_state (
|
||||
integration_id INT UNSIGNED NOT NULL PRIMARY KEY,
|
||||
last_synced_order_updated_at DATETIME NULL,
|
||||
last_synced_source_order_id VARCHAR(64) NULL,
|
||||
last_synced_external_order_id VARCHAR(128) NULL,
|
||||
last_run_at DATETIME NULL,
|
||||
last_success_at DATETIME NULL,
|
||||
last_error VARCHAR(500) NULL,
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
ALTER TABLE integration_order_sync_state
|
||||
ADD COLUMN IF NOT EXISTS last_synced_order_updated_at DATETIME NULL AFTER integration_id,
|
||||
ADD COLUMN IF NOT EXISTS last_synced_source_order_id VARCHAR(64) NULL AFTER last_synced_order_updated_at,
|
||||
ADD COLUMN IF NOT EXISTS last_success_at DATETIME NULL AFTER last_run_at,
|
||||
ADD COLUMN IF NOT EXISTS created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP AFTER last_error;
|
||||
|
||||
INSERT INTO cron_schedules (
|
||||
job_type, interval_seconds, priority, max_attempts, payload, enabled, last_run_at, next_run_at, created_at, updated_at
|
||||
) VALUES (
|
||||
'allegro_orders_import',
|
||||
300,
|
||||
20,
|
||||
3,
|
||||
JSON_OBJECT('max_pages', 5, 'page_limit', 50, 'max_orders', 200),
|
||||
1,
|
||||
NULL,
|
||||
NOW(),
|
||||
NOW(),
|
||||
NOW()
|
||||
)
|
||||
ON DUPLICATE KEY UPDATE
|
||||
interval_seconds = VALUES(interval_seconds),
|
||||
priority = VALUES(priority),
|
||||
max_attempts = VALUES(max_attempts),
|
||||
payload = VALUES(payload),
|
||||
enabled = VALUES(enabled),
|
||||
updated_at = VALUES(updated_at);
|
||||
@@ -0,0 +1,29 @@
|
||||
INSERT INTO app_settings (setting_key, setting_value, created_at, updated_at)
|
||||
VALUES
|
||||
('allegro_status_sync_direction', 'allegro_to_orderpro', NOW(), NOW()),
|
||||
('allegro_status_sync_interval_minutes', '15', NOW(), NOW())
|
||||
ON DUPLICATE KEY UPDATE
|
||||
setting_value = VALUES(setting_value),
|
||||
updated_at = VALUES(updated_at);
|
||||
|
||||
INSERT INTO cron_schedules (
|
||||
job_type, interval_seconds, priority, max_attempts, payload, enabled, last_run_at, next_run_at, created_at, updated_at
|
||||
) VALUES (
|
||||
'allegro_status_sync',
|
||||
900,
|
||||
25,
|
||||
3,
|
||||
NULL,
|
||||
1,
|
||||
NULL,
|
||||
NOW(),
|
||||
NOW(),
|
||||
NOW()
|
||||
)
|
||||
ON DUPLICATE KEY UPDATE
|
||||
interval_seconds = VALUES(interval_seconds),
|
||||
priority = VALUES(priority),
|
||||
max_attempts = VALUES(max_attempts),
|
||||
payload = VALUES(payload),
|
||||
enabled = VALUES(enabled),
|
||||
updated_at = VALUES(updated_at);
|
||||
Reference in New Issue
Block a user