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

@@ -0,0 +1,325 @@
/**
* features/workspace/shipping-task-center/ShippingRunProgressTable.vue
* 用途:任务中心「我的识别」续办表——展示用户自有抽取 Run 的阶段、耗时、取消态与续办动作。
* 依赖:shipping.api 分页列表/取消/重试、vue-i18n、vue-router、orderExtractionProgressDisplay。
* 逻辑:事实来自后端投影;打开会话/复核深链到 Chat;取消/重试复用工作台 API。
*/
<script setup lang="ts">
import { onMounted, ref, watch } from 'vue';
import { useI18n } from 'vue-i18n';
import { useRouter } from 'vue-router';
import {
cancelWorkspaceShippingOrderExtractionRun,
listShippingChatAgents,
listWorkspaceShippingOrderExtractionRunsPage,
retryWorkspaceShippingOrderExtractionRun,
SHIPPING_NOTICE_AGENT_CODE,
} from '@/features/chat/api/shipping.api';
import type { ShippingOrderExtractionRun } from '@/features/chat/types/shipping.api.types';
import { formatOrderExtractionElapsed } from '@/features/chat/shipping/orderExtractionProgressDisplay';
const { t, te } = useI18n();
const router = useRouter();
const loading = ref(false);
const actingRunNo = ref('');
const pendingCancelRunNo = ref('');
const cancelReason = ref('');
const status = ref('');
const page = ref(1);
const pageSize = 20;
const total = ref(0);
const rows = ref<ShippingOrderExtractionRun[]>([]);
const chatAgentId = ref<number | null>(null);
const error = ref('');
/**
* 解析货代 Chat Agent,供会话深链。
*/
async function resolveChatAgent() {
try {
const agents = await listShippingChatAgents();
const found = agents.find((a) => String(a.agent_code || '').trim() === SHIPPING_NOTICE_AGENT_CODE);
if (found) chatAgentId.value = found.id;
} catch {
/* ignore */
}
}
/**
* 分页加载当前用户识别 Run。
*/
async function load() {
loading.value = true;
error.value = '';
try {
const response = await listWorkspaceShippingOrderExtractionRunsPage({
status: status.value || undefined,
page: page.value,
page_size: pageSize,
});
rows.value = response.items || [];
total.value = Number(response.total || 0);
} catch {
error.value = t('workspace.shippingNotice.myRuns.loadFailed');
} finally {
loading.value = false;
}
}
/**
* 用户可见阶段文案;无投影时回退状态文案。
*/
function stageLabel(run: ShippingOrderExtractionRun): string {
const stage = String(run.current_activity?.user_visible_stage || '').trim();
if (stage) {
const key = `chat.shippingOrderExtractionUserStage.${stage}`;
if (te(key)) return t(key);
}
const statusKey = `chat.shippingOrderExtractionCardTitle.${run.status}`;
return te(statusKey) ? t(statusKey) : run.status;
}
/**
* 打开所属会话;活动 Run 进入聊天进度面。
*/
async function openInChat(run: ShippingOrderExtractionRun) {
const agentId = Number(run.agent_id || chatAgentId.value || 0);
if (!agentId) return;
const query: Record<string, string> = {};
const cid = String(run.conversation_id || '').trim();
if (cid) query.conversation_id = cid;
if (['review_required', 'partially_completed'].includes(run.status)) {
query.mode = 'order-review';
query.run_no = run.run_no;
}
await router.push({ path: `/chat/${agentId}`, query });
}
/** 请求取消整批;排队立即取消,执行中进入正在取消。 */
async function submitCancelRun(run: ShippingOrderExtractionRun, reason?: string | null) {
if (actingRunNo.value) return;
actingRunNo.value = run.run_no;
try {
await cancelWorkspaceShippingOrderExtractionRun(run.run_no, {
reason: String(reason || '').trim() || null,
});
pendingCancelRunNo.value = '';
cancelReason.value = '';
await load();
} catch {
error.value = t('chat.shippingOrderExtractionCancel.failed');
} finally {
actingRunNo.value = '';
}
}
/**
* 展开/收起单行取消表单。
*/
function beginCancelRun(run: ShippingOrderExtractionRun) {
if (pendingCancelRunNo.value === run.run_no) {
pendingCancelRunNo.value = '';
cancelReason.value = '';
return;
}
pendingCancelRunNo.value = run.run_no;
cancelReason.value = '';
}
/**
* 重试失败附件。
*/
async function retryRun(run: ShippingOrderExtractionRun) {
if (actingRunNo.value) return;
actingRunNo.value = run.run_no;
try {
await retryWorkspaceShippingOrderExtractionRun(run.run_no);
await load();
} catch {
error.value = t('chat.shippingOrderExtractionRetryFailed');
} finally {
actingRunNo.value = '';
}
}
watch(status, () => {
page.value = 1;
void load();
});
onMounted(async () => {
await resolveChatAgent();
await load();
});
defineExpose({ reload: load });
</script>
<template>
<section class="space-y-3" data-testid="shipping-run-progress-table">
<div class="flex flex-wrap items-center justify-between gap-3">
<div>
<h3 class="text-base font-semibold text-primary">{{ t('workspace.shippingNotice.myRuns.title') }}</h3>
<p class="text-xs text-muted">{{ t('workspace.shippingNotice.myRuns.subtitle') }}</p>
</div>
<label class="flex items-center gap-2 text-sm text-secondary">
{{ t('workspace.shippingNotice.myRuns.status') }}
<select v-model="status" class="input-field py-1.5 text-sm">
<option value="">{{ t('workspace.shippingNotice.myRuns.allStatuses') }}</option>
<option
v-for="value in ['queued', 'processing', 'completed', 'partially_completed', 'review_required', 'failed', 'cancelled']"
:key="value"
:value="value"
>
{{ t(`chat.shippingOrderExtractionCardTitle.${value}`) }}
</option>
</select>
</label>
</div>
<p v-if="error" class="rounded-lg border border-rose-200 bg-rose-50 p-3 text-sm text-rose-700">{{ error }}</p>
<div class="overflow-x-auto rounded-xl border border-default bg-surface">
<table class="min-w-[860px] w-full text-left text-sm">
<thead class="border-b border-default bg-surface-soft text-xs text-muted">
<tr>
<th class="px-3 py-2">{{ t('workspace.shippingNotice.myRuns.runNo') }}</th>
<th class="px-3 py-2">{{ t('workspace.shippingNotice.myRuns.status') }}</th>
<th class="px-3 py-2">{{ t('workspace.shippingNotice.myRuns.stage') }}</th>
<th class="px-3 py-2">{{ t('workspace.shippingNotice.myRuns.summary') }}</th>
<th class="px-3 py-2">{{ t('workspace.shippingNotice.myRuns.elapsed') }}</th>
<th class="px-3 py-2">{{ t('workspace.shippingNotice.myRuns.actions') }}</th>
</tr>
</thead>
<tbody>
<tr v-if="loading">
<td colspan="6" class="px-3 py-8 text-center text-muted">{{ t('workspace.shippingNotice.myRuns.loading') }}</td>
</tr>
<tr v-else-if="!rows.length">
<td colspan="6" class="px-3 py-8 text-center text-muted">{{ t('workspace.shippingNotice.myRuns.empty') }}</td>
</tr>
<tr
v-for="run in rows"
:key="run.run_no"
class="border-b border-default last:border-0"
>
<td class="px-3 py-2 font-mono text-xs">{{ run.run_no }}</td>
<td class="px-3 py-2">
{{ t(`chat.shippingOrderExtractionCardTitle.${run.status}`) }}
<span
v-if="run.cancellation?.requested && !run.cancellation?.completed_at"
class="ml-1 rounded-full bg-amber-100 px-1.5 py-0.5 text-[10px] text-amber-800"
>
{{ t('chat.shippingOrderExtractionUserStage.cancellation_requested') }}
</span>
</td>
<td class="px-3 py-2">
<div>{{ stageLabel(run) }}</div>
<div v-if="run.current_activity?.file_name" class="text-[11px] text-muted">
{{ run.current_activity.file_name }}
</div>
</td>
<td class="px-3 py-2 text-xs text-secondary">
{{ t('workspace.shippingNotice.myRuns.summaryCounts', {
total: run.summary?.total_documents || 0,
done: run.summary?.completed_documents || 0,
review: run.summary?.review_required_documents || 0,
failed: run.summary?.failed_documents || 0,
cancelled: run.summary?.cancelled_documents || 0,
}) }}
</td>
<td class="px-3 py-2 text-xs">
{{ formatOrderExtractionElapsed(run.current_activity?.elapsed_seconds) || '—' }}
</td>
<td class="px-3 py-2">
<div class="flex flex-wrap gap-2">
<button
type="button"
class="text-xs font-medium text-brand-700 hover:underline"
@click="openInChat(run)"
>
{{ t('workspace.shippingNotice.myRuns.openChat') }}
</button>
<template v-if="(run.available_actions || []).includes('cancel_run')">
<div
v-if="pendingCancelRunNo === run.run_no"
class="w-full min-w-[220px] space-y-1.5 rounded-md border border-rose-200 bg-rose-50/60 p-2 dark:border-rose-900/40 dark:bg-rose-950/20"
>
<label class="block text-[11px] text-secondary">
{{ t('chat.shippingOrderExtractionCancel.reasonOptional') }}
</label>
<textarea
v-model="cancelReason"
rows="2"
class="input-field w-full py-1 text-xs"
/>
<div class="flex flex-wrap gap-2">
<button
type="button"
class="text-xs font-medium text-rose-700 hover:underline"
:disabled="actingRunNo === run.run_no"
@click="submitCancelRun(run, cancelReason)"
>
{{ actingRunNo === run.run_no
? t('chat.shippingOrderExtractionCancel.submitting')
: t('chat.shippingOrderExtractionAction.cancel_run') }}
</button>
<button
type="button"
class="text-xs text-muted hover:underline"
:disabled="actingRunNo === run.run_no"
@click="pendingCancelRunNo = ''; cancelReason = ''"
>
{{ t('chat.shippingOrderExtractionCancel.dismiss') }}
</button>
</div>
</div>
<button
v-else
type="button"
class="text-xs font-medium text-rose-700 hover:underline"
:disabled="actingRunNo === run.run_no"
@click="beginCancelRun(run)"
>
{{ t('chat.shippingOrderExtractionAction.cancel_run') }}
</button>
</template>
<button
v-if="(run.available_actions || []).includes('retry_failed_attachments') || (run.summary?.failed_documents || 0) > 0"
type="button"
class="text-xs font-medium text-secondary hover:underline"
:disabled="actingRunNo === run.run_no"
@click="retryRun(run)"
>
{{ t('chat.shippingOrderExtractionAction.retry_failed_attachments') }}
</button>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<div class="flex items-center justify-end gap-3 text-sm">
<span class="text-xs text-muted">{{ t('workspace.shippingNotice.myRuns.total', { count: total }) }}</span>
<button
type="button"
class="rounded border border-default px-3 py-1.5 disabled:opacity-50"
:disabled="page <= 1 || loading"
@click="page -= 1; load()"
>
{{ t('workspace.shippingNotice.myRuns.previous') }}
</button>
<span>{{ page }}</span>
<button
type="button"
class="rounded border border-default px-3 py-1.5 disabled:opacity-50"
:disabled="page * pageSize >= total || loading"
@click="page += 1; load()"
>
{{ t('workspace.shippingNotice.myRuns.next') }}
</button>
</div>
</section>
</template>
@@ -1,8 +1,8 @@
/**
* features/workspace/shipping-task-center/ShippingTaskCenterPage.vue
* 用途:发货「我的待办」壳——Pending|Processing|Done + 右侧任务工作台或复核深链。
* 依赖:shipping-tasks.api(my-todos)、shipping.api 详情、ShippingTaskWorkbench、useShippingTodoBadge。
* 逻辑:review_case 项用 review_run_no 打开人工复核;task 项打开任务处理工作台。
* 用途:发货「我的待办」壳——Pending|Processing|Done + 识别 Run 续办表 + 右侧任务工作台或复核深链。
* 依赖:shipping-tasks.api(my-todos)、shipping.api 详情、ShippingTaskWorkbench、ShippingRunProgressTable、useShippingTodoBadge。
* 逻辑:review_case 项用 review_run_no 打开人工复核;task 项打开任务处理工作台;识别页承接取消/重试/回会话。
*/
<script setup lang="ts">
import { computed, onMounted, ref, watch } from 'vue';
@@ -22,11 +22,14 @@ import {
} from '@/features/workspace/api/shipping-tasks.api';
import { useShippingTodoBadge } from '../composables/useShippingTodoBadge';
import ShippingTaskWorkbench from './ShippingTaskWorkbench.vue';
import ShippingRunProgressTable from './ShippingRunProgressTable.vue';
const route = useRoute();
const router = useRouter();
const { refreshShippingTodoBadge } = useShippingTodoBadge();
/** todos=建单后待办;runs=建单前识别续办 */
const surface = ref<'todos' | 'runs'>('todos');
const bucket = ref<'pending' | 'processing' | 'done'>('pending');
const filterTodoCategory = ref<'all' | 'review' | 'exception' | 'manual_upload'>('all');
const filterCustomer = ref('');
@@ -58,6 +61,7 @@ const preferredTaskNo = computed(() =>
String(route.params.taskNo || route.query.task_no || '').trim().toUpperCase(),
);
const preferredReviewRun = computed(() => String(route.query.run_no || '').trim());
const isDirectTaskRoute = computed(() => Boolean(String(route.params.taskNo || '').trim()));
const selectedItem = computed(() =>
tasks.value.find((item) => todoItemKey(item) === selectedRef.value) || null,
@@ -193,6 +197,10 @@ async function loadDetail(taskNo: string) {
*/
async function refreshAll() {
await Promise.all([loadTodos(), loadCounts()]);
if (isDirectTaskRoute.value && preferredTaskNo.value) {
await loadDetail(preferredTaskNo.value);
return;
}
const item = selectedItem.value;
if (item?.task_no && item.item_kind !== 'review_case') {
await loadDetail(item.task_no);
@@ -281,6 +289,11 @@ watch(selectedItem, (item) => {
onMounted(async () => {
await Promise.all([resolveChatAgent(), loadCounts(), loadTodos()]);
if (preferredTaskNo.value) {
if (isDirectTaskRoute.value) {
selectedRef.value = preferredTaskNo.value;
await loadDetail(preferredTaskNo.value);
return;
}
const hit = tasks.value.find((item) => String(item.task_no || '').toUpperCase() === preferredTaskNo.value);
if (!hit) {
selectedRef.value = preferredTaskNo.value;
@@ -307,6 +320,52 @@ onMounted(async () => {
</button>
</div>
<div class="flex flex-wrap gap-2">
<button
type="button"
class="rounded-xl px-3 py-1.5 text-sm font-medium"
:class="surface === 'todos' ? 'bg-brand-600 text-white' : 'border border-default text-secondary hover:bg-surface-soft'"
@click="surface = 'todos'"
>
{{ $t('workspace.shippingNotice.myTodos.title') }}
</button>
<button
type="button"
class="rounded-xl px-3 py-1.5 text-sm font-medium"
:class="surface === 'runs' ? 'bg-brand-600 text-white' : 'border border-default text-secondary hover:bg-surface-soft'"
@click="surface = 'runs'"
>
{{ $t('workspace.shippingNotice.myRuns.title') }}
</button>
</div>
<div v-if="isDirectTaskRoute" class="rounded-2xl border border-default bg-surface p-4">
<div v-if="detailLoading" class="py-16 text-center text-sm text-muted">
{{ $t('workspace.shippingNotice.loading') }}
</div>
<div v-else-if="!detail" class="py-16 text-center text-sm text-muted">
{{ $t('workspace.shippingNotice.selectCase') }}
</div>
<div v-else class="space-y-3">
<div class="flex flex-wrap items-center justify-between gap-2">
<div class="font-mono text-lg font-bold text-primary">{{ detail.task_no }}</div>
<button
v-if="chatAgentId"
type="button"
class="inline-flex items-center gap-1 rounded-xl border border-default px-3 py-1.5 text-xs font-medium text-secondary hover:bg-surface-soft"
@click="openInChat"
>
<ExternalLink class="h-3.5 w-3.5" />
{{ $t('workspace.shippingNotice.openChat') }}
</button>
</div>
<ShippingTaskWorkbench :detail="detail" :can-handle="canHandle" @refreshed="refreshAll" />
</div>
</div>
<ShippingRunProgressTable v-else-if="surface === 'runs'" />
<template v-else>
<div class="flex flex-wrap gap-2">
<button
v-for="key in (['pending', 'processing', 'done'] as const)"
@@ -480,5 +539,6 @@ onMounted(async () => {
</div>
</div>
</div>
</template>
</div>
</template>