/** * 数据看板与经营复盘模块 — 控制器层 * * 对应规范文档 §十一「模块 8:数据看板与经营复盘模块」 */ import type { Request, Response } from 'express'; import { sendSuccess } from '../../../../shared/http/response.js'; import { getOverviewDashboard, getCommunityDashboard, getStoreDashboard, getActivityIndex, getActivityRanking, generatePeriodicReport, } from '../services/dashboard.service.js'; /** GET /api/dashboard/overview — 总览看板(§11.1) */ export async function overview(_req: Request, res: Response): Promise { try { const data = getOverviewDashboard(); sendSuccess(res, data); } catch (error) { throw error; } } /** GET /api/dashboard/community/:communityId — 小区看板(§11.2) */ export async function communityDashboard(req: Request, res: Response): Promise { try { const communityId = Number(req.params.communityId); const data = getCommunityDashboard(communityId); sendSuccess(res, data); } catch (error) { throw error; } } /** GET /api/dashboard/store/:storeId — 门店看板(§11.3) */ export async function storeDashboard(req: Request, res: Response): Promise { try { const storeId = Number(req.params.storeId); const data = getStoreDashboard(storeId); sendSuccess(res, data); } catch (error) { throw error; } } /** GET /api/dashboard/activity/:roomId — 群活跃度指数(§11.4) */ export async function activityIndex(req: Request, res: Response): Promise { try { const roomId = String(req.params.roomId); const data = getActivityIndex(roomId); sendSuccess(res, data); } catch (error) { throw error; } } /** GET /api/dashboard/activity-ranking — 群活跃度排行榜 */ export async function activityRanking(req: Request, res: Response): Promise { try { const limit = typeof req.query.limit === 'string' ? Number(req.query.limit) : 20; const data = getActivityRanking(limit); sendSuccess(res, data); } catch (error) { throw error; } } /** GET /api/dashboard/reports/weekly — 周报(§11.9) */ export async function weeklyReport(_req: Request, res: Response): Promise { try { const data = generatePeriodicReport('weekly'); sendSuccess(res, data); } catch (error) { throw error; } } /** GET /api/dashboard/reports/monthly — 月报(§11.9) */ export async function monthlyReport(_req: Request, res: Response): Promise { try { const data = generatePeriodicReport('monthly'); sendSuccess(res, data); } catch (error) { throw error; } }