feat(freight-rpa): 增加出站报表配置与回调支持,重构相关服务
- 将 RPA 管理 API 扩展至出站报表配置,新增出站相关的回调接口。 - 重构 freight_rpa_report_config_service,支持入站与出站报表配置的管理。 - 更新 ORM 模型,增加出站报表相关的持久化模型。 - 统一命名规范,确保在手、入站与出站的概念一致性。
This commit is contained in:
1 parent
39fe3c05f2
commit
911afa0f73
152 files changed
+9861
-2984
No files matched your search
@@ -1,24 +0,0 @@
|
||||
/**
|
||||
* features/workspace/api/inbound-report.api.spec.ts
|
||||
* 用途:锁定收料报表列表与下载地址的工作台契约。
|
||||
* 依赖:inbound-report.api、vitest。
|
||||
* 逻辑:普通接收人只能经工作台受控下载,不拼接对象存储地址。
|
||||
*/
|
||||
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import {
|
||||
listFailedInboundRpaUnits, inboundReportDownloadUrl, resendInboundReportFile, retryInboundRpaUnit,
|
||||
} from './inbound-report.api';
|
||||
|
||||
describe('inboundReportDownloadUrl', () => {
|
||||
it('uses the workspace authorization endpoint instead of an object storage URL', () => {
|
||||
// 关键断言:浏览器只能使用后端鉴权下载代理,不能得到 MinIO bucket/key。
|
||||
expect(inboundReportDownloadUrl(42)).toBe('/api/workspace/inbound-report-files/42/download');
|
||||
});
|
||||
|
||||
it('keeps manual compensation routes in the admin namespace', () => {
|
||||
expect(String(listFailedInboundRpaUnits)).toContain('inbound-rpa-units?status=failed');
|
||||
expect(String(retryInboundRpaUnit)).toContain('/api/admin/inbound-rpa-units/');
|
||||
expect(String(resendInboundReportFile)).toContain('/api/admin/inbound-report-files/');
|
||||
});
|
||||
});
|
||||
@@ -1,71 +0,0 @@
|
||||
/**
|
||||
* features/workspace/api/inbound-report.api.ts
|
||||
* 用途:工作台收料归档列表与受控下载 API。
|
||||
* 依赖:requestJson、getAuthHeaders。
|
||||
* 逻辑:列表由服务端按当前接收人/管理员授权裁剪;下载始终经过工作台鉴权代理。
|
||||
*/
|
||||
|
||||
import { requestJson } from '@/shared/api/client';
|
||||
import { getAuthHeaders } from '@/shared/utils/auth';
|
||||
|
||||
export type InboundReportFile = {
|
||||
id: number;
|
||||
original_filename: string;
|
||||
content_type?: string | null;
|
||||
file_size: number;
|
||||
sha256: string;
|
||||
source_code?: string | null;
|
||||
warehouse_id?: string | null;
|
||||
schedule_run_no?: string | null;
|
||||
archive_expires_at?: string | null;
|
||||
created_at?: string | null;
|
||||
download_url: string;
|
||||
};
|
||||
|
||||
export type InboundRpaUnit = {
|
||||
id: number;
|
||||
source_code: string;
|
||||
warehouse_id?: string | null;
|
||||
status: string;
|
||||
error_code?: string | null;
|
||||
error_message?: string | null;
|
||||
retry_of_id?: number | null;
|
||||
schedule_run_id: number;
|
||||
created_at?: string | null;
|
||||
finished_at?: string | null;
|
||||
};
|
||||
|
||||
/**
|
||||
* 读取当前用户有权查看的收料原文件列表。
|
||||
* 核心逻辑:不接收 user_id 或对象存储参数,服务端以当前会话和排程接收人关系授权。
|
||||
* @returns 脱敏归档元数据和受控下载地址。
|
||||
*/
|
||||
export const listWorkspaceInboundReportFiles = (limit = 100) => requestJson<{ items: InboundReportFile[] }>(
|
||||
`/api/workspace/inbound-report-files?limit=${encodeURIComponent(String(limit))}`,
|
||||
{ headers: getAuthHeaders() },
|
||||
);
|
||||
|
||||
/**
|
||||
* 返回一个收料文件的受控下载地址。
|
||||
* 核心逻辑:禁止把 MinIO bucket 或 object key 暴露到浏览器。
|
||||
* @param fileId - 收料归档文件主键。
|
||||
* @returns 由后端再次校验接收人权限的下载路径。
|
||||
*/
|
||||
export const inboundReportDownloadUrl = (fileId: number) => `/api/workspace/inbound-report-files/${encodeURIComponent(String(fileId))}/download`;
|
||||
|
||||
/** 管理员读取失败收料单元;普通用户不调用此管理端接口。 */
|
||||
export const listFailedInboundRpaUnits = () => requestJson<{ items: InboundRpaUnit[] }>(
|
||||
'/api/admin/inbound-rpa-units?status=failed&limit=100', { headers: getAuthHeaders() },
|
||||
);
|
||||
|
||||
/** 管理员以必填原因新建失败单元的独立人工重试事实。 */
|
||||
export const retryInboundRpaUnit = (unitId: number, reason: string) => requestJson<unknown>(
|
||||
`/api/admin/inbound-rpa-units/${encodeURIComponent(String(unitId))}/retry`,
|
||||
{ method: 'POST', headers: { ...getAuthHeaders(), 'Content-Type': 'application/json' }, body: JSON.stringify({ reason }) },
|
||||
);
|
||||
|
||||
/** 管理员仅重发已归档文件的企微消息,不会重新导出。 */
|
||||
export const resendInboundReportFile = (fileId: number) => requestJson<unknown>(
|
||||
`/api/admin/inbound-report-files/${encodeURIComponent(String(fileId))}/resend`,
|
||||
{ method: 'POST', headers: getAuthHeaders() },
|
||||
);
|
||||
@@ -41,7 +41,6 @@ const i18n = createI18n({
|
||||
admin: '管理控制台',
|
||||
applications: '应用管理',
|
||||
scheduleRuns: '排程记录',
|
||||
inboundReports: '收料文件',
|
||||
shippingNotice: '货代发货',
|
||||
shippingCustomers: '客户主数据',
|
||||
shippingMyTasks: '我的待办',
|
||||
@@ -68,7 +67,6 @@ async function mountSidebar(user: { role: string; is_platform_admin?: boolean })
|
||||
{ path: WORKSPACE_PATHS.applications, name: 'workspace-applications', component: { template: '<div />' } },
|
||||
{ path: WORKSPACE_PATHS.profile, name: 'workspace-profile', component: { template: '<div />' } },
|
||||
{ path: WORKSPACE_PATHS.scheduleRuns, name: 'workspace-schedule-runs', component: { template: '<div />' } },
|
||||
{ path: WORKSPACE_PATHS.inboundReports, name: 'workspace-inbound-reports', component: { template: '<div />' } },
|
||||
{ path: WORKSPACE_PATHS.feedback, name: 'workspace-feedback', component: { template: '<div />' } },
|
||||
{ path: WORKSPACE_PATHS.updates, name: 'workspace-updates', component: { template: '<div />' } },
|
||||
{ path: WORKSPACE_PATHS.shippingNoticeCustomers, name: 'workspace-shipping-customers', component: { template: '<div />' } },
|
||||
|
||||
@@ -10,7 +10,7 @@ import { computed, inject, onBeforeUnmount, onMounted, ref, watch } from 'vue';
|
||||
import { useRoute } from 'vue-router';
|
||||
import {
|
||||
LayoutGrid, Bot, FileText, User, LogOut, Edit, Megaphone, Clock, Package, PanelLeftClose, PanelLeftOpen,
|
||||
ChevronDown, ChevronRight, ContactRound, Inbox, FileDown, Settings,
|
||||
ChevronDown, ChevronRight, ContactRound, Inbox, Settings,
|
||||
} from 'lucide-vue-next';
|
||||
import { WORKSPACE_PATHS } from '../constants/routes';
|
||||
import { WORKSPACE_KEY } from '../composables/workspace.context';
|
||||
@@ -33,7 +33,6 @@ const primaryLinkItems = [
|
||||
{ path: WORKSPACE_PATHS.profile, labelKey: 'workspace.nav.profile', icon: User, match: ['workspace-profile'] },
|
||||
{ path: WORKSPACE_PATHS.applications, labelKey: 'workspace.nav.applications', icon: LayoutGrid, match: ['workspace-applications'] },
|
||||
{ path: WORKSPACE_PATHS.scheduleRuns, labelKey: 'workspace.nav.scheduleRuns', icon: Clock, match: ['workspace-schedule-runs'] },
|
||||
{ path: WORKSPACE_PATHS.inboundReports, labelKey: 'workspace.nav.inboundReports', icon: FileDown, match: ['workspace-inbound-reports'] },
|
||||
] as const;
|
||||
|
||||
const secondaryLinkItems = [
|
||||
|
||||
@@ -21,7 +21,6 @@ const ROUTE_NAME_TO_SIDEBAR: Record<string, WorkspaceSidebarItem> = {
|
||||
'workspace-knowledge-base': 'knowledge_base',
|
||||
'workspace-knowledge-base-group': 'knowledge_base',
|
||||
'workspace-schedule-runs': 'schedule_runs',
|
||||
'workspace-inbound-reports': 'receipt_reports',
|
||||
'workspace-shipping-customers': 'shipping_notice',
|
||||
'workspace-shipping-tasks': 'shipping_notice',
|
||||
'workspace-shipping-my-tasks': 'shipping_notice',
|
||||
|
||||
@@ -11,7 +11,6 @@ export const WORKSPACE_PATHS = {
|
||||
updates: '/workspace/updates',
|
||||
knowledgeBase: '/workspace/knowledge-base',
|
||||
scheduleRuns: '/workspace/schedule-runs',
|
||||
inboundReports: '/workspace/inbound-reports',
|
||||
shippingNotice: '/workspace/shipping-notice/my-tasks',
|
||||
shippingNoticeCustomers: '/workspace/shipping-notice/customers',
|
||||
shippingNoticeTasks: '/workspace/shipping-notice/tasks',
|
||||
@@ -35,7 +34,6 @@ export const LEGACY_VIEW_TO_PATH: Record<string, string> = {
|
||||
updates: WORKSPACE_PATHS.updates,
|
||||
knowledge_base: WORKSPACE_PATHS.knowledgeBase,
|
||||
schedule_runs: WORKSPACE_PATHS.scheduleRuns,
|
||||
receipt_reports: WORKSPACE_PATHS.inboundReports,
|
||||
shipping_notice: WORKSPACE_PATHS.shippingNotice,
|
||||
accounting_voucher_check: WORKSPACE_PATHS.accountingVoucherCheck,
|
||||
contract_payment: WORKSPACE_PATHS.contractPayment,
|
||||
|
||||
@@ -1,101 +0,0 @@
|
||||
/**
|
||||
* features/workspace/pages/InboundReportFilesPage.spec.ts
|
||||
* 用途:验证收料归档页的接收人与管理员补偿权限边界。
|
||||
* 依赖:Vue Test Utils、Vue I18n、inbound-report.api、Workspace 上下文。
|
||||
* 逻辑:普通接收人只能下载获授权文件;管理员才会查询失败单元并看到重发/重试操作。
|
||||
*/
|
||||
|
||||
import { flushPromises, mount } from '@vue/test-utils';
|
||||
import { createI18n } from 'vue-i18n';
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import InboundReportFilesPage from './InboundReportFilesPage.vue';
|
||||
import { WORKSPACE_KEY } from '../composables/workspace.context';
|
||||
|
||||
const listWorkspaceInboundReportFiles = vi.fn();
|
||||
const listFailedInboundRpaUnits = vi.fn();
|
||||
const resendInboundReportFile = vi.fn();
|
||||
|
||||
vi.mock('../api/inbound-report.api', () => ({
|
||||
listWorkspaceInboundReportFiles: (...args: unknown[]) => listWorkspaceInboundReportFiles(...args),
|
||||
listFailedInboundRpaUnits: (...args: unknown[]) => listFailedInboundRpaUnits(...args),
|
||||
inboundReportDownloadUrl: (id: number) => `/download/${id}`,
|
||||
resendInboundReportFile: (...args: unknown[]) => resendInboundReportFile(...args),
|
||||
retryInboundRpaUnit: vi.fn(),
|
||||
}));
|
||||
|
||||
const i18n = createI18n({
|
||||
legacy: false,
|
||||
locale: 'en',
|
||||
messages: {
|
||||
en: {
|
||||
workspace: {
|
||||
inboundReports: {
|
||||
title: 'Receipt Files', hint: 'hint', refresh: 'Refresh', loading: 'Loading', empty: 'Empty',
|
||||
file: 'File', site: 'Site', warehouse: 'Warehouse', createdAt: 'Created', expiresAt: 'Expires',
|
||||
action: 'Action', download: 'Download', resend: 'Resend to WeCom', failedUnits: 'Failed receipt units',
|
||||
retry: 'Retry with reason', retryReasonPrompt: 'Reason {target}',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
function mountPage(role: string) {
|
||||
return mount(InboundReportFilesPage, {
|
||||
global: {
|
||||
plugins: [i18n],
|
||||
provide: { [WORKSPACE_KEY as symbol]: { currentUser: { role } } },
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
describe('InboundReportFilesPage permissions', () => {
|
||||
it('does not expose administrator compensation actions to a recipient', async () => {
|
||||
listWorkspaceInboundReportFiles.mockResolvedValue({ items: [{
|
||||
id: 1, original_filename: 'receipt.xlsx', file_size: 12, sha256: 'a'.repeat(64),
|
||||
}] });
|
||||
listFailedInboundRpaUnits.mockResolvedValue({ items: [{ id: 9, source_code: 'DBS-A', status: 'failed' }] });
|
||||
|
||||
const wrapper = mountPage('user');
|
||||
await flushPromises();
|
||||
|
||||
// 普通接收人只能看到下载,前端也不得请求管理员失败单元接口。
|
||||
expect(wrapper.text()).toContain('Download');
|
||||
expect(wrapper.text()).not.toContain('Resend to WeCom');
|
||||
expect(wrapper.text()).not.toContain('Failed receipt units');
|
||||
expect(listFailedInboundRpaUnits).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('shows failed-unit compensation only to an administrator', async () => {
|
||||
listWorkspaceInboundReportFiles.mockResolvedValue({ items: [] });
|
||||
listFailedInboundRpaUnits.mockResolvedValue({ items: [{
|
||||
id: 9, source_code: 'DBS-A', warehouse_id: 'WH-01', status: 'failed', error_code: 'RPA.TIMEOUT',
|
||||
}] });
|
||||
|
||||
const wrapper = mountPage('admin');
|
||||
await flushPromises();
|
||||
|
||||
// 即使没有成功文件,管理员仍能看到独立失败单元并开始带原因的补偿。
|
||||
expect(wrapper.text()).toContain('Failed receipt units');
|
||||
expect(wrapper.text()).toContain('DBS-A / WH-01');
|
||||
expect(wrapper.text()).toContain('Retry with reason');
|
||||
expect(listFailedInboundRpaUnits).toHaveBeenCalledOnce();
|
||||
});
|
||||
|
||||
it('uses the notification resend action without creating another export', async () => {
|
||||
listWorkspaceInboundReportFiles.mockResolvedValue({ items: [{
|
||||
id: 7, original_filename: 'receipt.xlsx', file_size: 12, sha256: 'b'.repeat(64),
|
||||
}] });
|
||||
listFailedInboundRpaUnits.mockResolvedValue({ items: [] });
|
||||
resendInboundReportFile.mockResolvedValue({});
|
||||
|
||||
const wrapper = mountPage('admin');
|
||||
await flushPromises();
|
||||
await wrapper.get('button:nth-of-type(2)').trigger('click');
|
||||
await flushPromises();
|
||||
|
||||
// 重发只调用归档文件的通知接口,不存在浏览器侧重新导出入口。
|
||||
expect(resendInboundReportFile).toHaveBeenCalledWith(7);
|
||||
expect(wrapper.text()).not.toContain('Export');
|
||||
});
|
||||
});
|
||||
@@ -1,78 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* features/workspace/pages/InboundReportFilesPage.vue
|
||||
* 用途:向排程收件人展示可下载的收料原样归档文件。
|
||||
* 依赖:inbound-report.api、Vue I18n、Lucide。
|
||||
* 逻辑:文件列表始终由服务端按收件人授权裁剪;浏览器只请求受控下载地址。
|
||||
*/
|
||||
import { computed, inject, onMounted, ref } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { Download, RefreshCw } from 'lucide-vue-next';
|
||||
import {
|
||||
listFailedInboundRpaUnits, listWorkspaceInboundReportFiles, inboundReportDownloadUrl,
|
||||
resendInboundReportFile, retryInboundRpaUnit, type InboundReportFile, type InboundRpaUnit,
|
||||
} from '../api/inbound-report.api';
|
||||
import { WORKSPACE_KEY } from '../composables/workspace.context';
|
||||
import { isPlatformAdminUser } from '@/shared/utils/auth';
|
||||
|
||||
const files = ref<InboundReportFile[]>([]);
|
||||
const failedUnits = ref<InboundRpaUnit[]>([]);
|
||||
const loading = ref(false);
|
||||
const { t } = useI18n();
|
||||
const ws = inject(WORKSPACE_KEY);
|
||||
const isAdmin = computed(() => isPlatformAdminUser(ws?.currentUser));
|
||||
|
||||
/** 读取当前用户的收料归档,不在前端补充或推断授权范围。 */
|
||||
async function loadFiles(): Promise<void> {
|
||||
loading.value = true;
|
||||
try {
|
||||
files.value = (await listWorkspaceInboundReportFiles()).items;
|
||||
failedUnits.value = isAdmin.value ? (await listFailedInboundRpaUnits()).items : [];
|
||||
} catch {
|
||||
files.value = [];
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
/** 将 ISO 时间格式化为当前浏览器时区的简短可读值。 */
|
||||
function formatDate(value?: string | null): string {
|
||||
if (!value) return '-';
|
||||
const date = new Date(value);
|
||||
return Number.isNaN(date.getTime()) ? value : date.toLocaleString();
|
||||
}
|
||||
|
||||
/** 统一从后端受控下载入口获取文件,下载时服务端会再次做权限审计。 */
|
||||
function downloadFile(file: InboundReportFile): void {
|
||||
window.location.assign(inboundReportDownloadUrl(file.id));
|
||||
}
|
||||
|
||||
/** 管理员重发已归档文件,不触发任何新的 RPA 导出。 */
|
||||
async function resendFile(file: InboundReportFile): Promise<void> {
|
||||
await resendInboundReportFile(file.id);
|
||||
}
|
||||
|
||||
/** 管理员填写审计原因后才允许创建新的失败单元重试。 */
|
||||
async function retryUnit(unit: InboundRpaUnit): Promise<void> {
|
||||
const target = `${unit.source_code}${unit.warehouse_id ? ` / ${unit.warehouse_id}` : ''}`;
|
||||
const reason = window.prompt(t('workspace.inboundReports.retryReasonPrompt', { target }));
|
||||
if (!reason?.trim()) return;
|
||||
await retryInboundRpaUnit(unit.id, reason.trim());
|
||||
await loadFiles();
|
||||
}
|
||||
|
||||
onMounted(() => { void loadFiles(); });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section class="space-y-5 animate-fade-in-up">
|
||||
<header class="flex items-center justify-between gap-3">
|
||||
<div><h2 class="text-2xl font-bold text-primary">{{ $t('workspace.inboundReports.title') }}</h2><p class="mt-1 text-sm text-muted">{{ $t('workspace.inboundReports.hint') }}</p></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 hover:bg-surface-soft" :disabled="loading" @click="loadFiles"><RefreshCw class="h-3.5 w-3.5" />{{ $t('workspace.inboundReports.refresh') }}</button>
|
||||
</header>
|
||||
<div v-if="loading" class="rounded-2xl border border-dashed border-default py-10 text-center text-sm text-muted">{{ $t('workspace.inboundReports.loading') }}</div>
|
||||
<div v-else-if="!files.length" class="rounded-2xl border border-dashed border-default py-10 text-center text-sm text-muted">{{ $t('workspace.inboundReports.empty') }}</div>
|
||||
<div v-else class="overflow-hidden rounded-2xl border border-default bg-surface"><div class="overflow-auto"><table class="w-full min-w-[860px] text-sm"><thead class="border-b border-subtle bg-surface-soft text-left text-secondary"><tr><th class="px-4 py-3">{{ $t('workspace.inboundReports.file') }}</th><th class="px-4 py-3">{{ $t('workspace.inboundReports.site') }}</th><th class="px-4 py-3">{{ $t('workspace.inboundReports.warehouse') }}</th><th class="px-4 py-3">{{ $t('workspace.inboundReports.createdAt') }}</th><th class="px-4 py-3">{{ $t('workspace.inboundReports.expiresAt') }}</th><th class="px-4 py-3">{{ $t('workspace.inboundReports.action') }}</th></tr></thead><tbody><tr v-for="file in files" :key="file.id" class="border-b border-subtle last:border-0"><td class="px-4 py-3 font-medium text-primary">{{ file.original_filename }}</td><td class="px-4 py-3 text-muted">{{ file.source_code || '-' }}</td><td class="px-4 py-3 text-muted">{{ file.warehouse_id || '-' }}</td><td class="px-4 py-3 text-muted">{{ formatDate(file.created_at) }}</td><td class="px-4 py-3 text-muted">{{ formatDate(file.archive_expires_at) }}</td><td class="px-4 py-3"><button type="button" class="inline-flex items-center gap-1 rounded-lg border border-default px-2 py-1 text-xs font-medium text-secondary hover:bg-surface-soft" @click="downloadFile(file)"><Download class="h-3 w-3" />{{ $t('workspace.inboundReports.download') }}</button><button v-if="isAdmin" type="button" class="ml-2 inline-flex rounded-lg border border-default px-2 py-1 text-xs font-medium text-secondary hover:bg-surface-soft" @click="resendFile(file)">{{ $t('workspace.inboundReports.resend') }}</button></td></tr></tbody></table></div></div>
|
||||
<section v-if="isAdmin && failedUnits.length" class="overflow-hidden rounded-2xl border border-amber-200 bg-amber-50/40"><header class="border-b border-amber-200 px-4 py-3 text-sm font-semibold text-primary">{{ $t('workspace.inboundReports.failedUnits') }}</header><div class="overflow-auto"><table class="w-full min-w-[720px] text-sm"><tbody><tr v-for="unit in failedUnits" :key="unit.id" class="border-b border-amber-100 last:border-0"><td class="px-4 py-3 font-medium">{{ unit.source_code }}<span v-if="unit.warehouse_id"> / {{ unit.warehouse_id }}</span></td><td class="px-4 py-3 text-muted">{{ unit.error_code || unit.error_message || '-' }}</td><td class="px-4 py-3"><button type="button" class="rounded-lg border border-amber-300 px-2 py-1 text-xs font-medium text-amber-800 hover:bg-amber-100" @click="retryUnit(unit)">{{ $t('workspace.inboundReports.retry') }}</button></td></tr></tbody></table></div></section>
|
||||
</section>
|
||||
</template>
|
||||
@@ -24,7 +24,6 @@ export type WorkspaceSidebarItem =
|
||||
| 'updates'
|
||||
| 'knowledge_base'
|
||||
| 'schedule_runs'
|
||||
| 'receipt_reports'
|
||||
| 'shipping_notice'
|
||||
| 'history';
|
||||
|
||||
|
||||
Reference in new issue
Block a user