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
@@ -1,7 +1,7 @@
|
||||
"""
|
||||
backend/app/api/workspace/__init__.py
|
||||
|
||||
用途:工作台域 Blueprint 聚合(schedule、shipping_notice、file_check、announcements)。
|
||||
用途:工作台域 Blueprint 聚合(schedule、shipping_notice、file_check、voucher_check、announcements)。
|
||||
依赖:workspace 各子模块 blueprint。
|
||||
逻辑:import 子模块注册路由;register_blueprints 从本包导入各 bp。
|
||||
"""
|
||||
@@ -9,10 +9,12 @@ from app.api.workspace.announcements import workspace_announcements_bp
|
||||
from app.api.workspace.file_check import workspace_file_check_bp
|
||||
from app.api.workspace.schedule import workspace_schedule_bp
|
||||
from app.api.workspace.shipping_notice import workspace_shipping_notice_bp
|
||||
from app.api.workspace.voucher_check import workspace_voucher_check_bp
|
||||
|
||||
__all__ = [
|
||||
'workspace_announcements_bp',
|
||||
'workspace_file_check_bp',
|
||||
'workspace_schedule_bp',
|
||||
'workspace_shipping_notice_bp',
|
||||
'workspace_voucher_check_bp',
|
||||
]
|
||||
@@ -57,6 +57,31 @@ def serialize_current_step(payload: dict) -> dict | None:
|
||||
return None
|
||||
return {'step': str(current_step.get('step') or ''), 'label': str(current_step.get('label') or current_step.get('step') or ''), 'row_id': current_step.get('row_id'), 'started_at': current_step.get('started_at'), 'processed_count': int(current_step.get('processed_count') or 0), 'success_count': int(current_step.get('success_count') or 0), 'failed_count': int(current_step.get('failed_count') or 0), 'skipped_count': int(current_step.get('skipped_count') or 0)}
|
||||
|
||||
def serialize_progress_metrics(payload: dict) -> list[dict] | None:
|
||||
"""
|
||||
序列化领域自定义进度指标(如立账凭证检核的齐全/缺资料)。
|
||||
核心逻辑:读取 response_summary_json.progress_metrics;非法则返回 None 以回退旧八格。
|
||||
"""
|
||||
response_summary = payload.get('response_summary_json') if isinstance(payload.get('response_summary_json'), dict) else {}
|
||||
metrics = response_summary.get('progress_metrics')
|
||||
if not isinstance(metrics, list) or not metrics:
|
||||
return None
|
||||
out: list[dict] = []
|
||||
for item in metrics:
|
||||
if not isinstance(item, dict):
|
||||
continue
|
||||
key = str(item.get('key') or '').strip()
|
||||
if not key:
|
||||
continue
|
||||
out.append({
|
||||
'key': key,
|
||||
'label_key': str(item.get('label_key') or ''),
|
||||
'label': str(item.get('label') or ''),
|
||||
'value': int(item.get('value') or 0),
|
||||
})
|
||||
return out or None
|
||||
|
||||
|
||||
def _serialize_progress_run(run: ScheduleRun) -> dict:
|
||||
payload = serialize_run(run)
|
||||
total = int(payload.get('total_count') or 0)
|
||||
@@ -66,7 +91,39 @@ def _serialize_progress_run(run: ScheduleRun) -> dict:
|
||||
processed = success + failed + skipped
|
||||
percent = int(round(processed / total * 100)) if total > 0 else 0
|
||||
percent = max(0, min(percent, 100))
|
||||
return {'run_id': payload['id'], 'run_no': payload['run_no'], 'task_id': payload['schedule_task_id'], 'title': payload.get('schedule_name') or '', 'status': payload['status'], 'total_count': total, 'processed_count': processed, 'success_count': success, 'failed_count': failed, 'skipped_count': skipped, 'judgement': serialize_file_judgement(payload), 'current_step': serialize_current_step(payload), 'progress_percent': percent, 'started_at': payload.get('started_at'), 'finished_at': payload.get('finished_at'), 'duration_ms': payload.get('duration_ms'), 'error_message': payload.get('error_message'), 'excel': {'file_name': payload.get('excel_file_name'), 'file_size': payload.get('excel_file_size'), 'download_url': f'/api/workspace/file-check/runs/{run.id}/excel' if payload.get('excel_file_name') else None}, 'knowledge_base': {'sync_status': payload.get('kb_sync_status'), 'group_id': payload.get('kb_group_id'), 'document_id': payload.get('kb_document_id'), 'document_version_id': payload.get('kb_document_version_id'), 'sync_job_id': payload.get('kb_sync_job_id'), 'error_message': payload.get('kb_sync_error')}}
|
||||
return {
|
||||
'run_id': payload['id'],
|
||||
'run_no': payload['run_no'],
|
||||
'task_id': payload['schedule_task_id'],
|
||||
'title': payload.get('schedule_name') or '',
|
||||
'status': payload['status'],
|
||||
'total_count': total,
|
||||
'processed_count': processed,
|
||||
'success_count': success,
|
||||
'failed_count': failed,
|
||||
'skipped_count': skipped,
|
||||
'judgement': serialize_file_judgement(payload),
|
||||
'progress_metrics': serialize_progress_metrics(payload),
|
||||
'current_step': serialize_current_step(payload),
|
||||
'progress_percent': percent,
|
||||
'started_at': payload.get('started_at'),
|
||||
'finished_at': payload.get('finished_at'),
|
||||
'duration_ms': payload.get('duration_ms'),
|
||||
'error_message': payload.get('error_message'),
|
||||
'excel': {
|
||||
'file_name': payload.get('excel_file_name'),
|
||||
'file_size': payload.get('excel_file_size'),
|
||||
'download_url': f'/api/workspace/file-check/runs/{run.id}/excel' if payload.get('excel_file_name') else None,
|
||||
},
|
||||
'knowledge_base': {
|
||||
'sync_status': payload.get('kb_sync_status'),
|
||||
'group_id': payload.get('kb_group_id'),
|
||||
'document_id': payload.get('kb_document_id'),
|
||||
'document_version_id': payload.get('kb_document_version_id'),
|
||||
'sync_job_id': payload.get('kb_sync_job_id'),
|
||||
'error_message': payload.get('kb_sync_error'),
|
||||
},
|
||||
}
|
||||
|
||||
@workspace_file_check_bp.route('/file-check/runs/for-log', methods=['GET'])
|
||||
def workspace_file_check_run_for_log():
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
"""
|
||||
backend/app/api/workspace/voucher_check.py
|
||||
|
||||
用途:工作台立账凭证检核记录查询 API(批次明细 / 最新状态)。
|
||||
依赖:auth.jwt、response_utils envelope、voucher_check.query_service。
|
||||
逻辑:对话与检核记录页共用;标准 {success,data|error,request_id} envelope。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from flask import Blueprint, request
|
||||
|
||||
from app.core.auth.jwt import get_current_user
|
||||
from app.core.errors import UnauthorizedError
|
||||
from app.core.response import ok
|
||||
from app.services.voucher_check import query_service
|
||||
|
||||
workspace_voucher_check_bp = Blueprint("workspace_voucher_check", __name__)
|
||||
|
||||
|
||||
def _require_user():
|
||||
user = get_current_user()
|
||||
if not user:
|
||||
raise UnauthorizedError()
|
||||
return user
|
||||
|
||||
|
||||
@workspace_voucher_check_bp.route("/accounting-voucher-check/runs/<int:run_id>/items", methods=["GET"])
|
||||
def workspace_voucher_run_items(run_id: int):
|
||||
"""
|
||||
分页查看批次明细。
|
||||
核心逻辑:委托 query_service.list_run_items,可按 result 过滤。
|
||||
"""
|
||||
_require_user()
|
||||
data = query_service.list_run_items(
|
||||
run_id=run_id,
|
||||
result=request.args.get("result"),
|
||||
page=request.args.get("page", default=1, type=int) or 1,
|
||||
page_size=request.args.get("page_size", default=50, type=int) or 50,
|
||||
)
|
||||
return ok(data)
|
||||
|
||||
|
||||
@workspace_voucher_check_bp.route("/accounting-voucher-check/states", methods=["GET"])
|
||||
def workspace_voucher_states():
|
||||
"""
|
||||
按月份、状态、发票号筛选最新状态。
|
||||
"""
|
||||
_require_user()
|
||||
data = query_service.list_states(
|
||||
scope_code=str(request.args.get("scope_code") or "HXJM"),
|
||||
period=request.args.get("period"),
|
||||
status=request.args.get("status"),
|
||||
invoice_no=request.args.get("invoice_no"),
|
||||
page=request.args.get("page", default=1, type=int) or 1,
|
||||
page_size=request.args.get("page_size", default=50, type=int) or 50,
|
||||
)
|
||||
return ok(data)
|
||||
|
||||
|
||||
@workspace_voucher_check_bp.route("/accounting-voucher-check/states/<path:invoice_no>", methods=["GET"])
|
||||
def workspace_voucher_state_detail(invoice_no: str):
|
||||
"""查看单票最近状态和历史批次快照。"""
|
||||
_require_user()
|
||||
data = query_service.get_invoice_latest(
|
||||
invoice_no=invoice_no,
|
||||
scope_code=str(request.args.get("scope_code") or "HXJM"),
|
||||
period=request.args.get("period"),
|
||||
)
|
||||
return ok(data)
|
||||
Reference in new issue
Block a user