feat(queue): 添加旧知识库任务入队兼容入口

- 增加 enqueue_kb_job 和 enqueue_clean_job 函数以支持旧 KB 清洗任务入队
- 在 enqueue 函数中处理 KB_CLEAN 和 KB_DIFY_SYNC 类型的任务
- 引入 ValidationError 以处理 job_id 缺失的情况

feat(shipping_notice): 更新库存 RPA 工作流逻辑
- 修改 ensure_inventory_via_rpa 函数以支持手动重试逻辑
- 优化库存导出触发和状态更新的消息提示

fix(i18n): 更新任务未找到的提示信息
- 修改中文和英文提示,明确用户操作要求

feat(shipping_notice): 增强任务解析逻辑
- 添加缺失 Reservation ID 的检查,阻止任务进入确认阶段
- 更新 get_task_status 函数以处理多票会话的任务解析
This commit is contained in:
hugo committed 2026-06-30 21:00:25 +08:00
1 parent eb0466245b
commit 4cd987eef6
45 files changed
+2748 -1406

No files matched your search

@@ -189,6 +189,7 @@ const page = useChatPageContext();
@switch-batch="page.switchShippingBatch"
@focus-task="page.switchShippingFocusTask"
@resume-task="page.resumeShippingTask"
@retry-rpa="page.retryShippingInventoryRpa"
@query-shortage="page.queryShippingShortageDetails"
@retry-pending="page.retryCurrentShippingBatchPendingTasks"
/>
@@ -6,10 +6,11 @@
* 逻辑:生成式执行摘要由聊天消息流承载;本组件只提供固定状态 chrome 和明确范围的批次操作。
*/
import { computed, ref } from 'vue';
import { List, RefreshCw } from 'lucide-vue-next';
import { AlertTriangle, List, RefreshCw } from 'lucide-vue-next';
import { useI18n } from 'vue-i18n';
import { retryWorkspaceShippingBatchPending } from '@/features/chat/api/shipping.api';
import { useMessage } from '@/shared/composables/useMessage';
import { buildShippingWorkflowSteps } from '@/features/chat/shipping';
import type {
ShippingBatchSummary,
ShippingConversationWorkspace,
@@ -35,11 +36,20 @@ const { t } = useI18n();
const msg = useMessage();
const retryingPending = ref(false);
const COMPLETED_PROCESS_STATUSES = new Set(['uploaded', 'closed']);
const COMPLETED_PROCESS_STATUSES = new Set(['uploaded', 'completed', 'closed']);
const FAILED_PROCESS_STATUSES = new Set(['rejected', 'upload_failed']);
const workspaceBatches = computed(() => props.conversationWorkspace?.batches || []);
const activeBatchNo = computed(() =>
String(props.activeBatchNo || props.batchSummary?.batch_no || workspaceBatches.value[0]?.batch_no || '').trim(),
);
const focusedTaskNo = computed(() =>
String(
props.activeTaskDetail?.task_no
|| props.batchSummary?.current_focus_task_no
|| props.batchSummary?.process_summary?.current_task_no
|| '',
).trim(),
);
const processSummary = computed(() => {
const summary = props.batchSummary?.process_summary || null;
@@ -53,14 +63,19 @@ const processSummary = computed(() => {
(task) => !COMPLETED_PROCESS_STATUSES.has(String(task.process_status || '').trim()),
) ? 1 : 0;
const running = Number(summary?.running || runningFallback || 0);
const pending = Math.max(0, Number(summary?.pending ?? (total - completed - running)));
return { total, completed, running, pending };
const taskAbnormal = props.batchTasks.filter((task) => {
const status = String(task.process_status || '').trim();
return FAILED_PROCESS_STATUSES.has(status)
|| task.upload_status === 'failed'
|| Boolean(task.review_status || task.pending_human_reason);
}).length;
const summaryAbnormal = Number(summary?.failed || 0) + Number((summary as { needs_human?: number })?.needs_human || 0);
const abnormal = Math.max(taskAbnormal, summaryAbnormal);
const pending = Math.max(0, Number(summary?.pending ?? (total - completed - running - abnormal)));
return { total, completed, running, pending, abnormal };
});
const abnormalCount = computed(() => {
const batchSummary = props.batchSummary?.process_summary || {};
return Number(batchSummary.failed || 0) + Number((batchSummary as { needs_human?: number }).needs_human || 0);
});
const abnormalCount = computed(() => processSummary.value.abnormal);
const progressPercent = computed(() =>
processSummary.value.total
@@ -87,6 +102,53 @@ const executionStateMeta = computed(() => {
};
});
const activeTaskSteps = computed(() => buildShippingWorkflowSteps(props.activeTaskDetail));
const activeStepIndex = computed(() => {
const index = activeTaskSteps.value.findIndex((step) => step.status === 'current' || step.status === 'blocked');
return index >= 0 ? index : Math.max(0, activeTaskSteps.value.length - 1);
});
const activeStepLabel = computed(() => {
const step = activeTaskSteps.value[activeStepIndex.value];
return step ? t('chat.shippingNoticeUi.stepHeadline', {
current: activeStepIndex.value + 1,
total: activeTaskSteps.value.length,
label: t(step.label),
}) : '--';
});
const blockingMeta = computed(() => {
const task = props.activeTaskDetail;
if (!task) return null;
const reason = String(task.pending_human_reason || '').trim();
const reviewStatus = String(task.review_status || '').trim();
const processStatus = String(task.process_status || '').trim();
if (processStatus === 'upload_failed' || task.upload_status === 'failed') {
return {
text: t('chat.shippingNoticeUi.blockedUploadRetryable'),
className: 'border-rose-200 bg-rose-50 text-rose-700',
};
}
if (reason === 'shortage' || reason === 'shortage_review' || reviewStatus === 'shortage_review') {
return {
text: t('chat.shippingNoticeUi.blockedShortage'),
className: 'border-amber-200 bg-amber-50 text-amber-700',
};
}
if (reason === 'low_confidence' || reviewStatus === 'parse_review') {
return {
text: t('chat.shippingNoticeUi.blockedParseReview'),
className: 'border-amber-200 bg-amber-50 text-amber-700',
};
}
if (reason || reviewStatus) {
return {
text: t('chat.shippingNoticeUi.blockedWaitingHuman'),
className: 'border-amber-200 bg-amber-50 text-amber-700',
};
}
return null;
});
const handleRetryPending = async () => {
const batchNo = String(props.batchSummary?.batch_no || '').trim();
if (!batchNo || retryingPending.value) return;
@@ -107,24 +169,39 @@ const handleRetryPending = async () => {
<div
class="mx-auto w-full max-w-4xl rounded-2xl border border-default bg-gradient-to-r from-sky-50 via-white to-emerald-50 px-6 py-4 shadow-sm"
>
<div class="flex flex-wrap items-center justify-between gap-3">
<div class="flex flex-wrap items-start justify-between gap-3">
<div class="min-w-0 flex-1">
<div class="flex flex-wrap items-center gap-2 text-xs text-slate-500">
<span class="font-mono font-semibold text-brand-700">{{ activeBatchNo || '--' }}</span>
<span>
{{ t('chat.shippingNoticeUi.batchChromeSummary', {
total: processSummary.total,
completed: processSummary.completed,
running: processSummary.running,
abnormal: abnormalCount,
}) }}
</span>
<span>{{ t('chat.shippingNoticeUi.fileCount') }} {{ processSummary.total }}</span>
<span>{{ t('chat.shippingNoticeUi.completedCount') }} {{ processSummary.completed }}</span>
<span>{{ t('chat.shippingNoticeUi.runningCount') }} {{ processSummary.running }}</span>
<span>{{ t('chat.shippingNoticeUi.pendingCount') }} {{ processSummary.pending }}</span>
<span>{{ t('chat.shippingNoticeUi.needsIntervention') }} {{ abnormalCount }}</span>
<span
class="rounded-full border px-2 py-0.5 text-[11px] font-semibold"
:class="executionStateMeta.className"
>
{{ executionStateMeta.text }}
</span>
<span
v-if="blockingMeta"
class="inline-flex items-center gap-1 rounded-full border px-2 py-0.5 text-[11px] font-semibold"
:class="blockingMeta.className"
>
<AlertTriangle class="h-3 w-3" />
{{ blockingMeta.text }}
</span>
</div>
<div class="mt-2 flex flex-wrap items-center gap-x-4 gap-y-1 text-xs text-secondary">
<span>
<span class="text-muted">{{ t('chat.shippingNoticeUi.currentFocus') }}</span>
<span class="font-mono font-semibold text-primary">{{ focusedTaskNo || '--' }}</span>
</span>
<span>
<span class="text-muted">{{ t('chat.shippingNoticeUi.currentStepLabel') }}:</span>
<span class="font-medium text-primary">{{ activeStepLabel }}</span>
</span>
</div>
<div class="mt-2 h-1.5 max-w-md overflow-hidden rounded-full bg-slate-200">
<div
@@ -33,12 +33,13 @@ const emit = defineEmits<{
'switch-batch': [batchNo: string];
'focus-task': [taskNo: string];
'resume-task': [taskNo: string];
'retry-rpa': [taskNo: string];
'query-shortage': [taskNo: string];
'retry-pending': [];
}>();
const { t } = useI18n();
const activeFilter = ref<'all' | 'abnormal' | 'completed'>('all');
const activeFilter = ref<'all' | 'abnormal' | 'waitingHuman' | 'resumable' | 'completed'>('all');
const COMPLETED_PROCESS_STATUSES = new Set(['uploaded', 'completed', 'closed']);
@@ -59,6 +60,21 @@ const isAbnormalTask = (task: ShippingTaskSummary | ShippingTaskDetail) =>
|| Boolean(task.review_status || task.pending_human_reason)
|| String(task.process_status || '').trim() === 'waiting_inventory');
const isWaitingHumanTask = (task: ShippingTaskSummary | ShippingTaskDetail) =>
!isCompletedTask(task) && !isFailedTask(task) && Boolean(task.review_status || task.pending_human_reason);
const isResumableTask = (task: ShippingTaskSummary | ShippingTaskDetail) =>
!isCompletedTask(task) && !isWaitingHumanTask(task) && (
isFailedTask(task)
|| ['created', 'parsed', 'inventory_ready', 'matched', 'waiting_upload'].includes(String(task.process_status || '').trim())
);
const canRetryInventoryRpa = (task: ShippingTaskSummary | ShippingTaskDetail) => {
const reason = String(task.pending_human_reason || '').trim().toLowerCase();
const status = String(task.process_status || '').trim().toLowerCase();
return status === 'waiting_inventory' && ['rpa_exhausted', 'rpa_pending', 'inv_unavail'].includes(reason);
};
const batchAbnormalCount = (batch: ShippingBatchSummary) => {
const summary = batch.process_summary || {};
return Number(summary.failed || 0) + Number((summary as { needs_human?: number }).needs_human || 0);
@@ -74,9 +90,13 @@ const taskCounts = computed(() => {
const tasks = props.batchTasks || [];
const completed = tasks.filter(isCompletedTask).length;
const abnormal = tasks.filter(isAbnormalTask).length;
const waitingHuman = tasks.filter(isWaitingHumanTask).length;
const resumable = tasks.filter(isResumableTask).length;
return {
total: tasks.length,
abnormal,
waitingHuman,
resumable,
completed,
};
});
@@ -84,6 +104,8 @@ const taskCounts = computed(() => {
const filteredTasks = computed(() => {
const tasks = props.batchTasks || [];
if (activeFilter.value === 'abnormal') return tasks.filter(isAbnormalTask);
if (activeFilter.value === 'waitingHuman') return tasks.filter(isWaitingHumanTask);
if (activeFilter.value === 'resumable') return tasks.filter(isResumableTask);
if (activeFilter.value === 'completed') return tasks.filter(isCompletedTask);
return tasks;
});
@@ -107,6 +129,17 @@ const resolveTaskStateMeta = (task: ShippingTaskSummary | ShippingTaskDetail) =>
const taskStepNumber = (task: ShippingTaskSummary | ShippingTaskDetail) =>
resolveActiveStep(buildShippingWorkflowSteps(task)) + 1;
const taskStepHeadline = (task: ShippingTaskSummary | ShippingTaskDetail) => {
const steps = buildShippingWorkflowSteps(task);
const index = resolveActiveStep(steps);
const step = steps[index];
return step ? t('chat.shippingNoticeUi.stepHeadline', {
current: index + 1,
total: steps.length,
label: t(step.label),
}) : t('chat.shippingNoticeUi.stepFraction', { current: index + 1, total: steps.length });
};
const currentStepProgress = (task: ShippingTaskSummary | ShippingTaskDetail) =>
task.step_payload?.current_step_progress || null;
@@ -192,6 +225,27 @@ const resolveTaskDiagnosis = (task: ShippingTaskSummary | ShippingTaskDetail) =>
};
};
const resolveSuggestedAction = (task: ShippingTaskSummary | ShippingTaskDetail) => {
const reason = String(task.pending_human_reason || '').trim();
const reviewStatus = String(task.review_status || '').trim();
if (hasShortageLines(task) || reason === 'shortage' || reviewStatus === 'shortage_review') {
return t('chat.shippingNoticeUi.suggestShortageActions');
}
if (reason === 'align_review' || reviewStatus === 'align_review') {
return t('chat.shippingNoticeUi.suggestConfirmMapping');
}
if (reason === 'low_confidence' || reviewStatus === 'parse_review') {
return t('chat.shippingNoticeUi.suggestReviewParse');
}
if (isFailedTask(task)) {
return t('chat.shippingNoticeUi.suggestRetryStep');
}
if (isCompletedTask(task)) {
return t('chat.shippingNoticeUi.suggestViewOnly');
}
return t('chat.shippingNoticeUi.suggestContinue');
};
const resolveActiveStep = (steps: ShippingWorkflowStepItem[]) => {
const activeIndex = steps.findIndex((step) => step.status === 'current' || step.status === 'blocked');
return activeIndex >= 0 ? activeIndex : Math.max(0, steps.length - 1);
@@ -258,8 +312,9 @@ const handleSwitchBatch = (batchNo: string) => {
</div>
<div class="flex-1 overflow-y-auto px-6 py-6">
<section class="rounded-2xl border border-default bg-surface p-4 shadow-sm">
<h3 class="text-sm font-bold text-primary">{{ t('chat.shippingNoticeUi.batchActionsTitle') }}</h3>
<section class="rounded-lg border border-default bg-surface p-4 shadow-sm">
<h3 class="text-sm font-bold text-primary">{{ t('chat.shippingNoticeUi.taskQueueTitle') }}</h3>
<p class="mt-1 text-xs leading-5 text-muted">{{ t('chat.shippingNoticeUi.taskQueueHint') }}</p>
<div class="mt-4">
<button
type="button"
@@ -281,7 +336,7 @@ const handleSwitchBatch = (batchNo: string) => {
<h3 class="text-sm font-bold text-primary">
{{ t('chat.shippingNoticeUi.taskDetailCount', { count: filteredTasks.length }) }}
</h3>
<div class="flex rounded-lg bg-slate-100 p-1 text-xs">
<div class="flex flex-wrap rounded-lg bg-slate-100 p-1 text-xs">
<button
type="button"
class="rounded px-3 py-1 transition-colors"
@@ -298,6 +353,22 @@ const handleSwitchBatch = (batchNo: string) => {
>
{{ t('chat.shippingNoticeUi.filterAbnormal', { count: taskCounts.abnormal }) }}
</button>
<button
type="button"
class="rounded px-3 py-1 transition-colors"
:class="activeFilter === 'waitingHuman' ? 'bg-white text-primary shadow-sm' : 'text-muted hover:text-secondary'"
@click="activeFilter = 'waitingHuman'"
>
{{ t('chat.shippingNoticeUi.filterWaitingHuman', { count: taskCounts.waitingHuman }) }}
</button>
<button
type="button"
class="rounded px-3 py-1 transition-colors"
:class="activeFilter === 'resumable' ? 'bg-white text-primary shadow-sm' : 'text-muted hover:text-secondary'"
@click="activeFilter = 'resumable'"
>
{{ t('chat.shippingNoticeUi.filterResumable', { count: taskCounts.resumable }) }}
</button>
<button
type="button"
class="rounded px-3 py-1 transition-colors"
@@ -313,11 +384,11 @@ const handleSwitchBatch = (batchNo: string) => {
{{ t('chat.shippingNoticeUi.emptyFilteredTasks') }}
</div>
<div v-else class="space-y-4">
<div v-else class="space-y-3">
<article
v-for="task in filteredTasks"
:key="task.task_no"
class="relative overflow-hidden rounded-2xl border bg-white p-4 shadow-sm transition-colors"
class="relative overflow-hidden rounded-lg border bg-white p-3 shadow-sm transition-colors"
:class="[
isFailedTask(task) ? 'border-rose-100' : isAbnormalTask(task) ? 'border-amber-100' : 'border-default',
isCurrentTask(task.task_no) ? 'ring-1 ring-brand-200' : '',
@@ -327,19 +398,20 @@ const handleSwitchBatch = (batchNo: string) => {
class="absolute left-0 top-0 h-full w-1"
:class="isFailedTask(task) ? 'bg-rose-500' : isAbnormalTask(task) ? 'bg-amber-500' : 'bg-emerald-500'"
></div>
<div class="mb-4 flex items-start justify-between gap-3">
<div class="flex items-start justify-between gap-3">
<div class="min-w-0">
<div class="truncate font-mono text-sm font-bold text-primary">{{ task.task_no }}</div>
<div class="mt-0.5 truncate text-xs text-muted">
{{ task.source_file_name || task.customer_name || t('chat.shippingNoticeUi.currentNotice') }}
</div>
<div class="mt-1 text-xs font-medium text-secondary">{{ taskStepHeadline(task) }}</div>
</div>
<span class="rounded border px-2 py-1 text-[10px] font-bold" :class="resolveTaskStateMeta(task).className">
{{ resolveTaskStateMeta(task).text }}
</span>
</div>
<div class="mb-5 mt-4">
<div class="my-3">
<div class="scheme-stepper">
<template v-for="(step, index) in buildShippingWorkflowSteps(task)" :key="step.id">
<div
@@ -363,14 +435,18 @@ const handleSwitchBatch = (batchNo: string) => {
</div>
<div
class="mb-3 rounded-lg border p-2.5 text-xs font-medium leading-5"
class="mb-2 rounded-lg border p-2.5 text-xs font-medium leading-5"
:class="isFailedTask(task) ? 'border-rose-100 bg-rose-50 text-rose-700' : isAbnormalTask(task) ? 'border-amber-100 bg-amber-50 text-amber-700' : 'border-emerald-100 bg-emerald-50 text-emerald-700'"
>
<div class="font-semibold">{{ resolveTaskDiagnosis(task).title }}</div>
<div class="mt-1 font-normal text-slate-600">{{ resolveTaskDiagnosis(task).advice }}</div>
</div>
<div class="mb-3 text-xs leading-5 text-muted">
<span class="font-semibold text-secondary">{{ t('chat.shippingNoticeUi.suggestedAction') }}</span>
{{ resolveSuggestedAction(task) }}
</div>
<div class="flex gap-2">
<div class="flex flex-wrap gap-2">
<button
v-if="hasShortageLines(task)"
type="button"
@@ -381,18 +457,24 @@ const handleSwitchBatch = (batchNo: string) => {
</button>
<button
type="button"
class="flex flex-1 items-center justify-center gap-1.5 rounded-lg border border-transparent bg-surface-soft py-1.5 text-xs font-medium text-secondary transition-colors hover:border-brand-200 hover:bg-brand-50 hover:text-brand-600"
class="flex flex-1 items-center justify-center gap-1.5 rounded-lg border border-transparent bg-surface-soft px-2 py-1.5 text-xs font-medium text-secondary transition-colors hover:border-brand-200 hover:bg-brand-50 hover:text-brand-600"
@click="emit('focus-task', task.task_no)"
>
<Target class="h-3.5 w-3.5" />
{{ t('chat.shippingNoticeUi.focusRepair') }}
{{ t('chat.shippingNoticeUi.switchCurrentTask') }}
</button>
<button
type="button"
class="flex-1 rounded-lg border border-default bg-white py-1.5 text-xs font-medium text-secondary transition-colors hover:border-brand-300 hover:text-brand-700"
@click="emit('resume-task', task.task_no)"
class="flex-1 rounded-lg border border-default bg-white px-2 py-1.5 text-xs font-medium text-secondary transition-colors hover:border-brand-300 hover:text-brand-700"
@click="canRetryInventoryRpa(task) ? emit('retry-rpa', task.task_no) : emit('resume-task', task.task_no)"
>
{{ isCompletedTask(task) ? t('chat.shippingNoticeUi.viewDetail') : t('chat.shippingNoticeUi.retrySingleTask') }}
{{
isCompletedTask(task)
? t('chat.shippingNoticeUi.viewDetail')
: canRetryInventoryRpa(task)
? t('chat.shippingNoticeUi.retryRpa')
: t('chat.shippingNoticeUi.continueTask')
}}
</button>
</div>
</article>