feat(shipping-notice): 新增发货通知自动上传功能与候选资格评估

- 在环境配置中新增 SHIPPING_NOTICE_AUTO_UPLOAD_ENABLED 选项,默认关闭,需显式开启以支持自动上传。
- 引入新的 pytest.ini 文件,增加测试标记以支持自动化测试。
- 删除不再使用的 seed_shipping_notice_agents.py 文件,简化代码库。
- 更新相关 API,增强发货通知与候选资格评估功能,支持多种筛选条件。
- 增强文档与代码注释,反映新的业务逻辑与功能要求。
This commit is contained in:
hugo committed 2026-08-02 19:26:35 +08:00
1 parent cef3d5b26a
commit 3a9fbac2fc
226 files changed
+25010 -2098

No files matched your search

@@ -1,12 +1,16 @@
<!--
features/admin/modules/shipping-audit/ShippingAuditCenterPage.vue
用途:管理员货代统一审计中心——按 Workflow/Item/Run/PDF/Case/Task 筛选、详情 Diff、关联链、哈希校验、受控导出。
依赖:shipping-audit.api、ShippingAuditEventDetailDrawer、Vue I18n。
逻辑:列表不含快照全文;详情抽屉按权限脱敏;导出/校验写服务端访问审计。
用途:管理员货代统一审计中心——按 Conversation/Run/Candidate/Task/Gate/节点分组筛选、详情 Diff、关联链、哈希校验、受控导出。
依赖:shipping-audit.api、shippingAuditDisplay、ShippingAuditEventDetailDrawer、Vue I18n、BusinessError、useMessage。
逻辑:列表不含快照全文;详情抽屉按权限脱敏;导出/校验写服务端访问审计;
事件分组含复核/对话/Process Gate/资格/节点;支持 candidate_no / gate_code;
窄屏用卡片列表;桌面表无横滚,Case/Task 在业务关联列,WF/Item/Run 芯片可复制。
-->
<script setup lang="ts">
import { onMounted, ref } from 'vue';
import { computed, onMounted, ref } from 'vue';
import { useI18n } from 'vue-i18n';
import { BusinessError } from '@/shared/api/client';
import { useMessage } from '@/shared/composables/useMessage';
import {
exportShippingAuditEvents,
getShippingAuditEvent,
@@ -19,12 +23,15 @@ import {
type ShippingAuditHashVerifyResult,
} from '@/features/admin/api/shipping-audit.api';
import ShippingAuditEventDetailDrawer from './ShippingAuditEventDetailDrawer.vue';
import { shippingAuditBusinessLabel } from './shippingAuditDisplay';
const { t } = useI18n();
const { t, te } = useI18n();
const msg = useMessage();
const loading = ref(false);
const detailLoading = ref(false);
const exporting = ref(false);
const verifying = ref(false);
const moreOpen = ref(false);
const error = ref('');
const page = ref(1);
const pageSize = 25;
@@ -35,6 +42,7 @@ const chainHint = ref('');
const verifyResult = ref<ShippingAuditHashVerifyResult | null>(null);
const filters = ref<ShippingAuditFilters>({
event_type: '',
event_type_group: '',
actor_type: '',
actor_id: '',
workflow_id: '',
@@ -43,10 +51,13 @@ const filters = ref<ShippingAuditFilters>({
document_id: '',
review_case_no: '',
task_no: '',
candidate_no: '',
gate_code: '',
conversation_id: '',
owner_user_id: '',
operation_id: '',
request_id: '',
reason_code: '',
result: '',
created_from: '',
created_to: '',
@@ -77,6 +88,62 @@ function buildFilterPayload(): ShippingAuditFilters {
const formatTime = (value?: string | null) => (value ? new Date(value).toLocaleString() : '—');
/**
* 列表主区业务关联:仅 Case/Task,与 WF/Item/Run 技术编号严格分离。
*/
function primaryBusinessRefs(row: ShippingAuditEventSummary): string {
const parts = [
row.review_case_no ? `Case ${row.review_case_no}` : '',
row.task_no ? `Task ${row.task_no}` : '',
].filter(Boolean);
return parts.length ? parts.join(' · ') : '—';
}
/**
* 行级技术编号芯片(WF/Item/Run),供桌面业务关联列与窄屏卡片复用。
*/
function techRefChips(row: ShippingAuditEventSummary): Array<{ label: string; value: string }> {
return [
{ label: 'WF', value: row.workflow_id },
{ label: 'Item', value: row.workflow_item_id },
{ label: 'Run', value: row.run_no },
].filter((entry): entry is { label: string; value: string } => Boolean(entry.value));
}
/**
* 业务化标签:与详情抽屉共用 shippingAuditDisplay,保证口径一致。
*/
function businessLabel(kind: 'eventTypes' | 'actions' | 'reasonCodes' | 'actorTypes' | 'results', code?: string | null): string {
return shippingAuditBusinessLabel({ t, te }, kind, code);
}
/**
* 复制技术编号;失败时静默忽略。
*/
async function copyTechId(value?: string | null) {
const text = String(value || '').trim();
if (!text || !navigator?.clipboard?.writeText) return;
try {
await navigator.clipboard.writeText(text);
msg.success(t('admin.shippingAudit.copied'));
} catch {
/* ignore */
}
}
/**
* 统一捕获 API 错误为页面提示 + useMessage。
*/
function reportError(err: unknown, fallbackKey: string) {
if (err instanceof BusinessError) {
error.value = err.message;
msg.error(err.message);
return;
}
error.value = t(fallbackKey);
msg.error(t(fallbackKey));
}
/**
* 加载审计列表;服务端已做管理员鉴权与访问留痕。
*/
@@ -87,8 +154,8 @@ async function load() {
const response = await listShippingAuditEvents(page.value, pageSize, buildFilterPayload());
rows.value = response.items;
total.value = response.total;
} catch {
error.value = t('admin.shippingAudit.loadFailed');
} catch (err) {
reportError(err, 'admin.shippingAudit.loadFailed');
} finally {
loading.value = false;
}
@@ -110,8 +177,8 @@ async function openDetail(eventId: number) {
error.value = '';
try {
detail.value = await getShippingAuditEvent(eventId);
} catch {
error.value = t('admin.shippingAudit.detailFailed');
} catch (err) {
reportError(err, 'admin.shippingAudit.detailFailed');
} finally {
detailLoading.value = false;
}
@@ -123,6 +190,7 @@ async function openDetail(eventId: number) {
async function loadAssociationChain() {
error.value = '';
chainHint.value = '';
moreOpen.value = false;
try {
const payload = buildFilterPayload();
const hasSeed = Boolean(
@@ -141,8 +209,8 @@ async function loadAssociationChain() {
rows.value = chain.items.slice().reverse();
total.value = chain.total;
page.value = 1;
} catch {
error.value = t('admin.shippingAudit.chainFailed');
} catch (err) {
reportError(err, 'admin.shippingAudit.chainFailed');
}
}
@@ -153,6 +221,7 @@ async function runHashVerify() {
verifying.value = true;
error.value = '';
verifyResult.value = null;
moreOpen.value = false;
try {
const payload = buildFilterPayload();
verifyResult.value = await verifyShippingAuditHashChain({
@@ -160,8 +229,8 @@ async function runHashVerify() {
workflow_item_id: payload.workflow_item_id || undefined,
sample_limit: 200,
});
} catch {
error.value = t('admin.shippingAudit.verifyFailed');
} catch (err) {
reportError(err, 'admin.shippingAudit.verifyFailed');
} finally {
verifying.value = false;
}
@@ -175,13 +244,16 @@ async function exportCsv() {
error.value = '';
try {
await exportShippingAuditEvents(buildFilterPayload(), 'csv');
} catch {
error.value = t('admin.shippingAudit.exportFailed');
msg.success(t('admin.shippingAudit.exportDone'));
} catch (err) {
reportError(err, 'admin.shippingAudit.exportFailed');
} finally {
exporting.value = false;
}
}
const pageLabel = computed(() => String(page.value));
onMounted(() => {
void load();
});
@@ -189,24 +261,40 @@ onMounted(() => {
<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>
<header class="flex flex-col gap-3 sm:flex-row sm:flex-wrap sm:items-start sm:justify-between">
<div class="min-w-0">
<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 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>
<button type="button" class="btn-secondary btn-sm" :disabled="loading" @click="load">
<!-- [STEP] 窄屏主操作:刷新/导出;校验与关联链收入“更多”。 -->
<div class="flex w-full flex-wrap items-center gap-2 sm:w-auto sm:justify-end">
<button type="button" class="btn-secondary btn-sm" :disabled="loading" data-testid="shipping-audit-refresh" @click="load">
{{ t('admin.shippingAudit.refresh') }}
</button>
<button type="button" class="btn-secondary btn-sm" :disabled="exporting" data-testid="shipping-audit-export" @click="exportCsv">
{{ exporting ? t('admin.shippingAudit.exporting') : t('admin.shippingAudit.export') }}
</button>
<div class="relative">
<button
type="button"
class="btn-secondary btn-sm md:hidden"
data-testid="shipping-audit-more"
@click="moreOpen = !moreOpen"
>
{{ t('admin.shippingAudit.moreActions') }}
</button>
<div
class="absolute right-0 z-10 mt-1 w-44 rounded-lg border border-default bg-surface p-1 shadow-md md:static md:mt-0 md:flex md:w-auto md:items-center md:gap-2 md:border-0 md:bg-transparent md:p-0 md:shadow-none"
:class="moreOpen ? 'block' : 'hidden md:flex'"
>
<button type="button" class="btn-secondary btn-sm w-full justify-start md:w-auto" :disabled="verifying" @click="runHashVerify">
{{ verifying ? t('admin.shippingAudit.verifying') : t('admin.shippingAudit.verifyChain') }}
</button>
<button type="button" class="btn-secondary btn-sm w-full justify-start md:w-auto" @click="loadAssociationChain">
{{ t('admin.shippingAudit.loadChain') }}
</button>
</div>
</div>
</div>
</header>
@@ -235,24 +323,62 @@ onMounted(() => {
<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.candidateNo') }}</span>
<input
v-model="filters.candidate_no"
class="input-field text-sm"
data-testid="shipping-audit-filter-candidate-no"
@keyup.enter="applyFilters"
>
</label>
<label class="space-y-1 text-xs text-secondary">
<span>{{ t('admin.shippingAudit.filters.gateCode') }}</span>
<input
v-model="filters.gate_code"
class="input-field text-sm"
data-testid="shipping-audit-filter-gate-code"
@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>
<option value="user">{{ t('admin.shippingAudit.labels.actorTypes.user') }}</option>
<option value="admin">{{ t('admin.shippingAudit.labels.actorTypes.admin') }}</option>
<option value="system">{{ t('admin.shippingAudit.labels.actorTypes.system') }}</option>
<option value="rpa">{{ t('admin.shippingAudit.labels.actorTypes.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.eventTypeGroup') }}</span>
<select
v-model="filters.event_type_group"
class="select-field text-sm"
data-testid="shipping-audit-filter-event-type-group"
@change="applyFilters"
>
<option value="">{{ t('admin.shippingAudit.filters.all') }}</option>
<option value="review_workbench">{{ t('admin.shippingAudit.filters.eventTypeGroupReviewWorkbench') }}</option>
<option value="chat_workbench">{{ t('admin.shippingAudit.filters.eventTypeGroupChatWorkbench') }}</option>
<option value="process_gate">{{ t('admin.shippingAudit.filters.eventTypeGroupProcessGate') }}</option>
<option value="candidate_qualification">{{ t('admin.shippingAudit.filters.eventTypeGroupQualification') }}</option>
<option value="workflow_node">{{ t('admin.shippingAudit.filters.eventTypeGroupWorkflowNode') }}</option>
</select>
</label>
<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.reasonCode') }}</span>
<input v-model="filters.reason_code" class="input-field text-sm" data-testid="shipping-audit-filter-reason-code" @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">
@@ -288,43 +414,114 @@ onMounted(() => {
</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-[1360px] w-full text-left text-sm">
<!-- 窄屏卡片列表:避免 1360px 表强制横向滚动才能点到 Diff -->
<div class="space-y-3 lg:hidden" data-testid="shipping-audit-card-list">
<p v-if="loading" class="rounded-xl border border-default bg-surface px-3 py-8 text-center text-sm text-muted">
{{ t('admin.shippingAudit.loading') }}
</p>
<p v-else-if="!rows.length" class="rounded-xl border border-default bg-surface px-3 py-8 text-center text-sm text-muted">
{{ t('admin.shippingAudit.empty') }}
</p>
<article
v-for="row in rows"
:key="row.id"
class="rounded-xl border border-default bg-surface p-3"
>
<div class="flex items-start justify-between gap-2">
<div class="min-w-0">
<div class="text-sm font-medium text-secondary">{{ businessLabel('eventTypes', row.event_type) }}</div>
<div class="mt-0.5 text-xs text-muted">{{ businessLabel('actions', row.action) }}</div>
</div>
<button type="button" class="shrink-0 text-sm text-brand-600 hover:underline" @click="openDetail(row.id)">
{{ t('admin.shippingAudit.diff') }}
</button>
</div>
<dl class="mt-2 grid gap-1 text-xs text-secondary">
<div><dt class="inline text-muted">{{ t('admin.shippingAudit.columns.time') }}:</dt><dd class="inline">{{ formatTime(row.created_at) }}</dd></div>
<div><dt class="inline text-muted">{{ t('admin.shippingAudit.columns.actor') }}:</dt><dd class="inline">{{ businessLabel('actorTypes', row.actor_type) }}</dd></div>
<div><dt class="inline text-muted">{{ t('admin.shippingAudit.columns.reasonCode') }}:</dt><dd class="inline font-medium">{{ businessLabel('reasonCodes', row.reason_code) }}</dd></div>
<div><dt class="inline text-muted">{{ t('admin.shippingAudit.columns.result') }}:</dt><dd class="inline">{{ businessLabel('results', row.result) }}</dd></div>
<div v-if="primaryBusinessRefs(row) !== '—'">
<dt class="inline text-muted">{{ t('admin.shippingAudit.columns.businessRefs') }}:</dt>
<dd class="inline">{{ primaryBusinessRefs(row) }}</dd>
</div>
</dl>
<div
v-if="techRefChips(row).length"
class="mt-2 flex flex-wrap items-center gap-1.5"
data-testid="shipping-audit-tech-ref-chips"
>
<span class="text-[10px] text-muted">{{ t('admin.shippingAudit.techRefs') }}</span>
<button
v-for="item in techRefChips(row)"
:key="`${row.id}-m-tech-${item.label}`"
type="button"
class="rounded border border-default px-2 py-1 font-mono text-[11px] text-muted"
:title="item.value"
@click="copyTechId(item.value)"
>
{{ item.label }}
</button>
</div>
</article>
</div>
<!-- 桌面表:table-fixed + 无横滚;技术编号行内次要芯片,无需额外展开 -->
<div class="hidden overflow-x-hidden rounded-xl border border-default bg-surface lg:block" data-testid="shipping-audit-desktop-table">
<table class="w-full table-fixed 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.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>
<th class="px-3 py-2">{{ t('admin.shippingAudit.columns.result') }}</th>
<th class="px-3 py-2"></th>
<th class="w-[16%] px-3 py-2">{{ t('admin.shippingAudit.columns.time') }}</th>
<th class="w-[20%] px-3 py-2">{{ t('admin.shippingAudit.columns.event') }}</th>
<th class="w-[10%] px-3 py-2">{{ t('admin.shippingAudit.columns.actor') }}</th>
<th class="w-[18%] px-3 py-2">{{ t('admin.shippingAudit.columns.reasonCode') }}</th>
<th class="w-[10%] px-3 py-2">{{ t('admin.shippingAudit.columns.result') }}</th>
<th class="w-[16%] px-3 py-2">{{ t('admin.shippingAudit.columns.businessRefs') }}</th>
<th class="w-[10%] 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>
<td colspan="7" 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>
<td colspan="7" 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>
<tr
v-for="row in rows"
:key="row.id"
class="border-b border-default last:border-0"
>
<td class="px-3 py-2 align-top text-xs">{{ formatTime(row.created_at) }}</td>
<td class="px-3 py-2 align-top">
<div class="font-medium break-words">{{ businessLabel('eventTypes', row.event_type) }}</div>
<div class="text-[11px] text-muted break-words">{{ businessLabel('actions', 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.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>
<td class="px-3 py-2">{{ row.result || '—' }}</td>
<td class="px-3 py-2">
<td class="px-3 py-2 align-top text-xs">{{ businessLabel('actorTypes', row.actor_type) }}</td>
<td class="px-3 py-2 align-top text-xs break-words font-medium text-secondary">
{{ businessLabel('reasonCodes', row.reason_code) }}
</td>
<td class="px-3 py-2 align-top">{{ businessLabel('results', row.result) }}</td>
<td class="px-3 py-2 align-top text-[11px] text-secondary break-words">
<div>{{ primaryBusinessRefs(row) }}</div>
<div
v-if="techRefChips(row).length"
class="mt-1 flex flex-wrap gap-1"
data-testid="shipping-audit-tech-ref-chips"
>
<button
v-for="item in techRefChips(row)"
:key="`${row.id}-tech-${item.label}`"
type="button"
class="rounded border border-default bg-surface-soft px-1 py-0.5 font-mono text-[10px] text-muted"
:title="item.value"
@click="copyTechId(item.value)"
>
{{ item.label }}
</button>
</div>
</td>
<td class="px-3 py-2 align-top">
<button type="button" class="text-brand-600 hover:underline" @click="openDetail(row.id)">
{{ t('admin.shippingAudit.diff') }}
</button>
@@ -337,7 +534,7 @@ onMounted(() => {
<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>
<span>{{ pageLabel }}</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>