feat(in-transit-transfer): inbound/outbound 幂等重命名与解析用途分层
- receipt→inbound 三件套改名(回调桥/文件门禁/触发服务),回调链幂等去重,迁移 tt14 同步台账键与测试基建 - 库存解析用途分层 onhand/inbound/outbound(迁移 tt15):解析档案、文件存储与下载名按用途隔离,管理端表单同步 - 「成熟」概念退役(迁移 tt16):数据无成熟属性,日期边界由调用方入参严格判定 - backlog 新增重解析服务,在途重识别投影 processing,EML 父项不再停留处理中 - 收料 RPA 回调/归档/排程链路同步改名挂点,运维脚本复位假完成状态 - 文档随批:ADR 0003 模块边界决策、10-15/10-16 计划与设计、调拨文档族与 demand/tec/funclist - 同步 chat/errors 文案四语言、调拨前端卡片与 e2e、测试全家
This commit is contained in:
1 parent
43dceaf027
commit
8102a1fe44
151 files changed
+8057
-2382
No files matched your search
@@ -9,7 +9,9 @@
|
||||
retrigger → 202,D11 唯一出口);首页「已执行」区块:已执行单分页查询
|
||||
(GET /documents,只读)与人工关闭失败单(POST /documents/{doc_no}/close,
|
||||
D18 废单不废行);调拨类型选择数据源(GET /transfer-types,仅启用、
|
||||
最小暴露,读 Task 4 transfer_type_config_service)。
|
||||
最小暴露,读 Task 4 transfer_type_config_service);待匹配桶维护(spec §6):
|
||||
「清空并重新解析」预检(GET /backlog/pending-match/reparse-preview,只读)
|
||||
与执行(POST /backlog/pending-match/reparse,单事务由 service 提交并落审计)。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -60,6 +62,25 @@ in_transit_transfer_bp = Blueprint("in_transit_transfer", __name__)
|
||||
TRANSFER_AGENT_CODE = "in_transit_transfer"
|
||||
|
||||
|
||||
def _parse_int_arg(name: str, default: int, *, minimum: int, maximum: int | None = None) -> int:
|
||||
"""解析整数查询参数(缺省回默认值;下限钳制必填,上限可选;非法 400)。
|
||||
|
||||
分页参数统一入口(/documents、/backlog、/backlog/pending-match 共用,
|
||||
2026-10-16 由 list_documents_api 内嵌函数提升为模块级)。
|
||||
"""
|
||||
raw = (request.args.get(name) or "").strip()
|
||||
if not raw:
|
||||
return default
|
||||
try:
|
||||
value = int(raw)
|
||||
except ValueError as exc:
|
||||
raise ValidationError(f"{name} must be an integer") from exc
|
||||
value = max(minimum, value)
|
||||
if maximum is not None:
|
||||
value = min(maximum, value)
|
||||
return value
|
||||
|
||||
|
||||
def _require_user():
|
||||
"""校验当前登录用户;未认证抛 UnauthorizedError。"""
|
||||
user = get_current_user()
|
||||
@@ -95,7 +116,7 @@ def create_matching_api():
|
||||
"""创建或复用一次调拨匹配(只读,不写 外部系统)。
|
||||
|
||||
请求体:{"source_codes": [...], "business_date": "YYYY-MM-DD"(可选),
|
||||
"receipt_date_from"/"receipt_date_to"(可选),
|
||||
"movement_date_from"/"movement_date_to"(可选,明细异动日期范围),
|
||||
"transfer_type": 必填(类型编码,配置化;缺失/未配置/停用 → 422)}。
|
||||
响应:201 envelope,data 为匹配摘要(matching_id/hash/计数/来源进度);
|
||||
类型门禁失败 422(REQUIRED/NOT_CONFIGURED/DISABLED,规格 §11)。
|
||||
@@ -122,8 +143,8 @@ def create_matching_api():
|
||||
source_codes=[str(item).strip() for item in source_codes],
|
||||
business_date=business_date,
|
||||
deps=deps,
|
||||
receipt_date_from=str(body.get("receipt_date_from")) if body.get("receipt_date_from") else None,
|
||||
receipt_date_to=str(body.get("receipt_date_to")) if body.get("receipt_date_to") else None,
|
||||
movement_date_from=str(body.get("movement_date_from")) if body.get("movement_date_from") else None,
|
||||
movement_date_to=str(body.get("movement_date_to")) if body.get("movement_date_to") else None,
|
||||
transfer_type=transfer_type,
|
||||
)
|
||||
return _ok(serialize_summary(summary), status=201)
|
||||
@@ -162,10 +183,10 @@ def requery_items_api(matching_no: str):
|
||||
))
|
||||
|
||||
|
||||
@in_transit_transfer_bp.route("/sources/receipt-files", methods=["POST"])
|
||||
@in_transit_transfer_bp.route("/sources/inbound-files", methods=["POST"])
|
||||
@require_transfer_permission
|
||||
def download_source_receipt_files_api():
|
||||
"""按选中来源打包下载各自最新归档收料文件(zip);记录访问审计。"""
|
||||
def download_source_inbound_files_api():
|
||||
"""按选中来源打包下载各自最新归档入站文件(ShippingReceiptReport RPA 产物,zip);记录访问审计。"""
|
||||
import io
|
||||
import zipfile
|
||||
from pathlib import Path as _Path
|
||||
@@ -174,7 +195,7 @@ def download_source_receipt_files_api():
|
||||
from app.models import ShippingReceiptReportFile
|
||||
from app.services.file_assets.storage import file_asset_storage
|
||||
from app.services.in_transit_transfer.audit import build_transfer_audit_event
|
||||
from app.services.in_transit_transfer.receipt_file_gate import usable_receipt_file_condition
|
||||
from app.services.in_transit_transfer.inbound_file_gate import usable_inbound_file_condition
|
||||
|
||||
body = request.get_json(silent=True) or {}
|
||||
source_codes = body.get("source_codes")
|
||||
@@ -194,8 +215,8 @@ def download_source_receipt_files_api():
|
||||
.filter(
|
||||
ShippingReceiptReportFile.unit_run.has(source_code=code),
|
||||
# 可用门禁(未清理 + 当天业务日抓取 + 未过保留期)与徽标/匹配取文件同口径,
|
||||
# 单一事实来源见 receipt_file_gate。
|
||||
usable_receipt_file_condition(),
|
||||
# 单一事实来源见 inbound_file_gate。
|
||||
usable_inbound_file_condition(),
|
||||
)
|
||||
.order_by(ShippingReceiptReportFile.created_at.desc(), ShippingReceiptReportFile.id.desc())
|
||||
.first()
|
||||
@@ -207,11 +228,11 @@ def download_source_receipt_files_api():
|
||||
archive.writestr(f"{code}-{safe_name}", data)
|
||||
included.append(code)
|
||||
if not included:
|
||||
raise NotFoundError("no archived receipt files", code="SHIPPING.RECEIPT_FILE_NOT_FOUND")
|
||||
raise NotFoundError("no archived inbound files", code="SHIPPING.INBOUND_FILE_NOT_FOUND")
|
||||
|
||||
user = _require_user()
|
||||
db.session.add(build_transfer_audit_event(
|
||||
event_type="TRANSFER_RECEIPT_FILES_DOWNLOADED",
|
||||
event_type="TRANSFER_INBOUND_FILES_DOWNLOADED",
|
||||
aggregate_type="in_transit_source",
|
||||
aggregate_id=",".join(included),
|
||||
actor_type="user",
|
||||
@@ -226,7 +247,7 @@ def download_source_receipt_files_api():
|
||||
buffer,
|
||||
mimetype="application/zip",
|
||||
as_attachment=True,
|
||||
download_name=f"receipt-files-{len(included)}-source{'s' if len(included) > 1 else ''}.zip",
|
||||
download_name=f"inbound-files-{len(included)}-source{'s' if len(included) > 1 else ''}.zip",
|
||||
)
|
||||
|
||||
|
||||
@@ -342,11 +363,11 @@ def list_documents_api():
|
||||
Query:
|
||||
status_group ∈ {success, failed, executing, result_unknown}(可选,缺省全部;
|
||||
非法 400);date_from/date_to=YYYY-MM-DD(可选,仅作用 orders 列表,
|
||||
按收料日期过滤——列表展示的业务日期口径,2026-09-29 由 created_at 切换);
|
||||
按异动日期过滤——列表展示的业务日期口径,2026-09-29 由 created_at 切换);
|
||||
page(默认 1);page_size(默认 20,上限 100)。
|
||||
口径:分组计数恒全量(GROUP BY status 对全部单统计,不受筛选影响——
|
||||
失败/结果未知/执行中=未完结即待办,全量才不漏;成功=累计产出);
|
||||
列表按 收料日期→数据源→拨出/拨入库位 升序分页(2026-09-29 与可调拨
|
||||
列表按 异动日期→数据源→拨出/拨入库位 升序分页(2026-09-29 与可调拨
|
||||
明细/待处理池/结果卡统一口径,跨数据源不再乱序;执行落库时间仅作
|
||||
同序兜底),cancelled 不展示(无产生路径)。
|
||||
响应:{groups, total, page, page_size, orders:[serialize_executed_order 投影]}。
|
||||
@@ -365,20 +386,6 @@ def list_documents_api():
|
||||
except ValueError as exc:
|
||||
raise ValidationError(f"{name} must be YYYY-MM-DD") from exc
|
||||
|
||||
def _parse_int(name: str, default: int, *, minimum: int, maximum: int | None = None) -> int:
|
||||
"""解析整数查询参数(缺省回默认值;下限钳制必填,上限可选)。"""
|
||||
raw = (request.args.get(name) or "").strip()
|
||||
if not raw:
|
||||
return default
|
||||
try:
|
||||
value = int(raw)
|
||||
except ValueError as exc:
|
||||
raise ValidationError(f"{name} must be an integer") from exc
|
||||
value = max(minimum, value)
|
||||
if maximum is not None:
|
||||
value = min(maximum, value)
|
||||
return value
|
||||
|
||||
# [STEP 1] 参数校验:status_group 白名单外 400(fail-closed)。
|
||||
status_group = (request.args.get("status_group") or "").strip()
|
||||
if status_group and status_group not in DOCUMENT_STATUS_GROUPS:
|
||||
@@ -387,8 +394,9 @@ def list_documents_api():
|
||||
)
|
||||
date_from = _parse_date("date_from")
|
||||
date_to = _parse_date("date_to")
|
||||
page = _parse_int("page", 1, minimum=1)
|
||||
page_size = _parse_int("page_size", 20, minimum=1, maximum=100)
|
||||
# 整数分页参数解析复用模块级 _parse_int_arg(2026-10-16 自本函数内嵌提升)。
|
||||
page = _parse_int_arg("page", 1, minimum=1)
|
||||
page_size = _parse_int_arg("page_size", 20, minimum=1, maximum=100)
|
||||
|
||||
# [STEP 2] 分组计数恒全量:GROUP BY status 对全部单统计,不受任何筛选影响。
|
||||
counts = dict(
|
||||
@@ -402,21 +410,21 @@ def list_documents_api():
|
||||
}
|
||||
|
||||
# [STEP 3] 列表查询:status_group / 时间窗仅作用列表;cancelled 恒不展示。
|
||||
# [2026-09-29 口径] 时间窗按收料日期过滤(receipt_date 为 ISO 日期字符串,
|
||||
# 字典序即时间序);排序与可调拨明细/结果卡统一:收料日期→数据源→库位升序,
|
||||
# [2026-09-29 口径] 时间窗按异动日期过滤(movement_date 为 ISO 日期字符串,
|
||||
# 字典序即时间序);排序与可调拨明细/结果卡统一:异动日期→数据源→库位升序,
|
||||
# created_at/id 兜底稳定分页(跨数据源不再按落库序乱序)。
|
||||
query = TransferDocument.query.filter(TransferDocument.status != "cancelled")
|
||||
if status_group:
|
||||
query = query.filter(TransferDocument.status.in_(DOCUMENT_STATUS_GROUPS[status_group]))
|
||||
if date_from:
|
||||
query = query.filter(TransferDocument.receipt_date >= date_from.isoformat())
|
||||
query = query.filter(TransferDocument.movement_date >= date_from.isoformat())
|
||||
if date_to:
|
||||
window_end = (date_to + timedelta(days=1)).isoformat()
|
||||
query = query.filter(TransferDocument.receipt_date < window_end)
|
||||
query = query.filter(TransferDocument.movement_date < window_end)
|
||||
total = query.count()
|
||||
docs = (
|
||||
query.order_by(
|
||||
TransferDocument.receipt_date.asc(),
|
||||
TransferDocument.movement_date.asc(),
|
||||
TransferDocument.source_code.asc(),
|
||||
TransferDocument.from_warehouse.asc(),
|
||||
TransferDocument.to_warehouse.asc(),
|
||||
@@ -609,10 +617,10 @@ def exceptions_excel_api(run_no: str):
|
||||
)
|
||||
|
||||
|
||||
@in_transit_transfer_bp.route("/runs/<run_no>/receipt-files", methods=["GET"])
|
||||
@in_transit_transfer_bp.route("/runs/<run_no>/inbound-files", methods=["GET"])
|
||||
@require_transfer_permission
|
||||
def receipt_files_api(run_no: str):
|
||||
"""下载本次收料来源文件(清单 + 原始行追溯,zip);记录访问审计。"""
|
||||
def inbound_files_api(run_no: str):
|
||||
"""下载本次入站来源文件(清单 + 原始行追溯,zip);记录访问审计。"""
|
||||
import io
|
||||
import json
|
||||
import zipfile
|
||||
@@ -635,7 +643,7 @@ def receipt_files_api(run_no: str):
|
||||
"business_date": run.business_date,
|
||||
**dict(file_snapshot.get(source_code) or {}),
|
||||
}
|
||||
archive.writestr(f"{source_code}-receipt-info.json", json.dumps(manifest, ensure_ascii=False, indent=2))
|
||||
archive.writestr(f"{source_code}-inbound-info.json", json.dumps(manifest, ensure_ascii=False, indent=2))
|
||||
rows = []
|
||||
for item in TransferInvoiceItem.query.filter_by(run_id=run.id).all():
|
||||
for line in (item.raw_lines_json or []):
|
||||
@@ -648,7 +656,7 @@ def receipt_files_api(run_no: str):
|
||||
|
||||
user = _require_user()
|
||||
db.session.add(build_transfer_audit_event(
|
||||
event_type="TRANSFER_RECEIPT_FILES_DOWNLOADED",
|
||||
event_type="TRANSFER_INBOUND_FILES_DOWNLOADED",
|
||||
aggregate_type="transfer_run",
|
||||
aggregate_id=run_no,
|
||||
run_no=run_no,
|
||||
@@ -663,7 +671,7 @@ def receipt_files_api(run_no: str):
|
||||
io.BytesIO(buffer.getvalue()),
|
||||
mimetype="application/zip",
|
||||
as_attachment=True,
|
||||
download_name=f"receipt-files-{run_no}.zip",
|
||||
download_name=f"inbound-files-{run_no}.zip",
|
||||
)
|
||||
|
||||
|
||||
@@ -680,12 +688,12 @@ def erp_inventory_api(run_no: str):
|
||||
run = TransferRun.query.filter_by(run_no=str(run_no).strip()).first()
|
||||
if run is None:
|
||||
raise NotFoundError("run not found", code="TRANSFER.RUN_NOT_FOUND")
|
||||
lines = ["invoice_no,source_code,material_no,from_warehouse,to_warehouse,receipt_quantity,external_quantity,result,external_document_no"]
|
||||
lines = ["invoice_no,source_code,material_no,from_warehouse,to_warehouse,movement_quantity,external_quantity,result,external_document_no"]
|
||||
for item in TransferInvoiceItem.query.filter_by(run_id=run.id).order_by(TransferInvoiceItem.invoice_no).all():
|
||||
lines.append(",".join([
|
||||
str(item.invoice_no), str(item.source_code), str(item.material_no),
|
||||
str(item.from_warehouse), str(item.to_warehouse),
|
||||
str(item.receipt_quantity), str(item.external_quantity or ""),
|
||||
str(item.movement_quantity), str(item.external_quantity or ""),
|
||||
str(item.result_code or item.status), str(item.external_document_no or ""),
|
||||
]))
|
||||
data = ("\n".join(lines) + "\n").encode("utf-8")
|
||||
@@ -749,7 +757,7 @@ def transfer_types_api():
|
||||
def transfer_sources_api():
|
||||
"""来源实例列表(决策 3:平台 DBS/Crane 仅分组,实例为执行边界)。
|
||||
|
||||
每来源附收料文件状态(ready/parse_failed/fetching/failed/expired/none + has_ready_file),
|
||||
每来源附入站文件状态(ready/parse_failed/fetching/failed/expired/none + has_ready_file),
|
||||
供前端门禁(无 ready 文件时禁止确认匹配)与状态标识;保留期已到或非当天
|
||||
(业务日)抓取且未清理均投影 expired。只读复用已启用库存来源。
|
||||
"""
|
||||
@@ -774,20 +782,20 @@ def transfer_sources_api():
|
||||
@in_transit_transfer_bp.route("/sources/<source_code>/retry-rpa", methods=["POST"])
|
||||
@require_transfer_permission
|
||||
def retry_source_rpa_api(source_code: str):
|
||||
"""对指定来源重新触发一次收料 RPA 抓取(复用货代收料 trigger 链路)。
|
||||
"""对指定来源重新触发一次入站 RPA 抓取(复用货代 ShippingReceiptReport trigger 链路,shipping_notice 域术语保留)。
|
||||
|
||||
【AI 触发时机】来源收料文件不可用需要恢复时调用:解析失败(parse_failed)先
|
||||
【AI 触发时机】来源入站文件不可用需要恢复时调用:解析失败(parse_failed)先
|
||||
本地重解析已归档文件;文件缺失/失效(none/expired/failed)才重新触发 RPA 抓取。
|
||||
|
||||
解析失败优先本地重解析(解析失败分层 2026-09-29):当日文件可用但解析失败时,
|
||||
先走 sync_and_commit_for_callback 重解析归档文件——成功且投影回 ready →
|
||||
200 {"source_code", "ok": true, "file_status": "ready", "reparsed": true}
|
||||
(不触发 RPA、不返回 202/fetching);仍失败 → 同结构 ok=false
|
||||
(file_status=parse_failed)。其余状态沿用原路径:重新触发一次收料 RPA,
|
||||
(file_status=parse_failed)。其余状态沿用原路径:重新触发一次入站 RPA,
|
||||
成功 202+fetching;配置缺失时 fail-closed(ok=False)。
|
||||
"""
|
||||
from app.services.in_transit_transfer.evidence_sync import sync_and_commit_for_callback
|
||||
from app.services.in_transit_transfer.receipt_trigger_service import trigger_receipt_rpa
|
||||
from app.services.in_transit_transfer.inbound_trigger_service import trigger_inbound_rpa
|
||||
from app.services.in_transit_transfer.source_file_status import resolve_source_file_status
|
||||
|
||||
source_code = str(source_code).strip()
|
||||
@@ -810,11 +818,11 @@ def retry_source_rpa_api(source_code: str):
|
||||
"reparsed": True,
|
||||
})
|
||||
|
||||
# [STEP 2] 其余状态沿用原路径:重新触发一次收料 RPA 抓取(202 + fetching)。
|
||||
outcome = trigger_receipt_rpa(
|
||||
# [STEP 2] 其余状态沿用原路径:重新触发一次入站 RPA 抓取(202 + fetching)。
|
||||
outcome = trigger_inbound_rpa(
|
||||
source_code=source_code,
|
||||
business_date=str(business_date_now()),
|
||||
reason="transfer_retry_receipt",
|
||||
reason="transfer_retry_inbound",
|
||||
)
|
||||
status = resolve_source_file_status(source_code=source_code)
|
||||
if not outcome.get("ok"):
|
||||
@@ -835,11 +843,11 @@ def retry_source_rpa_api(source_code: str):
|
||||
@in_transit_transfer_bp.route("/sources/retry-rpa-batch", methods=["POST"])
|
||||
@require_transfer_permission
|
||||
def retry_sources_rpa_batch_api():
|
||||
"""批量重试多来源收料 RPA:全部有效来源合并写**一个** batch trigger(一文件 N units)。
|
||||
"""批量重试多来源入站 RPA:全部有效来源合并写**一个** batch trigger(一文件 N units)。
|
||||
|
||||
【AI 触发时机】聊天侧「批量重试 RPA」按钮提交多个来源编码时调用;
|
||||
逐来源调用单来源端点会产生 N 个 trigger 文件,Worker 每文件开/关一次浏览器;
|
||||
合并单文件后 Worker 单次登录串行导出全部来源(与收料排程路径同效率)。
|
||||
合并单文件后 Worker 单次登录串行导出全部来源(与 ShippingReceiptReport RPA 排程路径同效率)。
|
||||
|
||||
请求体:{"source_codes": ["DSV360_AWSBI", ...]}。逐来源解析失败分层与
|
||||
fail-closed 语义同单来源端点;单源配置缺失跳过并记录,不阻断其余来源。
|
||||
@@ -848,12 +856,12 @@ def retry_sources_rpa_batch_api():
|
||||
source_codes = [str(code).strip() for code in (payload.get("source_codes") or []) if str(code).strip()]
|
||||
if not source_codes:
|
||||
raise ValidationError("source_codes is required")
|
||||
from app.services.in_transit_transfer.receipt_trigger_service import trigger_receipt_rpa_batch
|
||||
from app.services.in_transit_transfer.inbound_trigger_service import trigger_inbound_rpa_batch
|
||||
|
||||
outcome = trigger_receipt_rpa_batch(
|
||||
outcome = trigger_inbound_rpa_batch(
|
||||
source_codes=source_codes,
|
||||
business_date=str(business_date_now()),
|
||||
reason="transfer_retry_receipt",
|
||||
reason="transfer_retry_inbound",
|
||||
)
|
||||
return _ok(outcome)
|
||||
|
||||
@@ -861,12 +869,56 @@ def retry_sources_rpa_batch_api():
|
||||
@in_transit_transfer_bp.route("/backlog", methods=["GET"])
|
||||
@require_transfer_permission
|
||||
def backlog_api():
|
||||
"""待处理异常列表(可恢复/已关闭/结果未知 + 老化等级);查看记录访问审计。"""
|
||||
"""待处理异常列表(可恢复/已关闭/结果未知 + 老化等级);查看记录访问审计。
|
||||
|
||||
Query(全部可选;不带 page/page_size 时保持历史行为返回全量数组——向后兼容):
|
||||
page(默认 1);page_size(默认 20,上限 100)——任一提供即切换为
|
||||
分页 envelope {items, total, page, page_size}(2026-10-16 服务端分页:
|
||||
池为无界增长集合,千行级全量拉取放大载荷与老化查询规模);
|
||||
keyword(Invoice/料号/品名/来源 子串大小写不敏感,与前端池内筛选同字段集);
|
||||
result_filter ∈ {all, recoverable, closed, unknown}(缺省 all,白名单外 400)。
|
||||
注意:keyword/result_filter 仅在分页模式下生效(兼容模式下为历史行为,
|
||||
筛选参数被忽略——前端恒带分页参数,不受影响)。
|
||||
口径:total=筛选后全量计数(供前端分页器);排序与全量版同一业务稳定键;
|
||||
老化批量查询只对当前页行执行。审计 after.item_count 记录当前页行数。
|
||||
"""
|
||||
from app import db
|
||||
from app.services.in_transit_transfer.audit import build_transfer_audit_event
|
||||
from app.services.in_transit_transfer.backlog_service import list_backlog
|
||||
from app.services.in_transit_transfer.backlog_service import (
|
||||
RESULT_FILTER_CHOICES,
|
||||
BACKLOG_PAGE_DEFAULT,
|
||||
BACKLOG_PAGE_SIZE_DEFAULT,
|
||||
BACKLOG_PAGE_SIZE_MAX,
|
||||
list_backlog,
|
||||
list_backlog_page,
|
||||
)
|
||||
|
||||
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)}",
|
||||
)
|
||||
paginated = bool((request.args.get("page") or "").strip() or (request.args.get("page_size") or "").strip())
|
||||
|
||||
if paginated:
|
||||
page_data = list_backlog_page(
|
||||
keyword=keyword or None,
|
||||
result_filter=result_filter,
|
||||
page=_parse_int_arg("page", BACKLOG_PAGE_DEFAULT, minimum=1),
|
||||
page_size=_parse_int_arg("page_size", BACKLOG_PAGE_SIZE_DEFAULT, minimum=1, maximum=BACKLOG_PAGE_SIZE_MAX),
|
||||
)
|
||||
items = page_data.items
|
||||
payload: dict[str, Any] | list[dict[str, Any]] = {
|
||||
'items': [_serialize_backlog_item(item) for item in items],
|
||||
'total': page_data.total,
|
||||
'page': page_data.page,
|
||||
'page_size': page_data.page_size,
|
||||
}
|
||||
else:
|
||||
items = list_backlog()
|
||||
payload = [_serialize_backlog_item(item) for item in items]
|
||||
|
||||
items = list_backlog()
|
||||
user = _require_user()
|
||||
db.session.add(build_transfer_audit_event(
|
||||
event_type='TRANSFER_BACKLOG_VIEWED',
|
||||
@@ -880,7 +932,7 @@ def backlog_api():
|
||||
after={'item_count': len(items)},
|
||||
))
|
||||
db.session.commit()
|
||||
return _ok([_serialize_backlog_item(item) for item in items])
|
||||
return _ok(payload)
|
||||
|
||||
|
||||
@in_transit_transfer_bp.route("/backlog/summary", methods=["GET"])
|
||||
@@ -894,7 +946,7 @@ def backlog_summary_api():
|
||||
'recoverable': summary.recoverable_count,
|
||||
'closed': summary.closed_count,
|
||||
'unknown': summary.unknown_count,
|
||||
# 首页待办看板第 4 张数字卡(D16):已落档尚未匹配的外部收料记录数。
|
||||
# 首页待办看板第 4 张数字卡(D16):已落档尚未匹配的外部入站记录数。
|
||||
'pending_match': summary.pending_match_count,
|
||||
'aging': {
|
||||
'warn_3d': summary.warn_3d,
|
||||
@@ -908,9 +960,34 @@ def backlog_summary_api():
|
||||
@require_transfer_permission
|
||||
def backlog_pending_match_api():
|
||||
"""首页待办看板「待匹配」桶清单(D16 只读:启用类型范围并集内已落档、
|
||||
尚未被任何匹配圈定的外部收料记录;无 item_id——不可勾选执行,
|
||||
前端仅提供只读清单与「去匹配」引导)。"""
|
||||
from app.services.in_transit_transfer.backlog_service import list_pending_match_records
|
||||
尚未被任何匹配圈定的外部入站记录;无 item_id——不可勾选执行,
|
||||
前端仅提供只读清单与「去匹配」引导)。
|
||||
|
||||
Query(可选;不带 page/page_size 时保持历史行为返回全量数组——向后兼容):
|
||||
page(默认 1);page_size(默认 20,上限 100)——任一提供即切换为
|
||||
分页 envelope {records, total, page, page_size}(2026-10-16 服务端分页:
|
||||
桶为 951 行级大池,全量序列化/传输从 O(桶) 降到 O(页))。
|
||||
"""
|
||||
from app.services.in_transit_transfer.backlog_service import (
|
||||
BACKLOG_PAGE_DEFAULT,
|
||||
BACKLOG_PAGE_SIZE_DEFAULT,
|
||||
BACKLOG_PAGE_SIZE_MAX,
|
||||
list_pending_match_records,
|
||||
list_pending_match_records_page,
|
||||
)
|
||||
|
||||
paginated = bool((request.args.get("page") or "").strip() or (request.args.get("page_size") or "").strip())
|
||||
if paginated:
|
||||
page_data = list_pending_match_records_page(
|
||||
page=_parse_int_arg("page", BACKLOG_PAGE_DEFAULT, minimum=1),
|
||||
page_size=_parse_int_arg("page_size", BACKLOG_PAGE_SIZE_DEFAULT, minimum=1, maximum=BACKLOG_PAGE_SIZE_MAX),
|
||||
)
|
||||
return _ok({
|
||||
'records': [_serialize_pending_match_record(record) for record in page_data.records],
|
||||
'total': page_data.total,
|
||||
'page': page_data.page,
|
||||
'page_size': page_data.page_size,
|
||||
})
|
||||
|
||||
return _ok([
|
||||
_serialize_pending_match_record(record)
|
||||
@@ -931,6 +1008,60 @@ 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 语义)。
|
||||
响应 data:{files:[{archived_at,sha256,rows}], profile:{code,version}|None,
|
||||
clearable_rows, kept_rows}——语义见 backlog_reparse_service.preview_pending_match_reparse。
|
||||
"""
|
||||
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")
|
||||
return _ok(preview_pending_match_reparse(source_code=source_code, now=datetime.utcnow()))
|
||||
|
||||
|
||||
@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"};任一归档解析失败整体中止(TRANSFER.REPARSE_PARSE_FAILED,
|
||||
一行不删)。审计 TRANSFER_PENDING_MATCH_REPARSED 由 service 落库(含操作人)。
|
||||
响应 data:{source_code, cleared, reinserted, date_skipped, kept_unrebuildable,
|
||||
unlinked_items(R9 废弃引用解绑数), collapses(重落坍缩键数), files}。
|
||||
"""
|
||||
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")
|
||||
user = _require_user()
|
||||
outcome = reparse_pending_match(
|
||||
source_code=source_code,
|
||||
operator=str(getattr(user, "username", "") or user.id),
|
||||
now=datetime.utcnow(),
|
||||
)
|
||||
return _ok({
|
||||
"source_code": outcome.source_code,
|
||||
"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 {
|
||||
@@ -943,12 +1074,12 @@ def _serialize_backlog_item(item) -> dict[str, Any]:
|
||||
'age_days': item.age_days,
|
||||
'aging_level': item.aging_level,
|
||||
'last_attempt_at': item.last_attempt_at,
|
||||
'receipt_date': item.receipt_date,
|
||||
'movement_date': item.movement_date,
|
||||
'material_name': item.material_name,
|
||||
'from_warehouse': item.from_warehouse,
|
||||
'to_warehouse': item.to_warehouse,
|
||||
'lot_no': item.lot_no,
|
||||
'receipt_quantity': item.receipt_quantity,
|
||||
'movement_quantity': item.movement_quantity,
|
||||
'external_quantity': item.external_quantity,
|
||||
'result_code': item.result_code,
|
||||
}
|
||||
@@ -1359,9 +1359,10 @@ def workspace_shipping_task_line_inventory_file(task_no: str, inventory_file_no:
|
||||
path = Path(storage_path).resolve() if storage_path else None
|
||||
if inventory_file is None or not storage_path or storage_path.startswith('failed://') or not path.is_file():
|
||||
raise NotFoundError('Inventory file not found', code='SHIPPING.TASK_INVENTORY_FILE_NOT_FOUND')
|
||||
download_name = str(
|
||||
inventory_file.source_file_name or f'{inventory_file.inventory_file_no}{path.suffix or ".xlsx"}',
|
||||
).strip()
|
||||
from app.services.shipping_notice.inventory_file_store import build_inventory_download_name
|
||||
download_name = build_inventory_download_name(
|
||||
inventory_file, source_file_name=inventory_file.source_file_name, path=path,
|
||||
)
|
||||
from app.services.shipping_notice.fulfillment_audit import record_access_audit
|
||||
record_access_audit(
|
||||
action='download_task_line_inventory_file',
|
||||
|
||||
Reference in new issue
Block a user