fix(shipping-recovery): 恢复库存RPA入口与门禁恢复流程
This commit is contained in:
1 parent
eb55f407ae
commit
938f3dd0e8
8 files changed
+1329
-194
No files matched your search
@@ -14,10 +14,7 @@ import logging
|
|||||||
|
|
||||||
from flask import current_app
|
from flask import current_app
|
||||||
from app import db
|
from app import db
|
||||||
from app.models import (
|
from app.models import ShippingOrderTask, ShippingTaskInventoryRpaAttempt
|
||||||
ShippingNotice,
|
|
||||||
ShippingTaskInventoryRpaAttempt,
|
|
||||||
)
|
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -82,8 +79,8 @@ def _scan_stale_inventory_attempts(*, timeout_seconds: int) -> int:
|
|||||||
|
|
||||||
total = 0
|
total = 0
|
||||||
for task in (
|
for task in (
|
||||||
ShippingNotice.query
|
ShippingOrderTask.query
|
||||||
.filter(ShippingNotice.task_no.in_(task_nos))
|
.filter(ShippingOrderTask.task_no.in_(task_nos))
|
||||||
.all()
|
.all()
|
||||||
):
|
):
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ const api = vi.hoisted(() => ({
|
|||||||
confirmCase: vi.fn(),
|
confirmCase: vi.fn(),
|
||||||
|
|
||||||
validateDraft: vi.fn(),
|
validateDraft: vi.fn(),
|
||||||
|
patchHeader: vi.fn(),
|
||||||
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@@ -89,7 +90,7 @@ vi.mock('../api/shipping.api', () => ({
|
|||||||
|
|
||||||
confirmWorkspaceShippingOrderReviewCase: api.confirmCase,
|
confirmWorkspaceShippingOrderReviewCase: api.confirmCase,
|
||||||
|
|
||||||
patchWorkspaceShippingOrderReviewHeaderField: vi.fn(),
|
patchWorkspaceShippingOrderReviewHeaderField: api.patchHeader,
|
||||||
|
|
||||||
patchWorkspaceShippingOrderReviewLineField: vi.fn(),
|
patchWorkspaceShippingOrderReviewLineField: vi.fn(),
|
||||||
|
|
||||||
@@ -135,7 +136,7 @@ const buildCase = (patch: Partial<ShippingOrderReviewCase> = {}): ShippingOrderR
|
|||||||
|
|
||||||
header_values: {},
|
header_values: {},
|
||||||
|
|
||||||
lines: [{ line_key: 'line-1' }],
|
lines: [{ draft_line_id: 'line-1' }],
|
||||||
|
|
||||||
issues: [],
|
issues: [],
|
||||||
|
|
||||||
@@ -149,7 +150,7 @@ const buildCase = (patch: Partial<ShippingOrderReviewCase> = {}): ShippingOrderR
|
|||||||
|
|
||||||
line_projections: [{
|
line_projections: [{
|
||||||
|
|
||||||
line_key: 'line-1',
|
draft_line_id: 'line-1',
|
||||||
|
|
||||||
line_index: 0,
|
line_index: 0,
|
||||||
|
|
||||||
@@ -403,7 +404,7 @@ describe('useShippingOrderReview build eligibility writes', () => {
|
|||||||
expect(review.canConfirmBuild.value).toBe(false);
|
expect(review.canConfirmBuild.value).toBe(false);
|
||||||
|
|
||||||
expect(review.routingRecoveryLines.value).toHaveLength(1);
|
expect(review.routingRecoveryLines.value).toHaveLength(1);
|
||||||
expect(review.routingRecoveryLines.value[0]?.line_key).toBe('line-1');
|
expect(review.routingRecoveryLines.value[0]?.draft_line_id).toBe('line-1');
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -441,6 +442,68 @@ describe('useShippingOrderReview build eligibility writes', () => {
|
|||||||
expect(resume).toEqual({ outcome: 'auto_create_enqueued' });
|
expect(resume).toEqual({ outcome: 'auto_create_enqueued' });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('tracks an enqueued validation until the worker creates the formal order task', async () => {
|
||||||
|
vi.useFakeTimers();
|
||||||
|
const queuedCase = buildCase({
|
||||||
|
status: 'ready',
|
||||||
|
automation: { status: 'queued' },
|
||||||
|
});
|
||||||
|
const confirmedCase = buildCase({
|
||||||
|
status: 'confirmed',
|
||||||
|
order_task_no: 'OT-1',
|
||||||
|
confirmed_task_no: 'OT-1',
|
||||||
|
automation: { status: 'running' },
|
||||||
|
});
|
||||||
|
api.validateDraft.mockResolvedValue({
|
||||||
|
case: queuedCase,
|
||||||
|
resume_outcome: { outcome: 'auto_create_enqueued' },
|
||||||
|
});
|
||||||
|
api.getCase.mockResolvedValueOnce(buildCase()).mockResolvedValue(confirmedCase);
|
||||||
|
api.getQueue.mockResolvedValue({
|
||||||
|
summary: { total: 1, needs_action: 0, processing: 1, completed: 0 },
|
||||||
|
items: [{
|
||||||
|
case_no: 'CASE-1', document_id: 1, status: 'confirmed',
|
||||||
|
lifecycle_stage: 'fulfillment_prep', lifecycle_entries: [],
|
||||||
|
}],
|
||||||
|
});
|
||||||
|
api.getExtractionRun.mockResolvedValue({ run_no: 'RUN-1', status: 'completed' });
|
||||||
|
api.getProcessingWorkItem.mockResolvedValue({
|
||||||
|
work_item_no: 'OT-1', status: 'processing', stage: 'inventory_preparation',
|
||||||
|
});
|
||||||
|
|
||||||
|
const review = useShippingOrderReview();
|
||||||
|
await review.load('RUN-1', 'CASE-1');
|
||||||
|
await review.validate();
|
||||||
|
|
||||||
|
await vi.advanceTimersByTimeAsync(0);
|
||||||
|
expect(review.workflowProgressPolling.value).toBe(true);
|
||||||
|
await vi.advanceTimersByTimeAsync(PROGRESS_POLL_MS + 100);
|
||||||
|
expect(review.reviewProgressContext.value?.user_task_no).toBe('OT-1');
|
||||||
|
expect(api.getProcessingWorkItem).toHaveBeenCalledWith('order_task', 'OT-1');
|
||||||
|
|
||||||
|
review.stopWorkflowProgressPolling();
|
||||||
|
vi.useRealTimers();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does not treat a field edit revalidation as a formal-order creation request', async () => {
|
||||||
|
vi.useFakeTimers();
|
||||||
|
const revalidatingCase = buildCase({
|
||||||
|
status: 'draft',
|
||||||
|
automation: { status: 'queued' },
|
||||||
|
});
|
||||||
|
api.patchHeader.mockResolvedValue(revalidatingCase);
|
||||||
|
|
||||||
|
const review = useShippingOrderReview();
|
||||||
|
await review.load('RUN-1', 'CASE-1');
|
||||||
|
await review.patchHeader('ship_to_name', '新收货方');
|
||||||
|
await vi.advanceTimersByTimeAsync(PROGRESS_POLL_MS + 100);
|
||||||
|
|
||||||
|
// 字段编辑后的 queued 是异步重校验,不是用户已确认的建单请求。
|
||||||
|
expect(api.getCase).toHaveBeenCalledTimes(1);
|
||||||
|
expect(review.workflowProgressPolling.value).toBe(false);
|
||||||
|
vi.useRealTimers();
|
||||||
|
});
|
||||||
|
|
||||||
it('refreshes the current Case silently without entering the PDF-switch loading state', async () => {
|
it('refreshes the current Case silently without entering the PDF-switch loading state', async () => {
|
||||||
const review = useShippingOrderReview();
|
const review = useShippingOrderReview();
|
||||||
await review.load('RUN-1', 'CASE-1');
|
await review.load('RUN-1', 'CASE-1');
|
||||||
@@ -934,6 +997,44 @@ describe('useShippingOrderReview build eligibility writes', () => {
|
|||||||
vi.useRealTimers();
|
vi.useRealTimers();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('stops workflow progress polling once the unified work item is interrupted (waiting_human)', async () => {
|
||||||
|
vi.useFakeTimers();
|
||||||
|
const readyCase = buildCase({
|
||||||
|
status: 'ready',
|
||||||
|
draft: {
|
||||||
|
...buildCase().draft!,
|
||||||
|
build_eligibility: { can_build: true, status: 'ready', line_projections: [] },
|
||||||
|
},
|
||||||
|
});
|
||||||
|
api.getCase.mockResolvedValue(readyCase);
|
||||||
|
api.getRun.mockResolvedValue({
|
||||||
|
run_no: 'RUN-1', summary: {},
|
||||||
|
items: [{ case_no: 'CASE-1', document_id: 1, status: 'ready', available_actions: ['confirm'] }],
|
||||||
|
});
|
||||||
|
api.getEvidence.mockResolvedValue({ items: [] });
|
||||||
|
api.getPreview.mockResolvedValue({ preview_url: '' });
|
||||||
|
api.getProcessingWorkItem.mockResolvedValue({
|
||||||
|
work_item_no: 'OT-1', status: 'blocked', user_status: 'waiting_human',
|
||||||
|
currentGate: { gateCode: 'inventory_matching', status: 'blocked_manual' },
|
||||||
|
});
|
||||||
|
api.confirmCase.mockResolvedValue({
|
||||||
|
task_no: 'SN-1', order_task_no: 'OT-1', shipping_notice_no: 'SN-1', idempotent_replay: false,
|
||||||
|
case: { ...readyCase, status: 'confirmed', order_task_no: 'OT-1' }, auto_progress_started: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
const review = useShippingOrderReview();
|
||||||
|
await review.load('RUN-1', 'CASE-1', { conversationId: 'conv-1', itemNo: 'WFI-1' });
|
||||||
|
await review.confirm();
|
||||||
|
|
||||||
|
await vi.advanceTimersByTimeAsync(0);
|
||||||
|
await Promise.resolve();
|
||||||
|
// 中断(waiting_human,即“等待人工处理”)视为线性终态:结果不会自行变化,必须停止轮询。
|
||||||
|
expect(review.workflowProgressPolling.value).toBe(false);
|
||||||
|
|
||||||
|
review.stopWorkflowProgressPolling();
|
||||||
|
vi.useRealTimers();
|
||||||
|
});
|
||||||
|
|
||||||
it('refreshes the active Case and queue while post-confirm automation is still active', async () => {
|
it('refreshes the active Case and queue while post-confirm automation is still active', async () => {
|
||||||
vi.useFakeTimers();
|
vi.useFakeTimers();
|
||||||
const readyCase = buildCase({
|
const readyCase = buildCase({
|
||||||
@@ -1116,7 +1217,8 @@ describe('useShippingOrderReview build eligibility writes', () => {
|
|||||||
run_no: caseNo === 'CASE-2' ? 'RUN-2' : 'RUN-1',
|
run_no: caseNo === 'CASE-2' ? 'RUN-2' : 'RUN-1',
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const review = useShippingOrderReview();
|
const onReparseCaseReady = vi.fn();
|
||||||
|
const review = useShippingOrderReview({ onReparseCaseReady });
|
||||||
await review.load('RUN-1', 'CASE-1', { conversationId: 'conv-1', itemNo: 'SWI-1' });
|
await review.load('RUN-1', 'CASE-1', { conversationId: 'conv-1', itemNo: 'SWI-1' });
|
||||||
await review.reparseDocument('document_quality');
|
await review.reparseDocument('document_quality');
|
||||||
|
|
||||||
@@ -1125,6 +1227,8 @@ describe('useShippingOrderReview build eligibility writes', () => {
|
|||||||
|
|
||||||
expect(review.reviewRun.value?.run_no).toBe('RUN-2');
|
expect(review.reviewRun.value?.run_no).toBe('RUN-2');
|
||||||
expect(review.activeCase.value?.case_no).toBe('CASE-2');
|
expect(review.activeCase.value?.case_no).toBe('CASE-2');
|
||||||
|
// 关键断言:只有新版 Case 真正落到 activeCase 后,页面才接收可同步深链的目标。
|
||||||
|
expect(onReparseCaseReady).toHaveBeenCalledWith({ runNo: 'RUN-2', caseNo: 'CASE-2', documentId: 1 });
|
||||||
review.stopReparseCaseRefreshPolling();
|
review.stopReparseCaseRefreshPolling();
|
||||||
vi.useRealTimers();
|
vi.useRealTimers();
|
||||||
});
|
});
|
||||||
@@ -1250,6 +1354,44 @@ describe('useShippingOrderReview build eligibility writes', () => {
|
|||||||
vi.useRealTimers();
|
vi.useRealTimers();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('[选法 2] defers review Case + Evidence load on a formal downstream work item', async () => {
|
||||||
|
api.getRun.mockResolvedValue({ run_no: 'RUN-1', summary: {}, items: [] });
|
||||||
|
api.getQueue.mockResolvedValue({
|
||||||
|
summary: { total: 1, needs_action: 0, processing: 0, completed: 1 },
|
||||||
|
items: [{
|
||||||
|
case_no: 'CASE-1', document_id: 1, status: 'confirmed',
|
||||||
|
lifecycle_stage: 'fulfillment_prep', lifecycle_entries: [],
|
||||||
|
has_formal_ot: true, confirmed_task_no: 'SN-1',
|
||||||
|
}],
|
||||||
|
});
|
||||||
|
api.getCase.mockClear();
|
||||||
|
api.getEvidence.mockClear();
|
||||||
|
|
||||||
|
const review = useShippingOrderReview();
|
||||||
|
await review.load('RUN-1', 'CASE-1', { conversationId: 'conv-1' });
|
||||||
|
|
||||||
|
// 正式任务下游阶段:首屏不拉复核 Case 快照 + Evidence。
|
||||||
|
expect(api.getCase).not.toHaveBeenCalled();
|
||||||
|
expect(api.getEvidence).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('[选法 2] loadReviewCase lazily fetches review Case + Evidence on demand', async () => {
|
||||||
|
api.getCase.mockClear();
|
||||||
|
api.getEvidence.mockClear();
|
||||||
|
api.getCase.mockResolvedValue({
|
||||||
|
case: buildCase({ case_no: 'CASE-1' }),
|
||||||
|
projection_version: 1,
|
||||||
|
loading_context: null,
|
||||||
|
});
|
||||||
|
api.getEvidence.mockResolvedValue({ case_no: 'CASE-1', items: [] });
|
||||||
|
|
||||||
|
const review = useShippingOrderReview();
|
||||||
|
await review.loadReviewCase('CASE-1');
|
||||||
|
|
||||||
|
expect(api.getCase).toHaveBeenCalledWith('CASE-1');
|
||||||
|
expect(api.getEvidence).toHaveBeenCalledWith('CASE-1');
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
@@ -1295,7 +1437,7 @@ describe('inventory routing recovery', () => {
|
|||||||
can_build: true,
|
can_build: true,
|
||||||
status: 'ready',
|
status: 'ready',
|
||||||
line_projections: [{
|
line_projections: [{
|
||||||
line_key: 'line-pending',
|
draft_line_id: 'line-pending',
|
||||||
line_index: 0,
|
line_index: 0,
|
||||||
can_build: false,
|
can_build: false,
|
||||||
block_reason: 'inventory_source_unavailable',
|
block_reason: 'inventory_source_unavailable',
|
||||||
@@ -1309,7 +1451,7 @@ describe('inventory routing recovery', () => {
|
|||||||
const review = useShippingOrderReview();
|
const review = useShippingOrderReview();
|
||||||
await review.load('RUN-1', 'CASE-1');
|
await review.load('RUN-1', 'CASE-1');
|
||||||
expect(review.routingRecoveryLines.value).toHaveLength(1);
|
expect(review.routingRecoveryLines.value).toHaveLength(1);
|
||||||
expect(review.routingRecoveryLines.value[0]?.line_key).toBe('line-pending');
|
expect(review.routingRecoveryLines.value[0]?.draft_line_id).toBe('line-pending');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('reroutes inventory routing with idempotency_key and expected_draft_version', async () => {
|
it('reroutes inventory routing with idempotency_key and expected_draft_version', async () => {
|
||||||
@@ -1324,7 +1466,7 @@ describe('inventory routing recovery', () => {
|
|||||||
expect(api.rerouteInventoryRouting).toHaveBeenCalledWith('CASE-1', {
|
expect(api.rerouteInventoryRouting).toHaveBeenCalledWith('CASE-1', {
|
||||||
expected_draft_version: 2,
|
expected_draft_version: 2,
|
||||||
idempotency_key: 'idem-reroute-1',
|
idempotency_key: 'idem-reroute-1',
|
||||||
line_key: 'line-1',
|
draft_line_id: 'line-1',
|
||||||
});
|
});
|
||||||
expect(review.activeCase.value?.draft?.draft_version).toBe(3);
|
expect(review.activeCase.value?.draft?.draft_version).toBe(3);
|
||||||
uuidSpy.mockRestore();
|
uuidSpy.mockRestore();
|
||||||
|
|||||||
@@ -5,9 +5,17 @@
|
|||||||
* 逻辑:按 runNo 加载 Review Run/Case;合成 ShippingReviewProgressContext;
|
* 逻辑:按 runNo 加载 Review Run/Case;合成 ShippingReviewProgressContext;
|
||||||
* OT 绑定 Case.order_task_no / Candidate;切换时保留稳定显示壳,目标快照到齐后原子替换;
|
* OT 绑定 Case.order_task_no / Candidate;切换时保留稳定显示壳,目标快照到齐后原子替换;
|
||||||
* 409 REVIEW_DRAFT_VERSION_MISMATCH 冲突处理;build_eligibility 驱动 confirm/reroute;
|
* 409 REVIEW_DRAFT_VERSION_MISMATCH 冲突处理;build_eligibility 驱动 confirm/reroute;
|
||||||
* 重识别后刷新正式 Run/Case/Gate 投影;PDF Blob 由 ensurePreviewLoaded 按需加载。
|
* 重识别后刷新正式 Run/Case/Gate 投影,并在新版 Case 确认落位后通知页面同步深链;
|
||||||
|
* PDF Blob 由 ensurePreviewLoaded 按需加载。
|
||||||
*/
|
*/
|
||||||
import { computed, getCurrentInstance, onBeforeUnmount, ref } from 'vue';
|
import {
|
||||||
|
computed,
|
||||||
|
getCurrentInstance,
|
||||||
|
onBeforeUnmount,
|
||||||
|
ref,
|
||||||
|
toValue,
|
||||||
|
type MaybeRefOrGetter,
|
||||||
|
} from 'vue';
|
||||||
import { BusinessError } from '@/shared/api/client';
|
import { BusinessError } from '@/shared/api/client';
|
||||||
import {
|
import {
|
||||||
addWorkspaceShippingOrderReviewLine,
|
addWorkspaceShippingOrderReviewLine,
|
||||||
@@ -303,7 +311,13 @@ function synthesizeWorkItemFromReviewContext(params: {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useShippingOrderReview(options: { onWorkflowRefresh?: () => void } = {}) {
|
export function useShippingOrderReview(options: {
|
||||||
|
onWorkflowRefresh?: () => void;
|
||||||
|
/** 新版重解析 Case 已完成 load 后通知页面;路由和工作面仍由页面统一裁决。 */
|
||||||
|
onReparseCaseReady?: (target: { runNo: string; caseNo: string; documentId: number }) => void | Promise<void>;
|
||||||
|
/** 正式任务 OT 号(选法 2):正式任务下游阶段不再反推复核 Case,改由任务详情提供。 */
|
||||||
|
externalOrderTaskNo?: MaybeRefOrGetter<string | null | undefined>;
|
||||||
|
} = {}) {
|
||||||
const reviewRun = ref<ShippingOrderReviewRun | null>(null);
|
const reviewRun = ref<ShippingOrderReviewRun | null>(null);
|
||||||
const reviewQueue = ref<ShippingOrderReviewQueue | null>(null);
|
const reviewQueue = ref<ShippingOrderReviewQueue | null>(null);
|
||||||
const activeCase = ref<ShippingOrderReviewCase | null>(null);
|
const activeCase = ref<ShippingOrderReviewCase | null>(null);
|
||||||
@@ -316,8 +330,10 @@ export function useShippingOrderReview(options: { onWorkflowRefresh?: () => void
|
|||||||
const authoritativeOrderTaskNo = computed(() => {
|
const authoritativeOrderTaskNo = computed(() => {
|
||||||
const item = reviewProgressContext.value;
|
const item = reviewProgressContext.value;
|
||||||
const no = String(item?.user_task_no || '').trim();
|
const no = String(item?.user_task_no || '').trim();
|
||||||
if (!no || item?.user_task_authoritative === false) return null;
|
if (no && item?.user_task_authoritative !== false) return no;
|
||||||
return no;
|
// [选法 2] 正式任务下游阶段 activeCase 可能为空;OT 号改由任务详情提供。
|
||||||
|
const external = String(toValue(options.externalOrderTaskNo) ?? '').trim();
|
||||||
|
return external || null;
|
||||||
});
|
});
|
||||||
const {
|
const {
|
||||||
projection: shippingProcessingProjection,
|
projection: shippingProcessingProjection,
|
||||||
@@ -399,6 +415,7 @@ export function useShippingOrderReview(options: { onWorkflowRefresh?: () => void
|
|||||||
let contextConversationId = '';
|
let contextConversationId = '';
|
||||||
let contextItemNo = '';
|
let contextItemNo = '';
|
||||||
let progressPollTimer: ReturnType<typeof window.setInterval> | null = null;
|
let progressPollTimer: ReturnType<typeof window.setInterval> | null = null;
|
||||||
|
let stpCreatePollTimer: ReturnType<typeof window.setInterval> | null = null;
|
||||||
let reparseCaseRefreshTimer: ReturnType<typeof window.setInterval> | null = null;
|
let reparseCaseRefreshTimer: ReturnType<typeof window.setInterval> | null = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -423,12 +440,67 @@ export function useShippingOrderReview(options: { onWorkflowRefresh?: () => void
|
|||||||
workflowProgressPolling.value = false;
|
workflowProgressPolling.value = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 跟踪复核条件满足后的异步 STP 建单,直到后端产生正式 OT。
|
||||||
|
*
|
||||||
|
* 核心逻辑:复核写操作只保证校验/入队成功;Worker 后续才会把
|
||||||
|
* Case 绑定到 order_task_no。发现 OT 后复用既有任务级投影轮询,避免
|
||||||
|
* 在各个复核按钮中重复实现阶段刷新逻辑。
|
||||||
|
*/
|
||||||
|
const stopStpAutoCreateTracking = () => {
|
||||||
|
if (stpCreatePollTimer != null) {
|
||||||
|
window.clearInterval(stpCreatePollTimer);
|
||||||
|
stpCreatePollTimer = null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const startStpAutoCreateTracking = () => {
|
||||||
|
stopStpAutoCreateTracking();
|
||||||
|
const caseNo = String(activeCase.value?.case_no || '').trim();
|
||||||
|
const initialStatus = String(activeCase.value?.automation?.status || '').trim().toLowerCase();
|
||||||
|
if (!caseNo || !['queued', 'running'].includes(initialStatus)) return;
|
||||||
|
|
||||||
|
const tick = async () => {
|
||||||
|
if (typeof document !== 'undefined' && document.hidden) return;
|
||||||
|
try {
|
||||||
|
const [caseSnapshot, queue] = await Promise.all([
|
||||||
|
getWorkspaceShippingOrderReviewCase(caseNo),
|
||||||
|
reviewRun.value?.run_no
|
||||||
|
? getWorkspaceShippingOrderReviewQueue(reviewRun.value.run_no)
|
||||||
|
: Promise.resolve(null),
|
||||||
|
]);
|
||||||
|
if (String(activeCase.value?.case_no || '').trim() !== caseNo) return;
|
||||||
|
applyCaseSnapshot(caseSnapshot);
|
||||||
|
if (queue) reviewQueue.value = queue;
|
||||||
|
await refreshWorkItemContext();
|
||||||
|
const taskNo = String(
|
||||||
|
caseSnapshot.case?.order_task_no
|
||||||
|
|| caseSnapshot.case?.confirmed_task_no
|
||||||
|
|| reviewProgressContext.value?.user_task_no
|
||||||
|
|| '',
|
||||||
|
).trim();
|
||||||
|
const status = String(caseSnapshot.case?.automation?.status || '').trim().toLowerCase();
|
||||||
|
if (taskNo) {
|
||||||
|
stopStpAutoCreateTracking();
|
||||||
|
startWorkflowProgressPolling(taskNo);
|
||||||
|
} else if (['failed', 'manual_fallback'].includes(status)) {
|
||||||
|
stopStpAutoCreateTracking();
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// 临时网络失败由下一拍继续读取,不改变后端 Job 状态。
|
||||||
|
}
|
||||||
|
};
|
||||||
|
void tick();
|
||||||
|
stpCreatePollTimer = window.setInterval(() => { void tick(); }, PROGRESS_POLL_MS);
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 等待后端明确产出新复核 Case 后切换工作台,不将 Run 技术状态推断成另一条用户进度。
|
* 等待后端明确产出新复核 Case 后切换工作台,不将 Run 技术状态推断成另一条用户进度。
|
||||||
*
|
*
|
||||||
* AI 触发时机:用户发起“重新识别此 PDF”后调用。
|
* AI 触发时机:用户发起“重新识别此 PDF”后调用。
|
||||||
* 核心逻辑:以会话级 Review Stream 队列中同一 document_id 的 source_run_no + case_no
|
* 核心逻辑:以会话级 Review Stream 队列中同一 document_id 的 source_run_no + case_no
|
||||||
* 触发 Case 加载;completed 也可能已生成可复核 Case,不能仅按 Run 技术终态停止。
|
* 触发 Case 加载;新版 Case 真正落位后通知页面同步后端授权的生命周期深链;
|
||||||
|
* completed 也可能已生成可复核 Case,不能仅按 Run 技术终态停止。
|
||||||
* failed/cancelled 仅刷新正式投影并停止,失败原因由正式状态卡与 Gate 表达。
|
* failed/cancelled 仅刷新正式投影并停止,失败原因由正式状态卡与 Gate 表达。
|
||||||
*
|
*
|
||||||
* Args:
|
* Args:
|
||||||
@@ -457,13 +529,22 @@ export function useShippingOrderReview(options: { onWorkflowRefresh?: () => void
|
|||||||
if (['review_required', 'partially_completed', 'completed'].includes(normalizedStatus)) {
|
if (['review_required', 'partially_completed', 'completed'].includes(normalizedStatus)) {
|
||||||
const target = await resolveCurrentStreamTarget(targetDocumentId, targetRunNo);
|
const target = await resolveCurrentStreamTarget(targetDocumentId, targetRunNo);
|
||||||
if (target) {
|
if (target) {
|
||||||
window.clearInterval(reparseCaseRefreshTimer!);
|
|
||||||
reparseCaseRefreshTimer = null;
|
|
||||||
await load(target.runNo, target.caseNo, {
|
await load(target.runNo, target.caseNo, {
|
||||||
conversationId: contextConversationId,
|
conversationId: contextConversationId,
|
||||||
itemNo: contextItemNo || undefined,
|
itemNo: contextItemNo || undefined,
|
||||||
restoreProgress: false,
|
restoreProgress: false,
|
||||||
});
|
});
|
||||||
|
// [STEP] 只有新 Case 真正落到工作台才停止轮询;Stream 尚未激活或 load
|
||||||
|
// 静默失败(内部回滚旧快照)时保留下一拍重试,避免一次性失败把用户
|
||||||
|
// 永远留在已被替代的历史版本上。
|
||||||
|
if (String(activeCase.value?.case_no || '').trim() === target.caseNo) {
|
||||||
|
await options.onReparseCaseReady?.({
|
||||||
|
runNo: target.runNo,
|
||||||
|
caseNo: target.caseNo,
|
||||||
|
documentId: targetDocumentId || 0,
|
||||||
|
});
|
||||||
|
stopReparseCaseRefreshPolling();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -522,8 +603,11 @@ export function useShippingOrderReview(options: { onWorkflowRefresh?: () => void
|
|||||||
showWorkflowProgress.value = true;
|
showWorkflowProgress.value = true;
|
||||||
workflowProgressPolling.value = true;
|
workflowProgressPolling.value = true;
|
||||||
// RPA 超时、可重试失败和人工复核都可能被后续回调推进,页面留存期间持续读取 Projection。
|
// RPA 超时、可重试失败和人工复核都可能被后续回调推进,页面留存期间持续读取 Projection。
|
||||||
// needs_human(等待人工)视为线性终态:结果不会自行变化,继续轮询浪费资源。
|
// 等待人工(waiting_human,即“中断”)视为线性终态:结果不会自行变化,继续轮询浪费资源。
|
||||||
const UNIFIED_TERMINAL = new Set(['completed', 'cancelled', 'needs_human']);
|
// 注意:统一投影的用户态值是 waiting_human(旧字段是 needs_human),若沿用旧的
|
||||||
|
// needs_human 会让已中断任务永远匹配不到终态、一直空转轮询;failed 同理是停止状态。
|
||||||
|
// 可重试失败(retryable)不在此列,需保留轮询以便后续成功回调自动刷新工作流。
|
||||||
|
const UNIFIED_TERMINAL = new Set(['completed', 'cancelled', 'waiting_human', 'failed']);
|
||||||
let lastUnifiedStatus = '';
|
let lastUnifiedStatus = '';
|
||||||
let lastLifecycleFingerprint = '';
|
let lastLifecycleFingerprint = '';
|
||||||
const RUN_TERMINAL = new Set(['completed', 'partially_completed', 'failed', 'cancelled']);
|
const RUN_TERMINAL = new Set(['completed', 'partially_completed', 'failed', 'cancelled']);
|
||||||
@@ -589,6 +673,7 @@ export function useShippingOrderReview(options: { onWorkflowRefresh?: () => void
|
|||||||
onBeforeUnmount(() => {
|
onBeforeUnmount(() => {
|
||||||
caseSwitchAbortController?.abort();
|
caseSwitchAbortController?.abort();
|
||||||
stopWorkflowProgressPolling();
|
stopWorkflowProgressPolling();
|
||||||
|
stopStpAutoCreateTracking();
|
||||||
stopReparseCaseRefreshPolling();
|
stopReparseCaseRefreshPolling();
|
||||||
stopShippingProcessing();
|
stopShippingProcessing();
|
||||||
clearPreview();
|
clearPreview();
|
||||||
@@ -960,16 +1045,13 @@ export function useShippingOrderReview(options: { onWorkflowRefresh?: () => void
|
|||||||
const queueRequest = getWorkspaceShippingOrderReviewQueue(runNo);
|
const queueRequest = getWorkspaceShippingOrderReviewQueue(runNo);
|
||||||
// 路由已明确目标 Case 时,详情读取不应等待较慢的 Run/Queue 摘要;
|
// 路由已明确目标 Case 时,详情读取不应等待较慢的 Run/Queue 摘要;
|
||||||
// 四份数据仍在全部成功后原子提交,避免混合工作面。
|
// 四份数据仍在全部成功后原子提交,避免混合工作面。
|
||||||
const preferredCaseRequest = preferredCaseNo
|
|
||||||
? Promise.all([
|
|
||||||
getWorkspaceShippingOrderReviewCase(preferredCaseNo),
|
|
||||||
getWorkspaceShippingOrderReviewEvidence(preferredCaseNo),
|
|
||||||
])
|
|
||||||
: null;
|
|
||||||
// 已有稳定工作台且路由明确目标 PDF 时,目标详情是用户切换的关键路径;
|
// 已有稳定工作台且路由明确目标 PDF 时,目标详情是用户切换的关键路径;
|
||||||
// Run/Queue 只负责后续更新导航和阶段摘要,不能用其慢投影阻塞当前文件显示。
|
// Run/Queue 只负责后续更新导航和阶段摘要,不能用其慢投影阻塞当前文件显示。
|
||||||
if (hasStableWorkbench && preferredCaseRequest) {
|
if (hasStableWorkbench && preferredCaseNo) {
|
||||||
const [caseSnapshot, caseEvidence] = await preferredCaseRequest;
|
const [caseSnapshot, caseEvidence] = await Promise.all([
|
||||||
|
getWorkspaceShippingOrderReviewCase(preferredCaseNo),
|
||||||
|
getWorkspaceShippingOrderReviewEvidence(preferredCaseNo),
|
||||||
|
]);
|
||||||
if (generation !== caseLoadGeneration) return;
|
if (generation !== caseLoadGeneration) return;
|
||||||
applyCaseSnapshot(caseSnapshot);
|
applyCaseSnapshot(caseSnapshot);
|
||||||
evidence.value = caseEvidence?.items || [];
|
evidence.value = caseEvidence?.items || [];
|
||||||
@@ -987,22 +1069,28 @@ export function useShippingOrderReview(options: { onWorkflowRefresh?: () => void
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const [run, queue, preferredSnapshot] = await Promise.all([
|
const [run, queue] = await Promise.all([runRequest, queueRequest]);
|
||||||
runRequest,
|
|
||||||
queueRequest,
|
|
||||||
preferredCaseRequest,
|
|
||||||
]);
|
|
||||||
if (generation !== caseLoadGeneration) return;
|
if (generation !== caseLoadGeneration) return;
|
||||||
// [STREAM] Run 替代不等于其内全部 PDF 替代;当前文件只由队列 Stream 裁决。
|
// [STREAM] Run 替代不等于其内全部 PDF 替代;当前文件只由队列 Stream 裁决。
|
||||||
const caseNo = preferredCaseNo || queue.items[0]?.case_no || run.items[0]?.case_no;
|
const caseNo = preferredCaseNo || queue.items[0]?.case_no || run.items[0]?.case_no;
|
||||||
const [caseSnapshot, caseEvidence] = preferredSnapshot
|
// [选法 2] 正式任务下游阶段(通知准备/货代上传/通知完成)本阶段不拉复核编辑器
|
||||||
? preferredSnapshot
|
// (Case 快照 + Evidence),改由任务详情 + 统一投影驱动;进入「订单复核」才补拉。
|
||||||
: caseNo
|
const navItem = (queue.items || run.items).find(
|
||||||
? await Promise.all([
|
(item) => String(item.case_no || '').trim() === String(caseNo || '').trim(),
|
||||||
getWorkspaceShippingOrderReviewCase(caseNo),
|
) || null;
|
||||||
getWorkspaceShippingOrderReviewEvidence(caseNo),
|
const navStage = String(navItem?.lifecycle_stage || '').trim().toLowerCase();
|
||||||
])
|
const isFormalDownstream = Boolean(
|
||||||
: [null, null];
|
navItem?.has_formal_ot
|
||||||
|
&& !['intake_parse', 'order_review'].includes(navStage),
|
||||||
|
);
|
||||||
|
let caseSnapshot: ShippingOrderReviewCaseSnapshot | null = null;
|
||||||
|
let caseEvidence: { case_no: string; items: ShippingOrderReviewEvidence[] } | null = null;
|
||||||
|
if (!isFormalDownstream && caseNo) {
|
||||||
|
[caseSnapshot, caseEvidence] = await Promise.all([
|
||||||
|
getWorkspaceShippingOrderReviewCase(caseNo),
|
||||||
|
getWorkspaceShippingOrderReviewEvidence(caseNo),
|
||||||
|
]);
|
||||||
|
}
|
||||||
if (generation !== caseLoadGeneration) return;
|
if (generation !== caseLoadGeneration) return;
|
||||||
reviewRun.value = run;
|
reviewRun.value = run;
|
||||||
reviewQueue.value = queue;
|
reviewQueue.value = queue;
|
||||||
@@ -1134,6 +1222,8 @@ export function useShippingOrderReview(options: { onWorkflowRefresh?: () => void
|
|||||||
const save = async (action: () => Promise<ShippingOrderReviewCase>) => {
|
const save = async (action: () => Promise<ShippingOrderReviewCase>) => {
|
||||||
saving.value = true;
|
saving.value = true;
|
||||||
saveFailed.value = false;
|
saveFailed.value = false;
|
||||||
|
// 任意草稿变更都会使上一轮“已提交建单”跟踪失效;新的草稿版本必须重新显式提交。
|
||||||
|
stopStpAutoCreateTracking();
|
||||||
const localVersion = version();
|
const localVersion = version();
|
||||||
try {
|
try {
|
||||||
const nextCase = await action();
|
const nextCase = await action();
|
||||||
@@ -1182,9 +1272,9 @@ export function useShippingOrderReview(options: { onWorkflowRefresh?: () => void
|
|||||||
return String(field?.field_code || fieldId).trim();
|
return String(field?.field_code || fieldId).trim();
|
||||||
};
|
};
|
||||||
|
|
||||||
const draftLineIndex = (lineKey: string) => {
|
const draftLineIndex = (draftLineId: string) => {
|
||||||
const lines = activeCase.value?.draft?.lines || [];
|
const lines = activeCase.value?.draft?.lines || [];
|
||||||
return lines.findIndex((row) => String(row.line_key || '') === String(lineKey || ''));
|
return lines.findIndex((row) => String(row.draft_line_id || '') === String(draftLineId || ''));
|
||||||
};
|
};
|
||||||
|
|
||||||
const formalEditOptions = () => ({
|
const formalEditOptions = () => ({
|
||||||
@@ -1315,7 +1405,6 @@ export function useShippingOrderReview(options: { onWorkflowRefresh?: () => void
|
|||||||
fieldId: string,
|
fieldId: string,
|
||||||
value: unknown,
|
value: unknown,
|
||||||
restoreMachine = false,
|
restoreMachine = false,
|
||||||
override?: { override_reason_code?: string; override_reason_text?: string },
|
|
||||||
) => {
|
) => {
|
||||||
if (!activeCase.value) return Promise.resolve();
|
if (!activeCase.value) return Promise.resolve();
|
||||||
if (isFormalTaskFieldEdit()) {
|
if (isFormalTaskFieldEdit()) {
|
||||||
@@ -1338,8 +1427,6 @@ export function useShippingOrderReview(options: { onWorkflowRefresh?: () => void
|
|||||||
expected_draft_version: version(),
|
expected_draft_version: version(),
|
||||||
value,
|
value,
|
||||||
restore_machine: restoreMachine,
|
restore_machine: restoreMachine,
|
||||||
override_reason_code: override?.override_reason_code,
|
|
||||||
override_reason_text: override?.override_reason_text,
|
|
||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
const addLine = () => activeCase.value && save(() => addWorkspaceShippingOrderReviewLine(activeCase.value!.case_no, version()));
|
const addLine = () => activeCase.value && save(() => addWorkspaceShippingOrderReviewLine(activeCase.value!.case_no, version()));
|
||||||
@@ -1351,6 +1438,12 @@ export function useShippingOrderReview(options: { onWorkflowRefresh?: () => void
|
|||||||
try {
|
try {
|
||||||
const response = await validateWorkspaceShippingOrderReviewDraft(activeCase.value.case_no, version());
|
const response = await validateWorkspaceShippingOrderReviewDraft(activeCase.value.case_no, version());
|
||||||
await save(async () => response.case);
|
await save(async () => response.case);
|
||||||
|
// 只有显式“保存并校验”且后端确认已入队时,才跟踪 Worker 创建正式订单。
|
||||||
|
// 普通字段编辑/增删行虽然会触发异步重校验,但仍停留在订单复核阶段。
|
||||||
|
const outcome = String(response.resume_outcome?.outcome || '').trim();
|
||||||
|
if (['auto_create_enqueued', 'already_queued', 'already_running'].includes(outcome)) {
|
||||||
|
startStpAutoCreateTracking();
|
||||||
|
}
|
||||||
return response.resume_outcome;
|
return response.resume_outcome;
|
||||||
} finally {
|
} finally {
|
||||||
validationInProgress.value = false;
|
validationInProgress.value = false;
|
||||||
@@ -1359,15 +1452,15 @@ export function useShippingOrderReview(options: { onWorkflowRefresh?: () => void
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* ?????????????????409 ????? markWriteFailure?
|
* ?????????????????409 ????? markWriteFailure?
|
||||||
* @param lineKey - ???????? reroute
|
* @param draftLineId - 草稿行稳定身份;为空表示整单重算
|
||||||
*/
|
*/
|
||||||
const rerouteInventoryRouting = (lineKey?: string) => {
|
const rerouteInventoryRouting = (draftLineId?: string) => {
|
||||||
if (!activeCase.value) return Promise.resolve();
|
if (!activeCase.value) return Promise.resolve();
|
||||||
const trimmed = String(lineKey || '').trim();
|
const trimmed = String(draftLineId || '').trim();
|
||||||
return save(() => postWorkspaceShippingOrderReviewInventoryRoutingReroute(activeCase.value!.case_no, {
|
return save(() => postWorkspaceShippingOrderReviewInventoryRoutingReroute(activeCase.value!.case_no, {
|
||||||
expected_draft_version: version(),
|
expected_draft_version: version(),
|
||||||
idempotency_key: crypto.randomUUID(),
|
idempotency_key: crypto.randomUUID(),
|
||||||
...(trimmed ? { line_key: trimmed } : {}),
|
...(trimmed ? { draft_line_id: trimmed } : {}),
|
||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1517,7 +1610,7 @@ export function useShippingOrderReview(options: { onWorkflowRefresh?: () => void
|
|||||||
try {
|
try {
|
||||||
const response = await requestWorkspaceShippingOrderReviewLlmSuggestion(activeCase.value.case_no, {
|
const response = await requestWorkspaceShippingOrderReviewLlmSuggestion(activeCase.value.case_no, {
|
||||||
field_id: focusedFieldId.value,
|
field_id: focusedFieldId.value,
|
||||||
line_key: focusedLineKey.value,
|
draft_line_id: focusedLineKey.value,
|
||||||
issue_code: issueCode ?? undefined,
|
issue_code: issueCode ?? undefined,
|
||||||
expected_draft_version: activeCase.value.draft?.draft_version,
|
expected_draft_version: activeCase.value.draft?.draft_version,
|
||||||
});
|
});
|
||||||
@@ -1580,6 +1673,31 @@ export function useShippingOrderReview(options: { onWorkflowRefresh?: () => void
|
|||||||
return target;
|
return target;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 【选法 2】正式任务下游阶段懒加载复核编辑器:不重拉 Run/Queue,仅按需读取
|
||||||
|
* 当前文件的 Case 快照 + Evidence,供用户从「通知准备」切回「订单复核」阶段使用。
|
||||||
|
*/
|
||||||
|
const loadReviewCase = async (caseNo: string | null | undefined) => {
|
||||||
|
const normalized = String(caseNo || '').trim();
|
||||||
|
if (!normalized) return;
|
||||||
|
const generation = ++caseLoadGeneration;
|
||||||
|
try {
|
||||||
|
const [caseSnapshot, caseEvidence] = await Promise.all([
|
||||||
|
getWorkspaceShippingOrderReviewCase(normalized),
|
||||||
|
getWorkspaceShippingOrderReviewEvidence(normalized),
|
||||||
|
]);
|
||||||
|
if (generation !== caseLoadGeneration) return;
|
||||||
|
applyCaseSnapshot(caseSnapshot);
|
||||||
|
evidence.value = caseEvidence?.items || [];
|
||||||
|
clearPreview();
|
||||||
|
await refreshWorkItemContext(contextConversationId, contextItemNo, {
|
||||||
|
expectedLoadGeneration: generation,
|
||||||
|
});
|
||||||
|
} catch {
|
||||||
|
// 懒加载失败保留当前工作面,不抛到页面主流程。
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
reviewRun,
|
reviewRun,
|
||||||
reviewQueue,
|
reviewQueue,
|
||||||
@@ -1638,6 +1756,7 @@ export function useShippingOrderReview(options: { onWorkflowRefresh?: () => void
|
|||||||
saveFailed,
|
saveFailed,
|
||||||
versionsLoading,
|
versionsLoading,
|
||||||
load,
|
load,
|
||||||
|
loadReviewCase,
|
||||||
selectCase,
|
selectCase,
|
||||||
resetCaseTransientState,
|
resetCaseTransientState,
|
||||||
requestedCaseNo,
|
requestedCaseNo,
|
||||||
@@ -1654,6 +1773,8 @@ export function useShippingOrderReview(options: { onWorkflowRefresh?: () => void
|
|||||||
validate,
|
validate,
|
||||||
rerouteInventoryRouting,
|
rerouteInventoryRouting,
|
||||||
confirm,
|
confirm,
|
||||||
|
startStpAutoCreateTracking,
|
||||||
|
stopStpAutoCreateTracking,
|
||||||
startWorkflowProgressPolling,
|
startWorkflowProgressPolling,
|
||||||
stopWorkflowProgressPolling,
|
stopWorkflowProgressPolling,
|
||||||
startReparseCaseRefreshPolling,
|
startReparseCaseRefreshPolling,
|
||||||
|
|||||||
File diff suppressed because it is too large.
Load diff
@@ -200,6 +200,7 @@ const {
|
|||||||
isFieldEditable,
|
isFieldEditable,
|
||||||
loadReviewCase,
|
loadReviewCase,
|
||||||
showWorkflowProgress,
|
showWorkflowProgress,
|
||||||
|
workflowProgressPolling,
|
||||||
startWorkflowProgressPolling,
|
startWorkflowProgressPolling,
|
||||||
stopWorkflowProgressPolling,
|
stopWorkflowProgressPolling,
|
||||||
stopReparseCaseRefreshPolling,
|
stopReparseCaseRefreshPolling,
|
||||||
@@ -675,6 +676,32 @@ const showObjectRetryOnFooter = computed(() => (
|
|||||||
* 补任一字段。否则“检查已通过”与旧 Gate 的“待裁决”会被拼到同一张卡上。
|
* 补任一字段。否则“检查已通过”与旧 Gate 的“待裁决”会被拼到同一张卡上。
|
||||||
*/
|
*/
|
||||||
const currentTaskUiState = computed(() => shippingProcessingProjection.value?.uiState ?? null);
|
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 只是降级快照,不能先暴露可执行动作。
|
* 正式 OT 已存在且文件切换或统一处理投影读取中时,Case Gate 只是降级快照,不能先暴露可执行动作。
|
||||||
* Projection 返回后才拥有动作裁决权;非切换错误路径仍保留原有的 Case Gate 恢复能力。
|
* Projection 返回后才拥有动作裁决权;非切换错误路径仍保留原有的 Case Gate 恢复能力。
|
||||||
@@ -698,22 +725,14 @@ const NOTICE_SCOPED_ACTION_CODES = new Set([
|
|||||||
'regenerate_excel_artifact',
|
'regenerate_excel_artifact',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
function isNoticeScopedAction(action: ShippingUnifiedAction | null | undefined): boolean {
|
|
||||||
return NOTICE_SCOPED_ACTION_CODES.has(String(action?.code || '').trim());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 将正式任务详情的已启用 Gate 动作适配为右侧当前任务卡的展示契约。
|
* 判断动作是否属于 Notice 作用域(应在通知组而非任务卡展示)。
|
||||||
*
|
* 核心逻辑:只读 code,兼容 ShippingUnifiedAction 与 Projection 的 primary/secondary 动作形状。
|
||||||
* 正式 OT 的写授权只能来自 ``ui_state.actions``;统一处理 Projection 仅承载
|
* @param action - 任意带 code 的动作对象
|
||||||
* 进度、阶段和阻断事实,不能以历史动作码替代正式 Gate 动作。
|
* @returns 是否为 Notice 作用域动作
|
||||||
*/
|
*/
|
||||||
function toCurrentTaskAction(action: ShippingUnifiedAction | null | undefined) {
|
function isNoticeScopedAction(action: { code?: string | null } | null | undefined): boolean {
|
||||||
if (!action?.enabled || !String(action.code || '').trim() || isNoticeScopedAction(action)) return null;
|
return NOTICE_SCOPED_ACTION_CODES.has(String(action?.code || '').trim());
|
||||||
return {
|
|
||||||
code: String(action.code).trim(),
|
|
||||||
i18nKey: `workspace.shippingNotice.processGate.actionCodes.${action.code}`,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const formalTaskActions = computed(() => {
|
const formalTaskActions = computed(() => {
|
||||||
@@ -725,15 +744,23 @@ const formalTaskActions = computed(() => {
|
|||||||
/** 行级库存选源动作:只在表格逐行处理,禁止作为任务级按钮出现在右侧"当前任务"卡(避免与表格打勾重复)。 */
|
/** 行级库存选源动作:只在表格逐行处理,禁止作为任务级按钮出现在右侧"当前任务"卡(避免与表格打勾重复)。 */
|
||||||
const LINE_SCOPE_INVENTORY_ACTIONS = new Set([
|
const LINE_SCOPE_INVENTORY_ACTIONS = new Set([
|
||||||
'override_line_inventory_source',
|
'override_line_inventory_source',
|
||||||
'select_line_inventory_source',
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const currentTaskPrimaryAction = computed(() => {
|
const currentTaskPrimaryAction = computed(() => {
|
||||||
if (formalTaskProjectionPending.value) return null;
|
if (formalTaskProjectionPending.value) return null;
|
||||||
if (hasFormalOt.value) {
|
if (hasFormalOt.value) {
|
||||||
const first = toCurrentTaskAction(formalTaskActions.value[0]);
|
// [§2.4 单源] 正式 OT 的主动作只从 A(shippingProcessingProjection.ui_state.primary_action)读,
|
||||||
if (!first || LINE_SCOPE_INVENTORY_ACTIONS.has(first.code)) return null;
|
// 不再读 B(formalTaskDetail.ui_state.actions —— 之后仅作工作面事实)。后端 flatten 已保证
|
||||||
return first;
|
// 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;
|
const projection = shippingProcessingProjection.value;
|
||||||
if (projection) {
|
if (projection) {
|
||||||
@@ -759,6 +786,7 @@ const currentTaskPrimaryAction = computed(() => {
|
|||||||
});
|
});
|
||||||
const currentTaskUserStatus = computed(() => {
|
const currentTaskUserStatus = computed(() => {
|
||||||
if (formalTaskDetail.value?.ui_state?.lifecycle_stage === 'upload_complete') return 'completed';
|
if (formalTaskDetail.value?.ui_state?.lifecycle_stage === 'upload_complete') return 'completed';
|
||||||
|
if (recoveryProjectionPending.value) return 'running';
|
||||||
// 已确认 OT 且权威投影在途时,先消费后端 automation 运行态(queued/running → running,
|
// 已确认 OT 且权威投影在途时,先消费后端 automation 运行态(queued/running → running,
|
||||||
// failed/manual_fallback → failed),状态行即显真实值,不应退回「正在获取最新状态」骨架;
|
// failed/manual_fallback → failed),状态行即显真实值,不应退回「正在获取最新状态」骨架;
|
||||||
// authority 仍以右侧投影为准,投影到达后覆盖。
|
// authority 仍以右侧投影为准,投影到达后覆盖。
|
||||||
@@ -778,6 +806,7 @@ const currentTaskUserStatus = computed(() => {
|
|||||||
* 仅当原因码在隐藏白名单且映射结果==当前状态(纯重复)才隐藏,其余诊断信息一律保留。
|
* 仅当原因码在隐藏白名单且映射结果==当前状态(纯重复)才隐藏,其余诊断信息一律保留。
|
||||||
*/
|
*/
|
||||||
const currentTaskStatusDetail = computed<{ text: string } | null>(() => {
|
const currentTaskStatusDetail = computed<{ text: string } | null>(() => {
|
||||||
|
if (recoveryProjectionPending.value) return null;
|
||||||
if (['completed', 'cancelled'].includes(String(currentTaskUserStatus.value || ''))) return null;
|
if (['completed', 'cancelled'].includes(String(currentTaskUserStatus.value || ''))) return null;
|
||||||
const message = resolveExtractionActivityMessage(lifecycleProgressForView.value, { t, te });
|
const message = resolveExtractionActivityMessage(lifecycleProgressForView.value, { t, te });
|
||||||
if (!message) return null;
|
if (!message) return null;
|
||||||
@@ -788,12 +817,14 @@ const currentTaskStatusDetail = computed<{ text: string } | null>(() => {
|
|||||||
});
|
});
|
||||||
const currentTaskBlockingReason = computed(() => {
|
const currentTaskBlockingReason = computed(() => {
|
||||||
if (formalTaskDetail.value?.ui_state?.lifecycle_stage === 'upload_complete') return null;
|
if (formalTaskDetail.value?.ui_state?.lifecycle_stage === 'upload_complete') return null;
|
||||||
|
if (recoveryProjectionPending.value) return null;
|
||||||
if (formalTaskProjectionPending.value) return null;
|
if (formalTaskProjectionPending.value) return null;
|
||||||
return currentTaskUiState.value?.blocking_reason ?? null;
|
return currentTaskUiState.value?.blocking_reason ?? null;
|
||||||
});
|
});
|
||||||
/** 当前 Gate 状态必须与右栏动作同源,均来自统一处理 Projection。 */
|
/** 当前 Gate 状态必须与右栏动作同源,均来自统一处理 Projection。 */
|
||||||
const currentTaskGateStatus = computed(() => {
|
const currentTaskGateStatus = computed(() => {
|
||||||
if (formalTaskDetail.value?.ui_state?.lifecycle_stage === 'upload_complete') return null;
|
if (formalTaskDetail.value?.ui_state?.lifecycle_stage === 'upload_complete') return null;
|
||||||
|
if (recoveryProjectionPending.value) return 'running';
|
||||||
if (formalTaskProjectionPending.value) return null;
|
if (formalTaskProjectionPending.value) return null;
|
||||||
const projection = shippingProcessingProjection.value;
|
const projection = shippingProcessingProjection.value;
|
||||||
if (projection?.currentGate?.status) return projection.currentGate.status;
|
if (projection?.currentGate?.status) return projection.currentGate.status;
|
||||||
@@ -809,15 +840,20 @@ const currentTaskRetryable = computed(() => (
|
|||||||
const currentTaskRecoveryActions = computed(() => {
|
const currentTaskRecoveryActions = computed(() => {
|
||||||
if (formalTaskProjectionPending.value) return [];
|
if (formalTaskProjectionPending.value) return [];
|
||||||
if (hasFormalOt.value) {
|
if (hasFormalOt.value) {
|
||||||
// [STAGE_CAPABILITY] 门禁恢复动作 + 阶段能力(任务级、已启用)按 code 去重。
|
// [§2.4 单源] 恢复动作从 A(shippingProcessingProjection.ui_state.secondary_actions)读,
|
||||||
// 能力统一在右侧"当前任务"卡展示,主工作台不再重复放按钮。这样在整库存阶段
|
// 不再从 B(formalTaskDetail.ui_state.actions)slice。能力仍取任务级
|
||||||
// (含非原生 gate,如 inventory_field_mapping 死局)右侧卡始终有"重抓/重读/改源"。
|
// stage_context.preparation.capabilities(B 工作面事实,§2 保留)。动作码同源(A==C==B),
|
||||||
// 行级库存选源动作(override/select_line_inventory_source)只在表格逐行处理,
|
// 该改动纯收敛。行级库存选源动作只在表格逐行处理,禁止作为任务级按钮出现在右侧卡。
|
||||||
// 禁止作为任务级按钮出现在右侧卡,避免与表格"打勾"重复。
|
const gateRecovery = (currentTaskUiState.value?.secondary_actions || [])
|
||||||
const gateRecovery = formalTaskActions.value.slice(1)
|
.filter((action) => action.enabled
|
||||||
.filter((action) => String(action.code || '').trim() !== 'download_excel' && !isNoticeScopedAction(action))
|
&& String(action.code || '').trim() !== 'download_excel'
|
||||||
.map(toCurrentTaskAction)
|
&& !isNoticeScopedAction(action))
|
||||||
.filter((action): action is NonNullable<typeof action> => Boolean(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 || [])
|
const capabilityActions = (formalPreparationContext.value?.capabilities || [])
|
||||||
.filter((cap) => cap.scope === 'task' && cap.enabled && String(cap.action_code || '').trim())
|
.filter((cap) => cap.scope === 'task' && cap.enabled && String(cap.action_code || '').trim())
|
||||||
.map((cap) => ({
|
.map((cap) => ({
|
||||||
@@ -1640,6 +1676,10 @@ async function retryFormalUploadRpa(taskNo: string) {
|
|||||||
* 一次性自动推进许可,待后端生命周期投影确认后才更新深链。
|
* 一次性自动推进许可,待后端生命周期投影确认后才更新深链。
|
||||||
*/
|
*/
|
||||||
function handleGateRecoveryAccepted(options: { releaseAutoAdvance?: boolean } = {}) {
|
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();
|
const caseNo = String(activeCase.value?.case_no || '').trim();
|
||||||
if (options.releaseAutoAdvance && caseNo) {
|
if (options.releaseAutoAdvance && caseNo) {
|
||||||
// 放行前可能是用户手动进入通知准备;该历史意图不能阻止本次放行后的自动推进。
|
// 放行前可能是用户手动进入通知准备;该历史意图不能阻止本次放行后的自动推进。
|
||||||
@@ -2634,14 +2674,17 @@ async function retryFormalPreparationLine(
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 人工上传登记是后端 Gate 的受控写动作;仅进入「货代上传」工作面不构成授权。
|
* 人工上传登记是后端 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 manualUploadRegistrationAuthorized = computed(() => {
|
||||||
const actions = formalTaskDetail.value?.ui_state?.actions;
|
const uiState = currentTaskUiState.value;
|
||||||
const candidates = [actions?.primary, ...(actions?.secondary || [])];
|
// primary_action 无 enabled 字段,出现即视为已授权;secondary_actions 必须 enabled === true。
|
||||||
return candidates.some((action) => (
|
if (uiState?.primary_action?.code === 'mark_manual_uploaded') return true;
|
||||||
action?.code === 'mark_manual_uploaded' && action.enabled === true
|
return (uiState?.secondary_actions || []).some(
|
||||||
));
|
(action) => action.code === 'mark_manual_uploaded' && action.enabled === true,
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
/** 直接在订单复核页打开人工上传登记,避免依赖仅在 formal_task 模式挂载的 TaskTodoPanel ref。 */
|
/** 直接在订单复核页打开人工上传登记,避免依赖仅在 formal_task 模式挂载的 TaskTodoPanel ref。 */
|
||||||
@@ -2838,6 +2881,42 @@ watch(
|
|||||||
{ immediate: true },
|
{ 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) {
|
function toggleFreightNoticeSelection(businessNo: string, checked: boolean) {
|
||||||
selectedFreightBusinessNos.value = checked
|
selectedFreightBusinessNos.value = checked
|
||||||
? Array.from(new Set([...selectedFreightBusinessNos.value, businessNo]))
|
? Array.from(new Set([...selectedFreightBusinessNos.value, businessNo]))
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ export interface AdminProcessExecutionListPage {
|
|||||||
page_size: number;
|
page_size: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AdminProcessExecutionDetail extends ShippingProcessGateUserSummary {
|
export interface AdminProcessExecutionDetail extends Omit<ShippingProcessGateUserSummary, 'current_gate'> {
|
||||||
current_gate?: Record<string, unknown> | null;
|
current_gate?: Record<string, unknown> | null;
|
||||||
current_blocking_gate?: ShippingProcessGateUserSummary['current_blocking_gate'];
|
current_blocking_gate?: ShippingProcessGateUserSummary['current_blocking_gate'];
|
||||||
gates?: Array<Record<string, unknown>>;
|
gates?: Array<Record<string, unknown>>;
|
||||||
|
|||||||
+76
@@ -54,6 +54,24 @@ function summary() {
|
|||||||
} as never;
|
} as never;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 非原生 Gate 摘要:阶段能力不在 recovery_targets / allowed_actions 内(Task 5 根因)。 */
|
||||||
|
function capabilitySummary() {
|
||||||
|
return {
|
||||||
|
execution_no: 'EXEC-1',
|
||||||
|
status: 'blocked',
|
||||||
|
current_blocking_gate: {
|
||||||
|
gate_code: 'inventory_field_mapping',
|
||||||
|
evaluation_version: 5,
|
||||||
|
status: 'blocked',
|
||||||
|
},
|
||||||
|
primary_action: null,
|
||||||
|
allowed_actions: [],
|
||||||
|
recovery_targets: [],
|
||||||
|
action_presentation: [],
|
||||||
|
next_action_code: null,
|
||||||
|
} as never;
|
||||||
|
}
|
||||||
|
|
||||||
function mountComposable() {
|
function mountComposable() {
|
||||||
let exposed!: ReturnType<typeof useShippingProcessGateRecovery>;
|
let exposed!: ReturnType<typeof useShippingProcessGateRecovery>;
|
||||||
const app = createApp(defineComponent({
|
const app = createApp(defineComponent({
|
||||||
@@ -92,4 +110,62 @@ describe('useShippingProcessGateRecovery', () => {
|
|||||||
|
|
||||||
app.unmount();
|
app.unmount();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('dispatches an enabled stage capability past the server guard when stageCapabilityBypass is true', async () => {
|
||||||
|
// 断言:能力动作不在 recovery_targets / allowed_actions 内(非原生 Gate 的根因场景),
|
||||||
|
// 开启 stageCapabilityBypass 后仍应 POST 到 request_gate_action,而非返回 noop。
|
||||||
|
const { exposed, app } = mountComposable();
|
||||||
|
|
||||||
|
const result = await exposed.submitPrimaryAction(capabilitySummary(), {
|
||||||
|
actionCode: 'override_line_inventory_source',
|
||||||
|
stageCapabilityBypass: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(result.outcome).toBe('submitted');
|
||||||
|
expect(postActionMock).toHaveBeenCalledTimes(1);
|
||||||
|
expect(getExecutionMock).not.toHaveBeenCalled();
|
||||||
|
expect(postActionMock).toHaveBeenCalledWith(
|
||||||
|
'EXEC-1',
|
||||||
|
'inventory_field_mapping',
|
||||||
|
expect.objectContaining({ action_code: 'override_line_inventory_source' }),
|
||||||
|
);
|
||||||
|
|
||||||
|
app.unmount();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('uses current_gate when the user projection omits current_blocking_gate', async () => {
|
||||||
|
const { exposed, app } = mountComposable();
|
||||||
|
const result = await exposed.submitPrimaryAction({
|
||||||
|
execution_no: 'EXEC-1',
|
||||||
|
status: 'processing',
|
||||||
|
current_gate: { gate_code: 'inventory_preparation', evaluation_version: 7, status: 'running' },
|
||||||
|
allowed_actions: [],
|
||||||
|
recovery_targets: [],
|
||||||
|
} as never, {
|
||||||
|
actionCode: 'retry_inventory_preparation',
|
||||||
|
stageCapabilityBypass: true,
|
||||||
|
});
|
||||||
|
expect(result.outcome).toBe('submitted');
|
||||||
|
expect(postActionMock).toHaveBeenCalledWith(
|
||||||
|
'EXEC-1',
|
||||||
|
'inventory_preparation',
|
||||||
|
expect.objectContaining({ action_code: 'retry_inventory_preparation' }),
|
||||||
|
);
|
||||||
|
app.unmount();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('keeps a non-capability action not in recovery_targets / allowed_actions guarded as noop', async () => {
|
||||||
|
// 断言:普通门禁动作不在服务端恢复集合内时,仍被 serverRecoveryAction 守卫拦截
|
||||||
|
// 返回 noop,符合「普通动作必须保持服务端校验」的不变式。
|
||||||
|
const { exposed, app } = mountComposable();
|
||||||
|
|
||||||
|
const result = await exposed.submitPrimaryAction(capabilitySummary(), {
|
||||||
|
actionCode: 'retry_freight_upload_rpa',
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(result.outcome).toBe('noop');
|
||||||
|
expect(postActionMock).not.toHaveBeenCalled();
|
||||||
|
|
||||||
|
app.unmount();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
+57
-37
@@ -85,62 +85,82 @@ export function useShippingProcessGateRecovery() {
|
|||||||
navigationContext?: ProcessGateNavigationContext;
|
navigationContext?: ProcessGateNavigationContext;
|
||||||
/** 仅允许使用服务端 recovery_targets 下发的动作码覆盖主动作。 */
|
/** 仅允许使用服务端 recovery_targets 下发的动作码覆盖主动作。 */
|
||||||
actionCode?: ShippingProcessGateActionCode | string;
|
actionCode?: ShippingProcessGateActionCode | string;
|
||||||
|
/**
|
||||||
|
* 阶段能力强制绕过:跳过服务端 recovery_targets/allowed_actions 校验与展示精确匹配,
|
||||||
|
* 直接把请求动作码作为 mutation POST 到 request_gate_action;后端按阶段能力豁免
|
||||||
|
* (Task 4)做授权并执行 execute_stage_capability。仅由已按 enabled 裁决的调用方
|
||||||
|
* (如 prep 工作台)用于正式阶段能力;普通门禁动作必须保持服务端校验。
|
||||||
|
*/
|
||||||
|
stageCapabilityBypass?: boolean;
|
||||||
},
|
},
|
||||||
): Promise<ProcessGateActionResult> {
|
): Promise<ProcessGateActionResult> {
|
||||||
const gate = summary.current_blocking_gate;
|
// 正式 OT 的系统等待态不会投影 current_blocking_gate,但仍保留
|
||||||
|
// current_gate 供通知准备阶段能力(改源/重抓)提交到当前 Execution。
|
||||||
|
// 普通人工恢复优先使用 current_blocking_gate,避免把非当前 Gate 当成待办。
|
||||||
|
const gate = summary.current_blocking_gate || summary.current_gate;
|
||||||
const requestedAction = String(options?.actionCode || '').trim();
|
const requestedAction = String(options?.actionCode || '').trim();
|
||||||
|
const stageCapabilityBypass = Boolean(options?.stageCapabilityBypass);
|
||||||
const serverRecoveryAction = (summary.recovery_targets || [])
|
const serverRecoveryAction = (summary.recovery_targets || [])
|
||||||
.find((target) => String(target.action_code || '').trim() === requestedAction)
|
.find((target) => String(target.action_code || '').trim() === requestedAction)
|
||||||
?.action_code
|
?.action_code
|
||||||
|| (summary.allowed_actions || []).find((code) => String(code).trim() === requestedAction);
|
|| (summary.allowed_actions || []).find((code) => String(code).trim() === requestedAction);
|
||||||
if (requestedAction && !serverRecoveryAction) {
|
if (requestedAction && !stageCapabilityBypass && !serverRecoveryAction) {
|
||||||
msg.warning(t('workspace.shippingNotice.processGate.noAction'));
|
msg.warning(t('workspace.shippingNotice.processGate.noAction'));
|
||||||
return { outcome: 'noop' };
|
return { outcome: 'noop' };
|
||||||
}
|
}
|
||||||
const actionCode = (serverRecoveryAction || summary.next_action_code || gate?.next_action_code || '') as ShippingProcessGateActionCode | '';
|
// 阶段能力不在 recovery_targets/allowed_actions 内;绕过时以调用方请求动作码为准。
|
||||||
|
const actionCode = (
|
||||||
|
stageCapabilityBypass && requestedAction
|
||||||
|
? requestedAction
|
||||||
|
: (serverRecoveryAction || summary.next_action_code || gate?.next_action_code || '')
|
||||||
|
) as ShippingProcessGateActionCode | '';
|
||||||
if (!summary.execution_no || !gate?.gate_code || !actionCode) {
|
if (!summary.execution_no || !gate?.gate_code || !actionCode) {
|
||||||
msg.warning(t('workspace.shippingNotice.processGate.noAction'));
|
msg.warning(t('workspace.shippingNotice.processGate.noAction'));
|
||||||
return { outcome: 'noop' };
|
return { outcome: 'noop' };
|
||||||
}
|
}
|
||||||
|
|
||||||
const action = resolveActionPresentation(summary, String(actionCode));
|
// 阶段能力是纯 mutation POST:调用方已按 enabled 裁决,且其动作码不在门禁
|
||||||
if (!action) {
|
// action_presentation 内,故跳过展示精确匹配与 dialog/导航分支,由后端授权。
|
||||||
msg.warning(t('workspace.shippingNotice.processGate.noAction'));
|
if (!stageCapabilityBypass) {
|
||||||
return { outcome: 'noop' };
|
const action = resolveActionPresentation(summary, String(actionCode));
|
||||||
}
|
if (!action) {
|
||||||
|
|
||||||
if (String(action.dispatch || '').trim() === 'dialog') {
|
|
||||||
const uiHandler = String(action.ui_handler || '').trim();
|
|
||||||
if (!uiHandler) {
|
|
||||||
msg.warning(t('workspace.shippingNotice.processGate.noAction'));
|
msg.warning(t('workspace.shippingNotice.processGate.noAction'));
|
||||||
return { outcome: 'failed' };
|
return { outcome: 'noop' };
|
||||||
}
|
}
|
||||||
return {
|
|
||||||
outcome: 'dialog',
|
|
||||||
uiHandler,
|
|
||||||
taskNo: String(summary.navigation?.task_no || summary.task_no || '').trim().toUpperCase(),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isProcessGateNavigationAction(action)) {
|
if (String(action.dispatch || '').trim() === 'dialog') {
|
||||||
const route = buildProcessGateNavigationRoute(
|
const uiHandler = String(action.ui_handler || '').trim();
|
||||||
summary,
|
if (!uiHandler) {
|
||||||
action,
|
msg.warning(t('workspace.shippingNotice.processGate.noAction'));
|
||||||
options?.navigationContext || {},
|
return { outcome: 'failed' };
|
||||||
);
|
}
|
||||||
if (!route) {
|
return {
|
||||||
msg.warning(t('workspace.shippingNotice.processGate.navigationMissing'));
|
outcome: 'dialog',
|
||||||
return { outcome: 'failed' };
|
uiHandler,
|
||||||
|
taskNo: String(summary.navigation?.task_no || summary.task_no || '').trim().toUpperCase(),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
busy.value = true;
|
|
||||||
try {
|
if (isProcessGateNavigationAction(action)) {
|
||||||
await router.push(route);
|
const route = buildProcessGateNavigationRoute(
|
||||||
return { outcome: 'navigated' };
|
summary,
|
||||||
} catch {
|
action,
|
||||||
msg.warning(t('workspace.shippingNotice.actions.failed'));
|
options?.navigationContext || {},
|
||||||
return { outcome: 'failed' };
|
);
|
||||||
} finally {
|
if (!route) {
|
||||||
busy.value = false;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user