feat(shipping-notice): 增强发货通知与审计功能,支持敏感数据控制与哈希链校验

- 更新发货通知工具 API,剥离不可信的操作人身份字段,确保审计安全
- 引入审计事件的哈希链校验机制,支持数据完整性验证
- 增强订单抽取与审计功能,支持敏感快照的访问控制
- 更新相关模型与服务,确保新功能的完整性与可追溯性
- 完善文档与代码注释,反映新的业务逻辑与审计要求
This commit is contained in:
hugo committed 2026-07-31 08:59:44 +08:00
1 parent 95cdfe66b0
commit d0fe084999
225 files changed
+25923 -6653

No files matched your search

@@ -1,8 +1,8 @@
<!--
features/admin/modules/shipping-audit/ShippingAuditCenterPage.vue
用途:管理员货代统一审计中心——筛选、详情 Diff、受控导出。
依赖:shipping-audit.api、Vue I18n、Vue Router。
逻辑:列表展示会话/工作项/Case 关联字段;不含快照全文;打开详情才拉取白名单前后差异;导出写服务端访问审计。
用途:管理员货代统一审计中心——按 Workflow/Item/Run/PDF/Case/Task 筛选、详情 Diff、关联链、哈希校验、受控导出。
依赖:shipping-audit.api、ShippingAuditEventDetailDrawer、Vue I18n。
逻辑:列表不含快照全文;详情抽屉按权限脱敏;导出/校验写服务端访问审计。
-->
<script setup lang="ts">
import { onMounted, ref } from 'vue';
@@ -10,32 +10,40 @@ import { useI18n } from 'vue-i18n';
import {
exportShippingAuditEvents,
getShippingAuditEvent,
listShippingAuditAssociationChain,
listShippingAuditEvents,
verifyShippingAuditHashChain,
type ShippingAuditEventDetail,
type ShippingAuditEventSummary,
type ShippingAuditFilters,
type ShippingAuditHashVerifyResult,
} from '@/features/admin/api/shipping-audit.api';
import ShippingAuditEventDetailDrawer from './ShippingAuditEventDetailDrawer.vue';
const { t } = useI18n();
const loading = ref(false);
const detailLoading = ref(false);
const exporting = ref(false);
const verifying = 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 chainHint = ref('');
const verifyResult = ref<ShippingAuditHashVerifyResult | null>(null);
const filters = ref<ShippingAuditFilters>({
event_type: '',
actor_type: '',
actor_id: '',
workflow_id: '',
workflow_item_id: '',
run_no: '',
task_no: '',
document_id: '',
conversation_id: '',
session_item_id: '',
review_case_no: '',
task_no: '',
conversation_id: '',
owner_user_id: '',
operation_id: '',
request_id: '',
@@ -56,6 +64,17 @@ function normalizeDateTimeFilter(value?: string): string {
return date.toISOString();
}
/**
* 组装当前筛选 payload。
*/
function buildFilterPayload(): ShippingAuditFilters {
return {
...filters.value,
created_from: normalizeDateTimeFilter(filters.value.created_from),
created_to: normalizeDateTimeFilter(filters.value.created_to),
};
}
const formatTime = (value?: string | null) => (value ? new Date(value).toLocaleString() : '—');
/**
@@ -65,12 +84,7 @@ 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);
const response = await listShippingAuditEvents(page.value, pageSize, buildFilterPayload());
rows.value = response.items;
total.value = response.total;
} catch {
@@ -103,6 +117,56 @@ async function openDetail(eventId: number) {
}
}
/**
* 按当前关联种子拉取全链摘要提示。
*/
async function loadAssociationChain() {
error.value = '';
chainHint.value = '';
try {
const payload = buildFilterPayload();
const hasSeed = Boolean(
payload.workflow_id || payload.workflow_item_id || payload.run_no
|| payload.document_id || payload.review_case_no || payload.task_no,
);
if (!hasSeed) {
error.value = t('admin.shippingAudit.chainSeedRequired');
return;
}
const chain = await listShippingAuditAssociationChain(payload, 500);
chainHint.value = t('admin.shippingAudit.chainSummary', {
total: chain.total,
truncated: chain.truncated ? t('admin.shippingAudit.chainTruncated') : '',
});
rows.value = chain.items.slice().reverse();
total.value = chain.total;
page.value = 1;
} catch {
error.value = t('admin.shippingAudit.chainFailed');
}
}
/**
* 触发哈希链校验。
*/
async function runHashVerify() {
verifying.value = true;
error.value = '';
verifyResult.value = null;
try {
const payload = buildFilterPayload();
verifyResult.value = await verifyShippingAuditHashChain({
workflow_id: payload.workflow_id || undefined,
workflow_item_id: payload.workflow_item_id || undefined,
sample_limit: 200,
});
} catch {
error.value = t('admin.shippingAudit.verifyFailed');
} finally {
verifying.value = false;
}
}
/**
* 导出当前筛选条件下的 CSV。
*/
@@ -110,12 +174,7 @@ 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');
await exportShippingAuditEvents(buildFilterPayload(), 'csv');
} catch {
error.value = t('admin.shippingAudit.exportFailed');
} finally {
@@ -135,7 +194,13 @@ onMounted(() => {
<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">
<div class="flex flex-wrap gap-2">
<button type="button" class="btn-secondary btn-sm" :disabled="verifying" @click="runHashVerify">
{{ verifying ? t('admin.shippingAudit.verifying') : t('admin.shippingAudit.verifyChain') }}
</button>
<button type="button" class="btn-secondary btn-sm" @click="loadAssociationChain">
{{ t('admin.shippingAudit.loadChain') }}
</button>
<button type="button" class="btn-secondary btn-sm" :disabled="exporting" @click="exportCsv">
{{ exporting ? t('admin.shippingAudit.exporting') : t('admin.shippingAudit.export') }}
</button>
@@ -147,8 +212,28 @@ onMounted(() => {
<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">
<span>{{ t('admin.shippingAudit.filters.workflowId') }}</span>
<input v-model="filters.workflow_id" class="input-field text-sm" @keyup.enter="applyFilters">
</label>
<label class="space-y-1 text-xs text-secondary">
<span>{{ t('admin.shippingAudit.filters.workflowItemId') }}</span>
<input v-model="filters.workflow_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.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.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.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.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.actorType') }}</span>
@@ -165,40 +250,8 @@ onMounted(() => {
<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">
<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.result') }}</span>
@@ -221,17 +274,29 @@ onMounted(() => {
</label>
</div>
<p v-if="chainHint" class="rounded-lg border border-default bg-surface-soft px-3 py-2 text-xs text-secondary">{{ chainHint }}</p>
<p
v-if="verifyResult"
class="rounded-lg border border-default bg-surface-soft px-3 py-2 text-xs text-secondary"
data-testid="shipping-audit-verify-result"
>
{{ t('admin.shippingAudit.verifySummary', {
ok: verifyResult.ok ? t('admin.shippingAudit.verifyOk') : t('admin.shippingAudit.verifyFailedShort'),
checked: verifyResult.checked_chains,
failed: verifyResult.failed_chains,
}) }}
</p>
<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">
<table class="min-w-[1360px] 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.workflow') }}</th>
<th class="px-3 py-2">{{ t('admin.shippingAudit.columns.workflowItem') }}</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>
@@ -253,8 +318,8 @@ onMounted(() => {
<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.workflow_id || '—' }}</td>
<td class="px-3 py-2 font-mono text-xs">{{ row.workflow_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>
@@ -276,41 +341,10 @@ onMounted(() => {
<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>
<ShippingAuditEventDetailDrawer
:detail="detail"
:loading="detailLoading"
@close="detail = null"
/>
</section>
</template>