feat(in-transit-transfer): 自动调拨支持收料日期范围并收归排程通用通知

- 自动调拨任务新增收料日期范围动态参数(receipt_date_from/to):缩小匹配面便于测试与排障,非法范围由匹配层校验拒绝
- 排程动态参数表单支持占位文案 key 与空值归 null,日期筛选直达任务配置
- 执行结果通知统一走排程「启用通知」通用企微通知,任务不再自建领域通知
- 门禁契约澄清 retry_inventory_matching 语义:复用已抓库存重匹配不重抓;STP 多候选无匹配时阶段能力禁用、不隐式触发 RPA
- 同步匹配/自动调拨/排程测试、四语言文案与文档
This commit is contained in:
hugo committed 2026-10-12 21:25:35 +08:00
1 parent 34c3bfb254
commit a8d721e793
35 files changed
+863 -138

No files matched your search

@@ -261,7 +261,7 @@ watch(
type="date"
:value="params[field.key] ?? ''"
class="input-field w-full !text-sm !leading-5"
@input="setField(field.key, ($event.target as HTMLInputElement).value)"
@input="setField(field.key, ($event.target as HTMLInputElement).value === '' ? null : ($event.target as HTMLInputElement).value)"
/>
<input
v-else-if="field.type === 'datetime'"
@@ -341,7 +341,7 @@ watch(
v-model="multiSearch[field.key]"
type="text"
class="mb-1 w-full rounded-lg border border-default px-2 py-1.5 text-sm outline-none focus:border-blue-500"
:placeholder="$t('admin.schedule.form.dynamicParamsSearchPlaceholder')"
:placeholder="resolveText(field.placeholder_key, field.placeholder) || $t('admin.schedule.form.dynamicParamsSearchPlaceholder')"
/>
<p v-if="optionsLoading[field.options_source || '']" class="px-2 py-1 text-xs text-muted">
{{ $t('admin.schedule.form.dynamicParamsOptionsLoading') }}
@@ -1,12 +1,14 @@
<!--
features/chat/components/messages/TransferBacklogSummaryCard.vue
用途:待处理异常卡(可恢复/已关闭/结果未知三组)——列与匹配窗口一致,
支持关键字/结果筛选、多选批量操作(重查/恢复处理/标记无需处理)与行级快捷操作。
支持关键字/结果筛选、多选批量操作(重查/恢复/关闭)与行级快捷操作。
依赖:props.items、i18n chat.transfer.*、transferBatch.deriveBatchNo、transferFormat.formatQuantity。
逻辑:仅 blocked_recoverable 可勾选与操作;result_unknown / manually_closed 只读;
可恢复行按 result_code 细分徽标(blocked_file_removed=文件已移除);
blocked_file_removed 行行内仅留「标记无需继续处理」(重查不可恢复——消失证据
blocked_file_removed 行行内仅留「关闭」(重查不可恢复——消失证据
无法由重查翻回,唯一出口=人工关闭或等文件重新同步);
批量按钮与行内按钮同用短文案键(重查/恢复/关闭,2026-10-12 文案一致化,
完整语义经 title 悬浮),勾选计数保留;
勾选集合为卡片本地态,操作经 emit 交父组件调用批量端点并刷新。
-->
<script setup lang="ts">
@@ -157,18 +159,22 @@ function resultLabelKey(item: TransferBacklogItem): string {
class="rounded-lg border border-brand-200 bg-brand-50 px-3 py-1 text-xs font-bold text-brand-700 transition hover:bg-brand-100 disabled:cursor-not-allowed disabled:opacity-40"
data-testid="transfer-backlog-batch-resume"
:disabled="busy"
:title="$t('chat.transfer.resumeAction')"
@click="emit('resume', selectedActionableIds)"
>
{{ $t('chat.transfer.resumeAction') }}({{ selectedActionableIds.length }})
<!-- [2026-10-12 文案一致化] 批量按钮与行内按钮同用短文案键(恢复/关闭),
勾选计数保留;完整语义经 title 悬浮透出(与行内按钮同模式) -->
{{ $t('chat.transfer.resumeActionShort') }}({{ selectedActionableIds.length }})
</button>
<button
type="button"
class="rounded-lg border border-red-200 bg-red-50 px-3 py-1 text-xs font-bold text-red-600 transition hover:bg-red-100 disabled:cursor-not-allowed disabled:opacity-40"
data-testid="transfer-backlog-batch-close"
:disabled="busy"
:title="$t('chat.transfer.manualClose')"
@click="emit('batchClose', selectedActionableIds)"
>
{{ $t('chat.transfer.manualClose') }}({{ selectedActionableIds.length }})
{{ $t('chat.transfer.manualCloseShort') }}({{ selectedActionableIds.length }})
</button>
<button
type="button"
@@ -10,7 +10,7 @@ import { mount } from '@vue/test-utils';
import { describe, expect, it } from 'vitest';
import i18n from '@/i18n';
import TransferMatchCard from './TransferMatchCard.vue';
import type { TransferMatchingSummary, TransferSourceProgress } from '../../types/transfer.types';
import type { TransferMatchingItem, TransferMatchingSummary, TransferSourceProgress } from '../../types/transfer.types';
/** 最小合法匹配摘要(TransferMatchingSummary 全必填字段齐备,计数为 0) */
function buildSummary(): TransferMatchingSummary {
@@ -70,3 +70,81 @@ describe('TransferMatchCard 来源失败顶栏', () => {
expect(wrapper.find('[data-testid="transfer-match-failed-sources"]').exists()).toBe(false);
});
});
/** [2026-10-12 单据数口径修正] 预计 ERP 单据数按执行建单五元组去重。
* 行分组键 = (external_org, source_code, receipt_date, from_warehouse,
* to_warehouse),与后端 execution_service.prepare_execution 同口径:
* 同组多行执行期合并一张 ERP 单,预估数不得等于可执行行数。 */
function buildItem(overrides: Partial<TransferMatchingItem>): TransferMatchingItem {
return {
item_id: 1,
source_code: 'DBS-AWSBI',
material_no: 'MAT-001',
material_name: '连接器组件',
specification: 'A 型',
invoice_no: 'HOM-001',
receipt_date: '2026-08-05',
from_warehouse: 'DBS-TRANSIT',
from_quantity: '100',
to_warehouse: 'HUB-CN01',
to_quantity: '100',
result: 'executable',
external_org: 'HX-CN01',
...overrides,
};
}
/** 计数卡第 5 格 = 预计 ERP 单据(可执行/未成熟/阻断/数量/单据/待查/失效)。 */
function estimateCardText(wrapper: ReturnType<typeof mount>): string {
const cells = wrapper.find('[data-testid="transfer-match-counts"]').findAll('div.rounded-lg');
return cells[4]?.text() ?? '';
}
describe('TransferMatchCard 预计 ERP 单据数(五元组去重)', () => {
const sameGroupA = buildItem({ item_id: 1, invoice_no: 'HOM-001' });
const sameGroupB = buildItem({ item_id: 2, invoice_no: 'HOX-002' });
const crossDate = buildItem({ item_id: 3, invoice_no: 'HOM-003', receipt_date: '2026-08-04' });
it('计数卡:同组两行 + 跨日一行 → 预估 2(不等于可执行行数 3)', () => {
// [断言意图] 锁定五元组去重口径:receipt_date 入键,同组合并、跨组拆分,
// 历史快照旧口径(=行数)持久值不再上屏。
const wrapper = mount(TransferMatchCard, {
props: {
summary: buildSummary(),
items: [sameGroupA, sameGroupB, crossDate],
selected: new Set<number>(),
},
global: { plugins: [i18n] },
});
expect(estimateCardText(wrapper).replace(/\D/g, '')).toBe('2');
});
it('生成按钮旁预估随勾选联动:勾选同组两行仍为 1,跨组勾选后为 2', async () => {
// [断言意图] 底部预估回答「点生成会出几张单」:仅统计勾选的可执行行并
// 按五元组分组;同组两行勾选=1 张(合并),追加跨日行勾选=2 张。
const wrapper = mount(TransferMatchCard, {
props: {
summary: buildSummary(),
items: [sameGroupA, sameGroupB, crossDate],
selected: new Set<number>([1, 2]),
},
global: { plugins: [i18n] },
});
expect(wrapper.find('[data-testid="transfer-estimate-selected"]').text()).toContain(':1');
await wrapper.setProps({ selected: new Set<number>([1, 2, 3]) });
expect(wrapper.find('[data-testid="transfer-estimate-selected"]').text()).toContain(':2');
});
it('阻断行不参与预估:勾选阻断行不改变单据数', () => {
const blocked = buildItem({ item_id: 4, invoice_no: 'HOM-BLOCKED', result: 'blocked_quantity_mismatch' });
const wrapper = mount(TransferMatchCard, {
props: {
summary: buildSummary(),
items: [sameGroupA, blocked],
selected: new Set<number>([1, 4]),
},
global: { plugins: [i18n] },
});
expect(wrapper.find('[data-testid="transfer-estimate-selected"]').text()).toContain(':1');
});
});
@@ -15,7 +15,12 @@
emit execute(itemIds);来源级解析/文件失败经 sources.error_code 透出
(防"安静全 0"),但路由未解析失败(TRANSFER.ROUTE_NOT_RESOLVED)不进顶栏
——路由失败保持行级(result=blocked_route_not_resolved 行内展示),
顶栏按 error_code 客户端排除,历史卡片回放同样生效。
顶栏按 error_code 客户端排除,历史卡片回放同样生效;
[2026-10-12 单据数口径修正] 预计 ERP 单据数(计数卡=全部可执行行、
生成按钮旁=勾选可执行行)按执行建单五元组 (external_org, source_code,
receipt_date, from_warehouse, to_warehouse) 去重实时计算(与后端
execution_service 同键),同组多行合并一张单——原「=可执行行数」口径
高估单据数误导用户。
-->
<script setup lang="ts">
import { computed, ref } from 'vue';
@@ -144,6 +149,34 @@ const executableCheckedItemIds = computed(() =>
props.items.filter((item) => isSelectable(item) && isChecked(item)).map((item) => item.item_id as number),
);
/** [2026-10-12 单据数口径修正] 执行建单五元组键(与后端 execution_service.
* prepare_execution 分组建单同键同 .trim() 规范化):(external_org, source_code,
* receipt_date, from_warehouse, to_warehouse),同组多行执行期合并一张 ERP 单。
* 老卡片行缺 external_org 按 '' 参与(分组退化为四元组,仅跨组织同仓库配置下有差异)。 */
function documentGroupKey(item: TransferMatchingItem): string {
return [
(item.external_org ?? '').trim(),
(item.source_code ?? '').trim(),
(item.receipt_date ?? '').trim(),
(item.from_warehouse ?? '').trim(),
(item.to_warehouse ?? '').trim(),
].join('\u001f');
}
/** 预计 ERP 单据数(计数卡):全部可执行行按五元组去重的组数。客户端实时计算,
* 使历史快照中旧口径(=可执行行数)的持久化估计值不再上屏误导。 */
const estimatedDocumentCountAll = computed(
() => new Set(props.items.filter((item) => item.result === 'executable').map(documentGroupKey)).size,
);
/** 预计 ERP 单据数(生成按钮旁):按当前勾选的可执行行分组计数,回答
* 「点生成会出几张单」;未勾选为 0。 */
const estimatedDocumentCountSelected = computed(
() => new Set(
props.items.filter((item) => item.result === 'executable' && isChecked(item)).map(documentGroupKey),
).size,
);
/**
* 库存查询时刻小字(HH:mm);后端 naive ISO 按 UTC 解析后转浏览器本地时区
* (仓库约定 parseApiUtcDate,2026-09-29 修复 UTC+8 展示异常);
@@ -220,7 +253,9 @@ function reasonTitle(item: TransferMatchingItem): string | undefined {
<div class="text-[11px] text-muted">{{ $t('chat.transfer.estimatedQuantity') }}</div>
</div>
<div class="rounded-lg bg-surface-soft p-2 text-center">
<div class="text-lg font-black text-brand-600">{{ summary.estimated_external_write_count }}</div>
<!-- [2026-10-12 单据数口径修正] 按执行建单五元组去重(客户端计算),
不再透传旧口径持久值(=可执行行数)——同组多行合并一张 ERP 单 -->
<div class="text-lg font-black text-brand-600">{{ estimatedDocumentCountAll }}</div>
<div class="text-[11px] text-muted">{{ $t('chat.transfer.estimatedExternalWrites') }}</div>
</div>
<!-- 待查库存:文件已落地、尚未查过 ERP 库存的行数(历史回放缺省 0) -->
@@ -393,9 +428,10 @@ function reasonTitle(item: TransferMatchingItem): string | undefined {
</div>
<div class="mt-3 flex items-center justify-end gap-3 border-t border-subtle pt-3">
<span class="text-xs text-muted">
<span class="text-xs text-muted" data-testid="transfer-estimate-selected">
{{ $t('chat.transfer.selectedCount', { count: selectedCount }) }} ·
{{ $t('chat.transfer.estimatedExternalWrites') }}:{{ summary.estimated_external_write_count }}
<!-- [2026-10-12 单据数口径修正] 随勾选联动:按勾选可执行行五元组分组计数 -->
{{ $t('chat.transfer.estimatedExternalWrites') }}:{{ estimatedDocumentCountSelected }}
</span>
<button
type="button"
@@ -5,6 +5,9 @@
逻辑:主卡内部 section = 「当前阶段/状态/正式OT → 下一步 → 动作区」;
状态文案严格绑定 user_status;blocking_reason 只作下一步问题说明;按钮显隐由后端 retryable + primary_action.parameters 决定;
主动作按钮文案 fail-closed:后端下发动作码但无受控 i18n 文案时整体隐藏该按钮(含图标),禁止渲染无文字裸按钮;
阶段能力禁用态:视图层把 preparation.capabilities 的 disabled_reason 并进动作对象
(capabilityDisabledReason),命中时按钮渲染 disabled + 原因 tooltip(capabilityDisabled 命名空间),
与 submitFormalGateAction 的点击拦截同源(展示=执行同源),禁止可点样式诱导用户点击后才被拦截;
loading 仅代表「权威投影读取中」而非系统运行态:已知阶段/状态/阻断仍照常展示
(与投影同源或后端 automation 运行态),空态自然落到「待机/状态待确认」,
禁止把读取占位误述为「系统处理中」,也不做骨架→真值的二次刷新;
@@ -45,12 +48,17 @@ const props = defineProps<{
| null;
retryable?: boolean;
blockingReason?: ShippingProcessingBlockingReason | null;
primaryAction?: ShippingProcessingPrimaryAction | null;
primaryAction?: (ShippingProcessingPrimaryAction & {
/** 阶段能力禁用原因(视图层从 preparation.capabilities 并入);非空=按钮渲染禁用态。 */
capabilityDisabledReason?: string | null;
}) | null;
recoveryActions?: Array<{
code: string;
i18nKey?: string | null;
label_key?: string | null;
parameters?: Record<string, unknown>;
/** 阶段能力禁用原因(视图层从 preparation.capabilities 并入);非空=按钮渲染禁用态。 */
capabilityDisabledReason?: string | null;
}>;
/** 正式 Gate 原始状态仅用于区分未入队、运行中与外部回执等待;不参与按钮裁决。 */
gateStatus?: string | null;
@@ -296,6 +304,11 @@ const businessActionLabel = computed(() => {
});
const businessActionTitle = computed(() => {
// 能力禁用原因优先于重试中提示:禁用态按钮的 tooltip 必须解释"为什么不可点"。
const capabilityText = capabilityDisabledText(
props.primaryAction ? capabilityDisabledReasonOf(props.primaryAction) : null,
);
if (capabilityText) return capabilityText;
const retryingFlag = Boolean(props.retrying);
if (retryingFlag) {
return t('chat.shippingOrderReview.currentTask.actionRetryRunningTooltip');
@@ -305,6 +318,29 @@ const businessActionTitle = computed(() => {
const actionIsRetry = computed(() => String(props.primaryAction?.code || '').trim().startsWith('retry_'));
const actionIsInventoryRpa = computed(() => String(props.primaryAction?.code || '').trim() === 'retry_inventory_preparation');
/**
* 阶段能力禁用态裁决:与视图层 submitFormalGateAction 的点击拦截同源(展示=执行同源)。
* 核心逻辑:视图层把 preparation.capabilities 的 disabled_reason 并进动作对象;本卡只负责
* 渲染禁用态与原因 tooltip,不自行推断业务能力。原因文案复用 capabilityDisabled 命名空间,
* 未登记的 reason fail-closed 禁用但不给 tooltip(禁止裸露内部原因码)。
*/
function capabilityDisabledReasonOf(action: { capabilityDisabledReason?: string | null }): string | null {
const reason = String(action.capabilityDisabledReason || '').trim();
return reason || null;
}
function capabilityDisabledText(reason: string | null | undefined): string {
const normalized = String(reason || '').trim();
if (!normalized) return '';
const key = `chat.shippingOrderReview.lifecycle.prepare.capabilityDisabled.${normalized}`;
return te(key) ? t(key) : '';
}
const businessActionCapabilityDisabled = computed(() => (
Boolean(props.primaryAction && capabilityDisabledReasonOf(props.primaryAction))
));
const recoveryActions = computed(() => (props.recoveryActions || []).filter((action) => {
const code = String(action.code || '').trim();
if (!code || isNonTaskCapabilityAction(code) || isInternalInventoryAction(code)) return false;
@@ -329,6 +365,8 @@ function recoveryActionLabel(action: (typeof recoveryActions.value)[number]): st
}
function handleBusinessActionClick() {
// 能力禁用态兜底:disabled 按钮通常不派发 click,此处防御键盘等旁路触发。
if (businessActionCapabilityDisabled.value) return;
const primaryActionCode = String(props.primaryAction?.code || '').trim();
if (!primaryActionCode || primaryActionCode === 'retry') return;
emit('action', primaryActionCode, props.primaryAction?.parameters ?? {});
@@ -464,9 +502,10 @@ type ReviewCurrentUserStatus =
<button
v-if="showBusinessAction"
type="button"
class="inline-flex items-center gap-1 rounded-md bg-sky-700 px-3 py-1.5 text-xs font-medium text-white shadow-sm transition hover:bg-sky-800 disabled:opacity-50 dark:bg-sky-600 dark:hover:bg-sky-500"
class="inline-flex items-center gap-1 rounded-md bg-sky-700 px-3 py-1.5 text-xs font-medium text-white shadow-sm transition hover:bg-sky-800 disabled:opacity-50 disabled:cursor-not-allowed dark:bg-sky-600 dark:hover:bg-sky-500"
:data-testid="actionIsRetry ? 'review-current-processing-retry' : 'review-current-task-primary-action'"
:disabled="retrying || locating"
:data-capability-disabled="businessActionCapabilityDisabled ? 'true' : undefined"
:disabled="retrying || locating || businessActionCapabilityDisabled"
:title="businessActionTitle"
@click="handleBusinessActionClick"
>
@@ -482,9 +521,11 @@ type ReviewCurrentUserStatus =
v-for="action in recoveryActions"
:key="action.code"
type="button"
class="inline-flex items-center gap-1 rounded-md border border-sky-300 bg-surface px-2.5 py-1.5 text-xs font-medium text-sky-800 shadow-sm transition hover:bg-sky-50 disabled:opacity-50 dark:border-sky-700 dark:bg-sky-900 dark:text-sky-100 dark:hover:bg-sky-800"
class="inline-flex items-center gap-1 rounded-md border border-sky-300 bg-surface px-2.5 py-1.5 text-xs font-medium text-sky-800 shadow-sm transition hover:bg-sky-50 disabled:opacity-50 disabled:cursor-not-allowed dark:border-sky-700 dark:bg-sky-900 dark:text-sky-100 dark:hover:bg-sky-800"
:data-testid="`review-current-task-recovery-${action.code}`"
:disabled="retrying || locating"
:data-capability-disabled="capabilityDisabledReasonOf(action) ? 'true' : undefined"
:disabled="retrying || locating || Boolean(capabilityDisabledReasonOf(action))"
:title="capabilityDisabledText(capabilityDisabledReasonOf(action))"
@click="$emit('action', action.code, action.parameters || {})"
>
{{ recoveryActionLabel(action) }}
@@ -67,6 +67,9 @@ export interface TransferMatchingItem {
stale?: boolean;
/** 行评估所用收料文件版本与来源最新可用文件是否一致;false = 文件已更新需重新匹配 */
file_current?: boolean;
/** [2026-10-12 单据数口径修正] 执行建单五元组首键(路由解析所得外部组织);
* 匹配评估路径透出,历史回放缺省——预估 ERP 单据数按五元组去重的分组输入 */
external_org?: string;
}
/** 来源实例级进度(决策 18:来源隔离展示) */
@@ -705,6 +705,9 @@ async function mountView(query: Record<string, string> = {}) {
partAvailableQty: '可用数量',
shortage: '库存不足',
pending: '库存匹配或通知文件尚未生成。',
capabilityDisabled: {
no_match_result: '暂无库存匹配结果,请先重新获取库存',
},
},
uploadComplete: {
title: '通知完成',
@@ -761,6 +764,8 @@ async function mountView(query: Record<string, string> = {}) {
actionCodes: {
confirm_customer: '确认客户',
resolve_field_conflicts: '处理字段冲突',
retry_inventory_preparation: '重新获取库存',
retry_inventory_matching: '重新匹配库存',
},
},
},
@@ -1622,6 +1627,81 @@ describe('ShippingOrderReviewView layout phase 1', () => {
);
});
it('renders capability-disabled actions as disabled buttons with reason tooltip', async () => {
// 回归(展示=执行同源):A 渲染的 retry_inventory_matching 命中阶段能力 disabled
// (no_match_result)时,右卡必须直接渲染禁用态 + 原因 tooltip;
// 禁止可点样式诱导用户点击后才被 submitFormalGateAction 弹提示拦截。
activeCase.value = {
...activeCase.value,
status: 'confirmed', has_formal_ot: true, task_missing: false,
confirmed_task_id: 906, confirmed_task_no: 'SN-RPA-CAP-DISABLED',
};
shippingProcessingProjection.value = {
workItemType: 'order_task', workItemNo: 'SN-RPA-CAP-DISABLED',
status: 'failed', userStatus: 'retryable', stage: 'inventory_fetching',
progressVersion: 5, currentGate: { status: 'blocked_retryable' },
uiState: {
status: 'retryable', stage: 'inventory_fetching', lifecycleStage: 'fulfillment_prep',
primary_action: { code: 'retry_inventory_matching' },
secondary_actions: [{ code: 'retry_inventory_preparation', enabled: true }],
},
} as any;
const taskApi = await import('@/features/chat/api/shipping.api');
vi.mocked(taskApi.getWorkspaceShippingTask).mockResolvedValue({
task_no: 'SN-RPA-CAP-DISABLED', status: 'processing', lines: [], events: [],
ui_state: {
actions: { primary: null, secondary: [] },
process_gate: {
execution_no: 'EXEC-RPA-CAP-DISABLED',
current_blocking_gate: {
gate_code: 'inventory_preparation', evaluation_version: 2, status: 'blocked_retryable',
},
allowed_actions: ['retry_inventory_matching', 'retry_inventory_preparation'],
},
stage_context: {
preparation: {
status: 'blocked', source_locked: false,
source_options: [{ source_code: 'DSV' }],
failed_source_codes: ['DSV'],
capabilities: [
{
code: 'retry_inventory_matching', scope: 'task',
action_code: 'retry_inventory_matching', enabled: false,
disabled_reason: 'no_match_result',
},
{
code: 'retry_inventory_preparation', scope: 'task',
action_code: 'retry_inventory_preparation', enabled: true,
disabled_reason: null,
},
],
frozen_order_lines: [], lines: [],
},
},
summary: {}, steps: [],
},
} as any);
submitProcessGatePrimaryActionMock.mockClear();
messageMocks.info.mockClear();
const wrapper = await mountView({ lifecycle_stage: 'fulfillment_prep' });
await flushPromises();
// 主按钮:能力禁用 → disabled + 原因 tooltip(复用 capabilityDisabled.no_match_result 文案)。
const primary = wrapper.get('[data-testid="review-current-processing-retry"]');
expect(primary.attributes('disabled')).toBeDefined();
expect(primary.attributes('data-capability-disabled')).toBe('true');
expect(primary.attributes('title')).toContain('暂无库存匹配结果');
// 侧路按钮:能力 enabled → 保持可点,不受主按钮禁用影响。
const recovery = wrapper.get('[data-testid="review-current-task-recovery-retry_inventory_preparation"]');
expect(recovery.attributes('disabled')).toBeUndefined();
// 点击禁用按钮不得触发提交,也不得弹任何 info 提示(此前会弹未翻译 key)。
await primary.trigger('click');
await flushPromises();
expect(submitProcessGatePrimaryActionMock).not.toHaveBeenCalled();
expect(messageMocks.info).not.toHaveBeenCalled();
});
it('refreshes the processing projection after field-conflict adjudication refreshes the Case', async () => {
activeCase.value = {
...activeCase.value,
@@ -2024,6 +2104,65 @@ describe('ShippingOrderReviewView layout phase 1', () => {
}
});
it('does not auto-advance when switching formal-downstream files without an activeCase identity', async () => {
// 回归:正式下游(通知准备/货代上传/通知完成,选法 2)activeCase 刻意为 null,
// 切换前后 activeCase 身份(case_no/document_id)恒为空值;自动推进守卫若用
// activeCase 做“同一文件”判据,会把目标文件更晚的阶段误判成当前文件被推进,
// 弹出“已自动推进到货代上传”。文件身份必须用 requestedCaseNo(与阶段解析同源,
// selectCase/beginCrossRunSwitch 同步块内更新):切换必变更 → 静默;真实推进
// 不触碰 requestedCaseNo → 提示行为不变。
const originalQueue = reviewQueue.value;
try {
reviewQueue.value = {
...reviewQueue.value,
summary: { total: 2, needs_action: 2, processing: 0, completed: 0 },
items: [
{
...reviewQueue.value.items[0],
has_formal_ot: true,
lifecycle_stage: 'fulfillment_prep',
lifecycle_entries: [
{ code: 'order_review', state: 'available', targetSurface: 'order_lifecycle_workbench' },
{ code: 'fulfillment_prep', state: 'current', targetSurface: 'order_lifecycle_workbench' },
{ code: 'freight_upload', state: 'unavailable', targetSurface: 'order_lifecycle_workbench' },
{ code: 'upload_complete', state: 'unavailable', targetSurface: 'order_lifecycle_workbench' },
],
},
{
case_no: 'CASE-2', source_run_no: 'RUN-1', document_id: 2, file_name: 'po-2.pdf',
status: 'confirmed', has_formal_ot: true, issue_count: 0,
lifecycle_stage: 'freight_upload',
lifecycle_entries: [
{ code: 'order_review', state: 'available', targetSurface: 'order_lifecycle_workbench' },
{ code: 'fulfillment_prep', state: 'available', targetSurface: 'order_lifecycle_workbench' },
{ code: 'freight_upload', state: 'current', targetSurface: 'order_lifecycle_workbench' },
{ code: 'upload_complete', state: 'unavailable', targetSurface: 'order_lifecycle_workbench' },
],
},
],
};
// 选法 2 盲区:源文件无复核 Case 快照(懒加载失败/未完成时生产即如此),
// 此刻文件身份只剩 requestedCaseNo。
activeCase.value = null;
requestedCaseNo.value = 'CASE-1';
const wrapper = await mountView({ case_no: 'CASE-1', lifecycle_stage: 'fulfillment_prep' });
await flushPromises();
messageMocks.success.mockClear();
// 模拟真实 selectCase 正式下游分支的同步块:更新 requestedCaseNo + activeCase 保持 null。
requestedCaseNo.value = 'CASE-2';
await nextTick();
await flushPromises();
expect(messageMocks.success).not.toHaveBeenCalledWith('已自动推进到货代上传');
// 守卫不得替用户改写深链:切文件是展示上下文切换,不是流程推进。
expect((wrapper.vm as any).$route.query.lifecycle_stage).toBe('fulfillment_prep');
} finally {
reviewQueue.value = originalQueue;
}
});
it('does not open a lifecycle stage before the backend authorizes lifecycle entries', async () => {
// 未收到正式 ui_state.lifecycle_entries 时,前端只能等待实时裁决,
// 不能因页面默认值自行开放订单复核或其他生命周期阶段。
@@ -817,6 +817,33 @@ const LINE_SCOPE_INVENTORY_ACTIONS = new Set([
'override_line_inventory_source',
]);
/**
* 阶段能力按执行动作码索引(preparation.capabilities)。
* 核心逻辑:右卡按钮的禁用态渲染必须与 submitFormalGateAction 的点击拦截消费同一份
* 能力投影,保证「展示=执行同源」——禁止按钮渲染成可点、点击才被能力门禁弹提示。
*/
const stageCapabilityByActionCode = computed(() => {
const map = new Map<string, { enabled: boolean; disabled_reason?: string | null }>();
for (const cap of formalPreparationContext.value?.capabilities || []) {
const code = String(cap.action_code || '').trim();
if (code) map.set(code, cap);
}
return map;
});
/**
* 给右卡动作附加阶段能力禁用原因。
* @param action - 已统一到卡片域的动作对象(须含 code)
* @returns 原对象浅拷贝;能力禁用时带 capabilityDisabledReason,否则该字段为 null
*/
function withStageCapabilityState<T extends { code: string }>(
action: T,
): T & { capabilityDisabledReason?: string | null } {
const cap = stageCapabilityByActionCode.value.get(String(action.code || '').trim());
if (!cap || cap.enabled) return { ...action, capabilityDisabledReason: null };
return { ...action, capabilityDisabledReason: String(cap.disabled_reason || '').trim() || null };
}
const currentTaskPrimaryAction = computed(() => {
if (formalTaskProjectionPending.value) return null;
if (hasFormalOt.value) {
@@ -828,10 +855,10 @@ const currentTaskPrimaryAction = computed(() => {
// 故必须统一映射到卡片域,否则按钮会因 businessActionLabel 为空而 fail-closed 消失。
const action = currentTaskUiState.value?.primary_action ?? null;
if (!action?.code || LINE_SCOPE_INVENTORY_ACTIONS.has(action.code)) return null;
return {
return withStageCapabilityState({
code: String(action.code).trim(),
i18nKey: `workspace.shippingNotice.processGate.actionCodes.${action.code}`,
};
});
}
const projection = shippingProcessingProjection.value;
if (projection) {
@@ -914,6 +941,8 @@ const currentTaskRecoveryActions = computed(() => {
// [§2.4 单源] 任务级恢复按钮只读 A.secondary_actions;不再叠加 B.capabilities。
// capabilities 仍可作点击执行的 stageCapabilityBypass 查找(见 handleCurrentTaskAction),
// 但不得单独渲成右卡按钮——能力要展示须先并进 A。行级选源禁止出现在右卡。
// [展示=执行同源] A 已渲染的按钮若命中阶段能力 disabled(capabilityDisabledReason
// 非空),右卡必须渲染禁用态 + 原因 tooltip,禁止可点样式诱导用户点击后才被拦截。
return (currentTaskUiState.value?.secondary_actions || [])
.filter((action) => action.enabled
&& String(action.code || '').trim() !== 'download_excel'
@@ -923,7 +952,8 @@ const currentTaskRecoveryActions = computed(() => {
// 统一右卡 domain:actionCodes.<code>(见 currentTaskPrimaryAction 注;A 的 i18nKey 可能是 chat 域)。
i18nKey: `workspace.shippingNotice.processGate.actionCodes.${String(action.code || '').trim()}`,
}))
.filter((action): action is { code: string; i18nKey: string } => {
.map((action) => withStageCapabilityState(action))
.filter((action): action is { code: string; i18nKey: string; capabilityDisabledReason?: string | null } => {
const code = String(action.code || '').trim();
return Boolean(code) && !LINE_SCOPE_INVENTORY_ACTIONS.has(code);
});
@@ -4879,20 +4909,21 @@ watch(
watch(
() => [
lifecycleCurrentStageCode.value,
String(activeCase.value?.case_no || '').trim(),
activeReviewDocumentId(),
// 文件身份必须用 requestedCaseNo(与 lifecycleUiState 解析阶段同源):正式下游
// (通知准备/货代上传/通知完成,选法 2)activeCase 刻意为 null,其 case_no/document_id
// 在这些文件之间恒为空值,用 activeCase 做身份会让"切换文件"被误判成"同一文件的
// 阶段推进"而弹出"已自动推进"。requestedCaseNo 在 selectCase/beginCrossRunSwitch/
// load 里与阶段重算同一同步块内更新,切换文件时本 watcher 必然看到变化而静默;
// 真正的自动推进只改队列投影、不触碰 requestedCaseNo,提示行为不变。
String(requestedCaseNo.value || activeCase.value?.case_no || '').trim(),
] as const,
async (current, previous) => {
const [currentStage, currentCaseNo, currentDocumentId] = current;
const [previousStage, previousCaseNo, previousDocumentId] = previous || [];
const [currentStage, currentFileKey] = current;
const [previousStage, previousFileKey] = previous || [];
if (await syncPendingReleaseAutoAdvance()) return;
// 切换文件时生命周期阶段会随新 Case 一起变更;这不是当前文件的自动推进,
// 切换文件时生命周期阶段会随新文件身份一起变更;这不是当前文件的自动推进,
// 不能跳转或弹出“已自动推进”提示。
if (
!previous
|| currentCaseNo !== previousCaseNo
|| currentDocumentId !== previousDocumentId
) return;
if (!previous || currentFileKey !== previousFileKey) return;
if (!currentStage || !previousStage || currentStage === previousStage) return;
const pendingReparse = pendingReparseNavigation.value;
if (