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

@@ -2,64 +2,41 @@
/**
* features/workspace/views/ShippingNoticeView.vue
* 用途:货代发货任务只读工作台,提供任务筛选、详情查看与跳转 Chat 继续处理入口。
* 依赖:ShippingWorkflowStepper、ShippingParseReviewMessage、ShippingMatchResultCard、shipping.api。
* 逻辑:先拉取任务列表与详情,再复用 Chat 区的发货组件展示步骤、匹配结果和 parse review。
* 依赖:ShippingWorkflowStepper、ShippingMatchResultCard、shipping.api。
* 逻辑:先拉取任务列表与详情,再以只读方式展示步骤、匹配结果和事件记录;所有写操作回到 Chat 主路径完成。
*/
import { computed, onMounted, ref, watch } from 'vue';
import { useRouter } from 'vue-router';
import { useI18n } from 'vue-i18n';
import { ArrowLeft, Download, ExternalLink, RefreshCw } from 'lucide-vue-next';
import ShippingWorkflowStepper from '@/features/chat/components/ShippingWorkflowStepper.vue';
import ShippingParseReviewMessage, {
type ShippingParseReviewHandlers,
} from '@/features/chat/components/messages/ShippingParseReviewMessage.vue';
import ShippingMatchResultCard from '@/features/chat/components/messages/ShippingMatchResultCard.vue';
import { formatLocalDateTime } from '@/shared/utils/dateTime';
import {
addWorkspaceShippingNoticeLine,
autoProgressWorkspaceShippingTask,
generateWorkspaceShippingExcel,
getShippingChatActions,
getWorkspaceShippingTask,
listShippingChatAgents,
listWorkspaceShippingTasks,
markWorkspaceShippingManualUploaded,
matchWorkspaceShippingInventory,
removeWorkspaceShippingNoticeLine,
retryWorkspaceShippingTask,
SHIPPING_NOTICE_AGENT_NAME,
submitWorkspaceShippingDecision,
updateWorkspaceShippingNoticeFields,
updateWorkspaceShippingNoticeLine,
workspaceShippingExportUrl,
type ShippingChatAction,
type ShippingCurrentStepProgress,
type ShippingNoticeHeader,
type ShippingNoticeLine,
type ShippingTaskDetail,
type ShippingTaskSummary,
} from '@/features/chat/api/shipping.api';
import type { ChatMessage } from '@/features/chat/types/chat.types';
import type { ShippingParseReviewPayload } from '@/features/chat/types/shipping.types';
import { getAuthHeaders } from '@/shared/utils/auth';
import { useMessage } from '@/shared/composables/useMessage';
import { buildShippingWorkflowSteps, shippingActionButtonClass } from '@/features/chat/shipping';
import { buildShippingWorkflowSteps } from '@/features/chat/shipping';
const props = defineProps<{
embedded?: boolean;
}>();
const router = useRouter();
const { t } = useI18n();
const msg = useMessage();
const { t, te } = useI18n();
const loading = ref(false);
const detailLoading = ref(false);
const tasks = ref<ShippingTaskSummary[]>([]);
const selectedTaskNo = ref<string | null>(null);
const detail = ref<ShippingTaskDetail | null>(null);
const detailSaving = ref(false);
const detailActionBusy = ref(false);
const detailRetrying = ref(false);
const detailActionButtons = ref<ShippingChatAction[]>([]);
const statusFilter = ref('all');
const chatAgentId = ref<number | null>(null);
const batchProgressLabel = computed(() => {
@@ -81,17 +58,54 @@ const statusOptions = computed(() => [
{ value: 'upload_failed', label: t('workspace.shippingNotice.status.uploadFailed') },
]);
const statusBadge = (status: string) => {
type ShippingStatusSource = Pick<
ShippingTaskSummary,
'process_status' | 'review_status' | 'pending_human_reason' | 'match_status'
>;
const displayStatusCode = (source: ShippingStatusSource | string) => {
if (typeof source === 'string') return source;
const reason = String(source.pending_human_reason || '').trim();
const reviewStatus = String(source.review_status || '').trim();
if (reason === 'shortage' || reason === 'shortage_review' || reviewStatus === 'shortage_review') return 'shortage_review';
if (reason === 'align_review' || reviewStatus === 'align_review') return 'align_review';
return String(source.process_status || '').trim();
};
const statusBadge = (source: ShippingStatusSource | string) => {
const status = displayStatusCode(source);
const map: Record<string, { cls: string; label: string }> = {
created: { cls: 'bg-slate-100 text-secondary', label: t('workspace.shippingNotice.status.created') },
parsed: { cls: 'bg-blue-100 text-blue-700', label: t('workspace.shippingNotice.status.parsed') },
pending_review: { cls: 'bg-amber-100 text-amber-700', label: t('workspace.shippingNotice.status.pendingReview') },
align_review: { cls: 'bg-amber-100 text-amber-700', label: t('workspace.shippingNotice.status.alignReview') },
shortage_review: { cls: 'bg-rose-100 text-rose-700', label: t('workspace.shippingNotice.status.shortageReview') },
waiting_inventory: { cls: 'bg-amber-100 text-amber-700', label: t('workspace.shippingNotice.status.waitingInventory') },
inventory_ready: { cls: 'bg-blue-100 text-blue-700', label: t('workspace.shippingNotice.status.inventoryReady') },
matched: { cls: 'bg-emerald-100 text-emerald-700', label: t('workspace.shippingNotice.status.matched') },
waiting_upload: { cls: 'bg-amber-100 text-amber-700', label: t('workspace.shippingNotice.status.waitingUpload') },
uploaded: { cls: 'bg-emerald-100 text-emerald-700', label: t('workspace.shippingNotice.status.uploaded') },
upload_failed: { cls: 'bg-rose-100 text-rose-700', label: t('workspace.shippingNotice.status.uploadFailed') },
rejected: { cls: 'bg-slate-100 text-secondary', label: t('workspace.shippingNotice.status.rejected') },
closed: { cls: 'bg-slate-100 text-secondary', label: t('workspace.shippingNotice.status.closed') },
};
return map[status] || { cls: 'bg-slate-100 text-secondary', label: status };
return map[status] || { cls: 'bg-slate-100 text-secondary', label: t('workspace.shippingNotice.status.unknown') };
};
const matchStatusLabel = (status?: string | null) => {
const key = String(status || '').trim();
const map: Record<string, string> = {
fulfillable: t('workspace.shippingNotice.matchStatus.fulfillable'),
partial: t('workspace.shippingNotice.matchStatus.partial'),
unfulfillable: t('workspace.shippingNotice.matchStatus.unfulfillable'),
};
return map[key] || (key ? t('workspace.shippingNotice.matchStatus.unknown') : '—');
};
const eventLabel = (eventType: string) => {
const normalized = String(eventType || '').trim().replace(/[^a-zA-Z0-9_]/g, '');
const key = `workspace.shippingNotice.eventTypes.${normalized}`;
return te(key) ? t(key) : t('workspace.shippingNotice.eventTypes.system');
};
const detailWorkflowSteps = computed(() => buildShippingWorkflowSteps(detail.value));
@@ -122,15 +136,9 @@ const loadCases = async () => {
const loadDetail = async (taskNo: string) => {
detailLoading.value = true;
try {
const [taskDetail, chatActions] = await Promise.all([
getWorkspaceShippingTask(taskNo),
getShippingChatActions(taskNo).catch(() => null),
]);
detail.value = taskDetail;
detailActionButtons.value = chatActions?.action_buttons || [];
detail.value = await getWorkspaceShippingTask(taskNo);
} catch {
detail.value = null;
detailActionButtons.value = [];
} finally {
detailLoading.value = false;
}
@@ -138,9 +146,7 @@ const loadDetail = async (taskNo: string) => {
const resolveChatAgent = async () => {
try {
const res = await fetch('/api/agents', { headers: getAuthHeaders() });
if (!res.ok) return;
const agents = (await res.json()) as Array<{ id: number; name: string }>;
const agents = await listShippingChatAgents();
const found = agents.find((a) => a.name === SHIPPING_NOTICE_AGENT_NAME);
if (found) chatAgentId.value = found.id;
} catch {
@@ -170,86 +176,6 @@ const downloadExport = async (taskNo: string) => {
URL.revokeObjectURL(a.href);
};
const parseReviewPayload = computed<ShippingParseReviewPayload | null>(() => {
if (!detail.value || detail.value.review_status !== 'pending_confirm') return null;
return {
taskId: detail.value.task_no,
checkpoint: 'parse_review',
header: {
customer_name: detail.value.customer_name ?? null,
customer_code: detail.value.customer_code ?? null,
ship_to: detail.value.ship_to ?? null,
po_number: detail.value.po_number ?? null,
required_date: detail.value.required_date ?? null,
},
lines: Array.isArray(detail.value.lines) ? detail.value.lines : [],
saving: detailSaving.value,
};
});
const parseReviewMessage = computed<ChatMessage>(() => ({
role: 'assistant',
type: 'shipping-parse-review',
content: `${t('chat.shippingNoticeUi.parseReviewIntro')}\n${t('chat.shippingNoticeUi.taskId', { taskId: detail.value?.task_no || '' })}`.trim(),
payload: parseReviewPayload.value || undefined,
}));
const parseReviewHandlers: ShippingParseReviewHandlers = {
getPayload: () => parseReviewPayload.value,
updateHeader: async (_msg, fields: Partial<ShippingNoticeHeader>) => {
if (!detail.value || detailSaving.value) return false;
detailSaving.value = true;
try {
await updateWorkspaceShippingNoticeFields(detail.value.task_no, fields, '工作台订单表修订');
await Promise.all([loadDetail(detail.value.task_no), loadCases()]);
return true;
} catch {
return false;
} finally {
detailSaving.value = false;
}
},
updateLine: async (_msg, lineIndex: number, patch: Partial<ShippingNoticeLine>) => {
if (!detail.value || detailSaving.value) return false;
detailSaving.value = true;
try {
await updateWorkspaceShippingNoticeLine(detail.value.task_no, lineIndex, patch, '工作台订单表修订');
await Promise.all([loadDetail(detail.value.task_no), loadCases()]);
return true;
} catch {
return false;
} finally {
detailSaving.value = false;
}
},
addLine: async (_msg, line: Partial<ShippingNoticeLine>) => {
if (!detail.value || detailSaving.value) return false;
detailSaving.value = true;
try {
await addWorkspaceShippingNoticeLine(detail.value.task_no, line, '工作台订单表新增行');
await Promise.all([loadDetail(detail.value.task_no), loadCases()]);
return true;
} catch {
return false;
} finally {
detailSaving.value = false;
}
},
removeLine: async (_msg, lineIndex: number) => {
if (!detail.value || detailSaving.value) return false;
detailSaving.value = true;
try {
await removeWorkspaceShippingNoticeLine(detail.value.task_no, lineIndex, '工作台订单表删除行');
await Promise.all([loadDetail(detail.value.task_no), loadCases()]);
return true;
} catch {
return false;
} finally {
detailSaving.value = false;
}
},
};
const shortageLines = computed(() => detail.value?.shortage?.lines || []);
const hasMatchCard = computed(() =>
!!detail.value && (
@@ -258,59 +184,6 @@ const hasMatchCard = computed(() =>
),
);
const handleWorkspaceAction = async (action: ShippingChatAction) => {
if (!detail.value || detailActionBusy.value) return;
const taskNo = detail.value.task_no;
detailActionBusy.value = true;
try {
if (action.id === 'download_excel') {
await downloadExport(taskNo);
return;
}
if (action.id === 'generate_excel') {
await generateWorkspaceShippingExcel(taskNo);
} else if (action.id === 'match_inventory') {
await matchWorkspaceShippingInventory(taskNo);
} else if (action.id === 'mark_manual_uploaded') {
await markWorkspaceShippingManualUploaded(taskNo);
} else if (action.id === 'refresh') {
await loadDetail(taskNo);
return;
} else if (action.id === 'confirm_inventory_mapping') {
await autoProgressWorkspaceShippingTask(taskNo);
} else if ([
'confirm',
'reject',
'reparse',
'correct_inventory_mapping',
'reparse_inventory',
'rematch',
].includes(action.id)) {
await submitWorkspaceShippingDecision(taskNo, action.id);
} else {
openInChat(taskNo, detail.value.conversation_id, detail.value.batch_no);
return;
}
await Promise.all([loadDetail(taskNo), loadCases()]);
} finally {
detailActionBusy.value = false;
}
};
const handleRetryCurrentTask = async () => {
if (!detail.value || detailRetrying.value) return;
detailRetrying.value = true;
try {
const result = await retryWorkspaceShippingTask(detail.value.task_no, '工作台重试当前票');
msg.success(result.message || t('workspace.shippingNotice.retryCurrentDone'));
await Promise.all([loadDetail(detail.value.task_no), loadCases()]);
} catch (error) {
msg.error(error instanceof Error ? error.message : t('workspace.shippingNotice.retryFailed'));
} finally {
detailRetrying.value = false;
}
};
watch(selectedTaskNo, (val) => {
if (val) loadDetail(val);
else detail.value = null;
@@ -382,13 +255,17 @@ onMounted(async () => {
>
<div class="flex items-center justify-between gap-2">
<span class="font-mono text-sm font-semibold text-primary">{{ item.task_no }}</span>
<span class="rounded-full px-2 py-0.5 text-xs font-medium" :class="statusBadge(item.process_status).cls">
{{ statusBadge(item.process_status).label }}
<span
class="rounded-full px-2 py-0.5 text-xs font-medium"
:class="statusBadge(item).cls"
:title="item.process_status"
>
{{ statusBadge(item).label }}
</span>
</div>
<div class="mt-1 truncate text-sm text-secondary">{{ item.customer_name || '—' }}</div>
<div class="mt-1 flex flex-wrap items-center gap-2 text-xs text-muted">
<span>{{ item.created_at || '' }}</span>
<span>{{ formatLocalDateTime(item.created_at) }}</span>
<span v-if="item.batch_index && item.batch_total" class="rounded-full bg-sky-50 px-2 py-0.5 font-medium text-sky-700">
{{ t('chat.shippingNoticeUi.batchProgress', { index: item.batch_index, total: item.batch_total }) }}
</span>
@@ -418,15 +295,6 @@ onMounted(async () => {
</div>
</div>
<div class="flex flex-wrap gap-2">
<button
type="button"
class="inline-flex items-center gap-1 rounded-xl border border-default px-3 py-1.5 text-sm font-medium text-secondary hover:bg-surface-soft disabled:cursor-not-allowed disabled:opacity-60"
:disabled="detailRetrying"
@click="handleRetryCurrentTask"
>
<RefreshCw class="h-3.5 w-3.5" />
{{ detailRetrying ? $t('workspace.shippingNotice.retrying') : $t('workspace.shippingNotice.retryCurrentTask') }}
</button>
<button
v-if="chatAgentId"
type="button"
@@ -486,8 +354,14 @@ onMounted(async () => {
</div>
<dl class="grid gap-3 sm:grid-cols-2 text-sm">
<div><dt class="text-muted">{{ $t('workspace.shippingNotice.fields.status') }}</dt><dd>{{ detail.process_status }}</dd></div>
<div><dt class="text-muted">{{ $t('workspace.shippingNotice.fields.match') }}</dt><dd>{{ detail.match_status || '—' }}</dd></div>
<div>
<dt class="text-muted">{{ $t('workspace.shippingNotice.fields.status') }}</dt>
<dd :title="detail.process_status">{{ statusBadge(detail).label }}</dd>
</div>
<div>
<dt class="text-muted">{{ $t('workspace.shippingNotice.fields.match') }}</dt>
<dd :title="detail.match_status || ''">{{ matchStatusLabel(detail.match_status) }}</dd>
</div>
<div><dt class="text-muted">{{ $t('workspace.shippingNotice.fields.shipTo') }}</dt><dd>{{ detail.ship_to || '—' }}</dd></div>
<div><dt class="text-muted">{{ $t('workspace.shippingNotice.fields.freightRef') }}</dt><dd>{{ detail.freight_ref_no || '—' }}</dd></div>
</dl>
@@ -502,20 +376,11 @@ onMounted(async () => {
:match-status="detail.match_status"
:line-results="detail.line_results"
:shortage-lines="shortageLines"
:action-buttons="detailActionButtons"
:action-busy="detailActionBusy"
:action-button-class="shippingActionButtonClass"
:on-action-click="handleWorkspaceAction"
:action-buttons="[]"
:action-busy="false"
/>
<div v-if="parseReviewPayload">
<ShippingParseReviewMessage
:message="parseReviewMessage"
:handlers="parseReviewHandlers"
/>
</div>
<div v-else-if="detail.lines?.length">
<div v-if="detail.lines?.length">
<h3 class="mb-2 text-sm font-semibold text-secondary">{{ $t('workspace.shippingNotice.lines') }}</h3>
<div class="overflow-x-auto rounded-xl border border-default">
<table class="min-w-full text-sm">
@@ -539,8 +404,8 @@ onMounted(async () => {
<h3 class="mb-2 text-sm font-semibold text-secondary">{{ $t('workspace.shippingNotice.events') }}</h3>
<ul class="max-h-48 space-y-1 overflow-y-auto text-xs text-muted">
<li v-for="(ev, idx) in [...detail.events].reverse()" :key="idx">
<span class="font-medium text-secondary">{{ ev.event_type }}</span>
<span class="ml-2">{{ ev.created_at }}</span>
<span class="font-medium text-secondary" :title="ev.event_type">{{ eventLabel(ev.event_type) }}</span>
<span class="ml-2">{{ formatLocalDateTime(ev.created_at) }}</span>
</li>
</ul>
</div>