feat(freight-rpa): 系统连接只保留上传开关并增加 Crane 一次回查

上传页、按钮和成功判断改由连接器固定。Crane 分配中只排一次 10 分钟状态回查,手动刷新不改到期时间。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
hugoandCursor committed 2026-10-23 12:20:29 +08:00
1 parent 95e7db0831
commit 3bb9938c05
33 files changed
+878 -374

No files matched your search

+2 -2
View File
@@ -43,7 +43,7 @@ def _ok(data, *, status: int = 200):
@admin_bp.route('/freight-rpa/rpa-profiles', methods=['GET'])
@require_admin
def list_shipping_rpa_profiles():
"""列出脱敏后的 RPA Profile 配置。"""
"""列出 RPA Profile;响应含用户名明文,不含密码与密文。"""
return _ok(freight_rpa_source_admin_service.list_profiles())
@@ -57,7 +57,7 @@ def create_shipping_rpa_profile():
@admin_bp.route('/freight-rpa/rpa-profiles/<int:profile_id>', methods=['PUT'])
@require_admin
def update_shipping_rpa_profile(profile_id: int):
"""更新 RPA Profile;未提交密码字段时保留既有密文。"""
"""更新 RPA Profile;用户名与已存明文相同、或密码留空时不重写对应密文。"""
return _ok(freight_rpa_source_admin_service.save_profile(request.get_json(silent=True) or {}, actor_id=_actor_id(), profile_id=profile_id))
+7 -1
View File
@@ -18,7 +18,7 @@ backend/app/api/freight_rpa.py
from __future__ import annotations
from flask import Blueprint, jsonify, request
from flask import Blueprint, current_app, jsonify, request
from app.core.errors import ValidationError
from app.core.tool_auth import require_tool_auth
@@ -65,6 +65,12 @@ def heartbeat():
except ValueError as exc:
raise ValidationError(str(exc))
# 心跳存储不可用(ServiceUnavailableError)原样上抛,由全局 AppError handler 出标准错误 envelope。
# 到期的 Crane 定时回查跟着心跳落成 trigger;写失败不让心跳本身失败。
try:
from app.services.freight_rpa.upload.crane_recheck import materialize_due_crane_rechecks
materialize_due_crane_rechecks()
except Exception:
current_app.logger.exception('crane recheck materialize failed')
return jsonify({'status': 'ok', 'message': 'heartbeat recorded', 'data': worker})
@@ -1102,6 +1102,47 @@ def workspace_confirm_shipping_notice_uploaded(business_no: str):
))
@workspace_shipping_notice_bp.route('/shipping-notices/<business_no>/refresh-crane-upload', methods=['POST'])
def workspace_refresh_crane_upload_status(business_no: str):
"""手动刷新一张仍在分配中的 Crane 发货单。
核心逻辑:校验当前用户可见的通知单,读取最近一次上传尝试,写入一条只查状态的 trigger。
不改 10 分钟定时回查的到期时间,也不重新上传 Excel。
Args:
business_no: 对外发货通知单号,同时是 Crane 的 Pull Request #。
Returns:
JSON: business_no 与 trigger_queued。
Raises:
ValidationError: 没有可刷新的上传尝试或来源连接。
ConflictError: 当前不是分配中,或上一次手动刷新还在排队。
"""
user = _require_user()
task = _load_business_notice_for_user(business_no=business_no, user_id=int(user.id))
from app.services.freight_rpa.upload.crane_recheck import request_manual_crane_refresh
from app.services.shipping_notice.onhand_source_rules import task_rpa_inventory_source
from app.services.shipping_notice.onhand_source_repository import get_rpa_trigger_inventory_source
from app.services.shipping_notice.upload_attempt_service import latest_upload_attempt
attempt = latest_upload_attempt(task)
from app.models import ShippingExportArtifact
artifact = db.session.get(ShippingExportArtifact, attempt.artifact_id) if attempt is not None else None
snapshot = task_rpa_inventory_source(task) or {}
upload_source = get_rpa_trigger_inventory_source(str(snapshot.get('source_code') or '')) if snapshot.get('source_code') else None
if attempt is None or artifact is None or not isinstance(upload_source, dict):
raise ValidationError('Crane upload status cannot be refreshed', code='SHIPPING.UPLOAD_CRANE_ALLOCATING')
trigger_path = request_manual_crane_refresh(
attempt,
upload_source,
task_no=str(task.task_no),
export_file_path=str(artifact.file_path or ''),
)
db.session.commit()
return _ok({'business_no': str(task.business_no), 'trigger_queued': bool(trigger_path)})
@workspace_shipping_notice_bp.route('/shipping-notices/<business_no>/rpa-upload', methods=['POST'])
def workspace_start_shipping_notice_rpa_upload(business_no: str):
"""按发货通知单号发起 RPA 上传;RPA 成功事实仍由受信回调裁决。"""