feat(in-transit-transfer): 落地证据流重解析并纳入货代与排程配套改动
外部单号进入异动档自然键,圈档按 T-2 成熟封顶,当前归档可单独重解析。同批带上 Crane 禁整页刷新、ODM 白名单降级、排程抽屉与执行记录日期窗,以及 YAML 库存源下线。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
911afa0f73
commit
4c2a7e2a23
145 files changed
+11695
-4214
No files matched your search
@@ -22,10 +22,12 @@
|
||||
(import 禁令)而保持口径逐位一致。
|
||||
【阶段 B Task 4】站点视图补主键/连接绑定/仓库识别方式与入站配置视图补
|
||||
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 / list_outbound_configured_source_codes)
|
||||
——供 in_transit_transfer 收敛为「只按 source_code / file_id 读取」的只读函数消费面。
|
||||
方案(get_inbound_parsing_profile / get_outbound_parsing_profile)、失效文件
|
||||
存在性(has_expired_inbound_file)、重建通道归档清单
|
||||
(list_reparseable_inbound_files / list_reparseable_outbound_files)、入站/
|
||||
出站可用站点编码清单(list_inbound_configured_source_codes /
|
||||
list_outbound_configured_source_codes)——供 in_transit_transfer 收敛为
|
||||
「只按 source_code / file_id 读取」的只读函数消费面。
|
||||
mark/clear 解析失败只 flush 不 commit——事务提交时机归属调用方。
|
||||
"""
|
||||
|
||||
@@ -44,6 +46,7 @@ from app.models import (
|
||||
FreightRpaInboundReportFile,
|
||||
FreightRpaOnhandReportConfig,
|
||||
FreightRpaOutboundReportConfig,
|
||||
FreightRpaOutboundReportFile,
|
||||
FreightRpaSource,
|
||||
)
|
||||
from app.services.file_assets.storage import file_asset_storage
|
||||
@@ -427,6 +430,34 @@ def get_inbound_parsing_profile(source_code: str) -> InboundProfileView | None:
|
||||
)
|
||||
|
||||
|
||||
def get_outbound_parsing_profile(source_code: str) -> InboundProfileView | None:
|
||||
"""按 source_code 返回出站配置绑定的解析方案只读视图(与入站同形)。
|
||||
|
||||
用途:调拨出站运行期落档(outbound_evidence_sync)与清空重建
|
||||
(backlog_reparse_service record_kind=outbound)读取出站文件解析规则。
|
||||
核心逻辑:站点 → 出站配置 → 配置绑定的解析方案,任一环节缺失返回 None;
|
||||
不校验 status/purpose(调用方按场景自行 fail-closed)。
|
||||
|
||||
Args:
|
||||
source_code: 站点实例编码。
|
||||
Returns:
|
||||
InboundProfileView(字段同入站方案视图);无配置/未绑定/方案缺失返回 None。
|
||||
"""
|
||||
site = FreightRpaSource.query.filter_by(source_code=source_code).first()
|
||||
config = site.outbound_report_config if site is not None else None
|
||||
profile = config.parsing_profile if config is not None else None
|
||||
if profile is None:
|
||||
return None
|
||||
return InboundProfileView(
|
||||
profile_id=profile.id,
|
||||
profile_code=profile.profile_code,
|
||||
version=int(profile.version or 1),
|
||||
status=profile.status,
|
||||
purpose=profile.purpose,
|
||||
definition_json=dict(profile.definition_json or {}),
|
||||
)
|
||||
|
||||
|
||||
def _inbound_file_view(report: FreightRpaInboundReportFile) -> InboundFileView:
|
||||
"""把归档文件 ORM 行映射为冻结只读视图(本模块内唯一映射点,字段增补只改此处)。"""
|
||||
return InboundFileView(
|
||||
@@ -507,6 +538,56 @@ def list_reparseable_inbound_files(source_code: str, *, now: datetime | None = N
|
||||
return [_inbound_file_view(report) for report in reports]
|
||||
|
||||
|
||||
def _outbound_file_view(report: FreightRpaOutboundReportFile) -> InboundFileView:
|
||||
"""出站归档 → 与入站同形的只读视图(重建/投影消费面字段对齐)。"""
|
||||
return InboundFileView(
|
||||
file_id=report.id,
|
||||
source_code=report.unit_run.source_code,
|
||||
sha256=report.sha256,
|
||||
storage_key=report.storage_key,
|
||||
original_filename=report.original_filename,
|
||||
created_at=report.created_at,
|
||||
parse_failed_at=report.parse_failed_at,
|
||||
)
|
||||
|
||||
|
||||
def list_reparseable_outbound_files(source_code: str, *, now: datetime | None = None) -> list[InboundFileView]:
|
||||
"""维护通道:列出某来源全部可重建出站归档(未删除 + 未过保留期),不设当日门禁。
|
||||
|
||||
用途:调拨待匹配桶「清空并重新解析」出站流(backlog_reparse_service
|
||||
record_kind=outbound)按来源取重建清单;与 list_reparseable_inbound_files
|
||||
同口径,禁止与运行期 latest_usable_outbound_file 混用。
|
||||
|
||||
核心逻辑:经出站执行单元行 source_code 过滤;【无当日门禁】;保留期口径
|
||||
archive_expires_at 为空视为长期有效;按 created_at/id 升序。
|
||||
|
||||
Args:
|
||||
source_code: 来源实例编码。
|
||||
now: 保留期判定时刻;缺省当前 UTC。
|
||||
Returns:
|
||||
InboundFileView 列表(created_at 升序;无可重建归档为空表)。
|
||||
"""
|
||||
now = now or datetime.utcnow()
|
||||
reports = (
|
||||
FreightRpaOutboundReportFile.query
|
||||
.join(FreightRpaOutboundReportFile.unit_run)
|
||||
.filter(
|
||||
FreightRpaOutboundReportFile.unit_run.has(source_code=source_code),
|
||||
FreightRpaOutboundReportFile.archive_deleted_at.is_(None),
|
||||
or_(
|
||||
FreightRpaOutboundReportFile.archive_expires_at.is_(None),
|
||||
FreightRpaOutboundReportFile.archive_expires_at > now,
|
||||
),
|
||||
)
|
||||
.order_by(
|
||||
FreightRpaOutboundReportFile.created_at.asc(),
|
||||
FreightRpaOutboundReportFile.id.asc(),
|
||||
)
|
||||
.all()
|
||||
)
|
||||
return [_outbound_file_view(report) for report in reports]
|
||||
|
||||
|
||||
def list_inbound_configured_source_codes() -> list[str]:
|
||||
"""列出已配置入站报表的启用站点编码(调拨排程缺省执行范围)。
|
||||
|
||||
@@ -661,4 +742,61 @@ def clear_inbound_parse_failure(file_id: int) -> None:
|
||||
report.parse_failed_at = None
|
||||
report.parse_error_code = None
|
||||
report.parse_error_message = None
|
||||
db.session.flush()
|
||||
db.session.flush()
|
||||
|
||||
|
||||
def mark_outbound_parse_failure(file_id: int, *, error_code: str, error_message: str) -> None:
|
||||
"""标记一份出站归档文件解析失败(写入解析失败三分层列;与入站同名函数对称)。
|
||||
|
||||
用途:出站归档文件解析(schema/字段校验)失败时把失败事实落到文件上,
|
||||
使来源出站流状态投影为 parse_failed、阻止下游当作 ready 使用
|
||||
(resolve_source_file_status(record_kind='outbound') 同一投影顺序)。
|
||||
核心逻辑:与 mark_inbound_parse_failure 同款(错误码截 64/错误信息截
|
||||
2000/flush 不 commit——事务归属调用方),仅目标表为
|
||||
FreightRpaOutboundReportFile。
|
||||
|
||||
Args:
|
||||
file_id: 出站归档文件主键(须已入库)。
|
||||
error_code: 机器可读错误码,超 64 字符截断(对齐列宽)。
|
||||
error_message: 人类可读错误信息,超 2000 字符截断(Text 列防御性截断)。
|
||||
Returns:
|
||||
None。失败标记随调用方事务落库。
|
||||
Raises:
|
||||
NotFoundError: file_id 对应的出站归档文件不存在。
|
||||
"""
|
||||
report = db.session.get(FreightRpaOutboundReportFile, file_id)
|
||||
if report is None:
|
||||
raise NotFoundError(
|
||||
f"Outbound report file not found: {file_id}",
|
||||
details={'file_id': file_id},
|
||||
)
|
||||
report.parse_failed_at = datetime.utcnow()
|
||||
report.parse_error_code = (error_code or '')[:_PARSE_ERROR_CODE_MAX]
|
||||
report.parse_error_message = (error_message or '')[:_PARSE_ERROR_MESSAGE_MAX]
|
||||
db.session.flush()
|
||||
|
||||
|
||||
def clear_outbound_parse_failure(file_id: int) -> None:
|
||||
"""清除一份出站归档文件的解析失败标记(三列置空),投影恢复 ready。
|
||||
|
||||
用途:同一出站文件重新解析成功后调用;不要在文件已被清理/过期后调用
|
||||
(无业务意义)。与 clear_inbound_parse_failure 同款,仅目标表为
|
||||
FreightRpaOutboundReportFile。
|
||||
|
||||
Args:
|
||||
file_id: 出站归档文件主键(须已入库)。
|
||||
Returns:
|
||||
None。清除随调用方事务落库。
|
||||
Raises:
|
||||
NotFoundError: file_id 对应的出站归档文件不存在。
|
||||
"""
|
||||
report = db.session.get(FreightRpaOutboundReportFile, file_id)
|
||||
if report is None:
|
||||
raise NotFoundError(
|
||||
f"Outbound report file not found: {file_id}",
|
||||
details={'file_id': file_id},
|
||||
)
|
||||
report.parse_failed_at = None
|
||||
report.parse_error_code = None
|
||||
report.parse_error_message = None
|
||||
db.session.flush()
|
||||
Reference in new issue
Block a user