fix(shipping-recovery): 恢复库存RPA入口与门禁恢复流程

This commit is contained in:
hugo committed 2026-09-04 20:38:48 +08:00
1 parent eb55f407ae
commit 938f3dd0e8
8 files changed
+1329 -194

No files matched your search

File diff suppressed because it is too large. Load diff
@@ -200,6 +200,7 @@ const {
isFieldEditable,
loadReviewCase,
showWorkflowProgress,
workflowProgressPolling,
startWorkflowProgressPolling,
stopWorkflowProgressPolling,
stopReparseCaseRefreshPolling,
@@ -675,6 +676,32 @@ const showObjectRetryOnFooter = computed(() => (
* 补任一字段。否则“检查已通过”与旧 Gate 的“待裁决”会被拼到同一张卡上。
*/
const currentTaskUiState = computed(() => shippingProcessingProjection.value?.uiState ?? null);
/**
* Gate/RPA 动作已受理但新投影尚未落位时的本地过渡态。
* 仅用于避免上一帧 failed 在轮询窗口继续冒充当前状态;真实终态仍以后端
* shippingProcessingProjection 为准,不新增业务状态或动作权限。
*/
const recoveryProjectionPending = ref(false);
const recoveryProjectionBaselineVersion = ref<number | null>(null);
watch(
shippingProcessingProjection,
(projection) => {
if (!recoveryProjectionPending.value || !projection) return;
const version = Number(projection.progressVersion || 0);
const baseline = recoveryProjectionBaselineVersion.value;
const status = String(projection.userStatus || projection.status || '').trim().toLowerCase();
const gateStatus = String(projection.currentGate?.status || '').trim().toLowerCase();
const hasFreshVersion = baseline == null || version > baseline;
const isActive = ['running', 'processing', 'automating', 'queued'].includes(status)
|| ['pending', 'queued', 'running', 'waiting_external'].includes(gateStatus);
const isSettled = ['completed', 'cancelled', 'waiting_human', 'retryable'].includes(status);
if (hasFreshVersion || isActive || isSettled) {
recoveryProjectionPending.value = false;
recoveryProjectionBaselineVersion.value = null;
}
},
);
/**
* 正式 OT 已存在且文件切换或统一处理投影读取中时,Case Gate 只是降级快照,不能先暴露可执行动作。
* Projection 返回后才拥有动作裁决权;非切换错误路径仍保留原有的 Case Gate 恢复能力。
@@ -698,22 +725,14 @@ const NOTICE_SCOPED_ACTION_CODES = new Set([
'regenerate_excel_artifact',
]);
function isNoticeScopedAction(action: ShippingUnifiedAction | null | undefined): boolean {
return NOTICE_SCOPED_ACTION_CODES.has(String(action?.code || '').trim());
}
/**
* 将正式任务详情的已启用 Gate 动作适配为右侧当前任务卡的展示契约。
*
* 正式 OT 的写授权只能来自 ``ui_state.actions``;统一处理 Projection 仅承载
* 进度、阶段和阻断事实,不能以历史动作码替代正式 Gate 动作。
* 判断动作是否属于 Notice 作用域(应在通知组而非任务卡展示)。
* 核心逻辑:只读 code,兼容 ShippingUnifiedAction 与 Projection 的 primary/secondary 动作形状。
* @param action - 任意带 code 的动作对象
* @returns 是否为 Notice 作用域动作
*/
function toCurrentTaskAction(action: ShippingUnifiedAction | null | undefined) {
if (!action?.enabled || !String(action.code || '').trim() || isNoticeScopedAction(action)) return null;
return {
code: String(action.code).trim(),
i18nKey: `workspace.shippingNotice.processGate.actionCodes.${action.code}`,
};
function isNoticeScopedAction(action: { code?: string | null } | null | undefined): boolean {
return NOTICE_SCOPED_ACTION_CODES.has(String(action?.code || '').trim());
}
const formalTaskActions = computed(() => {
@@ -725,15 +744,23 @@ const formalTaskActions = computed(() => {
/** 行级库存选源动作:只在表格逐行处理,禁止作为任务级按钮出现在右侧"当前任务"卡(避免与表格打勾重复)。 */
const LINE_SCOPE_INVENTORY_ACTIONS = new Set([
'override_line_inventory_source',
'select_line_inventory_source',
]);
const currentTaskPrimaryAction = computed(() => {
if (formalTaskProjectionPending.value) return null;
if (hasFormalOt.value) {
const first = toCurrentTaskAction(formalTaskActions.value[0]);
if (!first || LINE_SCOPE_INVENTORY_ACTIONS.has(first.code)) return null;
return first;
// [§2.4 单源] 正式 OT 的主动作只从 A(shippingProcessingProjection.ui_state.primary_action)读,
// 不再读 B(formalTaskDetail.ui_state.actions —— 之后仅作工作面事实)。后端 flatten 已保证
// A==C==B(动作码同源),故该改动纯收敛、不改变已授权按钮。
// 注意:A 的 i18nKey 可能是 chat 域(如 chat.shippingProcessing.action.*),而右卡
// ReviewCurrentProcessingCard 只解析 workspace.shippingNotice.processGate.actionCodes.*,
// 故必须统一映射到卡片域,否则按钮会因 businessActionLabel 为空而 fail-closed 消失。
const action = currentTaskUiState.value?.primary_action ?? null;
if (!action?.code || LINE_SCOPE_INVENTORY_ACTIONS.has(action.code)) return null;
return {
code: String(action.code).trim(),
i18nKey: `workspace.shippingNotice.processGate.actionCodes.${action.code}`,
};
}
const projection = shippingProcessingProjection.value;
if (projection) {
@@ -759,6 +786,7 @@ const currentTaskPrimaryAction = computed(() => {
});
const currentTaskUserStatus = computed(() => {
if (formalTaskDetail.value?.ui_state?.lifecycle_stage === 'upload_complete') return 'completed';
if (recoveryProjectionPending.value) return 'running';
// 已确认 OT 且权威投影在途时,先消费后端 automation 运行态(queued/running → running,
// failed/manual_fallback → failed),状态行即显真实值,不应退回「正在获取最新状态」骨架;
// authority 仍以右侧投影为准,投影到达后覆盖。
@@ -778,6 +806,7 @@ const currentTaskUserStatus = computed(() => {
* 仅当原因码在隐藏白名单且映射结果==当前状态(纯重复)才隐藏,其余诊断信息一律保留。
*/
const currentTaskStatusDetail = computed<{ text: string } | null>(() => {
if (recoveryProjectionPending.value) return null;
if (['completed', 'cancelled'].includes(String(currentTaskUserStatus.value || ''))) return null;
const message = resolveExtractionActivityMessage(lifecycleProgressForView.value, { t, te });
if (!message) return null;
@@ -788,12 +817,14 @@ const currentTaskStatusDetail = computed<{ text: string } | null>(() => {
});
const currentTaskBlockingReason = computed(() => {
if (formalTaskDetail.value?.ui_state?.lifecycle_stage === 'upload_complete') return null;
if (recoveryProjectionPending.value) return null;
if (formalTaskProjectionPending.value) return null;
return currentTaskUiState.value?.blocking_reason ?? null;
});
/** 当前 Gate 状态必须与右栏动作同源,均来自统一处理 Projection。 */
const currentTaskGateStatus = computed(() => {
if (formalTaskDetail.value?.ui_state?.lifecycle_stage === 'upload_complete') return null;
if (recoveryProjectionPending.value) return 'running';
if (formalTaskProjectionPending.value) return null;
const projection = shippingProcessingProjection.value;
if (projection?.currentGate?.status) return projection.currentGate.status;
@@ -809,15 +840,20 @@ const currentTaskRetryable = computed(() => (
const currentTaskRecoveryActions = computed(() => {
if (formalTaskProjectionPending.value) return [];
if (hasFormalOt.value) {
// [STAGE_CAPABILITY] 门禁恢复动作 + 阶段能力(任务级、已启用)按 code 去重。
// 能力统一在右侧"当前任务"卡展示,主工作台不再重复放按钮。这样在整库存阶段
// (含非原生 gate,如 inventory_field_mapping 死局)右侧卡始终有"重抓/重读/改源"。
// 行级库存选源动作(override/select_line_inventory_source)只在表格逐行处理,
// 禁止作为任务级按钮出现在右侧卡,避免与表格"打勾"重复。
const gateRecovery = formalTaskActions.value.slice(1)
.filter((action) => String(action.code || '').trim() !== 'download_excel' && !isNoticeScopedAction(action))
.map(toCurrentTaskAction)
.filter((action): action is NonNullable<typeof action> => Boolean(action));
// [§2.4 单源] 恢复动作从 A(shippingProcessingProjection.ui_state.secondary_actions)读,
// 不再从 B(formalTaskDetail.ui_state.actions)slice。能力仍取任务级
// stage_context.preparation.capabilities(B 工作面事实,§2 保留)。动作码同源(A==C==B),
// 该改动纯收敛。行级库存选源动作只在表格逐行处理,禁止作为任务级按钮出现在右侧卡。
const gateRecovery = (currentTaskUiState.value?.secondary_actions || [])
.filter((action) => action.enabled
&& String(action.code || '').trim() !== 'download_excel'
&& !isNoticeScopedAction(action))
.map((action) => ({
code: String(action.code || '').trim(),
// 统一右卡 domain:actionCodes.<code>(见 currentTaskPrimaryAction 注;A 的 i18nKey 可能是 chat 域)。
i18nKey: `workspace.shippingNotice.processGate.actionCodes.${String(action.code || '').trim()}`,
}))
.filter((action): action is { code: string; i18nKey: string } => Boolean(action.code));
const capabilityActions = (formalPreparationContext.value?.capabilities || [])
.filter((cap) => cap.scope === 'task' && cap.enabled && String(cap.action_code || '').trim())
.map((cap) => ({
@@ -1640,6 +1676,10 @@ async function retryFormalUploadRpa(taskNo: string) {
* 一次性自动推进许可,待后端生命周期投影确认后才更新深链。
*/
function handleGateRecoveryAccepted(options: { releaseAutoAdvance?: boolean } = {}) {
if (hasFormalOt.value) {
recoveryProjectionBaselineVersion.value = shippingProcessingProjection.value?.progressVersion ?? null;
recoveryProjectionPending.value = true;
}
const caseNo = String(activeCase.value?.case_no || '').trim();
if (options.releaseAutoAdvance && caseNo) {
// 放行前可能是用户手动进入通知准备;该历史意图不能阻止本次放行后的自动推进。
@@ -2634,14 +2674,17 @@ async function retryFormalPreparationLine(
/**
* 人工上传登记是后端 Gate 的受控写动作;仅进入「货代上传」工作面不构成授权。
* 任务详情与批次中心共用 ui_state.actions,避免页面按上传状态或生命周期自行放行。
* [§2 单源] 授权从 A(shippingProcessingProjection.ui_state)读 —— §2.5 差异① 已归一,A 的
* secondary_actions/primary_action 透传原始 mark_manual_uploaded 码(与 B/C 一致的写契约码)。
* 避免页面按上传状态或生命周期自行放行。
*/
const manualUploadRegistrationAuthorized = computed(() => {
const actions = formalTaskDetail.value?.ui_state?.actions;
const candidates = [actions?.primary, ...(actions?.secondary || [])];
return candidates.some((action) => (
action?.code === 'mark_manual_uploaded' && action.enabled === true
));
const uiState = currentTaskUiState.value;
// primary_action 无 enabled 字段,出现即视为已授权;secondary_actions 必须 enabled === true。
if (uiState?.primary_action?.code === 'mark_manual_uploaded') return true;
return (uiState?.secondary_actions || []).some(
(action) => action.code === 'mark_manual_uploaded' && action.enabled === true,
);
});
/** 直接在订单复核页打开人工上传登记,避免依赖仅在 formal_task 模式挂载的 TaskTodoPanel ref。 */
@@ -2838,6 +2881,42 @@ watch(
{ immediate: true },
);
// ============================================================================
// 正式 OT 自动推进的「阶段无关」投影轮询(问题1修复的正解)
// ============================================================================
// 背景:shippingProcessingProjection 是整工作台唯一的轻量实时投影(progressVersion 变化会
// 触发 [REFRESH_ON_CHANGE] 重新加载正式任务详情 → 表格数字/门禁/阶段自动更新)。但它的刷新
// 完全依赖 startWorkflowProgressPolling(useShippingProcessingWorkItem 已关 continuousPolling),
// 而历史上只有「货代上传」watching 会持续推进该轮询;通知准备阶段的 RPA 取数→匹配→满足性
// 异步推进期间轮询被停,导致「可用数量/缺口/匹配状态」停在初值,需手动刷新。
// 方案:新增一条与业务阶段解耦的推进监控——只要存在正式 OT、且其投影仍处于「自动推进中」
// (非终态/非等待人工/非中断),就保持轮询;落到终态/等待人工即停止。与货代上传 watcher 互不耦合,
// prep 阶段不再寄生在 freight 逻辑上。
const OT_PROGRESS_ACTIVE_STATUSES = new Set(['running', 'processing', 'automating', 'queued']);
const OT_PROGRESS_IDLE_STATUSES = new Set(['waiting_human', 'interrupted', 'failed', 'completed', 'cancelled']);
function isOtProgressing(projection: typeof shippingProcessingProjection.value): boolean {
const status = String(
projection?.uiState?.status
|| projection?.userStatus
|| projection?.status
|| '',
).trim().toLowerCase();
return OT_PROGRESS_ACTIVE_STATUSES.has(status) && !OT_PROGRESS_IDLE_STATUSES.has(status);
}
watch(
[() => hasFormalOt.value, authoritativeOrderTaskNo, shippingProcessingProjection],
([hasOt, otNo, projection]) => {
// 仅当正式 OT 存在且其投影处于自动推进态时保持轮询;否则停止,避免空转。
if (!hasOt || !otNo || !projection || !isOtProgressing(projection)) {
if (workflowProgressPolling.value) stopWorkflowProgressPolling();
return;
}
// 已在轮询则不动,避免每次投影刷新都重建 interval(否则 2.5s 定时器被反复重置)。
if (!workflowProgressPolling.value) startWorkflowProgressPolling();
},
{ immediate: true },
);
function toggleFreightNoticeSelection(businessNo: string, checked: boolean) {
selectedFreightBusinessNos.value = checked
? Array.from(new Set([...selectedFreightBusinessNos.value, businessNo]))