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
@@ -1,7 +1,7 @@
|
||||
"""freight_rpa/reports/__init__.py
|
||||
|
||||
用途:报表读域(阶段 B Task 3)——发货(shipping_notice 域)与在途调拨
|
||||
(in_transit_transfer 域)读取货代 RPA 报表事实的唯一入口包。
|
||||
用途:报表读域——发货(shipping_notice 域)与在途调拨
|
||||
(in_transit_transfer 域)读取货代 RPA 报表事实的唯一入口包(含出站配置视图)。
|
||||
依赖:facts(报表事实与 report kind 白名单)、queries(只读查询与解析失败标记)。
|
||||
逻辑:仅做门面转发;调用方(后续 in_transit_transfer / shipping_notice)
|
||||
一律 import 本包,禁止绕过直接引用 freight_rpa 模型表。
|
||||
@@ -15,12 +15,15 @@ from app.services.freight_rpa.reports.queries import (
|
||||
InboundConfigView,
|
||||
InboundFileView,
|
||||
OnhandConfigView,
|
||||
OutboundConfigView,
|
||||
SiteView,
|
||||
clear_inbound_parse_failure,
|
||||
get_inbound_config,
|
||||
get_onhand_config,
|
||||
get_outbound_config,
|
||||
get_site,
|
||||
latest_usable_inbound_file,
|
||||
list_outbound_configured_source_codes,
|
||||
mark_inbound_parse_failure,
|
||||
read_inbound_file_bytes,
|
||||
usable_inbound_file_condition,
|
||||
@@ -31,13 +34,16 @@ __all__ = [
|
||||
'InboundConfigView',
|
||||
'InboundFileView',
|
||||
'OnhandConfigView',
|
||||
'OutboundConfigView',
|
||||
'ReportFact',
|
||||
'SiteView',
|
||||
'clear_inbound_parse_failure',
|
||||
'get_inbound_config',
|
||||
'get_onhand_config',
|
||||
'get_outbound_config',
|
||||
'get_site',
|
||||
'latest_usable_inbound_file',
|
||||
'list_outbound_configured_source_codes',
|
||||
'mark_inbound_parse_failure',
|
||||
'read_inbound_file_bytes',
|
||||
'require_report_kind',
|
||||
|
||||
@@ -4,8 +4,9 @@
|
||||
终态、再投递事实」的第二段分发(批次 B Task 6)。
|
||||
依赖:app.core.errors.AppError、freight_rpa.reports.facts(ReportFact、
|
||||
require_report_kind)。
|
||||
逻辑:组合根(Task 7 的 shipping_notice.rpa_sinks.register_inbound_sinks /
|
||||
register_onhand_sinks 等)在应用启动时调用 register_report_handler 注入各
|
||||
逻辑:组合根(shipping_notice.rpa_sinks.register_onhand_sinks /
|
||||
in_transit_transfer.rpa_sinks.register_inbound_sinks /
|
||||
register_outbound_sinks)在应用启动时调用 register_report_handler 注入各
|
||||
kind 的业务处理函数;归档入口(如 freight_rpa.inbound.report_archive.
|
||||
ingest_inbound_callback)在每个终态 db.session.commit() 之后调用
|
||||
dispatch_report_fact。kind 未注册时显式 404(FREIGHT_RPA.
|
||||
@@ -33,8 +34,8 @@ def register_report_handler(report_kind: str, handler: Handler) -> None:
|
||||
"""
|
||||
注册一个报表事实处理函数(由组合根在应用启动时调用)。
|
||||
|
||||
【AI 触发时机】:组合根装配(Task 7 的 register_inbound_sinks /
|
||||
register_onhand_sinks)时调用;测试直接调用注入临时处理函数。
|
||||
【AI 触发时机】:组合根装配(register_onhand_sinks / register_inbound_sinks /
|
||||
register_outbound_sinks)时调用;测试直接调用注入临时处理函数。
|
||||
核心逻辑:kind 先经 require_report_kind 白名单校验(onhand / inbound /
|
||||
outbound,非法即 400 fail-closed);同一 kind 重复注册为覆盖。
|
||||
Args:
|
||||
@@ -42,7 +43,7 @@ def register_report_handler(report_kind: str, handler: Handler) -> None:
|
||||
handler: 处理函数(Handler 契约见模块 docstring);本模块只保存引用,
|
||||
不校验其内部行为。
|
||||
Raises:
|
||||
ValidationError: report_kind 不在白名单(code=SHIPPING.RECEIPT_CALLBACK_INVALID)。
|
||||
ValidationError: report_kind 不在白名单(code=SHIPPING.INBOUND_CALLBACK_INVALID)。
|
||||
"""
|
||||
kind = require_report_kind(report_kind)
|
||||
_REPORT_HANDLERS[kind] = handler
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
依赖:app.core.errors.ValidationError(非法 kind 的统一失败出口)。
|
||||
逻辑:本模块是纯契约层(dataclass + 校验函数),不做任何数据库/IO 操作;
|
||||
report kind 只认 onhand / inbound / outbound,非法值抛
|
||||
ValidationError(code='SHIPPING.RECEIPT_CALLBACK_INVALID'),
|
||||
ValidationError(code='SHIPPING.INBOUND_CALLBACK_INVALID'),
|
||||
与收料回调契约共用既有错误码(后续任务 6/7 的回调分发依赖此约定)。
|
||||
本模块不 import shipping_notice / in_transit_transfer。
|
||||
【Task 7 修复轮 2】ReportFact 末位新增可选 unit_run_id——归档入口每次投递
|
||||
@@ -23,7 +23,7 @@ REPORT_KINDS = ('onhand', 'inbound', 'outbound')
|
||||
|
||||
# 非法 report kind 复用收料回调契约错误码:同一回调入口族共享一个客户端可辨识码,
|
||||
# 避免为同一类入参错误分裂出多个近义 code。
|
||||
_INVALID_KIND_ERROR_CODE = 'SHIPPING.RECEIPT_CALLBACK_INVALID'
|
||||
_INVALID_KIND_ERROR_CODE = 'SHIPPING.INBOUND_CALLBACK_INVALID'
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
@@ -53,7 +53,7 @@ def require_report_kind(value: str) -> str:
|
||||
|
||||
用途:构造 ReportFact、注册/分发报表处理器前,把 kind 校验收敛到唯一入口。
|
||||
核心逻辑:value 不在 REPORT_KINDS 白名单(onhand / inbound / outbound)即抛
|
||||
ValidationError(code='SHIPPING.RECEIPT_CALLBACK_INVALID'),fail-closed。
|
||||
ValidationError(code='SHIPPING.INBOUND_CALLBACK_INVALID'),fail-closed。
|
||||
|
||||
Args:
|
||||
value: 待校验的报表种类字符串;空值/大小写敏感不匹配同样视为非法。
|
||||
|
||||
@@ -2,10 +2,11 @@
|
||||
|
||||
用途:本模块是发货与调拨读报表的唯一入口——以只读视图(View dataclass)+
|
||||
解析失败标记的方式,向 in_transit_transfer / shipping_notice 域暴露
|
||||
freight_rpa 报表事实(站点、登录连接、在手/入站报表配置、入站解析方案、
|
||||
freight_rpa 报表事实(站点、登录连接、在手/入站/出站报表配置、入站解析方案、
|
||||
入站归档文件),使消费方不再直接 import freight_rpa 模型表。
|
||||
依赖:app.db、app.models(FreightRpaSource / FreightRpaOnhandReportConfig /
|
||||
FreightRpaInboundReportConfig / FreightRpaInboundReportFile;登录连接
|
||||
FreightRpaInboundReportConfig / FreightRpaOutboundReportConfig /
|
||||
FreightRpaInboundReportFile;登录连接
|
||||
(RpaProfile)与解析方案(ParsingProfile)经站点/配置关系连线引用)、
|
||||
app.core.errors(NotFoundError)、
|
||||
file_assets.storage.file_asset_storage(按 storage_key 读对象字节)。
|
||||
@@ -23,8 +24,8 @@
|
||||
config_id/config_version;新增登录连接(get_rpa_login_profile)、入站解析
|
||||
方案(get_inbound_parsing_profile)、失效文件存在性(has_expired_inbound_
|
||||
file)、重建通道归档清单(list_reparseable_inbound_files)、入站可用站点
|
||||
编码清单(list_inbound_configured_source_codes)——供 in_transit_transfer
|
||||
收敛为「只按 source_code / file_id 读取」的只读函数消费面。
|
||||
编码清单(list_inbound_configured_source_codes / list_outbound_configured_source_codes)
|
||||
——供 in_transit_transfer 收敛为「只按 source_code / file_id 读取」的只读函数消费面。
|
||||
mark/clear 解析失败只 flush 不 commit——事务提交时机归属调用方。
|
||||
"""
|
||||
|
||||
@@ -42,6 +43,7 @@ from app.models import (
|
||||
FreightRpaInboundReportConfig,
|
||||
FreightRpaInboundReportFile,
|
||||
FreightRpaOnhandReportConfig,
|
||||
FreightRpaOutboundReportConfig,
|
||||
FreightRpaSource,
|
||||
)
|
||||
from app.services.file_assets.storage import file_asset_storage
|
||||
@@ -200,6 +202,21 @@ class InboundConfigView:
|
||||
config_version: int = 1
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class OutboundConfigView:
|
||||
"""出站报表配置只读视图(freight_rpa_outbound_report_configs 行),与入站同构。
|
||||
|
||||
config_id / config_version 供调拨出站触发落可审计单元行快照使用,
|
||||
不再引用配置模型。
|
||||
"""
|
||||
|
||||
report_path_json: dict
|
||||
query_parameters_json: list
|
||||
parsing_profile_id: int | None
|
||||
config_id: int = 0
|
||||
config_version: int = 1
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class InboundProfileView:
|
||||
"""入站解析方案只读视图(freight_rpa_parsing_profiles 行)。
|
||||
@@ -321,6 +338,36 @@ def get_inbound_config(source_code: str) -> InboundConfigView | None:
|
||||
)
|
||||
|
||||
|
||||
def get_outbound_config(source_code: str) -> OutboundConfigView | None:
|
||||
"""按 source_code 返回出站报表配置只读视图(与入站配置同构)。
|
||||
|
||||
用途:调拨出站触发读路径取出站报表定义;出站不设独立启停,是否运行由站点
|
||||
enabled 与本配置行是否存在决定。
|
||||
核心逻辑:join 站点表按 source_code 查 freight_rpa_outbound_report_configs 行,
|
||||
命中即映射视图;缺失返回 None。
|
||||
|
||||
Args:
|
||||
source_code: 站点实例编码。
|
||||
Returns:
|
||||
OutboundConfigView;站点或配置不存在返回 None。
|
||||
"""
|
||||
config = (
|
||||
FreightRpaOutboundReportConfig.query
|
||||
.join(FreightRpaSource, FreightRpaOutboundReportConfig.source_id == FreightRpaSource.id)
|
||||
.filter(FreightRpaSource.source_code == source_code)
|
||||
.first()
|
||||
)
|
||||
if config is None:
|
||||
return None
|
||||
return OutboundConfigView(
|
||||
report_path_json=dict(config.report_path_json or {}),
|
||||
query_parameters_json=list(config.query_parameters_json or []),
|
||||
parsing_profile_id=config.parsing_profile_id,
|
||||
config_id=config.id,
|
||||
config_version=int(config.config_version or 1),
|
||||
)
|
||||
|
||||
|
||||
def get_rpa_login_profile(source_code: str) -> RpaLoginProfileView | None:
|
||||
"""按 source_code 返回站点绑定的 RPA 登录连接只读视图。
|
||||
|
||||
@@ -478,6 +525,24 @@ def list_inbound_configured_source_codes() -> list[str]:
|
||||
return [str(code) for (code,) in rows]
|
||||
|
||||
|
||||
def list_outbound_configured_source_codes() -> list[str]:
|
||||
"""列出已配置出站报表的启用站点编码(调拨排程缺省执行范围)。
|
||||
|
||||
用途:在途自动调拨排程 source_codes 留空时的缺省范围
|
||||
(outbound_trigger_service.list_outbound_capable_source_codes 委托本函数)
|
||||
——出站文件只能来自已配置出站报表的启用站点。
|
||||
核心逻辑:站点 join 出站配置行、仅启用站点、按 source_code 排序;只读查询。
|
||||
|
||||
Returns:
|
||||
按 source_code 排序的来源编码列表;无匹配站点时为空列表。
|
||||
"""
|
||||
rows = db.session.query(FreightRpaSource.source_code).join(
|
||||
FreightRpaOutboundReportConfig,
|
||||
FreightRpaOutboundReportConfig.source_id == FreightRpaSource.id,
|
||||
).filter(FreightRpaSource.enabled.is_(True)).order_by(FreightRpaSource.source_code).all()
|
||||
return [str(code) for (code,) in rows]
|
||||
|
||||
|
||||
def latest_usable_inbound_file(
|
||||
source_code: str,
|
||||
*,
|
||||
|
||||
Reference in new issue
Block a user