Jelajahi Sumber

优化统计页面

guoziyun 8 bulan lalu
induk
melakukan
abcc56c5cf

+ 24 - 0
oms/dist/src/controllers/messageRecordController.js

@@ -126,11 +126,13 @@ class MessageRecordController {
          */
         this.getOverallStatistics = async (req, res) => {
             try {
+                console.time("getOverallStatistics");
                 const { startDate, endDate, strategyName } = req.query;
                 const start = startDate ? new Date(startDate) : undefined;
                 const end = endDate ? new Date(endDate) : undefined;
                 const stratName = strategyName ? strategyName : undefined;
                 const stats = await this.messageRecordService.getOverallStatistics(start, end, stratName);
+                console.timeEnd("getOverallStatistics");
                 return res.status(200).json({ success: true, data: stats });
             }
             catch (error) {
@@ -146,10 +148,12 @@ class MessageRecordController {
          */
         this.getStatisticsByActivity = async (req, res) => {
             try {
+                console.time("getStatisticsByActivity");
                 const { startDate, endDate } = req.query;
                 const start = startDate ? new Date(startDate) : undefined;
                 const end = endDate ? new Date(endDate) : undefined;
                 const stats = await this.messageRecordService.getStatisticsByActivity(start, end);
+                console.timeEnd("getStatisticsByActivity");
                 return res.status(200).json({ success: true, data: stats });
             }
             catch (error) {
@@ -165,11 +169,13 @@ class MessageRecordController {
          */
         this.getStatisticsByStrategy = async (req, res) => {
             try {
+                console.time("getStatisticsByStrategy");
                 const { startDate, endDate, strategyName } = req.query;
                 const start = startDate ? new Date(startDate) : undefined;
                 const end = endDate ? new Date(endDate) : undefined;
                 const stratName = strategyName ? strategyName : undefined;
                 const stats = await this.messageRecordService.getStatisticsByStrategy(start, end, stratName);
+                console.timeEnd("getStatisticsByStrategy");
                 return res.status(200).json({ success: true, data: stats });
             }
             catch (error) {
@@ -185,12 +191,14 @@ class MessageRecordController {
          */
         this.getStatisticsByTemplate = async (req, res) => {
             try {
+                console.time("getStatisticsByTemplate");
                 // 从查询参数中获取 startDate, endDate 和 strategyName
                 const { startDate, endDate, strategyName } = req.query;
                 const start = startDate ? new Date(startDate) : undefined;
                 const end = endDate ? new Date(endDate) : undefined;
                 const stratName = strategyName ? strategyName : undefined;
                 const stats = await this.messageRecordService.getStatisticsByTemplate(start, end, stratName);
+                console.timeEnd("getStatisticsByTemplate");
                 return res.status(200).json({ success: true, data: stats });
             }
             catch (error) {
@@ -206,12 +214,14 @@ class MessageRecordController {
          */
         this.getStatisticsByCc = async (req, res) => {
             try {
+                console.time("getStatisticsByCc");
                 // 从查询参数中获取 startDate, endDate 和 strategyName
                 const { startDate, endDate, strategyName } = req.query;
                 const start = startDate ? new Date(startDate) : undefined;
                 const end = endDate ? new Date(endDate) : undefined;
                 const stratName = strategyName ? strategyName : undefined;
                 const stats = await this.messageRecordService.getStatisticsByCc(start, end, stratName);
+                console.timeEnd("getStatisticsByCc");
                 return res.status(200).json({ success: true, data: stats });
             }
             catch (error) {
@@ -227,12 +237,14 @@ class MessageRecordController {
          */
         this.getStatisticsByImage = async (req, res) => {
             try {
+                console.time("getStatisticsByImage");
                 // 从查询参数中获取 startDate, endDate 和 strategyName
                 const { startDate, endDate, strategyName } = req.query;
                 const start = startDate ? new Date(startDate) : undefined;
                 const end = endDate ? new Date(endDate) : undefined;
                 const stratName = strategyName ? strategyName : undefined;
                 const stats = await this.messageRecordService.getStatisticsByImage(start, end, stratName);
+                console.timeEnd("getStatisticsByImage");
                 return res.status(200).json({ success: true, data: stats });
             }
             catch (error) {
@@ -248,12 +260,14 @@ class MessageRecordController {
          */
         this.getDailySentTrends = async (req, res) => {
             try {
+                console.time("getDailySentTrends");
                 // 从查询参数中获取 startDate, endDate 和 strategyName
                 const { startDate, endDate, strategyName } = req.query;
                 const start = startDate ? new Date(startDate) : undefined;
                 const end = endDate ? new Date(endDate) : undefined;
                 const stratName = strategyName ? strategyName : undefined;
                 const stats = await this.messageRecordService.getDailySentTrends(start, end, stratName);
+                console.timeEnd("getDailySentTrends");
                 return res.status(200).json({ success: true, data: stats });
             }
             catch (error) {
@@ -269,6 +283,7 @@ class MessageRecordController {
          */
         this.getMultiDimensionalStatistics = async (req, res) => {
             try {
+                console.time("getMultiDimensionalStatistics");
                 const { startDate, endDate, templateName, strategyName, cc, image } = req.query;
                 const filters = {};
                 if (startDate)
@@ -284,6 +299,7 @@ class MessageRecordController {
                 if (image)
                     filters.image = image;
                 const stats = await this.messageRecordService.getMultiDimensionalStatistics(filters);
+                console.timeEnd("getMultiDimensionalStatistics");
                 return res.status(200).json({ success: true, data: stats });
             }
             catch (error) {
@@ -299,6 +315,7 @@ class MessageRecordController {
          */
         this.getDailyTrendsByCc = async (req, res) => {
             try {
+                console.time("getDailyTrendsByCc");
                 const { cc } = req.params;
                 // 从查询参数中获取 startDate, endDate 和 strategyName
                 const { startDate, endDate, strategyName } = req.query;
@@ -309,6 +326,7 @@ class MessageRecordController {
                     return res.status(400).json({ success: false, message: "Country code is required." });
                 }
                 const stats = await this.messageRecordService.getDailyTrendsByCc(cc, start, end, stratName);
+                console.timeEnd("getDailyTrendsByCc");
                 return res.status(200).json({ success: true, data: stats });
             }
             catch (error) {
@@ -324,6 +342,7 @@ class MessageRecordController {
          */
         this.getDailyTrendsByStrategy = async (req, res) => {
             try {
+                console.time("getDailyTrendsByStrategy");
                 const { strategyName } = req.params;
                 // 从查询参数中获取 startDate, endDate
                 const { startDate, endDate } = req.query;
@@ -333,6 +352,7 @@ class MessageRecordController {
                     return res.status(400).json({ success: false, message: "Strategy name is required." });
                 }
                 const stats = await this.messageRecordService.getDailyTrendsByStrategy(strategyName, start, end);
+                console.timeEnd("getDailyTrendsByStrategy");
                 return res.status(200).json({ success: true, data: stats });
             }
             catch (error) {
@@ -348,6 +368,7 @@ class MessageRecordController {
          */
         this.getDailyTrendsByTemplate = async (req, res) => {
             try {
+                console.time("getDailyTrendsByTemplate");
                 const { templateName } = req.params;
                 // 从查询参数中获取 startDate, endDate 和 strategyName
                 const { startDate, endDate, strategyName } = req.query;
@@ -358,6 +379,7 @@ class MessageRecordController {
                     return res.status(400).json({ success: false, message: "Template Name is required." });
                 }
                 const stats = await this.messageRecordService.getDailyTrendsByTemplate(templateName, start, end, stratName);
+                console.timeEnd("getDailyTrendsByTemplate");
                 return res.status(200).json({ success: true, data: stats });
             }
             catch (error) {
@@ -373,6 +395,7 @@ class MessageRecordController {
          */
         this.getDailyTrendsByImage = async (req, res) => {
             try {
+                console.time("getDailyTrendsByImage");
                 const { image } = req.params;
                 // 从查询参数中获取 startDate, endDate 和 strategyName
                 const { startDate, endDate, strategyName } = req.query;
@@ -383,6 +406,7 @@ class MessageRecordController {
                     return res.status(400).json({ success: false, message: "Image URL is required." });
                 }
                 const stats = await this.messageRecordService.getDailyTrendsByImage(image, start, end, stratName);
+                console.timeEnd("getDailyTrendsByImage");
                 return res.status(200).json({ success: true, data: stats });
             }
             catch (error) {

+ 1 - 1
oms/public/app/index.html

@@ -9,5 +9,5 @@
   <style>body,html{width:100%;height:100%}*,:after,:before{box-sizing:border-box}html{font-family:sans-serif;line-height:1.15;-webkit-text-size-adjust:100%;-ms-text-size-adjust:100%;-ms-overflow-style:scrollbar;-webkit-tap-highlight-color:transparent}@-ms-viewport{width:device-width}body{margin:0;color:#000000d9;font-size:14px;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,Noto Sans,sans-serif,"Apple Color Emoji","Segoe UI Emoji",Segoe UI Symbol,"Noto Color Emoji";font-variant:tabular-nums;line-height:1.5715;background-color:#fff;font-feature-settings:"tnum"}html{--antd-wave-shadow-color:#1890ff;--scroll-bar:0}</style><link rel="stylesheet" href="styles-LXBSU6DF.css" media="print" onload="this.media='all'"><noscript><link rel="stylesheet" href="styles-LXBSU6DF.css"></noscript></head>
   <body>
     <app-root></app-root>
-  <script src="polyfills-B6TNHZQ6.js" type="module"></script><script src="main-DUKLU2H3.js" type="module"></script></body>
+  <script src="polyfills-B6TNHZQ6.js" type="module"></script><script src="main-PYUGQPKS.js" type="module"></script></body>
 </html>

File diff ditekan karena terlalu besar
+ 0 - 0
oms/public/app/main-PYUGQPKS.js


+ 26 - 0
oms/src/controllers/messageRecordController.ts

@@ -140,12 +140,14 @@ class MessageRecordController {
    */
   public getOverallStatistics = async (req: Request, res: Response): Promise<Response> => {
     try {
+      console.time("getOverallStatistics");
       const { startDate, endDate, strategyName } = req.query;
       const start = startDate ? new Date(startDate as string) : undefined;
       const end = endDate ? new Date(endDate as string) : undefined;
       const stratName = strategyName ? (strategyName as string) : undefined;
 
       const stats = await this.messageRecordService.getOverallStatistics(start, end, stratName);
+      console.timeEnd("getOverallStatistics");
 
       return res.status(200).json({ success: true, data: stats });
     } catch (error: any) {
@@ -162,10 +164,13 @@ class MessageRecordController {
    */
   public getStatisticsByActivity = async (req: Request, res: Response): Promise<Response> => {
     try {
+      console.time("getStatisticsByActivity");
       const { startDate, endDate } = req.query;
       const start = startDate ? new Date(startDate as string) : undefined;
       const end = endDate ? new Date(endDate as string) : undefined;
       const stats = await this.messageRecordService.getStatisticsByActivity(start, end);
+      console.timeEnd("getStatisticsByActivity");
+
       return res.status(200).json({ success: true, data: stats });
     } catch (error: any) {
       console.error("Error fetching statistics by activity:", error);
@@ -181,11 +186,13 @@ class MessageRecordController {
    */
   public getStatisticsByStrategy = async (req: Request, res: Response): Promise<Response> => {
     try {
+      console.time("getStatisticsByStrategy");
       const { startDate, endDate, strategyName } = req.query;
       const start = startDate ? new Date(startDate as string) : undefined;
       const end = endDate ? new Date(endDate as string) : undefined;
       const stratName = strategyName ? (strategyName as string) : undefined;
       const stats = await this.messageRecordService.getStatisticsByStrategy(start, end, stratName);
+      console.timeEnd("getStatisticsByStrategy");
       return res.status(200).json({ success: true, data: stats });
     } catch (error: any) {
       console.error("Error fetching statistics by strategy:", error);
@@ -201,12 +208,14 @@ class MessageRecordController {
    */
   public getStatisticsByTemplate = async (req: Request, res: Response): Promise<Response> => {
     try {
+      console.time("getStatisticsByTemplate");
       // 从查询参数中获取 startDate, endDate 和 strategyName
       const { startDate, endDate, strategyName } = req.query;
       const start = startDate ? new Date(startDate as string) : undefined;
       const end = endDate ? new Date(endDate as string) : undefined;
       const stratName = strategyName ? (strategyName as string) : undefined;
       const stats = await this.messageRecordService.getStatisticsByTemplate(start, end, stratName);
+      console.timeEnd("getStatisticsByTemplate");
       return res.status(200).json({ success: true, data: stats });
     } catch (error: any) {
       console.error("Error fetching statistics by template:", error);
@@ -222,12 +231,14 @@ class MessageRecordController {
    */
   public getStatisticsByCc = async (req: Request, res: Response): Promise<Response> => {
     try {
+      console.time("getStatisticsByCc");
       // 从查询参数中获取 startDate, endDate 和 strategyName
       const { startDate, endDate, strategyName } = req.query;
       const start = startDate ? new Date(startDate as string) : undefined;
       const end = endDate ? new Date(endDate as string) : undefined;
       const stratName = strategyName ? (strategyName as string) : undefined;
       const stats = await this.messageRecordService.getStatisticsByCc(start, end, stratName);
+      console.timeEnd("getStatisticsByCc");
       return res.status(200).json({ success: true, data: stats });
     } catch (error: any) {
       console.error("Error fetching statistics by cc:", error);
@@ -243,12 +254,14 @@ class MessageRecordController {
    */
   public getStatisticsByImage = async (req: Request, res: Response): Promise<Response> => {
     try {
+      console.time("getStatisticsByImage");
       // 从查询参数中获取 startDate, endDate 和 strategyName
       const { startDate, endDate, strategyName } = req.query;
       const start = startDate ? new Date(startDate as string) : undefined;
       const end = endDate ? new Date(endDate as string) : undefined;
       const stratName = strategyName ? (strategyName as string) : undefined;
       const stats = await this.messageRecordService.getStatisticsByImage(start, end, stratName);
+      console.timeEnd("getStatisticsByImage");
       return res.status(200).json({ success: true, data: stats });
     } catch (error: any) {
       console.error("Error fetching statistics by image:", error);
@@ -264,12 +277,14 @@ class MessageRecordController {
    */
   public getDailySentTrends = async (req: Request, res: Response): Promise<Response> => {
     try {
+      console.time("getDailySentTrends");
       // 从查询参数中获取 startDate, endDate 和 strategyName
       const { startDate, endDate, strategyName } = req.query;
       const start = startDate ? new Date(startDate as string) : undefined;
       const end = endDate ? new Date(endDate as string) : undefined;
       const stratName = strategyName ? (strategyName as string) : undefined;
       const stats = await this.messageRecordService.getDailySentTrends(start, end, stratName);
+      console.timeEnd("getDailySentTrends");
       return res.status(200).json({ success: true, data: stats });
     } catch (error: any) {
       console.error("Error fetching daily sent trends:", error);
@@ -285,6 +300,7 @@ class MessageRecordController {
    */
   public getMultiDimensionalStatistics = async (req: Request, res: Response): Promise<Response> => {
     try {
+      console.time("getMultiDimensionalStatistics");
       const { startDate, endDate, templateName, strategyName, cc, image } = req.query;
 
       const filters: { [key: string]: any } = {};
@@ -296,6 +312,8 @@ class MessageRecordController {
       if (image) filters.image = image;
 
       const stats = await this.messageRecordService.getMultiDimensionalStatistics(filters);
+      console.timeEnd("getMultiDimensionalStatistics");
+
       return res.status(200).json({ success: true, data: stats });
     } catch (error: any) {
       console.error("Error fetching multi-dimensional statistics:", error);
@@ -311,6 +329,7 @@ class MessageRecordController {
    */
   public getDailyTrendsByCc = async (req: Request, res: Response): Promise<Response> => {
     try {
+      console.time("getDailyTrendsByCc");
       const { cc } = req.params;
       // 从查询参数中获取 startDate, endDate 和 strategyName
       const { startDate, endDate, strategyName } = req.query;
@@ -323,6 +342,7 @@ class MessageRecordController {
       }
 
       const stats = await this.messageRecordService.getDailyTrendsByCc(cc as string, start, end, stratName);
+      console.timeEnd("getDailyTrendsByCc");
       return res.status(200).json({ success: true, data: stats });
     } catch (error: any) {
       console.error("Error fetching daily trends by cc:", error);
@@ -338,6 +358,7 @@ class MessageRecordController {
    */
   public getDailyTrendsByStrategy = async (req: Request, res: Response): Promise<Response> => {
     try {
+      console.time("getDailyTrendsByStrategy");
       const { strategyName } = req.params;
 
       // 从查询参数中获取 startDate, endDate
@@ -350,6 +371,7 @@ class MessageRecordController {
       }
 
       const stats = await this.messageRecordService.getDailyTrendsByStrategy(strategyName as string, start, end);
+      console.timeEnd("getDailyTrendsByStrategy");
       return res.status(200).json({ success: true, data: stats });
     } catch (error: any) {
       console.error("Error fetching daily trends by strategy:", error);
@@ -365,6 +387,7 @@ class MessageRecordController {
    */
   public getDailyTrendsByTemplate = async (req: Request, res: Response): Promise<Response> => {
     try {
+      console.time("getDailyTrendsByTemplate");
       const { templateName } = req.params;
       // 从查询参数中获取 startDate, endDate 和 strategyName
       const { startDate, endDate, strategyName } = req.query;
@@ -377,6 +400,7 @@ class MessageRecordController {
       }
 
       const stats = await this.messageRecordService.getDailyTrendsByTemplate(templateName as string, start, end, stratName);
+      console.timeEnd("getDailyTrendsByTemplate");
       return res.status(200).json({ success: true, data: stats });
     } catch (error: any) {
       console.error("Error fetching daily trends by template:", error);
@@ -392,6 +416,7 @@ class MessageRecordController {
    */
   public getDailyTrendsByImage = async (req: Request, res: Response): Promise<Response> => {
     try {
+      console.time("getDailyTrendsByImage");
       const { image } = req.params;
 
       // 从查询参数中获取 startDate, endDate 和 strategyName
@@ -405,6 +430,7 @@ class MessageRecordController {
       }
 
       const stats = await this.messageRecordService.getDailyTrendsByImage(image as string, start, end, stratName);
+      console.timeEnd("getDailyTrendsByImage");
       return res.status(200).json({ success: true, data: stats });
     } catch (error: any) {
       console.error("Error fetching daily trends by image:", error);

+ 5 - 1
omsapp/src/app/pages/message-dashboard.component.ts

@@ -360,6 +360,7 @@ export class MessageDashboardComponent implements OnInit {
 
     // 加载每日趋势(图表数据)
     this.chartLoading = true;
+    this.dailyTrendsLoading = true;
     this.http
       .get(`/api/message/statistics/daily-trends`, { params })
       .pipe(
@@ -369,7 +370,10 @@ export class MessageDashboardComponent implements OnInit {
           this.message.error('加载每日趋势失败');
           return of([]);
         }),
-        finalize(() => (this.chartLoading = false))
+        finalize(() => {
+          this.chartLoading = false;
+          this.dailyTrendsLoading = false;
+        })
       )
       .subscribe((data) => {
         this.dailyTrends = data;

Beberapa file tidak ditampilkan karena terlalu banyak file yang berubah dalam diff ini