feat(shipping-process-gates): 落地全门禁中断恢复并消除双真相
纳入 Execution/Gate/Attempt 模型与迁移、Worker/API/前端恢复卡片与 Admin 诊断, Gate 阻断时清零旧 action_buttons,异常摘要统一脱敏,并为运维筛选与 Attempt Diff 补齐入口。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
b352c281d5
commit
323928626b
92 files changed
+11930
-458
No files matched your search
+132
@@ -0,0 +1,132 @@
|
||||
/**
|
||||
* features/shipping-process-gates/composables/useShippingProcessGateRecovery.ts
|
||||
* 用途:任务工作台门禁恢复动作编排(导航、幂等键、版本锁、409 刷新)。
|
||||
* 依赖:process-gates.api、processGateNavigation、process-gate.types、useMessage。
|
||||
* 逻辑:ProcessGateRecoveryCard 调用 submitPrimaryAction;禁止本地发明 action_code。
|
||||
*/
|
||||
import { ref } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { useRouter } from 'vue-router';
|
||||
import { BusinessError, resolveLocalizedErrorMessage } from '@/shared/api/client';
|
||||
import { useMessage } from '@/shared/composables/useMessage';
|
||||
import { postWorkspaceProcessGateAction } from '../api/process-gates.api';
|
||||
import type {
|
||||
ShippingProcessGateActionCode,
|
||||
ShippingProcessGateUserSummary,
|
||||
} from '../types/process-gate.types';
|
||||
import {
|
||||
buildProcessGateNavigationRoute,
|
||||
isProcessGateNavigationAction,
|
||||
type ProcessGateNavigationContext,
|
||||
} from './processGateNavigation';
|
||||
|
||||
export type ProcessGateActionOutcome =
|
||||
| 'submitted'
|
||||
| 'navigated'
|
||||
| 'refresh_needed'
|
||||
| 'failed'
|
||||
| 'noop';
|
||||
|
||||
export interface ProcessGateActionResult {
|
||||
outcome: ProcessGateActionOutcome;
|
||||
}
|
||||
|
||||
function newIdempotencyKey(): string {
|
||||
if (typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function') {
|
||||
return crypto.randomUUID();
|
||||
}
|
||||
return `pg-${Date.now()}-${Math.random().toString(16).slice(2)}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* 编排单次门禁恢复:导航类动作直接 router.push;其余 POST 到 Workspace API。
|
||||
* @returns busy 状态与 submitPrimaryAction 方法
|
||||
*/
|
||||
export function useShippingProcessGateRecovery() {
|
||||
const { t } = useI18n();
|
||||
const msg = useMessage();
|
||||
const router = useRouter();
|
||||
const busy = ref(false);
|
||||
|
||||
/**
|
||||
* 提交或导航当前阻断 Gate 的主要恢复动作。
|
||||
* 核心逻辑:evaluation_version 来自 current_blocking_gate;409 返回 refresh_needed。
|
||||
*/
|
||||
async function submitPrimaryAction(
|
||||
summary: ShippingProcessGateUserSummary,
|
||||
options?: {
|
||||
payload?: Record<string, unknown>;
|
||||
navigationContext?: ProcessGateNavigationContext;
|
||||
},
|
||||
): Promise<ProcessGateActionResult> {
|
||||
const gate = summary.current_blocking_gate;
|
||||
const actionCode = (summary.next_action_code || gate?.next_action_code || '') as ShippingProcessGateActionCode | '';
|
||||
if (!summary.execution_no || !gate?.gate_code || !actionCode) {
|
||||
msg.warning(t('workspace.shippingNotice.processGate.noAction'));
|
||||
return { outcome: 'noop' };
|
||||
}
|
||||
|
||||
if (isProcessGateNavigationAction(actionCode)) {
|
||||
const route = buildProcessGateNavigationRoute(
|
||||
summary,
|
||||
actionCode,
|
||||
options?.navigationContext || {},
|
||||
);
|
||||
if (!route) {
|
||||
msg.warning(t('workspace.shippingNotice.processGate.navigationMissing'));
|
||||
return { outcome: 'failed' };
|
||||
}
|
||||
busy.value = true;
|
||||
try {
|
||||
await router.push(route);
|
||||
return { outcome: 'navigated' };
|
||||
} catch {
|
||||
msg.warning(t('workspace.shippingNotice.actions.failed'));
|
||||
return { outcome: 'failed' };
|
||||
} finally {
|
||||
busy.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
const expectedVersion = Number(gate.evaluation_version);
|
||||
if (!Number.isFinite(expectedVersion) || expectedVersion < 1) {
|
||||
msg.warning(t('workspace.shippingNotice.processGate.versionMissing'));
|
||||
return { outcome: 'failed' };
|
||||
}
|
||||
busy.value = true;
|
||||
try {
|
||||
await postWorkspaceProcessGateAction(summary.execution_no, String(gate.gate_code), {
|
||||
action_code: actionCode,
|
||||
expected_gate_version: expectedVersion,
|
||||
idempotency_key: newIdempotencyKey(),
|
||||
payload: options?.payload,
|
||||
});
|
||||
msg.success(t('workspace.shippingNotice.processGate.actionSubmitted'));
|
||||
return { outcome: 'submitted' };
|
||||
} catch (error: unknown) {
|
||||
const isVersionMismatch = error instanceof BusinessError && (
|
||||
error.code === 'SHIPPING.PROCESS_GATE_VERSION_MISMATCH'
|
||||
|| error.status === 409
|
||||
);
|
||||
if (isVersionMismatch) {
|
||||
msg.warning(resolveLocalizedErrorMessage(
|
||||
'SHIPPING.PROCESS_GATE_VERSION_MISMATCH',
|
||||
error instanceof BusinessError ? error.message : undefined,
|
||||
));
|
||||
return { outcome: 'refresh_needed' };
|
||||
}
|
||||
const message = error instanceof BusinessError
|
||||
? resolveLocalizedErrorMessage(error.code, error.message)
|
||||
: (error instanceof Error ? error.message : t('workspace.shippingNotice.actions.failed'));
|
||||
msg.warning(message);
|
||||
return { outcome: 'failed' };
|
||||
} finally {
|
||||
busy.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
busy,
|
||||
submitPrimaryAction,
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user