admin/scripts/order_batch_job_tables.sql
zzh 4f3bbd17bc feat(order): 订单批量任务 RabbitMQ 异步处理与治理 API
引入批量 Job 表、RabbitMQ 队列与消费者,支持导入/小包创建及我的订单批量操作异步化,并提供任务列表、重试失败、取消 pending 与 DLX 监控接口及测试。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-08 09:52:22 +08:00

53 lines
1.9 KiB
SQL
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- 订单批量异步任务表(RabbitMQ 方案)
-- 执行前请确认数据库为 oms
CREATE TABLE IF NOT EXISTS `t_order_batch_job` (
`Id` int NOT NULL AUTO_INCREMENT,
`Action` varchar(64) NOT NULL DEFAULT '',
`Status` varchar(32) NOT NULL DEFAULT 'pending',
`Total` int NOT NULL DEFAULT 0,
`SuccessCount` int NOT NULL DEFAULT 0,
`FailCount` int NOT NULL DEFAULT 0,
`CustomerId` int NULL,
`PayloadJson` json NULL,
`RequestId` varchar(64) NULL,
`StartedAt` datetime NULL,
`FinishedAt` datetime NULL,
`IsDeleted` tinyint(1) NOT NULL DEFAULT 0,
`CreateUserId` int NOT NULL DEFAULT 0,
`CreateTime` datetime NOT NULL,
`UpdateUserId` int NULL,
`UpdateTime` datetime NULL,
PRIMARY KEY (`Id`),
KEY `idx_order_batch_job_request` (`RequestId`),
KEY `idx_order_batch_job_status` (`Status`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE IF NOT EXISTS `t_order_batch_job_item` (
`Id` int NOT NULL AUTO_INCREMENT,
`JobId` int NOT NULL,
`OrderId` int NOT NULL,
`ServiceNo` varchar(64) NULL,
`Action` varchar(64) NOT NULL DEFAULT '',
`Status` varchar(32) NOT NULL DEFAULT 'pending',
`MessageId` varchar(128) NULL,
`FailReason` text NULL,
`RetryCount` int NOT NULL DEFAULT 0,
`StartedAt` datetime NULL,
`FinishedAt` datetime NULL,
`IsDeleted` tinyint(1) NOT NULL DEFAULT 0,
`CreateUserId` int NOT NULL DEFAULT 0,
`CreateTime` datetime NOT NULL,
`UpdateUserId` int NULL,
`UpdateTime` datetime NULL,
PRIMARY KEY (`Id`),
UNIQUE KEY `uk_order_batch_job_item_message` (`MessageId`),
KEY `idx_order_batch_job_item_job` (`JobId`),
KEY `idx_order_batch_job_item_order` (`OrderId`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
-- 阶段三:若表已存在,请执行
-- ALTER TABLE `t_order_batch_job_item` ADD COLUMN `ResultJson` text NULL AFTER `FailReason`;
-- 阶段四:若表已存在,请执行
-- ALTER TABLE `t_order_batch_job_item` ADD COLUMN `PayloadJson` text NULL AFTER `FailReason`;