feat(shipping-notice): 完善处理投影与待办轮询

- 统一处理阶段、Gate 状态及跨页面投影
- 优化订单提取自动推进与待办分类查询
- 完善任务中心待办与批次轮询逻辑
- 补充后端投影、Gate、查询及 Worker 测试
- 新增待办轮询设计文档并更新技术文档
This commit is contained in:
hugo committed 2026-09-14 17:06:11 +08:00
1 parent 9d2fa522fa
commit fbca0b485c
22 files changed
+1454 -225

No files matched your search

@@ -6,7 +6,7 @@
* 逻辑:选中项展示入口卡 + 五阶段筛选 + 统一进度紧凑摘要;主按钮深链「订单生命周期工作台」;
* review_case 在 failed/manual_fallback 时提供「重试自动推进」(与底栏同一 API/幂等键);
* 不内嵌 ShippingTaskWorkbench;生命周期筛选、禁用与深链只消费后端
* ui_state.lifecycle_entries,Intake parse_status 仅用于解析任务轮询。
* ui_state.lifecycle_entries;轮询只跟系统 running,silent 刷新不闪加载。
*/
<script setup lang="ts">
import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue';
@@ -31,38 +31,24 @@ import {
import { useShippingTodoBadge } from '../composables/useShippingTodoBadge';
import { useMessage } from '@/shared/composables/useMessage';
import { BusinessError } from '@/shared/api/client';
import {
IN_PROGRESS_PROCESSING_STATUSES,
TERMINAL_PROCESSING_STATUSES,
} from '@/features/chat/shipping/shippingProcessingFulfillment';
import { resolveGateReasonLabel } from '@/features/shipping-progress/gateReasonLabel';
import {
isShippingTodoListItemInProgress,
resolveTodoCenterPollIntervalMs,
} from './shippingTaskCenterPolling';
import ShippingRunProgressTable from './ShippingRunProgressTable.vue';
import { downloadWorkspaceShippingNoticeExportArchive } from '@/features/chat/shipping/shippingDownload';
const { t, te } = useI18n();
const msg = useMessage();
/** 进行中 Workflow/Task 前台轮询间隔。 */
const FOREGROUND_POLL_MS = 2000;
/** 页面隐藏时后台轮询间隔。 */
const BACKGROUND_POLL_MS = 8000;
/**
* 判断详情是否仍处于进行中。
* 核心逻辑:优先统一 ui_state.stage;技术 processing status 仅用于轮询,不用于业务阶段展示。
* 判断详情是否仍处于系统处理中。
* 核心逻辑:与列表项同一 running 谓词;阶段码不得单独维持轮询。
*/
function isDetailInProgress(task: ShippingTaskDetail | null): boolean {
if (!task) return false;
const stage = String(task.ui_state?.stage?.code || '').trim();
if (stage) return stage !== 'upload_complete';
const unified = String(task.shipping_processing_status || '').trim().toLowerCase();
if (unified) {
if (TERMINAL_PROCESSING_STATUSES.has(unified)) return false;
return IN_PROGRESS_PROCESSING_STATUSES.has(unified);
}
return false;
return isShippingTodoListItemInProgress(task);
}
/**
@@ -119,6 +105,9 @@ const bucketCounts = ref<ShippingMyTodosCount>({
const chatAgentId = ref<number | null>(null);
let pollTimer: ReturnType<typeof setTimeout> | null = null;
let pollInFlight = false;
let pollFailureCount = 0;
let processingPollStartedAt: number | null = null;
let lastForegroundPullAt = 0;
const totalPages = computed(() => Math.max(1, Math.ceil(totalTasks.value / pageSize)));
const preferredTaskNo = computed(() =>
@@ -345,23 +334,41 @@ async function runNoticeBatchAction(action: 'download' | 'confirm' | 'rpa'): Pro
}
/**
* 是否应继续自动轮询:processing 桶、进行中直链详情,或 runs 面;列表项按统一投影。
* 当前页是否存在系统正在自动跑的项。
*/
const shouldAutoRefresh = computed(() => {
if (surface.value === 'runs') return true;
if (bucket.value === 'processing') return true;
const hasRunningWork = computed(() => {
if (isDirectTaskRoute.value && isDetailInProgress(detail.value)) return true;
return tasks.value.some((item) => isListItemInProgress(item));
});
/**
* 按页面可见性选择轮询间隔。
* 当前页是否仅为人工等待(用于 30s 低频轮询;已完成桶不轮询)。
*/
function resolvePollMs(): number {
if (typeof document !== 'undefined' && document.visibilityState === 'hidden') {
return BACKGROUND_POLL_MS;
}
return FOREGROUND_POLL_MS;
const hasHumanWaitWork = computed(() => {
if (hasRunningWork.value) return false;
if (surface.value !== 'todos') return false;
if (bucket.value === 'done') return false;
return tasks.value.length > 0;
});
/**
* 是否应继续自动轮询:系统在跑或当前页仍有人工待办。
*/
const shouldAutoRefresh = computed(() => hasRunningWork.value || hasHumanWaitWork.value);
/**
* 解析待办轮询间隔:running 复用批次函数;人工等待 30s。
*/
function resolvePollMs(): number | null {
const visibility = typeof document !== 'undefined' ? document.visibilityState : 'visible';
const elapsedMs = processingPollStartedAt != null ? Date.now() - processingPollStartedAt : 0;
return resolveTodoCenterPollIntervalMs({
hasRunning: hasRunningWork.value,
hasHumanWait: hasHumanWaitWork.value,
elapsedMs,
visibility,
failureCount: pollFailureCount,
});
}
/**
@@ -375,26 +382,32 @@ function stopAutoRefresh() {
}
/**
* 调度下一次自动刷新(仅进行中项)。
* 调度下一次自动刷新(仅系统在跑或人工等待低频)。
*/
function scheduleAutoRefresh() {
stopAutoRefresh();
if (!shouldAutoRefresh.value) return;
const intervalMs = resolvePollMs();
if (intervalMs == null) return;
pollTimer = setTimeout(() => {
void (async () => {
if (pollInFlight || !shouldAutoRefresh.value) {
if (pollInFlight) {
scheduleAutoRefresh();
return;
}
const nextInterval = resolvePollMs();
if (nextInterval == null) return;
pollInFlight = true;
try {
await refreshAll({ silent: true });
pollFailureCount = 0;
} catch {
pollFailureCount += 1;
} finally {
pollInFlight = false;
scheduleAutoRefresh();
}
})();
}, resolvePollMs());
}, intervalMs);
}
/**
@@ -450,10 +463,12 @@ function resetFilters() {
/**
* 拉取当前桶待办列表。
* @param resetPage - 切换桶时重置到第一页
* @param options.silent - 为 true 时不切换 loading,保留旧列表(轮询失败也不清空)
*/
async function loadTodos(resetPage = false) {
async function loadTodos(resetPage = false, options?: { silent?: boolean }) {
if (resetPage) currentPage.value = 1;
loading.value = true;
const silent = Boolean(options?.silent);
if (!silent) loading.value = true;
try {
const category = appliedFilters.value.todo_category || undefined;
const result = await listWorkspaceShippingMyTodos({
@@ -475,34 +490,37 @@ async function loadTodos(resetPage = false) {
if (hit) selectedRef.value = todoItemKey(hit);
}
} catch {
tasks.value = [];
totalTasks.value = 0;
if (!silent) {
tasks.value = [];
totalTasks.value = 0;
}
} finally {
loading.value = false;
if (!silent) loading.value = false;
}
}
/**
* 直链场景拉取任务摘要(仅入口卡,不挂工作台)。
*/
async function loadDetail(taskNo: string) {
detailLoading.value = true;
async function loadDetail(taskNo: string, options?: { silent?: boolean }) {
const silent = Boolean(options?.silent);
if (!silent) detailLoading.value = true;
try {
detail.value = await getWorkspaceShippingTask(taskNo);
} catch {
detail.value = null;
if (!silent) detail.value = null;
} finally {
detailLoading.value = false;
if (!silent) detailLoading.value = false;
}
}
/**
* 列表与(可选)直链摘要联动刷新。
*/
async function refreshAll(_options?: { silent?: boolean }) {
await Promise.all([loadTodos(), loadCounts()]);
async function refreshAll(options?: { silent?: boolean }) {
await Promise.all([loadTodos(false, options), loadCounts()]);
if (isDirectTaskRoute.value && preferredTaskNo.value) {
await loadDetail(preferredTaskNo.value);
await loadDetail(preferredTaskNo.value, options);
}
}
@@ -675,17 +693,46 @@ watch(selectedItem, (item) => {
detail.value = null;
});
watch(hasRunningWork, (running) => {
if (running) {
processingPollStartedAt = processingPollStartedAt ?? Date.now();
} else {
processingPollStartedAt = null;
}
});
watch(shouldAutoRefresh, () => {
scheduleAutoRefresh();
});
/**
* 页面可见性变化时重排轮询间隔。
* 回到前台时立刻静默拉一次,再按当前间隔重排。
*/
function pullOnForeground() {
const now = Date.now();
if (now - lastForegroundPullAt < 1000) {
scheduleAutoRefresh();
return;
}
lastForegroundPullAt = now;
void refreshAll({ silent: true }).finally(() => scheduleAutoRefresh());
}
/**
* 页面可见性变化时:可见则立刻刷新,隐藏则只拉长间隔。
*/
function onVisibilityChange() {
if (typeof document !== 'undefined' && document.visibilityState === 'visible') {
pullOnForeground();
return;
}
scheduleAutoRefresh();
}
function onWindowFocus() {
pullOnForeground();
}
onMounted(async () => {
await Promise.all([resolveChatAgent(), loadCounts(), loadTodos()]);
if (preferredTaskNo.value) {
@@ -703,12 +750,14 @@ onMounted(async () => {
}
}
document.addEventListener('visibilitychange', onVisibilityChange);
window.addEventListener('focus', onWindowFocus);
scheduleAutoRefresh();
});
onBeforeUnmount(() => {
stopAutoRefresh();
document.removeEventListener('visibilitychange', onVisibilityChange);
window.removeEventListener('focus', onWindowFocus);
});
</script>