feat(agent): 立账凭证检核
(cherry picked from commit f9e2fb5efc1ec7bf4f6e52e08dd3591b4e77edd9)
This commit is contained in:
1 parent
9bcbf9d211
commit
f615e56bb9
70 files changed
+4968
-108
No files matched your search
@@ -81,7 +81,10 @@ def _run_platform_job_in_process(task: ScheduleTask, run: ScheduleRun) -> Schedu
|
||||
from app.services.schedule.job_registry import run_platform_job
|
||||
|
||||
key = normalize_platform_api_path(task.platform_api_path)
|
||||
# [STEP 1] 合并而非覆盖:保留会话触发写入的 run_options 等字段
|
||||
existing = run.api_request_json if isinstance(run.api_request_json, dict) else {}
|
||||
payload = {
|
||||
**existing,
|
||||
"run_no": run.run_no,
|
||||
"schedule_task_id": task.id,
|
||||
"schedule_name": task.name,
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
backend/app/services/schedule/job_registry.py
|
||||
|
||||
用途:平台内置排程 Job Registry(任务契约中心:key → handler + 展示信息 + params_schema + defaults)。
|
||||
依赖:shipping_inventory_rpa_job、faq_hot_aggregate_job、fixed_assets_snapshot_job、job_params(执行前校验)。
|
||||
依赖:shipping_inventory_rpa_job、faq_hot_aggregate_job、fixed_assets_snapshot_job、voucher_check_job、job_params。
|
||||
逻辑:internal_jobs API 与 platform_job 排程通过 platform_api_path 引用已注册 key;
|
||||
api/schedule/platform_tasks.py 下发 params_schema 供前端 DynamicTaskParamsForm 通用渲染。
|
||||
"""
|
||||
@@ -132,6 +132,8 @@ 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_inventory_rpa_job import run_shipping_inventory_rpa_schedule
|
||||
from app.services.schedule.voucher_check_job import run_voucher_check_schedule
|
||||
from app.services.voucher_check.config import DEFAULT_JOB_PARAMS, DEFAULT_REQUIRED_FILES
|
||||
|
||||
register_platform_job(PlatformJobDefinition(
|
||||
key="shipping-inventory-rpa",
|
||||
@@ -200,6 +202,77 @@ def _register_builtin_platform_jobs() -> None:
|
||||
description="按 TTL 清理未建单、未引用的临时 FileAsset 与关联 intake,并删除私有 MinIO 对象。",
|
||||
category="files",
|
||||
))
|
||||
register_platform_job(PlatformJobDefinition(
|
||||
key="accounting-voucher-check",
|
||||
label="立账凭证检核",
|
||||
label_key="admin.schedule.form.platformJobAccountingVoucherCheck",
|
||||
handler=run_voucher_check_schedule,
|
||||
description="按当前自然月拉取 ERP 发票清单,扫描共享盘必检材料是否存在(不读文件内容)。",
|
||||
description_key="admin.schedule.form.accountingVoucherCheckHint",
|
||||
category="finance",
|
||||
params_schema=(
|
||||
{
|
||||
"key": "scope_code",
|
||||
"type": "select",
|
||||
"label": "账套",
|
||||
"label_key": "admin.schedule.form.voucherCheckScope",
|
||||
"required": True,
|
||||
"default": "HXJM",
|
||||
"options": [{"value": "HXJM", "label": "HXJM"}],
|
||||
},
|
||||
{
|
||||
"key": "directory_template",
|
||||
"type": "text",
|
||||
"label": "目录模板",
|
||||
"label_key": "admin.schedule.form.voucherCheckDirTemplate",
|
||||
"required": True,
|
||||
"default": "{root}/{YYYY}/{MM}/{invoice_no}",
|
||||
"help": "仅允许 {root}/{YYYY}/{MM}/{invoice_no}",
|
||||
"help_key": "admin.schedule.form.voucherCheckDirTemplateHelp",
|
||||
},
|
||||
{
|
||||
"key": "required_files",
|
||||
"type": "json",
|
||||
"label": "必检材料",
|
||||
"label_key": "admin.schedule.form.voucherCheckRequiredFiles",
|
||||
"required": True,
|
||||
"default": DEFAULT_REQUIRED_FILES,
|
||||
},
|
||||
{
|
||||
"key": "filename_case_sensitive",
|
||||
"type": "boolean",
|
||||
"label": "文件名区分大小写",
|
||||
"label_key": "admin.schedule.form.voucherCheckCaseSensitive",
|
||||
"required": True,
|
||||
"default": True,
|
||||
},
|
||||
{
|
||||
"key": "notify_missing_enabled",
|
||||
"type": "boolean",
|
||||
"label": "缺资料通知",
|
||||
"label_key": "admin.schedule.form.voucherCheckNotifyMissing",
|
||||
"required": False,
|
||||
"default": True,
|
||||
},
|
||||
{
|
||||
"key": "notify_failure_enabled",
|
||||
"type": "boolean",
|
||||
"label": "失败告警",
|
||||
"label_key": "admin.schedule.form.voucherCheckNotifyFailure",
|
||||
"required": False,
|
||||
"default": True,
|
||||
},
|
||||
{
|
||||
"key": "same_day_dedup_enabled",
|
||||
"type": "boolean",
|
||||
"label": "同票同日去重",
|
||||
"label_key": "admin.schedule.form.voucherCheckSameDayDedup",
|
||||
"required": False,
|
||||
"default": True,
|
||||
},
|
||||
),
|
||||
defaults=dict(DEFAULT_JOB_PARAMS),
|
||||
))
|
||||
|
||||
|
||||
_register_builtin_platform_jobs()
|
||||
@@ -142,6 +142,11 @@ def _build_schedule_run_wecom_description(run: ScheduleRun) -> str:
|
||||
|
||||
|
||||
def _notify_schedule_run_wecom(task: ScheduleTask, run: ScheduleRun) -> None:
|
||||
"""
|
||||
排程完成后的通用企微通知。
|
||||
核心逻辑:若 response_summary_json.domain_notification_managed=true(如立账凭证检核),
|
||||
则跳过以免与领域缺件/失败告警重复。
|
||||
"""
|
||||
from app.services.wecom_notify import (
|
||||
upload_wecom_temp_media,
|
||||
send_wecom_file_message,
|
||||
@@ -151,6 +156,12 @@ def _notify_schedule_run_wecom(task: ScheduleTask, run: ScheduleRun) -> None:
|
||||
_get_enabled_events,
|
||||
)
|
||||
|
||||
# 领域自行管理通知时跳过通用完成通知,避免重复刷屏
|
||||
summary = run.response_summary_json if isinstance(run.response_summary_json, dict) else {}
|
||||
if summary.get('domain_notification_managed'):
|
||||
run.wecom_notify_error = 'domain_notification_managed'
|
||||
return
|
||||
|
||||
if not current_app.config.get('WECOM_NOTIFY_ENABLED', True):
|
||||
run.wecom_notify_error = 'WECOM_NOTIFY_ENABLED=false'
|
||||
return
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
"""
|
||||
backend/app/services/schedule/voucher_check_job.py
|
||||
|
||||
用途:立账凭证检核 platform_job 薄封装。
|
||||
依赖:voucher_check.runner、excel_rows 表头注册。
|
||||
逻辑:job_registry 注册 accounting-voucher-check 后由 schedule worker / 会话触发调用。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from app.models import ScheduleRun, ScheduleTask
|
||||
from app.services.schedule import register_schedule_header
|
||||
from app.services.voucher_check.excel_rows import (
|
||||
VOUCHER_CHECK_HEADER_LABELS,
|
||||
VOUCHER_CHECK_HEADER_ORDER,
|
||||
)
|
||||
from app.services.voucher_check.runner import run_voucher_check_batch
|
||||
|
||||
ScheduleExecuteResult = tuple[int, int, int, int, list[dict[str, Any]], list[str], list[dict[str, Any]]]
|
||||
|
||||
_HEADERS_REGISTERED = False
|
||||
|
||||
|
||||
def _ensure_headers() -> None:
|
||||
global _HEADERS_REGISTERED
|
||||
if _HEADERS_REGISTERED:
|
||||
return
|
||||
register_schedule_header(
|
||||
"accounting-voucher-check",
|
||||
VOUCHER_CHECK_HEADER_ORDER,
|
||||
VOUCHER_CHECK_HEADER_LABELS,
|
||||
)
|
||||
_HEADERS_REGISTERED = True
|
||||
|
||||
|
||||
def run_voucher_check_schedule(task: ScheduleTask, run: ScheduleRun) -> ScheduleExecuteResult:
|
||||
"""
|
||||
执行立账凭证检核排程。
|
||||
核心逻辑:注册 Excel 表头后委托 runner;日批默认 incremental。
|
||||
"""
|
||||
_ensure_headers()
|
||||
return run_voucher_check_batch(task, run)
|
||||
Reference in new issue
Block a user