feat(shipping-notice): 完善订单模板解析与库存 RPA 调度流程

- 新增行字段补充合并与订单模板匹配能力
- 优化运行时解析策略、签名校验及资料验证
- 完善库存 RPA 归档、收尾与 Worker 启动流程
- 补充前后端测试、多语言文案及功能文档
This commit is contained in:
hugo committed 2026-09-09 14:32:43 +08:00
1 parent 8f2f568f92
commit dabf140e41
45 files changed
+2007 -151

No files matched your search

@@ -294,7 +294,7 @@ export function useScheduleAdminRuns(
const a = document.createElement('a');
a.href = url;
const disposition = res.headers.get('content-disposition');
a.download = disposition?.match(/filename\*?=(?:UTF-8'')?["']?([^;"'\n]+)/)?.[1] || 'inventory-rpa-raw.zip';
a.download = disposition?.match(/filename\*?=(?:UTF-8'')?["']?([^;"'\n]+)/)?.[1] || '库存RPA-库存.zip';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
@@ -1115,6 +1115,19 @@ const nextOrderFieldSequence = (targetPageNo: number): number => {
const beginFormEdit = () => {
pendingFormEdit = snapshot();
};
/**
* 将选中物理行标记为主明细或 LN 补料号补充表(如 COO)。
* 核心逻辑:写入 tableRegionRole 后走同一 finishFormEdit,保存时按角色拆成两个 table_regions。
*/
const onSelectedLineTableRegionRoleChange = (event: Event): void => {
const target = selectedRegion.value;
if (!target || target.kind !== 'line') return;
const value = (event.target as HTMLSelectElement).value;
target.tableRegionRole = value === 'line_field_supplement'
? 'line_field_supplement'
: 'business_lines';
finishFormEdit();
};
/**
* 记录字段改绑前的共同视觉身份。
*
@@ -1549,12 +1562,51 @@ const definition = () => {
.map((item) => item.pageNo),
)]
.sort((left, right) => left - right)
.map((regionPageNo) => {
.flatMap((regionPageNo) => {
const regionSettings = ensureTableRegionSetting(regionPageNo);
const pageItems = normalizedRegions.filter(
(item) => item.pageNo === regionPageNo,
);
const lineRegions = pageItems.filter((item) => item.kind === "line");
const roles: Array<'business_lines' | 'line_field_supplement'> = [
'business_lines',
'line_field_supplement',
];
return roles.flatMap((regionRole) => {
const lineRegions = pageItems.filter(
(item) =>
item.kind === "line"
&& (item.tableRegionRole || 'business_lines') === regionRole,
);
const supplementLineRegions = pageItems.filter(
(item) =>
item.kind === "line"
&& (item.tableRegionRole || 'business_lines') === 'line_field_supplement',
);
/** 表头中心点是否落在补充表明细行并集内(含少量纵向余量)。 */
const headerOverlapsSupplement = (header: typeof pageItems[number]): boolean => {
if (!supplementLineRegions.length) return false;
const cy = (header.region.y0 + header.region.y1) / 2;
const cx = (header.region.x0 + header.region.x1) / 2;
return supplementLineRegions.some((line) => {
const pad = Math.max(0.01, (line.region.y1 - line.region.y0) * 0.5);
return (
cx >= line.region.x0
&& cx <= line.region.x1
&& cy >= line.region.y0 - pad
&& cy <= line.region.y1 + pad
);
});
};
// 表头只挂在业务明细区;补充表(COO)不携带 header_layouts。
// 落在补充行附近的表头不得并入 business,否则会污染版面签名 header_tokens。
const pageHeaderItems = regionRole === 'business_lines'
? pageItems.filter(
(item) => item.kind === "header_field" && !headerOverlapsSupplement(item),
)
: [];
if (!lineRegions.length && !pageHeaderItems.length) {
return [];
}
const groupedLineFields = groupUniqueOrderProfileLineFields(
pageItems,
lineRegions.map((item) => item.id),
@@ -1579,14 +1631,14 @@ const definition = () => {
lineFields.value.map((field) => field.field_code),
);
};
const headerLayouts = pageItems
.filter((item) => item.kind === "header_field" && item.parentId)
const headerLayouts = pageHeaderItems
.filter((item) => item.parentId)
.reduce<string[]>((layoutIds, item) => {
if (!layoutIds.includes(item.parentId!)) layoutIds.push(item.parentId!);
return layoutIds;
}, [])
.map((layoutId) => {
const fields = pageItems.filter(
const fields = pageHeaderItems.filter(
(item) =>
item.kind === "header_field" && item.parentId === layoutId,
);
@@ -1608,7 +1660,7 @@ const definition = () => {
});
const layoutRegions = [
...lineRegions,
...pageItems.filter((item) => item.kind === "header_field"),
...pageHeaderItems,
];
const tableRegion = layoutRegions.length
? {
@@ -1624,12 +1676,15 @@ const definition = () => {
? fieldRegionsFor(firstLineRegion.id).map((item) => item.field_code)
: [],
);
return {
region_id: `main_lines_page_${regionPageNo}`,
return [{
region_id: regionRole === 'line_field_supplement'
? `line_supplement_page_${regionPageNo}`
: `main_lines_page_${regionPageNo}`,
// 仅为旧 schema 提供兼容形状;运行时会自动选择适用页范围。
page_scope: 'exact_page' as const,
page_no: regionPageNo,
region: tableRegion,
region_role: regionRole,
line_start_field_code: resolveLineStartFieldCode(mainLineFieldCodes),
// 仅为旧 schema 提供兼容形状;运行时固定/自适应策略并行评估。
row_reconstruction_mode: 'fixed_subrows' as const,
@@ -1661,6 +1716,7 @@ const definition = () => {
(item) =>
(item.kind === "field" || item.kind === "header_field") &&
item.parentId &&
lineRegions.some((line) => line.id === item.parentId) &&
(!item.fieldCode ||
(item.kind === "header_field" && !coordinateFieldScope(item.fieldCode)) ||
(item.kind === "field" && !boundLineFieldRegionIds.has(item.id))),
@@ -1671,7 +1727,8 @@ const definition = () => {
label: item.label,
region: item.region,
})),
};
}];
});
});
const visualDefinition: OrderCoordinateProfileDefinition = {
// 主表身份由创建向导冻结;编辑器保存时随定义原样携带,不能退化为只存 sample.table_id。
@@ -2727,6 +2784,7 @@ const restoreRegions = (profile: ShippingOrderDocumentProfile) => {
label: item.layout_id,
region: item.region,
pageNo: regionPageNo,
tableRegionRole: table.region_role || 'business_lines',
})),
...table.line_layouts.flatMap((line) =>
line.field_regions.map((item, index) => ({
@@ -3443,6 +3501,20 @@ onBeforeUnmount(() => {
{{ line.label }}
</option>
</select></label
><label v-if="selectedRegion.kind === 'line'"
>{{ t('admin.shippingOrderProfiles.workbench.tableRegionRole')
}}<select
:value="selectedRegion.tableRegionRole || 'business_lines'"
class="select-field"
:disabled="compactEditor || saveState === 'readonly'"
@focus="beginFormEdit"
@change="onSelectedLineTableRegionRoleChange"
>
<option value="business_lines">{{ t('admin.shippingOrderProfiles.workbench.tableRegionRoles.business_lines') }}</option>
<option value="line_field_supplement">{{ t('admin.shippingOrderProfiles.workbench.tableRegionRoles.line_field_supplement') }}</option>
</select>
<small>{{ t('admin.shippingOrderProfiles.workbench.tableRegionRoleHint') }}</small>
</label
><label v-if="['header_field', 'field', 'order_field'].includes(selectedRegion.kind)"
>{{ t("admin.shippingOrderProfiles.workbench.schemaField")
}}<select
@@ -11,6 +11,8 @@ export type OrderProfileExtractorKey = 'direct' | 'temp_internal_parts' | 'quant
export type OrderProfileEvidenceLevel = 'coordinate' | 'ocr_coordinate';
export type OrderProfileAllowedSource = 'pdf_coordinate' | 'ocr_coordinate';
export type OrderProfileRowReconstructionMode = 'fixed_subrows' | 'adaptive_record_columns';
/** 主明细命中源 vs 同文档按 LN 补料号的补充表(如 COO)。 */
export type OrderProfileTableRegionRole = 'business_lines' | 'line_field_supplement';
export type OrderProfileChangeSource = 'wizard_created' | 'manual_save' | 'autosave' | 'restore' | 'sample_changed';
export type OrderProfileLeaseState = 'active' | 'expired' | 'released' | 'taken_over';
export type OrderProfileValidationRunType = 'instant_check' | 'current_sample' | 'blind_test' | 'scenario_coverage' | 'schema_compatibility' | 'layout_signature' | 'cross_template_overlap' | 'xfa_structure_signature';
@@ -72,7 +74,26 @@ export interface OrderProfileOrderFieldLayout { layout_id: string; field_id: str
export interface OrderProfileDraftUnboundOrderFieldLayout { layout_id: string; label: string; page_scope: 'first_page' | 'all_pages' | 'exact_page'; page_no?: number | null; anchor?: OrderProfileAnchorRule | null; value_region?: OrderProfileAnchorRelativeRegion | null; absolute_value_region?: OrderProfileRelativeRegion | null; fallback_value_region?: OrderProfileRelativeRegion | null; value_mode: 'single_line' | 'multi_line' | 'right_of_anchor' | 'below_anchor'; stop_anchors: OrderProfileAnchorRule[]; minimum_evidence_level: OrderProfileEvidenceLevel; }
export interface OrderProfileHeaderLayout { layout_id: string; region: OrderProfileRelativeRegion; field_regions: OrderProfileFieldRegion[]; }
export interface OrderProfileLineLayout { layout_id: string; row_offset: number; role: 'main' | 'continuation'; region: OrderProfileRelativeRegion; field_regions: OrderProfileFieldRegion[]; new_line_anchor?: OrderProfileAnchorRule | null; continuation_conditions: OrderProfileAnchorRule[]; required_fields: string[]; allowed_empty_fields: string[]; }
export interface OrderProfileTableRegion { region_id: string; page_scope: 'first_page' | 'all_pages' | 'continuation_pages' | 'exact_page'; page_no?: number | null; region: OrderProfileRelativeRegion; /** 逻辑明细起行锚点;默认 customer_po_line_no;line_no 为可识别内部项次亦可绑定。 */ line_start_field_code?: string; /** 默认固定子行;仅显式启用时允许在同一逻辑明细内跨视觉行按列重建。 */ row_reconstruction_mode?: OrderProfileRowReconstructionMode; /** 管理员确认的视觉行结构来源;审计用途,不是字段正式值源。 */ visual_evidence_source?: 'pdf_coordinate' | 'ocr_coordinate' | 'opencv_geometry' | 'acroform_widget_geometry' | null; header_layouts: OrderProfileHeaderLayout[]; line_layouts: OrderProfileLineLayout[]; continuation_rule: { allow_cross_page: boolean; required_anchor_ids: string[] }; termination_rules: Array<{ rule_id: string; anchor: OrderProfileAnchorRule }>; exclusion_regions: OrderProfileRelativeRegion[]; draft_unbound_field_regions?: Array<{ region_id: string; parent_layout_id: string; label: string; region: OrderProfileRelativeRegion }>; }
export interface OrderProfileTableRegion {
region_id: string;
page_scope: 'first_page' | 'all_pages' | 'continuation_pages' | 'exact_page';
page_no?: number | null;
region: OrderProfileRelativeRegion;
/** 主明细命中源(默认)或同文档 LN 补料号补充表。 */
region_role?: OrderProfileTableRegionRole;
/** 逻辑明细起行锚点;默认 customer_po_line_no;line_no 为可识别内部项次亦可绑定。 */
line_start_field_code?: string;
/** 默认固定子行;仅显式启用时允许在同一逻辑明细内跨视觉行按列重建。 */
row_reconstruction_mode?: OrderProfileRowReconstructionMode;
/** 管理员确认的视觉行结构来源;审计用途,不是字段正式值源。 */
visual_evidence_source?: 'pdf_coordinate' | 'ocr_coordinate' | 'opencv_geometry' | 'acroform_widget_geometry' | null;
header_layouts: OrderProfileHeaderLayout[];
line_layouts: OrderProfileLineLayout[];
continuation_rule: { allow_cross_page: boolean; required_anchor_ids: string[] };
termination_rules: Array<{ rule_id: string; anchor: OrderProfileAnchorRule }>;
exclusion_regions: OrderProfileRelativeRegion[];
draft_unbound_field_regions?: Array<{ region_id: string; parent_layout_id: string; label: string; region: OrderProfileRelativeRegion }>;
}
export interface OrderProfileDocumentMatch { document_type: 'purchase_order'; page_pattern: 'one_or_more'; required_anchors: OrderProfileDocumentMatchAnchor[]; optional_anchors: OrderProfileDocumentMatchAnchor[]; minimum_score: number; minimum_margin: number; }
/**
@@ -968,6 +989,8 @@ export interface OrderProfileCanvasRegion {
stopAnchorText?: string | null;
/** 标记所属文档页;画布切页时仅渲染当前页的区域。 */
pageNo: number;
/** 物理行所属表区角色;补充表(如 COO)保存为 line_field_supplement。 */
tableRegionRole?: OrderProfileTableRegionRole;
/** datasets adapter 可附加的视觉证据确认状态,不影响共同画布区域种类。 */
visualBindingStatus?: XfaVisualBindingStatus;
/** 工作台待确认候选的临时视觉标记;不会进入 Profile 保存 payload。 */
@@ -18,7 +18,9 @@ const i18n = createI18n({
title: '文档模板匹配', subtitle: '摘要', selected: '命中模板', noSelected: '未选定模板',
expandCandidates: '查看候选模板({count})', collapseCandidates: '收起候选模板',
routeType: '路由类型', executionMode: '执行模式',
extractionBlocked: '模板已命中,但字段提取仍被安全门禁阻断', extractionBlockedReason: '阻断原因:{reasons}',
extractionBlocked: '模板已命中,但字段提取仍被安全门禁阻断',
extractionBlockedNoMatch: '模板未唯一命中,字段提取被阻断',
extractionBlockedReason: '阻断原因:{reasons}',
coordinateModel: {
anchorFrame: '锚点坐标框架', status: '变换状态', translateX: '横向平移',
translateY: '纵向平移', reasonCodes: '原因码',
@@ -122,6 +124,30 @@ describe('ReviewProfileMatchPanel', () => {
// 关键断言:唯一模板命中不等于字段已提取,必须明确暴露下游阻断原因。
expect(wrapper.get('[data-testid="review-profile-match-extraction-blocked"]').text())
.toContain('PARSE_STRATEGY_ROW_MODE_AMBIGUOUS');
expect(wrapper.get('[data-testid="review-profile-match-extraction-blocked"]').text())
.toContain('模板已命中');
});
it('未选定模板时阻断文案不得再写模板已命中', () => {
const wrapper = mount(ReviewProfileMatchPanel, {
props: {
profileMatch: {
available: true,
visibility: 'admin',
status: 'evidence_insufficient',
needs_review: true,
selected_profile: null,
candidates: [],
fallback_reason_codes: ['coordinate_evidence_unavailable'],
},
},
global: { plugins: [i18n] },
});
const blocked = wrapper.get('[data-testid="review-profile-match-extraction-blocked"]').text();
expect(blocked).toContain('模板未唯一命中');
expect(blocked).not.toContain('模板已命中');
expect(blocked).toContain('coordinate_evidence_unavailable');
});
it('管理员技术详情展示锚点框架平移和稳定原因码,不展示原始正文或完整坐标', async () => {
@@ -43,10 +43,20 @@ const selectedCoordinateTransform = computed(() => {
const coordinateTransformReasonCodes = computed(() => (
selectedCoordinateTransform.value?.reason_codes || []
));
/** 唯一命中仅证明版式身份;下游字段/明细恢复若受门禁阻断,必须在同卡明确说明。 */
/** 唯一命中仅证明版式身份;下游字段/明细恢复若受门禁阻断,必须在同卡明确说明。
* 未选定模板时不得再写「模板已命中」,避免与上方「未选定模板」矛盾。 */
const extractionBlockReasons = computed(() => (
(props.profileMatch?.fallback_reason_codes || []).filter((code) => String(code).trim())
));
const hasSelectedProfile = computed(() => Boolean(
String(props.profileMatch?.selected_profile?.profile_code || '').trim()
|| String(props.profileMatch?.selected_profile?.display_name || '').trim(),
));
const extractionBlockedTitle = computed(() => (
hasSelectedProfile.value
? t('chat.shippingOrderReview.profileMatch.extractionBlocked')
: t('chat.shippingOrderReview.profileMatch.extractionBlockedNoMatch')
));
watch(
() => `${props.profileMatch?.status || ''}:${props.profileMatch?.selected_profile?.profile_code || ''}:${candidateCount.value}`,
@@ -117,7 +127,7 @@ const selectedLabel = computed(() => {
class="mt-3 rounded-lg border border-amber-200 bg-amber-50 px-2.5 py-2 text-xs text-amber-900 dark:border-amber-900 dark:bg-amber-950/30 dark:text-amber-100"
data-testid="review-profile-match-extraction-blocked"
>
<p class="font-medium">{{ t('chat.shippingOrderReview.profileMatch.extractionBlocked') }}</p>
<p class="font-medium">{{ extractionBlockedTitle }}</p>
<p class="mt-1 text-amber-800 dark:text-amber-200">
{{ t('chat.shippingOrderReview.profileMatch.extractionBlockedReason', { reasons: extractionBlockReasons.join(', ') }) }}
</p>
+6
View File
@@ -3699,6 +3699,12 @@
"noIssues": "No blocking configuration issue.",
"currentConfiguration": "Current configuration",
"tableRegionSettings": "Line table settings",
"tableRegionRole": "Table region role",
"tableRegionRoles": {
"business_lines": "Business line table (primary)",
"line_field_supplement": "Line-field supplement (e.g. COO, fill part numbers by LN)"
},
"tableRegionRoleHint": "Supplement tables must bind line number plus part fields; they are not business-line hits. Formal parse, blind test, and validation merge by LN.",
"coordinateModelTitle": "Coordinate value model",
"coordinateModelHint": "Legacy frozen absolute coordinates are used by default. Enable this only for bounded translation with stable static anchors.",
"coordinateModelType": "Coordinate model",
+1
View File
@@ -2462,6 +2462,7 @@
"routeType": "Route type",
"executionMode": "Execution mode",
"extractionBlocked": "The template matched, but a safety gate still blocked field extraction",
"extractionBlockedNoMatch": "No unique template match; field extraction was blocked",
"extractionBlockedReason": "Blocking reason: {reasons}",
"score": "Score {score}",
"reselectHint": "If the template is wrong or the layout drifted, use “Reparse this PDF” at the top. Gate re-route is on the recovery card below.",
+6
View File
@@ -3568,6 +3568,12 @@
"noIssues": "ไม่มีปัญหาการตั้งค่าที่ขัดขวาง",
"currentConfiguration": "การตั้งค่าปัจจุบัน",
"tableRegionSettings": "การตั้งค่าตารางรายละเอียด",
"tableRegionRole": "บทบาทของตาราง",
"tableRegionRoles": {
"business_lines": "ตารางรายละเอียดธุรกิจ (หลัก)",
"line_field_supplement": "ตารางเสริมฟิลด์รายการ (เช่น COO เติมเลขชิ้นส่วนตาม LN)"
},
"tableRegionRoleHint": "ตารางเสริมต้องผูกเลขบรรทัดและฟิลด์เลขชิ้นส่วน ไม่ใช่แหล่ง hit รายละเอียดหลัก การ parse / ทดสอบตาบอด / ตรวจยืนยัน จะรวมตาม LN",
"coordinateModelTitle": "โมเดลค่าพิกัด",
"coordinateModelHint": "ค่าเริ่มต้นใช้พิกัดสัมบูรณ์ที่แช่แข็ง เปิดใช้งานเฉพาะเมื่อมีการเลื่อนที่จำกัดและจุดยึดคงที่เท่านั้น",
"coordinateModelType": "โมเดลพิกัด",
+1
View File
@@ -2462,6 +2462,7 @@
"routeType": "ประเภทเส้นทาง",
"executionMode": "โหมดการทำงาน",
"extractionBlocked": "พบเทมเพลตแล้ว แต่การดึงข้อมูลฟิลด์ยังถูกบล็อกโดยเกตความปลอดภัย",
"extractionBlockedNoMatch": "ยังไม่จับคู่เทมเพลตแบบเฉพาะเจาะจง การดึงข้อมูลฟิลด์ถูกบล็อก",
"extractionBlockedReason": "สาเหตุที่บล็อก: {reasons}",
"score": "คะแนน {score}",
"reselectHint": "หากเทมเพลตผิดหรือเลย์เอาต์เพี้ยน ใช้ “ระบุ PDF นี้อีกครั้ง” ด้านบน การเปลี่ยนเส้นทางเกตอยู่ในการ์ดกู้คืนด้านล่าง",
+6
View File
@@ -3811,6 +3811,12 @@
"noIssues": "没有阻断配置问题。",
"currentConfiguration": "当前配置",
"tableRegionSettings": "明细表区设置",
"tableRegionRole": "表区角色",
"tableRegionRoles": {
"business_lines": "业务明细表(主表)",
"line_field_supplement": "明细字段补充表(如 COO,按 LN 补料号)"
},
"tableRegionRoleHint": "补充表须绑定行号与待补料号字段,不参与主表明细命中;正式/盲测/验证按 LN 合并。",
"coordinateModelTitle": "坐标取值模型",
"coordinateModelHint": "默认使用冻结绝对坐标;仅在版式存在受限平移且有稳定静态锚点时启用。",
"coordinateModelType": "坐标模型",
+1
View File
@@ -2581,6 +2581,7 @@
"routeType": "路由类型",
"executionMode": "执行模式",
"extractionBlocked": "模板已命中,但字段提取仍被安全门禁阻断",
"extractionBlockedNoMatch": "模板未唯一命中,字段提取被阻断",
"extractionBlockedReason": "阻断原因:{reasons}",
"score": "得分 {score}",
"reselectHint": "若模板不对或版面漂移,请使用顶部「重新识别此 PDF」;门禁重路由见下方恢复卡片。",
+6
View File
@@ -3573,6 +3573,12 @@
"noIssues": "沒有阻斷設定問題。",
"currentConfiguration": "目前設定",
"tableRegionSettings": "明細表區設定",
"tableRegionRole": "表區角色",
"tableRegionRoles": {
"business_lines": "業務明細表(主表)",
"line_field_supplement": "明細欄位補充表(如 COO,依 LN 補料號)"
},
"tableRegionRoleHint": "補充表須綁定行號與待補料號欄位,不參與主表明細命中;正式/盲測/驗證依 LN 合併。",
"coordinateModelTitle": "座標取值模型",
"coordinateModelHint": "預設使用凍結絕對座標;僅在版式存在受限平移且有穩定靜態錨點時啟用。",
"coordinateModelType": "座標模型",
+1
View File
@@ -2462,6 +2462,7 @@
"routeType": "路由類型",
"executionMode": "執行模式",
"extractionBlocked": "範本已命中,但欄位擷取仍被安全閘門阻擋",
"extractionBlockedNoMatch": "範本未唯一命中,欄位擷取被阻擋",
"extractionBlockedReason": "阻擋原因:{reasons}",
"score": "得分 {score}",
"reselectHint": "若範本不對或版面漂移,請使用頂部「重新識別此 PDF」;門禁重路由見下方恢復卡片。",