dashboard.controller.ts 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /**
  2. * 数据看板与经营复盘模块 — 控制器层
  3. *
  4. * 对应规范文档 §十一「模块 8:数据看板与经营复盘模块」
  5. */
  6. import type { Request, Response } from 'express';
  7. import { sendSuccess } from '../../../../shared/http/response.js';
  8. import {
  9. getOverviewDashboard,
  10. getCommunityDashboard,
  11. getStoreDashboard,
  12. getActivityIndex,
  13. getActivityRanking,
  14. generatePeriodicReport,
  15. } from '../services/dashboard.service.js';
  16. /** GET /api/dashboard/overview — 总览看板(§11.1) */
  17. export async function overview(_req: Request, res: Response): Promise<void> {
  18. try {
  19. const data = getOverviewDashboard();
  20. sendSuccess(res, data);
  21. } catch (error) {
  22. throw error;
  23. }
  24. }
  25. /** GET /api/dashboard/community/:communityId — 小区看板(§11.2) */
  26. export async function communityDashboard(req: Request, res: Response): Promise<void> {
  27. try {
  28. const communityId = Number(req.params.communityId);
  29. const data = getCommunityDashboard(communityId);
  30. sendSuccess(res, data);
  31. } catch (error) {
  32. throw error;
  33. }
  34. }
  35. /** GET /api/dashboard/store/:storeId — 门店看板(§11.3) */
  36. export async function storeDashboard(req: Request, res: Response): Promise<void> {
  37. try {
  38. const storeId = Number(req.params.storeId);
  39. const data = getStoreDashboard(storeId);
  40. sendSuccess(res, data);
  41. } catch (error) {
  42. throw error;
  43. }
  44. }
  45. /** GET /api/dashboard/activity/:roomId — 群活跃度指数(§11.4) */
  46. export async function activityIndex(req: Request, res: Response): Promise<void> {
  47. try {
  48. const roomId = String(req.params.roomId);
  49. const data = getActivityIndex(roomId);
  50. sendSuccess(res, data);
  51. } catch (error) {
  52. throw error;
  53. }
  54. }
  55. /** GET /api/dashboard/activity-ranking — 群活跃度排行榜 */
  56. export async function activityRanking(req: Request, res: Response): Promise<void> {
  57. try {
  58. const limit = typeof req.query.limit === 'string' ? Number(req.query.limit) : 20;
  59. const data = getActivityRanking(limit);
  60. sendSuccess(res, data);
  61. } catch (error) {
  62. throw error;
  63. }
  64. }
  65. /** GET /api/dashboard/reports/weekly — 周报(§11.9) */
  66. export async function weeklyReport(_req: Request, res: Response): Promise<void> {
  67. try {
  68. const data = generatePeriodicReport('weekly');
  69. sendSuccess(res, data);
  70. } catch (error) {
  71. throw error;
  72. }
  73. }
  74. /** GET /api/dashboard/reports/monthly — 月报(§11.9) */
  75. export async function monthlyReport(_req: Request, res: Response): Promise<void> {
  76. try {
  77. const data = generatePeriodicReport('monthly');
  78. sendSuccess(res, data);
  79. } catch (error) {
  80. throw error;
  81. }
  82. }