feat(fulfillment): 增加 Clean Cutover,历史任务隔离到人工入口

- 新增 flow_version,存量任务回填 1,Cutover 后新任务写 2
- 迁移设置 clean_flow_started_at,按订单支付/创建时间判定
- 自动选号只处理 clean 任务
- 工作台新增历史任务 Tab,历史列表不受订单起算时间限制
- 历史任务不参与自动重试和预售台账同步
- 补充流程边界测试和计划文档
This commit is contained in:
yml
2026-11-24 23:11:13 +08:00
parent 7dec3c4c48
commit aafac6e536
15 changed files with 294 additions and 7 deletions
@@ -525,6 +525,10 @@
"20261124_0131_fulfillment_customer_profile.py": {
"revision": "20261124_0131",
"sha256": "23f8780eb16a689a5f929f3f1e1865e84c0896dbde70be6bbffb0ef77d06d587"
},
"20261124_0132_fulfillment_flow_version.py": {
"revision": "20261124_0132",
"sha256": "c32ae403de640251e4ae8d86bd0948c189c3580141f1454490b4798bb286e3a3"
}
}
}
@@ -0,0 +1,91 @@
"""直播履约 clean/legacy 流程分界。
- 存量任务统一标记为 legacy(flow_version=1);
- 迁移执行时设置 clean_flow_started_at,之后的订单进入 clean 流程;
- 已经是 clean 的任务不会再被自动调度逻辑回退。
"""
from __future__ import annotations
import sqlalchemy as sa
from alembic import op
revision: str = "20261124_0132"
down_revision: str | None = "20261124_0131"
branch_labels: str | None = None
depends_on: str | None = None
TASK_TABLE = "platform_fulfillment_tasks"
SETTINGS_TABLE = "platform_fulfillment_settings"
def _column_exists(table: str, name: str) -> bool:
conn = op.get_bind()
count = conn.execute(
sa.text(
"SELECT COUNT(*) FROM information_schema.columns "
"WHERE table_schema = DATABASE() AND table_name = :table "
"AND column_name = :name"
),
{"table": table, "name": name},
).scalar()
return bool(count)
def _index_exists(table: str, name: str) -> bool:
conn = op.get_bind()
count = conn.execute(
sa.text(
"SELECT COUNT(*) FROM information_schema.statistics "
"WHERE table_schema = DATABASE() AND table_name = :table "
"AND index_name = :name"
),
{"table": table, "name": name},
).scalar()
return bool(count)
def upgrade() -> None:
if not _column_exists(TASK_TABLE, "flow_version"):
op.add_column(
TASK_TABLE,
sa.Column(
"flow_version",
sa.Integer(),
nullable=False,
server_default="1",
),
)
if not _index_exists(TASK_TABLE, "ix_platform_fulfillment_tasks_flow_version"):
op.create_index(
"ix_platform_fulfillment_tasks_flow_version",
TASK_TABLE,
["flow_version"],
)
if not _column_exists(SETTINGS_TABLE, "clean_flow_started_at"):
op.add_column(
SETTINGS_TABLE,
sa.Column("clean_flow_started_at", sa.DateTime(), nullable=True),
)
# 迁移执行时刻就是 Cutover;存量任务已在 flow_version 默认值 1。
op.execute(
sa.text(
"""
UPDATE platform_fulfillment_settings
SET clean_flow_started_at = UTC_TIMESTAMP()
WHERE id = 1 AND clean_flow_started_at IS NULL
"""
)
)
def downgrade() -> None:
if _column_exists(SETTINGS_TABLE, "clean_flow_started_at"):
op.drop_column(SETTINGS_TABLE, "clean_flow_started_at")
if _index_exists(TASK_TABLE, "ix_platform_fulfillment_tasks_flow_version"):
op.drop_index(
"ix_platform_fulfillment_tasks_flow_version",
table_name=TASK_TABLE,
)
if _column_exists(TASK_TABLE, "flow_version"):
op.drop_column(TASK_TABLE, "flow_version")