feat(in-transit-transfer): 更新证据下载与待匹配清单逻辑
- 修改证据下载接口,分别签发预览地址与带保存名的下载地址,避免浏览器使用对象键哈希作为保存名。 - 待匹配清单接口调整,按外部单号合计数量,不再返回外部项次,提升数据展示的清晰度。 - 移除待匹配桶的「清空并重新解析」功能,简化操作流程,确保用户体验一致性。 - 新增跨页全选支持的 API,允许用户在待处理池中选择全部待处理明细 ID,优化批量操作体验。
This commit is contained in:
1 parent
4c2a7e2a23
commit
663f401873
50 files changed
+2156
-1309
No files matched your search
@@ -10,7 +10,7 @@
|
||||
unconfigured 后再各写最多一个 batch;
|
||||
证据下载(POST /sources/inbound-files)按同一函数打包各来源最新可用
|
||||
入站/出站文件;当天清单(GET /sources/<code>/evidence-files)复用可用
|
||||
条件返回当天全部文件并签发预签地址;
|
||||
条件返回当天全部文件,并分别签发预览地址与带保存名的下载地址;
|
||||
匹配创建(POST /matchings)与进度恢复(GET /matchings/{id});执行为 D8
|
||||
异步契约(POST /items/execute → 202 queued + run_no,单在提交时组建);
|
||||
result_unknown 单人工重新触发(POST /runs/{run_no}/documents/{doc_no}/
|
||||
@@ -19,9 +19,11 @@
|
||||
D18 废单不废行); 调拨类型选择数据源(GET /transfer-types,仅启用、
|
||||
最小暴露,另附 record_kinds_of(scope_rules) 推导的 record_kinds,不回传
|
||||
scope_rules / warehouse_config / description);来源列表(GET /sources)
|
||||
一次批量投影全部启用来源的入站/出站文件状态;待匹配桶维护(spec §6):
|
||||
「清空并重新解析」预检(GET /backlog/pending-match/reparse-preview,只读)
|
||||
与执行(POST /backlog/pending-match/reparse,单事务由 service 提交并落审计)。
|
||||
一次批量投影全部启用来源的入站/出站文件状态。待匹配清单只读
|
||||
(GET /backlog/pending-match,含外部单号与外部项次)。
|
||||
2026-10-22 起不再挂「清空并重新解析」
|
||||
(原 GET/POST /backlog/pending-match/reparse*):该入口会重放保留期内
|
||||
全部归档。重解析只保留 POST /sources/<code>/reparse(当天最新一份)。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -163,7 +165,10 @@ def create_matching_api():
|
||||
@in_transit_transfer_bp.route("/items/executable", methods=["GET"])
|
||||
@require_transfer_permission
|
||||
def executable_items_api():
|
||||
"""可调拨明细(全局可执行行队列):勾选后 POST /items/execute 按行生成调拨单。"""
|
||||
"""可调拨明细(全局可执行行队列):勾选后 POST /items/execute 按行生成调拨单。
|
||||
|
||||
行上 transfer_type 是出生匹配快照的类型 code,供跨类型队列显示类别。
|
||||
"""
|
||||
return _ok(list_executable_items())
|
||||
|
||||
|
||||
@@ -235,6 +240,38 @@ def _usable_archive_files(source_code: str, record_kind: str) -> list:
|
||||
)
|
||||
|
||||
|
||||
def evidence_download_filename(
|
||||
source_code: str,
|
||||
created_at: datetime | None,
|
||||
original_filename: str | None,
|
||||
) -> str:
|
||||
"""证据单文件的保存名:库存源编码加东八区抓取日期和时分。
|
||||
|
||||
核心逻辑:created_at 无时区时按 UTC 理解,转到 UTC+8 后取年月日和时分,
|
||||
与详情行展示的时刻一致。扩展名沿用归档原名,缺省 .xlsx。对象键哈希不进入文件名。
|
||||
|
||||
Args:
|
||||
source_code: 库存源实例编码。
|
||||
created_at: 归档创建时间;naive 视为 UTC。
|
||||
original_filename: 归档原名,只取其扩展名。
|
||||
|
||||
Returns:
|
||||
如 CRANE_20261022_1057.xlsx。来源编码会收成文件名安全字符。
|
||||
"""
|
||||
import re
|
||||
from datetime import timezone
|
||||
from pathlib import Path
|
||||
|
||||
suffix = Path(original_filename or "").suffix
|
||||
ext = suffix if suffix and re.fullmatch(r"\.[A-Za-z0-9]{1,8}", suffix) else ".xlsx"
|
||||
label = re.sub(r"[^\w.-]+", "_", source_code or "").strip("._") or "unknown"
|
||||
if created_at is None:
|
||||
return f"{label}{ext}"
|
||||
aware = created_at if created_at.tzinfo is not None else created_at.replace(tzinfo=timezone.utc)
|
||||
stamp = aware.astimezone(timezone(timedelta(hours=8))).strftime("%Y%m%d_%H%M")
|
||||
return f"{label}_{stamp}{ext}"
|
||||
|
||||
|
||||
def _record_evidence_download_audit(*, aggregate_id: str) -> None:
|
||||
"""写入证据文件访问审计,事件类型保持 TRANSFER_INBOUND_FILES_DOWNLOADED。
|
||||
|
||||
@@ -332,9 +369,10 @@ def list_source_evidence_files_api(source_code: str):
|
||||
查询参数 record_kind 缺省 inbound,只接受 inbound 或 outbound。
|
||||
可用条件与证据压缩包相同,但返回当天全部可用文件,不只最新一份。
|
||||
每项含 file_id、original_filename、created_at、sha256、file_size、
|
||||
presigned_url。不解析 Excel,不含行数。预签调用
|
||||
presigned_get_url(storage_key, expires_seconds=300)。签发时写
|
||||
TRANSFER_INBOUND_FILES_DOWNLOADED,aggregate_id 为 source_code。
|
||||
presigned_url、download_url。不解析 Excel,不含行数。预览与下载各签一次
|
||||
presigned_get_url(storage_key, expires_seconds=300);下载地址额外带
|
||||
download_name(库存源_东八区年月日_时分.扩展名),避免浏览器用对象键哈希当保存名。
|
||||
签发时写 TRANSFER_INBOUND_FILES_DOWNLOADED,aggregate_id 为 source_code。
|
||||
"""
|
||||
from app.services.file_assets.storage import file_asset_storage
|
||||
|
||||
@@ -345,6 +383,7 @@ def list_source_evidence_files_api(source_code: str):
|
||||
payload = []
|
||||
for report in _usable_archive_files(code, kind):
|
||||
created = report.created_at.isoformat() if report.created_at is not None else None
|
||||
download_name = evidence_download_filename(code, report.created_at, report.original_filename)
|
||||
payload.append({
|
||||
"file_id": report.id,
|
||||
"original_filename": report.original_filename,
|
||||
@@ -354,6 +393,9 @@ def list_source_evidence_files_api(source_code: str):
|
||||
"presigned_url": file_asset_storage.presigned_get_url(
|
||||
report.storage_key, expires_seconds=300,
|
||||
),
|
||||
"download_url": file_asset_storage.presigned_get_url(
|
||||
report.storage_key, expires_seconds=300, download_name=download_name,
|
||||
),
|
||||
})
|
||||
_record_evidence_download_audit(aggregate_id=code)
|
||||
return _ok(payload)
|
||||
@@ -1208,6 +1250,8 @@ def retry_sources_rpa_batch_api():
|
||||
def backlog_api():
|
||||
"""待处理异常列表(可恢复/已关闭/结果未知 + 老化等级);查看记录访问审计。
|
||||
|
||||
行上 transfer_type 是出生匹配快照的类型 code。
|
||||
|
||||
Query(全部可选;不带 page/page_size 时保持历史行为返回全量数组——向后兼容):
|
||||
page(默认 1);page_size(默认 20,上限 100)——任一提供即切换为
|
||||
分页 envelope {items, total, page, page_size}(2026-10-16 服务端分页:
|
||||
@@ -1272,6 +1316,36 @@ def backlog_api():
|
||||
return _ok(payload)
|
||||
|
||||
|
||||
@in_transit_transfer_bp.route("/backlog/item-ids", methods=["GET"])
|
||||
@require_transfer_permission
|
||||
def backlog_item_ids_api():
|
||||
"""跨页全选支持(2026-10-22):当前筛选下全部待处理明细 id(轻量列表)。
|
||||
|
||||
Query:keyword / result_filter(与 /backlog 分页模式同口径、同白名单 400)。
|
||||
Returns:{ ids: [item_id...](升序,上限 BACKLOG_SELECT_ALL_MAX),
|
||||
total: 筛选后全量计数, truncated: total > len(ids) }。
|
||||
用途:待处理池「选择全部 N 行」——服务端分页下勾选集合默认只覆盖当前页,
|
||||
本端点按同一筛选口径取全量 id;批量端点(重查/恢复/关闭)本就按 item_ids
|
||||
列表逐行隔离,直接复用无需新批量契约。
|
||||
"""
|
||||
from app.services.in_transit_transfer.backlog_service import (
|
||||
BACKLOG_SELECT_ALL_MAX,
|
||||
RESULT_FILTER_CHOICES,
|
||||
list_backlog_item_ids,
|
||||
)
|
||||
|
||||
keyword = (request.args.get("keyword") or "").strip()
|
||||
result_filter = (request.args.get("result_filter") or "").strip() or "all"
|
||||
if result_filter not in RESULT_FILTER_CHOICES:
|
||||
raise ValidationError(
|
||||
f"result_filter must be one of {sorted(RESULT_FILTER_CHOICES)}",
|
||||
)
|
||||
ids, total = list_backlog_item_ids(
|
||||
keyword=keyword or None, result_filter=result_filter, limit=BACKLOG_SELECT_ALL_MAX,
|
||||
)
|
||||
return _ok({"ids": ids, "total": total, "truncated": total > len(ids)})
|
||||
|
||||
|
||||
@in_transit_transfer_bp.route("/backlog/summary", methods=["GET"])
|
||||
@require_transfer_permission
|
||||
def backlog_summary_api():
|
||||
@@ -1283,9 +1357,9 @@ def backlog_summary_api():
|
||||
'recoverable': summary.recoverable_count,
|
||||
'closed': summary.closed_count,
|
||||
'unknown': summary.unknown_count,
|
||||
# 首页待办看板第 4 张数字卡(D16):已落档尚未匹配的外部入站记录数。
|
||||
# 首页待办看板第 4 张数字卡:与待匹配清单同一外部单号合并口径。
|
||||
'pending_match': summary.pending_match_count,
|
||||
# 库存匹配卡:启用类型现在圈得住的行数。待匹配卡用上面的全量。
|
||||
# 库存匹配卡:与清单「当前可匹配」同一合并口径。
|
||||
'matchable_count': summary.matchable_count,
|
||||
'aging': {
|
||||
'warn_3d': summary.warn_3d,
|
||||
@@ -1305,7 +1379,9 @@ def backlog_pending_match_api():
|
||||
page(默认 1);page_size(默认 20,上限 100)——任一提供即切换为
|
||||
分页 envelope {records, total, page, page_size}。
|
||||
segment:all(默认,全量)/ matchable(启用类型现在圈得住)/
|
||||
outside(其余已落档)。每行带 matchable。
|
||||
outside(其余已落档)。每行带 matchable、external_doc_no。
|
||||
quantity 是同一来源、同一记录类型、同一外部单号下的数量合计;
|
||||
没有外部单号的档行仍逐行返回。不再返回 external_line_no。
|
||||
"""
|
||||
from app.services.in_transit_transfer.backlog_service import (
|
||||
BACKLOG_PAGE_DEFAULT,
|
||||
@@ -1339,10 +1415,11 @@ def backlog_pending_match_api():
|
||||
|
||||
|
||||
def _serialize_pending_match_record(record) -> dict[str, Any]:
|
||||
"""「待匹配」桶项序列化(档记录只读投影;含 record_kind;无 item_id)。"""
|
||||
"""「待匹配」桶项序列化(外部单号合计后的只读投影;无项次、无 item_id)。"""
|
||||
return {
|
||||
'ledger_record_id': record.ledger_record_id,
|
||||
'doc_no': record.doc_no,
|
||||
'external_doc_no': record.external_doc_no,
|
||||
'material_code': record.material_code,
|
||||
'material_name': record.material_name,
|
||||
'movement_date': record.movement_date,
|
||||
@@ -1353,65 +1430,6 @@ def _serialize_pending_match_record(record) -> dict[str, Any]:
|
||||
}
|
||||
|
||||
|
||||
@in_transit_transfer_bp.route("/backlog/pending-match/reparse-preview", methods=["GET"])
|
||||
@require_transfer_permission
|
||||
def pending_match_reparse_preview_api():
|
||||
"""待匹配桶「清空并重新解析」预检(只读;spec §6 确认弹窗数据源)。
|
||||
|
||||
【AI 触发时机】仅待匹配面板「清空并重新解析」确认弹窗加载预检结果时调用;
|
||||
禁止在运行期收料落地链路调用(运行期走 evidence_sync,当日 fail-closed 语义)。
|
||||
Query:source_code(必填)、record_kind(缺省 inbound;outbound=出站流)。
|
||||
响应 data:{record_kind, files, profile, clearable_rows, kept_rows}。
|
||||
"""
|
||||
from app.services.in_transit_transfer.backlog_reparse_service import preview_pending_match_reparse
|
||||
|
||||
source_code = str(request.args.get("source_code") or "").strip()
|
||||
if not source_code:
|
||||
raise ValidationError("source_code is required")
|
||||
record_kind = str(request.args.get("record_kind") or "inbound").strip() or "inbound"
|
||||
return _ok(preview_pending_match_reparse(
|
||||
source_code=source_code, now=datetime.utcnow(), record_kind=record_kind,
|
||||
))
|
||||
|
||||
|
||||
@in_transit_transfer_bp.route("/backlog/pending-match/reparse", methods=["POST"])
|
||||
@require_transfer_permission
|
||||
def pending_match_reparse_api():
|
||||
"""待匹配桶「清空并重新解析」执行(spec §6;单事务由 service 提交)。
|
||||
|
||||
【AI 触发时机】仅待匹配面板「清空并重新解析」确认提交时调用;
|
||||
禁止在运行期收料落地链路调用(运行期走 evidence_sync,当日 fail-closed 语义)。
|
||||
请求体 {"source_code", "record_kind"?};record_kind 缺省 inbound。
|
||||
任一归档解析失败整体中止(TRANSFER.REPARSE_PARSE_FAILED,一行不删)。
|
||||
响应 data:含 record_kind 与 cleared/reinserted 等计数。
|
||||
"""
|
||||
from app.services.in_transit_transfer.backlog_reparse_service import reparse_pending_match
|
||||
|
||||
payload = request.get_json(silent=True) or {}
|
||||
source_code = str(payload.get("source_code") or "").strip()
|
||||
if not source_code:
|
||||
raise ValidationError("source_code is required")
|
||||
record_kind = str(payload.get("record_kind") or "inbound").strip() or "inbound"
|
||||
user = _require_user()
|
||||
outcome = reparse_pending_match(
|
||||
source_code=source_code,
|
||||
operator=str(getattr(user, "username", "") or user.id),
|
||||
now=datetime.utcnow(),
|
||||
record_kind=record_kind,
|
||||
)
|
||||
return _ok({
|
||||
"source_code": outcome.source_code,
|
||||
"record_kind": outcome.record_kind,
|
||||
"cleared": outcome.cleared,
|
||||
"reinserted": outcome.reinserted,
|
||||
"date_skipped": outcome.date_skipped,
|
||||
"kept_unrebuildable": outcome.kept_unrebuildable,
|
||||
"unlinked_items": outcome.unlinked_items,
|
||||
"collapses": outcome.collapses,
|
||||
"files": list(outcome.files),
|
||||
})
|
||||
|
||||
|
||||
def _serialize_backlog_item(item) -> dict[str, Any]:
|
||||
"""待处理池项序列化(明细字段与匹配窗口列一致)。"""
|
||||
return {
|
||||
@@ -1432,4 +1450,5 @@ def _serialize_backlog_item(item) -> dict[str, Any]:
|
||||
'movement_quantity': item.movement_quantity,
|
||||
'external_quantity': item.external_quantity,
|
||||
'result_code': item.result_code,
|
||||
'transfer_type': item.transfer_type,
|
||||
}
|
||||
Reference in new issue
Block a user