feat(in-transit-transfer): 自动调拨联动收料就绪并分层来源错误
- 调度整合:退役 in_transit_receipt_file_job,收料归档收敛 shipping_receipt_rpa_archive,排程注册表统一 - 自动调拨 Job:调拨前确保各来源当日收料文件就绪(缺失自动触发收料 RPA),严格等量匹配后生成 ERP 调拨单 - worker 手动唤醒:排程工作台支持手动唤醒与 runs 透视,heartbeat 协议同步 - 收料缺失幸存 T2:parse_failed 状态落库(迁移 q4c5) - 来源错误分层与 stale 时钟换源:改挂 inventory_checked_at 库存查得时刻,展示阈值与执行门禁解耦(迁移 t5a6) - 新增 wecom_sender 企微通知:每非空 Run 汇总一条,通知失败不影响 ERP 结果 - 同步排程工作台/调拨卡片前端、chat/admin 文案四语言、RPA 脚本与测试全家
This commit is contained in:
1 parent
993e581135
commit
abf3d48927
144 files changed
+10161
-2132
No files matched your search
@@ -103,10 +103,11 @@ def _build_schedule_run_wecom_jump_params(task: ScheduleTask, run: ScheduleRun)
|
||||
"""
|
||||
构造排程企微 textcard 跳转 query 参数。
|
||||
|
||||
核心逻辑:指向管理端 /admin/schedules;有原始库存归档时附加 raw_zip=1 与 download 意图,
|
||||
由前端在登录后自动触发一次下载,失败时保留手动下载入口。
|
||||
核心逻辑:指向管理端 /admin/schedules;有原始库存/收料归档时附加 raw_zip=1
|
||||
与对应 download 意图,由前端登录后自动触发一次下载,失败时保留手动入口。
|
||||
"""
|
||||
from app.services.schedule.shipping_inventory_rpa_archive import inventory_raw_zip_available_from_summary
|
||||
from app.services.schedule.shipping_receipt_rpa_archive import receipt_raw_zip_available_from_summary
|
||||
|
||||
summary = run.response_summary_json if isinstance(run.response_summary_json, dict) else {}
|
||||
params: dict[str, Any] = {
|
||||
@@ -116,6 +117,9 @@ def _build_schedule_run_wecom_jump_params(task: ScheduleTask, run: ScheduleRun)
|
||||
if inventory_raw_zip_available_from_summary(summary):
|
||||
params['raw_zip'] = '1'
|
||||
params['download'] = 'inventory_raw_zip'
|
||||
elif receipt_raw_zip_available_from_summary(summary):
|
||||
params['raw_zip'] = '1'
|
||||
params['download'] = 'receipt_raw_zip'
|
||||
return params
|
||||
|
||||
|
||||
@@ -123,9 +127,9 @@ def _receipt_report_files_for_run(run: ScheduleRun) -> list[ShippingReceiptRepor
|
||||
"""
|
||||
收集收料排程 run 名下可投递的收料报表文件;非收料任务返回空列表。
|
||||
|
||||
核心逻辑:库存与收料 RPA 共用同一企微通知出口(_notify_schedule_run_wecom),
|
||||
本函数是收料侧的唯一分叉点——按 platform_api_path 识别收料排程,返回该 run
|
||||
全部单元已归档且未被清理(archive_deleted_at 为空)的报表文件。
|
||||
核心逻辑:按 platform_api_path 识别收料排程,返回该 run 全部单元已归档且
|
||||
未被清理(archive_deleted_at 为空)的报表文件。企微完成通知已改为发 ZIP,
|
||||
本函数保留给管理员单文件重发等旁路读取。
|
||||
"""
|
||||
from app.models import ShippingReceiptRpaUnitRun
|
||||
|
||||
@@ -154,7 +158,7 @@ def _build_schedule_run_wecom_description(run: ScheduleRun) -> str:
|
||||
组装排程完成企微 textcard 正文。
|
||||
|
||||
核心逻辑:与管理端统计口径一致,展示 total/success/skipped/failed 四列计数;
|
||||
有原始库存归档时提示点击卡片进入 HXOPS 并在登录后自动下载(URL 仅放 jump_url,不写进正文)。
|
||||
有原始库存/收料归档时提示包已随通知发送或可点击下载。
|
||||
"""
|
||||
status_label = _WECOM_STATUS_LABEL.get(run.status, run.status)
|
||||
skipped_count = int(run.skipped_count or 0)
|
||||
@@ -168,12 +172,12 @@ def _build_schedule_run_wecom_description(run: ScheduleRun) -> str:
|
||||
if summary.get('excel_failed') or summary.get('excel_export_status') == 'failed':
|
||||
description += '\n备注: 库存源已成功,但排程 Excel 生成失败'
|
||||
from app.services.schedule.shipping_inventory_rpa_archive import inventory_raw_zip_available_from_summary
|
||||
from app.services.schedule.shipping_receipt_rpa_archive import receipt_raw_zip_available_from_summary
|
||||
|
||||
if inventory_raw_zip_available_from_summary(summary):
|
||||
description += '\n原始库存包:点击本通知,登录 HXOPS 后自动下载'
|
||||
receipt_files = _receipt_report_files_for_run(run)
|
||||
if receipt_files:
|
||||
description += f'\n收料报表文件 {len(receipt_files)} 份:已随本通知发送'
|
||||
if receipt_raw_zip_available_from_summary(summary):
|
||||
description += '\n原始收料包:已随本通知发送;亦可点击本通知登录后下载'
|
||||
return description
|
||||
|
||||
|
||||
@@ -183,7 +187,7 @@ def _notify_schedule_run_wecom(task: ScheduleTask, run: ScheduleRun) -> None:
|
||||
核心逻辑:若 response_summary_json.domain_notification_managed=true(如立账凭证检核),
|
||||
则跳过以免与领域缺件/失败告警重复。
|
||||
库存与收料 RPA 共用本出口与同一套门禁:库存附加排程 Excel 与原始库存包;
|
||||
收料附加该 run 全部单元的收料报表文件(见 _receipt_report_files_for_run)。
|
||||
收料附加该 run 的原始收料 ZIP(不再逐文件推送)。
|
||||
"""
|
||||
from app.services.integrations.wecom.notify import (
|
||||
upload_wecom_temp_media,
|
||||
@@ -244,20 +248,20 @@ def _notify_schedule_run_wecom(task: ScheduleTask, run: ScheduleRun) -> None:
|
||||
run.run_no, exc,
|
||||
)
|
||||
|
||||
receipt_media: list[tuple[str, str]] = []
|
||||
for receipt_file in _receipt_report_files_for_run(run):
|
||||
try:
|
||||
from app.services.file_assets.storage import file_asset_storage
|
||||
receipt_zip_media_id = None
|
||||
receipt_zip_file_name = None
|
||||
try:
|
||||
from app.services.schedule.shipping_receipt_rpa_archive import resolve_receipt_raw_zip_download
|
||||
|
||||
receipt_media_id = upload_wecom_temp_media(
|
||||
file_asset_storage.get_bytes(receipt_file.storage_key), receipt_file.original_filename,
|
||||
)
|
||||
receipt_media.append((receipt_media_id, receipt_file.original_filename))
|
||||
except Exception as exc:
|
||||
current_app.logger.warning(
|
||||
'[wecom-schedule] receipt file media upload failed for run %s file %s: %s',
|
||||
run.run_no, receipt_file.id, exc,
|
||||
)
|
||||
receipt_zip_path, receipt_zip_file_name = resolve_receipt_raw_zip_download(run)
|
||||
receipt_zip_media_id = upload_wecom_temp_media(
|
||||
receipt_zip_path.read_bytes(), receipt_zip_file_name,
|
||||
)
|
||||
except Exception as exc:
|
||||
current_app.logger.info(
|
||||
'[wecom-schedule] raw receipt zip media skipped for run %s: %s',
|
||||
run.run_no, exc,
|
||||
)
|
||||
|
||||
textcard_ok_count = 0
|
||||
errors = []
|
||||
@@ -314,21 +318,23 @@ def _notify_schedule_run_wecom(task: ScheduleTask, run: ScheduleRun) -> None:
|
||||
except Exception as exc:
|
||||
errors.append(f'{u.real_name or u.username}: raw zip exception={exc}')
|
||||
|
||||
for receipt_media_id, receipt_filename in receipt_media:
|
||||
if receipt_zip_media_id:
|
||||
try:
|
||||
receipt_audit = _create_audit(
|
||||
f'{_WECOM_EVENT_TYPE}_receipt_file', u,
|
||||
title, f'[收料报表] {receipt_filename}', uuid.uuid4().hex,
|
||||
receipt_zip_audit = _create_audit(
|
||||
f'{_WECOM_EVENT_TYPE}_receipt_raw_zip', u,
|
||||
title, f'[原始收料包] {receipt_zip_file_name}', uuid.uuid4().hex,
|
||||
)
|
||||
receipt_data = send_wecom_file_message(u.wecom_userid, receipt_media_id)
|
||||
if receipt_data.get('errcode') == 0:
|
||||
receipt_audit.status = 'sent'
|
||||
receipt_zip_data = send_wecom_file_message(u.wecom_userid, receipt_zip_media_id)
|
||||
if receipt_zip_data.get('errcode') == 0:
|
||||
receipt_zip_audit.status = 'sent'
|
||||
else:
|
||||
receipt_audit.error_code = str(receipt_data.get('errcode'))
|
||||
receipt_audit.error_message = str(receipt_data.get('errmsg', 'unknown'))[:255]
|
||||
errors.append(f'{u.real_name or u.username}: receipt file errcode={receipt_data.get("errcode")}')
|
||||
receipt_zip_audit.error_code = str(receipt_zip_data.get('errcode'))
|
||||
receipt_zip_audit.error_message = str(receipt_zip_data.get('errmsg', 'unknown'))[:255]
|
||||
errors.append(
|
||||
f'{u.real_name or u.username}: receipt zip errcode={receipt_zip_data.get("errcode")}'
|
||||
)
|
||||
except Exception as exc:
|
||||
errors.append(f'{u.real_name or u.username}: receipt file exception={exc}')
|
||||
errors.append(f'{u.real_name or u.username}: receipt zip exception={exc}')
|
||||
|
||||
if textcard_ok_count > 0:
|
||||
run.wecom_notified = True
|
||||
|
||||
Reference in new issue
Block a user