feat(freight-rpa): 库存/收料改名在手/入站,报表归属RPA,类名统一FreightRpa
把 shipping 侧 inventory/receipt 词根迁到 onhand/inbound,29 张表与 枚举/权限/前端/i18n 同步改名;在手与入站报表配置及文件改由 freight_rpa 持有,发货与调拨仅按 source_code 消费;ORM 类加 FreightRpa 前缀, 上传动作改为 freight_rpa_upload。含类名与上传动作改名规格文档。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
ffc0d4a430
commit
39fe3c05f2
453 files changed
+17945
-8646
No files matched your search
@@ -4,19 +4,24 @@ services/freight_rpa/inbound/report_archive.py
|
||||
用途:inbound(入站,原收料)RPA 产物事实能力——Worker 回调的原样归档(xlsx 落 MinIO、
|
||||
三年保留期、不写库存快照表)、到期对象清理(retention)、单文件企微投递与管理员
|
||||
强制重发(resend)。批次 R Task 10 自 shipping_notice.receipt_report_storage /
|
||||
schedule.freight_inbound_rpa_retention / shipping_notice.receipt_report_notification
|
||||
平移而来(函数名 receipt 词根→inbound;模型 ShippingReceiptReport* 引用不变——批次 S 才改表)。
|
||||
依赖:models(ShippingReceiptReportFile / ShippingReceiptRpaUnitRun / ShippingReceiptNotificationDelivery /
|
||||
schedule.freight_rpa_inbound_retention / shipping_notice.receipt_report_notification
|
||||
平移而来(函数名 receipt 词根→inbound;模型 ShippingInboundReport* 引用不变——批次 S 才改表)。
|
||||
依赖:models(FreightRpaInboundReportFile / FreightRpaInboundUnitRun / FreightRpaInboundNotificationDelivery /
|
||||
User / ScheduleRun 相关模型经行对象访问)、file_assets.storage、integrations.wecom.notify、
|
||||
freight_rpa.inbound.trigger_io(回调 SCHEMA 与 drop 根)、
|
||||
shipping_notice.audit_service(适应度测试白名单内,本模块唯一 shipping_notice 业务依赖,
|
||||
见 tests/services/freight_rpa/test_import_boundary.py)。
|
||||
freight_rpa.common.report_audit(本域唯一审计写入口,批次 B Task 6 起替代
|
||||
shipping_notice.audit_service——freight_rpa 禁止 import shipping_notice 业务模块,
|
||||
边界由 tests/services/freight_rpa/test_import_boundary.py 空白名单锁定)、
|
||||
freight_rpa.reports.facts / reports.dispatch(ReportFact 事实投递,Task 6)。
|
||||
逻辑:Worker 回调进入 /api/freight-rpa/inbound-batch-ready 后由组合根注册的业务 sink
|
||||
(shipping_notice.rpa_sinks.register_inbound_sinks)调 ingest_inbound_callback 完成原样归档,
|
||||
empty/success/failed 三个终态分支各自 commit;终态落库后的业务桥(推进在途调拨来源任务、
|
||||
调拨证据同步)与排程终态归集(finalize)经 on_terminal 钩子回调 shipping_notice 侧实现,
|
||||
本模块不 import 任何桥与 finalize——依赖方向保持 shipping_notice → freight_rpa,
|
||||
与拆分前「归档 commit 后立刻推桥」的调用顺序逐点一致。
|
||||
empty/success/failed 三个终态分支各自「先 db.session.commit() 再投递事实」——
|
||||
commit 后构造 ReportFact(report_kind='inbound', ...) 调 dispatch_report_fact;
|
||||
处理函数异常原样外抛(不吞、不回滚已提交终态),kind 未注册时 404
|
||||
FREIGHT_RPA.SINK_NOT_REGISTERED;同一 unit_run_id + sha256 已有文件时不插第二行、
|
||||
仍投递 ok=True 的事实供处理函数重试。业务收尾(推进在途调拨来源任务、调拨证据
|
||||
同步、排程终态归集)改由 Task 7 的处理函数(handle_inbound_report 等)承担,
|
||||
本模块不 import 任何桥与 finalize——依赖方向保持 shipping_notice → freight_rpa。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -24,26 +29,24 @@ from __future__ import annotations
|
||||
import hashlib
|
||||
from datetime import datetime, timedelta
|
||||
from pathlib import Path
|
||||
from typing import Any, Callable
|
||||
from typing import Any
|
||||
|
||||
from flask import current_app
|
||||
|
||||
from app import db
|
||||
from app.core.errors import NotFoundError, ValidationError
|
||||
from app.models import (
|
||||
ShippingReceiptNotificationDelivery,
|
||||
ShippingReceiptReportFile,
|
||||
ShippingReceiptRpaUnitRun,
|
||||
FreightRpaInboundNotificationDelivery,
|
||||
FreightRpaInboundReportFile,
|
||||
FreightRpaInboundUnitRun,
|
||||
User,
|
||||
)
|
||||
from app.services.file_assets.storage import file_asset_storage
|
||||
from app.services.freight_rpa.common.report_audit import append_rpa_report_event
|
||||
from app.services.freight_rpa.inbound.trigger_io import SCHEMA as INBOUND_TRIGGER_SCHEMA, inbound_drop_dir
|
||||
from app.services.freight_rpa.reports.dispatch import dispatch_report_fact
|
||||
from app.services.freight_rpa.reports.facts import ReportFact
|
||||
from app.services.integrations.wecom.notify import send_wecom_file_message, upload_wecom_temp_media
|
||||
from app.services.shipping_notice.audit_service import append_shipping_audit_event
|
||||
|
||||
# 终态落库后的业务收尾钩子:由 shipping_notice 域注入(推进在途调拨来源任务 + 调拨证据同步
|
||||
# + 排程终态归集),契约 = 原 storage.ingest_receipt_callback 中「commit 之后的桥/finalize 尾巴」。
|
||||
InboundTerminalHook = Callable[..., None]
|
||||
|
||||
|
||||
def _read_inbound_callback_file(file_path: str) -> bytes:
|
||||
@@ -73,21 +76,29 @@ def _read_inbound_callback_file(file_path: str) -> bytes:
|
||||
return path.read_bytes()
|
||||
|
||||
|
||||
def ingest_inbound_callback(payload: dict[str, Any], *, on_terminal: InboundTerminalHook) -> dict[str, Any]:
|
||||
def ingest_inbound_callback(payload: dict[str, Any]) -> dict[str, Any]:
|
||||
"""幂等接收单个 inbound 单元回调,原样归档三年且不写库存快照表。
|
||||
|
||||
Args:
|
||||
payload: Worker 回调载荷(schema_version/callback_id/status/file_path/...)。
|
||||
on_terminal: 必填业务收尾钩子(shipping_notice 域注入,见模块 docstring);在每个终态
|
||||
分支 commit 之后、以与拆分前完全一致的实参被调用——
|
||||
empty/failed: on_terminal(unit, ok=False, error_code=..., error_message=...);
|
||||
success: on_terminal(unit, ok=True, file_no=..., file_sha256=...)。
|
||||
业务约束:钩子内部异常只记日志,绝不回滚归档终态(契约由实现方保持)。
|
||||
Returns:
|
||||
dict: unit_run_id/status[/file_id/idempotent],与拆分前逐键一致(API envelope 契约)。
|
||||
Raises:
|
||||
ValidationError: 载荷非法(schema/callback_id/sha256/文件路径)——commit 之前抛出,不投递事实。
|
||||
NotFoundError: callback_id 无匹配单元——commit 之前抛出,不投递事实。
|
||||
AppError: 终态已 commit 后 kind 未注册处理函数(FREIGHT_RPA.SINK_NOT_REGISTERED, 404)。
|
||||
业务顺序(Task 6 契约):每个终态分支先 db.session.commit() 再构造
|
||||
ReportFact(report_kind='inbound', source_code=unit.source_code, ...) 调
|
||||
dispatch_report_fact;事实恒带 unit_run_id=unit.id(Task 7 修复轮 2——
|
||||
含 failure/empty 与幂等重放,处理函数据此精确定位本单元的排程 run);
|
||||
处理函数异常原样外抛(不吞、不回滚已提交终态);
|
||||
同一 unit_run_id + sha256 已有文件时不插第二行,仍投递 ok=True 的事实
|
||||
(供处理函数重试)。落 MinIO / 插行失败时事务回滚,同样不投递。
|
||||
"""
|
||||
if payload.get('schema_version') != INBOUND_TRIGGER_SCHEMA:
|
||||
raise ValidationError('receipt callback schema_version is invalid', code='SHIPPING.RECEIPT_CALLBACK_INVALID')
|
||||
callback_id = str(payload.get('callback_id') or '').strip()
|
||||
unit = ShippingReceiptRpaUnitRun.query.filter_by(callback_id=callback_id).one_or_none()
|
||||
unit = FreightRpaInboundUnitRun.query.filter_by(callback_id=callback_id).one_or_none()
|
||||
if unit is None:
|
||||
raise NotFoundError('Receipt RPA unit not found', code='SHIPPING.RECEIPT_UNIT_NOT_FOUND')
|
||||
status = str(payload.get('status') or '').strip().lower()
|
||||
@@ -98,8 +109,8 @@ def ingest_inbound_callback(payload: dict[str, Any], *, on_terminal: InboundTerm
|
||||
unit.error_code = str(payload.get('error_code') or 'no_receipt_data')[:64]
|
||||
unit.error_message = str(payload.get('error_message') or 'no_receipt_data')[:2000]
|
||||
unit.finished_at = datetime.utcnow()
|
||||
append_shipping_audit_event(
|
||||
event_type='shipping_receipt_rpa_callback_received', aggregate_type='shipping_receipt_unit',
|
||||
append_rpa_report_event(
|
||||
event_type='shipping_inbound_rpa_callback_received', aggregate_type='shipping_inbound_unit',
|
||||
aggregate_id=str(unit.id), run_no=unit.schedule_run.run_no if unit.schedule_run else None,
|
||||
actor_type='rpa', actor_id='receipt-worker', unit_id=unit.id, result='success',
|
||||
before=before,
|
||||
@@ -111,46 +122,67 @@ def ingest_inbound_callback(payload: dict[str, Any], *, on_terminal: InboundTerm
|
||||
},
|
||||
metadata={'callback_status': status, 'skip_reason': unit.error_code},
|
||||
)
|
||||
# [STEP] 先 commit 终态,再投递 ok=False 事实(Task 6 顺序契约);unit_run_id
|
||||
# 自单元行回填(Task 7 修复轮 2——处理函数据此精确收口本单元的排程 run)。
|
||||
db.session.commit()
|
||||
on_terminal(
|
||||
unit, ok=False, error_code=unit.error_code or 'no_receipt_data',
|
||||
dispatch_report_fact(ReportFact(
|
||||
report_kind='inbound', source_code=unit.source_code, file_id=None, sha256=None, ok=False,
|
||||
error_code=unit.error_code or 'no_receipt_data',
|
||||
error_message=unit.error_message or 'no_receipt_data',
|
||||
)
|
||||
unit_run_id=unit.id,
|
||||
))
|
||||
return {'unit_run_id': unit.id, 'status': 'empty'}
|
||||
if status != 'success':
|
||||
unit.status = 'failed'; unit.error_code = str(payload.get('error_code') or 'RPA.RECEIPT_EXPORT_FAILED')[:64]; unit.error_message = str(payload.get('error_message') or 'receipt export failed')[:2000]; unit.finished_at = datetime.utcnow()
|
||||
append_shipping_audit_event(
|
||||
event_type='shipping_receipt_rpa_callback_received', aggregate_type='shipping_receipt_unit',
|
||||
append_rpa_report_event(
|
||||
event_type='shipping_inbound_rpa_callback_received', aggregate_type='shipping_inbound_unit',
|
||||
aggregate_id=str(unit.id), run_no=unit.schedule_run.run_no if unit.schedule_run else None,
|
||||
actor_type='rpa', actor_id='receipt-worker', unit_id=unit.id, result='failure',
|
||||
before=before, after={'status': 'failed', 'error_code': unit.error_code, 'error_message': unit.error_message},
|
||||
metadata={'callback_status': status},
|
||||
)
|
||||
# [STEP] 先 commit 终态,再投递 ok=False 事实(Task 6 顺序契约);unit_run_id
|
||||
# 自单元行回填(Task 7 修复轮 2——处理函数据此精确收口本单元的排程 run)。
|
||||
db.session.commit()
|
||||
on_terminal(unit, ok=False, error_code=unit.error_code, error_message=unit.error_message)
|
||||
dispatch_report_fact(ReportFact(
|
||||
report_kind='inbound', source_code=unit.source_code, file_id=None, sha256=None, ok=False,
|
||||
error_code=unit.error_code, error_message=unit.error_message,
|
||||
unit_run_id=unit.id,
|
||||
))
|
||||
return {'unit_run_id': unit.id, 'status': 'failed'}
|
||||
data = _read_inbound_callback_file(str(payload.get('file_path') or ''))
|
||||
sha256 = hashlib.sha256(data).hexdigest()
|
||||
claimed = str(payload.get('sha256') or '').lower()
|
||||
if claimed and claimed != sha256:
|
||||
raise ValidationError('receipt callback sha256 mismatch', code='SHIPPING.RECEIPT_CALLBACK_SHA_MISMATCH')
|
||||
existing = ShippingReceiptReportFile.query.filter_by(unit_run_id=unit.id, sha256=sha256).one_or_none()
|
||||
existing = FreightRpaInboundReportFile.query.filter_by(unit_run_id=unit.id, sha256=sha256).one_or_none()
|
||||
if existing:
|
||||
# [STEP] 幂等重放:不插第二行,仍投递 ok=True 事实(同一 file_id),供处理函数重试;
|
||||
# unit_run_id 自单元行回填(Task 7 修复轮 2)。
|
||||
dispatch_report_fact(ReportFact(
|
||||
report_kind='inbound', source_code=unit.source_code, file_id=existing.id, sha256=sha256, ok=True,
|
||||
unit_run_id=unit.id,
|
||||
))
|
||||
return {'unit_run_id': unit.id, 'status': unit.status, 'file_id': existing.id, 'idempotent': True}
|
||||
filename = Path(str(payload.get('original_filename') or payload.get('file_path') or 'receipt.xlsx')).name
|
||||
storage_key = f'shipping/receipt-reports/{datetime.utcnow():%Y/%m}/{unit.id}/{sha256}.xlsx'
|
||||
file_asset_storage.upload_bytes(storage_key=storage_key, data=data, content_type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
|
||||
record = ShippingReceiptReportFile(unit_run_id=unit.id, storage_provider='minio', storage_bucket=file_asset_storage.bucket_name, storage_key=storage_key, original_filename=filename, content_type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', file_size=len(data), sha256=sha256, archive_expires_at=datetime.utcnow() + timedelta(days=365 * 3))
|
||||
record = FreightRpaInboundReportFile(unit_run_id=unit.id, storage_provider='minio', storage_bucket=file_asset_storage.bucket_name, storage_key=storage_key, original_filename=filename, content_type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', file_size=len(data), sha256=sha256, archive_expires_at=datetime.utcnow() + timedelta(days=365 * 3))
|
||||
db.session.add(record)
|
||||
unit.status = 'success'; unit.finished_at = datetime.utcnow()
|
||||
db.session.flush()
|
||||
append_shipping_audit_event(event_type='shipping_receipt_report_archived', aggregate_type='shipping_receipt_unit', aggregate_id=str(unit.id), run_no=unit.schedule_run.run_no if unit.schedule_run else None, actor_type='rpa', actor_id='receipt-worker', unit_id=unit.id, result='success', before=before, after={'status': 'success', 'source_run_no': unit.callback_id, 'file_id': record.id, 'sha256': sha256, 'file_size': len(data)}, artifact_refs=[{'kind': 'receipt_report', 'id': str(record.id), 'sha256': sha256}], metadata={'file_size': len(data), 'retention_days': 365 * 3})
|
||||
append_rpa_report_event(event_type='shipping_inbound_report_archived', aggregate_type='shipping_inbound_unit', aggregate_id=str(unit.id), run_no=unit.schedule_run.run_no if unit.schedule_run else None, actor_type='rpa', actor_id='receipt-worker', unit_id=unit.id, result='success', before=before, after={'status': 'success', 'source_run_no': unit.callback_id, 'file_id': record.id, 'sha256': sha256, 'file_size': len(data)}, artifact_refs=[{'kind': 'receipt_report', 'id': str(record.id), 'sha256': sha256}], metadata={'file_size': len(data), 'retention_days': 365 * 3})
|
||||
# [STEP] 先 commit 归档,再投递 ok=True 事实(Task 6 顺序契约);unit_run_id
|
||||
# 自单元行回填(Task 7 修复轮 2——处理函数据此精确收口本单元的排程 run)。
|
||||
db.session.commit()
|
||||
on_terminal(unit, ok=True, file_no=str(record.id), file_sha256=sha256)
|
||||
dispatch_report_fact(ReportFact(
|
||||
report_kind='inbound', source_code=unit.source_code, file_id=record.id, sha256=sha256, ok=True,
|
||||
unit_run_id=unit.id,
|
||||
))
|
||||
return {'unit_run_id': unit.id, 'status': 'success', 'file_id': record.id, 'idempotent': False}
|
||||
|
||||
|
||||
def run_freight_inbound_rpa_retention_schedule(task: Any, run: Any) -> tuple[int, int, int, int, list[dict], list[str], list[dict]]:
|
||||
def run_freight_rpa_inbound_retention_schedule(task: Any, run: Any) -> tuple[int, int, int, int, list[dict], list[str], list[dict]]:
|
||||
"""仅删除已到三年保留期的 MinIO 对象,永不删除文件事实、运行或审计。
|
||||
|
||||
Args:
|
||||
@@ -161,11 +193,11 @@ def run_freight_inbound_rpa_retention_schedule(task: Any, run: Any) -> tuple[int
|
||||
"""
|
||||
limit = max(1, min(int((getattr(task, 'job_params', {}) or {}).get('limit', 100)), 1000))
|
||||
now = datetime.utcnow()
|
||||
rows = ShippingReceiptReportFile.query.filter(
|
||||
ShippingReceiptReportFile.archive_expires_at.is_not(None),
|
||||
ShippingReceiptReportFile.archive_expires_at <= now,
|
||||
ShippingReceiptReportFile.archive_deleted_at.is_(None),
|
||||
).order_by(ShippingReceiptReportFile.id).limit(limit).all()
|
||||
rows = FreightRpaInboundReportFile.query.filter(
|
||||
FreightRpaInboundReportFile.archive_expires_at.is_not(None),
|
||||
FreightRpaInboundReportFile.archive_expires_at <= now,
|
||||
FreightRpaInboundReportFile.archive_deleted_at.is_(None),
|
||||
).order_by(FreightRpaInboundReportFile.id).limit(limit).all()
|
||||
success = failed = 0
|
||||
errors: list[str] = []
|
||||
for report_file in rows:
|
||||
@@ -173,8 +205,8 @@ def run_freight_inbound_rpa_retention_schedule(task: Any, run: Any) -> tuple[int
|
||||
file_asset_storage.delete_object(report_file.storage_key)
|
||||
report_file.archive_deleted_at = now
|
||||
report_file.archive_delete_result_json = {'status': 'deleted', 'deleted_at': now.isoformat()}
|
||||
append_shipping_audit_event(
|
||||
event_type='shipping_receipt_report_archive_deleted', aggregate_type='shipping_receipt_file',
|
||||
append_rpa_report_event(
|
||||
event_type='shipping_inbound_report_archive_deleted', aggregate_type='shipping_inbound_file',
|
||||
aggregate_id=str(report_file.id), actor_type='worker', actor_id='receipt-retention',
|
||||
unit_id=report_file.unit_run_id, result='success',
|
||||
before={'status': 'archived'}, after={'status': 'archive_deleted'},
|
||||
@@ -183,8 +215,8 @@ def run_freight_inbound_rpa_retention_schedule(task: Any, run: Any) -> tuple[int
|
||||
success += 1
|
||||
except Exception as exc:
|
||||
errors.append(f'{report_file.id}: {exc}')
|
||||
append_shipping_audit_event(
|
||||
event_type='shipping_receipt_report_archive_delete_attempted', aggregate_type='shipping_receipt_file',
|
||||
append_rpa_report_event(
|
||||
event_type='shipping_inbound_report_archive_delete_attempted', aggregate_type='shipping_inbound_file',
|
||||
aggregate_id=str(report_file.id), actor_type='worker', actor_id='receipt-retention',
|
||||
unit_id=report_file.unit_run_id, result='failure',
|
||||
before={'status': 'archived'}, after={'status': 'archived', 'delete_error': str(exc)[:2000]},
|
||||
@@ -195,7 +227,7 @@ def run_freight_inbound_rpa_retention_schedule(task: Any, run: Any) -> tuple[int
|
||||
return len(rows), success, failed, 0, [{'file_id': row.id} for row in rows], errors, [{'step': 'receipt_retention', 'status': 'completed'}]
|
||||
|
||||
|
||||
def _recipient_ids(report_file: ShippingReceiptReportFile) -> list[int]:
|
||||
def _recipient_ids(report_file: FreightRpaInboundReportFile) -> list[int]:
|
||||
"""从所属排程冻结的接收人列表取目标用户;停用通知时返回空。"""
|
||||
run = report_file.unit_run.schedule_run
|
||||
task = run.task if run else None
|
||||
@@ -208,23 +240,23 @@ def deliver_inbound_file(file_id: int, *, force: bool = False) -> dict:
|
||||
"""向排程接收人逐一投递原样收料文件;同文件用户的成功投递可幂等重放。
|
||||
|
||||
Args:
|
||||
file_id: 已归档收料文件主键(ShippingReceiptReportFile.id)。
|
||||
file_id: 已归档收料文件主键(FreightRpaInboundReportFile.id)。
|
||||
force: 管理员补偿重发(resend 端点传 True),绕过成功幂等但仍受通知开关约束。
|
||||
Returns:
|
||||
dict: success_count / failed_count(file_not_found 时附 reason)。
|
||||
"""
|
||||
report_file = db.session.get(ShippingReceiptReportFile, file_id)
|
||||
report_file = db.session.get(FreightRpaInboundReportFile, file_id)
|
||||
if report_file is None:
|
||||
return {'success_count': 0, 'failed_count': 0, 'reason': 'file_not_found'}
|
||||
success_count = failed_count = 0
|
||||
for user_id in _recipient_ids(report_file):
|
||||
key = f'receipt:file:{report_file.id}:user:{user_id}'
|
||||
delivery = ShippingReceiptNotificationDelivery.query.filter_by(idempotency_key=key).one_or_none()
|
||||
delivery = FreightRpaInboundNotificationDelivery.query.filter_by(idempotency_key=key).one_or_none()
|
||||
if delivery and delivery.status == 'success' and not force:
|
||||
success_count += 1
|
||||
continue
|
||||
if delivery is None:
|
||||
delivery = ShippingReceiptNotificationDelivery(
|
||||
delivery = FreightRpaInboundNotificationDelivery(
|
||||
unit_run_id=report_file.unit_run_id, report_file_id=report_file.id, recipient_user_id=user_id,
|
||||
message_type='file', idempotency_key=key, status='pending',
|
||||
)
|
||||
@@ -234,8 +266,8 @@ def deliver_inbound_file(file_id: int, *, force: bool = False) -> dict:
|
||||
if user is None or not user.wecom_userid:
|
||||
delivery.status = 'failed'; delivery.error_code = 'WECOM_USER_UNBOUND'; delivery.error_message = 'recipient has no wecom binding'
|
||||
failed_count += 1
|
||||
append_shipping_audit_event(
|
||||
event_type='shipping_receipt_file_notification_attempted', aggregate_type='shipping_receipt_file',
|
||||
append_rpa_report_event(
|
||||
event_type='shipping_inbound_file_notification_attempted', aggregate_type='shipping_inbound_file',
|
||||
aggregate_id=str(report_file.id), actor_type='system', owner_user_id=user_id,
|
||||
unit_id=report_file.unit_run_id, result='failure',
|
||||
before={'delivery_status': 'pending'},
|
||||
@@ -252,8 +284,8 @@ def deliver_inbound_file(file_id: int, *, force: bool = False) -> dict:
|
||||
delivery.status = 'success'; delivery.sent_at = datetime.utcnow(); delivery.error_code = None; delivery.error_message = None
|
||||
delivery.response_summary_json = {'media_uploaded': True, 'errcode': 0}
|
||||
success_count += 1
|
||||
append_shipping_audit_event(
|
||||
event_type='shipping_receipt_file_notification_attempted', aggregate_type='shipping_receipt_file', aggregate_id=str(report_file.id),
|
||||
append_rpa_report_event(
|
||||
event_type='shipping_inbound_file_notification_attempted', aggregate_type='shipping_inbound_file', aggregate_id=str(report_file.id),
|
||||
actor_type='system', owner_user_id=user_id, unit_id=report_file.unit_run_id, result='success',
|
||||
before={'delivery_status': 'pending'}, after={'delivery_status': delivery.status, 'sent_at': delivery.sent_at.isoformat() if delivery.sent_at else None},
|
||||
artifact_refs=[{'kind': 'receipt_report', 'id': str(report_file.id), 'sha256': report_file.sha256}],
|
||||
@@ -262,8 +294,8 @@ def deliver_inbound_file(file_id: int, *, force: bool = False) -> dict:
|
||||
except Exception as exc:
|
||||
delivery.status = 'failed'; delivery.error_code = 'WECOM_SEND_FAILED'; delivery.error_message = str(exc)[:2000]
|
||||
failed_count += 1
|
||||
append_shipping_audit_event(
|
||||
event_type='shipping_receipt_file_notification_attempted', aggregate_type='shipping_receipt_file',
|
||||
append_rpa_report_event(
|
||||
event_type='shipping_inbound_file_notification_attempted', aggregate_type='shipping_inbound_file',
|
||||
aggregate_id=str(report_file.id), actor_type='system', owner_user_id=user_id,
|
||||
unit_id=report_file.unit_run_id, result='failure',
|
||||
before={'delivery_status': 'pending'},
|
||||
|
||||
@@ -5,7 +5,7 @@ services/freight_rpa/inbound/trigger_io.py
|
||||
原子写入,以及 Worker 触发/回调契约常量(SCHEMA/ACTION_*)。
|
||||
依赖:Flask current_app 配置、Path/JSON/文件系统工具;不 import 任何业务编排模块
|
||||
(import 边界由 tests/services/freight_rpa/test_import_boundary.py 锁死)。
|
||||
逻辑:由 schedule.freight_inbound_rpa_job(排程写 trigger)、api.schedule.runs(admin 单元重试)、
|
||||
逻辑:由 schedule.freight_rpa_inbound_job(排程写 trigger)、api.schedule.runs(admin 单元重试)、
|
||||
in_transit_transfer.inbound_trigger_service(调拨按需/批量触发)、
|
||||
freight_rpa.common.worker_heartbeat(inbound trigger 目录探测/就绪检查)、
|
||||
freight_rpa.inbound.report_archive(drop 目录定位与回调 SCHEMA 校验,Task 10 下沉)等调用,
|
||||
|
||||
Reference in new issue
Block a user