feat(shipping-notice): 收敛复核状态隔离、STP 重试幂等与 XFA 合成预览标注
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
84a881b554
commit
74270adc22
149 files changed
+20111
-3871
No files matched your search
@@ -15,7 +15,7 @@ import uuid
|
||||
from io import BytesIO
|
||||
from typing import Any
|
||||
|
||||
from flask import Blueprint, g, request, send_file
|
||||
from flask import Blueprint, current_app, g, request, send_file
|
||||
|
||||
from app import db
|
||||
from app.core.auth.jwt import get_current_user
|
||||
@@ -28,6 +28,7 @@ from app.services.shipping_notice.constants import (
|
||||
CP_EXPORT_GENERATED,
|
||||
CP_NOTICE_TEXT_EXTRACTION_FAILED,
|
||||
)
|
||||
from app.services.shipping_notice.processing_ownership import assert_notice_task_ownership
|
||||
from app.services.shipping_notice.query_service import (
|
||||
EXPORT_MIME_TYPE,
|
||||
count_my_todos,
|
||||
@@ -89,6 +90,35 @@ def _ok(payload: Any, *, status: int = 200):
|
||||
return ok(payload, request_id=getattr(g, 'request_id', None), status=status)
|
||||
|
||||
|
||||
def _assert_fulfillment_task_ownership(task: ShippingNotice, user_id: int) -> None:
|
||||
"""
|
||||
履约写接口:若请求携带期望 OT/Case/Run,校验与正式 Notice 归属一致。
|
||||
|
||||
核心逻辑:委托 assert_notice_task_ownership;未携带期望字段时放行(兼容旧客户端)。
|
||||
|
||||
Args:
|
||||
task: 已鉴权的 ShippingNotice。
|
||||
user_id: 当前用户 id。
|
||||
|
||||
Raises:
|
||||
ConflictError: 归属不匹配。
|
||||
"""
|
||||
data = request.get_json(silent=True) or {}
|
||||
assert_notice_task_ownership(
|
||||
task,
|
||||
expected_order_task_no=(
|
||||
str(data.get('expected_order_task_no') or data.get('order_task_no') or '').strip() or None
|
||||
),
|
||||
expected_review_case_no=(
|
||||
str(data.get('expected_review_case_no') or data.get('case_no') or '').strip() or None
|
||||
),
|
||||
expected_run_no=(
|
||||
str(data.get('expected_run_no') or data.get('run_no') or '').strip() or None
|
||||
),
|
||||
actor_id=user_id,
|
||||
)
|
||||
|
||||
|
||||
@workspace_shipping_notice_bp.route('/shipping-tasks', methods=['GET'])
|
||||
def workspace_shipping_tasks():
|
||||
"""分页列出当前用户可见的发货任务,可按批次与处理状态过滤。"""
|
||||
@@ -950,6 +980,7 @@ def workspace_match_shipping_inventory(task_no: str):
|
||||
task = get_task_for_user(task_no, user.id)
|
||||
if not task:
|
||||
raise NotFoundError('Not found')
|
||||
_assert_fulfillment_task_ownership(task, user.id)
|
||||
from app.services.shipping_notice import tools as shipping_tools
|
||||
from app.services.shipping_notice.state_machine import action_buttons_for_checkpoint, human_options_for_checkpoint
|
||||
matched = shipping_tools.match_inventory({
|
||||
@@ -993,6 +1024,7 @@ def workspace_generate_shipping_excel(task_no: str):
|
||||
task = get_task_for_user(task_no, user.id)
|
||||
if not task:
|
||||
raise NotFoundError('Not found')
|
||||
_assert_fulfillment_task_ownership(task, user.id)
|
||||
from app.services.shipping_notice import tools as shipping_tools
|
||||
result = shipping_tools.generate_excel({'task_id': task.task_no})
|
||||
if isinstance(result, dict) and result.get('status') == 'ok':
|
||||
@@ -1015,6 +1047,7 @@ def workspace_mark_manual_uploaded(task_no: str):
|
||||
task = get_task_for_user(task_no, user.id)
|
||||
if not task:
|
||||
raise NotFoundError('Not found')
|
||||
_assert_fulfillment_task_ownership(task, user.id)
|
||||
from app.services.shipping_notice import tools as shipping_tools
|
||||
data = request.get_json(silent=True) or {}
|
||||
payload = {
|
||||
@@ -1033,8 +1066,16 @@ def workspace_mark_manual_uploaded(task_no: str):
|
||||
|
||||
@workspace_shipping_notice_bp.route('/shipping-tasks/<task_no>/retry-upload', methods=['POST'])
|
||||
def workspace_retry_shipping_upload(task_no: str):
|
||||
"""首期禁用货代 RPA 重试上传;引导用户改走人工凭据登记。"""
|
||||
_require_user()
|
||||
"""
|
||||
货代上传重试入口;首期若全局禁用 RPA 则返回明确错误码。
|
||||
|
||||
核心逻辑:先做归属校验;若平台禁用 RPA 再抛 ValidationError,避免跳过归属门禁。
|
||||
"""
|
||||
user = _require_user()
|
||||
task = get_task_for_user(task_no, user.id)
|
||||
if not task:
|
||||
raise NotFoundError('Not found')
|
||||
_assert_fulfillment_task_ownership(task, user.id)
|
||||
raise ValidationError(
|
||||
'首期不支持货代 RPA 上传重试。请下载 Excel,在货代系统人工上传后提交截图/PDF 凭据。',
|
||||
code='SHIPPING.FREIGHT_RPA_UPLOAD_DISABLED',
|
||||
@@ -1378,7 +1419,11 @@ def workspace_get_shipping_order_review_case(case_no: str):
|
||||
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
|
||||
|
||||
payload = serialize_review_case(get_review_case_visible_to_user(case_no, user.id, is_admin=is_admin))
|
||||
# 只读:禁止在 GET 中入队 STP(入队仅抽取收尾 / resume / 显式 retry POST)。
|
||||
payload = serialize_review_case(
|
||||
get_review_case_visible_to_user(case_no, user.id, is_admin=is_admin),
|
||||
is_admin=is_admin,
|
||||
)
|
||||
record_access_audit(
|
||||
action='view_order_review_case',
|
||||
aggregate_type='order_review_case',
|
||||
@@ -1390,6 +1435,26 @@ def workspace_get_shipping_order_review_case(case_no: str):
|
||||
return _ok(payload)
|
||||
|
||||
|
||||
@workspace_shipping_notice_bp.route(
|
||||
'/shipping-notice/order-review-cases/<case_no>/stp-auto-create/retry',
|
||||
methods=['POST'],
|
||||
)
|
||||
def workspace_retry_shipping_order_stp_auto_create(case_no: str):
|
||||
"""
|
||||
显式重试 STP 自动建单入队(failed / manual_fallback)。
|
||||
|
||||
核心逻辑:委托 retry_stp_auto_create_for_case;成功返回 queued/reused+job_id;
|
||||
失败抛结构化业务错误,禁止伪装成功。
|
||||
"""
|
||||
user = _require_user()
|
||||
from app.services.shipping_notice.order_stp_auto_create_service import (
|
||||
retry_stp_auto_create_for_case,
|
||||
)
|
||||
|
||||
result = retry_stp_auto_create_for_case(user_id=int(user.id), case_no=str(case_no))
|
||||
return _ok(result)
|
||||
|
||||
|
||||
@workspace_shipping_notice_bp.route(
|
||||
'/shipping-notice/order-review-cases/<case_no>/access/version-history',
|
||||
methods=['POST'],
|
||||
|
||||
Reference in new issue
Block a user