feat(shipping-notice): 增强订单抽取与审计功能,支持取消与保留策略
- 在环境配置中新增进度细化、订单提取取消与审计导出相关的开关 - 实现订单抽取运行的取消功能,允许管理员在运行中进行操作 - 引入审计事件的保留策略,支持三年保留期的自动清理 - 更新相关模型与服务,确保新功能的完整性与可追溯性 - 增强文档与代码注释,反映新的业务逻辑与审计要求
This commit is contained in:
1 parent
c85997884b
commit
95cdfe66b0
158 files changed
+19005
-1201
No files matched your search
@@ -971,7 +971,7 @@ def workspace_generate_shipping_excel(task_no: str):
|
||||
|
||||
@workspace_shipping_notice_bp.route('/shipping-tasks/<task_no>/export', methods=['GET'])
|
||||
def workspace_shipping_task_export(task_no: str):
|
||||
"""下载当前用户可访问任务的出货 Excel。"""
|
||||
"""下载当前用户可访问任务的出货 Excel;写入统一访问审计。"""
|
||||
user = _require_user()
|
||||
task = get_task_for_user(task_no, user.id)
|
||||
err_msg = task_export_error_message(task)
|
||||
@@ -980,6 +980,15 @@ def workspace_shipping_task_export(task_no: str):
|
||||
resolved = resolve_task_export_download(task)
|
||||
assert resolved is not None
|
||||
path, download_name = resolved
|
||||
from app.services.shipping_notice.fulfillment_audit import record_access_audit
|
||||
record_access_audit(
|
||||
action='download_task_excel',
|
||||
aggregate_type='shipping_task',
|
||||
aggregate_id=str(task.task_no),
|
||||
actor_id=user.id,
|
||||
task_no=str(task.task_no),
|
||||
metadata={'export': 'excel'},
|
||||
)
|
||||
return send_file(path, as_attachment=True, download_name=download_name, mimetype=EXPORT_MIME_TYPE)
|
||||
|
||||
|
||||
@@ -1053,54 +1062,106 @@ def workspace_create_shipping_order_extraction_run():
|
||||
|
||||
@workspace_shipping_notice_bp.route('/shipping-notice/order-extraction-runs/<run_no>', methods=['GET'])
|
||||
def workspace_get_shipping_order_extraction_run(run_no: str):
|
||||
"""查询当前用户的一次订单抽取 Run;正文快照不会暴露给前端。"""
|
||||
"""查询当前用户的一次订单抽取 Run;正文快照不会暴露给前端;访问留痕。"""
|
||||
user = _require_user()
|
||||
from app.services.shipping_notice.fulfillment_audit import record_access_audit
|
||||
from app.services.shipping_notice.order_extraction_run_service import (
|
||||
get_order_extraction_run,
|
||||
serialize_order_extraction_run,
|
||||
)
|
||||
|
||||
return _ok(serialize_order_extraction_run(get_order_extraction_run(user_id=user.id, run_no=run_no)))
|
||||
run = get_order_extraction_run(user_id=user.id, run_no=run_no)
|
||||
payload = serialize_order_extraction_run(run)
|
||||
# 轮询接口 60s 节流:窗口内复用最近访问痕迹,仍可追溯访问者与范围。
|
||||
record_access_audit(
|
||||
action='view_order_extraction_run',
|
||||
aggregate_type='order_extraction_run',
|
||||
aggregate_id=str(run.run_no),
|
||||
actor_id=user.id,
|
||||
run_no=str(run.run_no),
|
||||
conversation_id=run.conversation_id,
|
||||
metadata={'status': str(run.status or ''), 'poll': True},
|
||||
)
|
||||
return _ok(payload)
|
||||
|
||||
|
||||
@workspace_shipping_notice_bp.route('/shipping-notice/order-extraction-runs/<run_no>/progress-events', methods=['GET'])
|
||||
def workspace_list_shipping_order_extraction_progress_events(run_no: str):
|
||||
"""返回当前用户展开状态卡时所需的脱敏业务阶段时间线。"""
|
||||
"""返回当前用户展开状态卡时所需的脱敏业务阶段时间线;访问留痕。"""
|
||||
user = _require_user()
|
||||
from app.services.shipping_notice.fulfillment_audit import record_access_audit
|
||||
from app.services.shipping_notice.order_extraction_run_service import list_user_order_extraction_progress_events
|
||||
|
||||
return _ok({'items': list_user_order_extraction_progress_events(user_id=user.id, run_no=run_no)})
|
||||
items = list_user_order_extraction_progress_events(user_id=user.id, run_no=run_no)
|
||||
record_access_audit(
|
||||
action='view_order_extraction_timeline',
|
||||
aggregate_type='order_extraction_run',
|
||||
aggregate_id=str(run_no),
|
||||
actor_id=user.id,
|
||||
run_no=str(run_no),
|
||||
metadata={'event_count': len(items or []), 'poll': True},
|
||||
)
|
||||
return _ok({'items': items})
|
||||
|
||||
|
||||
@workspace_shipping_notice_bp.route('/shipping-notice/order-extraction-runs/<run_no>/documents', methods=['GET'])
|
||||
def workspace_list_shipping_order_extraction_documents(run_no: str):
|
||||
"""返回当前用户一次订单抽取的按 PDF 归并详情。"""
|
||||
"""返回当前用户一次订单抽取的按 PDF 归并详情;访问留痕。"""
|
||||
user = _require_user()
|
||||
from app.services.shipping_notice.fulfillment_audit import record_access_audit
|
||||
from app.services.shipping_notice.order_extraction_run_service import list_user_order_extraction_documents
|
||||
|
||||
return _ok({'items': list_user_order_extraction_documents(user_id=user.id, run_no=run_no)})
|
||||
items = list_user_order_extraction_documents(user_id=user.id, run_no=run_no)
|
||||
record_access_audit(
|
||||
action='view_order_extraction_documents',
|
||||
aggregate_type='order_extraction_run',
|
||||
aggregate_id=str(run_no),
|
||||
actor_id=user.id,
|
||||
run_no=str(run_no),
|
||||
metadata={'document_count': len(items or []), 'poll': True},
|
||||
)
|
||||
return _ok({'items': items})
|
||||
|
||||
|
||||
@workspace_shipping_notice_bp.route('/shipping-notice/order-extraction-runs/<run_no>/review', methods=['GET'])
|
||||
def workspace_get_shipping_order_review_run(run_no: str):
|
||||
"""读取当前用户 Run 的复核 Case 汇总;不返回机器原文或内部执行快照。"""
|
||||
"""读取当前用户 Run 的复核 Case 汇总;不返回机器原文或内部执行快照;访问留痕。"""
|
||||
user = _require_user()
|
||||
is_admin = str(getattr(user, 'role', '') or '').lower() == 'admin'
|
||||
from app.services.shipping_notice.fulfillment_audit import record_access_audit
|
||||
from app.services.shipping_notice.order_review_projection import serialize_review_run
|
||||
from app.services.shipping_notice.order_review_service import get_review_run_visible_to_user
|
||||
|
||||
return _ok(serialize_review_run(get_review_run_visible_to_user(run_no, user.id, is_admin=is_admin)))
|
||||
payload = serialize_review_run(get_review_run_visible_to_user(run_no, user.id, is_admin=is_admin))
|
||||
record_access_audit(
|
||||
action='view_order_review_run',
|
||||
aggregate_type='order_extraction_run',
|
||||
aggregate_id=str(run_no),
|
||||
actor_id=user.id,
|
||||
run_no=str(run_no),
|
||||
)
|
||||
return _ok(payload)
|
||||
|
||||
|
||||
@workspace_shipping_notice_bp.route('/shipping-notice/order-review-cases/<case_no>', methods=['GET'])
|
||||
def workspace_get_shipping_order_review_case(case_no: str):
|
||||
"""读取当前用户的一份 PDF 复核详情;Case 编号不能跨 owner 越权访问。"""
|
||||
"""读取当前用户的一份 PDF 复核详情;Case 编号不能跨 owner 越权访问;访问留痕。"""
|
||||
user = _require_user()
|
||||
is_admin = str(getattr(user, 'role', '') or '').lower() == 'admin'
|
||||
from app.services.shipping_notice.fulfillment_audit import record_access_audit
|
||||
from app.services.shipping_notice.order_review_projection import serialize_review_case
|
||||
from app.services.shipping_notice.order_review_service import get_review_case_visible_to_user
|
||||
|
||||
return _ok(serialize_review_case(get_review_case_visible_to_user(case_no, user.id, is_admin=is_admin)))
|
||||
payload = serialize_review_case(get_review_case_visible_to_user(case_no, user.id, is_admin=is_admin))
|
||||
record_access_audit(
|
||||
action='view_order_review_case',
|
||||
aggregate_type='order_review_case',
|
||||
aggregate_id=str(case_no),
|
||||
actor_id=user.id,
|
||||
review_case_no=str(case_no),
|
||||
run_no=str(payload.get('run_no') or '') or None if isinstance(payload, dict) else None,
|
||||
)
|
||||
return _ok(payload)
|
||||
|
||||
|
||||
def _review_draft_payload() -> dict:
|
||||
@@ -1302,29 +1363,57 @@ def workspace_create_shipping_order_review_replacement_run(case_no: str):
|
||||
|
||||
@workspace_shipping_notice_bp.route('/shipping-notice/order-review-cases/<case_no>/evidence', methods=['GET'])
|
||||
def workspace_list_shipping_order_review_evidence(case_no: str):
|
||||
"""列出当前用户 PDF 的安全证据摘要;不泄露全文、对象存储位置或模型响应。"""
|
||||
"""列出当前用户 PDF 的安全证据摘要;不泄露全文、对象存储位置或模型响应;访问留痕。"""
|
||||
user = _require_user()
|
||||
from app.services.shipping_notice.fulfillment_audit import record_access_audit
|
||||
from app.services.shipping_notice.order_review_evidence_service import list_case_evidence
|
||||
|
||||
return _ok(list_case_evidence(user_id=user.id, case_no=case_no))
|
||||
payload = list_case_evidence(user_id=user.id, case_no=case_no)
|
||||
record_access_audit(
|
||||
action='view_order_review_evidence_list',
|
||||
aggregate_type='order_review_case',
|
||||
aggregate_id=str(case_no),
|
||||
actor_id=user.id,
|
||||
review_case_no=str(case_no),
|
||||
)
|
||||
return _ok(payload)
|
||||
|
||||
|
||||
@workspace_shipping_notice_bp.route('/shipping-notice/order-review-cases/<case_no>/evidence/<evidence_id>', methods=['GET'])
|
||||
def workspace_get_shipping_order_review_evidence(case_no: str, evidence_id: str):
|
||||
"""读取当前用户的一条字段证据,用于问题导航;evidence_id 不可跨 Case 使用。"""
|
||||
"""读取当前用户的一条字段证据,用于问题导航;evidence_id 不可跨 Case 使用;访问留痕。"""
|
||||
user = _require_user()
|
||||
from app.services.shipping_notice.fulfillment_audit import record_access_audit
|
||||
from app.services.shipping_notice.order_review_evidence_service import get_case_evidence
|
||||
|
||||
return _ok(get_case_evidence(user_id=user.id, case_no=case_no, evidence_id=evidence_id))
|
||||
payload = get_case_evidence(user_id=user.id, case_no=case_no, evidence_id=evidence_id)
|
||||
record_access_audit(
|
||||
action='view_order_review_evidence',
|
||||
aggregate_type='order_review_case',
|
||||
aggregate_id=str(case_no),
|
||||
actor_id=user.id,
|
||||
review_case_no=str(case_no),
|
||||
metadata={'evidence_id': str(evidence_id)[:64]},
|
||||
)
|
||||
return _ok(payload)
|
||||
|
||||
|
||||
@workspace_shipping_notice_bp.route('/shipping-notice/order-review-cases/<case_no>/document-preview', methods=['GET'])
|
||||
def workspace_preview_shipping_order_review_document(case_no: str):
|
||||
"""应用代理当前用户的 PDF 预览流;禁止向浏览器下发 MinIO key 或直连地址。"""
|
||||
"""应用代理当前用户的 PDF 预览流;禁止向浏览器下发 MinIO key 或直连地址;访问留痕。"""
|
||||
user = _require_user()
|
||||
from app.services.shipping_notice.fulfillment_audit import record_access_audit
|
||||
from app.services.shipping_notice.order_review_evidence_service import get_case_pdf_bytes
|
||||
|
||||
content, filename = get_case_pdf_bytes(user_id=user.id, case_no=case_no)
|
||||
record_access_audit(
|
||||
action='preview_order_review_document',
|
||||
aggregate_type='order_review_case',
|
||||
aggregate_id=str(case_no),
|
||||
actor_id=user.id,
|
||||
review_case_no=str(case_no),
|
||||
metadata={'preview': 'pdf'},
|
||||
)
|
||||
return send_file(
|
||||
BytesIO(content), mimetype='application/pdf', as_attachment=False, download_name=filename,
|
||||
conditional=True,
|
||||
@@ -1333,11 +1422,34 @@ def workspace_preview_shipping_order_review_document(case_no: str):
|
||||
|
||||
@workspace_shipping_notice_bp.route('/shipping-notice/order-extraction-runs/<run_no>/seen', methods=['POST'])
|
||||
def workspace_mark_shipping_order_extraction_run_seen(run_no: str):
|
||||
"""确认当前用户已加载终态订单识别卡片;仅用于会话待查看提醒,不改变业务结果。"""
|
||||
"""确认当前用户已加载终态订单识别卡片;写入已读状态变更审计。"""
|
||||
user = _require_user()
|
||||
from app.services.shipping_notice.order_extraction_run_service import mark_order_extraction_run_seen
|
||||
from app.services.shipping_notice.fulfillment_audit import record_fulfillment_audit
|
||||
from app.services.shipping_notice.order_extraction_run_service import (
|
||||
get_order_extraction_run,
|
||||
mark_order_extraction_run_seen,
|
||||
)
|
||||
|
||||
run = get_order_extraction_run(user_id=user.id, run_no=run_no)
|
||||
before = {'status': 'seen' if run.seen_at is not None else 'unseen'}
|
||||
seen = mark_order_extraction_run_seen(user_id=user.id, run_no=run_no)
|
||||
after_status = 'seen' if (seen or run.seen_at is not None) else before['status']
|
||||
record_fulfillment_audit(
|
||||
event_type='order_extraction_run_seen',
|
||||
aggregate_type='order_extraction_run',
|
||||
aggregate_id=str(run.run_no),
|
||||
action='mark_run_seen',
|
||||
actor_type='user',
|
||||
actor_id=user.id,
|
||||
run_no=str(run.run_no),
|
||||
conversation_id=run.conversation_id,
|
||||
result='success' if seen else ('ignored' if before['status'] == after_status else 'success'),
|
||||
before=before,
|
||||
after={'status': after_status},
|
||||
metadata={'first_seen': bool(seen)},
|
||||
source='api',
|
||||
strict=True,
|
||||
)
|
||||
db.session.commit()
|
||||
return _ok({'seen': seen})
|
||||
|
||||
@@ -1360,6 +1472,86 @@ def workspace_retry_shipping_order_extraction_run(run_no: str):
|
||||
)
|
||||
|
||||
|
||||
@workspace_shipping_notice_bp.route('/shipping-notice/order-extraction-runs/<run_no>/cancel', methods=['POST'])
|
||||
def workspace_cancel_shipping_order_extraction_run(run_no: str):
|
||||
"""
|
||||
请求取消整批订单抽取。
|
||||
|
||||
核心逻辑:排队项立即取消,执行中项进入正在取消;已完成结果保留。管理员代取消必须写原因。
|
||||
"""
|
||||
user = _require_user()
|
||||
body = request.get_json(silent=True) or {}
|
||||
if body and not isinstance(body, dict):
|
||||
raise ValidationError('Request body must be an object')
|
||||
from app.services.shipping_notice.order_extraction_cancel_service import cancel_order_extraction_run
|
||||
from app.services.shipping_notice.order_extraction_run_service import serialize_order_extraction_run
|
||||
|
||||
run = cancel_order_extraction_run(
|
||||
actor=user,
|
||||
run_no=run_no,
|
||||
reason=str(body.get('reason') or '') or None,
|
||||
reason_code=str(body.get('reason_code') or '') or None,
|
||||
operation_id=str(body.get('operation_id') or getattr(g, 'request_id', '') or '') or None,
|
||||
)
|
||||
db.session.commit()
|
||||
return ok({'run': serialize_order_extraction_run(run)}, request_id=getattr(g, 'request_id', None), status=202)
|
||||
|
||||
|
||||
@workspace_shipping_notice_bp.route(
|
||||
'/shipping-notice/order-extraction-runs/<run_no>/documents/<int:document_id>/cancel',
|
||||
methods=['POST'],
|
||||
)
|
||||
def workspace_cancel_shipping_order_extraction_document(run_no: str, document_id: int):
|
||||
"""请求取消单个 PDF Unit;权限与原因规则同整批取消。"""
|
||||
user = _require_user()
|
||||
body = request.get_json(silent=True) or {}
|
||||
if body and not isinstance(body, dict):
|
||||
raise ValidationError('Request body must be an object')
|
||||
from app.services.shipping_notice.order_extraction_cancel_service import cancel_order_extraction_unit
|
||||
from app.services.shipping_notice.order_extraction_run_service import serialize_order_extraction_run
|
||||
from app.services.shipping_notice.order_extraction_workspace_projection import serialize_workspace_run_documents
|
||||
|
||||
unit = cancel_order_extraction_unit(
|
||||
actor=user,
|
||||
run_no=run_no,
|
||||
document_id=int(document_id),
|
||||
reason=str(body.get('reason') or '') or None,
|
||||
reason_code=str(body.get('reason_code') or '') or None,
|
||||
operation_id=str(body.get('operation_id') or getattr(g, 'request_id', '') or '') or None,
|
||||
)
|
||||
run = unit.plan.run if unit.plan is not None else None
|
||||
db.session.commit()
|
||||
documents = serialize_workspace_run_documents(run) if run is not None else []
|
||||
document = next((item for item in documents if int(item.get('document_id') or 0) == int(document_id)), None)
|
||||
return ok(
|
||||
{
|
||||
'run': serialize_order_extraction_run(run) if run is not None else None,
|
||||
'document': document,
|
||||
},
|
||||
request_id=getattr(g, 'request_id', None),
|
||||
status=202,
|
||||
)
|
||||
|
||||
|
||||
@workspace_shipping_notice_bp.route('/shipping-notice/order-extraction-runs/<run_no>/timeline', methods=['GET'])
|
||||
def workspace_shipping_order_extraction_timeline(run_no: str):
|
||||
"""返回用户可见的 Run 时间线,含取消请求与重试相关进度事件;访问留痕。"""
|
||||
user = _require_user()
|
||||
from app.services.shipping_notice.fulfillment_audit import record_access_audit
|
||||
from app.services.shipping_notice.order_extraction_run_service import list_user_order_extraction_progress_events
|
||||
|
||||
items = list_user_order_extraction_progress_events(user_id=user.id, run_no=run_no)
|
||||
record_access_audit(
|
||||
action='view_order_extraction_timeline',
|
||||
aggregate_type='order_extraction_run',
|
||||
aggregate_id=str(run_no),
|
||||
actor_id=user.id,
|
||||
run_no=str(run_no),
|
||||
metadata={'event_count': len(items or []), 'surface': 'timeline', 'poll': True},
|
||||
)
|
||||
return _ok({'items': items})
|
||||
|
||||
|
||||
@workspace_shipping_notice_bp.route('/shipping-notice/order-extraction-runs/<run_no>/reparse', methods=['POST'])
|
||||
def workspace_reparse_shipping_order_extraction_run(run_no: str):
|
||||
"""
|
||||
@@ -1392,19 +1584,53 @@ def workspace_reparse_shipping_order_extraction_run(run_no: str):
|
||||
|
||||
@workspace_shipping_notice_bp.route('/shipping-notice/order-extraction-runs', methods=['GET'])
|
||||
def workspace_list_shipping_order_extraction_runs():
|
||||
"""列出当前用户订单抽取 Run,可按 HXOPS 会话过滤。"""
|
||||
"""
|
||||
列出当前用户订单抽取 Run。
|
||||
|
||||
核心逻辑:可按会话过滤;传 page 时返回分页供任务中心续办,否则保持会话内短列表契约。
|
||||
"""
|
||||
user = _require_user()
|
||||
conversation_id = str(request.args.get('conversation_id') or '').strip() or None
|
||||
try:
|
||||
limit = int(request.args.get('limit') or 50)
|
||||
except (TypeError, ValueError) as exc:
|
||||
raise ValidationError('limit must be an integer') from exc
|
||||
status = str(request.args.get('status') or '').strip() or None
|
||||
page_raw = request.args.get('page')
|
||||
page_size_raw = request.args.get('page_size')
|
||||
from app.services.shipping_notice.order_extraction_run_service import (
|
||||
list_order_extraction_runs,
|
||||
serialize_order_extraction_run,
|
||||
)
|
||||
|
||||
rows = list_order_extraction_runs(user_id=user.id, conversation_id=conversation_id, limit=limit)
|
||||
if page_raw is not None or page_size_raw is not None:
|
||||
try:
|
||||
page = int(page_raw or 1)
|
||||
page_size = int(page_size_raw or 20)
|
||||
except (TypeError, ValueError) as exc:
|
||||
raise ValidationError('page and page_size must be integers') from exc
|
||||
payload = list_order_extraction_runs(
|
||||
user_id=user.id,
|
||||
conversation_id=conversation_id,
|
||||
status=status,
|
||||
page=page,
|
||||
page_size=page_size,
|
||||
)
|
||||
assert isinstance(payload, dict)
|
||||
return _ok({
|
||||
'items': [serialize_order_extraction_run(row) for row in payload['items']],
|
||||
'total': payload['total'],
|
||||
'page': payload['page'],
|
||||
'page_size': payload['page_size'],
|
||||
})
|
||||
|
||||
try:
|
||||
limit = int(request.args.get('limit') or 50)
|
||||
except (TypeError, ValueError) as exc:
|
||||
raise ValidationError('limit must be an integer') from exc
|
||||
rows = list_order_extraction_runs(
|
||||
user_id=user.id,
|
||||
conversation_id=conversation_id,
|
||||
status=status,
|
||||
limit=limit,
|
||||
)
|
||||
assert isinstance(rows, list)
|
||||
return _ok({'items': [serialize_order_extraction_run(row) for row in rows]})
|
||||
|
||||
|
||||
@@ -1639,3 +1865,101 @@ def workspace_retry_shipping_batch_pending(batch_no: str):
|
||||
raise NotFoundError('Not found')
|
||||
from app.services.shipping_notice.batch_orchestrator import retry_batch_pending_tasks
|
||||
return jsonify(retry_batch_pending_tasks(batch.batch_no))
|
||||
|
||||
|
||||
@workspace_shipping_notice_bp.route('/shipping-notice/session-work-items', methods=['GET'])
|
||||
def workspace_list_session_work_items():
|
||||
"""
|
||||
会话 PDF 工作台读模型:未关闭/已关闭分组与统计。
|
||||
|
||||
核心逻辑:仅按 conversation_id 聚合工作项,禁止用最新 Run 充当本次处理范围;
|
||||
敏感读取写入访问审计(查询者、会话、结果数量、请求关联)。
|
||||
"""
|
||||
user = _require_user()
|
||||
conversation_id = str(request.args.get('conversation_id') or '').strip()
|
||||
if not conversation_id:
|
||||
raise ValidationError('conversation_id is required', code='SHIPPING_NOTICE.SESSION_WORK_ITEM_CONVERSATION_REQUIRED')
|
||||
open_only = str(request.args.get('open_only') or '').strip().lower() in {'1', 'true', 'yes'}
|
||||
from app.services.shipping_notice.fulfillment_audit import record_access_audit
|
||||
from app.services.shipping_notice.session_pdf_work_item_projection import project_session_workbench
|
||||
payload = project_session_workbench(
|
||||
user_id=int(user.id),
|
||||
conversation_id=conversation_id,
|
||||
open_only=open_only,
|
||||
include_closed=not open_only,
|
||||
)
|
||||
record_access_audit(
|
||||
action='list_session_work_items',
|
||||
aggregate_type='shipping_conversation',
|
||||
aggregate_id=conversation_id,
|
||||
actor_id=user.id,
|
||||
owner_user_id=user.id,
|
||||
conversation_id=conversation_id,
|
||||
metadata={
|
||||
'open_count': int(payload.get('open_count') or 0),
|
||||
'closed_count': int(payload.get('closed_count') or 0),
|
||||
'open_only': open_only,
|
||||
},
|
||||
)
|
||||
return _ok(payload)
|
||||
|
||||
|
||||
@workspace_shipping_notice_bp.route('/shipping-notice/session-work-items/<item_no>/versions', methods=['GET'])
|
||||
def workspace_list_session_work_item_versions(item_no: str):
|
||||
"""只读版本历史;旧版不可编辑或确认;访问写入审计。"""
|
||||
user = _require_user()
|
||||
from app.services.shipping_notice.fulfillment_audit import record_access_audit
|
||||
from app.services.shipping_notice.session_pdf_work_item_projection import list_session_work_item_versions
|
||||
from app.services.shipping_notice.session_pdf_work_item_service import get_work_item_for_user
|
||||
item = get_work_item_for_user(user_id=int(user.id), item_no=item_no)
|
||||
versions = list_session_work_item_versions(item=item)
|
||||
record_access_audit(
|
||||
action='list_session_work_item_versions',
|
||||
aggregate_type='session_pdf_work_item',
|
||||
aggregate_id=str(item.item_no),
|
||||
actor_id=user.id,
|
||||
owner_user_id=item.owner_user_id,
|
||||
conversation_id=item.conversation_id,
|
||||
session_item_id=item.item_no,
|
||||
document_id=item.current_document_id,
|
||||
review_case_no=item.current_case_no,
|
||||
metadata={'version_count': len(versions)},
|
||||
)
|
||||
return _ok({
|
||||
'item_no': item.item_no,
|
||||
'current_case_no': item.current_case_no,
|
||||
'current_version_no': int(item.current_version_no or 1),
|
||||
'versions': versions,
|
||||
})
|
||||
|
||||
|
||||
@workspace_shipping_notice_bp.route('/shipping-notice/session-work-items/<item_no>/close', methods=['POST'])
|
||||
def workspace_close_session_work_item(item_no: str):
|
||||
"""用户关闭工作项(取消确认);须填写原因。"""
|
||||
user = _require_user()
|
||||
body = request.get_json(silent=True) or {}
|
||||
if not isinstance(body, dict):
|
||||
raise ValidationError('JSON body must be an object')
|
||||
reason = str(body.get('reason') or '').strip()
|
||||
if not reason:
|
||||
raise ValidationError('reason is required', code='SHIPPING_NOTICE.SESSION_WORK_ITEM_CLOSE_REASON_REQUIRED')
|
||||
expected_lock = body.get('expected_lock_version')
|
||||
from app.services.shipping_notice.session_pdf_work_item_projection import serialize_session_work_item
|
||||
from app.services.shipping_notice.session_pdf_work_item_service import (
|
||||
close_work_item,
|
||||
get_work_item_for_user,
|
||||
)
|
||||
item = get_work_item_for_user(user_id=int(user.id), item_no=item_no, for_update=True)
|
||||
close_work_item(
|
||||
item=item,
|
||||
closed_reason='user_cancelled',
|
||||
actor_type='user',
|
||||
actor_id=int(user.id),
|
||||
reason=reason,
|
||||
expected_lock_version=int(expected_lock) if expected_lock is not None else None,
|
||||
request_id=getattr(g, 'request_id', None),
|
||||
operation_id=getattr(g, 'request_id', None),
|
||||
event_type='session_work_item_cancelled',
|
||||
)
|
||||
db.session.commit()
|
||||
return _ok({'item': serialize_session_work_item(item)})
|
||||
Reference in new issue
Block a user