feat(shipping-notice): 实现对话级批量重试自动推进功能,优化库存与PDF匹配逻辑

- 新增对话级批量重试自动推进的完整链路:后端服务、API、数据投影逻辑
- 前端新增对话级重试按钮、多语言国际化支持与API类型定义
- 优化行级库存重试控制,新增retryable字段统一管控重试按钮展示,清理废弃的view_fulfillment_detail动作,标准化前端动作码排序逻辑
- 修复PDF坐标匹配的fail-close防护逻辑,避免生成伪精确匹配分数
- 调整订单确认后流程,提前进入库存获取阶段,移除冗余的确认建单按钮,优化用户流转体验
- 新增对应单元测试用例覆盖核心业务逻辑
This commit is contained in:
hugo committed 2026-08-07 16:30:45 +08:00
1 parent fd6a23f870
commit 1008911a7e
41 files changed
+3956 -1256

No files matched your search

@@ -84,6 +84,22 @@ describe('resolveProcessingActionPresentation', () => {
expect([result.primary, result.secondary, ...result.overflow].some((i) => i?.intent === 'refresh')).toBe(false);
});
it('available_actions 乱序 / 大小写空格 / 重复不影响输出按钮顺序', () => {
const order1 = resolveProcessingActionPresentation(projection({
availableActions: [' Refresh ', 'view_details', 'retry_parse', 'view_details'],
}), { surface: 'chat', actionsExecutable: true });
const order2 = resolveProcessingActionPresentation(projection({
availableActions: ['retry_parse', 'VIEW_DETAILS', 'refresh'],
}), { surface: 'chat', actionsExecutable: true });
// presentation 主/次/溢出的 intent 序列必须相同,不受后端原始顺序影响。
const intentChain = (r: typeof order1) => [
r.primary?.intent ?? null,
r.secondary?.intent ?? null,
...r.overflow.map((o) => o.intent),
].join('|');
expect(intentChain(order1)).toBe(intentChain(order2));
});
it('maps open_order_review label to processing entry on chat surface', () => {
const result = resolveProcessingActionPresentation(projection({
availableActions: ['open_order_review'],
@@ -12,6 +12,7 @@ import type {
ShippingProcessingActionIntent,
ShippingProcessingProjection,
} from '@/features/chat/types/shipping.api.types';
import { normalizeActionCodes } from '@/features/chat/shipping/conversationProcessingProjection';
import type { ActionPresentation, ActionPresentationItem, ActionPresentationSurface } from './types';
import type { WorkbenchPanelAvailability } from './workbenchActionRegistry';
import {
@@ -65,6 +66,10 @@ const ACTION_CODE_TO_INTENT: Record<string, ShippingProcessingActionIntent> = {
};
const AUTOMATING_STATUSES = new Set(['processing', 'automating', 'queued']);
const NEEDS_ACTION_STATUSES = new Set([
'blocked', 'waiting_review', 'pending_review', 'failed', 'reparse_failed',
'manual_upload_pending', 'upload_rpa_failed',
]);
/** 永不升为主 CTA 的动作码(仍可作次要/溢出)。 */
const NEVER_PRIMARY_CODES = new Set(['cancel_task', 'cancel_run', 'view_details']);
@@ -213,7 +218,9 @@ export function resolveProcessingActionPresentation(
};
pushCode(projection.currentGate?.nextActionCode);
for (const action of projection.availableActions || []) {
// [ORDER-STABLE] 对 availableActions 标准化(去重 + 字典序排序),确保后端返回顺序不影响前端按钮顺序。
const normalizedAvailableActions = normalizeActionCodes(projection.availableActions || []);
for (const action of normalizedAvailableActions) {
pushCode(action);
}
@@ -243,6 +250,12 @@ export function resolveConversationTaskActionPresentation(
if (!task) return empty;
const surface = options?.surface || 'right';
const status = String(task.status_label || '').trim().toLowerCase();
const isNeedsAction = task.group === 'needs_action' || NEEDS_ACTION_STATUSES.has(status);
const isProcessing = task.group === 'processing' || AUTOMATING_STATUSES.has(status);
if (task.group === 'history' || status === 'cancelled') {
return empty;
}
const items: ActionPresentationItem[] = [];
const seen = new Set<string>();
@@ -258,16 +271,27 @@ export function resolveConversationTaskActionPresentation(
};
pushCode(task.primary_action);
for (const action of task.available_actions || []) {
// [ORDER-STABLE] 对 available_actions 标准化排序,确保后端顺序变化不影响按钮渲染顺序。
const normalizedTaskActions = normalizeActionCodes(task.available_actions || []);
for (const action of normalizedTaskActions) {
pushCode(action);
}
// 无正式业务入口时,默认提供查看进度(focus_task)。
// 人工待办禁止伪造查看进度;无明确动作时进入订单处理作为安全兜底。
if (isNeedsAction && !items.some((item) => !NEVER_PRIMARY_CODES.has(String(item.actionCode || '').trim().toLowerCase()))) {
pushCode('open_order_processing');
}
// 只有系统处理中才允许显示查看进度,且只能作为次要文字链。
if (isProcessing && !items.length) pushCode('focus_task');
const hasPrimaryCandidate = items.some(
(item) => !NEVER_PRIMARY_CODES.has(String(item.actionCode || '').trim().toLowerCase()),
);
if (!hasPrimaryCandidate) {
pushCode('focus_task');
if (!hasPrimaryCandidate && !isProcessing) {
return empty;
}
if (isProcessing) {
const progress = items.find((item) => String(item.actionCode).toLowerCase() === 'focus_task');
return { primary: null, secondary: progress || null, overflow: [] };
}
return partitionActionItems(items);
@@ -1,9 +1,10 @@
<!--
features/shipping-progress/components/ReviewProgressStrip.vue
用途:订单处理工作台只读进度——xl 等宽 15 阶;md 横向滚动;窄屏仅 N/15。
依赖:vue-i18n、ShippingProcessingProjection、progressWindow、stageNodesAuthority、gateReasonLabel。
逻辑:由 ReviewWorkflowProgressPanel 挂载;禁止点击节点;「当前需要」并入标题行文案;
「查看流程详情」在标题行右侧;正式 OT 后抑制「请确认建单」;写操作只在 Footer。
依赖:vue-i18n、ShippingProcessingProjection、progressWindow、stageNodesAuthority。
逻辑:由 ReviewWorkflowProgressPanel 挂载;禁止点击节点;标题只显示「订单处理进度」,
不混入等待系统启动/人工处理/失败等自动化文案(归右侧状态卡);
「查看流程详情」与标题同行;写操作只在 Footer / 右侧对象级。
-->
<script setup lang="ts">
import { computed, watch } from 'vue';
@@ -12,19 +13,18 @@ import type {
ShippingProcessingProjection,
ShippingProcessingStageNodeStatus,
} from '@/features/chat/types/shipping.api.types';
import { shippingProcessingStageKey, resolveShippingProcessingStageLabel } from '@/features/chat/shipping/shippingProcessingLabels';
import { shippingProcessingStageKey } from '@/features/chat/shipping/shippingProcessingLabels';
import { buildProgressRangeHint } from '../progressWindow';
import {
readAuthoritativeStageNodes,
warnStageNodesUnavailable,
} from '../stageNodesAuthority';
import { resolveCurrentNeedLabel } from '../gateReasonLabel';
const props = defineProps<{
projection: ShippingProcessingProjection;
/** 宿主轮询中提示(显示在标题行)。 */
polling?: boolean;
/** 正式 OT 已创建时禁止再投影「请确认建单」类当前需要。 */
/** 正式 OT 已创建时保留 prop 兼容(进度条不再展示当前需要文案)。 */
hasFormalOt?: boolean;
}>();
@@ -36,12 +36,6 @@ const emit = defineEmits<{
const { t, te } = useI18n();
const AUTOMATING_STATUSES = new Set(['processing', 'automating', 'queued']);
const CONFIRM_BUILD_ACTION_CODES = new Set([
'confirm_create',
'confirm_build',
'open_order_review',
'confirm_order',
]);
const SYSTEM_TECH_ACTION_PREFIXES = ['retry_', 'poll_'];
/** 权威 15 阶;非法时 null(fail-closed)。 */
@@ -50,7 +44,7 @@ const stageNodes = computed(() => readAuthoritativeStageNodes(props.projection))
const rangeHint = computed(() => buildProgressRangeHint(props.projection, 'workbench'));
/**
* 是否处于系统自动推进(含技术重试/轮询动作,避免被 nextAction 误判为人工待办)。
* 是否处于系统自动推进(用于刷新按钮,不进标题文案)。
*/
const isAutomating = computed(() => {
const status = String(props.projection.status || '').trim().toLowerCase();
@@ -61,50 +55,19 @@ const isAutomating = computed(() => {
return false;
});
const stageLabel = computed(() => resolveShippingProcessingStageLabel(
props.projection.stage,
te,
t,
props.projection.stageLabelKey,
));
/**
* 标题仅「订单处理进度」,阶段名由节点/窄屏摘要表达。
*/
const titleLine = computed(() => t('chat.shippingProcessing.progress.title'));
/**
* 单行标题:自动推进用「系统处理中 · 阶段」;否则「订单处理进度 · 阶段」。
* 窄屏当前阶段名:只用 stage code → 阶段 i18n,不用 waiting_system_start 等自动化 label_key。
*/
const titleLine = computed(() => {
const stage = stageLabel.value || '—';
if (isAutomating.value) {
return t('chat.shippingProcessing.progress.systemProcessingWithStage', { stage });
}
return t('chat.shippingProcessing.progress.progressTitleWithStage', { stage });
});
/**
* 有阻断 Gate 且非自动推进时展示「当前需要」。
* 正式 OT 已创建后禁止再显示确认建单类文案。
*/
const showCurrentNeed = computed(() => {
if (isAutomating.value) return false;
const gate = props.projection.currentGate;
if (!gate) return false;
const next = String(gate.nextActionCode || '').trim().toLowerCase();
if (props.hasFormalOt && CONFIRM_BUILD_ACTION_CODES.has(next)) return false;
if (props.hasFormalOt) {
const reason = String(gate.blockingReasonCode || '').trim().toLowerCase();
if (reason === 'waiting_review' || reason.includes('confirm')) return false;
}
return Boolean(
String(gate.blockingReasonCode || '').trim()
|| String(gate.nextActionCode || '').trim(),
);
});
/**
* 「当前需要」:blockingReasonCode 优先,缺失时回退 nextActionCode(与 Footer 语义对齐)。
*/
const currentNeed = computed(() => {
if (!showCurrentNeed.value) return '';
return resolveCurrentNeedLabel(props.projection.currentGate, { t, te });
const currentStageName = computed(() => {
const stage = String(props.projection.stage || '').trim();
if (!stage) return '—';
const key = shippingProcessingStageKey(stage);
return te(key) ? t(key) : stage;
});
watch(
@@ -153,11 +116,10 @@ function nodeShortLabel(stage: string): string {
>
{{ titleLine }}
<span
v-if="showCurrentNeed && currentNeed"
class="ml-2 font-semibold text-amber-800 dark:text-amber-200"
data-testid="review-progress-current-need"
class="ml-2 font-normal text-secondary md:hidden"
data-testid="review-progress-current-stage-narrow"
>
· {{ t('chat.shippingProcessing.progress.currentNeedLabel') }}{{ currentNeed }}
{{ t('chat.shippingProcessing.progress.currentStage', { stage: currentStageName }) }}
</span>
<span
v-if="polling"
@@ -189,7 +151,6 @@ function nodeShortLabel(stage: string): string {
</div>
</div>
<!-- xl:15 阶等宽铺满 -->
<div
v-if="stageNodes"
class="hidden xl:block"
@@ -218,7 +179,6 @@ function nodeShortLabel(stage: string): string {
</div>
</div>
<!-- md–xl:横向滚动、节点等宽 -->
<div
v-if="stageNodes"
class="hidden overflow-x-auto pb-1 md:block xl:hidden"
@@ -254,7 +214,6 @@ function nodeShortLabel(stage: string): string {
{{ t('chat.shippingProcessing.progress.stageNodesUnavailable') }}
</p>
<!-- &lt;md:仅已完成 N/15 + 标题中的当前阶段 -->
<p
v-if="rangeHint"
class="text-[11px] text-secondary md:hidden"
@@ -265,6 +224,5 @@ function nodeShortLabel(stage: string): string {
total: rangeHint.total,
}) }}
</p>
</div>
</template>