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
@@ -343,8 +343,8 @@ def _register_headers_from_config() -> None:
|
||||
for name, cfg in get_all_schedule_sql_configs().items():
|
||||
if cfg.alias_order and cfg.header_labels:
|
||||
register_schedule_header(name, cfg.alias_order, cfg.header_labels)
|
||||
from app.services.schedule.freight_onhand_rpa_finalize import register_inventory_rpa_excel_headers
|
||||
from app.services.schedule.freight_inbound_rpa_finalize import register_receipt_rpa_excel_headers
|
||||
from app.services.schedule.freight_rpa_onhand_finalize import register_inventory_rpa_excel_headers
|
||||
from app.services.schedule.freight_rpa_inbound_finalize import register_receipt_rpa_excel_headers
|
||||
|
||||
register_inventory_rpa_excel_headers()
|
||||
register_receipt_rpa_excel_headers()
|
||||
|
||||
+13
-13
@@ -1,9 +1,9 @@
|
||||
"""
|
||||
backend/app/services/schedule/freight_inbound_rpa_archive.py
|
||||
backend/app/services/schedule/freight_rpa_inbound_archive.py
|
||||
|
||||
用途:货代收料 RPA 排程 run 的原始收料 ZIP 归档(finalize 预生成 + 下载直传)与企微展示名。
|
||||
依赖:ScheduleRun、ShippingReceiptReportFile / ShippingReceiptRpaUnitRun、
|
||||
file_asset_storage、timezone_util、freight_inbound_rpa_finalize.is_freight_receipt_rpa_task。
|
||||
依赖:ScheduleRun、FreightRpaInboundReportFile / FreightRpaInboundUnitRun、
|
||||
file_asset_storage、timezone_util、freight_rpa_inbound_finalize.is_freight_receipt_rpa_task。
|
||||
逻辑:finalize 调用 persist_receipt_rpa_raw_zip_archive 写入磁盘与 summary;
|
||||
企微/下载展示名用「收料RPA-日期-时刻-收料」;包内条目 `{序号}_{source_code}.xlsx`;
|
||||
warehouse_id / file_id 只写在 manifest.json;磁盘归档键为 {run_no}.zip。
|
||||
@@ -21,9 +21,9 @@ from typing import Any
|
||||
from flask import current_app
|
||||
|
||||
from app.core.errors import NotFoundError
|
||||
from app.models import ScheduleRun, ShippingReceiptReportFile, ShippingReceiptRpaUnitRun
|
||||
from app.models import ScheduleRun, FreightRpaInboundReportFile, FreightRpaInboundUnitRun
|
||||
from app.services.file_assets.storage import file_asset_storage
|
||||
from app.services.schedule.freight_inbound_rpa_finalize import is_freight_receipt_rpa_task
|
||||
from app.services.schedule.freight_rpa_inbound_finalize import is_freight_receipt_rpa_task
|
||||
from app.services.schedule.timezone_util import resolve_schedule_tzinfo
|
||||
|
||||
_RAW_ZIP_NOT_FOUND_MESSAGE = '原始收料包不存在,请重新执行或联系管理员'
|
||||
@@ -111,7 +111,7 @@ def receipt_raw_zip_download_name(run: ScheduleRun) -> str:
|
||||
|
||||
|
||||
def receipt_rpa_result_excel_name(run: ScheduleRun) -> str:
|
||||
"""收料 RPA 结果 Excel 的企微/下载展示名(对齐库存 inventory_rpa_result_excel_name)。"""
|
||||
"""收料 RPA 结果 Excel 的企微/下载展示名(对齐库存 onhand_rpa_result_excel_name)。"""
|
||||
return f'{receipt_rpa_attachment_stem(run)}-结果.xlsx'
|
||||
|
||||
|
||||
@@ -127,20 +127,20 @@ def _iter_packable_receipt_files(run: ScheduleRun):
|
||||
核心逻辑:join unit_run,过滤 archive_deleted_at 为空;按 file id 升序稳定序号。
|
||||
|
||||
Yields:
|
||||
ShippingReceiptReportFile: 可从 MinIO 读取的归档记录。
|
||||
FreightRpaInboundReportFile: 可从 MinIO 读取的归档记录。
|
||||
"""
|
||||
if not is_freight_receipt_rpa_task(getattr(run, 'task', None)):
|
||||
return
|
||||
rows = (
|
||||
ShippingReceiptReportFile.query.join(
|
||||
ShippingReceiptRpaUnitRun,
|
||||
ShippingReceiptReportFile.unit_run_id == ShippingReceiptRpaUnitRun.id,
|
||||
FreightRpaInboundReportFile.query.join(
|
||||
FreightRpaInboundUnitRun,
|
||||
FreightRpaInboundReportFile.unit_run_id == FreightRpaInboundUnitRun.id,
|
||||
)
|
||||
.filter(
|
||||
ShippingReceiptRpaUnitRun.schedule_run_id == run.id,
|
||||
ShippingReceiptReportFile.archive_deleted_at.is_(None),
|
||||
FreightRpaInboundUnitRun.schedule_run_id == run.id,
|
||||
FreightRpaInboundReportFile.archive_deleted_at.is_(None),
|
||||
)
|
||||
.order_by(ShippingReceiptReportFile.id.asc())
|
||||
.order_by(FreightRpaInboundReportFile.id.asc())
|
||||
.all()
|
||||
)
|
||||
for report_file in rows:
|
||||
+18
-18
@@ -1,9 +1,9 @@
|
||||
"""
|
||||
backend/app/services/schedule/freight_inbound_rpa_finalize.py
|
||||
backend/app/services/schedule/freight_rpa_inbound_finalize.py
|
||||
|
||||
用途:独立收料 RPA 排程等待态收口——进度回写、全单元终态后写计数、预生成 ZIP、发企微;
|
||||
另含超时对账:排程 run 级(每轮 tick)与按需触发孤儿单元级(schedule_run_id=NULL)。
|
||||
依赖:ShippingReceiptRpaUnitRun、freight_inbound_rpa_archive、scheduler_service 企微通知。
|
||||
依赖:FreightRpaInboundUnitRun、freight_rpa_inbound_archive、scheduler_service 企微通知。
|
||||
逻辑:每笔回调 → refresh 进度计数 → 全终态时 persist ZIP → _notify_schedule_run_wecom;
|
||||
超时对账只终态化失败,绝不自动重试或重发(恢复走人工显式重试入口)。
|
||||
"""
|
||||
@@ -18,10 +18,10 @@ from sqlalchemy import func
|
||||
|
||||
from app import db
|
||||
from app.models import ScheduleRun, ScheduleTask
|
||||
from app.models import ShippingReceiptRpaUnitRun
|
||||
from app.models import FreightRpaInboundUnitRun
|
||||
from app.services.schedule import normalize_platform_api_path, register_schedule_header, resolve_schedule_header
|
||||
from app.services.schedule.excel_service import export_schedule_result_excel
|
||||
from app.services.schedule.freight_inbound_rpa_job import AWAITING_RECEIPT_RPA_CALLBACK_STATUS, INBOUND_RPA_JOB_KEY
|
||||
from app.services.schedule.freight_rpa_inbound_job import AWAITING_RECEIPT_RPA_CALLBACK_STATUS, INBOUND_RPA_JOB_KEY
|
||||
from app.services.freight_rpa.inbound.trigger_io import SCHEMA as INBOUND_TRIGGER_SCHEMA
|
||||
from app.services.shipping_notice.audit_service import append_shipping_audit_event
|
||||
|
||||
@@ -57,7 +57,7 @@ def register_receipt_rpa_excel_headers() -> None:
|
||||
)
|
||||
|
||||
|
||||
def _build_receipt_finalize_details(units: list[ShippingReceiptRpaUnitRun]) -> list[dict[str, Any]]:
|
||||
def _build_receipt_finalize_details(units: list[FreightRpaInboundUnitRun]) -> list[dict[str, Any]]:
|
||||
"""
|
||||
收料单元 → 排程 Excel 明细行(对齐库存 finalize 的行结构)。
|
||||
|
||||
@@ -144,7 +144,7 @@ def refresh_receipt_schedule_run_progress(schedule_run_id: int) -> dict:
|
||||
if run.status != 'running' or not summary.get('awaiting_receipt_rpa'):
|
||||
return {'updated': False, 'reason': 'not_awaiting_receipt_callback'}
|
||||
|
||||
units = ShippingReceiptRpaUnitRun.query.filter_by(schedule_run_id=run.id).all()
|
||||
units = FreightRpaInboundUnitRun.query.filter_by(schedule_run_id=run.id).all()
|
||||
success_count = sum(unit.status == 'success' for unit in units)
|
||||
skipped_count = sum(unit.status == 'empty' for unit in units)
|
||||
failed_count = sum(unit.status in {'failed', 'cancelled'} for unit in units)
|
||||
@@ -239,7 +239,7 @@ def mark_receipt_unit_processing(payload: dict) -> dict:
|
||||
callback_id = str(payload.get('callback_id') or '').strip()
|
||||
if not callback_id:
|
||||
return {'updated': False, 'reason': 'callback_id_required'}
|
||||
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:
|
||||
return {'updated': False, 'reason': 'unit_not_found'}
|
||||
if unit.status in {'success', 'empty', 'failed', 'cancelled'}:
|
||||
@@ -268,7 +268,7 @@ def finalize_receipt_schedule_run_if_complete(schedule_run_id: int) -> dict:
|
||||
summary = run.response_summary_json if isinstance(run.response_summary_json, dict) else {}
|
||||
if not summary.get('awaiting_receipt_rpa'):
|
||||
return {'finalized': False, 'reason': 'not_awaiting_receipt_callback'}
|
||||
units = ShippingReceiptRpaUnitRun.query.filter_by(schedule_run_id=run.id).all()
|
||||
units = FreightRpaInboundUnitRun.query.filter_by(schedule_run_id=run.id).all()
|
||||
terminal = {'success', 'empty', 'failed', 'cancelled'}
|
||||
if any(unit.status not in terminal for unit in units):
|
||||
return {'finalized': False, 'reason': 'units_pending'}
|
||||
@@ -315,7 +315,7 @@ def finalize_receipt_schedule_run_if_complete(schedule_run_id: int) -> dict:
|
||||
run.error_message = '; '.join(filter(None, [run.error_message, f'Excel导出失败: {excel_exc}']))[:2000]
|
||||
else:
|
||||
# 企微/下载展示名:收料RPA-{日期}-{时刻}-结果.xlsx(完整 run_no 留在卡片与 DB)。
|
||||
from app.services.schedule.freight_inbound_rpa_archive import receipt_rpa_result_excel_name
|
||||
from app.services.schedule.freight_rpa_inbound_archive import receipt_rpa_result_excel_name
|
||||
|
||||
excel_name = receipt_rpa_result_excel_name(run)
|
||||
run.excel_file_data = excel_data
|
||||
@@ -331,7 +331,7 @@ def finalize_receipt_schedule_run_if_complete(schedule_run_id: int) -> dict:
|
||||
'raw_receipt_zip_size': 0,
|
||||
}
|
||||
try:
|
||||
from app.services.schedule.freight_inbound_rpa_archive import persist_receipt_rpa_raw_zip_archive
|
||||
from app.services.schedule.freight_rpa_inbound_archive import persist_receipt_rpa_raw_zip_archive
|
||||
|
||||
archive_summary = persist_receipt_rpa_raw_zip_archive(run)
|
||||
except Exception as archive_exc:
|
||||
@@ -381,7 +381,7 @@ def is_freight_receipt_rpa_task(task: ScheduleTask | None) -> bool:
|
||||
)
|
||||
|
||||
|
||||
def _receipt_last_activity(run: ScheduleRun, units: list[ShippingReceiptRpaUnitRun]) -> datetime:
|
||||
def _receipt_last_activity(run: ScheduleRun, units: list[FreightRpaInboundUnitRun]) -> datetime:
|
||||
"""收料 run 的最后活动锚:run 开始时间与全部单元 started/finished 时间的最大值。
|
||||
|
||||
语义为「笔间静默」:worker 每开始/完成一笔都会推进锚点,锚点静默超过
|
||||
@@ -399,7 +399,7 @@ def _receipt_last_activity(run: ScheduleRun, units: list[ShippingReceiptRpaUnitR
|
||||
|
||||
|
||||
def _fail_receipt_unit_with_timeout(
|
||||
unit: ShippingReceiptRpaUnitRun, *, now: datetime, timeout_seconds: int,
|
||||
unit: FreightRpaInboundUnitRun, *, now: datetime, timeout_seconds: int,
|
||||
run_no: str | None = None,
|
||||
) -> None:
|
||||
"""单个收料单元回调超时收口为失败并写审计(run 级与孤儿级回收共用的唯一实现)。
|
||||
@@ -422,7 +422,7 @@ def _fail_receipt_unit_with_timeout(
|
||||
unit.error_message = f'Receipt RPA callback timed out after {timeout_seconds} seconds'
|
||||
unit.finished_at = now
|
||||
append_shipping_audit_event(
|
||||
event_type='shipping_receipt_rpa_callback_timeout', aggregate_type='shipping_receipt_unit',
|
||||
event_type='shipping_inbound_rpa_callback_timeout', aggregate_type='shipping_inbound_unit',
|
||||
aggregate_id=str(unit.id), run_no=run_no, actor_type='worker', actor_id='schedule-recovery',
|
||||
unit_id=unit.id, result='failure', before=before,
|
||||
after={'status': unit.status, 'error_code': unit.error_code, 'error_message': unit.error_message},
|
||||
@@ -442,7 +442,7 @@ def _recover_stale_receipt_run(run: ScheduleRun, *, cutoff: datetime, timeout_se
|
||||
task = run.task or db.session.get(ScheduleTask, run.schedule_task_id)
|
||||
if not is_freight_receipt_rpa_task(task):
|
||||
return False
|
||||
units = ShippingReceiptRpaUnitRun.query.filter_by(schedule_run_id=run.id).all()
|
||||
units = FreightRpaInboundUnitRun.query.filter_by(schedule_run_id=run.id).all()
|
||||
if _receipt_last_activity(run, units) > cutoff:
|
||||
return False
|
||||
now = datetime.utcnow()
|
||||
@@ -516,11 +516,11 @@ def recover_all_stale_orphan_receipt_units() -> int:
|
||||
timeout_seconds = _receipt_timeout_seconds()
|
||||
cutoff = datetime.utcnow() - timedelta(seconds=timeout_seconds)
|
||||
orphans = (
|
||||
ShippingReceiptRpaUnitRun.query
|
||||
FreightRpaInboundUnitRun.query
|
||||
.filter(
|
||||
ShippingReceiptRpaUnitRun.schedule_run_id.is_(None),
|
||||
ShippingReceiptRpaUnitRun.status.in_(('queued', 'awaiting_rpa', 'processing')),
|
||||
func.coalesce(ShippingReceiptRpaUnitRun.started_at, ShippingReceiptRpaUnitRun.created_at) < cutoff,
|
||||
FreightRpaInboundUnitRun.schedule_run_id.is_(None),
|
||||
FreightRpaInboundUnitRun.status.in_(('queued', 'awaiting_rpa', 'processing')),
|
||||
func.coalesce(FreightRpaInboundUnitRun.started_at, FreightRpaInboundUnitRun.created_at) < cutoff,
|
||||
)
|
||||
.all()
|
||||
)
|
||||
+15
-15
@@ -1,9 +1,9 @@
|
||||
"""
|
||||
backend/app/services/schedule/freight_inbound_rpa_job.py
|
||||
backend/app/services/schedule/freight_rpa_inbound_job.py
|
||||
|
||||
用途:独立收料 RPA 排程——按勾选库存源一对一冻结执行单元并写 receipt trigger。
|
||||
依赖:freight_rpa.inbound.trigger_io.write_inbound_export_batch_trigger、assert_receipt_rpa_worker_ready、
|
||||
ShippingInventorySource / ShippingReceiptReportConfig / ShippingReceiptRpaUnitRun、
|
||||
FreightRpaSource / FreightRpaInboundReportConfig / FreightRpaInboundUnitRun、
|
||||
ScheduleTask/Run。
|
||||
逻辑:job_registry 的 freight-rpa-inbound 调用本 handler;写 trigger 前 fail-fast;
|
||||
口径与库存排程一致(选中 N 源 → N unit),query_parameters 原样下发。
|
||||
@@ -16,7 +16,7 @@ from typing import Any
|
||||
|
||||
from app import db
|
||||
from app.core.errors import ServiceUnavailableError
|
||||
from app.models import ScheduleRun, ScheduleTask, ShippingInventorySource, ShippingReceiptReportConfig, ShippingReceiptRpaUnitRun
|
||||
from app.models import ScheduleRun, ScheduleTask, FreightRpaSource, FreightRpaInboundReportConfig, FreightRpaInboundUnitRun
|
||||
from app.services.freight_rpa.inbound.trigger_io import SCHEMA, write_inbound_export_batch_trigger
|
||||
from app.services.freight_rpa.common.worker_heartbeat import (
|
||||
RPA_WORKER_OFFLINE_MESSAGE,
|
||||
@@ -37,16 +37,16 @@ def _wanted_source_codes(task: ScheduleTask) -> set[str]:
|
||||
return {str(value).strip().upper() for value in values if str(value).strip()}
|
||||
|
||||
|
||||
def _eligible_sources(task: ScheduleTask) -> list[tuple[ShippingInventorySource, ShippingReceiptReportConfig]]:
|
||||
def _eligible_sources(task: ScheduleTask) -> list[tuple[FreightRpaSource, FreightRpaInboundReportConfig]]:
|
||||
"""读取已启用且已配置收料报表的站点;不依赖库存报表路径、解析绑定或 Warehouse 条件。"""
|
||||
wanted = _wanted_source_codes(task)
|
||||
rows = db.session.query(ShippingInventorySource, ShippingReceiptReportConfig).join(
|
||||
ShippingReceiptReportConfig, ShippingReceiptReportConfig.inventory_source_id == ShippingInventorySource.id,
|
||||
).filter(ShippingInventorySource.enabled.is_(True)).all()
|
||||
rows = db.session.query(FreightRpaSource, FreightRpaInboundReportConfig).join(
|
||||
FreightRpaInboundReportConfig, FreightRpaInboundReportConfig.source_id == FreightRpaSource.id,
|
||||
).filter(FreightRpaSource.enabled.is_(True)).all()
|
||||
return [(source, config) for source, config in rows if not wanted or source.source_code.upper() in wanted]
|
||||
|
||||
|
||||
def _copy_query_parameters(config: ShippingReceiptReportConfig) -> list[dict[str, Any]]:
|
||||
def _copy_query_parameters(config: FreightRpaInboundReportConfig) -> list[dict[str, Any]]:
|
||||
"""浅拷贝收料查询条件原样入快照;空列表表示 Worker 使用页面默认、不填 Warehouse。"""
|
||||
return [
|
||||
dict(item) for item in (config.query_parameters_json or [])
|
||||
@@ -55,8 +55,8 @@ def _copy_query_parameters(config: ShippingReceiptReportConfig) -> list[dict[str
|
||||
|
||||
|
||||
def _build_unit(
|
||||
source: ShippingInventorySource, config: ShippingReceiptReportConfig, schedule_run_id: int,
|
||||
) -> ShippingReceiptRpaUnitRun:
|
||||
source: FreightRpaSource, config: FreightRpaInboundReportConfig, schedule_run_id: int,
|
||||
) -> FreightRpaInboundUnitRun:
|
||||
"""冻结可审计的收料执行单元(一源一单元);DBS 日期字段不进入查询快照。"""
|
||||
callback_id = f'receipt:{uuid.uuid4().hex}'
|
||||
snapshot = {
|
||||
@@ -64,16 +64,16 @@ def _build_unit(
|
||||
'report_path_json': config.report_path_json or {}, 'query_parameters_json': _copy_query_parameters(config),
|
||||
'warehouse_id': None, 'rpa_profile_id': source.rpa_profile_id,
|
||||
}
|
||||
return ShippingReceiptRpaUnitRun(
|
||||
schedule_run_id=schedule_run_id, inventory_source_id=source.id, source_code=source.source_code,
|
||||
return FreightRpaInboundUnitRun(
|
||||
schedule_run_id=schedule_run_id, source_id=source.id, source_code=source.source_code,
|
||||
connector_type=source.connector_type, warehouse_id=None, callback_id=callback_id,
|
||||
status='awaiting_rpa', config_snapshot_json=snapshot,
|
||||
)
|
||||
|
||||
|
||||
def _serialize_trigger_unit(unit: ShippingReceiptRpaUnitRun) -> dict[str, Any]:
|
||||
def _serialize_trigger_unit(unit: FreightRpaInboundUnitRun) -> dict[str, Any]:
|
||||
"""生成 Worker 唯一可见的冻结执行载荷;密文凭据只随 receipt trigger 下发。"""
|
||||
source = unit.inventory_source
|
||||
source = unit.source
|
||||
profile = source.rpa_profile if source is not None else None
|
||||
if source is None or profile is None or not profile.enabled:
|
||||
raise RuntimeError(f'receipt source profile unavailable: {unit.source_code}')
|
||||
@@ -105,7 +105,7 @@ def run_freight_receipt_rpa_schedule(task: ScheduleTask, run: ScheduleRun) -> Sc
|
||||
核心逻辑:写 trigger 前 assert_receipt_rpa_worker_ready;离线立即 failed,
|
||||
不创建 unit、不进入 awaiting_receipt_rpa。
|
||||
"""
|
||||
units: list[ShippingReceiptRpaUnitRun] = [
|
||||
units: list[FreightRpaInboundUnitRun] = [
|
||||
_build_unit(source, config, run.id) for source, config in _eligible_sources(task)
|
||||
]
|
||||
if not units:
|
||||
+4
-4
@@ -1,9 +1,9 @@
|
||||
"""收料原样归档三年到期对象清理(排程壳)。
|
||||
|
||||
批次 R Task 10 起,清理能力本体已下沉 freight_rpa.inbound.report_archive
|
||||
(run_freight_inbound_rpa_retention_schedule,函数名 receipt 词根→inbound);
|
||||
(run_freight_rpa_inbound_retention_schedule,函数名 receipt 词根→inbound);
|
||||
本文件仅保留排程平台 Job 处理器接缝(job_registry 按 schedule 包路径注册,
|
||||
Task 11 已随排程壳平移改名为 freight_inbound_rpa_retention,git mv 保留历史)。
|
||||
Task 11 已随排程壳平移改名为 freight_rpa_inbound_retention,git mv 保留历史)。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -13,6 +13,6 @@ from typing import Any
|
||||
|
||||
def run_freight_receipt_rpa_retention_schedule(task: Any, run: Any) -> tuple[int, int, int, int, list[dict], list[str], list[dict]]:
|
||||
"""排程壳:委托 freight_rpa.inbound.report_archive 执行三年保留清理(行为不变)。"""
|
||||
from app.services.freight_rpa.inbound.report_archive import run_freight_inbound_rpa_retention_schedule
|
||||
from app.services.freight_rpa.inbound.report_archive import run_freight_rpa_inbound_retention_schedule
|
||||
|
||||
return run_freight_inbound_rpa_retention_schedule(task, run)
|
||||
return run_freight_rpa_inbound_retention_schedule(task, run)
|
||||
+10
-10
@@ -1,8 +1,8 @@
|
||||
"""
|
||||
backend/app/services/schedule/freight_onhand_rpa_archive.py
|
||||
backend/app/services/schedule/freight_rpa_onhand_archive.py
|
||||
|
||||
用途:货代库存 RPA 排程 run 的原始库存 ZIP 归档(finalize 预生成 + 下载直传)与企微展示名。
|
||||
依赖:ScheduleRun、ShippingInventoryFile、freight_onhand_rpa_finalize.is_shipping_inventory_rpa_task。
|
||||
依赖:ScheduleRun、FreightRpaOnhandReportFile、freight_rpa_onhand_finalize.is_shipping_inventory_rpa_task。
|
||||
逻辑:finalize 调用 persist_inventory_rpa_raw_zip_archive 写入磁盘与 summary;
|
||||
企微/下载展示名用「库存RPA-日期-时刻-结果|库存」;包内条目仅「序号_仓码」;
|
||||
完整 source_code / inventory_file_no 只写在 manifest.json;磁盘归档键仍为 {run_no}.zip。
|
||||
@@ -21,8 +21,8 @@ from flask import current_app
|
||||
|
||||
from app import db
|
||||
from app.core.errors import NotFoundError
|
||||
from app.models import ScheduleRun, ShippingInventoryFile
|
||||
from app.services.schedule.freight_onhand_rpa_finalize import is_shipping_inventory_rpa_task
|
||||
from app.models import ScheduleRun, FreightRpaOnhandReportFile
|
||||
from app.services.schedule.freight_rpa_onhand_finalize import is_shipping_inventory_rpa_task
|
||||
from app.services.schedule.timezone_util import resolve_schedule_tzinfo
|
||||
|
||||
_RAW_ZIP_NOT_FOUND_MESSAGE = "原始库存包不存在,请重新执行或联系管理员"
|
||||
@@ -98,7 +98,7 @@ def inventory_rpa_attachment_stem(run: ScheduleRun) -> str:
|
||||
|
||||
def inventory_rpa_result_excel_name(run: ScheduleRun) -> str:
|
||||
"""库存 RPA 结果 Excel 的企微/下载展示名。"""
|
||||
return f"{inventory_rpa_attachment_stem(run)}-结果.xlsx"
|
||||
return f"{onhand_rpa_attachment_stem(run)}-结果.xlsx"
|
||||
|
||||
|
||||
def inventory_raw_zip_download_name(run: ScheduleRun) -> str:
|
||||
@@ -107,7 +107,7 @@ def inventory_raw_zip_download_name(run: ScheduleRun) -> str:
|
||||
|
||||
核心逻辑:磁盘归档仍为 {run_no}.zip;本函数只影响 Content-Disposition 与企微 filename。
|
||||
"""
|
||||
return f"{inventory_rpa_attachment_stem(run)}-库存.zip"
|
||||
return f"{onhand_rpa_attachment_stem(run)}-库存.zip"
|
||||
|
||||
|
||||
def _inventory_raw_zip_archive_path(run_no: str) -> Path:
|
||||
@@ -139,10 +139,10 @@ def _iter_packable_inventory_files(
|
||||
"""
|
||||
遍历可实际打包的库存快照。
|
||||
|
||||
核心逻辑:需存在 ShippingInventoryFile 且 storage_path 指向可读文件。
|
||||
核心逻辑:需存在 FreightRpaOnhandReportFile 且 storage_path 指向可读文件。
|
||||
|
||||
Yields:
|
||||
tuple[dict, ShippingInventoryFile, Path]: created 项、快照记录、可读路径。
|
||||
tuple[dict, FreightRpaOnhandReportFile, Path]: created 项、快照记录、可读路径。
|
||||
"""
|
||||
if not is_shipping_inventory_rpa_task(getattr(run, "task", None)):
|
||||
return
|
||||
@@ -154,8 +154,8 @@ def _iter_packable_inventory_files(
|
||||
continue
|
||||
|
||||
inv_file = (
|
||||
db.session.query(ShippingInventoryFile)
|
||||
.filter(ShippingInventoryFile.inventory_file_no == inventory_file_no)
|
||||
db.session.query(FreightRpaOnhandReportFile)
|
||||
.filter(FreightRpaOnhandReportFile.onhand_file_no == inventory_file_no)
|
||||
.first()
|
||||
)
|
||||
if not inv_file:
|
||||
+6
-6
@@ -1,9 +1,9 @@
|
||||
"""
|
||||
backend/app/services/schedule/freight_onhand_rpa_finalize.py
|
||||
backend/app/services/schedule/freight_rpa_onhand_finalize.py
|
||||
|
||||
用途:货代库存 RPA 排程异步终态(defer / finalize / 超时回收)。
|
||||
依赖:ScheduleRun/ScheduleTask、excel_service、kb_sync、scheduler_service 企微通知、tool_common。
|
||||
逻辑:freight_onhand_rpa_job 写 trigger 后 defer;inventory_rpa_workflow 回调后 finalize;
|
||||
逻辑:freight_rpa_onhand_job 写 trigger 后 defer;onhand_rpa_workflow 回调后 finalize;
|
||||
run_task_now / cron 调度循环启动前回收超时 awaiting run;服务重启跳过 awaiting RPA run。
|
||||
"""
|
||||
|
||||
@@ -276,7 +276,7 @@ def _try_recover_stale_awaiting_run(
|
||||
finished_at = datetime.utcnow()
|
||||
step_logs = list(run.step_logs or [])
|
||||
step_logs.append({
|
||||
"step": "shipping_inventory_rpa",
|
||||
"step": "freight_rpa_onhand",
|
||||
"status": "failed",
|
||||
"detail": {"message": "RPA 库存导出等待超时", "timeout_seconds": timeout_seconds},
|
||||
})
|
||||
@@ -495,13 +495,13 @@ def _finalize_shipping_inventory_schedule_run_impl(
|
||||
status = "partial_failed"
|
||||
else:
|
||||
# 企微/下载展示名:库存RPA-{日期}-{时刻}-结果.xlsx(完整 run_no 留在卡片与 DB)。
|
||||
from app.services.schedule.freight_onhand_rpa_archive import inventory_rpa_result_excel_name
|
||||
from app.services.schedule.freight_rpa_onhand_archive import inventory_rpa_result_excel_name
|
||||
|
||||
file_name = inventory_rpa_result_excel_name(run)
|
||||
|
||||
step_logs = list(run.step_logs or [])
|
||||
step_logs.append({
|
||||
"step": "shipping_inventory_rpa",
|
||||
"step": "freight_rpa_onhand",
|
||||
"status": "success" if status == "success" else "failed" if status == "failed" else "partial_failed",
|
||||
"detail": {
|
||||
"created_count": success_count,
|
||||
@@ -537,7 +537,7 @@ def _finalize_shipping_inventory_schedule_run_impl(
|
||||
"raw_inventory_zip_size": 0,
|
||||
}
|
||||
try:
|
||||
from app.services.schedule.freight_onhand_rpa_archive import persist_inventory_rpa_raw_zip_archive
|
||||
from app.services.schedule.freight_rpa_onhand_archive import persist_inventory_rpa_raw_zip_archive
|
||||
|
||||
archive_summary = persist_inventory_rpa_raw_zip_archive(run, created=created)
|
||||
except Exception as archive_exc:
|
||||
+11
-11
@@ -1,10 +1,10 @@
|
||||
"""
|
||||
backend/app/services/schedule/freight_onhand_rpa_job.py
|
||||
backend/app/services/schedule/freight_rpa_onhand_job.py
|
||||
|
||||
用途:排程触发货代库存 RPA 批量导出(每个 Inventory Source 一次执行)。
|
||||
依赖:inventory_source_repository、rpa.write_inventory_export_batch_trigger、ScheduleTask/ScheduleRun。
|
||||
依赖:onhand_source_repository、rpa.write_inventory_export_batch_trigger、ScheduleTask/ScheduleRun。
|
||||
逻辑:platform_api_path=freight-rpa-onhand 时由 job_registry 调用;
|
||||
写 trigger 后返回 awaiting_rpa_callback;终态由 freight_onhand_rpa_finalize 在 RPA 回调时写入。
|
||||
写 trigger 后返回 awaiting_rpa_callback;终态由 freight_rpa_onhand_finalize 在 RPA 回调时写入。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -16,8 +16,8 @@ from typing import Any
|
||||
from app import db
|
||||
from app.core.errors import ServiceUnavailableError
|
||||
from app.models import ScheduleRun, ScheduleTask
|
||||
from app.services.schedule.freight_onhand_rpa_finalize import AWAITING_RPA_CALLBACK_STATUS
|
||||
from app.services.shipping_notice.inventory_source_repository import list_database_inventory_sources
|
||||
from app.services.schedule.freight_rpa_onhand_finalize import AWAITING_RPA_CALLBACK_STATUS
|
||||
from app.services.shipping_notice.onhand_source_repository import list_database_inventory_sources
|
||||
from app.services.shipping_notice.onhand_trigger_batch import write_inventory_export_batch_trigger
|
||||
from app.services.freight_rpa.common.worker_heartbeat import (
|
||||
RPA_WORKER_OFFLINE_MESSAGE,
|
||||
@@ -105,21 +105,21 @@ def _filter_sources(task: ScheduleTask) -> list[dict[str, Any]]:
|
||||
return enabled
|
||||
|
||||
|
||||
def run_shipping_inventory_rpa_schedule(task: ScheduleTask, run: ScheduleRun) -> ScheduleExecuteResult:
|
||||
def run_freight_rpa_onhand_schedule(task: ScheduleTask, run: ScheduleRun) -> ScheduleExecuteResult:
|
||||
"""
|
||||
写入批量库存 RPA trigger,由 worker 异步导出并在 callback 入库。
|
||||
核心逻辑:写 trigger 后返回 awaiting_rpa_callback;终态由 finalize 在回调时写入。
|
||||
"""
|
||||
sources = _filter_sources(task)
|
||||
step_logs: list[dict[str, Any]] = [{
|
||||
"step": "shipping_inventory_rpa",
|
||||
"step": "freight_rpa_onhand",
|
||||
"status": "started",
|
||||
"detail": {"source_count": len(sources)},
|
||||
}]
|
||||
|
||||
if not sources:
|
||||
message = "no enabled inventory sources"
|
||||
step_logs.append({"step": "shipping_inventory_rpa", "status": "skipped", "detail": {"message": message}})
|
||||
step_logs.append({"step": "freight_rpa_onhand", "status": "skipped", "detail": {"message": message}})
|
||||
return 0, 0, 0, 1, [], [message], step_logs
|
||||
|
||||
run_no = run.run_no or f"RUN{datetime.utcnow().strftime('%Y%m%d%H%M%S')}"
|
||||
@@ -139,7 +139,7 @@ def run_shipping_inventory_rpa_schedule(task: ScheduleTask, run: ScheduleRun) ->
|
||||
message = str(exc.message or RPA_WORKER_OFFLINE_MESSAGE)
|
||||
detail_message = str((exc.details or {}).get("detail_message") or message)
|
||||
step_logs.append({
|
||||
"step": "shipping_inventory_rpa",
|
||||
"step": "freight_rpa_onhand",
|
||||
"status": "failed",
|
||||
"detail": {
|
||||
"message": message,
|
||||
@@ -151,7 +151,7 @@ def run_shipping_inventory_rpa_schedule(task: ScheduleTask, run: ScheduleRun) ->
|
||||
return len(sources), 0, len(sources), 0, [], [detail_message], step_logs
|
||||
if not trigger_path:
|
||||
message = "inventory RPA trigger dir not configured"
|
||||
step_logs.append({"step": "shipping_inventory_rpa", "status": "failed", "detail": {"message": message}})
|
||||
step_logs.append({"step": "freight_rpa_onhand", "status": "failed", "detail": {"message": message}})
|
||||
return len(sources), 0, len(sources), 0, [], [message], step_logs
|
||||
|
||||
run.api_request_json = {
|
||||
@@ -162,7 +162,7 @@ def run_shipping_inventory_rpa_schedule(task: ScheduleTask, run: ScheduleRun) ->
|
||||
db.session.commit()
|
||||
|
||||
step_logs.append({
|
||||
"step": "shipping_inventory_rpa",
|
||||
"step": "freight_rpa_onhand",
|
||||
"status": AWAITING_RPA_CALLBACK_STATUS,
|
||||
"detail": {"trigger_path": trigger_path, "run_no": run_no},
|
||||
})
|
||||
@@ -2,9 +2,10 @@
|
||||
backend/app/services/schedule/job_options.py
|
||||
|
||||
用途:平台任务参数 schema 的动态选项来源(options_source → 统一 label/value 列表)。
|
||||
依赖:models.Agent、shipping_notice.inventory_source_repository。
|
||||
依赖:models.Agent、shipping_notice.onhand_source_repository。
|
||||
逻辑:api/schedule/platform_tasks.py options 接口与 job_params 选项范围校验调用;
|
||||
前端只认识 options_source 字符串,不感知数据来自哪张表/哪个配置文件。
|
||||
货代 RPA 注册键为 freight_rpa_sources 与 freight_rpa_inbound_sources。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -35,7 +36,7 @@ def _agent_apps_options() -> list[dict[str, Any]]:
|
||||
|
||||
def _shipping_inventory_sources_options() -> list[dict[str, Any]]:
|
||||
"""启用中的货代库存源(value=source_code,来自数据库主数据)。"""
|
||||
from app.services.shipping_notice.inventory_source_repository import list_database_inventory_sources
|
||||
from app.services.shipping_notice.onhand_source_repository import list_database_inventory_sources
|
||||
|
||||
return [
|
||||
{
|
||||
@@ -53,11 +54,11 @@ def _shipping_inventory_sources_options() -> list[dict[str, Any]]:
|
||||
|
||||
def _shipping_receipt_sources_options() -> list[dict[str, Any]]:
|
||||
"""已启用且已配置收料报表的站点,供独立收料排程选择。"""
|
||||
from app.models import ShippingInventorySource, ShippingReceiptReportConfig
|
||||
from app.models import FreightRpaSource, FreightRpaInboundReportConfig
|
||||
|
||||
rows = db.session.query(ShippingInventorySource, ShippingReceiptReportConfig).join(
|
||||
ShippingReceiptReportConfig, ShippingReceiptReportConfig.inventory_source_id == ShippingInventorySource.id,
|
||||
).filter(ShippingInventorySource.enabled.is_(True)).all()
|
||||
rows = db.session.query(FreightRpaSource, FreightRpaInboundReportConfig).join(
|
||||
FreightRpaInboundReportConfig, FreightRpaInboundReportConfig.source_id == FreightRpaSource.id,
|
||||
).filter(FreightRpaSource.enabled.is_(True)).all()
|
||||
return [{
|
||||
'label': source.display_name or source.source_code, 'value': source.source_code,
|
||||
'description': f'{source.connector_type} · 收料已配置',
|
||||
@@ -101,8 +102,8 @@ def _users_options() -> list[dict[str, Any]]:
|
||||
# options_source 注册表:新增来源只需在此登记 provider,不动 API 层
|
||||
_OPTIONS_PROVIDERS: dict[str, Callable[[], list[dict[str, Any]]]] = {
|
||||
"agent_apps": _agent_apps_options,
|
||||
"shipping_inventory_sources": _shipping_inventory_sources_options,
|
||||
"shipping_receipt_sources": _shipping_receipt_sources_options,
|
||||
"freight_rpa_sources": _shipping_inventory_sources_options,
|
||||
"freight_rpa_inbound_sources": _shipping_receipt_sources_options,
|
||||
"hxops_users": _hxops_users_options,
|
||||
"users": _users_options,
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
backend/app/services/schedule/job_registry.py
|
||||
|
||||
用途:平台内置排程 Job Registry(任务契约中心:key → handler + 展示信息 + params_schema + defaults)。
|
||||
依赖:freight_onhand_rpa_job、faq_hot_aggregate_job、fixed_assets_snapshot_job、voucher_check_job、voucher_po_print_job、voucher_oa_sales_release_job、job_params。
|
||||
依赖:freight_rpa_onhand_job、faq_hot_aggregate_job、fixed_assets_snapshot_job、voucher_check_job、voucher_po_print_job、voucher_oa_sales_release_job、job_params。
|
||||
逻辑:internal_jobs API 与 platform_job 排程通过 platform_api_path 引用已注册 key;
|
||||
api/schedule/platform_tasks.py 下发 params_schema 供前端 DynamicTaskParamsForm 通用渲染。
|
||||
"""
|
||||
@@ -34,7 +34,7 @@ class PlatformJobDefinition:
|
||||
"label_key": "...", # 前端 i18n key(可选)
|
||||
"required": False,
|
||||
"default": [],
|
||||
"options_source": "shipping_inventory_sources", # select/multi_select 动态选项来源(可选)
|
||||
"options_source": "freight_rpa_sources", # select/multi_select 动态选项来源(可选)
|
||||
"placeholder": "...", "placeholder_key": "...",
|
||||
"help": "...", "help_key": "...",
|
||||
}
|
||||
@@ -44,7 +44,7 @@ class PlatformJobDefinition:
|
||||
label: str
|
||||
handler: PlatformJobHandler
|
||||
description: str = ""
|
||||
# 前端 i18n key(如 admin.schedule.form.platformJobShippingInventory);
|
||||
# 前端 i18n key(如 admin.schedule.form.platformJobFreightRpaOnhand);
|
||||
# 前端下拉优先 $t(label_key),label 仅作 fallback/debug。
|
||||
label_key: str = ""
|
||||
description_key: str = ""
|
||||
@@ -132,9 +132,9 @@ def _register_builtin_platform_jobs() -> None:
|
||||
from app.services.schedule.file_asset_cleanup_job import run_file_asset_cleanup_schedule
|
||||
from app.services.schedule.fixed_assets_snapshot_job import run_fixed_assets_snapshot_schedule
|
||||
from app.services.schedule.shipping_audit_retention_job import run_shipping_audit_retention_schedule
|
||||
from app.services.schedule.freight_onhand_rpa_job import run_shipping_inventory_rpa_schedule
|
||||
from app.services.schedule.freight_inbound_rpa_job import run_freight_receipt_rpa_schedule
|
||||
from app.services.schedule.freight_inbound_rpa_retention import run_freight_receipt_rpa_retention_schedule
|
||||
from app.services.schedule.freight_rpa_onhand_job import run_freight_rpa_onhand_schedule
|
||||
from app.services.schedule.freight_rpa_inbound_job import run_freight_receipt_rpa_schedule
|
||||
from app.services.schedule.freight_rpa_inbound_retention import run_freight_receipt_rpa_retention_schedule
|
||||
from app.services.schedule.shipping_order_extraction_progress_cleanup_job import run_shipping_order_extraction_progress_cleanup_schedule
|
||||
from app.services.schedule.shipping_post_ot_auto_fulfill_compensation_job import (
|
||||
run_shipping_post_ot_auto_fulfill_compensation_schedule,
|
||||
@@ -373,25 +373,25 @@ def _register_builtin_platform_jobs() -> None:
|
||||
register_platform_job(PlatformJobDefinition(
|
||||
key="freight-rpa-onhand",
|
||||
label="货代库存 RPA",
|
||||
label_key="admin.schedule.form.platformJobShippingInventory",
|
||||
handler=run_shipping_inventory_rpa_schedule,
|
||||
label_key="admin.schedule.form.platformJobFreightRpaOnhand",
|
||||
handler=run_freight_rpa_onhand_schedule,
|
||||
description="按计划从配置的库存源抓取库存数据,由 freight_rpa_worker 异步导出。",
|
||||
description_key="admin.schedule.form.shippingInventoryJobHint",
|
||||
description_key="admin.schedule.form.freightRpaOnhandJobHint",
|
||||
category="shipping",
|
||||
params_schema=(
|
||||
{
|
||||
"key": "source_codes",
|
||||
"type": "multi_select",
|
||||
"label": "库存源",
|
||||
"label_key": "admin.schedule.form.shippingInventorySources",
|
||||
"label_key": "admin.schedule.form.freightRpaSources",
|
||||
# 兼容历史任务语义:留空 = 导出全部启用库存源,故不设 required
|
||||
"required": False,
|
||||
"default": [],
|
||||
"options_source": "shipping_inventory_sources",
|
||||
"options_source": "freight_rpa_sources",
|
||||
"placeholder": "留空则导出全部启用库存源",
|
||||
"placeholder_key": "admin.schedule.form.shippingInventorySourcesPlaceholder",
|
||||
"placeholder_key": "admin.schedule.form.freightRpaSourcesPlaceholder",
|
||||
"help": "选择需要执行的库存源;选项来自库存源配置,留空则全部执行。",
|
||||
"help_key": "admin.schedule.form.shippingInventorySourcesHelp",
|
||||
"help_key": "admin.schedule.form.freightRpaSourcesHelp",
|
||||
},
|
||||
),
|
||||
defaults={"source_codes": []},
|
||||
@@ -404,7 +404,7 @@ def _register_builtin_platform_jobs() -> None:
|
||||
category="shipping",
|
||||
params_schema=({
|
||||
"key": "source_codes", "type": "multi_select", "label": "收料站点", "required": False,
|
||||
"default": [], "options_source": "shipping_receipt_sources",
|
||||
"default": [], "options_source": "freight_rpa_inbound_sources",
|
||||
"help": "选择需要执行的收料站点;留空则执行所有已启用收料配置。",
|
||||
},),
|
||||
defaults={"source_codes": []},
|
||||
@@ -596,7 +596,7 @@ def _register_builtin_platform_jobs() -> None:
|
||||
"label_key": "admin.schedule.form.transferSourceCodes",
|
||||
"required": False,
|
||||
"default": [],
|
||||
"options_source": "shipping_inventory_sources",
|
||||
"options_source": "freight_rpa_sources",
|
||||
},
|
||||
{
|
||||
"key": "recover_history",
|
||||
|
||||
@@ -9,8 +9,8 @@ from sqlalchemy.orm import joinedload
|
||||
from app import db
|
||||
from app.models import ScheduleRun, ScheduleTask
|
||||
from app.core.response import utc_iso
|
||||
from app.services.schedule.freight_onhand_rpa_archive import inventory_raw_zip_available_from_summary
|
||||
from app.services.schedule.freight_inbound_rpa_archive import receipt_raw_zip_available_from_summary
|
||||
from app.services.schedule.freight_rpa_onhand_archive import inventory_raw_zip_available_from_summary
|
||||
from app.services.schedule.freight_rpa_inbound_archive import receipt_raw_zip_available_from_summary
|
||||
from app.services.schedule.timezone_util import (
|
||||
DEFAULT_SCHEDULE_TIMEZONE,
|
||||
compute_next_run_at,
|
||||
|
||||
@@ -19,11 +19,11 @@ from app import db
|
||||
from app.jobs.queue import enqueue, fail_job, finish_job, recover_stale_jobs
|
||||
from app.jobs.types import JobType
|
||||
from app.models import Job, ScheduleRun, ScheduleTask
|
||||
from app.services.schedule.freight_onhand_rpa_finalize import (
|
||||
from app.services.schedule.freight_rpa_onhand_finalize import (
|
||||
recover_all_stale_awaiting_rpa_schedule_runs,
|
||||
recover_stale_awaiting_rpa_schedule_runs,
|
||||
)
|
||||
from app.services.schedule.freight_inbound_rpa_finalize import (
|
||||
from app.services.schedule.freight_rpa_inbound_finalize import (
|
||||
recover_all_stale_orphan_receipt_units,
|
||||
recover_all_stale_receipt_rpa_schedule_runs,
|
||||
recover_stale_receipt_rpa_schedule_runs,
|
||||
@@ -332,7 +332,7 @@ def prepare_schedule_queue() -> int:
|
||||
|
||||
if not _worker_initialized:
|
||||
# [STEP 1] 兼容升级前由 Web 线程留下的 running 记录;无活动 Job 承接时标记中断。
|
||||
from app.services.schedule.freight_onhand_rpa_finalize import is_awaiting_rpa_schedule_run
|
||||
from app.services.schedule.freight_rpa_onhand_finalize import is_awaiting_rpa_schedule_run
|
||||
|
||||
legacy_running = db.session.query(ScheduleRun).filter(ScheduleRun.status == "running").all()
|
||||
interrupted = 0
|
||||
@@ -379,7 +379,7 @@ def prepare_schedule_queue() -> int:
|
||||
|
||||
# 收料 run 超时对账同为每轮领取维护(2026-10-07 从启动一次性分支迁出):
|
||||
# 此前长驻进程期间超时 run 永不终态(RUN20261001131705E5E5 卡执行中的根因)。
|
||||
# 回收判据为最后活动锚(笔间静默),健康长批次不被误杀,见 freight_inbound_rpa_finalize。
|
||||
# 回收判据为最后活动锚(笔间静默),健康长批次不被误杀,见 freight_rpa_inbound_finalize。
|
||||
receipt_stale = recover_all_stale_receipt_rpa_schedule_runs()
|
||||
if receipt_stale:
|
||||
current_app.logger.info("[schedule-worker] recovered %d stale receipt RPA runs", receipt_stale)
|
||||
|
||||
@@ -23,8 +23,9 @@ VALID_DATA_PIPELINE_SOURCES = frozenset({DATA_SOURCE_DATABASE, DATA_SOURCE_EXTER
|
||||
|
||||
LEGACY_SCHEDULE_TYPES = frozenset({"platform_app", "dify_app"})
|
||||
|
||||
# 仍在导入 JSON 里出现的历史 data_source。货代在手任务的旧键已由 s17c 整列改写,
|
||||
# 运行期只认 platform job key freight-rpa-onhand。
|
||||
LEGACY_DATA_SOURCE_TO_PLATFORM_JOB = {
|
||||
"shipping_inventory_rpa": "freight-rpa-onhand",
|
||||
"faq_hot_aggregate": "faq-aggregate-hot",
|
||||
}
|
||||
|
||||
|
||||
@@ -18,19 +18,19 @@ from typing import Any
|
||||
from flask import current_app
|
||||
|
||||
from app import db
|
||||
from app.models import ScheduleRun, ScheduleTask, ShippingReceiptReportFile, User
|
||||
from app.models import ScheduleRun, ScheduleTask, FreightRpaInboundReportFile, User
|
||||
from app.services.schedule.cron_util import normalize_cron_expr
|
||||
from app.services.schedule.dify_snapshot import capture_dify_execution_snapshot
|
||||
from app.services.schedule.excel_service import export_schedule_result_excel
|
||||
from app.services.schedule import resolve_schedule_executor, resolve_schedule_header, normalize_platform_api_path
|
||||
from app.services.schedule.freight_inbound_rpa_job import INBOUND_RPA_JOB_KEY
|
||||
from app.services.schedule.freight_onhand_rpa_finalize import (
|
||||
from app.services.schedule.freight_rpa_inbound_job import INBOUND_RPA_JOB_KEY
|
||||
from app.services.schedule.freight_rpa_onhand_finalize import (
|
||||
apply_deferred_schedule_run_state,
|
||||
is_awaiting_rpa_schedule_run,
|
||||
recover_stale_awaiting_rpa_schedule_runs,
|
||||
should_defer_schedule_run_finalization,
|
||||
)
|
||||
from app.services.schedule.freight_inbound_rpa_finalize import (
|
||||
from app.services.schedule.freight_rpa_inbound_finalize import (
|
||||
apply_deferred_receipt_schedule_run_state,
|
||||
recover_stale_receipt_rpa_schedule_runs,
|
||||
should_defer_receipt_schedule_run,
|
||||
@@ -106,8 +106,8 @@ def _build_schedule_run_wecom_jump_params(task: ScheduleTask, run: ScheduleRun)
|
||||
核心逻辑:指向管理端 /admin/schedules;有原始库存/收料归档时附加 raw_zip=1
|
||||
与对应 download 意图,由前端登录后自动触发一次下载,失败时保留手动入口。
|
||||
"""
|
||||
from app.services.schedule.freight_onhand_rpa_archive import inventory_raw_zip_available_from_summary
|
||||
from app.services.schedule.freight_inbound_rpa_archive import receipt_raw_zip_available_from_summary
|
||||
from app.services.schedule.freight_rpa_onhand_archive import inventory_raw_zip_available_from_summary
|
||||
from app.services.schedule.freight_rpa_inbound_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] = {
|
||||
@@ -123,7 +123,7 @@ def _build_schedule_run_wecom_jump_params(task: ScheduleTask, run: ScheduleRun)
|
||||
return params
|
||||
|
||||
|
||||
def _receipt_report_files_for_run(run: ScheduleRun) -> list[ShippingReceiptReportFile]:
|
||||
def _receipt_report_files_for_run(run: ScheduleRun) -> list[FreightRpaInboundReportFile]:
|
||||
"""
|
||||
收集收料排程 run 名下可投递的收料报表文件;非收料任务返回空列表。
|
||||
|
||||
@@ -131,7 +131,7 @@ def _receipt_report_files_for_run(run: ScheduleRun) -> list[ShippingReceiptRepor
|
||||
未被清理(archive_deleted_at 为空)的报表文件。企微完成通知已改为发 ZIP,
|
||||
本函数保留给管理员单文件重发等旁路读取。
|
||||
"""
|
||||
from app.models import ShippingReceiptRpaUnitRun
|
||||
from app.models import FreightRpaInboundUnitRun
|
||||
|
||||
task = run.task
|
||||
if (
|
||||
@@ -141,14 +141,14 @@ def _receipt_report_files_for_run(run: ScheduleRun) -> list[ShippingReceiptRepor
|
||||
):
|
||||
return []
|
||||
return (
|
||||
ShippingReceiptReportFile.query.join(
|
||||
ShippingReceiptRpaUnitRun, ShippingReceiptReportFile.unit_run_id == ShippingReceiptRpaUnitRun.id,
|
||||
FreightRpaInboundReportFile.query.join(
|
||||
FreightRpaInboundUnitRun, FreightRpaInboundReportFile.unit_run_id == FreightRpaInboundUnitRun.id,
|
||||
)
|
||||
.filter(
|
||||
ShippingReceiptRpaUnitRun.schedule_run_id == run.id,
|
||||
ShippingReceiptReportFile.archive_deleted_at.is_(None),
|
||||
FreightRpaInboundUnitRun.schedule_run_id == run.id,
|
||||
FreightRpaInboundReportFile.archive_deleted_at.is_(None),
|
||||
)
|
||||
.order_by(ShippingReceiptReportFile.id)
|
||||
.order_by(FreightRpaInboundReportFile.id)
|
||||
.all()
|
||||
)
|
||||
|
||||
@@ -171,8 +171,8 @@ def _build_schedule_run_wecom_description(run: ScheduleRun) -> str:
|
||||
summary = run.response_summary_json if isinstance(run.response_summary_json, dict) else {}
|
||||
if summary.get('excel_failed') or summary.get('excel_export_status') == 'failed':
|
||||
description += '\n备注: 库存源已成功,但排程 Excel 生成失败'
|
||||
from app.services.schedule.freight_onhand_rpa_archive import inventory_raw_zip_available_from_summary
|
||||
from app.services.schedule.freight_inbound_rpa_archive import receipt_raw_zip_available_from_summary
|
||||
from app.services.schedule.freight_rpa_onhand_archive import inventory_raw_zip_available_from_summary
|
||||
from app.services.schedule.freight_rpa_inbound_archive import receipt_raw_zip_available_from_summary
|
||||
|
||||
if inventory_raw_zip_available_from_summary(summary):
|
||||
description += '\n原始库存包:点击本通知,登录 HXOPS 后自动下载'
|
||||
@@ -238,7 +238,7 @@ def _notify_schedule_run_wecom(task: ScheduleTask, run: ScheduleRun) -> None:
|
||||
raw_zip_media_id = None
|
||||
raw_zip_file_name = None
|
||||
try:
|
||||
from app.services.schedule.freight_onhand_rpa_archive import resolve_inventory_raw_zip_download
|
||||
from app.services.schedule.freight_rpa_onhand_archive import resolve_inventory_raw_zip_download
|
||||
|
||||
raw_zip_path, raw_zip_file_name = resolve_inventory_raw_zip_download(run)
|
||||
raw_zip_media_id = upload_wecom_temp_media(raw_zip_path.read_bytes(), raw_zip_file_name)
|
||||
@@ -251,7 +251,7 @@ def _notify_schedule_run_wecom(task: ScheduleTask, run: ScheduleRun) -> None:
|
||||
receipt_zip_media_id = None
|
||||
receipt_zip_file_name = None
|
||||
try:
|
||||
from app.services.schedule.freight_inbound_rpa_archive import resolve_receipt_raw_zip_download
|
||||
from app.services.schedule.freight_rpa_inbound_archive import resolve_receipt_raw_zip_download
|
||||
|
||||
receipt_zip_path, receipt_zip_file_name = resolve_receipt_raw_zip_download(run)
|
||||
receipt_zip_media_id = upload_wecom_temp_media(
|
||||
|
||||
@@ -16,7 +16,7 @@ from app.services.shipping_notice.line_auto_fulfill_coordinator import (
|
||||
coordinate_post_ot_auto_fulfill,
|
||||
enqueue_post_ot_auto_fulfill_job,
|
||||
)
|
||||
from app.services.shipping_notice.line_inventory_match_projection import line_auto_fulfill_enabled
|
||||
from app.services.shipping_notice.line_onhand_match_projection import line_auto_fulfill_enabled
|
||||
from app.services.shipping_notice.post_ot_fulfillment_wave_service import (
|
||||
list_eligible_post_ot_snapshot_line_ids,
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user