wfansh hai 5 meses
pai
achega
453ffa8a85

+ 1 - 16
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/dmp/controller/DMPDataController.java

@@ -68,22 +68,7 @@ public class DMPDataController {
                 gaDailyReportService.getDailyStatsWithinPeriod(siteCode, start, end);
                 gaDailyReportService.getDailyStatsWithinPeriod(siteCode, start, end);
 
 
         // 3. 生成SiteOverviewStatsVO并返回
         // 3. 生成SiteOverviewStatsVO并返回
-        SiteOverviewStatsVO siteOverviewStatsVO = new SiteOverviewStatsVO();
-        siteOverviewStatsVO.setTotalUsers(
-                dailyStatsVOs.stream().mapToInt(DailyStatsVO::getTotalUsers).sum());
-        siteOverviewStatsVO.setPageViews(
-                dailyStatsVOs.stream().mapToInt(DailyStatsVO::getPageViews).sum());
-        siteOverviewStatsVO.setEnquires(
-                dailyStatsVOs.stream().mapToInt(DailyStatsVO::getEnquires).sum());
-        siteOverviewStatsVO.setDailyPageViews(12.00d);
-        siteOverviewStatsVO.setAvgTimeOnPage(120);
-        siteOverviewStatsVO.setPageViewsPerSession(10);
-        siteOverviewStatsVO.setBounceRate("15.00%");
-        siteOverviewStatsVO.setEnquiryConversionRate("10%");
-
-        siteOverviewStatsVO.setDailyStats(dailyStatsVOs);
-
-        return Result.ok(siteOverviewStatsVO);
+        return Result.ok(SiteOverviewStatsVO.fromDailyStats(dailyStatsVOs));
     }
     }
 
 
     @GetMapping("/source-medium/stats")
     @GetMapping("/source-medium/stats")

+ 5 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/dmp/service/impl/GADailyReportServiceImpl.java

@@ -52,7 +52,12 @@ public class GADailyReportServiceImpl extends ServiceImpl<GADailyReportMapper, G
             dailyStatsVO.setDate(
             dailyStatsVO.setDate(
                     DateUtils.date2Str(gaDailyReport.getDate(), DateUtils.date_sdf.get()));
                     DateUtils.date2Str(gaDailyReport.getDate(), DateUtils.date_sdf.get()));
             dailyStatsVO.setTotalUsers(gaDailyReport.getTotalUsers());
             dailyStatsVO.setTotalUsers(gaDailyReport.getTotalUsers());
+            dailyStatsVO.setSessions(gaDailyReport.getSessions());
+            dailyStatsVO.setBounceRate(gaDailyReport.getBounceRate());
+            dailyStatsVO.setAvgSessionDuration(gaDailyReport.getAvgSessionDuration());
             dailyStatsVO.setPageViews(gaDailyReport.getPageViews());
             dailyStatsVO.setPageViews(gaDailyReport.getPageViews());
+            dailyStatsVO.setPageViewsPerSession(gaDailyReport.getPageViewsPerSession());
+
             // TODO: 待后续步骤设置
             // TODO: 待后续步骤设置
             dailyStatsVO.setEnquires(0);
             dailyStatsVO.setEnquires(0);
 
 

+ 84 - 10
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/dmp/vo/report/SiteOverviewStatsVO.java

@@ -1,7 +1,12 @@
 package org.jeecg.modules.adweb.dmp.vo.report;
 package org.jeecg.modules.adweb.dmp.vo.report;
 
 
+import com.fasterxml.jackson.annotation.JsonIgnore;
+
 import lombok.Data;
 import lombok.Data;
 
 
+import org.apache.commons.collections4.CollectionUtils;
+import org.jeecg.modules.adweb.common.util.NumberUtil;
+
 import java.util.List;
 import java.util.List;
 
 
 /**
 /**
@@ -12,22 +17,25 @@ import java.util.List;
 @Data
 @Data
 public class SiteOverviewStatsVO {
 public class SiteOverviewStatsVO {
 
 
-    private int totalUsers;
+    // 加和数据
+    private int totalUsers; // 总访客数 UV
+
+    private int sessions; // 总会话数
 
 
-    private int pageViews;
+    private int pageViews; // 总浏览量 PV
 
 
-    private int enquires;
+    private int enquires; // 总询盘数
 
 
-    // 计算统计数据
-    private double dailyPageViews;
+    // 计算数据
+    private String dailyTotalUsers; // 日均访问量
 
 
-    private int avgTimeOnPage;
+    private String avgTimeOnPage; // 平均访问时长
 
 
-    private double pageViewsPerSession;
+    private String pageViewsPerSession; // 平均访问页面数
 
 
-    private String bounceRate;
+    private String bounceRate; // 跳出率
 
 
-    private String enquiryConversionRate;
+    private String enquiryConversionRate; // UV到询盘转化率
 
 
     private List<DailyStatsVO> dailyStats;
     private List<DailyStatsVO> dailyStats;
 
 
@@ -38,8 +46,74 @@ public class SiteOverviewStatsVO {
 
 
         private int totalUsers;
         private int totalUsers;
 
 
-        private int pageViews;
+        @JsonIgnore private int sessions;
+
+        @JsonIgnore private double bounceRate;
+
+        @JsonIgnore private double avgSessionDuration;
+
+        @JsonIgnore private int pageViews;
+
+        @JsonIgnore private double pageViewsPerSession;
 
 
         private int enquires;
         private int enquires;
     }
     }
+
+    public static SiteOverviewStatsVO fromDailyStats(List<DailyStatsVO> dailyStatsVOs) {
+        if (CollectionUtils.isEmpty(dailyStatsVOs)) {
+            return null;
+        }
+
+        SiteOverviewStatsVO siteOverviewStatsVO = new SiteOverviewStatsVO();
+        // 1. 加和数据
+        int totalUsers = dailyStatsVOs.stream().mapToInt(DailyStatsVO::getTotalUsers).sum();
+        int sessions = dailyStatsVOs.stream().mapToInt(DailyStatsVO::getSessions).sum();
+        int pageViews = dailyStatsVOs.stream().mapToInt(DailyStatsVO::getPageViews).sum();
+        int enquires = dailyStatsVOs.stream().mapToInt(DailyStatsVO::getEnquires).sum();
+
+        siteOverviewStatsVO.setTotalUsers(totalUsers);
+        siteOverviewStatsVO.setSessions(sessions);
+        siteOverviewStatsVO.setPageViews(pageViews);
+        siteOverviewStatsVO.setEnquires(enquires);
+
+        // 2. 计算数据
+        int numDays = dailyStatsVOs.size();
+
+        // 2.1 日均访问量
+        siteOverviewStatsVO.setDailyTotalUsers(
+                NumberUtil.formatDecimal(totalUsers / numDays, 2).toPlainString());
+
+        // 2.2 平均访问时长
+        // -- SUM (avgSessionDuration * sessions)
+        double durationSum =
+                dailyStatsVOs.stream()
+                        .mapToDouble(
+                                dailyStatsVO ->
+                                        dailyStatsVO.getAvgSessionDuration()
+                                                * dailyStatsVO.getSessions())
+                        .sum();
+        siteOverviewStatsVO.setAvgTimeOnPage(
+                NumberUtil.formatDecimal(sessions == 0 ? 0 : durationSum / sessions, 2)
+                                .toPlainString()
+                        + "s"); // 后端返回秒单位
+
+        // 2.3 平均访问页面数
+        siteOverviewStatsVO.setPageViewsPerSession(
+                NumberUtil.formatDecimal(sessions == 0 ? 0 : pageViews / sessions, 2)
+                        .toPlainString());
+
+        // 2.4 跳出率
+        // -- SUM (avgSessionDuration * sessions)
+        double bounceRateSum =
+                dailyStatsVOs.stream().mapToDouble(DailyStatsVO::getBounceRate).sum();
+        siteOverviewStatsVO.setBounceRate(NumberUtil.formatPercentage(bounceRateSum / numDays, 2));
+
+        // 2.5 UV到询盘转化率
+        siteOverviewStatsVO.setEnquiryConversionRate(
+                NumberUtil.formatPercentage(totalUsers == 0 ? 0 : enquires / totalUsers, 2));
+
+        siteOverviewStatsVO.setDailyStats(dailyStatsVOs);
+
+        return siteOverviewStatsVO;
+    }
 }
 }