feat(shipping-notice,receipt-report): 新增收料报表功能并优化发货通知流程
清理废弃的shipping xfa ocr automark相关代码和job配置 新增收料报表管理的前端页面、路由和侧边栏入口 新增后端收料报表配置接口、数据库模型和RPA脚本 优化发货通知流程的重试策略,将shipping相关job默认不自动重试 移除废弃的库存源确认相关逻辑,更新流程门禁规则 重构订单模板的值适配器模块,新增坐标OCR值适配器 清理前端shipping菜单和action的废弃选项 更新相关文档和测试用例,调整.gitignore忽略规则
This commit is contained in:
1 parent
260465b72d
commit
1b6483a4ea
466 files changed
+32115
-33796
No files matched your search
@@ -0,0 +1,101 @@
|
||||
/**
|
||||
* features/workspace/pages/ReceiptReportFilesPage.spec.ts
|
||||
* 用途:验证收料归档页的接收人与管理员补偿权限边界。
|
||||
* 依赖:Vue Test Utils、Vue I18n、receipt-report.api、Workspace 上下文。
|
||||
* 逻辑:普通接收人只能下载获授权文件;管理员才会查询失败单元并看到重发/重试操作。
|
||||
*/
|
||||
|
||||
import { flushPromises, mount } from '@vue/test-utils';
|
||||
import { createI18n } from 'vue-i18n';
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import ReceiptReportFilesPage from './ReceiptReportFilesPage.vue';
|
||||
import { WORKSPACE_KEY } from '../composables/workspace.context';
|
||||
|
||||
const listWorkspaceReceiptReportFiles = vi.fn();
|
||||
const listFailedReceiptRpaUnits = vi.fn();
|
||||
const resendReceiptReportFile = vi.fn();
|
||||
|
||||
vi.mock('../api/receipt-report.api', () => ({
|
||||
listWorkspaceReceiptReportFiles: (...args: unknown[]) => listWorkspaceReceiptReportFiles(...args),
|
||||
listFailedReceiptRpaUnits: (...args: unknown[]) => listFailedReceiptRpaUnits(...args),
|
||||
receiptReportDownloadUrl: (id: number) => `/download/${id}`,
|
||||
resendReceiptReportFile: (...args: unknown[]) => resendReceiptReportFile(...args),
|
||||
retryReceiptRpaUnit: vi.fn(),
|
||||
}));
|
||||
|
||||
const i18n = createI18n({
|
||||
legacy: false,
|
||||
locale: 'en',
|
||||
messages: {
|
||||
en: {
|
||||
workspace: {
|
||||
receiptReports: {
|
||||
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(ReceiptReportFilesPage, {
|
||||
global: {
|
||||
plugins: [i18n],
|
||||
provide: { [WORKSPACE_KEY as symbol]: { currentUser: { role } } },
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
describe('ReceiptReportFilesPage permissions', () => {
|
||||
it('does not expose administrator compensation actions to a recipient', async () => {
|
||||
listWorkspaceReceiptReportFiles.mockResolvedValue({ items: [{
|
||||
id: 1, original_filename: 'receipt.xlsx', file_size: 12, sha256: 'a'.repeat(64),
|
||||
}] });
|
||||
listFailedReceiptRpaUnits.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(listFailedReceiptRpaUnits).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('shows failed-unit compensation only to an administrator', async () => {
|
||||
listWorkspaceReceiptReportFiles.mockResolvedValue({ items: [] });
|
||||
listFailedReceiptRpaUnits.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(listFailedReceiptRpaUnits).toHaveBeenCalledOnce();
|
||||
});
|
||||
|
||||
it('uses the notification resend action without creating another export', async () => {
|
||||
listWorkspaceReceiptReportFiles.mockResolvedValue({ items: [{
|
||||
id: 7, original_filename: 'receipt.xlsx', file_size: 12, sha256: 'b'.repeat(64),
|
||||
}] });
|
||||
listFailedReceiptRpaUnits.mockResolvedValue({ items: [] });
|
||||
resendReceiptReportFile.mockResolvedValue({});
|
||||
|
||||
const wrapper = mountPage('admin');
|
||||
await flushPromises();
|
||||
await wrapper.get('button:nth-of-type(2)').trigger('click');
|
||||
await flushPromises();
|
||||
|
||||
// 重发只调用归档文件的通知接口,不存在浏览器侧重新导出入口。
|
||||
expect(resendReceiptReportFile).toHaveBeenCalledWith(7);
|
||||
expect(wrapper.text()).not.toContain('Export');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,77 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* features/workspace/pages/ReceiptReportFilesPage.vue
|
||||
* 用途:向排程收件人展示可下载的收料原样归档文件。
|
||||
* 依赖:receipt-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 {
|
||||
listFailedReceiptRpaUnits, listWorkspaceReceiptReportFiles, receiptReportDownloadUrl,
|
||||
resendReceiptReportFile, retryReceiptRpaUnit, type ReceiptReportFile, type ReceiptRpaUnit,
|
||||
} from '../api/receipt-report.api';
|
||||
import { WORKSPACE_KEY } from '../composables/workspace.context';
|
||||
|
||||
const files = ref<ReceiptReportFile[]>([]);
|
||||
const failedUnits = ref<ReceiptRpaUnit[]>([]);
|
||||
const loading = ref(false);
|
||||
const { t } = useI18n();
|
||||
const ws = inject(WORKSPACE_KEY);
|
||||
const isAdmin = computed(() => String(ws?.currentUser?.role || '').trim().toLowerCase() === 'admin');
|
||||
|
||||
/** 读取当前用户的收料归档,不在前端补充或推断授权范围。 */
|
||||
async function loadFiles(): Promise<void> {
|
||||
loading.value = true;
|
||||
try {
|
||||
files.value = (await listWorkspaceReceiptReportFiles()).items;
|
||||
failedUnits.value = isAdmin.value ? (await listFailedReceiptRpaUnits()).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: ReceiptReportFile): void {
|
||||
window.location.assign(receiptReportDownloadUrl(file.id));
|
||||
}
|
||||
|
||||
/** 管理员重发已归档文件,不触发任何新的 RPA 导出。 */
|
||||
async function resendFile(file: ReceiptReportFile): Promise<void> {
|
||||
await resendReceiptReportFile(file.id);
|
||||
}
|
||||
|
||||
/** 管理员填写审计原因后才允许创建新的失败单元重试。 */
|
||||
async function retryUnit(unit: ReceiptRpaUnit): Promise<void> {
|
||||
const target = `${unit.source_code}${unit.warehouse_id ? ` / ${unit.warehouse_id}` : ''}`;
|
||||
const reason = window.prompt(t('workspace.receiptReports.retryReasonPrompt', { target }));
|
||||
if (!reason?.trim()) return;
|
||||
await retryReceiptRpaUnit(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.receiptReports.title') }}</h2><p class="mt-1 text-sm text-muted">{{ $t('workspace.receiptReports.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.receiptReports.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.receiptReports.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.receiptReports.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.receiptReports.file') }}</th><th class="px-4 py-3">{{ $t('workspace.receiptReports.site') }}</th><th class="px-4 py-3">{{ $t('workspace.receiptReports.warehouse') }}</th><th class="px-4 py-3">{{ $t('workspace.receiptReports.createdAt') }}</th><th class="px-4 py-3">{{ $t('workspace.receiptReports.expiresAt') }}</th><th class="px-4 py-3">{{ $t('workspace.receiptReports.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.receiptReports.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.receiptReports.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.receiptReports.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.receiptReports.retry') }}</button></td></tr></tbody></table></div></section>
|
||||
</section>
|
||||
</template>
|
||||
Reference in new issue
Block a user