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,316 @@
<!--
features/admin/modules/shipping-audit/ShippingAuditCenterPage.vue
用途:管理员货代统一审计中心——筛选、详情 Diff、受控导出。
依赖:shipping-audit.api、Vue I18n、Vue Router。
逻辑:列表展示会话/工作项/Case 关联字段;不含快照全文;打开详情才拉取白名单前后差异;导出写服务端访问审计。
-->
<script setup lang="ts">
import { onMounted, ref } from 'vue';
import { useI18n } from 'vue-i18n';
import {
exportShippingAuditEvents,
getShippingAuditEvent,
listShippingAuditEvents,
type ShippingAuditEventDetail,
type ShippingAuditEventSummary,
type ShippingAuditFilters,
} from '@/features/admin/api/shipping-audit.api';
const { t } = useI18n();
const loading = ref(false);
const detailLoading = ref(false);
const exporting = ref(false);
const error = ref('');
const page = ref(1);
const pageSize = 25;
const total = ref(0);
const rows = ref<ShippingAuditEventSummary[]>([]);
const detail = ref<ShippingAuditEventDetail | null>(null);
const filters = ref<ShippingAuditFilters>({
event_type: '',
actor_type: '',
actor_id: '',
run_no: '',
task_no: '',
document_id: '',
conversation_id: '',
session_item_id: '',
review_case_no: '',
owner_user_id: '',
operation_id: '',
request_id: '',
result: '',
created_from: '',
created_to: '',
q: '',
});
/**
* 将 datetime-local 值规范为 ISO 字符串供 API 查询。
*/
function normalizeDateTimeFilter(value?: string): string {
const raw = String(value || '').trim();
if (!raw) return '';
const date = new Date(raw);
if (Number.isNaN(date.getTime())) return raw;
return date.toISOString();
}
const formatTime = (value?: string | null) => (value ? new Date(value).toLocaleString() : '—');
/**
* 加载审计列表;服务端已做管理员鉴权与访问留痕。
*/
async function load() {
loading.value = true;
error.value = '';
try {
const payload: ShippingAuditFilters = {
...filters.value,
created_from: normalizeDateTimeFilter(filters.value.created_from),
created_to: normalizeDateTimeFilter(filters.value.created_to),
};
const response = await listShippingAuditEvents(page.value, pageSize, payload);
rows.value = response.items;
total.value = response.total;
} catch {
error.value = t('admin.shippingAudit.loadFailed');
} finally {
loading.value = false;
}
}
/**
* 应用筛选并回到第一页。
*/
async function applyFilters() {
page.value = 1;
await load();
}
/**
* 打开详情抽屉并加载白名单 Diff。
*/
async function openDetail(eventId: number) {
detailLoading.value = true;
error.value = '';
try {
detail.value = await getShippingAuditEvent(eventId);
} catch {
error.value = t('admin.shippingAudit.detailFailed');
} finally {
detailLoading.value = false;
}
}
/**
* 导出当前筛选条件下的 CSV。
*/
async function exportCsv() {
exporting.value = true;
error.value = '';
try {
const payload: ShippingAuditFilters = {
...filters.value,
created_from: normalizeDateTimeFilter(filters.value.created_from),
created_to: normalizeDateTimeFilter(filters.value.created_to),
};
await exportShippingAuditEvents(payload, 'csv');
} catch {
error.value = t('admin.shippingAudit.exportFailed');
} finally {
exporting.value = false;
}
}
onMounted(() => {
void load();
});
</script>
<template>
<section class="space-y-5 p-5 md:p-7" data-testid="shipping-audit-center">
<header class="flex flex-wrap items-start justify-between gap-4">
<div>
<h1 class="section-title">{{ t('admin.shippingAudit.title') }}</h1>
<p class="section-desc mt-1 max-w-3xl">{{ t('admin.shippingAudit.subtitle') }}</p>
</div>
<div class="flex gap-2">
<button type="button" class="btn-secondary btn-sm" :disabled="exporting" @click="exportCsv">
{{ exporting ? t('admin.shippingAudit.exporting') : t('admin.shippingAudit.export') }}
</button>
<button type="button" class="btn-secondary btn-sm" :disabled="loading" @click="load">
{{ t('admin.shippingAudit.refresh') }}
</button>
</div>
</header>
<div class="grid gap-3 rounded-xl border border-default bg-surface p-3 md:grid-cols-3 lg:grid-cols-4">
<label class="space-y-1 text-xs text-secondary">
<span>{{ t('admin.shippingAudit.filters.eventType') }}</span>
<input v-model="filters.event_type" class="input-field text-sm" @keyup.enter="applyFilters">
</label>
<label class="space-y-1 text-xs text-secondary">
<span>{{ t('admin.shippingAudit.filters.actorType') }}</span>
<select v-model="filters.actor_type" class="select-field text-sm" @change="applyFilters">
<option value="">{{ t('admin.shippingAudit.filters.all') }}</option>
<option value="user">user</option>
<option value="admin">admin</option>
<option value="system">system</option>
<option value="rpa">rpa</option>
</select>
</label>
<label class="space-y-1 text-xs text-secondary">
<span>{{ t('admin.shippingAudit.filters.actorId') }}</span>
<input v-model="filters.actor_id" class="input-field text-sm" @keyup.enter="applyFilters">
</label>
<label class="space-y-1 text-xs text-secondary">
<span>{{ t('admin.shippingAudit.filters.runNo') }}</span>
<input v-model="filters.run_no" class="input-field text-sm" @keyup.enter="applyFilters">
</label>
<label class="space-y-1 text-xs text-secondary">
<span>{{ t('admin.shippingAudit.filters.taskNo') }}</span>
<input v-model="filters.task_no" class="input-field text-sm" @keyup.enter="applyFilters">
</label>
<label class="space-y-1 text-xs text-secondary">
<span>{{ t('admin.shippingAudit.filters.documentId') }}</span>
<input v-model="filters.document_id" class="input-field text-sm" @keyup.enter="applyFilters">
</label>
<label class="space-y-1 text-xs text-secondary">
<span>{{ t('admin.shippingAudit.filters.conversationId') }}</span>
<input v-model="filters.conversation_id" class="input-field text-sm" @keyup.enter="applyFilters">
</label>
<label class="space-y-1 text-xs text-secondary">
<span>{{ t('admin.shippingAudit.filters.sessionItemId') }}</span>
<input v-model="filters.session_item_id" class="input-field text-sm" @keyup.enter="applyFilters">
</label>
<label class="space-y-1 text-xs text-secondary">
<span>{{ t('admin.shippingAudit.filters.reviewCaseNo') }}</span>
<input v-model="filters.review_case_no" class="input-field text-sm" @keyup.enter="applyFilters">
</label>
<label class="space-y-1 text-xs text-secondary">
<span>{{ t('admin.shippingAudit.filters.ownerUserId') }}</span>
<input v-model="filters.owner_user_id" class="input-field text-sm" @keyup.enter="applyFilters">
</label>
<label class="space-y-1 text-xs text-secondary">
<span>{{ t('admin.shippingAudit.filters.operationId') }}</span>
<input v-model="filters.operation_id" class="input-field text-sm" @keyup.enter="applyFilters">
</label>
<label class="space-y-1 text-xs text-secondary">
<span>{{ t('admin.shippingAudit.filters.requestId') }}</span>
<input v-model="filters.request_id" class="input-field text-sm" @keyup.enter="applyFilters">
</label>
<label class="space-y-1 text-xs text-secondary">
<span>{{ t('admin.shippingAudit.filters.result') }}</span>
<input v-model="filters.result" class="input-field text-sm" @keyup.enter="applyFilters">
</label>
<label class="space-y-1 text-xs text-secondary">
<span>{{ t('admin.shippingAudit.filters.createdFrom') }}</span>
<input v-model="filters.created_from" type="datetime-local" class="input-field text-sm" @change="applyFilters">
</label>
<label class="space-y-1 text-xs text-secondary">
<span>{{ t('admin.shippingAudit.filters.createdTo') }}</span>
<input v-model="filters.created_to" type="datetime-local" class="input-field text-sm" @change="applyFilters">
</label>
<label class="space-y-1 text-xs text-secondary md:col-span-2 lg:col-span-1">
<span>{{ t('admin.shippingAudit.filters.q') }}</span>
<div class="flex gap-2">
<input v-model="filters.q" class="input-field text-sm flex-1" @keyup.enter="applyFilters">
<button type="button" class="btn-secondary btn-sm" @click="applyFilters">{{ t('admin.shippingAudit.apply') }}</button>
</div>
</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-[1280px] 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('admin.shippingAudit.columns.time') }}</th>
<th class="px-3 py-2">{{ t('admin.shippingAudit.columns.event') }}</th>
<th class="px-3 py-2">{{ t('admin.shippingAudit.columns.actor') }}</th>
<th class="px-3 py-2">{{ t('admin.shippingAudit.columns.conversation') }}</th>
<th class="px-3 py-2">{{ t('admin.shippingAudit.columns.sessionItem') }}</th>
<th class="px-3 py-2">{{ t('admin.shippingAudit.columns.reviewCase') }}</th>
<th class="px-3 py-2">{{ t('admin.shippingAudit.columns.run') }}</th>
<th class="px-3 py-2">{{ t('admin.shippingAudit.columns.task') }}</th>
<th class="px-3 py-2">{{ t('admin.shippingAudit.columns.result') }}</th>
<th class="px-3 py-2"></th>
</tr>
</thead>
<tbody>
<tr v-if="loading">
<td colspan="10" class="px-3 py-8 text-center text-muted">{{ t('admin.shippingAudit.loading') }}</td>
</tr>
<tr v-else-if="!rows.length">
<td colspan="10" class="px-3 py-8 text-center text-muted">{{ t('admin.shippingAudit.empty') }}</td>
</tr>
<tr v-for="row in rows" :key="row.id" class="border-b border-default last:border-0">
<td class="px-3 py-2 text-xs">{{ formatTime(row.created_at) }}</td>
<td class="px-3 py-2">
<div class="font-medium">{{ row.event_type }}</div>
<div class="text-[11px] text-muted">{{ row.action || '—' }}</div>
</td>
<td class="px-3 py-2 text-xs">{{ row.actor_type }}<span v-if="row.actor_id"> / {{ row.actor_id }}</span></td>
<td class="px-3 py-2 font-mono text-xs">{{ row.conversation_id || '—' }}</td>
<td class="px-3 py-2 font-mono text-xs">{{ row.session_item_id || '—' }}</td>
<td class="px-3 py-2 font-mono text-xs">{{ row.review_case_no || '—' }}</td>
<td class="px-3 py-2 font-mono text-xs">{{ row.run_no || '—' }}</td>
<td class="px-3 py-2 font-mono text-xs">{{ row.task_no || '—' }}</td>
<td class="px-3 py-2">{{ row.result || '—' }}</td>
<td class="px-3 py-2">
<button type="button" class="text-brand-600 hover:underline" @click="openDetail(row.id)">
{{ t('admin.shippingAudit.diff') }}
</button>
</td>
</tr>
</tbody>
</table>
</div>
<div class="flex items-center justify-end gap-3 text-sm">
<span class="text-xs text-muted">{{ t('admin.shippingAudit.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('admin.shippingAudit.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('admin.shippingAudit.next') }}</button>
</div>
<div v-if="detail || detailLoading" class="fixed inset-0 z-50 flex justify-end bg-overlay" @click.self="detail = null">
<aside class="h-full w-full max-w-xl overflow-y-auto bg-surface p-6 shadow-2xl">
<div class="flex items-center justify-between">
<h2 class="text-lg font-bold">{{ t('admin.shippingAudit.detailTitle') }}</h2>
<button type="button" class="text-secondary" @click="detail = null">{{ t('admin.close') }}</button>
</div>
<p v-if="detailLoading" class="mt-6 text-muted">{{ t('admin.shippingAudit.loading') }}</p>
<template v-else-if="detail">
<dl class="mt-5 grid grid-cols-2 gap-3 text-sm">
<dt>{{ t('admin.shippingAudit.columns.event') }}</dt><dd>{{ detail.event_type }}</dd>
<dt>{{ t('admin.shippingAudit.columns.actor') }}</dt><dd>{{ detail.actor_type }} / {{ detail.actor_id || '—' }}</dd>
<dt>{{ t('admin.shippingAudit.columns.run') }}</dt><dd class="font-mono text-xs">{{ detail.run_no || '—' }}</dd>
<dt>{{ t('admin.shippingAudit.columns.task') }}</dt><dd class="font-mono text-xs">{{ detail.task_no || '—' }}</dd>
<dt>{{ t('admin.shippingAudit.filters.conversationId') }}</dt><dd class="font-mono text-xs">{{ detail.conversation_id || '—' }}</dd>
<dt>{{ t('admin.shippingAudit.filters.sessionItemId') }}</dt><dd class="font-mono text-xs">{{ detail.session_item_id || '—' }}</dd>
<dt>{{ t('admin.shippingAudit.filters.reviewCaseNo') }}</dt><dd class="font-mono text-xs">{{ detail.review_case_no || '—' }}</dd>
<dt>{{ t('admin.shippingAudit.filters.ownerUserId') }}</dt><dd class="font-mono text-xs">{{ detail.owner_user_id || '—' }}</dd>
<dt>operation_id</dt><dd class="font-mono text-xs">{{ detail.operation_id || '—' }}</dd>
<dt>request_id</dt><dd class="font-mono text-xs">{{ detail.request_id || '—' }}</dd>
</dl>
<h3 class="mt-6 font-semibold">{{ t('admin.shippingAudit.diff') }}</h3>
<div v-if="detail.diff?.length" class="mt-2 space-y-2">
<div
v-for="row in detail.diff"
:key="row.key"
class="rounded-lg border border-default p-3 text-xs"
>
<div class="font-medium">{{ row.key }} · {{ row.change }}</div>
<div class="mt-1 text-muted">{{ t('admin.shippingAudit.before') }}: {{ row.before == null ? '—' : JSON.stringify(row.before) }}</div>
<div class="text-muted">{{ t('admin.shippingAudit.after') }}: {{ row.after == null ? '—' : JSON.stringify(row.after) }}</div>
</div>
</div>
<p v-else class="mt-2 text-sm text-muted">{{ t('admin.shippingAudit.noDiff') }}</p>
</template>
</aside>
</div>
</section>
</template>