feat: 添加MSW模拟服务和数据源集成
refactor: 重构页面组件移除冗余Layout组件 feat: 实现WebSocket和事件总线系统 feat: 添加队列和调度系统 docs: 更新架构文档和服务映射 style: 清理重复接口定义使用数据源 chore: 更新依赖项配置 feat: 添加运行时系统和领域引导 ci: 配置ESLint边界检查规则 build: 添加Redis和WebSocket依赖 test: 添加MSW浏览器环境入口 perf: 优化数据获取逻辑使用统一数据源 fix: 修复类型定义和状态管理问题
This commit is contained in:
101
dashboard/src/services/financeDataSource.ts
Normal file
101
dashboard/src/services/financeDataSource.ts
Normal file
@@ -0,0 +1,101 @@
|
||||
/**
|
||||
* [MOCK-FINANCE] Finance模块DataSource
|
||||
*/
|
||||
|
||||
export interface Transaction {
|
||||
id: string;
|
||||
type: 'income' | 'expense' | 'refund' | 'fee';
|
||||
amount: number;
|
||||
currency: string;
|
||||
category: string;
|
||||
description: string;
|
||||
orderId?: string;
|
||||
status: 'pending' | 'completed' | 'failed';
|
||||
createdAt: string;
|
||||
}
|
||||
|
||||
export interface ReconciliationRecord {
|
||||
id: string;
|
||||
platform: string;
|
||||
orderId: string;
|
||||
platformAmount: number;
|
||||
systemAmount: number;
|
||||
difference: number;
|
||||
status: 'matched' | 'mismatch' | 'pending';
|
||||
reconciledAt?: string;
|
||||
createdAt: string;
|
||||
}
|
||||
|
||||
export interface IFinanceDataSource {
|
||||
fetchTransactions(params?: { type?: string; startDate?: string; endDate?: string }): Promise<Transaction[]>;
|
||||
createTransaction(data: Partial<Transaction>): Promise<Transaction>;
|
||||
|
||||
fetchReconciliation(params?: { platform?: string; status?: string }): Promise<ReconciliationRecord[]>;
|
||||
reconcile(id: string, data: { action: 'approve' | 'reject'; note?: string }): Promise<ReconciliationRecord>;
|
||||
autoReconcile(platform: string): Promise<{ matched: number; mismatched: number }>;
|
||||
}
|
||||
|
||||
class MockFinanceDataSource implements IFinanceDataSource {
|
||||
async fetchTransactions(params?: { type?: string; startDate?: string; endDate?: string }): Promise<Transaction[]> {
|
||||
return [
|
||||
{ id: 'txn_001', type: 'income', amount: 1250.00, currency: 'USD', category: 'Sales', description: 'Order #ORD-001 payment', orderId: 'ORD-001', status: 'completed', createdAt: '2026-03-18 10:30:00' },
|
||||
{ id: 'txn_002', type: 'expense', amount: 45.50, currency: 'USD', category: 'Shipping', description: 'FedEx shipping fee', status: 'completed', createdAt: '2026-03-18 11:00:00' },
|
||||
{ id: 'txn_003', type: 'fee', amount: 187.50, currency: 'USD', category: 'Platform Fee', description: 'Amazon referral fee', orderId: 'ORD-001', status: 'completed', createdAt: '2026-03-18 10:35:00' },
|
||||
{ id: 'txn_004', type: 'refund', amount: 89.99, currency: 'USD', category: 'Refund', description: 'Customer return refund', orderId: 'ORD-002', status: 'pending', createdAt: '2026-03-18 14:00:00' },
|
||||
];
|
||||
}
|
||||
|
||||
async createTransaction(data: Partial<Transaction>): Promise<Transaction> {
|
||||
return { ...data, id: `txn_${Date.now()}`, createdAt: new Date().toISOString() } as Transaction;
|
||||
}
|
||||
|
||||
async fetchReconciliation(params?: { platform?: string; status?: string }): Promise<ReconciliationRecord[]> {
|
||||
return [
|
||||
{ id: 'rec_001', platform: 'AMAZON', orderId: 'ORD-001', platformAmount: 1250.00, systemAmount: 1250.00, difference: 0, status: 'matched', reconciledAt: '2026-03-18 12:00:00', createdAt: '2026-03-18 10:30:00' },
|
||||
{ id: 'rec_002', platform: 'AMAZON', orderId: 'ORD-002', platformAmount: 89.99, systemAmount: 85.99, difference: 4.00, status: 'mismatch', createdAt: '2026-03-18 11:00:00' },
|
||||
{ id: 'rec_003', platform: 'EBAY', orderId: 'ORD-003', platformAmount: 350.00, systemAmount: 350.00, difference: 0, status: 'pending', createdAt: '2026-03-18 14:00:00' },
|
||||
];
|
||||
}
|
||||
|
||||
async reconcile(id: string, data: { action: 'approve' | 'reject'; note?: string }): Promise<ReconciliationRecord> {
|
||||
return { id, platform: 'AMAZON', orderId: 'ORD-001', platformAmount: 1250, systemAmount: 1250, difference: 0, status: 'matched', reconciledAt: new Date().toISOString(), createdAt: new Date().toISOString() };
|
||||
}
|
||||
|
||||
async autoReconcile(platform: string): Promise<{ matched: number; mismatched: number }> {
|
||||
return { matched: 45, mismatched: 3 };
|
||||
}
|
||||
}
|
||||
|
||||
class ApiFinanceDataSource implements IFinanceDataSource {
|
||||
private baseUrl = '/api/finance';
|
||||
|
||||
async fetchTransactions(params?: { type?: string; startDate?: string; endDate?: string }): Promise<Transaction[]> {
|
||||
const query = new URLSearchParams(params as any).toString();
|
||||
const res = await fetch(`${this.baseUrl}/transactions?${query}`);
|
||||
return res.json();
|
||||
}
|
||||
|
||||
async createTransaction(data: Partial<Transaction>): Promise<Transaction> {
|
||||
const res = await fetch(`${this.baseUrl}/transactions`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(data) });
|
||||
return res.json();
|
||||
}
|
||||
|
||||
async fetchReconciliation(params?: { platform?: string; status?: string }): Promise<ReconciliationRecord[]> {
|
||||
const query = new URLSearchParams(params as any).toString();
|
||||
const res = await fetch(`${this.baseUrl}/reconciliation?${query}`);
|
||||
return res.json();
|
||||
}
|
||||
|
||||
async reconcile(id: string, data: { action: 'approve' | 'reject'; note?: string }): Promise<ReconciliationRecord> {
|
||||
const res = await fetch(`${this.baseUrl}/reconciliation/${id}`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(data) });
|
||||
return res.json();
|
||||
}
|
||||
|
||||
async autoReconcile(platform: string): Promise<{ matched: number; mismatched: number }> {
|
||||
const res = await fetch(`${this.baseUrl}/reconciliation/auto`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ platform }) });
|
||||
return res.json();
|
||||
}
|
||||
}
|
||||
|
||||
const useMock = process.env.REACT_APP_USE_MOCK === 'true';
|
||||
export const financeDataSource: IFinanceDataSource = useMock ? new MockFinanceDataSource() : new ApiFinanceDataSource();
|
||||
Reference in New Issue
Block a user