feat(shipping-notice): 增强订单抽取与审计功能,支持取消与保留策略

- 在环境配置中新增进度细化、订单提取取消与审计导出相关的开关
- 实现订单抽取运行的取消功能,允许管理员在运行中进行操作
- 引入审计事件的保留策略,支持三年保留期的自动清理
- 更新相关模型与服务,确保新功能的完整性与可追溯性
- 增强文档与代码注释,反映新的业务逻辑与审计要求
This commit is contained in:
hugo committed 2026-07-30 14:52:21 +08:00
1 parent c85997884b
commit 95cdfe66b0
158 files changed
+19005 -1201

No files matched your search

@@ -1,30 +1,55 @@
/**
* features/chat/components/shipping/ShippingOrderExtractionCard.vue
* 用途:聊天主区一句过程通知——不重复右侧统计,无逐 PDF 列表、无复核按钮。
* 依赖:订单抽取 Run 状态卡 DTO、vue-i18n。
* 逻辑:右侧 ShippingSessionSummaryPanel 为唯一状态与跳转面;纯 open_existing 时用重复关联文案。
* 用途:聊天主区批次进度卡——摘要计数、Run 级处理事项、当前文件阶段、健康提醒与动作。
* 依赖:订单抽取 Run 状态卡 DTO、orderExtractionProgressDisplay、vue-router、vue-i18n。
* 逻辑:事实一律来自后端 handling_items / primary_notice;右侧 ShippingSessionSummaryPanel 承接逐 PDF 明细。
*/
<script setup lang="ts">
import { computed } from 'vue';
import { computed, ref } from 'vue';
import { useI18n } from 'vue-i18n';
import { useRoute, useRouter } from 'vue-router';
import { CircleCheck, CircleX, LoaderCircle, TriangleAlert } from 'lucide-vue-next';
import type { ShippingOrderExtractionState } from '../../types/chat.types';
import type {
ShippingOrderExtractionHandlingItemState,
ShippingOrderExtractionState,
} from '../../types/chat.types';
import {
formatOrderExtractionElapsed,
resolveOrderExtractionUserStageKey,
} from '../../shipping/orderExtractionProgressDisplay';
import {
listDisplayableHandlingAffectedRefs,
type ShippingHandlingAffectedRef,
type ShippingHandlingRefTarget,
} from '../../shipping/orderExtractionHandlingRefs';
const props = defineProps<{
state: ShippingOrderExtractionState;
runNo?: string;
retrying?: boolean;
refreshing?: boolean;
cancelling?: boolean;
}>();
const emit = defineEmits<{
retry: [];
refresh: [];
cancel: [reason?: string];
}>();
const { t, te } = useI18n();
const route = useRoute();
const router = useRouter();
const confirmCancelOpen = ref(false);
const cancelReason = ref('');
const handlingItems = computed(() => props.state.handlingItems || []);
/**
* 是否为「仅重复关联已有任务、无需人工复核」终态通知。
*/
const isDuplicateOnlyNotice = computed(() => {
if (handlingItems.value.length > 0) return false;
const opened = Math.max(0, Number(props.state.summary.openedExistingCount || 0));
if (opened <= 0) return false;
const review = Math.max(0, Number(props.state.summary.reviewRequiredDocuments || 0));
@@ -32,10 +57,25 @@ const isDuplicateOnlyNotice = computed(() => {
return review === 0 && failed === 0;
});
/**
* 是否为纯候选确认场景;优先信任后端 primary_notice,避免用摘要计数掩盖混合原因。
*/
const isCandidateConfirmationNotice = computed(() => (
props.state.primaryNotice === 'candidate_confirmation'
|| (
!props.state.primaryNotice
&& handlingItems.value.length === 1
&& handlingItems.value[0]?.category === 'candidate_confirmation'
)
));
const toneClass = computed(() => {
if (isDuplicateOnlyNotice.value) {
return 'border-violet-200 bg-violet-50/80 text-violet-950 dark:border-violet-800 dark:bg-violet-950/35 dark:text-violet-100';
}
if (isCandidateConfirmationNotice.value) {
return 'border-teal-200 bg-teal-50/80 text-teal-950 dark:border-teal-800 dark:bg-teal-950/35 dark:text-teal-100';
}
switch (props.state.status) {
case 'completed':
return 'border-emerald-200 bg-emerald-50/80 text-emerald-950 dark:border-emerald-800 dark:bg-emerald-950/35 dark:text-emerald-100';
@@ -50,13 +90,42 @@ const toneClass = computed(() => {
}
});
const stageLabel = computed(() => {
const key = resolveOrderExtractionUserStageKey(
props.state.currentActivity?.userVisibleStage || props.state.userVisibleStage,
props.state.currentActivity?.eventCode || props.state.status,
);
return te(key) ? t(key) : '';
});
const elapsedLabel = computed(() =>
formatOrderExtractionElapsed(props.state.currentActivity?.elapsedSeconds),
);
/**
* 一句过程通知;纯重复关联不误报「需人工处理」。
* 将处理事项类别映射为一句过程通知文案。
* @param category - 后端 primary_notice / handling item category
*/
function noticeForCategory(category: string): string {
const key = `chat.shippingOrderExtractionHandling.primaryNotice.${category}`;
return te(key) ? t(key) : t('chat.shippingSessionSummary.processNoticeNeedsAction');
}
/**
* 一句过程通知;有 handling_items 时以后端类别为准,不再笼统写「需人工处理」。
*/
const compactLine = computed(() => {
if (props.state.cancellation?.requested && !props.state.cancellation?.completedAt && !props.state.terminal) {
return t('chat.shippingOrderExtractionUserStage.cancellation_requested');
}
if (isDuplicateOnlyNotice.value) {
return t('chat.shippingSessionSummary.processNoticeDuplicateLinked');
}
const notice = String(props.state.primaryNotice || '').trim();
if (notice) return noticeForCategory(notice);
if (handlingItems.value[0]?.category) {
return noticeForCategory(handlingItems.value[0].category);
}
switch (props.state.status) {
case 'completed':
return t('chat.shippingSessionSummary.processNoticeCompleted');
@@ -66,8 +135,23 @@ const compactLine = computed(() => {
case 'failed':
case 'cancelled':
return t('chat.shippingSessionSummary.processNoticeFailed');
default:
default: {
if (props.state.status === 'queued' || props.state.status === 'processing') {
const parts: string[] = [];
const fileName = String(props.state.currentActivity?.fileName || '').trim();
if (fileName) {
parts.push(t('chat.shippingOrderExtractionCurrentFile', {
fileName: fileName || t('chat.shippingOrderExtractionUnknownDocument'),
}));
}
const stage = stageLabel.value;
if (stage) parts.push(stage);
const elapsed = elapsedLabel.value;
if (elapsed) parts.push(t('chat.shippingOrderExtractionElapsed', { elapsed }));
if (parts.length) return parts.join(' · ');
}
return t('chat.shippingSessionSummary.processNoticeProcessing');
}
}
});
@@ -81,6 +165,133 @@ const showRetry = computed(() => (
props.state.availableActions.includes('retry_failed_attachments')
|| props.state.summary.failedDocuments > 0
));
const showRefresh = computed(() => props.state.availableActions.includes('refresh_status'));
const showCancel = computed(() => (
props.state.availableActions.includes('cancel_run')
&& !(props.state.cancellation?.requested && !props.state.cancellation?.completedAt)
));
const healthTips = computed(() => props.state.healthTips || []);
/**
* 解析处理事项标题。
* @param item - 后端 handling item
*/
function handlingTitle(item: ShippingOrderExtractionHandlingItemState): string {
const key = `chat.shippingOrderExtractionHandling.category.${item.category}`;
return te(key) ? t(key) : item.category;
}
/**
* 解析原因码文案;未知码回退为原文。
* @param code - 原因码
*/
function reasonLabel(code: string): string {
const key = `chat.shippingOrderExtractionReason.${code}`;
if (te(key)) return t(key);
const freezeKey = `chat.shippingOrderExtractionHandling.reason.${code}`;
return te(freezeKey) ? t(freezeKey) : code;
}
/**
* 打开订单复核工作台(Chat order-review 模式)。
* @param options.documentId - 可选,定位到具体 PDF(由右侧 case 映射承接时仍打开 Run 复核)
* @param options.candidateNo - 可选,写入 query 供复核页筛选
*/
async function openOrderReview(options?: { documentId?: number; candidateNo?: string }) {
const runNo = String(props.runNo || '').trim();
if (!runNo) return;
const query: Record<string, string> = {
...Object.fromEntries(
Object.entries(route.query).filter(([, v]) => typeof v === 'string') as Array<[string, string]>,
),
mode: 'order-review',
run_no: runNo,
};
const candidateNo = String(options?.candidateNo || '').trim();
if (candidateNo) query.candidate = candidateNo;
const documentId = Number(options?.documentId || 0);
if (documentId > 0) query.document_id = String(documentId);
await router.push({
name: 'Chat',
params: { agentId: String(route.params.agentId || '') },
query,
});
}
/**
* 打开任务工作台,定位自动冻结受阻等任务号。
*/
async function openTaskWorkbench(taskNo: string) {
const normalized = String(taskNo || '').trim();
if (!normalized) return;
await router.push({
name: 'workspace-shipping-tasks',
params: { taskNo: normalized },
});
}
/**
* 按受影响对象引用跳转到任务或复核入口。
*/
async function openAffectedRef(target: ShippingHandlingRefTarget) {
if (target.kind === 'task') {
await openTaskWorkbench(target.taskNo);
return;
}
if (target.kind === 'review') {
await openOrderReview({
documentId: target.documentId,
candidateNo: target.candidateNo,
});
}
}
/**
* 列出事项下可展示的受影响对象。
*/
function affectedRows(item: ShippingOrderExtractionHandlingItemState) {
return listDisplayableHandlingAffectedRefs(item.affectedRefs as ShippingHandlingAffectedRef[]);
}
/**
* 按处理事项主动作跳转或触发重试;优先跳到首个受影响对象。
* @param item - 处理事项
*/
async function handleHandlingAction(item: ShippingOrderExtractionHandlingItemState) {
const action = String(item.primaryAction || '').trim();
if (action === 'retry_failed_attachments') {
emit('retry');
return;
}
const first = affectedRows(item)[0];
if (first && first.target.kind !== 'none') {
await openAffectedRef(first.target);
return;
}
if (
action === 'enter_manual_review'
|| action === 'review_candidate'
|| action === 'view_details'
) {
await openOrderReview();
}
}
/**
* 确认后发出取消事件;取消是请求语义,由后端检查点生效。
*/
function confirmCancel() {
confirmCancelOpen.value = false;
const reason = String(cancelReason.value || '').trim();
cancelReason.value = '';
emit('cancel', reason || undefined);
}
/** 打开取消确认并清空上次填写的原因。 */
function openCancelConfirm() {
cancelReason.value = '';
confirmCancelOpen.value = true;
}
</script>
<template>
@@ -95,7 +306,7 @@ const showRetry = computed(() => (
class="mt-0.5 h-4 w-4 shrink-0 animate-spin"
/>
<CircleCheck
v-else-if="state.status === 'completed' || isDuplicateOnlyNotice"
v-else-if="state.status === 'completed' || isDuplicateOnlyNotice || isCandidateConfirmationNotice"
class="mt-0.5 h-4 w-4 shrink-0"
/>
<TriangleAlert
@@ -106,23 +317,175 @@ const showRetry = computed(() => (
<div class="min-w-0 flex-1">
<div class="text-sm font-medium">{{ compactLine }}</div>
<div
v-if="state.summary.totalDocuments > 0"
class="mt-1.5 flex flex-wrap gap-1.5 text-[11px] opacity-90"
data-testid="shipping-order-extraction-summary"
>
<span>{{ t('chat.shippingOrderExtractionSummary.total', { count: state.summary.totalDocuments }) }}</span>
<span v-if="state.summary.processingDocuments > 0">
{{ t('chat.shippingOrderExtractionSummary.processing', { count: state.summary.processingDocuments }) }}
</span>
<span v-if="state.summary.pendingDocuments > 0">
{{ t('chat.shippingOrderExtractionSummary.pending', { count: state.summary.pendingDocuments }) }}
</span>
<span v-if="state.summary.completedDocuments > 0">
{{ t('chat.shippingOrderExtractionSummary.completed', { count: state.summary.completedDocuments }) }}
</span>
<span v-if="state.summary.reviewRequiredDocuments > 0">
{{ t('chat.shippingOrderExtractionSummary.reviewRequired', { count: state.summary.reviewRequiredDocuments }) }}
</span>
<span v-if="state.summary.failedDocuments > 0">
{{ t('chat.shippingOrderExtractionSummary.failed', { count: state.summary.failedDocuments }) }}
</span>
<span v-if="(state.summary.cancelledDocuments || 0) > 0">
{{ t('chat.shippingOrderExtractionSummary.cancelled', { count: state.summary.cancelledDocuments }) }}
</span>
</div>
<div
v-if="handlingItems.length"
class="mt-2 space-y-1.5"
data-testid="shipping-order-extraction-handling-items"
>
<div class="text-[11px] font-medium opacity-90">
{{ t('chat.shippingOrderExtractionHandling.title') }}
</div>
<div
v-for="item in handlingItems"
:key="item.category"
class="rounded-md border border-current/15 bg-black/5 px-2 py-1.5 text-xs dark:bg-white/5"
data-testid="shipping-order-extraction-handling-item"
>
<div class="flex flex-wrap items-center justify-between gap-2">
<div class="min-w-0 font-medium">
{{ handlingTitle(item) }}
<span class="ml-1 opacity-80">{{ t('chat.shippingOrderExtractionHandling.count', { count: item.count }) }}</span>
</div>
<button
v-if="item.primaryAction"
type="button"
class="shrink-0 rounded-md border border-current/20 px-2 py-0.5 text-[11px] font-medium hover:bg-black/5 dark:hover:bg-white/5"
@click="handleHandlingAction(item)"
>
{{ te(`chat.shippingOrderExtractionAction.${item.primaryAction}`)
? t(`chat.shippingOrderExtractionAction.${item.primaryAction}`)
: t('chat.shippingOrderExtractionAction.view_details') }}
</button>
</div>
<div v-if="item.reasonCodes.length" class="mt-1 opacity-80">
{{ t('chat.shippingOrderExtractionHandling.reasonPrefix') }}
{{ item.reasonCodes.slice(0, 4).map(reasonLabel).join(';') }}
</div>
<div
v-if="affectedRows(item).length"
class="mt-1.5 flex flex-wrap gap-1"
data-testid="shipping-order-extraction-affected-refs"
>
<span class="opacity-80">{{ t('chat.shippingOrderExtractionHandling.affectedPrefix') }}</span>
<button
v-for="row in affectedRows(item)"
:key="row.key"
type="button"
class="rounded border border-current/20 px-1.5 py-0.5 text-[11px] font-medium underline-offset-2 hover:underline"
@click="openAffectedRef(row.target)"
>
{{ row.label }}
</button>
</div>
</div>
</div>
<div v-if="state.currentActivity?.fileName" class="mt-1 text-xs opacity-80">
{{ t('chat.shippingOrderExtractionCurrentFile', {
fileName: state.currentActivity.fileName || t('chat.shippingOrderExtractionUnknownDocument'),
}) }}
<span v-if="activityKey"> · {{ t(activityKey) }}</span>
<span v-if="stageLabel"> · {{ stageLabel }}</span>
<span v-else-if="activityKey"> · {{ t(activityKey) }}</span>
<span v-if="elapsedLabel"> · {{ t('chat.shippingOrderExtractionElapsed', { elapsed: elapsedLabel }) }}</span>
</div>
<div
v-for="tip in healthTips"
:key="tip.code"
class="mt-1 text-xs font-medium opacity-90"
data-testid="shipping-order-extraction-health-tip"
>
{{ t(`chat.shippingOrderExtractionHealthTip.${tip.code}`) }}
</div>
<div v-if="state.refreshFailed" class="mt-1 text-xs font-medium opacity-90">
{{ t('chat.shippingOrderExtractionRefreshFailed') }}
</div>
<button
v-if="showRetry"
type="button"
class="mt-2 inline-flex items-center rounded-md border border-current/20 px-2.5 py-1 text-xs font-medium hover:bg-black/5 dark:hover:bg-white/5"
@click="emit('retry')"
>
{{ t('chat.shippingOrderExtractionAction.retry_failed_attachments') }}
</button>
<div v-if="confirmCancelOpen" class="mt-2 rounded-md border border-current/20 bg-black/5 p-2 text-xs dark:bg-white/5">
<div class="font-medium">{{ t('chat.shippingOrderExtractionCancel.confirmTitle') }}</div>
<div class="mt-1 opacity-80">{{ t('chat.shippingOrderExtractionCancel.confirmImpact') }}</div>
<label class="mt-2 block opacity-90">
{{ t('chat.shippingOrderExtractionCancel.reasonOptional') }}
<textarea
v-model="cancelReason"
rows="2"
class="input-field mt-1 w-full py-1 text-xs"
:placeholder="t('chat.shippingOrderExtractionCancel.reasonOptional')"
/>
</label>
<div class="mt-2 flex flex-wrap gap-2">
<button
type="button"
class="inline-flex items-center rounded-md border border-current/20 px-2.5 py-1 text-xs font-medium hover:bg-black/5 dark:hover:bg-white/5"
:disabled="cancelling"
@click="confirmCancel"
>
{{ cancelling
? t('chat.shippingOrderExtractionCancel.submitting')
: t('chat.shippingOrderExtractionAction.cancel_run') }}
</button>
<button
type="button"
class="inline-flex items-center rounded-md px-2.5 py-1 text-xs font-medium opacity-80 hover:underline"
:disabled="cancelling"
@click="confirmCancelOpen = false; cancelReason = ''"
>
{{ t('chat.shippingOrderExtractionCancel.dismiss') }}
</button>
</div>
</div>
<div v-else class="mt-2 flex flex-wrap gap-2">
<button
v-if="showRefresh"
type="button"
class="inline-flex items-center rounded-md border border-current/20 px-2.5 py-1 text-xs font-medium hover:bg-black/5 dark:hover:bg-white/5"
:disabled="refreshing"
@click="emit('refresh')"
>
{{ refreshing
? t('chat.shippingOrderExtractionRefreshing')
: t('chat.shippingOrderExtractionAction.refresh_status') }}
</button>
<button
v-if="showCancel"
type="button"
class="inline-flex items-center rounded-md border border-current/20 px-2.5 py-1 text-xs font-medium hover:bg-black/5 dark:hover:bg-white/5"
:disabled="cancelling"
@click="openCancelConfirm"
>
{{ t('chat.shippingOrderExtractionAction.cancel_run') }}
</button>
<button
v-if="showRetry"
type="button"
class="inline-flex items-center rounded-md border border-current/20 px-2.5 py-1 text-xs font-medium hover:bg-black/5 dark:hover:bg-white/5"
:disabled="retrying"
@click="emit('retry')"
>
{{ retrying
? t('chat.shippingOrderExtractionRetrying')
: t('chat.shippingOrderExtractionAction.retry_failed_attachments') }}
</button>
</div>
</div>
</div>
</div>