feat(shipping-notice): 新增货代发货通知全流程业务功能

- 新增后端完整业务支持:数据库模型、API接口、核心服务与RPA对接逻辑
- 新增前端工作台页面、路由适配与多语言国际化
- 新增Dify自定义工具OpenAPI规范、Agent配置脚本与部署文档
- 新增发货Excel模板生成脚本与默认模板
- 修复测试配置文件中的环境变量命名错误
- 更新本地开发环境变量配置
This commit is contained in:
hugo committed 2026-06-01 21:22:22 +08:00
1 parent 93e99793d8
commit 2d7bdecc43
46 files changed
+3462 -7

No files matched your search

+60
View File
@@ -0,0 +1,60 @@
import { getAuthHeaders } from '../utils/auth';
export interface ShippingCaseSummary {
id: number;
case_no: string;
source_type: string;
customer_name?: string | null;
process_status: string;
review_status?: string | null;
match_status?: string | null;
pending_human_reason?: string | null;
conversation_id?: string | null;
export_file_name?: string | null;
freight_ref_no?: string | null;
created_at?: string | null;
updated_at?: string | null;
}
export interface ShippingCaseEvent {
event_type: string;
detail_json?: Record<string, unknown> | null;
created_at?: string | null;
}
export interface ShippingCaseDetail extends ShippingCaseSummary {
customer_code?: string | null;
ship_to?: string | null;
required_date?: string | null;
lines: Array<Record<string, unknown>>;
shortage?: Record<string, unknown> | null;
line_results?: Array<Record<string, unknown>>;
parse_confidence?: number | null;
error_message?: string | null;
events: ShippingCaseEvent[];
}
async function getJson<T>(url: string): Promise<T> {
const res = await fetch(url, { headers: getAuthHeaders() });
if (!res.ok) {
const body = await res.json().catch(() => ({}));
throw new Error((body as { error?: string }).error || res.statusText);
}
return res.json() as Promise<T>;
}
export const listWorkspaceShippingCases = (params?: { process_status?: string; limit?: number }) => {
const sp = new URLSearchParams();
if (params?.process_status) sp.set('process_status', params.process_status);
if (params?.limit) sp.set('limit', String(params.limit));
const qs = sp.toString();
return getJson<ShippingCaseSummary[]>(`/api/workspace/shipping-cases${qs ? '?' + qs : ''}`);
};
export const getWorkspaceShippingCase = (caseNo: string) =>
getJson<ShippingCaseDetail>(`/api/workspace/shipping-cases/${encodeURIComponent(caseNo)}`);
export const workspaceShippingExportUrl = (caseNo: string) =>
`/api/workspace/shipping-cases/${encodeURIComponent(caseNo)}/export`;
export const SHIPPING_NOTICE_AGENT_NAME = '货代发货通知 Agent';
+73 -1
View File
@@ -1,4 +1,4 @@
import { createI18n } from 'vue-i18n';
import { createI18n } from 'vue-i18n';
const messages = {
'en': {
@@ -353,6 +353,7 @@ const messages = {
applications: 'Applications',
knowledgeBase: 'Knowledge Base',
scheduleRuns: 'Schedule Runs',
shippingNotice: 'Shipping Notice',
feedback: 'Feedback',
updates: 'Recent Updates',
backToChat: 'Back to Chat',
@@ -408,6 +409,40 @@ const messages = {
downloadExcelFailed: 'Failed to download Excel'
}
},
shippingNotice: {
title: 'Shipping Notice Cases',
subtitle: 'Read-only view. Continue processing in Chat.',
refresh: 'Refresh',
search: 'Search',
loading: 'Loading...',
empty: 'No shipping cases yet',
selectCase: 'Select a case to view details',
loadFailed: 'Failed to load case',
openChat: 'Continue in Chat',
download: 'Download Excel',
lines: 'Shipment lines',
qty: 'Qty',
events: 'Event log',
filters: {
status: 'Status'
},
fields: {
status: 'Process status',
match: 'Match status',
shipTo: 'Ship to',
freightRef: 'Freight ref no.'
},
status: {
all: 'All',
created: 'Created',
waitingInventory: 'Waiting inventory',
inventoryReady: 'Inventory ready',
matched: 'Matched',
waitingUpload: 'Waiting upload',
uploaded: 'Uploaded',
uploadFailed: 'Upload failed'
}
},
profile: {
msg: {
loadFailed: 'Failed to load profile',
@@ -1214,6 +1249,7 @@ const messages = {
thinking: 'Generating response...',
disclaimer: 'AI can make mistakes. Please verify important information.',
createNewChat: 'New Chat',
shippingNoticeContinue: 'Please continue shipping case {caseId}. Call get_case_status first and tell me the next step.',
clearAll: 'Clear All',
clearOneRecord: 'Clear This Record',
agents: 'Agents',
@@ -1808,6 +1844,7 @@ const messages = {
applications: '应用管理',
knowledgeBase: '知识库管理',
scheduleRuns: '排程记录',
shippingNotice: '货代发货',
feedback: '意见反馈',
updates: '最近更新',
backToChat: '返回聊天',
@@ -1863,6 +1900,40 @@ const messages = {
downloadExcelFailed: '下载 Excel 失败'
}
},
shippingNotice: {
title: '货代发货通知',
subtitle: '只读工作台,请在 Chat 中继续处理。',
refresh: '刷新',
search: '查询',
loading: '正在加载...',
empty: '暂无发货任务',
selectCase: '选择左侧任务查看详情',
loadFailed: '加载失败',
openChat: '在 Chat 中继续',
download: '下载 Excel',
lines: '发货明细',
qty: '数量',
events: '事件记录',
filters: {
status: '状态'
},
fields: {
status: '流程状态',
match: '匹配状态',
shipTo: '收货地址',
freightRef: '货代单号'
},
status: {
all: '全部',
created: '已创建',
waitingInventory: '等待库存',
inventoryReady: '库存就绪',
matched: '已匹配',
waitingUpload: '等待上传',
uploaded: '已上传',
uploadFailed: '上传失败'
}
},
profile: {
msg: {
loadFailed: '加载个人中心失败',
@@ -2648,6 +2719,7 @@ const messages = {
thinking: '正在生成回答...',
disclaimer: 'AI 可能会犯错,请核实重要信息。',
createNewChat: '创建新对话',
shippingNoticeContinue: '请继续处理发货任务 {caseId},请先调用 get_case_status 查询当前状态并告知我下一步。',
clearAll: '清空全部',
clearOneRecord: '清除该记录',
agents: '智能体',
+7
View File
@@ -6,6 +6,7 @@ import ChatView from '../views/ChatView.vue';
import AdminView from '../views/AdminView.vue';
import ResetPasswordView from '../views/ResetPasswordView.vue';
import KbWorkspaceView from '../views/KbWorkspaceView.vue';
import ShippingNoticeView from '../views/ShippingNoticeView.vue';
import { config } from '../config';
import { getStoredAuthUser } from '../utils/auth';
@@ -47,6 +48,12 @@ const routes = [
component: KbWorkspaceView,
meta: { title: '知识库工作台' }
},
{
path: '/shipping-notice',
name: 'ShippingNotice',
component: ShippingNoticeView,
meta: { title: '货代发货通知' }
},
{
path: '/kb/admin',
redirect: { path: '/admin', query: { module: 'knowledge_base' } }
+8
View File
@@ -1671,6 +1671,11 @@ const presetQuestion = computed(() => {
return typeof q === 'string' ? q : '';
});
const shippingCaseIdFromQuery = computed(() => {
const value = route.query.case_id;
return typeof value === 'string' ? value.trim() : '';
});
/**
* handleSend
* 用途:将输入框内容发送给当前 Agent
@@ -2072,6 +2077,9 @@ onMounted(async () => {
if (presetQuestion.value) {
input.value = presetQuestion.value;
handleSend();
} else if (shippingCaseIdFromQuery.value) {
input.value = t('chat.shippingNoticeContinue', { caseId: shippingCaseIdFromQuery.value });
handleSend();
}
// Use config from config.ts instead of API
showChatRating.value = config.workspace?.showChatRating ?? true;
+271
View File
@@ -0,0 +1,271 @@
<script setup lang="ts">
import { computed, onMounted, ref, watch } from 'vue';
import { useRouter } from 'vue-router';
import { useI18n } from 'vue-i18n';
import { ArrowLeft, Download, ExternalLink, RefreshCw } from 'lucide-vue-next';
import {
getWorkspaceShippingCase,
listWorkspaceShippingCases,
SHIPPING_NOTICE_AGENT_NAME,
workspaceShippingExportUrl,
type ShippingCaseDetail,
type ShippingCaseSummary,
} from '../api/shippingNotice';
import { getAuthHeaders } from '../utils/auth';
const props = defineProps<{
embedded?: boolean;
}>();
const router = useRouter();
const { t } = useI18n();
const loading = ref(false);
const detailLoading = ref(false);
const cases = ref<ShippingCaseSummary[]>([]);
const selectedCaseNo = ref<string | null>(null);
const detail = ref<ShippingCaseDetail | null>(null);
const statusFilter = ref('all');
const chatAgentId = ref<number | null>(null);
const statusOptions = computed(() => [
{ value: 'all', label: t('workspace.shippingNotice.status.all') },
{ value: 'created', label: t('workspace.shippingNotice.status.created') },
{ value: 'waiting_inventory', label: t('workspace.shippingNotice.status.waitingInventory') },
{ value: 'inventory_ready', label: t('workspace.shippingNotice.status.inventoryReady') },
{ value: 'matched', label: t('workspace.shippingNotice.status.matched') },
{ value: 'waiting_upload', label: t('workspace.shippingNotice.status.waitingUpload') },
{ value: 'uploaded', label: t('workspace.shippingNotice.status.uploaded') },
{ value: 'upload_failed', label: t('workspace.shippingNotice.status.uploadFailed') },
]);
const statusBadge = (status: string) => {
const map: Record<string, { cls: string; label: string }> = {
created: { cls: 'bg-slate-100 text-secondary', label: t('workspace.shippingNotice.status.created') },
waiting_inventory: { cls: 'bg-amber-100 text-amber-700', label: t('workspace.shippingNotice.status.waitingInventory') },
inventory_ready: { cls: 'bg-blue-100 text-blue-700', label: t('workspace.shippingNotice.status.inventoryReady') },
matched: { cls: 'bg-emerald-100 text-emerald-700', label: t('workspace.shippingNotice.status.matched') },
waiting_upload: { cls: 'bg-amber-100 text-amber-700', label: t('workspace.shippingNotice.status.waitingUpload') },
uploaded: { cls: 'bg-emerald-100 text-emerald-700', label: t('workspace.shippingNotice.status.uploaded') },
upload_failed: { cls: 'bg-rose-100 text-rose-700', label: t('workspace.shippingNotice.status.uploadFailed') },
};
return map[status] || { cls: 'bg-slate-100 text-secondary', label: status };
};
const loadCases = async () => {
loading.value = true;
try {
cases.value = await listWorkspaceShippingCases({
process_status: statusFilter.value === 'all' ? undefined : statusFilter.value,
limit: 100,
});
} catch {
cases.value = [];
} finally {
loading.value = false;
}
};
const loadDetail = async (caseNo: string) => {
detailLoading.value = true;
try {
detail.value = await getWorkspaceShippingCase(caseNo);
} catch {
detail.value = null;
} finally {
detailLoading.value = false;
}
};
const resolveChatAgent = async () => {
try {
const res = await fetch('/api/agents', { headers: getAuthHeaders() });
if (!res.ok) return;
const agents = (await res.json()) as Array<{ id: number; name: string }>;
const found = agents.find((a) => a.name === SHIPPING_NOTICE_AGENT_NAME);
if (found) chatAgentId.value = found.id;
} catch {
/* ignore */
}
};
const openInChat = (caseNo: string) => {
if (!chatAgentId.value) return;
router.push({ path: `/chat/${chatAgentId.value}`, query: { case_id: caseNo } });
};
const downloadExport = async (caseNo: string) => {
const url = workspaceShippingExportUrl(caseNo);
const res = await fetch(url, { headers: getAuthHeaders() });
if (!res.ok) return;
const blob = await res.blob();
const a = document.createElement('a');
a.href = URL.createObjectURL(blob);
a.download = detail.value?.export_file_name || `${caseNo}.xlsx`;
a.click();
URL.revokeObjectURL(a.href);
};
watch(selectedCaseNo, (val) => {
if (val) loadDetail(val);
else detail.value = null;
});
onMounted(async () => {
await Promise.all([loadCases(), resolveChatAgent()]);
});
</script>
<template>
<div class="space-y-5 animate-fade-in-up">
<div class="flex items-center justify-between gap-3">
<div class="flex items-center gap-3">
<button
v-if="!embedded"
type="button"
class="inline-flex h-9 w-9 items-center justify-center rounded-xl border border-default text-secondary hover:bg-surface-soft"
@click="router.push('/workspace')"
>
<ArrowLeft class="h-4 w-4" />
</button>
<div>
<h2 class="text-2xl font-bold text-primary">{{ $t('workspace.shippingNotice.title') }}</h2>
<p class="text-sm text-muted">{{ $t('workspace.shippingNotice.subtitle') }}</p>
</div>
</div>
<button
type="button"
class="inline-flex items-center gap-1.5 rounded-xl border border-default px-3 py-1.5 text-sm font-medium text-secondary transition-colors hover:bg-surface-soft"
@click="loadCases"
>
<RefreshCw class="h-3.5 w-3.5" />
{{ $t('workspace.shippingNotice.refresh') }}
</button>
</div>
<div class="flex flex-wrap items-end gap-3 rounded-2xl border border-default/80 bg-surface/70 px-4 py-3 shadow-sm">
<div>
<label class="mb-1 block text-xs font-medium text-muted">{{ $t('workspace.shippingNotice.filters.status') }}</label>
<select v-model="statusFilter" class="rounded-xl border border-default bg-surface px-3 py-2 text-sm">
<option v-for="opt in statusOptions" :key="opt.value" :value="opt.value">{{ opt.label }}</option>
</select>
</div>
<button
type="button"
class="rounded-xl bg-brand-600 px-4 py-2 text-sm font-medium text-white hover:bg-brand-700"
@click="loadCases"
>
{{ $t('workspace.shippingNotice.search') }}
</button>
</div>
<div class="grid gap-5 lg:grid-cols-5">
<div class="lg:col-span-2 space-y-2">
<div v-if="loading" class="rounded-2xl border border-dashed border-default py-10 text-center text-sm text-muted">
{{ $t('workspace.shippingNotice.loading') }}
</div>
<div v-else-if="cases.length === 0" class="rounded-2xl border border-dashed border-default py-10 text-center text-sm text-muted">
{{ $t('workspace.shippingNotice.empty') }}
</div>
<button
v-for="item in cases"
:key="item.case_no"
type="button"
class="w-full rounded-2xl border px-4 py-3 text-left transition-colors"
:class="selectedCaseNo === item.case_no ? 'border-brand-400 bg-brand-50/60' : 'border-default hover:bg-surface-soft/70'"
@click="selectedCaseNo = item.case_no"
>
<div class="flex items-center justify-between gap-2">
<span class="font-mono text-sm font-semibold text-primary">{{ item.case_no }}</span>
<span class="rounded-full px-2 py-0.5 text-xs font-medium" :class="statusBadge(item.process_status).cls">
{{ statusBadge(item.process_status).label }}
</span>
</div>
<div class="mt-1 truncate text-sm text-secondary">{{ item.customer_name || '—' }}</div>
<div class="mt-1 text-xs text-muted">{{ item.created_at || '' }}</div>
</button>
</div>
<div class="lg:col-span-3 rounded-2xl border border-default bg-surface/50 p-5">
<div v-if="!selectedCaseNo" class="py-16 text-center text-sm text-muted">
{{ $t('workspace.shippingNotice.selectCase') }}
</div>
<div v-else-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.loadFailed') }}
</div>
<div v-else class="space-y-4">
<div class="flex flex-wrap items-center justify-between gap-3">
<div>
<div class="font-mono text-lg font-bold text-primary">{{ detail.case_no }}</div>
<div class="text-sm text-muted">{{ detail.customer_name }} · {{ detail.customer_code || '—' }}</div>
</div>
<div class="flex flex-wrap gap-2">
<button
v-if="chatAgentId"
type="button"
class="inline-flex items-center gap-1 rounded-xl border border-brand-300 bg-brand-50 px-3 py-1.5 text-sm font-medium text-brand-700 hover:bg-brand-100"
@click="openInChat(detail.case_no)"
>
<ExternalLink class="h-3.5 w-3.5" />
{{ $t('workspace.shippingNotice.openChat') }}
</button>
<button
v-if="detail.export_file_name"
type="button"
class="inline-flex items-center gap-1 rounded-xl border border-default px-3 py-1.5 text-sm font-medium text-secondary hover:bg-surface-soft"
@click="downloadExport(detail.case_no)"
>
<Download class="h-3.5 w-3.5" />
{{ $t('workspace.shippingNotice.download') }}
</button>
</div>
</div>
<dl class="grid gap-3 sm:grid-cols-2 text-sm">
<div><dt class="text-muted">{{ $t('workspace.shippingNotice.fields.status') }}</dt><dd>{{ detail.process_status }}</dd></div>
<div><dt class="text-muted">{{ $t('workspace.shippingNotice.fields.match') }}</dt><dd>{{ detail.match_status || '—' }}</dd></div>
<div><dt class="text-muted">{{ $t('workspace.shippingNotice.fields.shipTo') }}</dt><dd>{{ detail.ship_to || '—' }}</dd></div>
<div><dt class="text-muted">{{ $t('workspace.shippingNotice.fields.freightRef') }}</dt><dd>{{ detail.freight_ref_no || '—' }}</dd></div>
</dl>
<div v-if="detail.error_message" class="rounded-xl border border-rose-200 bg-rose-50 px-3 py-2 text-sm text-rose-700">
{{ detail.error_message }}
</div>
<div v-if="detail.lines?.length">
<h3 class="mb-2 text-sm font-semibold text-secondary">{{ $t('workspace.shippingNotice.lines') }}</h3>
<div class="overflow-x-auto rounded-xl border border-default">
<table class="min-w-full text-sm">
<thead class="bg-surface-soft text-left text-xs text-muted">
<tr>
<th class="px-3 py-2">SKU</th>
<th class="px-3 py-2">{{ $t('workspace.shippingNotice.qty') }}</th>
</tr>
</thead>
<tbody>
<tr v-for="(line, idx) in detail.lines" :key="idx" class="border-t border-default/60">
<td class="px-3 py-2 font-mono">{{ line.sku || line.part_no || '—' }}</td>
<td class="px-3 py-2">{{ line.qty ?? line.quantity ?? '—' }}</td>
</tr>
</tbody>
</table>
</div>
</div>
<div v-if="detail.events?.length">
<h3 class="mb-2 text-sm font-semibold text-secondary">{{ $t('workspace.shippingNotice.events') }}</h3>
<ul class="max-h-48 space-y-1 overflow-y-auto text-xs text-muted">
<li v-for="(ev, idx) in [...detail.events].reverse()" :key="idx">
<span class="font-medium text-secondary">{{ ev.event_type }}</span>
<span class="ml-2">{{ ev.created_at }}</span>
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
</template>
+20 -3
View File
@@ -56,8 +56,9 @@ import {
} from 'lucide-vue-next';
import KbWorkspaceView from './KbWorkspaceView.vue';
import ShippingNoticeView from './ShippingNoticeView.vue';
import { listWorkspaceScheduleRuns, workspaceRunExcelUrl, type ScheduleRun } from '../api/schedule';
import { Clock, Download, Search, RefreshCw } from 'lucide-vue-next';
import { Clock, Download, Search, RefreshCw, Package } from 'lucide-vue-next';
const { t, locale } = useI18n();
const msg = useMessage();
@@ -779,7 +780,7 @@ const handleRegister = async () => {
}
};
const activeSidebarItem = ref<'profile' | 'applications' | 'feedback' | 'updates' | 'knowledge_base' | 'schedule_runs' | 'history'>('applications');
const activeSidebarItem = ref<'profile' | 'applications' | 'feedback' | 'updates' | 'knowledge_base' | 'schedule_runs' | 'shipping_notice' | 'history'>('applications');
const wsScheduleFilterInputClass = 'admin-table-filter-input text-xs py-1.5 px-2';
const isProfileLoading = ref(false);
const isProfileSaving = ref(false);
@@ -1040,6 +1041,10 @@ const navigateToScheduleRuns = () => {
loadWorkspaceScheduleRuns();
};
const navigateToShippingNotice = () => {
activeSidebarItem.value = 'shipping_notice';
};
const workspaceScheduleRuns = ref<ScheduleRun[]>([]);
const workspaceScheduleLoading = ref(false);
const wsScheduleStatusFilter = ref('all');
@@ -1385,7 +1390,7 @@ onMounted(async () => {
await fetchHome();
await handleWecomDeeplinkContext();
const viewParam = route.query.view as string;
const validViews: string[] = ['profile', 'applications', 'feedback', 'updates', 'knowledge_base', 'schedule_runs', 'history'];
const validViews: string[] = ['profile', 'applications', 'feedback', 'updates', 'knowledge_base', 'schedule_runs', 'shipping_notice', 'history'];
if (viewParam && validViews.includes(viewParam)) {
activeSidebarItem.value = viewParam as typeof activeSidebarItem.value;
if (viewParam === 'profile' && !profileUser.value.id) {
@@ -1626,6 +1631,14 @@ onBeforeUnmount(() => {
<Clock class="h-4 w-4" />
<span>{{ $t('workspace.nav.scheduleRuns') }}</span>
</button>
<button
@click="navigateToShippingNotice"
class="ws-nav-btn"
:class="{ 'ws-nav-btn--active': activeSidebarItem === 'shipping_notice' }"
>
<Package class="h-4 w-4" />
<span>{{ $t('workspace.nav.shippingNotice') }}</span>
</button>
<button
@click="openGeneralFeedback"
class="ws-nav-btn"
@@ -1998,6 +2011,10 @@ onBeforeUnmount(() => {
</div>
</template>
<template v-else-if="activeSidebarItem === 'shipping_notice'">
<ShippingNoticeView :embedded="true" />
</template>
<template v-else>
<div v-if="wecomEntryHint" class="rounded-2xl border border-blue-200 bg-blue-50 px-4 py-3 text-sm text-blue-700">
{{ wecomEntryHint }}