feat(pdd): 引入拼多多原始订单暂存仓 pdd_raw_orders 与两段式解耦流水线
1. 数据库新增 081_pdd_raw_orders.sql 迁移,创建 pdd_raw_orders 原始暂存表及索引; 2. 新增 pdd-raw-order-repo 仓储,支持原汁原味批量暂存、pending 单据消费、状态回填与重置; 3. 重构 pdd-sync-service 为采集暂存(Staging)与业务进单(Ingestion)两段式解耦流水线,实现断点续传; 4. 管理后台路由接入 raw-orders 原始流水查询及 replay 一键历史单重放 API。
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
-- 081_pdd_raw_orders.sql —— 拼多多原始订单暂存仓与两段式同步支持。
|
||||
|
||||
CREATE TABLE IF NOT EXISTS pdd_raw_orders (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
order_sn TEXT NOT NULL UNIQUE,
|
||||
shop_id TEXT NOT NULL DEFAULT '',
|
||||
shop_name TEXT NOT NULL DEFAULT '',
|
||||
order_status INTEGER NOT NULL DEFAULT 1,
|
||||
order_status_str TEXT NOT NULL DEFAULT '',
|
||||
goods_id TEXT NOT NULL DEFAULT '',
|
||||
goods_name TEXT NOT NULL DEFAULT '',
|
||||
out_sku_sn TEXT NOT NULL DEFAULT '',
|
||||
spec TEXT NOT NULL DEFAULT '',
|
||||
quantity INTEGER NOT NULL DEFAULT 1,
|
||||
order_amount_fen BIGINT NOT NULL DEFAULT 0,
|
||||
buyer_nickname TEXT NOT NULL DEFAULT '',
|
||||
buyer_memo TEXT NOT NULL DEFAULT '',
|
||||
mall_remark TEXT NOT NULL DEFAULT '',
|
||||
order_time TIMESTAMPTZ,
|
||||
confirm_time TIMESTAMPTZ,
|
||||
raw_payload_json JSONB NOT NULL DEFAULT '{}'::jsonb,
|
||||
sync_status TEXT NOT NULL DEFAULT 'pending'
|
||||
CHECK (sync_status IN ('pending', 'synced', 'ignored', 'failed')),
|
||||
sync_error TEXT NOT NULL DEFAULT '',
|
||||
synced_order_id BIGINT REFERENCES orders(id) ON DELETE SET NULL,
|
||||
synced_at TIMESTAMPTZ,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
||||
);
|
||||
|
||||
-- 店铺与订单时间复合索引(用于增量拉单断点极速定位)
|
||||
CREATE INDEX IF NOT EXISTS idx_pdd_raw_orders_shop_order_time
|
||||
ON pdd_raw_orders (shop_id, order_time DESC NULLS LAST);
|
||||
|
||||
-- 待处理订单部分索引(用于业务引擎快速扫描待进单数据)
|
||||
CREATE INDEX IF NOT EXISTS idx_pdd_raw_orders_pending_sync
|
||||
ON pdd_raw_orders (created_at ASC)
|
||||
WHERE sync_status = 'pending';
|
||||
|
||||
-- 商家外部编码索引(用于按 out_sku_sn 快速对账和重放)
|
||||
CREATE INDEX IF NOT EXISTS idx_pdd_raw_orders_out_sku_sn
|
||||
ON pdd_raw_orders (out_sku_sn);
|
||||
|
||||
-- 关联的平台订单索引
|
||||
CREATE INDEX IF NOT EXISTS idx_pdd_raw_orders_synced_order_id
|
||||
ON pdd_raw_orders (synced_order_id)
|
||||
WHERE synced_order_id IS NOT NULL;
|
||||
Reference in New Issue
Block a user