Merge branch 'hugo-shipping-notice' into dev
# Conflicts: # backend/app/api/__init__.py # backend/app/jobs/types.py # backend/app/models/__init__.py # backend/app/services/schedule/job_registry.py # docs/features/README.md # docs/funclist.md # docs/tec.md # frontend/src/locales/zh-CN/admin.json
This commit is contained in:
commit
dac31e48bd
691 files changed
+53341
-14863
No files matched your search
@@ -40,7 +40,7 @@ def run_freight_receipt_rpa_retention_schedule(task: Any, run: Any) -> tuple[int
|
||||
append_shipping_audit_event(
|
||||
event_type='shipping_receipt_report_archive_delete_attempted', aggregate_type='shipping_receipt_file',
|
||||
aggregate_id=str(report_file.id), actor_type='worker', actor_id='receipt-retention',
|
||||
unit_id=report_file.unit_run_id, result='failed',
|
||||
unit_id=report_file.unit_run_id, result='failure',
|
||||
before={'status': 'archived'}, after={'status': 'archived', 'delete_error': str(exc)[:2000]},
|
||||
artifact_refs=[{'kind': 'receipt_report', 'id': str(report_file.id), 'sha256': report_file.sha256}],
|
||||
)
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
"""独立收料文件抓取排程(08:00)。
|
||||
|
||||
用途:为已启用来源实例确保当日 ready 收料文件;缺文件时按来源触发收料 RPA。
|
||||
依赖:schedule.job_registry 的 ScheduleExecuteResult、transfer deps、file_preparation。
|
||||
逻辑:与 09:00 自动调拨解耦;自动调拨仍会调用统一文件准备服务,不假设本排程成功。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from app.models import ScheduleRun, ScheduleTask
|
||||
from app.services.in_transit_transfer import deps as transfer_deps
|
||||
from app.services.in_transit_transfer.date_policy import business_date_now
|
||||
from app.services.in_transit_transfer.file_preparation import ensure_receipt_file_ready
|
||||
from app.services.schedule.job_registry import ScheduleExecuteResult
|
||||
|
||||
|
||||
def _wanted_sources(task: ScheduleTask) -> list[str]:
|
||||
"""提取结构化 source_codes;留空代表全部启用来源。"""
|
||||
params = task.job_params if isinstance(task.job_params, dict) else {}
|
||||
values = params.get("source_codes") or []
|
||||
if isinstance(values, str):
|
||||
values = [values]
|
||||
return [str(item).strip() for item in values if str(item).strip()]
|
||||
|
||||
|
||||
def run_in_transit_receipt_file_schedule(task: ScheduleTask, run: ScheduleRun) -> ScheduleExecuteResult:
|
||||
"""08:00 收料文件抓取;按来源实例独立执行。"""
|
||||
deps = transfer_deps.get_transfer_dependencies()
|
||||
sources = _wanted_sources(task) or []
|
||||
business_date = str(business_date_now())
|
||||
total = success = failed = empty = 0
|
||||
results: list[dict[str, Any]] = []
|
||||
warnings: list[str] = []
|
||||
errors: list[str] = []
|
||||
for source_code in sources:
|
||||
total += 1
|
||||
try:
|
||||
prepared = ensure_receipt_file_ready(
|
||||
source_code=source_code,
|
||||
business_date=business_date,
|
||||
repository=deps.file_repository,
|
||||
rpa_trigger=deps.rpa_trigger,
|
||||
)
|
||||
results.append({"source_code": source_code, "stage": prepared.stage})
|
||||
if prepared.stage == "file_ready":
|
||||
success += 1
|
||||
elif prepared.stage == "waiting_rpa_callback":
|
||||
empty += 1
|
||||
else:
|
||||
failed += 1
|
||||
errors.append(f"{source_code}: {prepared.error_code or 'file_prep_failed'}")
|
||||
except Exception as exc: # noqa: BLE001 —— 来源隔离
|
||||
failed += 1
|
||||
errors.append(f"{source_code}: {exc}")
|
||||
return (total, success, failed, empty, results, warnings, errors)
|
||||
@@ -0,0 +1,59 @@
|
||||
"""自动调拨排程(09:00)。
|
||||
|
||||
用途:自动处理当日新成熟可调拨项与历史可恢复异常,并发送一次企微汇总通知。
|
||||
依赖:auto_transfer、transfer deps、ScheduleExecuteResult。
|
||||
逻辑:复用统一文件准备服务,不假设 08:00 排程成功;来源实例独立执行。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from app.models import ScheduleRun, ScheduleTask
|
||||
from app.services.in_transit_transfer import deps as transfer_deps
|
||||
from app.services.in_transit_transfer.auto_transfer import run_auto_transfer
|
||||
from app.services.in_transit_transfer.date_policy import business_date_now
|
||||
from app.services.schedule.job_registry import ScheduleExecuteResult
|
||||
|
||||
|
||||
def _task_params(task: ScheduleTask) -> dict[str, Any]:
|
||||
return task.job_params if isinstance(task.job_params, dict) else {}
|
||||
|
||||
|
||||
def run_in_transit_transfer_schedule(task: ScheduleTask, run: ScheduleRun) -> ScheduleExecuteResult:
|
||||
"""09:00 自动调拨:恢复 + 预检 + 执行 + 通知。"""
|
||||
params = _task_params(task)
|
||||
source_codes = params.get("source_codes") or []
|
||||
if isinstance(source_codes, str):
|
||||
source_codes = [source_codes]
|
||||
recover_history = bool(params.get("recover_history", True))
|
||||
recipients = params.get("notify_user_ids") or []
|
||||
|
||||
deps = transfer_deps.get_transfer_dependencies()
|
||||
outcome = run_auto_transfer(
|
||||
business_date=str(business_date_now()),
|
||||
deps=deps,
|
||||
source_codes=[str(item).strip() for item in source_codes],
|
||||
recover_history=recover_history,
|
||||
sender=None, # 企微发送器在 deps/运维接线处注入(本期先记录阶段结果)
|
||||
recipients=[str(item) for item in recipients],
|
||||
)
|
||||
results: list[dict[str, Any]] = []
|
||||
errors: list[str] = list(outcome.errors)
|
||||
if outcome.run_no:
|
||||
results.append({
|
||||
"run_no": outcome.run_no,
|
||||
"status": outcome.run_status,
|
||||
"notification_status": outcome.notification_status,
|
||||
})
|
||||
recovery = outcome.recovery
|
||||
success = 1 if outcome.run_status in {"success", "partial_failed"} else 0
|
||||
return (
|
||||
success + recovery.recovered_count,
|
||||
success,
|
||||
recovery.still_blocked_count,
|
||||
0,
|
||||
results,
|
||||
[f"recovered={recovery.recovered_count} still_blocked={recovery.still_blocked_count}"],
|
||||
errors,
|
||||
)
|
||||
@@ -178,6 +178,8 @@ def _register_builtin_platform_jobs() -> None:
|
||||
description="按预付款、出货款、验收款、质保款的三轮升级规则发送企业微信提醒。",
|
||||
category="procurement",
|
||||
))
|
||||
from app.services.schedule.in_transit_receipt_file_job import run_in_transit_receipt_file_schedule
|
||||
from app.services.schedule.in_transit_transfer_job import run_in_transit_transfer_schedule
|
||||
|
||||
register_platform_job(PlatformJobDefinition(
|
||||
key="shipping-order-extraction-progress-cleanup",
|
||||
@@ -403,6 +405,67 @@ def _register_builtin_platform_jobs() -> None:
|
||||
),
|
||||
defaults=dict(DEFAULT_JOB_PARAMS),
|
||||
))
|
||||
register_platform_job(PlatformJobDefinition(
|
||||
key="in-transit-receipt-file",
|
||||
label="在途收料文件抓取",
|
||||
handler=run_in_transit_receipt_file_schedule,
|
||||
description=(
|
||||
"每日 08:00 为已启用来源实例确保当日 ready 收料文件;缺文件时按来源触发收料 RPA。"
|
||||
"09:00 自动调拨仍会调用统一文件准备服务,不假设本排程成功。"
|
||||
),
|
||||
category="platform",
|
||||
params_schema=(
|
||||
{
|
||||
"key": "source_codes",
|
||||
"type": "multi_select",
|
||||
"label": "来源实例",
|
||||
"label_key": "admin.schedule.form.transferSourceCodes",
|
||||
"required": False,
|
||||
"default": [],
|
||||
"options_source": "shipping_inventory_sources",
|
||||
},
|
||||
),
|
||||
defaults={"source_codes": []},
|
||||
))
|
||||
register_platform_job(PlatformJobDefinition(
|
||||
key="in-transit-transfer",
|
||||
label="在途自动调拨",
|
||||
handler=run_in_transit_transfer_schedule,
|
||||
description=(
|
||||
"每日 09:00 自动处理新增可调拨项与历史可恢复异常;"
|
||||
"每非空 Run 发送一条企微汇总通知;通知失败不改变 ERP 结果。"
|
||||
),
|
||||
category="platform",
|
||||
params_schema=(
|
||||
{
|
||||
"key": "source_codes",
|
||||
"type": "multi_select",
|
||||
"label": "来源实例",
|
||||
"label_key": "admin.schedule.form.transferSourceCodes",
|
||||
"required": False,
|
||||
"default": [],
|
||||
"options_source": "shipping_inventory_sources",
|
||||
},
|
||||
{
|
||||
"key": "recover_history",
|
||||
"type": "boolean",
|
||||
"label": "历史可恢复异常复核",
|
||||
"label_key": "admin.schedule.form.transferRecoverHistory",
|
||||
"required": False,
|
||||
"default": True,
|
||||
},
|
||||
{
|
||||
"key": "notify_user_ids",
|
||||
"type": "multi_select",
|
||||
"label": "通知人",
|
||||
"label_key": "admin.schedule.form.transferNotifyUsers",
|
||||
"required": False,
|
||||
"default": [],
|
||||
"options_source": "users",
|
||||
},
|
||||
),
|
||||
defaults={"source_codes": [], "recover_history": True, "notify_user_ids": []},
|
||||
))
|
||||
|
||||
|
||||
_register_builtin_platform_jobs()
|
||||
@@ -2,7 +2,7 @@
|
||||
services/schedule/shipping_post_ot_auto_fulfill_compensation_job.py
|
||||
|
||||
用途:OT 后行级自动履约补偿轮询(每 15 分钟)——补齐 matching/ot_created 事件丢失。
|
||||
依赖:line_auto_fulfill_coordinator、ShippingOrderReviewCase、list_eligible_post_ot_line_keys。
|
||||
依赖:line_auto_fulfill_coordinator、ShippingOrderReviewCase、list_eligible_post_ot_snapshot_line_ids。
|
||||
逻辑:platform_api_path=shipping-post-ot-auto-fulfill-compensation;flag 关闭时 no-op;
|
||||
仅扫描有正式 OT 且存在 eligible 行的 Case,复用 coordinate_post_ot_auto_fulfill(trigger=compensation)。
|
||||
"""
|
||||
@@ -18,7 +18,7 @@ from app.services.shipping_notice.line_auto_fulfill_coordinator import (
|
||||
)
|
||||
from app.services.shipping_notice.line_inventory_match_projection import line_auto_fulfill_enabled
|
||||
from app.services.shipping_notice.post_ot_fulfillment_wave_service import (
|
||||
list_eligible_post_ot_line_keys,
|
||||
list_eligible_post_ot_snapshot_line_ids,
|
||||
)
|
||||
|
||||
ScheduleExecuteResult = tuple[int, int, int, int, list[dict[str, Any]], list[str], list[dict[str, Any]]]
|
||||
@@ -63,7 +63,7 @@ def run_post_ot_auto_fulfill_compensation(*, limit: int = 50) -> dict[str, Any]:
|
||||
if scanned >= safe_limit:
|
||||
break
|
||||
scanned += 1
|
||||
eligible = list_eligible_post_ot_line_keys(case)
|
||||
eligible = list_eligible_post_ot_snapshot_line_ids(case)
|
||||
if not eligible:
|
||||
skipped += 1
|
||||
continue
|
||||
|
||||
Reference in new issue
Block a user