refactor(shipping-notice): 重构货代发货通知状态管理,移除废弃的process_status字段

统一货代发货通知的业务阶段为四个标准阶段:接收解析、订单复核、发货准备、上传完成
设置 ui_state 为前端唯一状态数据源,不再依赖 process_status 驱动业务流程
删除 shipping_notices 表的废弃 process_status 列及对应复合索引,新增数据库迁移脚本
替换全栈代码中所有对 process_status 的引用为生命周期、上传状态等领域字段
更新相关文档、测试用例与前端展示逻辑适配新的状态管理规则
This commit is contained in:
hugo committed 2026-08-15 10:19:10 +08:00
1 parent 6684e7181a
commit 5ef8329bd8
178 files changed
+5091 -1734

No files matched your search

@@ -40,7 +40,7 @@ function projection(
}
describe('resolveProcessingActionPresentation', () => {
it('prefers gate nextActionCode as primary', () => {
it('does not turn diagnostic gate nextActionCode into a user action', () => {
const result = resolveProcessingActionPresentation(projection({
currentGate: {
gateCode: 'inventory_source_routing',
@@ -51,9 +51,46 @@ describe('resolveProcessingActionPresentation', () => {
},
availableActions: ['refresh', 'retry'],
}));
expect(result.primary?.intent).toBe('open_inventory_source_review');
expect(result.secondary?.intent).toBe('refresh');
expect(result.overflow.map((i) => i.intent)).toContain('retry');
expect(result.primary?.intent).toBe('refresh');
expect(result.secondary?.intent).toBe('retry');
expect(result.overflow).toEqual([]);
});
it('uses ui_state actions as the only source when the backend supplies it', () => {
const result = resolveProcessingActionPresentation(projection({
status: 'processing',
currentGate: {
gateCode: 'inventory_source_routing', status: 'blocked', nextActionCode: 'retry',
blockingReasonCode: null, attemptNo: 1,
},
primaryAction: { code: 'retry_parse', i18nKey: 'action.retry_parse', parameters: {} },
availableActions: ['retry_parse', 'view_result'],
uiState: {
status: 'waiting_human', stage: 'fulfillment_prep', blocking_reason: null,
primary_action: { code: 'open_inventory_source_review', i18nKey: 'action.open_inventory_source_review', parameters: {} },
secondary_actions: [
{ code: 'view_details', enabled: true },
{ code: 'retry_parse', enabled: false },
],
},
}));
expect(result.primary?.actionCode).toBe('open_inventory_source_review');
expect(result.secondary?.actionCode).toBe('view_details');
expect(result.overflow).toEqual([]);
});
it('does not revive a legacy primary action when authoritative ui_state explicitly has none', () => {
const result = resolveProcessingActionPresentation(projection({
primaryAction: { code: 'retry_parse', i18nKey: 'action.retry_parse', parameters: {} },
availableActions: ['retry_parse'],
uiState: {
status: 'processing', stage: 'document_parsing', blocking_reason: null,
primary_action: null, secondary_actions: [],
},
}));
// ui_state 表达的“无可操作动作”是后端裁决,旧字段不得让按钮复活。
expect(result).toEqual({ primary: null, secondary: null, overflow: [] });
});
it('hides primary while automating without gate', () => {
@@ -75,6 +112,28 @@ describe('resolveProcessingActionPresentation', () => {
expect(result.primary?.actionCode).toBe('retry_parse');
});
it('keeps inventory preparation retry as the batch-card primary action', () => {
const result = resolveProcessingActionPresentation(projection({
status: 'waiting_human',
uiState: {
status: 'waiting_human', stage: 'inventory_fetching', blocking_reason: null,
primary_action: {
code: 'retry_inventory_preparation',
i18nKey: 'workspace.shippingNotice.processGate.actionCodes.retry_inventory_preparation',
parameters: {},
},
// Gate 工作台可保留受控上传入口;批次卡只消费 primary_action。
secondary_actions: [],
},
}), { surface: 'right' });
expect(result.primary).toMatchObject({
actionCode: 'retry_inventory_preparation',
labelKey: 'workspace.shippingNotice.processGate.actionCodes.retry_inventory_preparation',
});
expect(result.secondary).toBeNull();
});
it('filters open_order_review and refresh on review surface', () => {
const result = resolveProcessingActionPresentation(projection({
availableActions: ['open_order_review', 'refresh', 'view_result'],
@@ -2,7 +2,7 @@
* features/shipping-progress/actionPresentation.ts
* 用途:从统一投影 / 会话 OT 任务解析四页面共用的 ActionPresentation(主/次/溢出)。
* 依赖:ShippingProcessingProjection、ConversationProcessingUserTask、workbenchActionRegistry、types。
* 逻辑:优先级 Gate.nextActionCode → availableActions → 终态查看 → none;
* 逻辑:新版优先 ui_state.primary_action / secondary_actions;旧响应才兼容 primaryAction / availableActions;
* cancel_* 与 view_details 永不作主 CTA;无业务入口时 focus_task 兜底并映射「查看进度」;
* 自动处理中(processing/automating)主按钮为空;review 面经注册表 fail-closed 过滤。
*/
@@ -41,6 +41,7 @@ const ACTION_CODE_TO_INTENT: Record<string, ShippingProcessingActionIntent> = {
match_inventory: 'open_inventory_match_review',
open_shortage_review: 'open_shortage_review',
upload_inventory_file: 'upload_inventory_file',
retry_inventory_preparation: 'retry',
retry: 'retry',
retry_parse: 'retry',
retry_failed_documents: 'retry',
@@ -105,6 +106,8 @@ function toItem(
const chatOrRight = surface === 'chat' || surface === 'right';
if (intent === 'open_order_review' && chatOrRight) {
labelKey = 'chat.shippingProcessing.action.open_order_processing';
} else if (normalized === 'retry_inventory_preparation') {
labelKey = 'workspace.shippingNotice.processGate.actionCodes.retry_inventory_preparation';
} else if (normalized === 'retry_freight_upload_rpa' || normalized === 'retry_upload') {
labelKey = 'chat.shippingNoticeRetryUploadAction';
} else if (intent === 'retry' && chatOrRight) {
@@ -160,9 +163,9 @@ export interface ResolveProcessingActionPresentationOptions {
* 解析统一动作投影。
*
* 核心逻辑:
* 1. processing/automating/queued → 主按钮为空(自动推进中);
* 2. currentGate.nextActionCode 优先;
* 3. availableActions 依次填主/次/溢出;
* 1. 有 ui_state 时只渲染其已授权主/次动作;
* 2. 旧响应 processing/automating/queued → 主按钮为空(自动推进中);
* 3. 旧响应由 primaryAction / availableActions 填主/次/溢出;
* 4. completed/failed/cancelled → view_result / view_record 兜底;
* 5. surface=review 时经注册表 fail-closed(未知隐藏 + 告警;隐藏 refresh/自跳转);
* 6. cancel / view_details 强制降为次要或溢出。
@@ -180,8 +183,9 @@ export function resolveProcessingActionPresentation(
const surface = options?.surface;
const actionsExecutable = options?.actionsExecutable !== false;
const panels = options?.panels ?? null;
const status = String(projection.status || '').trim().toLowerCase();
if (AUTOMATING_STATUSES.has(status) && !projection.currentGate?.nextActionCode) {
const authoritativeUiState = projection.uiState;
const status = String(authoritativeUiState?.status || projection.userStatus || projection.status || '').trim().toLowerCase();
if (!authoritativeUiState && AUTOMATING_STATUSES.has(status) && !projection.currentGate?.nextActionCode) {
return empty;
}
@@ -231,41 +235,18 @@ export function resolveProcessingActionPresentation(
items.push(toItem(code, intent, surface));
};
pushCode(projection.primaryAction?.code || projection.currentGate?.nextActionCode);
// Gate 20 同时保留两条用户路径:主动重试 RPA 与人工上传登记。
// 该动作由正式任务面板打开登记弹窗,不走 Gate API。
if (
String(projection.currentGate?.gateCode || '').trim().toLowerCase() === 'manual_upload_handoff'
&& items.some((item) => String(item.actionCode).toLowerCase() === 'retry_freight_upload_rpa')
) {
pushCode('mark_manual_uploaded');
}
// [ORDER-STABLE] 对 availableActions 标准化(去重 + 字典序排序),确保后端返回顺序不影响前端按钮顺序。
const normalizedAvailableActions = normalizeActionCodes(projection.availableActions || []);
for (const action of normalizedAvailableActions) {
// [AUTHORITY] 新版只消费同一份 ui_state;currentGate 只保留诊断,禁止产生或替换按钮。
// 旧服务端未下发 ui_state 时才兼容 primaryAction / availableActions。
pushCode(authoritativeUiState
? authoritativeUiState.primary_action?.code
: projection.primaryAction?.code);
const actionCodes = authoritativeUiState
? authoritativeUiState.secondary_actions.filter((action) => action.enabled).map((action) => action.code)
: normalizeActionCodes(projection.availableActions || []);
for (const action of actionCodes) {
pushCode(action);
}
// Gate 19 RPA 失败时,人工登记作为任务级替代路径展示,避免与 RPA 重试并列。
if (
String(projection.currentGate?.gateCode || '').trim().toLowerCase() === 'freight_upload_rpa'
&& items.some((item) => String(item.actionCode).toLowerCase() === 'retry_freight_upload_rpa')
) {
for (let index = items.length - 1; index >= 0; index -= 1) {
const code = String(items[index]?.actionCode || '').toLowerCase();
if (code === 'mark_manual_uploaded' || code === 'open_manual_upload' || code === 'wait_manual_upload') {
items.splice(index, 1);
}
}
}
if (items.length === 0 && (status === 'completed' || status === 'failed' || status === 'cancelled')) {
pushCode('view_result');
}
if (AUTOMATING_STATUSES.has(status) && items.length === 0) {
return empty;
}
return partitionActionItems(items);
}
@@ -284,7 +265,7 @@ export function resolveConversationTaskActionPresentation(
if (!task) return empty;
const surface = options?.surface || 'right';
const userStatus = String(task.userStatus ?? '').trim().toLowerCase();
const userStatus = String(task.uiState?.status ?? task.userStatus ?? '').trim().toLowerCase();
const legacyStatus = String(task.status_label ?? '').trim().toLowerCase();
const status = userStatus || legacyStatus;
const isNeedsAction = task.group === 'needs_action' || NEEDS_ACTION_STATUSES.has(status);
@@ -308,19 +289,19 @@ export function resolveConversationTaskActionPresentation(
items.push(toItem(code, intent, surface));
};
pushCode(task.primaryAction?.code || task.primary_action);
pushCode(task.uiState
? task.uiState.primary_action?.code
: (task.primaryAction?.code || task.primary_action));
// [ORDER-STABLE] 对 available_actions 标准化排序,确保后端顺序变化不影响按钮渲染顺序。
const normalizedTaskActions = normalizeActionCodes(task.available_actions || []);
const normalizedTaskActions = normalizeActionCodes(
task.uiState?.secondary_actions?.filter((item) => item.enabled).map((item) => item.code)
|| task.available_actions
|| [],
);
for (const action of normalizedTaskActions) {
pushCode(action);
}
// 人工待办禁止伪造查看进度;无明确动作时进入订单处理作为安全兜底。
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()),
);
@@ -43,13 +43,19 @@ const SYSTEM_TECH_ACTION_PREFIXES = ['retry_', 'poll_'];
const stageNodes = computed(() => readAuthoritativeStageNodes(props.projection));
const rangeHint = computed(() => buildProgressRangeHint(props.projection, 'workbench'));
/** 新投影存在时,状态、阶段、阻断和动作只能消费同一次后端 ui_state 裁决。 */
const authoritativeUiState = computed(() => props.projection.uiState || null);
/**
* 人工阻断优先于遗留 processing/automating 投影,避免已中断任务仍显示系统处理中并持续轮询。
*/
const isWaitingHuman = computed(() => (
props.projection.userStatus === 'waiting_human'
|| String(props.projection.currentGate?.status || '').trim().toLowerCase() === 'blocked_manual'
authoritativeUiState.value
? authoritativeUiState.value.status === 'waiting_human'
: (
props.projection.userStatus === 'waiting_human'
|| String(props.projection.currentGate?.status || '').trim().toLowerCase() === 'blocked_manual'
)
));
/**
@@ -57,8 +63,11 @@ const isWaitingHuman = computed(() => (
*/
const isAutomating = computed(() => {
if (isWaitingHuman.value) return false;
const status = String(props.projection.status || '').trim().toLowerCase();
const status = String(
authoritativeUiState.value?.status || props.projection.status || '',
).trim().toLowerCase();
if (!AUTOMATING_STATUSES.has(status)) return false;
if (authoritativeUiState.value) return true;
const next = String(props.projection.currentGate?.nextActionCode || '').trim().toLowerCase();
if (!next) return true;
if (SYSTEM_TECH_ACTION_PREFIXES.some((prefix) => next.startsWith(prefix))) return true;
@@ -97,6 +106,12 @@ const titleLine = computed(() => {
const currentNeedLabel = computed<string | null>(() => {
if (props.hasFormalOt) return null;
if (isAutomating.value) return null;
const uiState = authoritativeUiState.value;
if (uiState) {
const key = String(uiState.blocking_reason?.i18nKey || '').trim();
if (key && te(key)) return t(key);
return String(uiState.blocking_reason?.code || '').trim() || null;
}
const gate = props.projection.currentGate;
if (!gate) return null;
const reasonCode = String(gate.blockingReasonCode || '').trim();
@@ -118,7 +133,7 @@ const currentNeedLabel = computed<string | null>(() => {
* 窄屏当前阶段名:只用 stage code → 阶段 i18n,不用 waiting_system_start 等自动化 label_key。
*/
const currentStageName = computed(() => {
const stage = String(props.projection.stage || '').trim();
const stage = String(authoritativeUiState.value?.stage || props.projection.stage || '').trim();
if (!stage) return '—';
const key = shippingProcessingStageKey(stage);
return te(key) ? t(key) : stage;
@@ -9,8 +9,7 @@
import { computed } from 'vue';
import { useI18n } from 'vue-i18n';
import type { ShippingProcessingProjection } from '@/features/chat/types/shipping.api.types';
import { shippingProcessingStageKey } from '@/features/chat/shipping/shippingProcessingLabels';
import { buildProgressRangeHint, stageAbsoluteIndex } from '../progressWindow';
import { resolveShippingProcessingStatusLabel, shippingProcessingStageKey } from '@/features/chat/shipping/shippingProcessingLabels';
import { useProcessingActionPresentation } from '../composables/useProcessingActionPresentation';
import type { ActionPresentationItem } from '../types';
import { resolveGateReasonLabel } from '../gateReasonLabel';
@@ -32,26 +31,32 @@ const { t, te } = useI18n();
const projectionRef = computed(() => props.projection);
const actionPresentation = useProcessingActionPresentation(projectionRef, { surface: 'right' });
const rangeHint = computed(() => buildProgressRangeHint(props.projection, 'right'));
/**
* 紧凑单行:● 阶段名 · 第 x/total。
*/
const inlineLine = computed(() => {
const hint = rangeHint.value;
const stageKey = hint?.currentLabelKey || shippingProcessingStageKey(props.projection.stage);
const stageLabel = te(stageKey) ? t(stageKey) : props.projection.stage;
const index = stageAbsoluteIndex(props.projection.stage) + 1;
return `● ${stageLabel} · ${t('chat.shippingProcessing.progress.positionOfTotal', { current: index, total: 15 })}`;
const stage = props.projection.uiState?.stage || props.projection.userStage || props.projection.stage;
const stageKey = shippingProcessingStageKey(stage);
const stageLabel = te(stageKey) ? t(stageKey) : stage;
return `● ${stageLabel}`;
});
/**
* Gate 阻断原因(禁止展示内部码)。
*/
const gateReason = computed(() => resolveGateReasonLabel(
props.projection.currentGate?.blockingReasonCode,
props.projection.uiState
? props.projection.uiState.blocking_reason?.code
: (props.projection.blockingReason?.code || props.projection.currentGate?.blockingReasonCode),
{ t, te },
));
/** 单一状态标签:阶段行只描述位置,状态标签只描述当前可操作状态。 */
const statusLabel = computed(() => resolveShippingProcessingStatusLabel(
props.projection.uiState?.status || props.projection.userStatus || props.projection.status,
te,
t,
));
</script>
<template>
@@ -66,6 +71,13 @@ const gateReason = computed(() => resolveGateReasonLabel(
>
{{ inlineLine }}
</div>
<span
v-if="statusLabel"
class="inline-flex rounded-full border border-default bg-surface-muted px-2 py-0.5 text-[10px] font-semibold text-secondary"
data-testid="sidebar-progress-status"
>
{{ statusLabel }}
</span>
<template v-if="!compact">
<p
v-if="gateReason"
@@ -1,7 +1,7 @@
<!--
features/shipping-progress/components/WorkbenchProgressGrouped.vue
用途:任务台分组进度——解析 1–10 / 库存 11–12 / 履约 13–15 三域 + 当前阶段;可选动作栏。
依赖:vue-i18n、ShippingProcessingProjection、progressWindow、UnifiedProgressTrack、UnifiedActionBar。
用途:任务台四阶段进度——接收解析 / 订单复核 / 发货准备 / 上传完成;可选动作栏。
依赖:vue-i18n、ShippingProcessingProjection、UnifiedProgressTrack、UnifiedActionBar。
逻辑:由 ShippingTaskWorkbench 挂载;任务台履约动作归 TaskTodoPanel,默认关闭本组件动作栏(UI-05)。
-->
<script setup lang="ts">
@@ -9,7 +9,6 @@ import { computed, ref } from 'vue';
import { useI18n } from 'vue-i18n';
import type { ShippingProcessingProjection } from '@/features/chat/types/shipping.api.types';
import { shippingProcessingStageKey } from '@/features/chat/shipping/shippingProcessingLabels';
import { buildProgressRangeHint, stageAbsoluteIndex } from '../progressWindow';
import { useProcessingActionPresentation } from '../composables/useProcessingActionPresentation';
import type { ActionPresentationItem } from '../types';
import UnifiedActionBar from './UnifiedActionBar.vue';
@@ -19,8 +18,11 @@ const props = withDefaults(defineProps<{
projection: ShippingProcessingProjection;
/** 是否渲染投影动作栏;任务台内嵌时应为 false,避免与 TaskTodoPanel 双入口。 */
showActions?: boolean;
/** 是否允许展开技术 15 节点;批次中心只展示业务四阶段。 */
showTechnicalDetail?: boolean;
}>(), {
showActions: true,
showTechnicalDetail: true,
});
const emit = defineEmits<{
@@ -32,24 +34,25 @@ const showDetailTrack = ref(false);
const projectionRef = computed(() => props.projection);
const actionPresentation = useProcessingActionPresentation(projectionRef, { surface: 'workbench' });
const rangeHint = computed(() => buildProgressRangeHint(props.projection, 'workbench'));
/** 三域阶段下标区间(0-based,含端点)。 */
const DOMAIN_RANGES = [
{ key: 'intake', labelKey: 'chat.shippingProcessing.progress.domainIntake', start: 0, end: 9 },
{ key: 'inventory', labelKey: 'chat.shippingProcessing.progress.domainInventory', start: 10, end: 11 },
{ key: 'fulfillment', labelKey: 'chat.shippingProcessing.progress.domainFulfillment', start: 12, end: 14 },
{ key: 'intake_parse', label: '接收解析', stages: ['upload_received', 'email_parsing', 'email_adjudicating', 'document_parsing', 'candidate_creating'] },
{ key: 'order_review', label: '订单复核', stages: ['order_creating', 'review_required', 'waiting_review'] },
{ key: 'fulfillment_prep', label: '发货准备', stages: ['inventory_fetching', 'inventory_matching', 'excel_generating'] },
{ key: 'upload_complete', label: '上传完成', stages: ['freight_uploading', 'completed'] },
] as const;
const currentIndex = computed(() => stageAbsoluteIndex(props.projection.stage));
/**
* 判断某域是否为当前/已过/未到。
*/
function domainState(start: number, end: number): 'passed' | 'current' | 'pending' {
const idx = currentIndex.value;
if (idx > end) return 'passed';
if (idx >= start && idx <= end) return 'current';
function domainState(index: number): 'passed' | 'current' | 'pending' {
const currentStage = String(
props.projection.uiState?.stage || props.projection.userStage || props.projection.stage || '',
).trim();
const currentIndex = DOMAIN_RANGES.findIndex((domain) => (
(domain.stages as readonly string[]).includes(currentStage)
));
if (index < currentIndex) return 'passed';
if (index === currentIndex || (currentIndex < 0 && index === 0)) return 'current';
return 'pending';
}
@@ -66,8 +69,9 @@ function domainClass(state: 'passed' | 'current' | 'pending'): string {
* 当前阶段中性名称。
*/
const currentStageLabel = computed(() => {
const key = rangeHint.value?.currentLabelKey || shippingProcessingStageKey(props.projection.stage);
return te(key) ? t(key) : props.projection.stage;
const stage = props.projection.uiState?.stage || props.projection.userStage || props.projection.stage;
const key = shippingProcessingStageKey(stage);
return te(key) ? t(key) : stage;
});
</script>
@@ -76,29 +80,20 @@ const currentStageLabel = computed(() => {
class="space-y-3"
data-testid="workbench-progress-grouped"
>
<div
v-if="rangeHint"
class="text-xs text-secondary"
data-testid="workbench-progress-range"
>
{{ t('chat.shippingProcessing.progress.completedOfTotal', {
done: rangeHint.done,
total: rangeHint.total,
}) }}
·
{{ t('chat.shippingProcessing.progress.currentStage', { stage: currentStageLabel }) }}
<div class="text-xs text-secondary" data-testid="workbench-progress-current-stage">
当前阶段:{{ currentStageLabel }}
</div>
<div class="grid gap-2 sm:grid-cols-3">
<div class="grid gap-2 sm:grid-cols-4" data-testid="workbench-four-stage-track">
<div
v-for="domain in DOMAIN_RANGES"
v-for="(domain, index) in DOMAIN_RANGES"
:key="domain.key"
class="rounded-xl border px-3 py-2 text-xs font-semibold"
:class="domainClass(domainState(domain.start, domain.end))"
:class="domainClass(domainState(index))"
:data-domain="domain.key"
:data-state="domainState(domain.start, domain.end)"
:data-state="domainState(index)"
>
{{ te(domain.labelKey) ? t(domain.labelKey) : domain.key }}
{{ domain.label }}
</div>
</div>
@@ -110,6 +105,7 @@ const currentStageLabel = computed(() => {
/>
<button
v-if="showTechnicalDetail"
type="button"
class="text-xs font-medium text-brand-700 underline-offset-2 hover:underline dark:text-brand-300"
data-testid="workbench-progress-toggle-detail"
@@ -121,7 +117,7 @@ const currentStageLabel = computed(() => {
</button>
<UnifiedProgressTrack
v-if="showDetailTrack"
v-if="showTechnicalDetail && showDetailTrack"
:projection="projection"
density="workbench"
/>
@@ -141,6 +141,7 @@ describe('shipping progress presenters', () => {
global: { plugins: [i18n] },
});
expect(wrapper.find('[data-testid="sidebar-progress-inline"]').exists()).toBe(true);
expect(wrapper.get('[data-testid="sidebar-progress-line"]').text()).not.toContain('/ 15');
});
it('mounts ReviewProgressStrip as compressed 15-stage readonly strip', () => {
@@ -181,6 +182,6 @@ describe('shipping progress presenters', () => {
global: { plugins: [i18n] },
});
expect(wrapper.find('[data-testid="workbench-progress-grouped"]').exists()).toBe(true);
expect(wrapper.findAll('[data-domain]').length).toBe(3);
expect(wrapper.findAll('[data-domain]').length).toBe(4);
});
});