Files
makemd/server/src/api/controllers/ReportController.ts
wurenzhi b31591e04c feat: 实现多商户管理模块与前端服务
refactor: 优化服务层代码并修复类型问题

docs: 更新开发进度文档

feat(merchant): 新增商户监控与数据统计服务

feat(dashboard): 添加商户管理前端页面与服务

fix: 修复类型转换与可选参数处理

feat: 实现商户订单、店铺与结算管理功能

refactor: 重构审计日志格式与服务调用

feat: 新增商户入驻与身份注册功能

fix(controller): 修复路由参数类型问题

feat: 添加商户排名与统计报告功能

chore: 更新模拟数据与服务配置
2026-03-18 13:38:05 +08:00

62 lines
2.2 KiB
TypeScript

import { Request, Response } from 'express';
import { ReportService, ReportType } from '../../domains/Analytics/ReportService';
import { AnalyticsService } from '../../domains/Analytics/AnalyticsService';
import { OrderProfitService } from '../../domains/Finance/OrderProfitService';
import { logger } from '../../utils/logger';
export class ReportController {
/**
* [FE_FIN_01] 获取实时 P&L 穿透分析数据 (Profit Breakdown)
*/
static async getProfitBreakdown(req: Request, res: Response) {
try {
const { tenantId } = (req as any).traceContext || req.query;
if (!tenantId) return res.status(400).json({ success: false, error: 'tenantId is required' });
const breakdown = await OrderProfitService.getGlobalProfitBreakdown(tenantId as string);
res.json({ success: true, data: breakdown });
} catch (err: any) {
res.status(500).json({ success: false, error: err.message });
}
}
/**
* [CORE_GOV_03] 下钻到具体订单或套利任务的明细 (Traceability)
*/
static async getDetailedEvidence(req: Request, res: Response) {
const { traceId } = req.params;
if (!traceId) {
return res.status(400).json({ success: false, error: 'traceId is required' });
}
try {
const data = await AnalyticsService.getDetailedEvidence(traceId as string);
return res.json({ success: true, data });
} catch (err: any) {
logger.error(`[ReportController] Get evidence failed: ${err.message}`);
return res.status(500).json({ success: false, error: 'Internal server error' });
}
}
/**
* 获取多维报表数据
*/
static async getReport(req: Request, res: Response) {
const tenantId = req.headers['x-tenant-id'] as string;
const { type } = req.params;
const filters = req.query;
if (!tenantId || !type) {
return res.status(400).json({ success: false, error: 'tenantId and report type are required' });
}
try {
const data = await ReportService.getReportData(tenantId, type as ReportType, filters);
return res.json({ success: true, data });
} catch (err: any) {
logger.error(`[ReportController] Get report failed: ${err.message}`);
return res.status(500).json({ success: false, error: 'Internal server error' });
}
}
}