feat(shipping-notice): 完善发货通知自动推进与多库存源复核闭环

This commit is contained in:
hugo committed 2026-08-09 11:43:53 +08:00
1 parent cfa19a0b7b
commit 8e0bbf7a81
180 files changed
+31210 -1864

No files matched your search

+51
View File
@@ -30,6 +30,25 @@ class Job(Base):
Index('ix_jobs_business_ref', 'domain', 'job_type', 'business_ref'),
Index('ix_jobs_locked_at', 'locked_at'),
Index('ix_jobs_retry_of_job_id', 'retry_of_job_id'),
# P0-3:同一 Task 同时只允许一个正式 AutoProgress 决策 Job。库存源 RPA
# Attempt 不使用该索引,因此可以按 source 并行执行。
Index(
'uq_jobs_shipping_auto_progress_one_active_task',
'task_id',
unique=True,
postgresql_where=text(
"domain = 'shipping_notice' "
"AND job_type = 'shipping_auto_progress' "
"AND status IN ('queued', 'running') "
"AND task_id IS NOT NULL"
),
sqlite_where=text(
"domain = 'shipping_notice' "
"AND job_type = 'shipping_auto_progress' "
"AND status IN ('queued', 'running') "
"AND task_id IS NOT NULL"
),
),
# 仅预解析 Job:同业务锚点同时只允许一条 queued
# (不含 running:retry 可在旧 running 残留时另建 queued;RUN 复查也不受限)
Index(
@@ -101,6 +120,26 @@ class Job(Base):
"AND business_ref IS NOT NULL"
),
),
# Review Revalidate Job:同 Case 同时只允许一条 queued/running(failed 可新建重试 Job)
Index(
'uq_jobs_shipping_review_revalidate_progress_active_ref',
'domain',
'job_type',
'business_ref',
unique=True,
postgresql_where=text(
"domain = 'shipping_notice' "
"AND job_type = 'shipping_review_revalidate_progress' "
"AND status IN ('queued', 'running') "
"AND business_ref IS NOT NULL"
),
sqlite_where=text(
"domain = 'shipping_notice' "
"AND job_type = 'shipping_review_revalidate_progress' "
"AND status IN ('queued', 'running') "
"AND business_ref IS NOT NULL"
),
),
)
id: Mapped[int] = mapped_column(primary_key=True)
@@ -120,6 +159,18 @@ class Job(Base):
locked_at: Mapped[Optional[datetime]] = mapped_column(DateTime)
# 重试链:新 Job 指向被替换的 failed/dead Job,保留旧行审计。
retry_of_job_id: Mapped[Optional[int]] = mapped_column(ForeignKey('jobs.id'), nullable=True)
# 正式编排作用域。payload 仍保留相同 identity,列用于数据库唯一约束、恢复扫描和审计查询。
task_id: Mapped[Optional[int]] = mapped_column(ForeignKey('shipping_notices.id'), nullable=True, index=True)
execution_id: Mapped[Optional[int]] = mapped_column(
ForeignKey('shipping_process_executions.id'), nullable=True, index=True,
)
gate_id: Mapped[Optional[int]] = mapped_column(
ForeignKey('shipping_process_gates.id'), nullable=True, index=True,
)
candidate_set_id: Mapped[Optional[int]] = mapped_column(
ForeignKey('shipping_inventory_candidate_sets.id'), nullable=True, index=True,
)
fencing_token: Mapped[Optional[str]] = mapped_column(String(64), nullable=True, index=True)
created_by_id: Mapped[Optional[int]] = mapped_column(ForeignKey('users.id'))
created_at: Mapped[datetime] = mapped_column(default=datetime.utcnow)
updated_at: Mapped[datetime] = mapped_column(default=datetime.utcnow, onupdate=datetime.utcnow)