feat(shipping-notice): 新增通用解析能力,优化性能并清理遗留废弃代码

This commit is contained in:
hugo committed 2026-08-23 00:27:18 +08:00
1 parent 935bf26fa6
commit 7cfd5d167e
230 files changed
+9337 -10989

No files matched your search

+3
View File
@@ -283,6 +283,8 @@
- 历史口径曾写“一封 EML = 一个 Intake”;该语义保留为 EML Intake 规则,并扩展直接 PDF Intake。上传阶段只做快览:读取邮件头、正文白名单 HTML 表格快照和附件目录,不抽取附件全文、不创建附件 Document/派生资产、不调度 MinerU/OCR。订单抽取已切换为独立 Run:点击发送直接创建后台作业并轮询 Run/投影状态,不再把 `shipping_intake_nos` 发送给普通 Chatflow;普通无附件问答仍走聊天 SSE。
- 一个附件可包含多个订单,一个订单也可跨正文/多个附件;按实际业务订单生成 Candidate,不按附件数量机械拆分。EML 多 PDF 时每个 PDF 独立 Candidate,禁止跨 PDF 拼行。
- 正文与附件由 HXOPS 的确定性关系规则关联并统一裁决;**有主 PDF 时当前值按 PDF 优先**(见上节);`part_number`/Qty 必须保留原文 evidence,不确定字段返回空值,关键字段冲突必须阻断自动建单。订单抽取主链不调用 Dify。
- 邮件正文补充字段冲突必须可解释并可恢复:新 Finding 固定携带字段/行、双方原值与规范化值、文档/证据引用、严重度和处理状态;金额等字段按 Schema 语义比较,明细按精确 `PO + MPN` 对齐。历史无双方证据的旧冲突不得按空 Case 投影放行,管理员重评估冻结输入后仅清除格式等价假冲突;无法恢复证据时保持阻断并引导重新识别当前 PDF。
- Draft「保存并校验」必须由后端统一恢复协调器完成资格、Gate 和幂等自动建单入队;前端只显示 `resume_outcome`,不自行推导流程。入队/已排队/运行中均须明确提示,Worker 实际状态以后端处理投影为准。
- 判重以 Candidate 为业务粒度:附件 hash 判断相同文件,业务身份指纹判断同一订单,内容指纹区分完全重复与订单修订。
- 迁移前高置信 Candidate 可自动创建 Batch/Task;订单人工复核目标态切换后,任何 PDF 均必须由对应 Review Case 使用指定草稿版本确认,才可创建 Task。Reservation ID 缺失仍是硬门禁;`inventory_source_hint` 是可选库存源路由线索,不作为必填门禁。
- 低置信、证据不足、阻断冲突或可能修订的 Candidate 保留待处理;同 Intake 已自动建单部分不得导致剩余 Candidate 丢失。
@@ -290,6 +292,7 @@
- 订单附件结构化必须支持版本化订单坐标 Profile v2。模板真相为静态文档锚点、表区相对坐标、独立表头布局、明细物理行布局、字段区域到稳定 `field_id + field_code` 的绑定、注册解析器、跨页/终止规则;表头文字只能用于建议、校准和匹配,不能决定最终字段。已发布版本不可原地修改,同模板发布新版本时原子退役旧版本;Run 必须复制完整 published Profile,不能只保存当前 Profile ID。
- **XFA 客户采购订单(PO)统一解析(2026-08-18)**:普通 PDF 与 XFA 共用同一编辑、自动标注、保存、验证、发布和运行时解析主链。`/XFA datasets + 拆分规则`是 XFA 的首选正式值源;datasets 缺失、受限、Profile/结构不匹配、规则或对账失败时,必须继续进入普通 PDF 共用的 PDFium 原生坐标/OCR 证据链。AcroForm Widget 同时作为统一画布的视觉绑定和自动标注证据。每个 observation 记录 `value_source` 与坐标/引文证据;PDF 证据不得伪装为 datasets。回退结果可创建候选供人工复核,但固定 `needs_review`、禁止 CQ/STP 自动建单;低置信、证据不足或冲突同样不得静默建单。Dify 不参与解析主链。
- **XFA 统一视觉标注、字段拆分与精确解析**:页面画框、自动标注 Job、保存、验证、发布与普通 PDF 使用同一入口和 DTO;服务端仅按已持久化 Profile 能力选择 datasets 或 PDF 证据适配器。XFA `value_binding.type=xfa_dataset` 保持为首选配置,不把 OCR 固化成主映射;确认后的 `visual_binding` 用于定位、复核和审计。拆分优先级固定 `prefix > regex > position > unmatched`,冲突进入 `needs_review`;正则优先 RE2。
- **PDF 订单解析证据链收口(2026-08-21)**:原 PDF 是不可变事实;固定 `matching_features.v1` 仅提供稳定版式匹配输入,坐标统一按当前 Layout、快照补缺、原 PDF、OCR 的顺序按需恢复。Profile 只负责版式,Schema 是唯一字段契约,订单头/订单行共用受限几何变换和字段证据。关键证据缺失、模板歧义/漂移、变换异常、XFA/OCR 冲突均必须进入 Review;自动标注仅辅助 Draft,生产通用解析必须冻结 Parse Plan,Dify 不参与主链或自动建单。
- **XFA 字段拆分映射(历史增量,已由统一方案接管)**:早期曾落地多阶段 `stages[]` 流水线与独立 XFA 映射页。统一方案冻结后,拆分语义以 `prefix > regex > position > unmatched` 为准,工作台并入统一画框编辑器;历史契约文档 [xfa-field-split-mapping.md](features/shipping-notice/xfa-field-split-mapping.md) 仅作迁移对照,不再作为新开发权威。
- 业务管理员必须通过受控样本页面维护订单坐标 Profile:可配置相对区域、静态锚点、独立表头/明细布局和注册解析器;不得编辑 HTML、原始 bbox、JSON、正则、脚本、Prompt 或结构指纹。草稿更新使用乐观锁;每个明细字段区域必须绑定 Schema 允许的 `pdf_coordinate`/`ocr_coordinate` 来源和最低证据等级;不可变版本可复制为新草稿或退役。
- Profile 治理必须保存模板模式、训练样本计数和不含锚点正文的匹配策略摘要;训练/标注样本、盲测样本及其增删、草稿保存、区域/字段绑定变化、测试执行/批准、发布和退役均追加审计。样本文档被训练或盲测引用后不得删除;审计不得保存 PDF、HTML、对象存储地址、正文或凭据。
@@ -12,14 +12,18 @@
<style>
:root { --canvas:#f8fafc; --surface:#fff; --surface-soft:#f5f8fc; --line:#e5eaf1; --ink:#182230; --text:#4d5d73; --muted:#8491a5; --brand:#1677d2; --brand-50:#edf6ff; --good:#18854d; --good-50:#ecf9f0; --warn:#b7730d; --warn-50:#fff7e7; --bad:#c63d53; --bad-50:#fff0f2; --shadow:0 10px 28px rgba(21,39,66,.07); }
*{box-sizing:border-box} html,body,#app{width:100%;height:100%;margin:0} #app{display:flex;min-width:0;overflow:hidden} body{font:14px/1.5 "Microsoft YaHei","PingFang SC",Arial,sans-serif;color:var(--text);background:var(--canvas)} button,input,select{font:inherit} button{cursor:pointer} button:focus-visible,input:focus-visible,select:focus-visible{outline:3px solid rgba(22,119,210,.22);outline-offset:2px}
.shell{display:flex;width:100%;height:100%;min-width:0;overflow:hidden}.side{display:flex;flex:0 0 244px;width:244px;min-width:244px;max-width:244px;flex-direction:column;overflow:hidden;background:var(--surface);border-right:1px solid var(--line)}.brand{display:flex;align-items:center;gap:10px;height:64px;padding:0 18px;border-bottom:1px solid var(--line)}.brand-mark{display:grid;place-items:center;width:32px;height:32px;border-radius:9px;background:linear-gradient(135deg,#208add,#2368c9);color:#fff;font-size:12px;font-weight:800}.brand b{display:block;color:var(--ink);font-size:15px}.brand span{display:block;color:var(--muted);font-size:11px}.new-chat{margin:14px;border:1px solid #bfdbf6;border-radius:9px;padding:9px 12px;text-align:left;color:#1265af;background:var(--brand-50);font-weight:700}.nav-label{padding:9px 17px 5px;color:#96a2b3;font-size:10px;font-weight:800;letter-spacing:.08em}.history{min-height:0;padding:0 9px;overflow:auto}.history button{position:relative;width:100%;border:0;border-radius:8px;padding:9px 10px;background:transparent;color:var(--text);text-align:left}.history button:hover{background:var(--surface-soft)}.history button.active{color:#1469b4;background:var(--brand-50)}.history b,.history span{display:block;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.history b{font-size:12px}.history span{margin-top:2px;color:var(--muted);font-size:10px}.dot{position:absolute;top:11px;right:10px;width:7px;height:7px;border-radius:50%;background:#ed9a2c}.dot.bad{background:#d64d61}.user{display:flex;gap:8px;align-items:center;margin-top:auto;padding:14px 17px;border-top:1px solid var(--line)}.avatar{display:grid;place-items:center;width:30px;height:30px;border-radius:50%;color:#1269b3;background:#dff1ff;font-size:11px;font-weight:800}.user b,.user span{display:block}.user b{color:var(--ink);font-size:11px}.user span{color:var(--muted);font-size:10px}
.shell{display:flex;width:100%;height:100%;min-width:0;overflow:hidden}.side{display:flex;flex:0 0 244px;width:244px;min-width:244px;max-width:244px;flex-direction:column;overflow:hidden;background:var(--surface);border-right:1px solid var(--line)}.brand{display:flex;align-items:center;gap:10px;height:64px;padding:0 18px;border-bottom:1px solid var(--line)}.brand-mark{display:grid;place-items:center;width:32px;height:32px;border-radius:9px;background:linear-gradient(135deg,#208add,#2368c9);color:#fff;font-size:12px;font-weight:800}.brand b{display:block;color:var(--ink);font-size:15px}.brand span{display:block;color:var(--muted);font-size:11px}.new-chat{margin:14px;border:1px solid #bfdbf6;border-radius:9px;padding:9px 12px;text-align:left;color:#1265af;background:var(--brand-50);font-weight:700}.nav-label{padding:9px 17px 5px;color:#96a2b3;font-size:10px;font-weight:800;letter-spacing:.08em}.history{min-height:0;padding:0 9px;overflow:auto}.history button{position:relative;width:100%;border:0;border-radius:8px;padding:9px 10px;background:transparent;color:var(--text);text-align:left}.history button:hover{background:var(--surface-soft)}.history button.active{color:#1469b4;background:var(--brand-50)}.history b,.history span{display:block;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.history b{font-size:12px}.history span{margin-top:2px;color:var(--muted);font-size:10px}.history-divider{height:1px;margin:8px 8px 4px;background:var(--line)}.history-label{padding:5px 10px 3px;color:#96a2b3;font-size:10px;font-weight:800;letter-spacing:.05em}.history button.walkthrough b{font-weight:600}.history button.walkthrough span{color:#8797ab}.dot{position:absolute;top:11px;right:10px;width:7px;height:7px;border-radius:50%;background:#ed9a2c}.dot.bad{background:#d64d61}.user{display:flex;gap:8px;align-items:center;margin-top:auto;padding:14px 17px;border-top:1px solid var(--line)}.avatar{display:grid;place-items:center;width:30px;height:30px;border-radius:50%;color:#1269b3;background:#dff1ff;font-size:11px;font-weight:800}.user b,.user span{display:block}.user b{color:var(--ink);font-size:11px}.user span{color:var(--muted);font-size:10px}
.main{display:flex;min-width:0;min-height:0;flex:1 1 auto;flex-direction:column;overflow:hidden}.topbar{height:64px;display:flex;align-items:center;gap:10px;padding:0 28px;background:var(--surface);border-bottom:1px solid var(--line)}.agent-icon{display:grid;place-items:center;width:32px;height:32px;border-radius:9px;color:var(--brand);background:var(--brand-50);font-weight:800}.title b{display:block;color:var(--ink);font-size:14px}.title span{display:block;margin-top:1px;color:var(--muted);font-size:11px}.crumb{margin-left:auto;color:var(--muted);font-size:12px}.layout{min-height:0;flex:1;overflow:auto}.page{width:min(1160px,100%);margin:0 auto;padding:28px}.page-head{display:flex;align-items:flex-start;justify-content:space-between;gap:18px;margin-bottom:18px}.page-head h1{margin:0;color:var(--ink);font-size:22px}.page-head p{max-width:720px;margin:5px 0 0;color:var(--muted);font-size:13px}.back{border:0;background:transparent;color:#176fba;font-weight:700}.card{border:1px solid var(--line);border-radius:12px;background:var(--surface);box-shadow:var(--shadow)}.card-h{display:flex;align-items:center;justify-content:space-between;gap:12px;padding:15px 18px;border-bottom:1px solid var(--line)}.card-h h2{margin:0;color:var(--ink);font-size:15px}.card-h p{margin:3px 0 0;color:var(--muted);font-size:11px}.card-b{padding:18px}.grid{display:grid;gap:16px}.grid.two{grid-template-columns:1.55fr 1fr}.summary{display:grid;grid-template-columns:repeat(4,1fr);gap:12px}.metric{padding:13px;border:1px solid var(--line);border-radius:10px;background:#fff}.metric b{display:block;color:var(--ink);font-size:20px}.metric span{display:block;margin-top:3px;color:var(--muted);font-size:11px}.metric button{border:0;padding:0;background:transparent;color:inherit;text-align:left}.metric.action{border-color:#cfe5f9;background:var(--brand-50)}.metric.action b{color:#1268b2}.notice{display:flex;gap:9px;margin-top:14px;border-radius:8px;padding:10px 12px;color:#596b82;background:var(--surface-soft);font-size:12px}.notice i{font-style:normal;font-weight:800}.notice.good{color:#167642;background:var(--good-50)}.notice.warn{color:#97620c;background:var(--warn-50)}.notice.bad{color:#ae3146;background:var(--bad-50)}.btn{border:1px solid #d1dbe7;border-radius:8px;padding:8px 12px;color:#43536a;background:#fff;font-size:12px;font-weight:700}.btn:hover{background:var(--surface-soft)}.btn.primary{border-color:var(--brand);color:#fff;background:var(--brand)}.btn.danger{border-color:#efb9c2;color:#b43449;background:var(--bad-50)}.btn[disabled]{cursor:not-allowed;opacity:.48}.actions{display:flex;flex-wrap:wrap;gap:8px;margin-top:14px}.chip{display:inline-flex;align-items:center;border-radius:999px;padding:3px 8px;font-size:11px;font-weight:700}.chip.good{color:#147340;background:var(--good-50)}.chip.warn{color:#9a640c;background:var(--warn-50)}.chip.bad{color:#ad3145;background:var(--bad-50)}.chip.gray{color:#68788e;background:#eff3f7}.chat-panel{min-height:370px;display:flex;flex-direction:column}.chat-messages{flex:1;padding:18px}.bubble{max-width:88%;margin-bottom:13px;border:1px solid var(--line);border-radius:4px 12px 12px;padding:10px 12px;color:var(--text);background:#fff;font-size:13px}.bubble.user-msg{margin-left:auto;border-color:var(--brand);border-radius:12px 4px 12px 12px;color:#fff;background:var(--brand)}.composer{display:flex;gap:8px;padding:12px;border-top:1px solid var(--line)}.composer input{min-width:0;flex:1;border:1px solid #d4dee9;border-radius:8px;padding:9px 11px}.quick{display:grid;gap:8px}.quick button{border:1px solid var(--line);border-radius:8px;padding:10px;color:#53637a;background:#fff;text-align:left;font-size:12px}.quick button:hover{border-color:#bfdcf7;color:#1267b1;background:var(--brand-50)}
.scope{display:flex;justify-content:space-between;gap:16px;align-items:center;padding:14px;border:1px solid #d7e9fa;border-radius:10px;background:#f5faff}.scope b{display:block;color:#145f9f}.scope span{display:block;margin-top:2px;color:#60748c;font-size:12px}.source-toolbar{display:flex;gap:10px;align-items:center;margin-bottom:13px}.source-toolbar input{width:280px;border:1px solid #d4dee9;border-radius:8px;padding:8px 10px}.source-toolbar .count{margin-left:auto;color:var(--muted);font-size:12px}.source-group{border:1px solid var(--line);border-radius:10px;overflow:hidden;margin-top:10px}.source-group-head{display:flex;align-items:center;gap:10px;padding:12px 13px;background:#fbfcfe}.source-group-head b{color:var(--ink)}.source-group-head span{color:var(--muted);font-size:11px}.source-group-head button{margin-left:auto;border:0;color:#176fba;background:transparent;font-size:12px}.source-list{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));border-top:1px solid var(--line)}.source-item{display:flex;align-items:center;gap:9px;min-height:54px;padding:10px 13px;border-right:1px solid var(--line);border-bottom:1px solid var(--line)}.source-item:nth-child(even){border-right:0}.source-item:last-child{border-bottom:0}.source-item b{display:block;color:var(--ink);font-size:12px}.source-item span{display:block;color:var(--muted);font-size:11px}.sticky-actions{position:sticky;bottom:0;display:flex;justify-content:flex-end;gap:8px;margin:18px -18px -18px;padding:13px 18px;border-top:1px solid var(--line);background:rgba(255,255,255,.96)}
.stage-list{display:grid;gap:10px}.stage{display:grid;grid-template-columns:14px 1fr auto;gap:10px;align-items:start;padding:12px;border:1px solid var(--line);border-radius:9px}.stage .mark{width:10px;height:10px;margin-top:4px;border-radius:50%;background:#a8b3c1}.stage.good .mark{background:var(--good)}.stage.warn .mark{background:#e1a238}.stage.bad .mark{background:var(--bad)}.stage b{display:block;color:var(--ink);font-size:12px}.stage span{display:block;margin-top:2px;color:var(--muted);font-size:11px}.facts{display:grid;grid-template-columns:repeat(3,1fr);gap:0;border:1px solid var(--line);border-radius:9px;overflow:hidden}.fact{padding:10px 12px;border-right:1px solid var(--line);border-bottom:1px solid var(--line)}.fact:nth-child(3n){border-right:0}.fact:nth-last-child(-n+3){border-bottom:0}.fact span{display:block;color:var(--muted);font-size:10px}.fact b{display:block;margin-top:3px;color:var(--ink);font-size:12px}.table-wrap{overflow:auto}.table{width:100%;border-collapse:collapse;font-size:12px}.table th,.table td{padding:11px 10px;border-bottom:1px solid var(--line);text-align:left;vertical-align:middle}.table th{color:#7d8ba0;background:#fafbfd;font-size:11px;font-weight:700}.table td b{color:var(--ink)}.table tr.disabled{color:#8693a4;background:#fbfcfe}.link{border:0;padding:0;color:#146fba;background:transparent;font-weight:700}.confirm-band{display:flex;justify-content:space-between;align-items:center;gap:14px;margin-top:13px;border:1px solid #d3e8f9;border-radius:9px;padding:12px;background:#f5faff}.confirm-band b{color:#155f9f}.route-org{margin-top:12px;border:1px solid var(--line);border-radius:10px;background:#fff;overflow:hidden}.route-org>summary,.route-item>summary{display:flex;align-items:center;gap:12px;list-style:none;cursor:pointer}.route-org>summary::-webkit-details-marker,.route-item>summary::-webkit-details-marker{display:none}.route-org>summary{padding:14px 16px;background:#fbfcfe}.route-org>summary::before,.route-item>summary::before{content:'›';width:16px;color:#6d7d91;font-size:20px;line-height:1;transition:transform .15s}.route-org[open]>summary::before,.route-item[open]>summary::before{transform:rotate(90deg)}.route-org-title{min-width:0;flex:1}.route-org-title b{display:block;color:var(--ink);font-size:14px}.route-org-title span{display:block;margin-top:2px;color:var(--muted);font-size:11px}.route-org-metrics{display:flex;gap:14px;color:#52637a;font-size:12px}.route-org-metrics b{color:var(--ink)}.route-table{border-top:1px solid var(--line)}.route-item{border-bottom:1px solid var(--line)}.route-item:last-child{border-bottom:0}.route-item>summary{padding:11px 16px}.route-item>summary:hover{background:var(--surface-soft)}.route-item-main{min-width:0;flex:1}.route-item-main b{color:var(--ink)}.route-item-main span{margin-left:8px;color:var(--muted);font-size:11px}.route-item-metrics{display:flex;gap:18px;color:#52637a;font-size:12px}.route-item-metrics strong{color:var(--ink)}.route-invoices{padding:0 16px 14px 44px;background:#fcfdff}.tabs{display:flex;gap:5px;border-bottom:1px solid var(--line);margin-bottom:14px}.tab{border:0;border-bottom:2px solid transparent;padding:9px 11px;color:#718097;background:transparent;font-size:12px;font-weight:700}.tab.active{border-color:var(--brand);color:#146bb4}.filters{display:flex;gap:8px;margin-bottom:12px}.filters select{border:1px solid #d5dfe9;border-radius:7px;padding:7px 9px;color:var(--text);background:#fff}.progress{height:7px;border-radius:999px;background:#eaf0f6;overflow:hidden}.progress i{display:block;height:100%;border-radius:inherit;background:var(--brand)}
.toast{position:fixed;right:24px;bottom:24px;z-index:20;max-width:380px;border-radius:9px;padding:11px 14px;color:#fff;background:#253c57;box-shadow:0 12px 30px rgba(20,37,60,.23);font-size:12px;opacity:0;transform:translateY(12px);pointer-events:none;transition:.18s}.toast.show{opacity:1;transform:translateY(0)}.overlay{position:fixed;inset:0;z-index:10;display:none;align-items:center;justify-content:center;padding:20px;background:rgba(19,32,49,.38)}.overlay.show{display:flex}.modal{width:min(480px,100%);border-radius:12px;background:#fff;box-shadow:0 24px 60px rgba(20,37,60,.28)}.modal h2{margin:0;padding:17px 18px 10px;color:var(--ink);font-size:16px}.modal p{margin:0;padding:0 18px;color:var(--muted);font-size:12px}.modal .body{padding:16px 18px}.modal input{width:100%;border:1px solid #d4dee9;border-radius:8px;padding:9px 10px}.modal .footer{display:flex;justify-content:flex-end;gap:8px;padding:12px 18px;border-top:1px solid var(--line)}
/* Chat 首页复用 HXOPS 真实 Chat 壳层:无业务顶栏、消息列居中、输入容器贴近底部。 */
.chat-mode .topbar{display:none}.chat-mode .main{background:var(--surface)}.chat-mode .layout{overflow:hidden}.chat-mode .side{flex-basis:320px;width:320px;max-width:320px}.chat-mode .page{width:100%;height:100%;max-width:none;margin:0;padding:0 24px}.chat-home{display:flex;height:100%;min-height:0;flex-direction:column;align-items:center}.chat-home-head{width:100%;max-width:780px;padding:38px 0 12px;text-align:center}.chat-home-head .welcome-mark{display:grid;place-items:center;width:46px;height:46px;margin:0 auto 14px;border-radius:50%;color:#fff;background:linear-gradient(135deg,#2f80d1,#1f65b0);font-weight:800;box-shadow:0 8px 22px rgba(47,128,209,.22)}.chat-home-head h1{margin:0;color:#0f172a;font-size:28px;line-height:1.25}.chat-home-head h1 span{color:#2f80d1}.chat-home-head p{margin:9px auto 0;max-width:650px;color:#64748b;font-size:13px}.chat-scenarios{display:flex;width:100%;max-width:860px;gap:8px;overflow-x:auto;padding:6px 0 14px;scrollbar-width:none}.chat-scenarios::-webkit-scrollbar{display:none}.chat-scenarios .tab{flex:0 0 auto;border:1px solid #e2e8f0;border-bottom:1px solid #e2e8f0;border-radius:999px;padding:8px 13px;color:#475569;background:#fff;font-size:12px;font-weight:600;white-space:nowrap}.chat-scenarios .tab.active{border-color:#9cc7f2;color:#1f5f99;background:#eef6ff}.chat-thread{width:100%;max-width:780px;min-height:0;flex:1;overflow:auto;padding:12px 0 150px}.chat-thread .bubble{max-width:82%;border-radius:14px;background:#fff;box-shadow:0 2px 8px rgba(15,23,42,.04)}.chat-thread .bubble.user-msg{border:0;border-radius:14px 5px 14px 14px;background:#2f80d1;box-shadow:none}.chat-thread .scope{border-color:#cfe5f9;border-radius:14px;background:#f8fbff}.chat-thread .notice{border-radius:12px}.chat-action{display:flex;justify-content:flex-end;margin-top:10px}.chat-input-wrap{position:fixed;right:0;bottom:0;left:320px;z-index:4;padding:12px 24px 18px;background:linear-gradient(transparent,rgba(255,255,255,.96) 22%)}.chat-input{display:flex;align-items:flex-end;gap:8px;width:min(780px,100%);margin:0 auto;border:1px solid #d8e0ec;border-radius:16px;padding:9px 10px;background:#fff;box-shadow:0 8px 28px rgba(15,23,42,.10)}.chat-input input{min-width:0;flex:1;border:0;outline:0;padding:9px 8px;color:#0f172a;background:transparent;font-size:15px}.chat-input button{display:grid;place-items:center;width:38px;height:38px;border:0;border-radius:50%;color:#fff;background:#2f80d1;font-weight:700}.chat-input-hint{width:min(780px,100%);margin:7px auto 0;text-align:center;color:#94a3b8;font-size:10px}
@media(max-width:800px){body{font-size:13px}#app{display:block;height:auto;min-height:100%;overflow:auto}.shell{display:block;overflow:auto}.side{display:none}.main{min-height:100%;overflow:visible}.topbar{padding:0 16px}.crumb{display:none}.page{padding:17px}.grid.two{grid-template-columns:1fr}.summary{grid-template-columns:repeat(2,1fr)}.page-head{display:block}.page-head .back{margin-bottom:8px}.source-toolbar{flex-wrap:wrap}.source-toolbar input{width:100%}.source-toolbar .count{margin-left:0}.source-list{grid-template-columns:1fr}.source-item{border-right:0}.facts{grid-template-columns:1fr}.fact{border-right:0}.fact:nth-last-child(-n+3){border-bottom:1px solid var(--line)}.fact:last-child{border-bottom:0}.confirm-band{display:block}.confirm-band .actions{margin-top:10px}.table{min-width:650px}.chat-mode .page{padding:0 14px}.chat-home-head{padding-top:25px}.chat-home-head h1{font-size:23px}.chat-input-wrap{left:0;padding:10px 12px 14px}.chat-thread{padding-bottom:140px}.chat-thread .bubble{max-width:92%}}
/* Chat 首页对齐当前 HXOPS Chat:深色画布、56px 顶栏、抽屉式历史记录与底部双行输入区。 */
.chat-mode{background:#020617;color:#cbd5e1}.chat-mode #app{background:#020617}.chat-mode .main{background:#020617}.chat-mode .topbar{display:flex;height:56px;gap:9px;padding:0 16px;border-color:#1e293b;background:#020617}.chat-mode .agent-icon{width:28px;height:28px;border-radius:8px;color:#e0f2fe;background:#2582ca;font-size:11px}.chat-mode .title{display:flex;align-items:center;gap:10px}.chat-mode .title b{color:#f8fafc;font-size:14px}.chat-mode .title span{display:none}.chat-mode .crumb{margin-left:0;border:1px solid #7dd3fc;border-radius:8px;padding:5px 10px;color:#0369a1;background:#e0f2fe;font-size:12px;font-weight:700}.chat-mode .chat-nav-actions{display:flex;align-items:center;gap:8px;margin-left:auto}.chat-mode .chat-nav-actions button{display:grid;place-items:center;width:32px;height:32px;border:0;border-radius:8px;color:#94a3b8;background:transparent;font-size:18px}.chat-mode .chat-nav-actions button:hover{color:#e2e8f0;background:#0f172a}.chat-mode .layout{overflow:hidden}.chat-mode .page{width:100%;height:100%;max-width:none;margin:0;padding:0}.chat-mode .side{position:fixed;top:0;bottom:0;left:0;z-index:30;display:flex;flex:0 0 296px;width:296px;min-width:296px;max-width:296px;transform:translateX(-100%);border-color:#1e293b;background:#0f172a;box-shadow:18px 0 44px rgba(0,0,0,.38);transition:transform .2s ease}.chat-mode.history-open .side{transform:translateX(0)}.chat-mode .brand{height:56px;border-color:#1e293b;padding:0 16px}.chat-mode .brand-mark{width:28px;height:28px;border-radius:8px;background:#2582ca;font-size:11px}.chat-mode .brand b{color:#f8fafc;font-size:14px}.chat-mode .brand span{color:#64748b}.chat-mode .new-chat{margin:12px;border-color:#1d4f78;border-radius:8px;color:#bae6fd;background:#082f49}.chat-mode .nav-label,.chat-mode .history-label{color:#64748b}.chat-mode .history-divider{background:#1e293b}.chat-mode .history button{color:#cbd5e1}.chat-mode .history button:hover{background:#172554}.chat-mode .history button.active{color:#e0f2fe;background:#0c4a6e}.chat-mode .history span{color:#64748b}.chat-mode .user{border-color:#1e293b}.chat-mode .user b{color:#e2e8f0}.chat-mode .user span{color:#64748b}.chat-mode .avatar{color:#bae6fd;background:#164e63}.chat-home{display:flex;height:100%;min-height:0;flex-direction:column;align-items:center}.chat-home-head{width:100%;max-width:920px;padding:67px 20px 17px;text-align:center}.chat-home-head .welcome-mark{display:none}.chat-home-head h1{margin:0;color:#f8fafc;font-size:29px;line-height:1.3}.chat-home-head h1 span{margin-left:6px;color:#7dd3fc}.chat-home-head p{display:none}.chat-todo-section{width:100%;max-width:760px;padding:0 16px 12px}.chat-todo-label{margin:0 0 8px;color:#94a3b8;font-size:12px;font-weight:700}.chat-today{display:flex;justify-content:center}.today-item{display:flex;align-items:center;gap:9px;width:auto;max-width:100%;border:1px solid #334155;border-radius:999px;padding:9px 14px;color:#cbd5e1;background:#0f172a;text-align:left}.today-item:hover{border-color:#7dd3fc;color:#e0f2fe;background:#172554}.today-item .today-icon{display:grid;place-items:center;width:18px;height:18px;flex:0 0 18px;border-radius:50%;color:#0c4a6e;background:#7dd3fc;font-size:15px;line-height:1}.today-item b{display:inline;color:inherit;font-size:13px}.today-item span{display:inline;margin:0;color:#94a3b8;font-size:12px}.today-item span span{display:none}.today-item .today-go{display:none}.chat-pending{display:flex;justify-content:center;gap:8px}.pending-item{display:flex;align-items:center;gap:6px;min-width:0;width:auto;border:1px solid #334155;border-radius:999px;padding:8px 12px;color:#cbd5e1;background:#0f172a;text-align:left}.pending-item:hover{border-color:#64748b;background:#172554}.pending-item.primary{border-color:#2c5572;background:#082f49}.pending-item b{display:inline;color:inherit;font-size:12px}.pending-item.primary b{color:#bae6fd}.pending-item span{display:none}.pending-item .pending-count{display:inline;margin:0;color:#7dd3fc;font-size:12px}.pending-item.warning .pending-count{color:#fbbf24}.pending-item.muted .pending-count{color:#94a3b8}.chat-thread{width:100%;max-width:760px;min-height:0;flex:1;overflow:auto;padding:36px 16px 154px}.chat-thread .bubble{max-width:82%;border:1px solid #1e293b;border-radius:6px 14px 14px;padding:11px 13px;color:#cbd5e1;background:#0f172a;box-shadow:none}.chat-thread .bubble.user-msg{margin-left:auto;border:0;border-radius:14px 5px 14px 14px;color:#eff6ff;background:#075985}.chat-thread .scope{border-color:#1e3a5f;border-radius:10px;color:#cbd5e1;background:#0b1327}.chat-thread .scope b{color:#bae6fd}.chat-thread .scope span{color:#94a3b8}.chat-thread .notice{border-radius:10px;color:#fcd34d;background:#2a1d05}.chat-action .btn{border-color:#0369a1;color:#e0f2fe;background:#075985}.chat-input-wrap{position:fixed;right:0;bottom:0;left:0;z-index:4;padding:0 14px 8px;background:#020617}.chat-input{display:block;width:min(760px,100%);margin:0 auto;border:0;border-radius:0;padding:0;backLine truncated
/* 当前浏览器的浅色 Chat 基线:常驻会话栏、无业务顶栏、居中欢迎区和底部输入容器。 */
.chat-mode{color:#334155;background:#fff}.chat-mode #app{background:#fff}.chat-mode .main{background:#fff}.chat-mode .topbar{display:none}.chat-mode .layout{overflow:hidden}.chat-mode .page{width:100%;height:100%;max-width:none;margin:0;padding:0}.chat-mode .side{position:static;z-index:auto;display:flex;flex:0 0 300px;width:300px;min-width:300px;max-width:300px;transform:none;border-color:#dbe7ef;background:#fff;box-shadow:none;transition:none}.chat-mode.history-open .side{transform:none}.chat-mode .brand{height:72px;border:0;padding:16px}.chat-mode .brand-mark{width:34px;height:34px;border-radius:10px;background:#3187cf;font-size:12px}.chat-mode .brand b{color:#0f172a;font-size:15px}.chat-mode .brand span{color:#94a3b8}.chat-mode .new-chat{margin:10px 16px 18px;border-color:#e2e8f0;border-radius:10px;padding:11px 12px;color:#334155;background:#f8fafc;box-shadow:0 2px 8px rgba(15,23,42,.04)}.chat-mode .nav-label,.chat-mode .history-label{padding-left:16px;color:#64748b;font-size:12px;letter-spacing:0}.chat-mode .history-divider{margin:10px 16px 6px;background:#e2e8f0}.chat-mode .history{padding:0 9px}.chat-mode .history button{padding:9px 10px;color:#475569}.chat-mode .history button:hover{background:#f1f5f9}.chat-mode .history button.active{color:#0f5e9c;background:#eaf5ff}.chat-mode .history span{color:#94a3b8}.chat-mode .user{margin:0;padding:14px 16px;border-color:#edf2f7}.chat-mode .user b{color:#334155}.chat-mode .user span{color:#94a3b8}.chat-mode .avatar{color:#1d70b7;background:#e0f2fe}.chat-home-head{max-width:960px;padding:49px 20px 24px}.chat-home-head .welcome-mark{display:none}.chat-home-head h1{color:#0f172a;font-size:30px;font-weight:800}.chat-home-head h1 span{margin-left:6px;color:#2582ca}.chat-home-head p{display:none}.chat-todo-section{max-width:760px;padding:0 16px 14px}.chat-todo-label{margin-bottom:9px;color:#64748b}.chat-today{display:flex;justify-content:center}.today-item{gap:8px;width:auto;border-color:#d9e3eb;border-radius:999px;padding:9px 14px;color:#334155;background:#fff;box-shadow:0 2px 7px rgba(15,23,42,.035)}.today-item:hover{border-color:#7dc0ed;color:#1267a7;background:#f6fbff}.today-item .today-icon{width:18px;height:18px;flex-basis:18px;border-radius:50%;color:#0f5e9c;background:#dff1ff;font-size:15px;line-height:1}.today-item b{display:inline;color:inherit;font-size:13px}.today-item span{display:inline;margin:0;color:#64748b;font-size:12px}.today-item span span{display:none}.today-item .today-go{display:none}.chat-pending{display:flex;justify-content:center;gap:8px}.pending-item{display:flex;align-items:center;gap:6px;width:auto;border-color:#e2e8f0;border-radius:999px;padding:8px 12px;color:#475569;background:#fff;box-shadow:0 2px 7px rgba(15,23,42,.03)}.pending-item:hover{border-color:#b9d9ef;background:#f8fbff}.pending-item.primary{border-color:#c5e2f4;background:#f4faff}.pending-item b{display:inline;color:inherit;font-size:12px}.pending-item.primary b{color:#1f5f99}.pending-item span{display:none}.pending-item .pending-count{display:inline;margin:0;color:#2582ca;font-size:12px}.pending-item.warning .pending-count{color:#b7791f}.pending-item.muted .pending-count{color:#64748b}.chat-thread{max-width:760px;padding:34px 16px 154px}.chat-thread .bubble{border-color:#e2e8f0;border-radius:6px 14px 14px;padding:11px 13px;color:#475569;background:#fff;box-shadow:0 2px 8px rgba(15,23,42,.04)}.chat-thread .bubble.user-msg{border:0;border-radius:14px 5px 14px 14px;color:#fff;background:#2582ca}.chat-thread .scope{border-color:#d8ecfa;border-radius:10px;color:#475569;background:#f6fbff}.chat-thread .scope b{color:#1f5f99}.chat-thread .scope span{color:#64748b}.chat-thread .notice{border-radius:10px;color:#9a640c;background:#fff7e7}.chat-action .btn{border-color:#2582ca;color:#fff;background:#2582ca}.chat-input-wrap{left:300px;padding:0 14px 8px;background:linear-gradient(transparent,rgba(255,255,255,.96) 28%)}.chat-input{width:min(760px,100%);border:1px solid #edf1f5;border-radius:17px;padding:8px 10px;background:#fff;box-shadow:0 8px 26px rgba(15,23,42,.08)}.chat-input textarea{min-height:42px;padding:8px 10px;color:#0f172a}.chat-input textarea::placeholder{color:#94a3b8}.chat-input-tools{min-height:35px;padding:0 4px}.chat-input-tools button{width:30px;height:30px;color:#64748b}.chat-input-tools button:hover{color:#2582ca;background:#f1f5f9}.chat-input-tools .kb-pill{border-color:#e2e8f0;border-radius:7px;color:#94a3b8;background:#fff}.chat-input-tools .send{border-color:#edf1f5;color:#cbd5e1;background:#f8fafc}.chat-input-hint{margin-top:8px;color:#94a3b8}
/* 待办是业务工作入口,保留卡片、计数和辅助说明,不压缩为聊天快捷问题。 */
.chat-mode .chat-todo-section{width:100%;max-width:780px;padding:0 0 14px}.chat-mode .chat-todo-label{margin:0 0 8px;color:#506e8b;font-size:14px;font-weight:800}.chat-mode .chat-today{display:grid;grid-template-columns:1fr;gap:10px}.chat-mode .today-item{display:flex;align-items:center;gap:12px;width:100%;border:1px solid #9cc7f2;border-radius:12px;padding:13px;color:#1f5f99;background:#eef6ff;text-align:left;box-shadow:none}.chat-mode .today-item:hover{background:#e3f1ff}.chat-mode .today-item .today-icon{display:grid;place-items:center;width:34px;height:34px;flex:0 0 34px;border-radius:10px;color:#fff;background:#2f80d1;font-size:18px;font-weight:800}.chat-mode .today-item b,.chat-mode .today-item span{display:block}.chat-mode .today-item b{color:#1f5f99;font-size:13px}.chat-mode .today-item span{margin-top:2px;color:#54718f;font-size:11px}.chat-mode .today-item span span{display:block}.chat-mode .today-item .today-go{display:block;margin-left:auto;color:#2f80d1;font-size:19px}.chat-mode .chat-pending{display:grid;width:100%;grid-template-columns:1.3fr 1fr 1fr;gap:10px}.chat-mode .pending-item{display:block;min-width:0;width:100%;border:1px solid #e2e8f0;border-radius:12px;padding:12px 13px;color:#475569;background:#fff;text-align:left;box-shadow:none}.chat-mode .pending-item:hover{border-color:#9cc7f2;background:#f8fbff}.chat-mode .pending-item.primary{border-color:#9cc7f2;background:#eef6ff}.chat-mode .pending-item b,.chat-mode .pending-item span{display:block}.chat-mode .pending-item b{color:#0f172a;font-size:13px}.chat-mode .pending-item.primary b{color:#1f5f99}.chat-mode .pending-item span{margin-top:3px;color:#64748b;font-size:11px}.chat-mode .pending-item .pending-count{display:inline-block;margin:0 0 4px;color:#2f80d1;font-size:22px;line-height:1;font-weight:800}.chat-mode .pending-item.warning .pending-count{color:#b7730d}.chat-mode .pending-item.muted .pending-count{color:#64748b}
@media(max-width:800px){body{font-size:13px}#app{display:block;height:auto;min-height:100%;overflow:auto}.shell{display:block;overflow:auto}.side{display:none}.main{min-height:100%;overflow:visible}.topbar{padding:0 16px}.crumb{display:none}.page{padding:17px}.grid.two{grid-template-columns:1fr}.summary{grid-template-columns:repeat(2,1fr)}.page-head{display:block}.page-head .back{margin-bottom:8px}.source-toolbar{flex-wrap:wrap}.source-toolbar input{width:100%}.source-toolbar .count{margin-left:0}.source-list{grid-template-columns:1fr}.source-item{border-right:0}.facts{grid-template-columns:1fr}.fact{border-right:0}.fact:nth-last-child(-n+3){border-bottom:1px solid var(--line)}.fact:last-child{border-bottom:0}.confirm-band{display:block}.confirm-band .actions{margin-top:10px}.table{min-width:650px}.chat-mode .page{padding:0 14px}.chat-home-head{padding-top:25px}.chat-home-head h1{font-size:23px}.chat-pending{grid-template-columns:1fr;padding-bottom:10px}.chat-input-wrap{left:0;padding:10px 12px 14px}.chat-thread{padding-bottom:140px}.chat-thread .bubble{max-width:92%}}
</style>
</head>
<body>
@@ -33,11 +37,18 @@
<button data-action="go-precheck"><b>DBS 昨日收料预检</b><span>PRE-20260818-001</span></button>
<button data-action="go-run"><b>自动调拨结果</b><span>AUTO-20260818-0900</span><i class="dot"></i></button>
<button data-action="go-backlog"><b>待处理调拨</b><span>6 笔可恢复异常</span><i class="dot bad"></i></button>
<div class="history-divider"></div>
<div class="history-label">评审对话走查(演示)</div>
<button class="walkthrough" data-action="chat-scene-intent"><b>处理昨天 DBS-AWSBI 的收料</b><span>发起调拨意图</span></button>
<button class="walkthrough" data-action="chat-scene-status"><b>还有哪些待处理调拨?</b><span>历史待办状态</span></button>
<button class="walkthrough" data-action="chat-scene-mismatch"><b>INV-031 为什么不可调拨?</b><span>数量不一致说明</span></button>
<button class="walkthrough" data-action="chat-scene-recovery"><b>我已在 ERP 处理好库存,如何复查?</b><span>异常 ERP 复查</span></button>
<button class="walkthrough" data-action="chat-scene-schedule"><b>最近自动调拨执行结果?</b><span>自动 Run 汇总</span></button>
</div>
<div class="user"><div class="avatar">仓</div><div><b>仓库管理人员</b><span>在途仓调拨 Agent</span></div></div>
</aside>
<main class="main">
<header class="topbar"><div class="agent-icon">AI</div><div class="title"><b>在途仓自动调拨</b><span id="sub-title">Chat 首页 · 仅展示摘要与入口</span></div><div class="crumb" id="crumb">/chat/:agentId</div></header>
<header class="topbar"><div class="agent-icon">AI</div><div class="title"><b>在途仓自动调拨</b><span id="sub-title">Chat 首页 · 仅展示摘要与入口</span></div><div class="crumb" id="crumb">调拨中心</div><div class="chat-nav-actions"><button type="button" aria-label="打开历史记录" title="历史记录" data-action="toggle-history">↶</button><button type="button" aria-label="更多功能" title="更多功能">▦</button></div></header>
<div class="layout" id="page"></div>
</main>
</div>
@@ -45,7 +56,7 @@
<div class="overlay" id="modal-mask"><div class="modal"><h2 id="modal-title"></h2><p id="modal-desc"></p><div class="body"><input id="reason" placeholder="请输入原因(必填)" /></div><div class="footer"><button class="btn" data-action="modal-cancel">取消</button><button class="btn primary" data-action="modal-confirm">确认</button></div></div></div>
<script>
const $ = id => document.getElementById(id);
const S = { selected:new Set(['DBS-AWSBI']), collapsed:new Set(), businessDate:'2026-08-18', backlogTab:'recoverable', modal:null, toastTimer:null, precheckRequery:'initial', routeOrgs:new Set() };
const S = { selected:new Set(['DBS-AWSBI']), collapsed:new Set(), businessDate:'2026-08-18', backlogTab:'recoverable', modal:null, toastTimer:null, precheckRequery:'initial', routeOrgs:new Set(), historyOpen:false };
const sources = [
{ platform:'DBS', code:'DBS-AWSBI', name:'AWSBI 在途仓', warehouse:'AWSBI-TRANSIT', enabled:true },
{ platform:'DBS', code:'DBS-AWSSG', name:'AWSSG 在途仓', warehouse:'AWSSG-TRANSIT', enabled:true },
@@ -73,12 +84,13 @@
safety:{ label:'结果未知说明', user:'为什么不能重试结果未知?', reply:'ERP 调用未返回可确认的成功或失败时,系统无法证明没有产生单据。再次提交存在重复写入风险,所以该状态只读,必须由 ERP 管理员线下核实。', evidence:'禁止:重试、关闭、恢复、重新执行;允许:查看已知事实与审计。', action:'go-unknown', actionLabel:'查看结果未知事项' },
schedule:{ label:'自动调拨结果', user:'最近一次自动调拨执行得怎么样?', reply:'自动排程按来源实例独立处理:每个实例使用其任务开始前的最新有效文件,分别预检、写入和汇总通知。一个实例失败不会阻断其他实例。', evidence:'演示 Run:DBS-AWSBI 成功 18 项;CRANE-SZ 文件获取超时并保留异常证据。', action:'go-run', actionLabel:'查看最近自动 Run' }
};
const chatScenario = () => new URL(location.href).searchParams.get('scene') || 'welcome';
const chatScenario = () => new URL(location.href).searchParams.get('scene');
function chatPage(){
setHeader('Chat 首页 · 对话解释与业务入口','/chat/:agentId');
const key=chatScenario(), scene=chatScenarios[key] || chatScenarios.welcome;
const scenarioTabs=Object.entries(chatScenarios).map(([id,item])=>`<button class="tab ${id===key?'active':''}" data-action="chat-scene-${id}">${item.label}</button>`).join('');
return `<section class="page"><div class="chat-home"><div class="chat-home-head"><div class="welcome-mark">AI</div><h1>你好,欢迎使用<span>在途仓自动调拨 Agent</span></h1><p>我会解释规则、展示收料文件与 ERP 查询进度;需要改变业务数据时,请在对应页面点击按钮确认。</p></div><div class="chat-scenarios" aria-label="对话场景">${scenarioTabs}</div><div class="chat-thread"><div class="bubble user-msg">${scene.user}</div><div class="bubble">${scene.reply}</div><div class="scope"><div><b>系统状态 / 可核验依据</b><span>${scene.evidence}</span></div></div><div class="chat-action">${button(scene.actionLabel,scene.action,'primary')}</div><div class="notice warn"><i>!</i><span>对话不会绕过业务按钮直接发起 ERP 写入;当天收料不会进入 ERP 查询或调拨。</span></div></div><div class="chat-input-wrap"><div class="chat-input"><input id="chat-input" aria-label="对话输入" placeholder="例如:为什么今天不能调拨?" /><button aria-label="发送" data-action="chat-send">↑</button></div><div class="chat-input-hint">AI 可能会犯错,请核实重要信息。 · 原型数据仅用于业务走查</div></div></div></section>`;
const key=chatScenario(), scene=key && chatScenarios[key];
const welcome=`<div class="chat-home-head"><div class="welcome-mark">AI</div><h1>你好,您已进入<span>在途仓自动调拨 Agent</span></h1><p>我会解释规则、展示收料文件与 ERP 查询进度;需要改变业务数据时,请在对应页面点击按钮确认。</p></div><section class="chat-todo-section" aria-label="今日待办"><p class="chat-todo-label">今日待办</p><div class="chat-today"><button class="today-item" data-action="go-source"><i class="today-icon">+</i><span><b>发起今日调拨预检</b><span>选择来源实例后,系统默认以昨天为业务日期处理可成熟收料。</span></span><i class="today-go">›</i></button></div></section><section class="chat-todo-section" aria-label="历史待办"><p class="chat-todo-label">历史待办</p><div class="chat-pending"><button class="pending-item primary" data-action="go-backlog-recoverable"><span class="pending-count">6</span><b>可恢复异常</b><span>可重新查询 ERP 库存后继续处理</span></button><button class="pending-item muted" data-action="go-backlog-closed"><span class="pending-count">2</span><b>已人工关闭</b><span>可查看原因并恢复处理</span></button><button class="pending-item warning" data-action="go-unknown"><span class="pending-count">1</span><b>结果未知</b><span>只读,需线下核实 ERP 事实</span></button></div></section>`;
const thread=scene?`<div class="chat-thread"><div class="bubble user-msg">${scene.user}</div><div class="bubble">${scene.reply}</div><div class="scope"><div><b>系统状态 / 可核验依据</b><span>${scene.evidence}</span></div></div><div class="chat-action">${button(scene.actionLabel,scene.action,'primary')}</div><div class="notice warn"><i>!</i><span>对话不会绕过业务按钮直接发起 ERP 写入;当天收料不会进入 ERP 查询或调拨。</span></div></div>`:welcome;
return `<section class="page"><div class="chat-home">${thread}<div class="chat-input-wrap"><div class="chat-input"><textarea id="chat-input" aria-label="对话输入" rows="1" placeholder="问我任何事..."></textarea><div class="chat-input-tools"><button type="button" aria-label="语音功能" title="语音功能">♩</button><button type="button" class="kb-pill" aria-label="企业知识库" disabled>▤ 企业知识库⌄</button><button type="button" class="send" aria-label="发送" title="发送" data-action="chat-send">➤</button></div></div><div class="chat-input-hint">AI 可能会犯错,请核实重要信息。</div></div></div></section>`;
}
function sourcePage(){
setHeader('来源实例选择 · 本次调拨范围','/chat/:agentId?mode=transfer-source-selection');
@@ -150,12 +162,13 @@
function recoverable(){return `<div class="filters"><select><option>来源:全部</option><option>DBS</option><option>Crane</option></select><select><option>日期:全部</option><option>最近 3 天</option></select></div><div class="table-wrap"><table class="table"><thead><tr><th></th><th>来源实例 / 日期</th><th>Invoice</th><th>当前事实</th><th>最近查询</th><th></th></tr></thead><tbody><tr><td><input type="checkbox" checked /></td><td>DBS-AWSBI<br><small>2026-08-16</small></td><td><b>INV-031</b></td><td>收料 300 / ERP 280</td><td>09:12</td><td><button class="link" data-action="show-audit">证据</button></td></tr><tr><td><input type="checkbox" checked /></td><td>CRANE-SZ<br><small>2026-08-15</small></td><td><b>INV-042</b></td><td>收料 800 / ERP 0</td><td>09:12</td><td><button class="link" data-action="show-audit">证据</button></td></tr><tr><td><input type="checkbox" /></td><td>DBS-AWSSG<br><small>2026-08-14</small></td><td><b>INV-073</b></td><td>明确技术失败</td><td>08:50</td><td><button class="link" data-action="show-audit">证据</button></td></tr></tbody></table></div><div class="notice"><i>i</i><span>多选后每个 Invoice 都会重新查询 ERP 库存;满足严格等量的项目才进入新的确认页。</span></div><div class="actions">${button('重新查询 ERP 库存(2)','requery','primary')}${button('标记无需继续处理','close-item','danger')}</div>`}
function closed(){return `<div class="table-wrap"><table class="table"><thead><tr><th>Invoice</th><th>关闭原因</th><th>关闭人 / 时间</th><th></th></tr></thead><tbody><tr><td>INV-061</td><td>货代确认无需调拨</td><td>仓库管理人员 · 08-17 15:00</td><td><button class="link" data-action="restore-item">恢复处理</button></td></tr><tr><td>INV-068</td><td>业务已线下完成</td><td>仓库管理人员 · 08-17 16:20</td><td><button class="link" data-action="restore-item">恢复处理</button></td></tr></tbody></table></div><div class="notice"><i>i</i><span>恢复后回到“可恢复异常”池;原关闭原因、操作者和快照永久保留。</span></div>`}
function unknown(){return `<div class="notice bad"><i>!</i><span>ERP 未返回确定成功或失败。系统只展示已知事实,不提供重查、关闭、恢复或执行按钮。</span></div><div class="table-wrap"><table class="table"><thead><tr><th>Invoice</th><th>所属 Run</th><th>调用时间</th><th>Operation ID</th><th></th></tr></thead><tbody><tr><td><b>INV-052</b></td><td>AUTO-20260818-0900</td><td>09:17:21</td><td>OP-20260818-8891</td><td><button class="link" data-action="show-unknown">查看事实与 SOP</button></td></tr></tbody></table></div>`}
function render(){ const page=pageName(); document.body.classList.toggle('chat-mode',page==='chat'); const renderer={chat:chatPage,source:sourcePage,precheck:precheckPage,confirm:confirmPage,run:runPage,backlog:backlogPage,unknown:backlogPage}[page]||chatPage; $('page').innerHTML=renderer(); bind(); if(page==='source') filterSources(); }
function render(){ const page=pageName(); document.body.classList.toggle('chat-mode',page==='chat'); document.body.classList.toggle('history-open',page==='chat'&&S.historyOpen); const renderer={chat:chatPage,source:sourcePage,precheck:precheckPage,confirm:confirmPage,run:runPage,backlog:backlogPage,unknown:backlogPage}[page]||chatPage; $('page').innerHTML=renderer(); bind(); if(page==='source') filterSources(); }
function filterSources(){ const input=$('source-search'); if(!input)return; const apply=()=>{const q=input.value.trim().toLowerCase(); document.querySelectorAll('[data-source-row]').forEach(row=>row.hidden=!row.textContent.toLowerCase().includes(q));}; input.addEventListener('input',apply); $('source-count').textContent=`已选 ${S.selected.size} 个来源实例`; }
function openModal(type){S.modal=type; const data={close:['标记“无需继续处理”','该 Invoice 将变为 manually_closed,自动排程不再处理;历史与审计永久保留。'],restore:['恢复处理','恢复后回到可恢复异常池,可重新查询 ERP 库存。']}[type]; $('modal-title').textContent=data[0];$('modal-desc').textContent=data[1];$('reason').value='';$('modal-mask').classList.add('show');}
function action(a){
if(a.startsWith('chat-scene-'))return goto('chat',{scene:a.slice(11)});
if(a==='go-chat')return goto('chat'); if(a==='go-source')return goto('source'); if(a==='go-precheck')return goto('precheck'); if(a==='go-confirm')return goto('confirm'); if(a==='go-run')return goto('run'); if(a==='go-backlog')return goto('backlog'); if(a==='go-unknown'){S.backlogTab='unknown';return goto('backlog')}
if(a==='toggle-history'){S.historyOpen=!S.historyOpen;render();return}
if(a.startsWith('chat-scene-')){S.historyOpen=false;return goto('chat',{scene:a.slice(11)});}
if(a==='go-chat')return goto('chat'); if(a==='go-source')return goto('source'); if(a==='go-precheck')return goto('precheck'); if(a==='go-confirm')return goto('confirm'); if(a==='go-run')return goto('run'); if(a==='go-backlog')return goto('backlog'); if(a==='go-backlog-recoverable'){S.backlogTab='recoverable';return goto('backlog')} if(a==='go-backlog-closed'){S.backlogTab='closed';return goto('backlog')} if(a==='go-unknown'){S.backlogTab='unknown';return goto('backlog')}
if(a==='select-enabled'){sources.filter(x=>x.enabled).forEach(x=>S.selected.add(x.code));render();return} if(a==='clear-sources'){S.selected.clear();render();return} if(a.startsWith('toggle-org-')){const org=a.slice(11);S.routeOrgs.has(org)?S.routeOrgs.delete(org):S.routeOrgs.add(org);return} if(a.startsWith('toggle-')){const p=a.slice(7);S.collapsed.has(p)?S.collapsed.delete(p):S.collapsed.add(p);render();return}
if(a==='start-precheck'){if(!S.selected.size){toast('请至少选择一个已启用来源实例。');return} toast('原型:正在使用任务创建前可用的最新有效文件。');setTimeout(()=>goto('precheck'),450);return}
if(a==='execute'){toast('原型:已提交 Worker 执行。关闭页面不会取消后台任务。');setTimeout(()=>goto('run'),650);return} if(a==='requery'){toast('原型:仅重新查询所选异常的 ERP 库存;文件版本不变,未写入 ERP。');setTimeout(()=>goto('confirm'),500);return} if(a==='requery-precheck'){S.precheckRequery='loading';render();toast('原型:正在重新查询 INV-031 的 ERP 库存;未抓取 RPA 文件。');setTimeout(()=>{S.precheckRequery='matched';render();toast('原型:INV-031 已匹配并加入本次确认范围。');},900);return}
@@ -59,7 +59,7 @@
### 3.1 一期实现
- 对话查询今天可调拨数量。
- 按 DBS、Crane 或指定 Invoice 查询。
- 按来源实例分组、路由或指定 Invoice 查询;DBS、Crane 仅为当前已配置的来源分组示例。
- 检查当前业务日期的最新 `ready` 收料文件。
- 文件缺失时实时触发 RPA,并在对话中持续展示进度。
- 按 HUB 仓收料日期执行 D+1 成熟规则。
@@ -73,8 +73,8 @@
- 每日收料文件抓取排程,默认 08:00。
- 每日自动调拨排程,默认 09:00。
- 自动复核历史未成功且未人工关闭的 Invoice。
- 安全恢复、手工重试、请求停止、人工关闭。
- 一次自动调拨排程发送一条企业微信汇总通知并附异常 Excel。
- 安全恢复、拆分的人工重试(重新抓取 RPA / 重新查询 ERP)、请求停止、人工关闭。
- 一次自动调拨排程发送一条企业微信汇总通知;存在异常时附异常 Excel,空数据也发送通知但不附 Excel。
- 全节点审计和 MinIO 归档。
### 3.2 一期不实现
@@ -87,7 +87,6 @@
- ERP 写操作自动技术重试。
- `result_unknown` 自动重试。
- 通知自动重试。
- 空数据通知。
- 业务删除和历史兼容层。
---
@@ -171,7 +170,8 @@ source_code + business_date + file_purpose(receipt)
| 选择 Invoice、确认执行 | 允许 |
| 查看所有有权限用户发起的 Run | 允许 |
| 请求停止剩余任务 | 允许,原因必填 |
| 手工重试可重试项 | 允许 |
| 重新抓取 RPA | 仅在任务创建前允许;创建 Run 后禁止更新文件 |
| 重新查询 ERP | 任务创建后允许基于冻结文件执行;不触发 RPA、不写 ERP |
| `manually_closed` | 允许,原因必填 |
| 修改数量、仓库、ERP 组织 | 禁止 |
| 删除业务或审计记录 | 禁止 |
@@ -208,9 +208,11 @@ flowchart TD
S --> T[Worker写入前重新预检]
T --> U[逐项ERP原子调拨]
U --> V[生成结果和异常Excel]
V --> W{自动排程且非空数据}
W -->|是| X[发送一条企微汇总通知和附件]
W -->|否| Y[只保留Run和审计]
V --> W{自动排程}
W --> X[发送一条企微汇总通知]
X --> Y{存在异常}
Y -->|是| Z[附异常Excel]
Y -->|否| AA[不附Excel]
```
### 6.1 文件准备进度阶段
@@ -225,7 +227,7 @@ flowchart TD
8. 查询 ERP 库存。
9. 匹配可调拨结果。
每阶段使用 `pending | running | success | failed | skipped`,并分别展示 DBS、Crane 状态,不伪造总体百分比。
每阶段使用 `pending | running | success | failed | skipped`,并按来源实例/路由分别展示状态,不伪造总体百分比。
### 6.2 确认失效
@@ -314,7 +316,7 @@ pending
→ success | partial_failed | failed
```
DBS、Crane 独立执行、独立锁、独立审计,互不阻断。
各来源实例独立执行、独立锁、独立审计,互不阻断;来源分组仅用于页面聚合,不是业务隔离键。
### 8.3 Invoice Item
@@ -365,7 +367,8 @@ pending
| GET | `/api/in-transit-transfer/runs/{runNo}` | Run进度和结果 |
| GET | `/api/in-transit-transfer/runs/{runNo}/items` | Invoice分页明细 |
| POST | `/api/in-transit-transfer/runs/{runNo}/cancel` | 请求停止剩余任务 |
| POST | `/api/in-transit-transfer/items/{id}/retry` | 原Run创建新Attempt |
| POST | `/api/in-transit-transfer/items/{id}/retry-rpa` | 任务创建前重新抓取 RPA 并创建新文件 Attempt |
| POST | `/api/in-transit-transfer/items/{id}/retry-erp` | 基于已冻结文件仅重新查询 ERP 并创建新预检 Attempt |
| POST | `/api/in-transit-transfer/items/{id}/manual-close` | 人工关闭 |
| GET | `/api/in-transit-transfer/runs/{runNo}/exceptions.xlsx` | 下载异常Excel |
| GET | `/api/in-transit-transfer/items/{id}/audit` | 查询Invoice审计时间线 |
@@ -486,7 +489,8 @@ ERP地址和凭据只允许通过环境变量或Secret注入。
| 确认执行 | 用户 | 确认Hash、有效期、预计写入 |
| ERP调拨 | worker | 状态前后、单号、错误码、脱敏报文Hash |
| 请求停止 | 用户 | 原因和Run/Item前后状态 |
| 手工重试 | 用户 | 原因、新Attempt和重新预检证据 |
| 重新抓取 RPA | 用户 | 原因、新文件 Attempt、文件版本和重新预检证据;仅允许在任务创建前 |
| 重新查询 ERP | 用户 | 原因、新 ERP 查询 Attempt 和重新预检证据;任务创建后不得更新文件 |
| 自动历史复核 | 排程 | 每次保存摘要;相同结果引用前次完整快照 |
| 人工关闭 | 用户 | 原因、数量、文件版本、状态前后 |
| 查看详情/审计 | 用户 | 对象、时间、来源页面 |
@@ -505,7 +509,7 @@ ERP地址和凭据只允许通过环境变量或Secret注入。
## 12. 企业微信与Excel
每次非空自动调拨排程发送一条汇总通知,DBS、Crane合并展示。接收人是任务所有者和来源配置通知人的去重合集。
每次自动调拨排程(包括空数据)发送一条汇总通知,按来源实例/路由聚合展示。接收人是任务所有者和来源配置通知人的去重合集。
通知包含:
@@ -513,7 +517,7 @@ ERP地址和凭据只允许通过环境变量或Secret注入。
- 历史异常恢复成功数量。
- 当前待处理、`result_unknown`、3天以上积压数量。
- 调拨总数量和ERP单据数。
- 一份本次排程异常Excel。
- 存在异常时附一份本次排程异常Excel;空数据不附Excel。
Excel Sheet:
@@ -525,7 +529,7 @@ Excel Sheet:
6. 通知失败
7. 原始文件追溯
空数据Run:`success + no_data`,不调用ERP、不通知。
空数据Run:`success + no_data`,不调用ERP,但仍发送一条“无可调拨数据”企业微信汇总通知,不附异常 Excel。
---
@@ -540,7 +544,7 @@ Excel Sheet:
│ │ 今日待处理 │
│ 历史会话 │ 历史待处理 5 已恢复 2 结果未知 1 超期 2 │
│ 今日自动调拨 │ │
│ DBS数量异常 │ [查询今天可调拨数据] │
│ 来源实例数量异常 │ [查询今天可调拨数据] │
│ INV-001处理结果 │ [执行今天全部可调拨项] │
│ │ [查看待处理异常] │
│ │ │
@@ -559,14 +563,14 @@ Excel Sheet:
```text
用户:查询今天有多少可以调拨
AI:正在检查今天的DBS和Crane收料文件;缺失来源会实时抓取。
AI:正在检查已选来源实例的收料文件;缺失来源会实时抓取。
┌─ 正在准备可调拨数据 ──────────────────────────────┐
│ 可处理收料日期 截至 2026-08-05 │
│ 当前阶段 准备收料Excel │
│ │
│ DBS ✓ 复用今日08:00 ready文件 │
│ Crane ◉ 未找到今日文件,RPA已领取,等待Callback │
│ DBS-AWSBI ✓ 复用今日08:00 ready文件 │
│ AWS-SG ◉ 未找到今日文件,RPA已领取,等待Callback│
│ │
│ 后续:校验 → 过滤未成熟 → 汇总 → ERP查询 → 匹配 │
│ [刷新进度] │
@@ -596,10 +600,10 @@ AI:正在检查今天的DBS和Crane收料文件;缺失来源会实时抓取
```text
┌─ 执行前确认 ──────────────────────────────────────┐
│ 搜索Invoice [_______________________________] │
│ [✓] INV-001 DBS 1,200 = 1,200 可执行 │
│ [✓] INV-002 DBS 800 = 800 可执行 │
│ [ ] INV-003 DBS 1,200 ≠ 1,000 已阻断 │
│ [✓] INV-004 Crane 600 = 600 可执行 │
│ [✓] INV-001 DBS-AWSBI 1,200 = 1,200 可执行 │
│ [✓] INV-002 DBS-AWSBI 800 = 800 可执行 │
│ [ ] INV-003 AWS-SG 1,200 ≠ 1,000 已阻断 │
│ [✓] INV-004 Crane-EU 600 = 600 可执行 │
│ │
│ 已选择 3张 总数量 2,600 PCS ERP写入 3张 │
│ 确认有效期 10分钟 │
@@ -638,7 +642,7 @@ AI:正在检查今天的DBS和Crane收料文件;缺失来源会实时抓取
```text
┌─ INV-260806-019 ──────────────────────────────────┐
│ 来源 DBS 状态 数量不一致 │
│ 来源实例 DBS-AWSBI 状态 数量不一致 │
│ 文件 receipt-v20.xlsx Sheet Receipt │
│ 原始行 128、129 收料 1,200 / ERP 1,000 │
│ │
@@ -647,10 +651,12 @@ AI:正在检查今天的DBS和Crane收料文件;缺失来源会实时抓取
│ 09:02 ERP查询完成 │
│ 09:02 数量门禁阻断 │
│ │
│ [下载证据] [手工重试] [无需再处理] │
│ [重新查询ERP] [重新抓取RPA] [无需再处理] │
└────────────────────────────────────────────────────┘
```
`重新抓取RPA` 仅在尚未创建调拨 Run 的文件准备阶段可用;Run 创建后按钮禁用,异常项只能使用“重新查询 ERP”。
### 13.8 人工关闭
```text
@@ -671,7 +677,7 @@ AI:正在检查今天的DBS和Crane收料文件;缺失来源会实时抓取
┌─ HXOPS管理后台 ───────────────────────────────────────────────────┐
│ 调拨配置 │
│ ● 数据来源 ┌─ 收料文件来源 ──────────────────────────────┐ │
│ 调拨策略 │ DBS收料汇总 Crane收料汇总 │ │
│ 调拨策略 │ DBS-AWSBI收料 AWS-SG收料 │ │
│ 仓库与组织 │ 用途 receipt 用途 receipt │ │
│ 自动排程 │ RPA Profile HTTP Callback │ │
│ 通知设置 │ 解析方案 V3 解析方案 V3 │ │
@@ -708,13 +714,13 @@ AI:正在检查今天的DBS和Crane收料文件;缺失来源会实时抓取
```text
┌─ 自动排程 ──────────────────────────────────────────────────────┐
│ 每日收料文件抓取 08:00 DBS、Crane并发2 [编辑][停用] │
│ 每日收料文件抓取 08:00 已启用来源实例并发2 [编辑][停用] │
│ 每日自动调拨 09:00 查询并发2 / 写并发1 [编辑][停用] │
└─────────────────────────────────────────────────────────────────┘
┌─ 通知设置 ──────────────────────────────────────────────────────┐
│ 任务所有者 李仓储 额外通知人 王仓管、陈主管 │
│ 非空Run一条汇总通知 一份七Sheet异常Excel │
│ 空数据不通知 notification_failed不改变业务结果 │
│ 每个Run一条汇总通知 有异常时附七Sheet Excel │
│ 空数据发送通知(不附Excel) notification_failed不改变业务结果 │
└─────────────────────────────────────────────────────────────────┘
┌─ 发布门禁与审计 ────────────────────────────────────────────────┐
│ 来源 ✓ 映射 ✓ 环境变量 ✓ 通知人 ! 配置验证 ✓ │
@@ -744,7 +750,7 @@ AI:正在检查今天的DBS和Crane收料文件;缺失来源会实时抓取
| `frontend/src/features/admin/modules/shipping-inventory/ShippingInventoryPage.vue` | 复用现有页面增加收料来源字段,不新增管理页 |
| `frontend/src/features/admin/modules/shipping-inventory/shippingInventorySourceForm.ts` | 表单归一化、校验和脏状态比较 |
| `frontend/src/features/admin/api/admin.api.ts` | 扩展来源DTO |
| `docs/platform/in-transit-transfer-source-instance-mvp.html` | Chat 摘要发起、来源实例选择、文件冻结预检、异常 ERP 重查、组织→路由→Invoice 聚合确认与 Run/待处理跳转 |
| `docs/features/in-transit-transfer/in-transit-transfer-source-instance-mvp.html` | Chat 摘要发起、来源实例选择、文件冻结预检、异常 ERP 重查、组织→路由→Invoice 聚合确认与 Run/待处理跳转 |
| `docs/demand.md`、`docs/tec.md`、`docs/funclist.md` | 同步需求、架构和功能清单 |
#### 新增文件
@@ -800,7 +806,7 @@ AI:正在检查今天的DBS和Crane收料文件;缺失来源会实时抓取
| `frontend/src/features/chat/components/TransferInvoiceDetailDrawer.vue` | Invoice明细 |
| 对应前后端测试 | 文件幂等、日期、解析、汇总、ERP查询、历史恢复 |
验收:缺文件时5秒内返回进度卡;并发请求只触发一次RPA;当天收料100%不查ERP;多行汇总准确率100%;DBS失败不影响Crane;历史会话可恢复进度;同一查询Run在历史侧栏中始终只有一条会话记录。
验收:缺文件时5秒内返回进度卡;并发请求只触发一次RPA;当天收料100%不查ERP;多行汇总准确率100%;任一来源实例失败不影响其他来源实例;历史会话可恢复进度;同一查询Run在历史侧栏中始终只有一条会话记录。
### Phase 2:确认和ERP调拨
@@ -858,7 +864,7 @@ AI:正在检查今天的DBS和Crane收料文件;缺失来源会实时抓取
| `backend/app/services/schedule/in_transit_transfer_job.py` | 09:00自动调拨排程 |
| `backend/app/services/in_transit_transfer/backlog_service.py` | 历史待处理池和老化 |
| `backend/app/services/in_transit_transfer/recovery_service.py` | 自动复核和新Attempt |
| `backend/app/services/in_transit_transfer/retry_service.py` | 手工重试 |
| `backend/app/services/in_transit_transfer/retry_service.py` | 校验人工重试状态门禁,并分派至重新抓取 RPA 或重新查询 ERP |
| `backend/app/services/in_transit_transfer/manual_close_service.py` | 人工关闭 |
| `backend/app/services/in_transit_transfer/excel_export.py` | 七Sheet Excel |
| `backend/app/services/in_transit_transfer/notification.py` | 一次排程一条企微通知 |
@@ -956,8 +962,8 @@ AI:正在检查今天的DBS和Crane收料文件;缺失来源会实时抓取
5. 未确认、过期确认、变化预检的ERP写入数量均为0。
6. `result_unknown`自动重试数量为0。
7. 历史可恢复项能自动进入新Attempt,旧Attempt不变。
8. DBS和Crane故障互不影响。
9. 非空自动排程仅发送一条汇总通知和一份Excel。
8. 任一来源实例故障不影响其他来源实例。
9. 每个自动排程Run恰好发送一条汇总通知;有异常时附一份Excel,空数据不附Excel。
10. 前端构建、四语言、专项测试、E2E、迁移和真实ERP沙箱验收全部通过。
11. 查询、文件准备、ERP预检在一次对话中原位投影,历史侧栏不产生重复阶段记录。
12. 后台配置必须经过草稿、校验、发布流程;ERP与RPA凭据明文展示数量为0。
@@ -3,7 +3,7 @@
> 评审状态:**开发部门内部评审稿**。
> 适用读者:产品、前端、后端、测试、架构/运维;仓储业务与 ERP 团队可按需参阅。
> 本文目标:用于内部确认 MVP 的实现范围、用户操作、页面跳转、前后端职责和高风险边界;不是开发任务拆分或测试用例替代品。
> 唯一原型基线:[来源实例路由化 MVP 可点击原型](../../platform/in-transit-transfer-source-instance-mvp.html)。
> 唯一原型基线:[来源实例路由化 MVP 可点击原型](./in-transit-transfer-source-instance-mvp.html)。
> 业务全量规格参考:[一期最小化实现规格](./minimum-implementation-spec.md)。
---
@@ -27,7 +27,7 @@
| 材料 | 本次用途 | 评审时的使用原则 |
| --- | --- | --- |
| 本文 | 议程、范围、场景、评审结论记录 | **本次会议主材料** |
| [可点击原型](../../platform/in-transit-transfer-source-instance-mvp.html) | 页面布局、跳转与操作反馈演示 | **唯一 UI/UX 基线** |
| [可点击原型](./in-transit-transfer-source-instance-mvp.html) | 页面布局、跳转与操作反馈演示 | **唯一 UI/UX 基线** |
| [一期最小化实现规格](./minimum-implementation-spec.md) | 后端、审计、文件、排程、验收的完整约束 | 业务规则的完整参考 |
| [PRD](./prd.md) | 业务价值、问题背景、角色与范围 | 背景参考;其中旧原型链接不作为本次 UI 基线 |
| [路线图](./roadmap.md) | 分阶段投入、依赖和上线门禁 | 排期与资源讨论参考 |
@@ -80,7 +80,7 @@
| R10 | 路由是确认与审计边界 | 路由键:`来源实例 + ERP 组织 + 来源仓 + 目标仓`;不同路由不能被汇总为一个统一 HUB 仓 |
| R11 | `result_unknown` 只读 | 不允许重查、关闭、恢复、再次执行或猜测其 ERP 业务结果 |
| R12 | 异常可关闭也可恢复 | `manually_closed` 必须填写原因;恢复也必须记录原因;不删除历史 |
| R13 | 自动任务隔离 | 一个来源实例失败不能阻断其他来源实例;每个自动 Run 只发一条汇总企业微信通知 |
| R13 | 自动任务隔离 | 一个来源实例失败不能阻断其他来源实例;每个自动 Run(包括空数据)只发一条汇总企业微信通知,有异常时附 Excel |
## 5. MVP 用户、权限与职责
@@ -344,7 +344,7 @@ stateDiagram-v2
| 执行恢复 | 页面关闭或 SSE 断开不取消后台 Run;重新进入可恢复固定结果 |
| 异常 | `result_unknown` 下重查/关闭/恢复/再次执行次数均为 0;关闭/恢复原因必填 |
| 审计 | 关键业务操作与证据读取/下载的审计字段完整率 100% |
| 自动任务 | 单个来源实例失败不阻断其他实例;每个非空自动 Run 企业微信汇总通知为 1 条 |
| 自动任务 | 单个来源实例失败不阻断其他实例;每个自动 Run(包括空数据)企业微信汇总通知为 1 条,有异常时附 Excel |
## 15. 90 分钟开发部门内部评审议程与决策记录
+21 -21
View File
@@ -17,7 +17,7 @@
- [完整规格说明书](./minimum-implementation-spec.md)
- [TDD实施与验证规范](./in-transit-transfer-tdd.md)
- [开发部门需求与原型评审包](./mvp-requirements-and-prototype-review-pack.md)
- [来源实例路由化 MVP 原型](../../platform/in-transit-transfer-source-instance-mvp.html)
- [来源实例路由化 MVP 原型](./in-transit-transfer-source-instance-mvp.html)
---
@@ -64,7 +64,7 @@ M2不是一期最终完成,只是为了尽早验证真实业务价值的受控
- **业务真相确定性:** Dify只理解意图和组织对话,不判断最终库存、不持有ERP写权限。
- **读取与写入分离:** 查询、预检、确认、执行为不同状态;没有有效确认不得写ERP。
- **按Invoice隔离:** 自动Run采用逐项结果,只执行可执行项;单项失败不阻断其他Invoice。
- **来源隔离:** DBS与Crane只是不同调拨源,各自准备文件和报告状态,互不影响。
- **来源隔离:** 来源实例各自准备文件和报告状态,互不影响;来源分组只用于聚合展示。
- **失败不遗忘:** 未成功且未`manually_closed`的可恢复项进入待处理池;下一排程重新预检并创建新Attempt。
- **结果未知隔离:** `result_unknown`禁止自动重试,必须执行人工核实SOP。
- **全链路审计:** 所有读取、下载、确认、执行、重试、关闭、配置和发布节点均可追溯。
@@ -74,13 +74,13 @@ M2不是一期最终完成,只是为了尽早验证真实业务价值的受控
- 现有Chat中的专用自动调拨Agent。
- 对话查询、文件准备进度、预检、选择、确认、执行、结果、异常和审计。
- DBS RPA和Crane HTTP Callback收料来源。
- 已配置来源实例的 RPA / HTTP Callback 收料来源。
- 当前业务日期最新Ready累计全量文件。
- D+1成熟规则、Invoice多行收料数量汇总、精确数量匹配。
- ERP账面库存查询及单接口原子新建、审核、过账。
- Invoice幂等、重复成功识别、结果未知隔离。
- 08:00文件获取、09:00自动调拨、历史失败恢复、3/5/7天老化机制。
- 每个非空自动Run一条企业微信汇总通知和一份七Sheet异常Excel。
- 每个自动Run一条企业微信汇总通知;有异常时附七Sheet异常Excel,空数据不附Excel。
- 人工重试、请求停止、人工关闭及完整审计。
- 来源、策略、映射、排程、通知、校验和发布配置。
- 四语言、基础移动端适配、MinIO证据和归档。
@@ -107,7 +107,7 @@ M2不是一期最终完成,只是为了尽早验证真实业务价值的受控
| Phase 0 契约与测试底座 | 团队对业务真相和外部接口形成一致理解 | ERP/文件契约、状态机、DTO、审计模型、Fake、迁移草案 | 核心L0测试从Red到Green;ERP沙箱契约可执行 |
| Phase 1 文件与只读预检 | 仓储用户能查到“哪些可调拨、为什么” | 文件准备、D+1、汇总、ERP查询、Chat进度与预检 | 当天收料ERP调用0;缺文件5秒内反馈;来源互不阻断 |
| Phase 2 确认与ERP写入 | 对话发起的一次确认调拨闭环 | 确认Hash、写前复检、Worker、ERP原子写、结果卡 | 未确认/过期/变化写入0;重复建单0;单号可追溯 |
| Phase 3 排程与异常闭环 | 系统每日自动处理且不会遗忘失败项 | 排程、待办池、新Attempt、老化、Excel、企微、配置发布 | 可恢复项100%重新预检;非空Run恰好1条通知 |
| Phase 3 排程与异常闭环 | 系统每日自动处理且不会遗忘失败项 | 排程、待办池、新Attempt、老化、Excel、企微、配置发布 | 可恢复项100%重新预检;每个Run恰好1条通知 |
| Phase 4 生产硬化与上线 | 满足生产安全、稳定和运维要求 | 性能、故障注入、安全、归档、指标、UAT、上线方案 | P0/P1为0;全量门禁通过;业务和ERP签字 |
| Phase 5 优化与平台演进 | 降低新增来源/ERP Operation接入成本 | 薄集成内核、Operation元数据、连接器治理、SLO | 新Operation无需改核心编排;迁移演练成功 |
@@ -211,7 +211,7 @@ ERP契约和结果未知SOP未关闭时,可以完成纯领域和前端Mock工
### 5.2 用户能力
- 查询今天、指定日期、指定来源或指定Invoice的可调拨情况。
- 查看DBS和Crane独立的文件准备状态。
- 查看各来源实例独立的文件准备状态。
- 查看未成熟、可执行、数量不一致、ERP无库存和文件异常。
- 查看可调拨总数量和预计ERP单据数。
- 下载只读预检明细和查看原始行追溯。
@@ -251,7 +251,7 @@ ERP契约和结果未知SOP未关闭时,可以完成纯领域和前端Mock工
- 对话首次进度反馈不晚于5秒。
- 不显示无法解释的单一Spinner;必须显示当前来源、阶段和最近更新时间。
- DBS失败时Crane继续,反之亦然。
- 任一来源实例失败时其他来源实例继续。
- 当天收料显示`not_matured`,不显示为ERP异常。
- 查询和文件准备不会显示“执行成功”等写入语义。
- 刷新、切换会话或SSE断开后从Run投影恢复。
@@ -261,7 +261,7 @@ ERP契约和结果未知SOP未关闭时,可以完成纯领域和前端Mock工
- [ ] 有当日Ready文件时正确复用最新有效版本。
- [ ] 无Ready文件时,同来源并发请求只创建一个活动Source Job。
- [ ] 缺文件后5秒内返回来源级进度。
- [ ] DBS和Crane故障互不影响。
- [ ] 任一来源实例故障不影响其他来源实例。
- [ ] 相同Invoice多行汇总准确率100%,原始行追溯完整率100%。
- [ ] 当天收料ERP查询和写入均为0。
- [ ] 数量只有完全相等时为`executable`。
@@ -356,10 +356,10 @@ Phase 2完成后可以在ERP测试组织进行端到端试点。若申请小范
- 默认08:00执行收料文件获取,09:00执行自动调拨。
- 自动调拨始终调用统一文件准备服务,不假设08:00一定成功。
- 单个自动调拨排程可来源级多线程处理DBS和Crane;ERP写并发仍默认1。
- 单个自动调拨排程可按来源实例并发处理;ERP写并发仍默认1。
- 当前来源失败不阻断其他来源。
- 每个非空自动Run只发送一条企业微信汇总通知和一份异常Excel。
- 空数据为`success + no_data`,不通知。
- 每个自动Run只发送一条企业微信汇总通知;有异常时附一份异常Excel,空数据不附Excel。
- 空数据为`success + no_data`,仍发送一条“无可调拨数据”通知,不附Excel。
- 通知失败记录`notification_failed`,不改变ERP业务结果且不自动重试。
### 7.3 历史失败恢复矩阵
@@ -386,7 +386,7 @@ Phase 2完成后可以在ERP测试组织进行端到端试点。若申请小范
| 计划新增 | `backend/app/services/schedule/in_transit_transfer_job.py` | 09:00自动调拨任务 |
| 计划新增 | `backend/app/services/in_transit_transfer/backlog_service.py` | 待处理池、3/5/7天老化和责任人 |
| 计划新增 | `backend/app/services/in_transit_transfer/recovery_service.py` | 最新快照重新预检和新Attempt |
| 计划新增 | `backend/app/services/in_transit_transfer/retry_service.py` | 合法状态人工重试 |
| 计划新增 | `backend/app/services/in_transit_transfer/retry_service.py` | 合法状态人工重试,并区分重新抓取 RPA 与重新查询 ERP |
| 计划新增 | `backend/app/services/in_transit_transfer/manual_close_service.py` | 原因必填、永久关闭和审计 |
| 计划新增 | `backend/app/services/in_transit_transfer/excel_export.py` | 七Sheet异常Excel、Hash和原始行追溯 |
| 计划新增 | `backend/app/services/in_transit_transfer/notification.py` | 企业微信汇总、人员去重和独立失败状态 |
@@ -413,7 +413,7 @@ Phase 2完成后可以在ERP测试组织进行端到端试点。若申请小范
3. `Failed_Items`:明确业务失败和技术失败。
4. `Result_Unknown`:结果未知、Operation ID和人工核实提示。
5. `Backlog_Aging`:待处理年龄、3/5/7天等级和责任人。
6. `Source_Status`:DBS/Crane文件、checksum、准备结果和错误。
6. `Source_Status`:来源实例文件、checksum、准备结果和错误。
7. `Raw_Line_Trace`:Invoice对应Sheet、行号、原始数量和文件版本。
### 7.7 阶段验收
@@ -424,8 +424,8 @@ Phase 2完成后可以在ERP测试组织进行端到端试点。若申请小范
- [ ] 每次恢复创建新Attempt,旧Attempt不变。
- [ ] `result_unknown`和`manually_closed`自动ERP写入均为0。
- [ ] 3/5/7天老化等级和通知对象准确率100%。
- [ ] 每个非空自动Run企业微信汇总通知恰好1条。
- [ ] 空数据Run通知0条。
- [ ] 每个自动Run(包括空数据)企业微信汇总通知恰好1条。
- [ ] 空数据通知不附异常Excel,且ERP调用数为0。
- [ ] 七Sheet名称、字段、行数和Hash验证全部通过。
- [ ] 通知失败不改变ERP业务状态。
- [ ] 配置草稿、校验、Diff、发布和回滚均有完整审计。
@@ -482,8 +482,8 @@ Phase 2完成后可以在ERP测试组织进行端到端试点。若申请小范
### 8.5 UAT场景
- DBS Ready复用和实时RPA获取。
- Crane Callback正常、延迟、重复和来源不匹配。
- 来源实例 Ready复用和实时RPA获取。
- HTTP Callback正常、延迟、重复和来源不匹配。
- 当天收料不进入ERP。
- Invoice多行汇总后数量精确匹配。
- 用户取消部分可执行项并确认执行。
@@ -491,7 +491,7 @@ Phase 2完成后可以在ERP测试组织进行端到端试点。若申请小范
- 页面关闭后Run继续,重新登录恢复。
- 自动排程处理新增项和历史可恢复项。
- `result_unknown`人工核实、人工关闭和审计。
- 非空Run一条通知和七Sheet Excel;空数据不通知。
- 每个Run一条通知;有异常时附七Sheet Excel,空数据不附Excel。
- ERP测试组织创建、审核、过账并作废真实测试单。
### 8.6 上线策略
@@ -658,7 +658,7 @@ ERP SOAP / HTTP / 未来其他系统
| --- | --- | --- | --- |
| Q1 | ERP正式WSDL、字段、错误码、超时和可留存脱敏字段是什么? | Phase 0退出前 | 禁止进入真实ERP写入开发 |
| Q2 | ERP写超时后的人工核实SOP、责任人和完成时限是什么? | Phase 0退出前 | `result_unknown`无法安全运营 |
| Q3 | DBS/Crane正式收料样例、Sheet、表头和结构漂移规则是否齐全? | Phase 1开始前 | 文件解析和汇总验收不可执行 |
| Q3 | 各启用来源实例正式收料样例、Sheet、表头和结构漂移规则是否齐全? | Phase 1开始前 | 文件解析和汇总验收不可执行 |
| Q4 | 企业微信附件上限是否满足最大七Sheet Excel? | Phase 3开始前 | 需要切换为受控下载链接方案 |
| Q5 | 自动调拨完成率正式目标和人工处理基线是多少? | Phase 4上线前 | 无法证明业务收益 |
| Q6 | 所有Agent授权用户查看同权限Run的范围是否通过安全评审? | Phase 2上线前 | 可能产生跨用户数据暴露 |
@@ -720,7 +720,7 @@ ERP SOAP / HTTP / 未来其他系统
### 13.3 技术与体验指标
- 文件准备、解析、ERP查询、匹配、写入和通知各阶段P50/P95耗时。
- DBS/Crane来源成功率和超时率。
- 各来源实例成功率和超时率。
- ERP业务失败、技术失败、重复成功和结果未知占比。
- Chat首次进度反馈和Run恢复成功率。
- 企业微信通知和附件发送成功率。
@@ -790,5 +790,5 @@ ERP SOAP / HTTP / 未来其他系统
### 16.4 推荐下一步
召开一次Phase 0启动评审,只关闭四项:ERP WSDL及错误语义、结果未知人工SOP、DBS/Crane正式样例、权限范围。评审通过后,严格从TDD文档的L0失败测试和Fake ERP开始开发,不先写完整业务实现。
召开一次Phase 0启动评审,只关闭四项:ERP WSDL及错误语义、结果未知人工SOP、各启用来源实例正式样例、权限范围。评审通过后,严格从TDD文档的L0失败测试和Fake ERP开始开发,不先写完整业务实现。
@@ -213,6 +213,9 @@ WYC26071501
- 建单后工作台会持久展示订单解析结果;若新订单与旧任务同 PO 但字段冲突,系统会标出冲突并停住后续库存步骤,需您选择保留旧值、采用新值或手工修正后再继续。
- **要求交期、供应商料号、币种** 按**明细行**解析与导出;若 PDF 仅有一个文档级交期或币种,系统会回填到各行。
- **单价、金额、币种** 主要用于展示与导出,**不参与**「够不够货」的自动比对。
- 邮件正文补充字段与 PDF 的差异会明确展示字段、PDF/邮件双方取值和证据位置;单价等金额字段会先按数值语义比较,`1731.6`、`1731.60`、`1,731.60` 不属于冲突。同一 PO 的不同料号不会互相比较单价。
- 旧订单若只留下“补充来源字段冲突”而没有可展示的双方证据,系统不会静默放行;会显示“历史证据不足,建议重新识别此 PDF”。管理员重评估后,格式差异会解除,真实差异仍要求复核。
- 点击「保存并校验」后,如已满足自动建单资格,页面会显示“已自动入队建单并推进”;该提示表示后台 Worker 已接手,实际进度仍以任务处理状态为准。
- 若库存文件缺少发布方案要求的 Reservation ID、内部料号或数量栏位,系统会拒绝本次文件并提示管理员检查库存文件解析方案。
**订单行示例**(便于理解系统解析目标):
@@ -0,0 +1,145 @@
# 订单复核工作台文件切换性能优化与验收(2026-08-21)
## 1. 目标与边界
本次只优化订单复核工作台左侧文件队列的读取编排,不改变订单事实、草稿、确认建单、权限、访问审计或 Dify 业务边界。用户切换文件时,系统必须以最新选择为准;已过期的浏览器读取不得继续消耗不必要的服务端投影资源,更不得覆盖最新 Case。
不把单次浏览器网络截图直接等同于数据库慢查询结论。生产慢点须以本次增加的响应分段指标和真实 PostgreSQL 证据继续确认。
## 2. 根因证据
2026-08-21 的浏览器 Network 截图显示:
- `GET .../review` 约 89 ms 与 478 ms;
- `GET .../evidence` 约 71 ms;
- Case 快照约 656 ms;
- 相同 `SNER-20260821-5A563840` Run 读取出现两次,约 3.38 s 与 7.85 s,是当次最长请求。
代码链路确认:左侧 Case 切换由 `useShippingOrderReview.selectCase()` 并发读取 Case 快照和证据;聊天 Run 状态轮询也读取同一完整 Run DTO。`serialize_workspace_run()` 会读取 Unit、进度事件、Candidate、Review Case 与处理项;最小 SQLite 采样已有 9 条 SQL,且其中包含重复的进度事件、Candidate、Review Case 读取。该采样只能说明投影并非轻量接口,不能外推生产耗时。
因此已确认的根因是“重型 Run 投影被并发/重叠读取”和“快速切换仅丢弃旧结果、未取消旧 Case/evidence 请求”。截图缺少 HAR Initiator 与 PostgreSQL 执行计划,不能断言两条 SNER 都由单次切换直接发起,也不能在没有 `EXPLAIN (ANALYZE, BUFFERS)` 前猜测索引。
## 3. 已实施方案
### 3.1 同一 Run 的在途请求合并
`getWorkspaceShippingOrderExtractionRun()` 按 `run_no` 保存仅在途的 Promise。多个组件同时读取同一 Run 时复用一条 HTTP 请求;完成、失败或 10 秒超时后立即移除,不缓存已完成业务数据。调用方已取消只影响其发起前的调用,不取消其他消费者共享的读取。
这是“request coalescing / single-flight”模式,用于消除同一资源在客户端组件间的重复昂贵读取,同时不引入可能过期的客户端业务缓存。
### 3.2 latest-wins 的 Case 切换
Case 快照与 evidence API 接受可选 `AbortSignal`。每次 `selectCase()` 新建一个联合取消控制器,并先取消上一次 Case/evidence 读取;组件卸载、重新加载 Run 时同样取消。既有 `caseLoadGeneration` 与 `requestedCaseNo` 双校验继续保留,防止已到达但过期的响应写回 UI。
这符合交互型浏览器读取的 latest-wins 模式:取消只终止当前 HTTP 读取,绝不取消后台 Run、草稿保存、确认建单或审计语义。
### 3.3 服务端可观测性
`GET /api/workspace/shipping-notice/order-extraction-runs/{run_no}` 返回:
```text
Server-Timing: run_lookup;dur=<ms>, workspace_projection;dur=<ms>
```
它只包含耗时,不包含订单字段、PDF/EML 正文、对象存储定位、Prompt、凭据或其他敏感内容。浏览器 HAR 可据此区分 Run 查询与工作台投影,作为下一轮优化是否需要 PostgreSQL 计划分析或轻量 DTO 的依据。
## 4. 验收与回归证据
- 前端 TDD:新增同 Run 并发读取用例先验证 RED(两次调用会发出两条请求),实现后通过。
- 前端 TDD:新增快速切换时必须 abort 旧 Case 快照用例先验证 RED,实施后通过。
- 后端 TDD:新增 `Server-Timing` Header 断言先验证 RED,实施后通过。
- 前端定向回归:`npm run test:unit -- --run src/features/chat/api/shipping.api.request-dedupe.spec.ts src/features/chat/shipping/useShippingOrderExtractionRuns.spec.ts src/features/chat/shipping-review/useShippingOrderReview.spec.ts`,58 passed。
- 后端定向回归:`backend\\.venv\\Scripts\\python.exe -m pytest tests/test_shipping_order_extraction_runs.py -k "partial_success_isolated_per_pdf" -q`,1 passed。
- `git diff --check` 通过;工作区中存在与本次无关的既有 CRLF 提示和未提交改动,未改写。
完整后端整模块测试已启动并跑完,但当前终端执行器截断了最终汇总,不能将其作为通过证据;需在 CI 或本地保留完整日志后再登记。
本机运行态只读探测(2026-08-21):前端 Vite 服务 `127.0.0.1:3080` 与后端服务 `127.0.0.1:5052` 均可连接;未携带凭据读取目标 Run API 返回 `401`,符合用户态读取鉴权边界。因此不能在无已登录业务会话、也不读取或构造凭据的前提下,取得真实 Run 的 `Server-Timing` 或模拟左侧文件切换。
## 5. 上线后的真实 HAR 验收
1. 在生产同版本数据下打开 Network,勾选 Preserve log,并连续快速切换至少三个不同文件。
2. 确认同一时刻同一 `SNER` 只保留一条在途完整 Run GET;被跳过的 Case/evidence 请求应显示为 cancelled 或不再继续占用网络。
3. 打开其中一条 Run GET 的 Response Headers,记录 `Server-Timing` 两段耗时、总耗时、响应大小与 Initiator。
4. 若 `workspace_projection` 持续为主耗时,使用真实 PostgreSQL 对对应查询执行 `EXPLAIN (ANALYZE, BUFFERS)`,再决定是否批量预取、消除重复查询或拆分只读轻量 DTO。
5. 若 `run_lookup` 或连接等待为主耗时,检查连接池、慢 SQL、锁等待和网络路径;不得直接凭截图新增索引。
建议门槛:同一 Run 的重复重型 GET 为 0;非目标 Case 不得回写 UI;保留基线与优化后 p50/p95、取消数、`Server-Timing` 分段的对比。达到门槛后才可以宣称生产切换性能验收完成。
## 6. Dify 手工配置说明
本性能改动不要求修改 Dify:不新增画布、变量、Prompt、Tool、Provider 或密钥。订单抽取、Review Case、草稿、确认建单和本次读取治理均由 HXOPS 负责。
若环境已启用 `order-review-llm.v1` 字段建议分支,管理员仅做非破坏性核验:该分支不得调用业务写 Tool、自动确认、冻结或建单;Provider 不可用时人工复核仍可继续。不得在 Dify 中填写或复制任何 `Server-Timing`、请求 ID、订单正文、凭据或对象存储地址。
## 7. 后续决策
当前不新增“轻量 Run API”,因为尚无真实 `Server-Timing` 与 PostgreSQL 执行计划证明现有 DTO 的哪一段是主耗时。该接口只能在上述 HAR 验收显示投影持续主导、且字段消费边界清晰时,以独立契约、权限审查、审计与回归测试方式引入。
## 8. 最终阶段验收合规报告
| 阶段 | 目标与关键节点 | Review 结论 | 证据与状态 |
| --- | --- | --- | --- |
| 0:根因与基线 | 区分 Case/evidence 与完整 Run 请求;不把截图误判为 SQL 根因 | 截图、调用链和最小 SQL 采样相互印证;生产数据库结论未越界 | 通过(根因范围已确认) |
| 1:Run 读取治理 | 合并同 `run_no` 的并发重型读取;保留调用方取消语义;增加可观测性 | 用例覆盖合并与单消费者取消;DTO、鉴权、审计未改变;Header 不含敏感数据 | 通过(前端 2 个定向用例、后端 Header 用例) |
| 2:Case 切换治理 | 新选择取消旧 Case 与 evidence;旧响应不可覆盖新 Case | 联合 AbortSignal 和 generation / Case 编号双校验均在代码与测试中核对 | 通过(复核 composable 38 个用例) |
| 3:回归与范围 | 前后端行为、构建、格式;不引入 Dify 或业务状态改动 | 前端定向 58 passed;后端定向 1 passed;`git diff --check` 通过;前端 build 通过 | 通过(代码级) |
| 4:真实运行验收 | 真实业务数据 HAR、Server-Timing、p50/p95 和必要时 PostgreSQL 计划 | 无可复用已登录浏览器页面;本机只读 API 探测返回 401;Playwright 依赖 WSL `/bin/bash` 不可用 | 待业务环境人工验收,未计为生产通过 |
**整体结论**:本次前后端实现、自动化回归、正式技术说明和 Dify 手工说明已完成,且不存在已知未解决的代码级问题。生产级“切换耗时已达标”尚未被真实 HAR / PostgreSQL 证据证明,必须按第 5 节由具备业务登录态的人员完成后,才可关闭该外部验收项;在此之前不得对外宣称生产性能目标已验收通过。
## 9. 批次进度中心空白的根因与修复(2026-08-21)
### 已证实根因
真实会话 `29268344573b4fad8eb57532e9068fb3` 含 18 封 EML Intake、18 个邮件正文和 30 个业务 PDF。直接调用会话投影能正确返回 `total_files=30`、`waiting_human_files=30` 与 18 个待人工 EML 容器;因此“18 个文件”不是业务数据缺失,而是超时后的旧聊天快照回退值。
浏览器证据显示会话投影 GET 在约 10 秒被客户端取消。前端共享请求设置为 10 秒 Abort;修复前,服务端在同一会话内对每个 EML 再查询附件集合,并在 Intake 摘要重复统计附件,形成 N+1。真实会话测得 1091 条 SQL、约 7.79 秒(另一采样约 14.3 秒);超时后 `processing=null`,右侧原先渲染为 0,左侧回退到仅包含 18 个 EML 的历史快照。
### 实施内容
- `shipping_processing_projection.py` 在一次会话投影中批量读取全部非 `email_body` Document,并通过请求内只读上下文复用给 Intake 摘要及 EML 附件叶子;独立单条投影仍保留原查询语义。
- 同一上下文提前装载 Gate 的 latest Attempt,避免序列化 Process Gate 时按 Gate 再做主键查询。
- 批次重解析资格拆分为读写两条路径:会话/工作台 GET 使用无锁只读选取,且会话投影只计算一次并在请求内复用;实际 `POST reparse_batch` 仍使用 `FOR UPDATE` 锁定参与决策的 Case。禁止读投影调用写命令选择器。
- 右侧批次进度中心在投影尚未返回时显示骨架,在读取失败时显示可手动刷新的错误态;不再把“暂无投影”伪装为 `0` 个文件。
- 会话投影共享请求的超时由 10 秒调整为 30 秒。该值覆盖已测得的合法大批次读取,防止服务端仍在返回正确投影时被客户端提前取消;它不是对剩余 Gate/Job 投影 N+1 的替代方案。
### 回归与当前测量
- 新增/运行回归 `test_conversation_projection_prefetches_eml_attachments_once`:两封 EML / 两个附件的 Document SELECT 从失败基线 6 次收敛为 1 次,测试通过。
- 新增/运行回归 `test_conversation_projection_reparseability_read_path_does_not_lock`:会话投影不进入带锁写选择器,捕获 SQL 不含 `FOR UPDATE`;批次谱系写命令回归仍通过。
- 真实会话修复后仍准确返回:30 个业务文件、30 个待人工文件、18 个 EML 容器,状态顶层为 `waiting_human → EML → PDF`。
- 真实会话总 SQL 从 1091 降至 920;Gate、Job、Review Case、Run/Plan/Unit 仍存在其它既有逐行投影读取,后续需单列性能工作继续批量化,不能把本次附件查询修复误称为全部数据库 N+1 已清除。
## 10. 复核队列单次投影 N+1 治理(2026-08-22)
### 根因与边界
真实开发会话的 `GET /order-review-queue/{run_no}` 不慢在单 Case `review` DTO,而慢在会话级队列投影。28 个当前 Case 在逐项序列化时重复读取 Candidate、Intake、Draft、STP Job,以及 Process Gate 的最新 Attempt;同一次请求实测为 187 条 SQL、约 4.62 秒,浏览器侧还会叠加跨 Run 的重复读取。
批量预取后继续进行函数级采样,确认单次仍可能达到约 4 秒的第二根因:`psycopg2.fetchall` 内的 JSON 解码占约 2.96 秒,而 SQL 执行本身仅约 1.12 秒。队列授权路径将会话中的全部 Run 以完整 ORM 实体读取,队列联表又重复装配带有审计/执行大 JSON 的 Run;这些字段不属于队列摘要 DTO,却在传输后被逐个反序列化。
### 实施与等价性
- `serialize_review_queue()` 在读取当前 Stream 后一次性预取以上领域对象,建立并在 `finally` 恢复 `shipping_conversation_projection_read_cache`。
- STP 同时按精确幂等键与文件前缀缓存全部历史版本 Job,保持自动建单失败、运行中和重试裁决与原查询语义一致。
- Process Execution、Gate 与 latest Attempt 也按当前 Case 批量加载;生命周期、PO、权限、`available_actions`、阶段入口和前端 DTO 字段均未删除或改由前端推导。
- 队列可见性与联表投影改为只加载摘要必需的标量、冻结文档快照和 Case 处置字段;已批量读取的 Draft 显式传给摘要函数,避免关系延迟加载。完整 Run 读取 API 仍保持原 DTO/审计语义。
- 跨 Run 选择只修改深链,由既有路由 watcher 唯一执行 `load()`,避免 `router.replace()` 后第二次完整加载。
### 复测结果与 Dify
对同一真实 28 文件会话复测,最终两次队列读取为 27 条 SQL、0.899 秒与 0.718 秒,且 Review Case 的逐项延迟加载为 0。该数据为开发环境单次只读采样,不能替代生产 HAR 的 p95 验收。Dify 未新增或修改任何配置;本优化不涉及 Prompt、Provider、Tool、变量或凭据。
## 11. 最终阶段验收合规报告(2026-08-22)
| 阶段 | 目标与关键节点 | Review 结论 | 验收证据 |
| --- | --- | --- | --- |
| 1:根因确认 | 区分跨 Run 重复加载与单请求慢;以真实会话采样确认 SQL 与 JSON 解码占比 | 已确认前者由路由重复触发,后者由摘要路径装载大 JSON;未将开发采样外推为生产 p95 | 28 文件会话:187 SQL / 4.62 秒;函数级采样:JSON 解码约 2.96 秒 |
| 2:服务端读模型治理 | 批量预取 Case 依赖;仅加载摘要字段;保持历史 STP / Gate 裁决 | 无逐 Case 延迟加载;缓存仅限当前请求并在 finally 恢复;确认、冻结、权限与审计写路径不变 | 同会话复测:27 SQL、0.899 秒和 0.718 秒;逐项 Case lazy load 为 0 |
| 3:客户端切换治理 | 跨 Run 路由变更只触发一次 load | 路由 watcher 是唯一加载所有者;未删除任一文件选择、阶段或工作台入口 | `ShippingOrderReviewView.spec.ts` 跨 Run 单次加载用例通过 |
| 4:契约回归 | 冻结 Schema、客户确认事实、Gate action 和波次建单保持 fail-closed | 修复过期测试夹具,未放宽生产校验;客户确认必须由来源 Extraction 事实继承 | 后端完整:58 passed |
| 5:前端回归与构建 | 工作台生命周期、文件导航、成功上传证据和解析处置边界 | i18n mock 缺键和文本代理断言已改为可验证真实行为;生产翻译资源未改 | Spec 完整:69 passed;`vue-tsc -b`、`vite build` 通过 |
| 6:Dify 边界 | 说明人工配置职责,确认本次不触碰 Dify | 无 Dify 配置变更;若启用字段建议分支,仅按第 6 节进行非破坏性人工核验 | 第 6 节与第 10 节 Dify 说明 |
**总体结论**:代码级性能、行为和回归验收均达标。本次不含生产登录态 HAR / PostgreSQL 执行计划,因此生产 p50/p95 仍必须按第 5 节的人工运行验收补证;在取得该证据前,不得将开发库采样表述为生产 SLA。
+49 -1
View File
@@ -23,7 +23,41 @@
本次五阶段工作面调整**无需修改 Dify**。Dify 不能创建/推进 Gate,不能确认客户、裁决订单、匹配库存、生成 Excel、上传货代或登记回执;这些写入只由 HXOPS 服务端 Gate 校验后的工作台动作执行。若管理员维护现有 `shipping_notice` Chatflow,仍只能保留只读 `get_task_status` Tool,并原样传递 HXOPS 注入的短效能力令牌;发现任何写 Tool 或由 Dify 推断“已完成”时,应停止发布并移除。
## 2026-07-31 订单解析增强最终实施方案(待实施)
## 2026-08-21 PDF 订单解析证据链收口(已验收)
本节是当前 PDF 订单解析的实现与验收基线,优先于下方保留的历史“待实施”方案。此次不发布新版本、不修改既有 Profile 业务定义、不按文件名/订单号/客户/坐标变体写特例,也不新增独立 Evidence Package。
### 运行时事实与路由
- 原 PDF 是不可变源事实。`ensure_on_demand_coordinate_evidence()` 是唯一坐标补全入口:当前 Layout -> Run 快照补缺 -> 原生 PDF -> OCR;返回合并后的当前 Layout。任一关键坐标无法取得时固定输出 `coordinate_evidence_unavailable` 并进入 `review_required`。
- `matching_features.v1` 在压缩 `page_glyphs` 前持久化页面结构、主表框、表头及顺序、列数/中心/宽度和静态字段关系。它是稳定匹配输入,不升级命名;缺少关键特征不得从评分分母剔除后形成 `hard_match`。
- Profile 只识别版式身份;Schema 是唯一业务字段契约。订单头由 `page_glyphs + Profile field layout + Schema` 取值,订单行由 `table_glyphs + Profile table layout + Schema` 重建;两者共享同一个 Profile、Layout、Schema 和 `CoordinateTransform`。
- `CoordinateTransform` 统一处理归一化坐标及受限平移、缩放、小角度旋转。锚点不足、残差超限、越界、共线、非法矩阵或局部非线性失真必须 fail-closed,禁止强行命中。
- 普通 PDF、OCR、XFA datasets 和 AcroForm Widget 都输出相同 Observation 语义:`value_source`、`evidence_ref`、`transform_ref`、置信度和校验状态。XFA datasets 是正式值源;datasets 回退到 PDF/OCR 时保留 `fallback_from=xfa_dataset` 并固定 Review,不得自动建单。
- 路由固定为:唯一 Profile 命中走确定性模板解析;明确不存在特殊模板特征才走受限通用解析;`layout_drift`、`ambiguous`、证据不足、XFA/OCR 冲突全部 Review。所有候选最终必须通过统一 Candidate Qualification,Dify 不参与事实生成或 Gate。
### 通用解析与模板治理
- 自动标注只生成 Draft 的 `layout_schema_candidates`/建议,不能直接作为生产规则、不能自动接受、更不能自动发布。生产通用解析必须有冻结 `generic_parse_plan`,绑定 Schema、Layout、候选 checksum、映射决定及字段 `cell_id/evidence_ref`;Plan 缺失、漂移或证据缺失即 Review。
- **模板样本就绪门禁(2026-08-21)**:上传成功只表示 PDF/EML 已物化为 `ShippingOrderDocument`,不表示可自动标注。Draft annotation sample 必须由同一 `refresh_profile_sample_readiness()` 在当前 ready Layout 上验证视觉主表、内容 hash、canonical payload checksum、parser provenance,并冻结 `layout_version_id + layout_payload_checksum` 后,才返回 `automark_ready=true`。保存草稿、样本状态轮询和 `/pdf-automark` 入队共用此服务;一旦主表缺失/歧义、Layout 尚未完成或身份不一致,返回稳定原因码并禁止入队,绝不降级成“配置无效”或猜测。Worker 执行期仍复验 Job 的冻结身份。状态按 `profile_id + annotation sample` 隔离,同一文档被其他 Draft 引用不会影响当前模板。该回填仅更新现有 Draft sample 字段和追加式审计,不新建 Profile 版本、不修改已发布版本。
- Profile 仅允许 `draft -> published`;发布前必须满足 Schema/字段绑定校验、训练样本、独立盲测、双人批准、冻结样本证据及发布检查。已发布/退役版本只读;演进只能克隆为新 Draft,旧发布版本退役。管理端不提供自动接受、自动批准或自动发布路径。
### Dify 手工配置说明
此项由管理员手工完成,HXOPS 不调用 Dify 管理 API。保留 `shipping_notice` Chatflow 的只读任务状态与可选 Review 建议能力即可:Review 建议只能消费 HXOPS 下发的最小脱敏证据,并由人工确认后再由 HXOPS 校验写入草稿。必须删除或禁用所有订单抽取、附件遍历、模板匹配、Profile/Schema 写入、候选创建、Gate 推进、自动建单、库存/Excel/RPA 写入及“模型判断已完成”的 Tool、节点和连线。Dify 不可用不得影响 PDF/XFA/OCR 主解析、模板治理、Review 或 Candidate Qualification。
### 阶段验收报告
| 阶段 | 验收结论 | 关键证据 |
| --- | --- | --- |
| 1. 证据恢复与稳定特征 | 通过 | 当前 Layout 优先、快照补缺、原 PDF/OCR 恢复及不可恢复 Review 回归通过。 |
| 2. 几何归一化 | 通过 | Matcher、订单头和订单行共用受限变换;异常变换 fail-closed 回归通过。 |
| 3. PDF/OCR/XFA Observation 与 Gate | 通过 | 值源与证据引用统一;XFA fallback 固定 Review;Candidate Gate 无绕过路径。 |
| 4. 冻结 Parse Plan | 通过 | Plan 绑定 checksum 和字段证据;候选漂移、缺失或未限定均阻断至 Review。 |
| 5. 模板治理与管理端 | 通过 | 后端治理/发布/版本回归 114 项通过;前端无自动接受、批准或发布路径。 |
| 6. 最终工程校验 | 通过 | 解析主链定向回归、Python 编译、前端 `npm run build`、`git diff --check` 均通过。 |
## 2026-07-31 订单解析增强最终实施方案(历史待实施)
> **适用范围**:本节冻结“异型模板优先、通用确定性解析补位、Dify 仅辅助人工复核”的目标方案,作为后续开发、Review 与验收依据。现有模板库、复核工作台、任务中心和审计中心继续复用并增强,不新建第二套平行模块。本文不要求兼容旧 Dify 订单解析运行路径;历史业务订单、冻结 Snapshot 和审计事实仍永久只读保留。
@@ -941,6 +975,8 @@ MinerU 服务地址、无认证方式和 OpenAPI 已确认,并已取得脱敏
**坐标模板修复闭环 Review(2026-07-23)**:对于表头混入首条明细的 PDF,模板页显示“自动识别行版式”和“重建表格候选”。系统先建议从 `0` 到 `1` 严格递增的相对列边界,管理员按示例确认字段并可高级校准;系统仅使用同一 `ShippingDocumentLayoutVersion` 中表格 bbox 内的 PDF 原生字符重建网格。候选固定 `needs_review`,界面必须显式勾选审核确认后才可创建草稿。确认的边界随 Profile 定义冻结,Run 输入快照同时冻结对应的坐标证据;运行和盲测无法取得证据时阻断,不回读资产、不回退错误 MinerU 网格、不调用 Dify。坐标、页面图像、完整 PDF 正文和 MinerU 原始响应不返回浏览器或 Dify。
**表格边界校正(2026-08-21)**:当 MinerU 候选仅覆盖表头、表格 bbox 内没有明细起行,但同页完整 PDF/OCR 坐标存在唯一连续明细时,重建器仅沿原候选的纵向边界派生表格候选,并在明确 `Total`/终止行前收口。原始 MinerU bbox 保留为不可变事实,派生候选标记 `table_bbox_source=page_coordinate_derived`;无起行锚点、存在多义边界或来源冲突时保持 `needs_review`,禁止扩大框后猜测。普通表格候选通过完整性校验时继续使用原路径。
**模板页样本上传 Review(2026-07-23,2026-08-04 解耦修订)**:管理员可直接在“订单文档模板”页上传 PDF 或 EML。文件先写入用户私有 `FileAsset`,再创建 purpose=`order_document_profile_sample` 的独立 Intake;上传成功只要求 PDF Document 建立或 EML 完成 MIME 拆分并物化可用 Document。布局 Job 继续作为后台预热,但 queued/failed/unsupported 均不得阻断上传或把已物化文件显示为失败。盲测复核分三态:queued/running 为 `preparing` 且不可复核;failed/unsupported 为 `diagnostic`,可从原 PDF 临时恢复坐标帮助定位兼容性但禁止确认;仅 ready Layout 的真实 `table_id` 为 `formal_review`。正式预览返回 `layout_version_id + payload_checksum + parser` 身份,确认时重新校验并冻结到 TestSample,后续盲测执行读取该冻结 LayoutVersion,不读取 Document 当前最新布局。该 Intake 不绑定 Chat 会话,禁止创建 Candidate、业务指纹、重复决策、Task 或 Dify 调用。EML 正文与附件分别作为候选,附件不得自动合并;页面状态接口只返回文件物化状态和安全 Document 身份,不返回正文、HTML 或 bbox。PDF/EML 以外的文件由前后端双重拒绝。
MinerU 生产捕获固定使用 `pipeline`,通过 `/tasks` 异步提交、状态轮询和 `/result` 取回结果,不使用同步 `/file_parse` 长连接。Intake 不再内联调用 MinerU:它在持久化 Document/派生 FileAsset 后,同事务创建独立布局版本和 `shipping_document_layout` Job;布局 Worker 再读取对象存储并调用 Provider。`SHIPPING_NOTICE_LAYOUT_MINERU_ENABLED=false` 时不创建布局 Job;启用后只保存 `shipping_document_table_snapshot.v1` 的页/整表 bbox、HTML 表格与能力摘要,不保存 task 原响应、model output、content list 或非表格文本块。默认每个 Intake 最多 4 个支持文档;超量建立 `unsupported` 审计版本。所有 HTML/bbox 在 Dify Manifest 编译前剥离,仅 Profile 映射后的 `field_id/value/quote` 紧凑候选可进入 Dify。
@@ -2638,6 +2674,14 @@ primary_pdf_parsed_value
**核心原则**:当前裁决值优先 PDF ≠ 所有 PDF 冲突都允许自动建单。
#### 2.1 邮件补充字段冲突、历史重评估与校验后恢复(2026-08-21)
- 新产生的邮件正文补充冲突必须是可解释的 Finding:包含稳定 `conflict_key`、`field`、`scope`、`line_index`、`severity=blocking`、`resolution_status=unresolved`、规则版本,以及 PDF/邮件双方的 `raw_value`、规范化值、`document_id` 与 `evidence_ref`。Case 投影直接消费该 Finding 的双方来源;禁止再以空的旧 Observation 投影作为阻断依据。
- 比较必须服从冻结 Schema 的字段类型和行关联。金额按 decimal 规范化后比较,故 `1731.6`、`1731.60` 与 `1,731.60` 等价;同 PO 的明细只能按精确 `PO + MPN` 关联,禁止把另一料号行的 `unit_price` 误判为冲突。值确有语义差异时仍保持阻断,不能因 PDF 优先采值而静默放行。
- 历史 `reason=supplement_field_conflict` 没有双方原值/证据时不得仅因 Case 面板为空而放行。管理员可调用 `POST /api/admin/shipping-notice/legacy-supplement-conflicts/reassess`,按 `candidate_no` 或 `run_no` 重跑冻结 Run 输入、冻结订单和冻结 Schema:格式等价则清除旧假冲突,真实差异则重建当前完整 Finding;全量处理必须显式传入 `include_all=true` 和确认串 `REASSESS_LEGACY_SUPPLEMENT_CONFLICTS`。
- 冻结证据已不可恢复时,服务端将旧记录升级为 `supplement_conflict_evidence_insufficient`(仍为 blocking),并提供 `recovery_action=reparse_current_pdf`;前端必须展示“证据不足、建议重新识别此 PDF”,不得出现“没有显示冲突却不能推进”。每次重评估均重算 Candidate Qualification 并写统一审计;实际生产历史数据重评估须由管理员在批准环境执行。
- “保存并校验”由 `resume_after_review_change(..., allow_auto_create=True)` 统一执行资格、Gate 和幂等入队。前端只消费 API 的 `resume_outcome`:`auto_create_enqueued`、`already_queued`、`already_running` 均提示已入队等待 Worker;不得以本地字段完整度猜测下一步。此处只证明已入队,后续状态以 `ShippingProcessingProjection` 为准。
#### 3. 统一 ShippingProcessingProjection
推荐 API(阶段 4 接线):
@@ -2748,6 +2792,8 @@ pytest tests/test_shipping_notice_state_machine.py tests/test_shipping_notice_ui
- 附件选择、深度解析、扩批、预算、完整性门禁和自动冻结均由 HXOPS Worker/服务执行;字段复核建议只预填人工草稿且必须由 HXOPS 再验证。
- 完整手工节点顺序、代码、Prompt、Fail Branch 和验收用例以 [order-extraction-workflow-dify-guide.md](order-extraction-workflow-dify-guide.md) 为准。
**本次手工配置确认(2026-08-21)**:不要求新增或修改 Dify 节点、变量、Tool、Prompt 或自动化。若已启用 `order-review-llm.v1`,它只可返回单字段候选建议、原文 quote 和 document ID,且必须经过人工确认及 HXOPS 后端校验;不得裁决补充字段冲突、写正式事实、确认/建单或推进 Gate。Provider 不可用不得阻断人工复核、历史冲突重评估或自动建单队列。
### STP 阶段 0:字段契约冻结(2026-07-30,项次派生 Phase 0 纠偏)
- 标准资产 **58** 项;`shipping_order_fields` 唯一键为 `(field_code, scope)`,允许 Header/Line 同名 `reservation_id`。
@@ -3251,6 +3297,8 @@ Case 状态:`unreviewed`、`draft`、`ready`、`confirming`、`confirmed`、`n
工作台切换 PDF 时仅更新 `case` query,必须保留 `mode`、`run_no` 与原会话 query,防止主区误退回聊天欢迎页;切换后保持当前 `ReviewWorkbenchMode` 与字段区滚动位置。
**左侧文件切换读取治理(2026-08-21)**:完整 Run DTO 可能同时被聊天状态卡和复核工作台读取,前端按 `run_no` 合并仅在途的请求,完成、失败或超时后不缓存业务数据;单个消费者取消只结束其自身等待,不中止共享读取。Case 切换对 Case 快照和证据摘要采用同一个 `AbortController` 的 latest-wins 策略,新选择、重新加载或卸载立即取消旧读取,同时保留 generation / Case 编号双校验,禁止迟到数据回写。Run GET 返回不含敏感业务内容的 `Server-Timing: run_lookup;dur=<ms>, workspace_projection;dur=<ms>`,用于与真实 HAR 对齐;若投影持续为慢点,必须先取得 PostgreSQL `EXPLAIN (ANALYZE, BUFFERS)` 再决定查询或 DTO 演进。根因、测试证据、Dify 手工核验和上线验收门槛见 [review-workbench-file-switch-performance.md](./review-workbench-file-switch-performance.md)。
**本目标态 Dify 配置**:订单抽取、Review Case 状态、草稿保存、确认建单和聊天入口仍由 HXOPS 实现;唯一 Chatflow 需要增加按 `order-review-llm.v1` 硬路由的字段建议分支。该分支不得新增业务写 Tool、自动确认或冻结逻辑,Provider 不可用也不得阻断人工复核。
阶段 1 的只读接口为 `GET /api/workspace/shipping-notice/order-extraction-runs/{run_no}/review` 和 `GET /api/workspace/shipping-notice/order-review-cases/{case_no}`。DTO 只包含按冻结 Schema 安全投影的字段、行、状态、问题、动作和证据摘要;它不返回 PDF 正文、MinIO 地址/对象键、原始模型响应、Prompt 或未授权 Document。后续写接口由 Case 和冻结 Schema 决定可编辑字段,不能由浏览器传入任意 Schema、Document 或 evidence identity。
+4 -1
View File
@@ -95,9 +95,10 @@
| **订单模板版面签名 Matcher** | 代码已落地(待真实样本灰度) | 版面签名存 ValidationRun;Profile 轻量引用;Matcher 三态证据 + Top-N 解析验证;表头签名直接消费既有 `header_layout.region`,签名生成与运行时统一视觉词组和坐标口径;跨模板发布门禁与发布检查页;重识别亲和性校验签名;`SHIPPING_NOTICE_PROFILE_LAYOUT_SIGNATURE_REQUIRED` 控制全量切换。说明:[order-profile-layout-signature.md](features/shipping-notice/order-profile-layout-signature.md) |
| **XFA 数据路径 Profile(统一回退)** | 代码收口(2026-08-18) | datasets + 拆分规则为首选;失败进入普通 PDF 共用 PDFium/Widget/OCR 证据链,保留 `fallback_from`、原因码与 `value_source`,回退候选固定 Review、禁止 STP;Dify 主链:**NONE**。 |
| **XFA 统一视觉标注 + 字段拆分** | 统一入口已收口 | 普通 PDF/XFA 共用 Editor、`/pdf-automark` Job、保存、验证和发布 DTO;`value_binding` + `visual_binding`、RE2、统一 CQ/STP;XFA 仅在首选 datasets 取值与拆分规则上保留适配器差异。 |
| **PDF 订单解析证据链与冻结 Parse Plan** | 已验收(2026-08-21) | 原 PDF + `matching_features.v1` + 按需坐标恢复;统一几何变换、PDF/OCR/XFA Observation、Schema 单一契约、通用解析冻结 Plan 与 fail-closed Review。模板治理维持人工审核、独立盲测、发布检查和只读历史版本;Dify 主链 NONE。见 `technical.md`。 |
| **旧 XFA 合成预览/OCR 专用入口** | 已废弃 | 浏览器不得调用 `/xfa/automark`;内部 XFA 多源执行器由统一 `/pdf-automark` 调用,原生 PDF 页是统一画布。 |
| **XFA 字段拆分映射(历史)** | 已被统一方案接管 | 早期 `stages[]` 流水线与独立映射页能力将在统一方案阶段 1/4 对齐并收口;对照文档:[xfa-field-split-mapping.md](features/shipping-notice/xfa-field-split-mapping.md)。 |
| 订单模板录入 UX 重构(阶段 0-7) | 已完成 | 已完成 Draft Revision、Lease、向导、独立草稿编辑器自动保存、不可变验证运行与两步发布报告;样本上传仅负责资产保存和 PDF/EML Document 物化,版面解析作为后台预热且不阻断上传。盲测复核区分准备中、兼容性诊断和正式复核:仅 ready Layout 的真实 table_id 可确认,确认时冻结 LayoutVersion/checksum/parser 身份,执行不回读最新布局;临时 PDF 恢复仅作诊断。同模板族历史 annotation/training/新旧 blind test 文档可重新复核复用,当前版本建模样本仍严格排除。编辑器在可见状态自动续租。Dify 无需配置变更。 |
| 订单模板录入 UX 重构(阶段 0-7) | 已完成 | 已完成 Draft Revision、Lease、向导、独立草稿编辑器自动保存、不可变验证运行与两步发布报告;样本上传仅负责资产保存和 PDF/EML Document 物化,版面解析作为后台预热且不阻断上传。自动标注另经统一 Draft 样本就绪门禁:当前 ready Layout、唯一视觉主表、内容/hash/checksum/parser 身份均可验证时才幂等冻结样本证据并入队;保存、轮询、入队和 Worker 复验使用同一契约,失败展示可操作原因且不影响其他 Profile。盲测复核区分准备中、兼容性诊断和正式复核:仅 ready Layout 的真实 table_id 可确认,确认时冻结 LayoutVersion/checksum/parser 身份,执行不回读最新布局;临时 PDF 恢复仅作诊断。同模板族历史 annotation/training/新旧 blind test 文档可重新复核复用,当前版本建模样本仍严格排除。编辑器在可见状态自动续租。Dify 无需配置变更。 |
| 订单人工复核工作台(阶段 0-7) | 已实现 | 每个 PDF Unit 一个 Review Case,机器 Candidate/Extraction 不可变、人工 Draft 独立版本化;按 PDF 独立处置、证据复核与原子确认建单,不支持多订单 PDF 或跨 PDF 合并/拆分。字段和明细可按冻结 bbox 定位 PDF 原文(明细按 table/cell 反查),版本历史按需展开;确认后展示 `auto_progress` 真实结果/检查点并可直达任务进度工作台。单 PDF 重识别复用 WorkflowItem 真实状态展示已提交/版面解析/字段提取/草稿生成,完成后自动打开新版;“跳转当前版本”点击时强制刷新工作项,目标未就绪时明确提示。 |
| **复核工作台布局重构(阶段 0–5)** | 已实现(待真机视觉签署) | 替换旧三栏:主编辑区 + 阻断摘要侧栏;PDF **默认右下角浮动证据面板**(八向 resize、记忆尺寸位置、展开/移侧;用户主动「固定为侧栏」才双栏),不挤占订单网格;Ctrl/Cmd+滚轮与适合宽度/页面;溢出拖拽平移;双击字段定位与证据联动高亮;异常字段 Alt+[/] 导航;真正按需加载;Chat/证据/pdfjs 异步分包;AI/版本历史/完整检查按需抽屉且审计失败阻断展示;确认与自动推进态解耦并可重试;同事务入队 `shipping_notice_run`;单一主滚动 + sticky 底栏。真机三档 viewport 清单见 layout-plan §11.1。权威方案:[review-workbench-layout-plan.md](features/shipping-notice/review-workbench-layout-plan.md)。 |
| **复核工作台状态隔离(Case/证据/资格/自动化)** | 进行中(正式 OT 后分层已落地) | Case 切换请求代次 + 瞬态清理;正式 OT 后右侧主卡切自动处理、订单检查折叠、系统等待不冒充人工待办;`profile_match` 四态 + `field_completeness`;`completed_checks` 后端投影;`automation.phase` 区分建单前/后文案。契约:[review-workbench-state-isolation-contract.md](features/shipping-notice/review-workbench-state-isolation-contract.md)。 |
@@ -107,6 +108,8 @@
| **会话多任务聚合与统一提交(阶段 0–5)** | 整改中 | 契约冻结(§1.6.1);统一提交 + 独立 submission 幂等;同 PDF 指纹继承 OT(跨 Schema);投影按「当前有效最新 Run」;未查看 completed 仍可见;任务级取消/重试均走 Run API;状态四语言 + 更新时间。权威:technical.md §1.6.1。 |
| **多 EML / 直接 PDF / PDF 优先全链路重构(阶段 0–7)** | 蓝图 §六 表层基本对齐;workflow/batches DROP 推迟 | `co4`–`co7`:接入层、Notice/履约、`order_tasks`/evidences/notice_lines/document_versions、`processing_runs/units/plans/route_decisions`。待:DROP batches/workflows、FE 去旧 Workflow。 |
| **Candidate 统一自动建单资格** | 阶段 1 已实现 | 新增 `candidate_qualification_contract/service`、表 `shipping_order_candidate_qualifications`;三种解析来源统一门禁;模板批准仅 parser_trace;移除 LLM 天然阻断;STP 自动建单前持久化资格快照。 |
| **邮件补充冲突可解释性与历史重评估** | 已实现(2026-08-21) | 新 Finding 展示 PDF/邮件双方原值、规范化值与证据;金额语义比较、精确 `PO + MPN` 行关联;管理员可按 Candidate/Run 或受确认的全量操作重评估历史旧冲突,证据不足显示重新识别 PDF 恢复动作并保留阻断/审计。 |
| **复核保存校验自动入队反馈** | 已实现(2026-08-21) | Draft validate 保留后端 `resume_outcome`;`auto_create_enqueued`、已排队或运行中统一显示已入队,实际后续节点仅消费后端处理投影。 |
| **后台顺序自动推进 + Process Gate 对话恢复** | 已实现 | 自动链:库存准备→匹配→库存 RPA→Excel;货代上传 RPA 须 `SHIPPING_NOTICE_AUTO_UPLOAD_ENABLED` 显式 true 且通过就绪校验。RPA 中投影 `upload_rpa_pending` / `is_waiting_manual_upload=false`。对话侧 ProcessGateRecoveryCard;技术重试上限 3。 |
| **建单前统一恢复协调器(Gate/资格/auto_gate)** | 进行中(P0 缺陷已修,待正式验收) | `order_review_resume_service` + 行级履约 fail-closed(库存重校验、task 行不可 reopen、审计 before/after);复核侧栏置顶业务阻断,履约表格在库存模式;业务审计含白名单快照。权威:[process-gate-recovery-contract.md](features/shipping-notice/process-gate-recovery-contract.md)。 |
| **双工作台审计闭环** | 已实现(阶段 6) | 事件字典冻结 chat_* / review_* / process_gate_* / qualification / workflow_node;对话恢复写 `chat_process_gate_*`;审计中心分组与 Candidate/Gate 筛选;普通账本脱敏 + 敏感快照独立鉴权;覆盖率举证见 AUDIT_COVERAGE_MATRIX。 |
@@ -0,0 +1,176 @@
# Shipping Notice Five-Stage Lifecycle Implementation Plan
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
**Goal:** Make `接收解析 -> 订单复核 -> 通知准备 -> 货代上传 -> 通知完成` the only user-visible Shipping Notice lifecycle, where completion means verifiable freight-upload success.
**Architecture:** Keep Process Gate, Intake, Run/Unit, upload attempt and technical progress as execution facts. Extend the existing shared read-model projection with `freight_upload`; inject `upload_complete` only when the canonical success predicate confirms task status, every reservation and an audit-backed succeeded upload attempt. API consumers receive `lifecycle_nodes`; `four_stage_nodes` remains a one-release compatibility alias.
**Tech Stack:** Flask, SQLAlchemy, pytest, Vue 3, TypeScript, Vue I18n, Vitest.
---
### Task 1: Define the server-side lifecycle and success predicate
**Files:**
- Modify: `backend/app/services/shipping_notice/lifecycle_projection.py`
- Modify: `backend/app/services/shipping_notice/ui_state.py`
- Modify: `backend/app/services/shipping_notice/process_gate_contract.py`
- Test: `backend/tests/test_shipping_notice_ui_state.py`
- [ ] **Step 1: Add failing assertions for the new stage and completion boundary**
```python
assert state['lifecycle_stage'] == 'freight_upload'
assert [entry['code'] for entry in state['lifecycle_entries']][-2:] == [
'freight_upload', 'upload_complete',
]
assert completed_state['lifecycle_stage'] == 'upload_complete'
```
- [ ] **Step 2: Run the focused UI-state test**
Run: `cd backend; pytest -q tests/test_shipping_notice_ui_state.py`
Expected: failing assertions because the current implementation has four lifecycle stages.
- [ ] **Step 3: Implement one canonical predicate and five-stage projection**
```python
def has_verified_upload_success(task: ShippingNotice) -> bool:
return (
task.upload_status == 'uploaded'
and reservations_are_uploaded(task)
and has_succeeded_upload_attempt(task)
)
if has_verified_upload_success(task):
lifecycle_stage = 'upload_complete'
elif gate_code in LIFECYCLE_STAGE_BY_GATE:
lifecycle_stage = LIFECYCLE_STAGE_BY_GATE[gate_code]
```
Map `freight_upload_rpa`, `manual_upload_handoff`, and all upload-pending/failure/unknown reasons to `freight_upload`. Map only a verified success to `upload_complete`; update Gate `ui_placement.target_surface` to `freight_upload`.
- [ ] **Step 4: Re-run the focused UI-state test**
Run: `cd backend; pytest -q tests/test_shipping_notice_ui_state.py`
Expected: PASS.
### Task 2: Evolve batch projection without breaking callers
**Files:**
- Modify: `backend/app/services/shipping_notice/shipping_processing_projection.py`
- Modify: `backend/tests/test_shipping_processing_projection.py`
- Modify: `backend/tests/test_shipping_processing_projection_stage4.py`
- [ ] **Step 1: Add failing batch-node assertions**
```python
assert [node['code'] for node in payload['lifecycle_nodes']] == [
'intake_parse', 'order_review', 'fulfillment_prep', 'freight_upload', 'upload_complete',
]
assert payload['four_stage_nodes'] == payload['lifecycle_nodes']
```
- [ ] **Step 2: Implement `lifecycle_nodes` and compatibility alias**
```python
lifecycle_nodes = _batch_lifecycle_nodes(work_items)
payload['lifecycle_nodes'] = lifecycle_nodes
payload['four_stage_nodes'] = lifecycle_nodes # deprecated compatibility field
```
Use the shared success predicate when deriving an item lifecycle so technical `completed`, a PDF candidate, a reference number, cancellation, or archive cannot make an item complete.
- [ ] **Step 3: Run the projection tests**
Run: `cd backend; pytest -q tests/test_shipping_processing_projection.py tests/test_shipping_processing_projection_stage4.py tests/test_shipping_projection_cross_surface.py`
Expected: PASS.
### Task 3: Make all frontend surfaces consume five lifecycle stages
**Files:**
- Modify: `frontend/src/features/chat/types/shipping.api.types.ts`
- Modify: `frontend/src/features/chat/shipping/shippingStepper.ts`
- Modify: `frontend/src/features/chat/components/shipping/ShippingConversationProcessingCard.vue`
- Modify: `frontend/src/features/chat/views/ShippingOrderReviewView.vue`
- Modify: `frontend/src/features/workspace/shipping-task-center/ShippingTaskCenterPage.vue`
- Modify: `frontend/src/features/shipping-progress/components/WorkbenchProgressGrouped.vue`
- Test: `frontend/src/features/chat/shipping/shippingStepper.spec.ts`
- Test: `frontend/src/features/chat/views/ShippingOrderReviewView.spec.ts`
- Test: `frontend/src/features/chat/components/shipping/ShippingConversationProcessingCard.spec.ts`
- [ ] **Step 1: Add failing five-stage type and rendering tests**
```ts
expect(resolveShippingWorkflowSteps({ ui_state: { steps } })).toHaveLength(5)
expect(wrapper.text()).toContain('货代上传')
expect(wrapper.text()).toContain('通知完成')
```
- [ ] **Step 2: Update shared types and Stepper**
Add `'freight_upload'` to `LifecycleWorkbenchStage`, stage-node DTOs and the five label-key array. Prefer `lifecycleNodes`; retain the old field only as an API fallback.
- [ ] **Step 3: Split the lifecycle workbench surfaces**
`freight_upload` hosts Excel download, RPA retry/poll, manual evidence registration and unknown-result reconciliation. `upload_complete` becomes read-only success evidence: uploaded time, freight receipt/reference, succeeded attempt and reservation summary. Do not move action authorization into the frontend.
- [ ] **Step 4: Ensure polling does not stop at freight-upload**
Keep polling while `lifecycleStage === 'freight_upload'`; stop only after verified `upload_complete`, cancellation, archive, or explicit terminal failure.
- [ ] **Step 5: Run focused frontend tests**
Run: `cd frontend; npm run test:unit -- shippingStepper.spec.ts ShippingOrderReviewView.spec.ts ShippingConversationProcessingCard.spec.ts`
Expected: PASS.
### Task 4: Synchronize i18n and documentation
**Files:**
- Modify: `frontend/src/locales/zh-CN/chat.json`
- Modify: `frontend/src/locales/zh-TW/chat.json`
- Modify: `frontend/src/locales/en/chat.json`
- Modify: `frontend/src/locales/th/chat.json`
- Modify: `frontend/src/locales/zh-CN/workspace.json`
- Modify: `frontend/src/locales/zh-TW/workspace.json`
- Modify: `frontend/src/locales/en/workspace.json`
- Modify: `frontend/src/locales/th/workspace.json`
- Modify: `docs/demand.md`
- Modify: `docs/tec.md`
- Modify: `docs/funclist.md`
- Modify: `docs/features/shipping-notice/technical.md`
- Modify: `docs/features/shipping-notice/business.md`
- [ ] **Step 1: Add all four-language stage and work-surface labels**
Add `freightUpload` and descriptions for upload in progress, manual upload pending, failure, and unknown result. Retain `uploadComplete` text as `通知完成`; its description must require verified success.
- [ ] **Step 2: Update the authoritative business and technical contracts**
Replace four-stage wording with the five-stage order. Document the single success predicate, unknown-result handling, `lifecycle_nodes` compatibility period, and the rule that completed lists/statistics use verified success only.
- [ ] **Step 3: Validate locale JSON**
Run: `Get-ChildItem frontend/src/locales/*/{chat,workspace}.json | ForEach-Object { Get-Content -Raw $_ | ConvertFrom-Json | Out-Null }`
Expected: no output and exit code 0.
### Task 5: Full verification
**Files:**
- Verify all modified files.
- [ ] **Step 1: Run focused backend regression**
Run: `cd backend; pytest -q tests/test_shipping_notice_ui_state.py tests/test_shipping_upload_attempt.py tests/test_shipping_manual_upload_evidence.py tests/test_shipping_upload_unknown_state.py tests/test_shipping_processing_projection.py tests/test_shipping_processing_projection_stage4.py tests/test_shipping_projection_cross_surface.py`
Expected: PASS.
- [ ] **Step 2: Build frontend**
Run: `cd frontend; npm run build`
Expected: PASS.
- [ ] **Step 3: Check diff integrity**
Run: `git diff --check; git status --short`
Expected: no whitespace errors; status lists only the planned files plus pre-existing user changes.
@@ -0,0 +1,264 @@
# Shipping Profile Anchor Frame Implementation Plan
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
**Goal:** 让坐标 Profile 能在同一稳定版式因动态内容导致主表纵向平移时,使用冻结的锚点坐标框架完成确定性匹配和取值,而不影响未启用该能力的模板。
**Architecture:** 在现有 `OrderCoordinateProfile` 中增加可选的扁平 `coordinate_model` 声明(`type`、`anchors`、`max_translate_x`、`max_translate_y`)。matcher 从当前 Layout 的唯一锚点和主表结构计算受限的平移变换;同一变换贯穿表头观测、主表定位、订单头字段和值框、订单行坐标重建,禁止建立第二套偏移估算机制。
**Tech Stack:** Flask、Pydantic、SQLAlchemy JSON Profile、pytest、Vue 3、TypeScript、Vue I18n、Vitest。
## Global Constraints
- 原 PDF 是不可变事实;匹配和解析所需的页级坐标必须通过 `ensure_on_demand_coordinate_evidence()` 获取。
- 未声明 `coordinate_model.type = anchor_frame` 的 Profile 必须逐位保持现有 matcher、取值、阈值和候选排序行为。
- 不允许按订单号、客户名、文件名或固定偏移量写代码;不建立按 PDF 的坐标变体。
- 仅允许平移;锚点不存在、不唯一、位移超过模板上限、关键结构冲突或多个 Profile 合格时必须 `review_required`。
- Schema 是唯一业务字段契约;Dify 不参与模板选择、坐标变换或正式值取值。Dify 配置由用户维护,本项目仅在收尾文档说明其边界。
- 不改数据库表结构、不新增依赖、不修改其他 Profile 数据;FOX MX Profile 现版数据在后端能力通过回归后再单独受控更新。
---
### Task 1: 冻结 Profile 契约与变换审计输出
**Files:**
- Modify: `backend/app/services/shipping_notice/document_layout/order_profile.py`
- Modify: `backend/app/services/shipping_notice/document_layout/order_profile_matcher.py`
- Test: `backend/tests/test_shipping_order_profile_matcher.py`
**Interfaces:**
- Produces `CoordinateModel` / `AnchorFrameCoordinateModel`,作为 `OrderCoordinateProfile.coordinate_model`。
- Produces `CoordinateTransform`,包含 `status`、`translate_x`、`translate_y`、`anchor_ids`、`reason_codes`;仅含配置身份与数值,不含正文。
- Extends `ProfileMatchCandidate` with optional `coordinate_transform`.
- [ ] **Step 1: 写入失败用例**
```python
def test_anchor_frame_matches_same_structure_after_bounded_vertical_translation():
profile = _with_signature(_profile('PO_A', coordinate_model={
'type': 'anchor_frame',
'anchors': [{'anchor_id': 'title', 'text': 'PURCHASE ORDER', 'region': {'x0': .1, 'y0': .05, 'x1': .9, 'y1': .15}}],
'max_translate_x': .01, 'max_translate_y': .04,
}), _layout())
result = match_frozen_coordinate_profiles(profiles=[profile], layout=_translated_layout(.03))
assert result.status == 'unique_match'
assert result.candidates[0].coordinate_transform['translate_y'] == .03
```
- [ ] **Step 2: 验证 RED**
Run: `cd backend; .\\venv\\Scripts\\python.exe -m pytest -q tests/test_shipping_order_profile_matcher.py -k anchor_frame`
Expected: FAIL,因为 Profile 契约尚不接受 `coordinate_model`,且 matcher 未输出变换。
- [ ] **Step 3: 最小实现**
```python
class AnchorFrameCoordinateModel(OrderProfileModel):
type: Literal['anchor_frame']
anchors: list[AnchorRule] = Field(min_length=1, max_length=4)
max_translate_x: float = Field(default=.03, ge=0, le=.15)
max_translate_y: float = Field(default=.06, ge=0, le=.20)
class CoordinateModel(OrderProfileModel):
type: Literal['legacy', 'anchor_frame'] = 'legacy'
anchor_frame: AnchorFrameCoordinateModel | None = None
```
在 matcher 中仅当 `anchor_frame` 明确启用时从唯一静态锚点计算一致的 X/Y 平移;超界、缺失、歧义或多个锚点不一致必须为硬失败原因。对当前观察表头和主表 bbox 应用该平移后才评分;`legacy` 路径不改。
- [ ] **Step 4: 验证 GREEN 与旧逻辑回归**
Run: `cd backend; .\\venv\\Scripts\\python.exe -m pytest -q tests/test_shipping_order_profile_matcher.py`
Expected: PASS;新增用例覆盖受限平移、缺锚点、歧义锚点、超界平移和 legacy 不变。
### Task 2: 让已选变换贯穿 Profile 行重建
**Files:**
- Modify: `backend/app/services/shipping_notice/order_extraction_workflow.py`
- Modify: `backend/app/services/shipping_notice/document_layout/coordinate_table_reconstruction.py`
- Test: `backend/tests/test_shipping_coordinate_table_reconstruction.py`
- Test: `backend/tests/test_shipping_generic_order_gate.py`
**Interfaces:**
- Consumes `ProfileMatchResult` 中唯一选中 Profile 的 `coordinate_transform`。
- Extends `reconstruct_coordinate_profile_rows(..., coordinate_transform: dict | None = None)`。
- Produces仅以同一运行时平移投影后的表区/行区重建结果。
- [x] **Step 1: 写入失败用例**
```python
def test_reconstruction_uses_selected_anchor_frame_translation_for_all_subrows():
rows = reconstruct_coordinate_profile_rows(
characters=_translated_rows(.03), table_bbox=_page_bbox(),
table_region=_legacy_region(), line_layouts=_layouts(),
coordinate_transform={'status': 'applied', 'translate_x': 0, 'translate_y': .03},
)
assert rows[0].fields['customer_po_line_no'] == '00010'
```
- [x] **Step 2: 验证 RED**
Run: `cd backend; .\\venv\\Scripts\\python.exe -m pytest -q tests/test_shipping_coordinate_table_reconstruction.py -k anchor_frame`
Expected: FAIL,因为重建函数没有接收或应用运行时变换。
- [x] **Step 3: 最小实现**
为坐标重建增加仅限 `status=applied` 的平移投影;校验平移数字有限且投影框仍在页内,非法变换返回现有的不可重建结果。工作流必须从共同 matcher 的唯一结果传递同一 `coordinate_transform`,不能重新计算、不能按 raw table 猜测偏移。
- [x] **Step 4: 验证 GREEN 与路由门禁**
Run: `cd backend; .\\venv\\Scripts\\python.exe -m pytest -q tests/test_shipping_coordinate_table_reconstruction.py tests/test_shipping_generic_order_gate.py`
Expected: PASS;缺失/非法变换保持 `coordinate_evidence_unavailable → review_required`,其他 Profile 路由不变。
### Task 3: 管理端声明与复核端审计展示
**Files:**
- Modify: `frontend/src/features/admin/types/shipping-order-document-profile.types.ts`
- Modify: `frontend/src/features/admin/modules/shipping-order-document-profiles/OrderProfileEditorPage.vue`
- Modify: `frontend/src/features/chat/types/shipping.api.types.ts`
- Modify: `frontend/src/features/chat/components/shipping-review/ReviewProfileMatchPanel.vue`
- Modify: `frontend/src/locales/zh-CN/chat.json`
- Modify: `frontend/src/locales/zh-TW/chat.json`
- Modify: `frontend/src/locales/en/chat.json`
- Modify: `frontend/src/locales/th/chat.json`
- Test: `frontend/src/features/chat/components/shipping-review/ReviewProfileMatchPanel.spec.ts`
**Interfaces:**
- Admin payload accepts optional `coordinate_model`,默认 `legacy`,只有管理员显式确认时才提交 `anchor_frame`。
- Review DTO exposes `coordinate_transform` only for the selected/current candidate and reason codes only.
- [x] **Step 1: 写入失败的前端展示用例**
```ts
it('shows anchor-frame translation only in the technical template-match detail', () => {
const wrapper = mount(ReviewProfileMatchPanel, { props: { profileMatch: anchorFrameMatch } })
expect(wrapper.text()).toContain('锚点坐标框架')
expect(wrapper.text()).toContain('纵向平移')
})
```
- [x] **Step 2: 验证 RED**
Run: `cd frontend; npm run test:unit -- ReviewProfileMatchPanel.spec.ts`
Expected: FAIL,因为 DTO 和面板尚未呈现坐标框架诊断。
- [x] **Step 3: 最小实现**
在现有 Profile 编辑器增加受控的“相对锚点坐标框架”选项:默认关闭,启用时要求至少一个唯一静态 AnchorRule 与 X/Y 上限。复核面板只展示模式、是否应用、X/Y 平移和稳定 reason code;不显示原始字符、不显示完整 PDF 坐标、不新增终端用户操作。
- [x] **Step 4: 验证 GREEN、四语一致和构建**
Run: `cd frontend; npm run test:unit -- ReviewProfileMatchPanel.spec.ts; npm run build`
Expected: PASS;所有新增 i18n key 存在于四种语言,构建无 TypeScript 错误。
### Task 4: 当前 FOX MX 现版数据、端到端回归与正式文档
**Files:**
- Modify: `docs/demand.md`
- Modify: `docs/tec.md`
- Modify: `docs/funclist.md`
- Modify: `docs/features/shipping-notice/technical.md`
- Modify: `docs/features/shipping-notice/business.md`
- Modify: current database Profile `61` only after Task 1-3 pass
- Test: `backend/tests/test_shipping_order_profile_matcher.py`
- Test: `backend/tests/test_shipping_coordinate_table_reconstruction.py`
- Test: `frontend/src/features/chat/components/shipping-review/ReviewProfileMatchPanel.spec.ts`
**Interfaces:**
- FOX MX current Profile uses `coordinate_model.type = anchor_frame`; it has no order-number-specific rule and no stored A/B variant.
- Dify document only explains that Dify must not participate in this deterministic path; it contains no credentials or platform mutation.
- [ ] **Step 1: 增加真实 Layout 回归测试**
```python
def test_fox_mx_anchor_frame_matches_baseline_and_dynamic_vertical_shift(app):
assert _match_profile_layout(profile_id=61, layout_id=124).status == 'unique_match'
assert _match_profile_layout(profile_id=61, layout_id=346).status == 'unique_match'
assert _match_profile_layout(profile_id=61, layout_id=344).status == 'unique_match'
```
- [ ] **Step 2: 验证 RED**
Run: `cd backend; .\\venv\\Scripts\\python.exe -m pytest -q tests/test_shipping_order_profile_matcher.py -k fox_mx_anchor_frame`
Expected: FAIL,直到当前 Profile 明确声明 `anchor_frame` 且现版签名/定义一致。
- [ ] **Step 3: 受控更新现版 Profile 数据**
只在 Task 1-3 的全量相关测试通过后,事务更新 Profile 61 的 `definition_json`、结构指纹、checksum、matching signature 及其 validation run;不新建版本。变换锚点仅取固定标题/表头等静态文本,基线为 `4210007483.pdf`,回归样本为 `4210012208.pdf` 和 `4210012210.pdf`。
- [ ] **Step 4: 完成端到端验证和正式文档**
Run: `cd backend; .\\venv\\Scripts\\python.exe -m pytest -q tests/test_shipping_order_profile_matcher.py tests/test_shipping_coordinate_table_reconstruction.py tests/test_shipping_order_field_extraction.py tests/test_shipping_generic_order_gate.py`
Run: `cd frontend; npm run test:unit -- ReviewProfileMatchPanel.spec.ts; npm run build`
Run: `git diff --check`
Expected: 全部 PASS;正式文档包含架构、失败闭环、其他模板隔离、FOX MX 校准规则及 Dify 手动配置边界。
## Phase Review Gates
| 阶段 | 关键节点 | 放行证据 |
| --- | --- | --- |
| 1 | 范围/数据基线/既有能力 | 本计划、Profile 61 回滚校验、2208/2210 差异证据、未影响其他 Profile 的 DB 查询 |
| 2 | 契约/Matcher/行重建 | RED→GREEN 测试、legacy 回归、缺锚/歧义/超界 fail-closed 测试 |
| 3 | 管理端/复核端/i18n | Vitest、四语言 JSON 解析、前端 build、无新增用户端越权动作 |
| 4 | 数据/全链路/文档 | 三份 FOX PDF 真实 Layout 回归、相关后端测试、前端 build、`git diff --check`、文档一致性检查 |
## Phase 1 Review Record
- [x] 原因确认:2026-08-20 将 Profile 61 的表格/表头/行布局整体下移 `0.0124703088`,使 Layout 344 命中但 Layout 346 发生 `profile_header_signature_conflict`。
- [x] 基线恢复:Profile 61 与 validation run #150 已恢复至 `4210007483.pdf` 对应的历史冻结定义;Layout 124 和 346 已复算为 `unique_match`。
- [x] 范围确认:不采用按 PDF 的 A/B 变体,不改变全局 matcher 阈值,不改 Dify,不新增数据库表。
- [x] 影响确认:本阶段仅修改计划文档;已有数据库恢复仅涉及 Profile 61,其他 6 个 Profile 未写入。
- [x] 下一阶段准入:已具备最小契约、测试和隔离边界,可进入后端 TDD。
## Phase 2 Review Record
- [x] 契约/Matcher:`legacy` 默认路径保持 `coordinate_transform=None`;`anchor_frame` 仅由唯一静态锚点计算有限平移,缺失、歧义、不一致、超界均 fail-closed。
- [x] 评分一致性:matcher 对当前观察和七维结构评分均使用不回写冻结签名的平移副本;签名校验仍使用冻结签名原文。
- [x] 行重建:共同 matcher 选中的变换只经 Profile 身份校验后传入工作流;页级裁剪、表区、物理行、字段区、终止/排除区使用同一内存投影。
- [x] Fail-closed:非法/缺失变换不回退旧绝对坐标,保持 `order_profile_coordinate_reconstruction_unavailable -> coordinate_evidence_unavailable`。
- [x] 回归证据:matcher 24 passed;坐标重建 40 passed;通用路由门禁 22 passed。
- [x] 范围 Review:未新增数据库表、依赖、Profile 版本或 Dify 配置;未改变订单头第二套取值机制;其他 legacy Profile 调用点默认行为不变。
- [x] 下一阶段准入:后端变换闭环已完成并通过阶段验收,进入管理端/复核端/i18n 实现。
## Phase 3 Review Record
- [x] DTO 契约:前端与后端统一使用扁平 `coordinate_model`(`type`、`anchors`、`max_translate_x`、`max_translate_y`),不保留嵌套变体。
- [x] 管理端:默认 `legacy`;仅显式选择 `anchor_frame` 才提交配置;锚点为空、无坐标或 X/Y 上限越界时保存门禁阻断;legacy 不写新字段。
- [x] 复核端:仅管理员技术详情展示模式、应用状态、X/Y 平移和 reason code;普通用户不显示坐标框架诊断;不输出原始正文或完整坐标。
- [x] 四语言:zh-CN、zh-TW、en、th 均补齐 `coordinateModel` 与管理端配置文案。
- [x] Header 闭环:订单头字段读取消费 matcher 已选同一 `coordinate_transform`,订单号/日期/币种不再独立使用旧绝对框。
- [x] 自动化证据:后端相关测试 123 passed;复核投影测试 3 passed;前端 ReviewPanel 5 passed;`npm run build` passed。
- [x] 范围 Review:未新增数据库表、依赖、Dify 配置或用户端动作;legacy Profile 和其他模板默认路径保持不变。
- [x] 下一阶段准入:阶段 3 合规 Review 通过,可进入现版 FOX MX Profile 61 受控数据校准。
## Phase 4 Review Record
- [x] 数据基线复核:Profile 61 当前 `definition_json` 与历史 revision 51 逐项一致;附件 `4210007483.pdf` 的表头、订单号标签、订单号值框与现版坐标一致,未发现需要恢复的坐标。
- [x] 订单号根因:PDFium 原生字符将 `ORDER NO.:` 嵌在整行文本中;旧的锚点匹配将整行作为 `exact` 比较对象,导致锚点无法命中,根因不是 Profile 坐标偏移。
- [x] 最小修复:matcher 在视觉行内定位锚点子串并使用锚点自身 bbox;未改变 Profile 61 的定义、字段/表格坐标、版本号或其他 Profile 数据。
- [x] 真实回归:Layout 124 为 `unique_match`(0.985938),Layout 346 为同 Profile `unique_match`(0.889008),Layout 344 为 `evidence_insufficient` 并进入 Review;禁止证据不足时高分自动命中。
- [x] 订单头取值:Layout 124 确定性读出 `customer_po_number=4210007483`,状态 `confirmed`,来源 `pdf_coordinate`;日期、币种、目的地等绑定字段均通过。
- [x] 范围与数据隔离:未新建 Profile 版本、未更新 Profile 61 数据、未修改其他 Profile、未修改 Dify 配置;数据库写入范围为零。
- [x] 下一阶段准入:后端 matcher、订单头/订单行相关回归及前端构建完成后,进入最终阶段验收报告。
## Final Phase Acceptance Report
| 阶段 | 验收结果 | 证据 |
| --- | --- | --- |
| 4A 基线核验 | 通过 | Profile 61 当前定义与 revision 51 一致;PDF 实测坐标未支持坐标回写 |
| 4B matcher 修复 | 通过 | `tests/test_shipping_order_profile_matcher.py`:25 passed;行内 `ORDER NO.:` 锚点可定位自身字符框 |
| 4C 影响 Review | 通过 | Layout 124/346 唯一匹配;Layout 344 `evidence_insufficient`;订单号 `4210007483` confirmed |
| 4D 数据边界 | 通过 | version=1 保持不变;未新建版本、未修改其他 Profile、未写入 Profile 61 数据、未修改 Dify |
| 5 全链路验收 | 通过 | 后端 124 passed;ReviewPanel 5 passed;前端 `npm run build` 通过;`git diff --check` 通过 |
结论:该阶段工作满足“原 PDF 不可变、Schema 唯一契约、证据不足进入 Review、无坐标变体、其他模板隔离”的要求。订单号识别问题由行内锚点匹配修复解决,不通过修改现版 Profile 坐标规避。
+3
View File
@@ -65,7 +65,9 @@
- **状态契约**:`state_machine.checkpoint_kind`(`auto_continue` / `must_human` / `wait_manual_upload` / `complete`)+ `ui_state.summary`(当前待办、暂停原因、下一自动步骤、`entry_surface`)为唯一 UI 读模型;前端禁止估算进度。
- **写操作面(双工作台架构 2026-08-02)**:对话工作台承载主入口、状态投影与轻量写操作(正式 Workspace API);人工复核承载建单前深度编辑;Task 页面仅为备用深链。Chat Turn 履约写路径废弃。权威:[review-workbench-layout-plan.md](features/shipping-notice/review-workbench-layout-plan.md) §0、[technical.md](features/shipping-notice/technical.md) §1.6。
- **Candidate Qualification**:模板质量资格与候选自动建单资格分离;三种解析来源统一门禁;前端类型 `WorkbenchSurface` / `CandidateQualificationStatus` / `WorkflowNodeStatus`。
- **补充字段冲突契约与历史兼容**:新冲突以包含稳定键、字段/行、Schema 规范化双方值和双侧证据的 blocking Finding 为唯一门禁事实;金额等按 Schema 语义比较,行级关系固定为精确 `PO + MPN`。历史无证据旧 Finding 通过管理员受控重评估冻结 Run 输入、订单和 Schema;不能恢复时升级为带 `reparse_current_pdf` 恢复动作的证据不足阻断,禁止以空 UI 投影放行。
- **自动推进**:`progress_workflow.auto_progress` 与后续节点顺序由后端状态机固定;前端只消费投影,禁止估算进度百分比。
- **复核保存恢复**:Draft validate 调用统一恢复协调器,资格满足时幂等入队自动建单;响应的 `resume_outcome` 是页面唯一提示来源。`auto_create_enqueued` 仅表示队列已受理,后续运行状态仍读取 `ShippingProcessingProjection`。
- **待办**:`query_service.list_my_todos` / `count_my_todos` + `/shipping-tasks/my-todos`;创建者可处理,管理员只读;打开后优先对话聚焦或复核。
- **Dify**:画布仍由管理员手工配置;架构阶段结束时补充配置说明,代码侧不代改。
@@ -95,6 +97,7 @@
- L3 扫描 PDF 直接适配 RapidOCR 多边形坐标,OCR cell 必须同时通过 OpenCV 网格和全部非空 cell 文本一致性;EML HTML 只保留清洗后的 table DOM,并用逻辑网格表达 rowspan/colspan。OCR/HTML 均固定 needs_review,原始 OCR 响应、页面图、主动 HTML 和临时表格片段不入库或 Dify;相关实现变化由 parser 内容指纹自动隔离缓存。
- L4 新增 layout.v1→冻结 Schema 映射层,复用现有 HTML Grid 安全规则并保留真实 cell/token evidence。Run snapshot 升级为 v3并冻结内部 `layout_schema_candidates`;跨页只读显式 continuation。Manifest 强制剥离布局及映射候选,needs_review 不参与当前确定性执行。
- 订单坐标 Profile v2 的真相是 `document_match + table_regions[]`:每个表区保存相对区域、独立 `header_layouts[]`、连续的 `line_layouts[]`、字段区域到稳定 `field_id + field_code` 的绑定、受控解析器、排除/终止和跨页规则。表头只参与建议、校准和匹配,不能决定字段;所有区域为 `0..1` 相对坐标,越界、正面积重叠、重复明细字段和错序物理行由后端拒绝。
- **PDF 证据与通用解析收口(2026-08-21)**:原 PDF 为不可变源事实,`ensure_on_demand_coordinate_evidence()` 是唯一恢复入口;`matching_features.v1` 固定保存与 Profile 无关的页面/表格/表头/列特征。统一 `CoordinateTransform` 由稳定锚点估计有限仿射,锚点不足或残差异常即 Review。PDF、OCR、XFA datasets 和 Widget 经统一 Observation 输出来源、证据和变换引用;Profile 仅匹配版式,Schema 负责业务字段,`generic_parse_plan` 冻结 Schema/Layout/候选 checksum 与字段证据。证据缺失、漂移、歧义和 XFA fallback 均 fail-closed 至 Review,并统一通过 Candidate Qualification。
- **XFA 数据路径 Profile + 审计架构(2026-08-18)**:`template_mode` 鉴别联合为 `coordinate | xfa_dataset`;Layout 先探测 `/AcroForm`/`/XFA`,但不得因 XFA capability 提前中断通用 PDF Layout。运行时优先 datasets + 拆分规则;datasets 不能产值时复用普通 PDF 的 PDFium/原生坐标与 OCR 证据管线,observation 明确记录 `value_source`;Widget 作为视觉绑定/自动标注的独立证据。回退保留 `fallback_from=xfa_dataset` 与 datasets 原因码,CQ 将其固定为 `xfa_fallback_requires_review`,禁止 STP。审计仍仅保存脱敏 diff/checksum 与受控快照;Dify 不参与主链。
- **XFA 统一视觉标注 + 安全拆分选型(2026-08-05 冻结)**:
- **统一 binding**:`value_binding`(XFA=`xfa_dataset`;普通 PDF=`pdf_coordinate`/`ocr_coordinate`)+ `visual_binding`(页码、归一化 bbox、source、status、confidence)+ 可选 `split_rule_ref`。正式字段必须双绑定确认后才可发布。