feat(freight-rpa): 增加出站报表配置与回调支持,重构相关服务
- 将 RPA 管理 API 扩展至出站报表配置,新增出站相关的回调接口。 - 重构 freight_rpa_report_config_service,支持入站与出站报表配置的管理。 - 更新 ORM 模型,增加出站报表相关的持久化模型。 - 统一命名规范,确保在手、入站与出站的概念一致性。
This commit is contained in:
1 parent
39fe3c05f2
commit
911afa0f73
152 files changed
+9861
-2984
No files matched your search
@@ -4,7 +4,7 @@ backend/app/models/__init__.py
|
||||
用途:按业务域拆分的 ORM 模型包入口;聚合导出以保持 `from app.models import User` 兼容。
|
||||
依赖:models/* 子模块(含 voucher_check、equipment_acceptance、freight_rpa_*)、app.extensions.db(经 base.Base)。
|
||||
逻辑:Alembic / Flask-Migrate 通过本模块 import 注册全部表元数据;业务代码继续从此处导入模型类。
|
||||
在手/入站模型导出 FreightRpa*。
|
||||
在手/入站/出站模型导出 FreightRpa*。
|
||||
"""
|
||||
|
||||
from app.models.agent import Agent, AgentDirectoryMember, AgentGuide, PermissionRequest
|
||||
@@ -154,11 +154,15 @@ from app.models.freight_rpa_config import (
|
||||
FreightRpaProfile,
|
||||
)
|
||||
from app.models.freight_rpa_inbound_report import (
|
||||
FreightRpaInboundNotificationDelivery,
|
||||
FreightRpaInboundReportConfig,
|
||||
FreightRpaInboundReportFile,
|
||||
FreightRpaInboundUnitRun,
|
||||
)
|
||||
from app.models.freight_rpa_outbound_report import (
|
||||
FreightRpaOutboundReportConfig,
|
||||
FreightRpaOutboundReportFile,
|
||||
FreightRpaOutboundUnitRun,
|
||||
)
|
||||
from app.models.shipping_temporary_onhand import ShippingTemporaryOnhandSession
|
||||
from app.models.shipping_customer import (
|
||||
ShippingBusinessSequence,
|
||||
@@ -378,7 +382,9 @@ __all__ = [
|
||||
'FreightRpaInboundReportConfig',
|
||||
'FreightRpaInboundUnitRun',
|
||||
'FreightRpaInboundReportFile',
|
||||
'FreightRpaInboundNotificationDelivery',
|
||||
'FreightRpaOutboundReportConfig',
|
||||
'FreightRpaOutboundUnitRun',
|
||||
'FreightRpaOutboundReportFile',
|
||||
'FreightRpaOnhandField',
|
||||
'FreightRpaOnhandStructureAnalysis',
|
||||
'FreightRpaOnhandRoutingRule',
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
"""
|
||||
backend/app/models/freight_rpa_config.py
|
||||
|
||||
用途:定义货代库存源、RPA Profile、在手报表配置、通用路由规则及外部系统仓库映射主数据。
|
||||
用途:定义货代库存源、RPA Profile、在手/入站/出站报表配置、通用路由规则及外部系统仓库映射主数据。
|
||||
依赖:models.base.Base、SQLAlchemy ORM;凭据密文由 freight_rpa.common.credential_crypto 读写。
|
||||
逻辑:库存运行链路以 FreightRpaSource.source_code 为业务主键;RPA Profile 仅提供登录连接配置;
|
||||
在手报表路径/查询条件/解析方案绑定自 s18 起归 FreightRpaOnhandReportConfig(站点行不再存这三列),
|
||||
入站/出站配置分别挂 inbound_report_config / outbound_report_config 一对一关系;
|
||||
外部系统映射仅供后端内部复用,不承载调拨决策。
|
||||
"""
|
||||
|
||||
@@ -132,6 +133,9 @@ class FreightRpaSource(Base):
|
||||
inbound_report_config: Mapped[Optional['FreightRpaInboundReportConfig']] = relationship(
|
||||
back_populates='source', uselist=False, cascade='all, delete-orphan',
|
||||
)
|
||||
outbound_report_config: Mapped[Optional['FreightRpaOutboundReportConfig']] = relationship(
|
||||
back_populates='source', uselist=False, cascade='all, delete-orphan',
|
||||
)
|
||||
|
||||
|
||||
class FreightRpaOnhandReportConfig(Base):
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"""
|
||||
backend/app/models/freight_rpa_inbound_report.py
|
||||
|
||||
用途:入站报表 RPA 的配置、运行、归档与通知投递持久化模型。
|
||||
用途:入站报表 RPA 的配置、运行与归档持久化模型(per-file 企微投递表已拆除,见 Task 4 迁移)。
|
||||
依赖:freight_rpa_sources、排程运行、freight_rpa_parsing_profiles、SQLAlchemy Base;完整操作追溯统一写入 ShippingAuditEvent。
|
||||
逻辑:模型只复用站点连接资料,通过独立外键与唯一约束隔离在手快照、匹配和旧 RPA Worker 链路。
|
||||
"""
|
||||
@@ -126,45 +126,3 @@ class FreightRpaInboundReportFile(Base):
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow, nullable=False)
|
||||
|
||||
unit_run: Mapped[FreightRpaInboundUnitRun] = relationship(back_populates='files')
|
||||
deliveries: Mapped[list['FreightRpaInboundNotificationDelivery']] = relationship(
|
||||
back_populates='report_file', cascade='all, delete-orphan',
|
||||
)
|
||||
|
||||
|
||||
class FreightRpaInboundNotificationDelivery(Base):
|
||||
"""收料文件或汇总企微消息的幂等投递事实,响应仅保存脱敏摘要。"""
|
||||
|
||||
__tablename__ = 'freight_rpa_inbound_notification_deliveries'
|
||||
__table_args__ = (
|
||||
UniqueConstraint('idempotency_key', name='uq_freight_rpa_inbound_notification_deliveries_idempotency'),
|
||||
CheckConstraint("message_type IN ('file', 'summary')", name='ck_freight_rpa_inbound_notification_deliveries_type'),
|
||||
CheckConstraint(
|
||||
"status IN ('pending', 'sending', 'success', 'failed')",
|
||||
name='ck_freight_rpa_inbound_notification_deliveries_status',
|
||||
),
|
||||
Index('ix_shipping_receipt_delivery_file_recipient', 'report_file_id', 'recipient_user_id'),
|
||||
Index('ix_shipping_receipt_delivery_unit_created', 'unit_run_id', 'created_at'),
|
||||
# PostgreSQL 标识符上限 63。表名替换后的自动名是 64 字节,故用显式短名。
|
||||
Index('ix_fr_inbound_notif_deliveries_recipient_user_id', 'recipient_user_id'),
|
||||
)
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
unit_run_id: Mapped[Optional[int]] = mapped_column(
|
||||
ForeignKey('freight_rpa_inbound_rpa_unit_runs.id'), nullable=True, index=True,
|
||||
)
|
||||
report_file_id: Mapped[Optional[int]] = mapped_column(
|
||||
ForeignKey('freight_rpa_inbound_report_files.id'), nullable=True, index=True,
|
||||
)
|
||||
recipient_user_id: Mapped[int] = mapped_column(ForeignKey('users.id'), nullable=False)
|
||||
message_type: Mapped[str] = mapped_column(String(16), nullable=False)
|
||||
idempotency_key: Mapped[str] = mapped_column(String(255), nullable=False)
|
||||
status: Mapped[str] = mapped_column(String(16), nullable=False, default='pending', server_default='pending')
|
||||
response_summary_json: Mapped[dict[str, Any]] = mapped_column(JSON, nullable=False, default=dict)
|
||||
error_code: Mapped[Optional[str]] = mapped_column(String(64), nullable=True)
|
||||
error_message: Mapped[Optional[str]] = mapped_column(Text, nullable=True)
|
||||
sent_at: Mapped[Optional[datetime]] = mapped_column(DateTime, nullable=True)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow, nullable=False)
|
||||
updated_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow, nullable=False)
|
||||
|
||||
unit_run: Mapped[Optional[FreightRpaInboundUnitRun]] = relationship(foreign_keys=[unit_run_id])
|
||||
report_file: Mapped[Optional[FreightRpaInboundReportFile]] = relationship(back_populates='deliveries')
|
||||
@@ -0,0 +1,129 @@
|
||||
"""
|
||||
backend/app/models/freight_rpa_outbound_report.py
|
||||
|
||||
用途:出站报表 RPA 的配置、运行与归档持久化模型(不建 per-file 企微投递表)。
|
||||
依赖:freight_rpa_sources、排程运行、freight_rpa_parsing_profiles、SQLAlchemy Base;完整操作追溯统一写入 ShippingAuditEvent。
|
||||
逻辑:模型只复用站点连接资料,通过独立外键与唯一约束隔离在手快照、匹配和旧 RPA Worker 链路。
|
||||
FreightRpaSource.outbound_report_config 一对一回指本配置行。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import datetime
|
||||
from typing import Any, Optional
|
||||
|
||||
from sqlalchemy import CheckConstraint, DateTime, ForeignKey, Index, Integer, JSON, String, Text, UniqueConstraint, text
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from app.models.base import Base
|
||||
|
||||
|
||||
class FreightRpaOutboundReportConfig(Base):
|
||||
"""库存站点的一对一出站报表配置;路径和条件始终独立于库存 / 入站配置。"""
|
||||
|
||||
__tablename__ = 'freight_rpa_outbound_report_configs'
|
||||
__table_args__ = (
|
||||
UniqueConstraint('source_id', name='uq_freight_rpa_outbound_report_configs_source'),
|
||||
)
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
source_id: Mapped[int] = mapped_column(
|
||||
ForeignKey('freight_rpa_sources.id'), nullable=False, index=True,
|
||||
)
|
||||
# 出站不设独立启停:是否运行统一由库存站点 enabled 与本配置是否存在决定。
|
||||
# 出站文件解析规则(purpose='outbound');定死领域字段端点。空则无法解析出站文件。
|
||||
parsing_profile_id: Mapped[Optional[int]] = mapped_column(
|
||||
ForeignKey('freight_rpa_parsing_profiles.id'), nullable=True, index=True,
|
||||
)
|
||||
report_path_json: Mapped[dict[str, Any]] = mapped_column(
|
||||
JSON, default=dict, server_default=text("'{}'"), nullable=False,
|
||||
)
|
||||
query_parameters_json: Mapped[list[dict[str, Any]]] = mapped_column(
|
||||
JSON, default=list, server_default=text("'[]'"), nullable=False,
|
||||
)
|
||||
# 与库存同构:查询条件原样下发 Worker;空条件表示页面默认。排程一源一单元,不按仓拆分。
|
||||
config_version: Mapped[int] = mapped_column(Integer, default=1, server_default=text('1'), nullable=False)
|
||||
created_by: Mapped[Optional[int]] = mapped_column(ForeignKey('users.id'), nullable=True)
|
||||
updated_by: Mapped[Optional[int]] = mapped_column(ForeignKey('users.id'), nullable=True)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow, nullable=False)
|
||||
updated_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow, nullable=False)
|
||||
|
||||
source: Mapped['FreightRpaSource'] = relationship(back_populates='outbound_report_config')
|
||||
parsing_profile: Mapped[Optional['FreightRpaParsingProfile']] = relationship()
|
||||
|
||||
|
||||
class FreightRpaOutboundUnitRun(Base):
|
||||
"""一次出站执行的站点或站点-Warehouse 不可重复执行单元。
|
||||
|
||||
schedule_run_id 指向排程 run;调拨按需触发(重试/预检补抓)无排程,保持 NULL。
|
||||
"""
|
||||
|
||||
__tablename__ = 'freight_rpa_outbound_rpa_unit_runs'
|
||||
__table_args__ = (
|
||||
UniqueConstraint('callback_id', name='uq_freight_rpa_outbound_rpa_unit_runs_callback'),
|
||||
CheckConstraint(
|
||||
"status IN ('queued', 'awaiting_rpa', 'processing', 'success', 'empty', 'failed', 'cancelled')",
|
||||
name='ck_freight_rpa_outbound_rpa_unit_runs_status',
|
||||
),
|
||||
Index('ix_freight_rpa_outbound_unit_run_schedule_status', 'schedule_run_id', 'status'),
|
||||
Index('ix_freight_rpa_outbound_unit_run_source_created', 'source_id', 'created_at'),
|
||||
)
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
schedule_run_id: Mapped[Optional[int]] = mapped_column(ForeignKey('schedule_runs.id'), nullable=True, index=True)
|
||||
source_id: Mapped[int] = mapped_column(ForeignKey('freight_rpa_sources.id'), nullable=False, index=True)
|
||||
retry_of_id: Mapped[Optional[int]] = mapped_column(
|
||||
ForeignKey('freight_rpa_outbound_rpa_unit_runs.id'), nullable=True, index=True,
|
||||
)
|
||||
source_code: Mapped[str] = mapped_column(String(64), nullable=False)
|
||||
connector_type: Mapped[str] = mapped_column(String(32), nullable=False)
|
||||
warehouse_id: Mapped[Optional[str]] = mapped_column(String(64), nullable=True)
|
||||
callback_id: Mapped[str] = mapped_column(String(128), nullable=False)
|
||||
status: Mapped[str] = mapped_column(String(32), nullable=False, default='queued', server_default='queued')
|
||||
config_snapshot_json: Mapped[dict[str, Any]] = mapped_column(JSON, nullable=False, default=dict)
|
||||
trigger_snapshot_json: Mapped[dict[str, Any]] = mapped_column(JSON, nullable=False, default=dict)
|
||||
result_json: Mapped[dict[str, Any]] = mapped_column(JSON, nullable=False, default=dict)
|
||||
error_code: Mapped[Optional[str]] = mapped_column(String(64), nullable=True)
|
||||
error_message: Mapped[Optional[str]] = mapped_column(Text, nullable=True)
|
||||
started_at: Mapped[Optional[datetime]] = mapped_column(DateTime, nullable=True)
|
||||
finished_at: Mapped[Optional[datetime]] = mapped_column(DateTime, nullable=True)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow, nullable=False)
|
||||
|
||||
schedule_run: Mapped[Optional['ScheduleRun']] = relationship(foreign_keys=[schedule_run_id])
|
||||
source: Mapped['FreightRpaSource'] = relationship()
|
||||
retry_of: Mapped[Optional['FreightRpaOutboundUnitRun']] = relationship(remote_side=[id])
|
||||
files: Mapped[list['FreightRpaOutboundReportFile']] = relationship(
|
||||
back_populates='unit_run', cascade='all, delete-orphan',
|
||||
)
|
||||
|
||||
|
||||
class FreightRpaOutboundReportFile(Base):
|
||||
"""出站原样归档文件;保留文件身份和对象清理事实,不关联库存快照。"""
|
||||
|
||||
__tablename__ = 'freight_rpa_outbound_report_files'
|
||||
__table_args__ = (
|
||||
UniqueConstraint('unit_run_id', 'sha256', name='uq_freight_rpa_outbound_report_files_unit_sha256'),
|
||||
CheckConstraint("file_size >= 0", name='ck_freight_rpa_outbound_report_files_size'),
|
||||
Index('ix_freight_rpa_outbound_report_files_unit', 'unit_run_id'),
|
||||
Index('ix_freight_rpa_outbound_report_files_expires', 'archive_expires_at', 'archive_deleted_at'),
|
||||
)
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
unit_run_id: Mapped[int] = mapped_column(ForeignKey('freight_rpa_outbound_rpa_unit_runs.id'), nullable=False, index=True)
|
||||
storage_provider: Mapped[str] = mapped_column(String(32), nullable=False)
|
||||
storage_bucket: Mapped[str] = mapped_column(String(128), nullable=False)
|
||||
storage_key: Mapped[str] = mapped_column(String(1024), nullable=False)
|
||||
original_filename: Mapped[str] = mapped_column(String(255), nullable=False)
|
||||
content_type: Mapped[Optional[str]] = mapped_column(String(128), nullable=True)
|
||||
file_size: Mapped[int] = mapped_column(Integer, nullable=False)
|
||||
sha256: Mapped[str] = mapped_column(String(64), nullable=False)
|
||||
# 解析失败分层标记:归档文件解析失败时写入;三者全空=未失败/已清除。
|
||||
parse_failed_at: Mapped[Optional[datetime]] = mapped_column(DateTime, nullable=True)
|
||||
parse_error_code: Mapped[Optional[str]] = mapped_column(String(64), nullable=True)
|
||||
parse_error_message: Mapped[Optional[str]] = mapped_column(Text, nullable=True)
|
||||
archive_expires_at: Mapped[Optional[datetime]] = mapped_column(DateTime, nullable=True)
|
||||
archive_deleted_at: Mapped[Optional[datetime]] = mapped_column(DateTime, nullable=True)
|
||||
archive_delete_result_json: Mapped[dict[str, Any]] = mapped_column(JSON, nullable=False, default=dict)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow, nullable=False)
|
||||
|
||||
unit_run: Mapped[FreightRpaOutboundUnitRun] = relationship(back_populates='files')
|
||||
Reference in new issue
Block a user