Merge branch 'dev' into runny827
feat(training): 新增精益培训视频与周任务管理 # Conflicts: # backend/app/models/__init__.py
This commit is contained in:
1 parent
85d27e9ffa
commit
91b7233872
812 files changed
+73763
-18908
No files matched your search
@@ -22,12 +22,12 @@ from app import db
|
||||
from app.core.auth.jwt import get_current_user
|
||||
from app.core.errors import AppError, NotFoundError, UnauthorizedError, ValidationError
|
||||
from app.core.response import ok
|
||||
from app.models import ShippingOrderIntake, ShippingOrderExtraction, ShippingNotice
|
||||
from app.models import ShippingOrderIntake, ShippingOrderExtraction, ShippingNotice, ShippingOrderTask
|
||||
from app.services.shipping_notice.chat_actions import build_chat_actions_payload
|
||||
from app.services.shipping_notice.constants import (
|
||||
AUTO_CHAIN_FALLBACK,
|
||||
CP_EXPORT_GENERATED,
|
||||
CP_NOTICE_TEXT_EXTRACTION_FAILED,
|
||||
POSITION_EXPORT_GENERATED,
|
||||
POSITION_NOTICE_TEXT_EXTRACTION_FAILED,
|
||||
)
|
||||
from app.services.shipping_notice.processing_ownership import assert_notice_task_ownership
|
||||
from app.services.shipping_notice.query_service import (
|
||||
@@ -53,7 +53,6 @@ from app.services.shipping_notice.customer_identity_gate import (
|
||||
confirm_task_customer,
|
||||
list_customer_options,
|
||||
)
|
||||
from app.services.shipping_notice.order_customer_matching import confirm_order_customer_match
|
||||
|
||||
workspace_shipping_notice_bp = Blueprint("workspace_shipping_notice", __name__)
|
||||
|
||||
@@ -145,6 +144,16 @@ def _assert_fulfillment_task_ownership(task: ShippingNotice, user_id: int) -> No
|
||||
)
|
||||
|
||||
|
||||
def _require_formal_notice(task: Any) -> ShippingNotice:
|
||||
"""正式 Notice 专属接口的实体守卫;OT 在库存门禁前不得进入通知/上传写路径。"""
|
||||
if not isinstance(task, ShippingNotice):
|
||||
raise ValidationError(
|
||||
'Formal shipping notice is required for this operation',
|
||||
code='SHIPPING.FORMAL_NOTICE_REQUIRED',
|
||||
)
|
||||
return task
|
||||
|
||||
|
||||
@workspace_shipping_notice_bp.route('/shipping-tasks', methods=['GET'])
|
||||
def workspace_shipping_tasks():
|
||||
"""分页列出当前用户可见的发货任务,可按处理状态过滤。"""
|
||||
@@ -214,7 +223,7 @@ def _batch_task_nos(data: dict) -> list[str]:
|
||||
return normalized
|
||||
|
||||
|
||||
def _can_dispose_task(user, task: ShippingNotice) -> bool:
|
||||
def _can_dispose_task(user, task) -> bool:
|
||||
"""管理员可跨用户处置;普通用户仅可处置自己名下或未归属任务。"""
|
||||
return str(getattr(user, 'role', '')).lower() == 'admin' or task.user_id in {None, user.id}
|
||||
|
||||
@@ -372,96 +381,6 @@ def workspace_confirm_shipping_customer(task_no: str):
|
||||
return _ok(serialize_task_detail(updated))
|
||||
|
||||
|
||||
@workspace_shipping_notice_bp.route(
|
||||
'/shipping-order-extractions/<int:extraction_id>/customer-matches/<role>/confirm',
|
||||
methods=['POST'],
|
||||
)
|
||||
def workspace_confirm_order_customer_match(extraction_id: int, role: str):
|
||||
"""确认当前用户订单解析中的 Bill-to 客户或 Ship-to 送货站点。"""
|
||||
user = _require_user()
|
||||
extraction = (
|
||||
db.session.query(ShippingOrderExtraction)
|
||||
.join(ShippingOrderIntake, ShippingOrderIntake.id == ShippingOrderExtraction.intake_id)
|
||||
.filter(
|
||||
ShippingOrderExtraction.id == extraction_id,
|
||||
ShippingOrderIntake.user_id == user.id,
|
||||
)
|
||||
.one_or_none()
|
||||
)
|
||||
if extraction is None:
|
||||
raise NotFoundError(
|
||||
'Order extraction not found',
|
||||
code='SHIPPING.ORDER_EXTRACTION_NOT_FOUND',
|
||||
)
|
||||
data = request.get_json(silent=True) or {}
|
||||
try:
|
||||
customer_id = int(data.get('customer_id'))
|
||||
site_id = int(data['site_id']) if data.get('site_id') is not None else None
|
||||
except (TypeError, ValueError) as exc:
|
||||
raise ValidationError(
|
||||
'Customer id is required',
|
||||
code='SHIPPING.ORDER_CUSTOMER_REQUIRED',
|
||||
details={'field': 'customer_id'},
|
||||
) from exc
|
||||
result = confirm_order_customer_match(
|
||||
extraction.id,
|
||||
role=role,
|
||||
customer_id=customer_id,
|
||||
site_id=site_id,
|
||||
actor_id=user.id,
|
||||
reason=str(data.get('reason') or ''),
|
||||
commit=False,
|
||||
)
|
||||
# [STEP P1-7] 抽取侧客户确认后,同事务内触发 Case 级协调器(level-triggered reconcile 补偿)。
|
||||
# 通过 Extraction → Candidate → Review Case 反查未终态 Case;若抽取阶段太早尚无 Case,不报错跳过。
|
||||
if role == 'bill_to':
|
||||
from app.models import (
|
||||
ShippingOrderCandidate,
|
||||
ShippingOrderReviewCase,
|
||||
ShippingOrderReviewStream,
|
||||
)
|
||||
from app.services.shipping_notice.order_review_auto_progress_coordinator import (
|
||||
reconcile_single_case_for_auto_progress,
|
||||
)
|
||||
_TERMINAL = frozenset({
|
||||
'confirmed', 'confirming', 'non_order', 'superseded', 'quality_issue', 'reparse_pending',
|
||||
})
|
||||
candidates = list(
|
||||
ShippingOrderCandidate.query
|
||||
.filter_by(order_extraction_id=int(extraction.id))
|
||||
.all()
|
||||
)
|
||||
candidate_ids = {int(c.id) for c in candidates}
|
||||
case = None
|
||||
if candidate_ids:
|
||||
case = (
|
||||
ShippingOrderReviewCase.query
|
||||
.join(
|
||||
ShippingOrderReviewStream,
|
||||
ShippingOrderReviewStream.current_case_id == ShippingOrderReviewCase.id,
|
||||
)
|
||||
.filter(ShippingOrderReviewCase.candidate_id.in_(candidate_ids))
|
||||
.first()
|
||||
)
|
||||
if case is None and extraction.run_id:
|
||||
case = (
|
||||
ShippingOrderReviewCase.query
|
||||
.join(
|
||||
ShippingOrderReviewStream,
|
||||
ShippingOrderReviewStream.current_case_id == ShippingOrderReviewCase.id,
|
||||
)
|
||||
.filter(ShippingOrderReviewCase.run_id == int(extraction.run_id))
|
||||
.first()
|
||||
)
|
||||
if case is not None and str(case.status or '') not in _TERMINAL and not case.confirmed_task_id:
|
||||
reconcile_single_case_for_auto_progress(
|
||||
case=case,
|
||||
trigger='extraction_customer_confirmed',
|
||||
refresh_validation=True,
|
||||
)
|
||||
db.session.commit()
|
||||
return _ok(result)
|
||||
|
||||
@workspace_shipping_notice_bp.route('/shipping-tasks/create-from-notice', methods=['POST'])
|
||||
def workspace_create_shipping_task_from_notice():
|
||||
"""接收单个发货通知附件,建单后抽取文本并保存 raw_text,再交给后台编排器。"""
|
||||
@@ -491,12 +410,15 @@ def workspace_create_shipping_task_from_notice():
|
||||
task_no=task_id,
|
||||
)
|
||||
if not intake.accepted:
|
||||
return _ok({'status': 'needs_human', 'task_id': task_id, 'message': '未能从附件抽取到可解析文本(可能是扫描件/OCR 不可用)。请复制粘贴文本,或更换清晰版文件后重试。', 'data': {'notice_upload': intake.to_notice_upload_meta()}, 'checkpoint': CP_NOTICE_TEXT_EXTRACTION_FAILED})
|
||||
task = ShippingNotice.query.filter_by(task_no=task_id).first()
|
||||
return _ok({'status': 'needs_human', 'task_id': task_id, 'message': '未能从附件抽取到可解析文本(可能是扫描件/OCR 不可用)。请复制粘贴文本,或更换清晰版文件后重试。', 'data': {'notice_upload': intake.to_notice_upload_meta()}, 'position': POSITION_NOTICE_TEXT_EXTRACTION_FAILED})
|
||||
from app.models import ShippingOrderTask
|
||||
from app.models import ShippingOrderIntake
|
||||
task = ShippingOrderTask.query.filter_by(task_no=task_id).first()
|
||||
if task:
|
||||
task.raw_content = intake.text
|
||||
task.source_file_name = intake.filename or task.source_file_name
|
||||
task.source_file_type = intake.source_file_type or task.source_file_type
|
||||
intake_row = db.session.get(ShippingOrderIntake, task.intake_id) if task.intake_id else None
|
||||
if intake_row is not None:
|
||||
intake_row.extracted_text = intake.text
|
||||
intake_row.parse_warnings_json = list(intake.warnings or [])
|
||||
db.session.commit()
|
||||
from app.services.shipping_notice.batch_orchestrator import start_task_orchestrator
|
||||
orchestrator_started = start_task_orchestrator(task_id)
|
||||
@@ -540,7 +462,7 @@ def workspace_shipping_task_detail(task_no: str):
|
||||
返回指定任务的详情快照与内嵌 UI State。
|
||||
|
||||
核心逻辑:详情接口直接内嵌 `ui_state`,让页面首屏读取任务详情时即可拿到
|
||||
checkpoint / actions / steps,减少前端二次推导与竞态刷新。
|
||||
position / user_mode / actions / steps,减少前端二次推导与竞态刷新。
|
||||
"""
|
||||
user = _require_user()
|
||||
is_admin = str(getattr(user, 'role', '') or '').lower() == 'admin'
|
||||
@@ -548,8 +470,8 @@ def workspace_shipping_task_detail(task_no: str):
|
||||
task = get_task_visible_to_user(task_no, user.id, is_admin=is_admin)
|
||||
if not task:
|
||||
raise NotFoundError('Not found')
|
||||
# [PERF] view=workbench 供订单生命周期工作台首屏裁剪:剔除复核编辑器重字段,
|
||||
# 响应体与序列化耗时显著下降;缺省/非法值一律回退 full,保持兼容。
|
||||
# [PERF] view=workbench:跳过 DETAIL 重投影,仅身份壳 + ui_state enrich;
|
||||
# 缺省/非法值一律回退 full,保持兼容。
|
||||
view = str(request.args.get('view', 'full') or 'full').strip().lower()
|
||||
if view not in ('full', 'workbench'):
|
||||
view = 'full'
|
||||
@@ -637,6 +559,7 @@ def workspace_update_shipping_notice_fields(task_no: str):
|
||||
task = get_task_for_user(task_no, user.id)
|
||||
if not task:
|
||||
raise NotFoundError('Not found')
|
||||
task = _require_formal_notice(task)
|
||||
data = request.get_json(silent=True) or {}
|
||||
fields = data.get('fields')
|
||||
if not isinstance(fields, dict) or not fields:
|
||||
@@ -683,6 +606,7 @@ def workspace_update_shipping_notice_line(task_no: str):
|
||||
task = get_task_for_user(task_no, user.id)
|
||||
if not task:
|
||||
raise NotFoundError('Not found')
|
||||
task = _require_formal_notice(task)
|
||||
data = request.get_json(silent=True) or {}
|
||||
try:
|
||||
line_index = int(data.get('line_index'))
|
||||
@@ -771,6 +695,7 @@ def workspace_add_shipping_notice_line(task_no: str):
|
||||
task = get_task_for_user(task_no, user.id)
|
||||
if not task:
|
||||
raise NotFoundError('Not found')
|
||||
task = _require_formal_notice(task)
|
||||
data = request.get_json(silent=True) or {}
|
||||
line = data.get('line')
|
||||
if not isinstance(line, dict) or not line:
|
||||
@@ -796,6 +721,7 @@ def workspace_remove_shipping_notice_line(task_no: str):
|
||||
task = get_task_for_user(task_no, user.id)
|
||||
if not task:
|
||||
raise NotFoundError('Not found')
|
||||
task = _require_formal_notice(task)
|
||||
data = request.get_json(silent=True) or {}
|
||||
try:
|
||||
line_index = int(data.get('line_index'))
|
||||
@@ -834,11 +760,15 @@ def workspace_auto_progress_shipping_task(task_no: str):
|
||||
str(task.task_no), trigger='workspace_auto_progress', operator_id=int(user.id),
|
||||
)
|
||||
|
||||
# 兼容旧前端:若仍有 export 路径则附带 download_url。
|
||||
# 导出下载路径只从当前有效 Artifact 读取,Notice 不再保存文件投影。
|
||||
if isinstance(result, dict) and result.get('status') in {'completed', 'running', 'ok'}:
|
||||
# 重新加载任务以读取 export_file_path(若决策器已推进到导出)。
|
||||
refreshed = get_task_for_user(task_no, user.id)
|
||||
export_path = getattr(refreshed, 'export_file_path', None) if refreshed is not None else None
|
||||
artifact = None
|
||||
if refreshed is not None:
|
||||
from app.services.shipping_notice.upload_attempt_service import latest_export_artifact
|
||||
|
||||
artifact = latest_export_artifact(refreshed)
|
||||
export_path = getattr(artifact, 'file_path', None)
|
||||
if export_path:
|
||||
result = {
|
||||
**result,
|
||||
@@ -862,6 +792,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')
|
||||
task = _require_formal_notice(task)
|
||||
_assert_fulfillment_task_ownership(task, user.id)
|
||||
from app.services.shipping_notice import tools as shipping_tools
|
||||
data = request.get_json(silent=True) or {}
|
||||
@@ -1139,6 +1070,7 @@ def workspace_shipping_task_export(task_no: str):
|
||||
"""下载当前用户可访问任务的出货 Excel;写入统一访问审计。"""
|
||||
user = _require_user()
|
||||
task = get_task_for_user(task_no, user.id)
|
||||
task = _require_formal_notice(task)
|
||||
err_msg = task_export_error_message(task)
|
||||
if err_msg:
|
||||
raise NotFoundError(err_msg)
|
||||
@@ -1900,19 +1832,17 @@ def workspace_patch_shipping_order_review_header_field(case_no: str, field_id: s
|
||||
return _ok(result)
|
||||
|
||||
|
||||
@workspace_shipping_notice_bp.route('/shipping-notice/order-review-cases/<case_no>/draft/lines/<line_key>/fields/<field_id>', methods=['PATCH'])
|
||||
def workspace_patch_shipping_order_review_line_field(case_no: str, line_key: str, field_id: str):
|
||||
"""修改或恢复一个复核订单行字段;行只接受服务端返回的稳定 line_key。"""
|
||||
@workspace_shipping_notice_bp.route('/shipping-notice/order-review-cases/<case_no>/draft/lines/<draft_line_id>/fields/<field_id>', methods=['PATCH'])
|
||||
def workspace_patch_shipping_order_review_line_field(case_no: str, draft_line_id: str, field_id: str):
|
||||
"""修改或恢复一个复核订单行字段;行只接受服务端返回的 draft_line_id。"""
|
||||
user = _require_user()
|
||||
from app.services.shipping_notice.order_review_draft_service import patch_line_field
|
||||
|
||||
payload = _review_draft_payload(user_id=user.id, case_no=case_no, action='line_field_changed')
|
||||
result = patch_line_field(
|
||||
user_id=user.id, case_no=case_no, line_key=line_key, field_id=field_id, value=payload.get('value'),
|
||||
user_id=user.id, case_no=case_no, draft_line_id=draft_line_id, field_id=field_id, value=payload.get('value'),
|
||||
expected_draft_version=payload.get('expected_draft_version'),
|
||||
restore_machine=bool(payload.get('restore_machine')),
|
||||
override_reason_code=payload.get('override_reason_code'),
|
||||
override_reason_text=payload.get('override_reason_text'),
|
||||
)
|
||||
db.session.commit()
|
||||
return _ok(result)
|
||||
@@ -1930,30 +1860,30 @@ def workspace_add_shipping_order_review_line(case_no: str):
|
||||
return _ok(result)
|
||||
|
||||
|
||||
@workspace_shipping_notice_bp.route('/shipping-notice/order-review-cases/<case_no>/draft/lines/<line_key>/copy', methods=['POST'])
|
||||
def workspace_copy_shipping_order_review_line(case_no: str, line_key: str):
|
||||
@workspace_shipping_notice_bp.route('/shipping-notice/order-review-cases/<case_no>/draft/lines/<draft_line_id>/copy', methods=['POST'])
|
||||
def workspace_copy_shipping_order_review_line(case_no: str, draft_line_id: str):
|
||||
"""复制一条复核行;后端校验会阻断由复制造成的重复 Reservation。"""
|
||||
user = _require_user()
|
||||
from app.services.shipping_notice.order_review_draft_service import copy_line
|
||||
|
||||
payload = _review_draft_payload(user_id=user.id, case_no=case_no, action='line_copied')
|
||||
result = copy_line(
|
||||
user_id=user.id, case_no=case_no, line_key=line_key,
|
||||
user_id=user.id, case_no=case_no, draft_line_id=draft_line_id,
|
||||
expected_draft_version=payload.get('expected_draft_version'),
|
||||
)
|
||||
db.session.commit()
|
||||
return _ok(result)
|
||||
|
||||
|
||||
@workspace_shipping_notice_bp.route('/shipping-notice/order-review-cases/<case_no>/draft/lines/<line_key>', methods=['DELETE'])
|
||||
def workspace_delete_shipping_order_review_line(case_no: str, line_key: str):
|
||||
@workspace_shipping_notice_bp.route('/shipping-notice/order-review-cases/<case_no>/draft/lines/<draft_line_id>', methods=['DELETE'])
|
||||
def workspace_delete_shipping_order_review_line(case_no: str, draft_line_id: str):
|
||||
"""删除一条复核行;即使删除最后一行,也只更新草稿和阻断校验。"""
|
||||
user = _require_user()
|
||||
from app.services.shipping_notice.order_review_draft_service import delete_line
|
||||
|
||||
payload = _review_draft_payload(user_id=user.id, case_no=case_no, action='line_deleted')
|
||||
result = delete_line(
|
||||
user_id=user.id, case_no=case_no, line_key=line_key,
|
||||
user_id=user.id, case_no=case_no, draft_line_id=draft_line_id,
|
||||
expected_draft_version=payload.get('expected_draft_version'),
|
||||
)
|
||||
db.session.commit()
|
||||
@@ -1992,7 +1922,7 @@ def workspace_reroute_shipping_order_review_inventory_routing(case_no: str):
|
||||
"""
|
||||
按最新已发布规则重算库存源路由;不重新识别 PDF,并清除历史人工库存源决定。
|
||||
|
||||
核心逻辑:可选 line_key;携带 expected_draft_version 与幂等键。
|
||||
核心逻辑:可选 draft_line_id;携带 expected_draft_version 与幂等键。
|
||||
"""
|
||||
user = _require_user()
|
||||
from app.services.shipping_notice.order_review_draft_service import reroute_inventory_routing
|
||||
@@ -2005,7 +1935,7 @@ def workspace_reroute_shipping_order_review_inventory_routing(case_no: str):
|
||||
case_no=case_no,
|
||||
expected_draft_version=payload.get('expected_draft_version'),
|
||||
idempotency_key=payload.get('idempotency_key'),
|
||||
line_key=payload.get('line_key'),
|
||||
draft_line_id=payload.get('draft_line_id'),
|
||||
)
|
||||
db.session.commit()
|
||||
return _ok(result)
|
||||
@@ -2122,7 +2052,7 @@ def workspace_decide_shipping_order_review_line_fulfillment(case_no: str):
|
||||
"""
|
||||
写入行级履约决定。
|
||||
|
||||
Body: line_key, decision_code, reason?, release_field_values?, expected_draft_version?
|
||||
Body: draft_line_id, decision_code, reason?, release_field_values?, expected_draft_version?
|
||||
"""
|
||||
user = _require_user()
|
||||
data = request.get_json(silent=True) or {}
|
||||
@@ -2134,7 +2064,7 @@ def workspace_decide_shipping_order_review_line_fulfillment(case_no: str):
|
||||
result = decide_review_line_fulfillment(
|
||||
user_id=user.id,
|
||||
case_no=case_no,
|
||||
line_key=str(data.get('line_key') or ''),
|
||||
draft_line_id=str(data.get('draft_line_id') or ''),
|
||||
decision_code=str(data.get('decision_code') or ''),
|
||||
reason=str(data.get('reason') or '').strip() or None,
|
||||
release_field_values=(
|
||||
@@ -2156,7 +2086,7 @@ def workspace_create_shipping_order_review_fulfillment_wave(case_no: str):
|
||||
"""
|
||||
为选中完整明细行创建履约波次。
|
||||
|
||||
Body: line_keys[], expected_draft_version, idempotency_key, reason?
|
||||
Body: snapshot_line_ids[], expected_draft_version, idempotency_key, reason?
|
||||
只允许正式 OT 走 create_post_ot_fulfillment_wave +
|
||||
schedule_post_ot_wave_progress。无正式 OT 的历史波次路径已下线,调用方必须
|
||||
先完成正式建单,避免同一业务动作存在两套推进事实。
|
||||
@@ -2171,14 +2101,14 @@ def workspace_create_shipping_order_review_fulfillment_wave(case_no: str):
|
||||
|
||||
case = soft_load_review_case_for_audit(user_id=int(user.id), case_no=str(case_no or ''))
|
||||
formal = resolve_formal_ot(case) if case is not None else {'has_formal_ot': False}
|
||||
line_keys = list(data.get('line_keys') or [])
|
||||
snapshot_line_ids = list(data.get('snapshot_line_ids') or [])
|
||||
idem = data.get('idempotency_key') or request.headers.get('Idempotency-Key')
|
||||
reason = str(data.get('reason') or '').strip() or None
|
||||
|
||||
if formal.get('has_formal_ot'):
|
||||
result = create_post_ot_fulfillment_wave(
|
||||
case_no=str(case_no),
|
||||
line_keys=line_keys,
|
||||
snapshot_line_ids=snapshot_line_ids,
|
||||
decision_source='user',
|
||||
actor_user_id=int(user.id),
|
||||
reason=reason,
|
||||
@@ -2190,7 +2120,7 @@ def workspace_create_shipping_order_review_fulfillment_wave(case_no: str):
|
||||
progress = schedule_post_ot_wave_progress(
|
||||
task_no=str(result.get('task_no') or ''),
|
||||
wave_no=result.get('wave_no'),
|
||||
line_keys=list(result.get('accepted_line_keys') or line_keys),
|
||||
snapshot_line_ids=list(result.get('accepted_snapshot_line_ids') or snapshot_line_ids),
|
||||
review_case_id=int(result.get('review_case_id') or (case.id if case is not None else 0) or 0) or None,
|
||||
idempotency_row_id=result.get('idempotency_row_id'),
|
||||
request_idempotency_key=str(result.get('idempotency_key') or idem or '') or None,
|
||||
@@ -2223,7 +2153,7 @@ def workspace_close_shipping_order_review_fulfillment(case_no: str):
|
||||
"""
|
||||
关闭行级或 Case 剩余开放行。
|
||||
|
||||
Body: reason, line_keys?, expected_draft_version?
|
||||
Body: reason, draft_line_ids?, expected_draft_version?
|
||||
"""
|
||||
user = _require_user()
|
||||
data = request.get_json(silent=True) or {}
|
||||
@@ -2236,7 +2166,7 @@ def workspace_close_shipping_order_review_fulfillment(case_no: str):
|
||||
user_id=user.id,
|
||||
case_no=case_no,
|
||||
reason=str(data.get('reason') or ''),
|
||||
line_keys=list(data.get('line_keys') or []) or None,
|
||||
draft_line_ids=list(data.get('draft_line_ids') or []) or None,
|
||||
expected_draft_version=data.get('expected_draft_version'),
|
||||
actor_is_admin=is_admin,
|
||||
)
|
||||
@@ -2349,9 +2279,7 @@ def workspace_confirm_shipping_order_review_case(case_no: str):
|
||||
user = _require_user()
|
||||
from app.services.shipping_notice.order_review_confirmation_service import (
|
||||
confirm_review_case,
|
||||
finalize_sync_auto_progress_after_commit,
|
||||
resolve_confirm_outcome,
|
||||
schedule_auto_progress_after_review_confirm,
|
||||
)
|
||||
|
||||
payload = _review_draft_payload(
|
||||
@@ -2366,14 +2294,22 @@ def workspace_confirm_shipping_order_review_case(case_no: str):
|
||||
warning_acknowledgements=payload.get('warning_acknowledgements'),
|
||||
)
|
||||
# [STEP] 与建单同事务写入 shipping_notice_run,避免「已建单、推进失败不可恢复」。
|
||||
# 复核确认只产生 OT;正式 ShippingNotice 尚未生成,不能把 OT 编号投递到
|
||||
# 旧的 notice-run Job。库存源候选的裁决/冻结确认后由正式 inventory_source_routing
|
||||
# Gate 负责;通过 schedule_auto_progress_after_review_confirm 入队自动推进,
|
||||
# 使 OT 在不冻结候选的情况下仍能走到库存链路。
|
||||
from app.services.shipping_notice.order_review_confirmation_service import (
|
||||
finalize_sync_auto_progress_after_commit,
|
||||
schedule_auto_progress_after_review_confirm,
|
||||
)
|
||||
progress = schedule_auto_progress_after_review_confirm(
|
||||
task_no=result.get('task_no'),
|
||||
task_no=str(result.get('task_no')),
|
||||
idempotent_replay=bool(result.get('idempotent_replay')),
|
||||
created_by_id=int(user.id),
|
||||
commit=False,
|
||||
)
|
||||
# [STEP] BE-4:正式 OT 创建后补触发自动履约(flag 关时 enqueue 内部 no-op)
|
||||
if result.get('task_no') and not result.get('idempotent_replay'):
|
||||
if result.get('shipping_notice_no') and not result.get('idempotent_replay'):
|
||||
from app.services.shipping_notice.line_auto_fulfill_coordinator import (
|
||||
enqueue_post_ot_auto_fulfill_job,
|
||||
)
|
||||
@@ -2383,8 +2319,8 @@ def workspace_confirm_shipping_order_review_case(case_no: str):
|
||||
commit=False,
|
||||
)
|
||||
db.session.commit()
|
||||
# [STEP] sync 执行失败不得变成 HTTP 500,须返回「确认成功 + 推进态」字段。
|
||||
progress = finalize_sync_auto_progress_after_commit(progress)
|
||||
# [STEP] sync 执行失败不得变成 HTTP 500,须返回「确认成功 + 推进态」字段。
|
||||
result = dict(result)
|
||||
result.pop('trigger_auto_progress', None)
|
||||
result['confirm_ok'] = True
|
||||
@@ -2395,12 +2331,36 @@ def workspace_confirm_shipping_order_review_case(case_no: str):
|
||||
'message': '无需调度自动推进,或任务已离开待推进态',
|
||||
}
|
||||
else:
|
||||
# [STEP] 仅下发 position / user_mode;禁止 checkpoint 别名。
|
||||
position = progress.get('position')
|
||||
user_mode = progress.get('user_mode')
|
||||
if not position or not user_mode:
|
||||
try:
|
||||
from app.models import ShippingOrderTask
|
||||
from app.services.shipping_notice.progress_workflow import (
|
||||
_entry_position,
|
||||
_entry_user_mode,
|
||||
)
|
||||
|
||||
ot = (
|
||||
db.session.query(ShippingOrderTask)
|
||||
.filter(
|
||||
ShippingOrderTask.task_no == str(result.get('task_no') or '').strip().upper()
|
||||
)
|
||||
.first()
|
||||
)
|
||||
if ot is not None:
|
||||
position = position or _entry_position(ot)
|
||||
user_mode = user_mode or _entry_user_mode(ot)
|
||||
except Exception:
|
||||
pass
|
||||
result['auto_progress_started'] = bool(progress.get('auto_progress_started'))
|
||||
result['auto_progress'] = {
|
||||
'status': progress.get('status'),
|
||||
'message': progress.get('message'),
|
||||
'enqueue_result': progress.get('enqueue_result'),
|
||||
'checkpoint': progress.get('checkpoint'),
|
||||
'position': position,
|
||||
'user_mode': user_mode,
|
||||
}
|
||||
result['confirm_outcome'] = resolve_confirm_outcome(
|
||||
{
|
||||
@@ -2632,7 +2592,7 @@ def workspace_request_shipping_order_review_llm_suggestion(case_no: str):
|
||||
user_id=user.id,
|
||||
case_no=case_no,
|
||||
field_id=str(payload.get('field_id') or ''),
|
||||
line_key=payload.get('line_key'),
|
||||
draft_line_id=payload.get('draft_line_id'),
|
||||
evidence_level=payload.get('evidence_level'),
|
||||
issue_code=payload.get('issue_code'),
|
||||
allow_full_pdf=bool(payload.get('allow_full_pdf')),
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
"""
|
||||
backend/app/api/workspace/voucher_check.py
|
||||
|
||||
用途:工作台立账凭证检核记录查询 API(批次明细 / 最新状态)。
|
||||
用途:工作台立账凭证检核查询与强制重检 API(任务列表 / 批次明细 / 企微发送记录)。
|
||||
依赖:auth.jwt、response_utils envelope、voucher_check.query_service。
|
||||
逻辑:对话与检核记录页共用;标准 {success,data|error,request_id} envelope。
|
||||
逻辑:对话与检核任务页共用;GET notifications 为企微发送记录;POST runs 仅 admin,以 force_all 入队周批排程。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -11,7 +11,7 @@ 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.errors import ForbiddenError, UnauthorizedError, ValidationError
|
||||
from app.core.response import ok
|
||||
from app.services.voucher_check import query_service
|
||||
|
||||
@@ -25,11 +25,55 @@ def _require_user():
|
||||
return user
|
||||
|
||||
|
||||
def _require_admin():
|
||||
"""工作台强制重检仅管理员可触发,鉴权方式与本蓝图 GET 一致。"""
|
||||
user = _require_user()
|
||||
if getattr(user, "role", None) != "admin":
|
||||
raise ForbiddenError("Admin privilege required")
|
||||
return user
|
||||
|
||||
|
||||
@workspace_voucher_check_bp.route("/accounting-voucher-check/runs", methods=["GET"])
|
||||
def workspace_voucher_runs():
|
||||
"""
|
||||
分页查看检核任务列表。
|
||||
核心逻辑:委托 query_service.list_runs,按资料所属期间/业务方/状态筛选。
|
||||
"""
|
||||
_require_user()
|
||||
data = query_service.list_runs(
|
||||
period=request.args.get("period"),
|
||||
profile_code=request.args.get("profile_code"),
|
||||
status=request.args.get("status"),
|
||||
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/runs", methods=["POST"])
|
||||
def workspace_voucher_force_run():
|
||||
"""
|
||||
强制重检上一个自然月(不走增量跳过)。
|
||||
核心逻辑:body.mode 仅接受 force_all;入队默认周批排程,由 schedule worker 执行。
|
||||
"""
|
||||
user = _require_admin()
|
||||
payload = request.get_json(silent=True) or {}
|
||||
mode = str(payload.get("mode") or "force_all").strip().lower()
|
||||
if mode != "force_all":
|
||||
raise ValidationError(
|
||||
"工作台仅支持 force_all",
|
||||
code="VOUCHER_CHECK.CONFIG_INVALID",
|
||||
details={"mode": mode},
|
||||
)
|
||||
data = query_service.enqueue_force_all_run(triggered_by_user_id=getattr(user, "id", None))
|
||||
return ok(data)
|
||||
|
||||
|
||||
@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 过滤。
|
||||
核心逻辑:委托 query_service.list_run_items,可按 result 过滤,并返回 by_file_type。
|
||||
"""
|
||||
_require_user()
|
||||
data = query_service.list_run_items(
|
||||
@@ -41,30 +85,17 @@ def workspace_voucher_run_items(run_id: int):
|
||||
return ok(data)
|
||||
|
||||
|
||||
@workspace_voucher_check_bp.route("/accounting-voucher-check/states", methods=["GET"])
|
||||
def workspace_voucher_states():
|
||||
@workspace_voucher_check_bp.route("/accounting-voucher-check/notifications", methods=["GET"])
|
||||
def workspace_voucher_notifications():
|
||||
"""
|
||||
按月份、状态、发票号筛选最新状态。
|
||||
分页查看企微缺件汇总发送记录。
|
||||
核心逻辑:委托 query_service.list_notifications,可按期间和发送状态筛选。
|
||||
"""
|
||||
_require_user()
|
||||
data = query_service.list_states(
|
||||
scope_code=str(request.args.get("scope_code") or "HXJM"),
|
||||
data = query_service.list_notifications(
|
||||
period=request.args.get("period"),
|
||||
status=request.args.get("status"),
|
||||
invoice_no=request.args.get("invoice_no"),
|
||||
send_status=request.args.get("send_status"),
|
||||
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