Parcourir la source

Peoridic status

wfansh il y a 6 jours
Parent
commit
76fc13e00e

+ 7 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/common/util/DateUtil.java

@@ -2,6 +2,7 @@ package org.jeecg.modules.adweb.common.util;
 
 import lombok.extern.slf4j.Slf4j;
 
+import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.tuple.Pair;
 
 import java.text.ParseException;
@@ -77,6 +78,12 @@ public class DateUtil {
                 end = getTmrZeroTime(now);
                 start = addDays(end, -30);
                 break;
+            default:
+                // e.g. dateType = 7
+                if (StringUtils.isNumeric(dateType)) {
+                    end = getTmrZeroTime(now);
+                    start = addDays(end, -Integer.parseInt(dateType));
+                }
         }
 
         return Pair.of(start, end);

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

@@ -14,10 +14,7 @@ import org.jeecg.modules.adweb.dmp.service.IGACountryReportService;
 import org.jeecg.modules.adweb.dmp.service.IGADailyReportService;
 import org.jeecg.modules.adweb.dmp.service.IGAPagePathReportService;
 import org.jeecg.modules.adweb.dmp.service.IGASourceMediumReportService;
-import org.jeecg.modules.adweb.dmp.vo.report.CountryStatsVO;
-import org.jeecg.modules.adweb.dmp.vo.report.PagePathStatsVO;
-import org.jeecg.modules.adweb.dmp.vo.report.SiteOverviewStatsVO;
-import org.jeecg.modules.adweb.dmp.vo.report.SourceMediumStatsVO;
+import org.jeecg.modules.adweb.dmp.vo.report.*;
 import org.jeecg.modules.adweb.enquiry.service.IAdwebEnquiryService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.format.annotation.DateTimeFormat;
@@ -46,6 +43,13 @@ public class DMPDataController {
 
     @Autowired private IAdwebEnquiryService adwebEnquiryService;
 
+    /** 首页:网站流量按时间段分析统计 - 今天,昨天,本周,上周等 */
+    @GetMapping("/site-periodic/stats")
+    public Result<List<PeriodicStatsVO>> getSitePeriodicStats(String siteCode) {
+        // 查询并返回
+        return Result.ok(gaDailyReportService.getPeriodicStats(siteCode));
+    }
+
     /** 网站流量整体分析统计 */
     @GetMapping("/site-overview/stats")
     public Result<SiteOverviewStatsVO> getSiteOverviewStats(
@@ -62,7 +66,7 @@ public class DMPDataController {
 
         // 2. 查询GA Daily Report和Enquiries
         List<DailyStatsVO> dailyStatsVOs =
-                gaDailyReportService.getDailyStatsWithinPeriod(siteCode, start, end);
+                gaDailyReportService.getDailyStatsForDateRange(siteCode, start, end);
 
         // 3. 生成SiteOverviewStatsVO并返回
         return Result.ok(SiteOverviewStatsVO.fromDailyStats(dailyStatsVOs));

+ 11 - 11
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/dmp/mapper/xml/GADailyReportMapper.xml

@@ -1,15 +1,15 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
-<mapper namespace="org.jeecg.modules.adweb.dmp.mapper.GA">
+<mapper namespace="org.jeecg.modules.adweb.dmp.mapper.GADailyReportMapper">
 
     <select id="getPeriodicStats" resultType="org.jeecg.modules.adweb.dmp.vo.report.PeriodicStatsVO">
         SELECT
-        tp.time_period,
+        tp.period AS period,
         COALESCE(SUM(d.total_users), 0) AS total_users,
         COALESCE(SUM(d.page_views), 0) AS page_views
         FROM
         (
-        SELECT 'today' AS time_period
+        SELECT 'today' AS period
         UNION ALL SELECT 'yesterday'
         UNION ALL SELECT 'thisWeek'
         UNION ALL SELECT 'lastWeek'
@@ -22,16 +22,16 @@
         ON
         d.site_code = #{siteCode}
         AND (
-        (tp.time_period = 'today' AND DATE(d.date) = CURDATE()) OR
-        (tp.time_period = 'yesterday' AND DATE(d.date) = CURDATE() - INTERVAL 1 DAY) OR
-        (tp.time_period = 'thisWeek' AND YEARWEEK(d.date, 1) = YEARWEEK(CURDATE(), 1)) OR
-        (tp.time_period = 'lastWeek' AND YEARWEEK(d.date, 1) = YEARWEEK(CURDATE() - INTERVAL 1 WEEK, 1)) OR
-        (tp.time_period = 'thisMonth' AND YEAR(d.date) = YEAR(CURDATE()) AND MONTH(d.date) = MONTH(CURDATE())) OR
-        (tp.time_period = 'lastMonth' AND YEAR(d.date) = YEAR(CURDATE() - INTERVAL 1 MONTH) AND MONTH(d.date) =
+        (tp.period = 'today' AND DATE(d.date) = CURDATE()) OR
+        (tp.period = 'yesterday' AND DATE(d.date) = CURDATE() - INTERVAL 1 DAY) OR
+        (tp.period = 'thisWeek' AND YEARWEEK(d.date, 1) = YEARWEEK(CURDATE(), 1)) OR
+        (tp.period = 'lastWeek' AND YEARWEEK(d.date, 1) = YEARWEEK(CURDATE() - INTERVAL 1 WEEK, 1)) OR
+        (tp.period = 'thisMonth' AND YEAR(d.date) = YEAR(CURDATE()) AND MONTH(d.date) = MONTH(CURDATE())) OR
+        (tp.period = 'lastMonth' AND YEAR(d.date) = YEAR(CURDATE() - INTERVAL 1 MONTH) AND MONTH(d.date) =
         MONTH(CURDATE() - INTERVAL 1 MONTH)) OR
-        (tp.time_period = 'allTime')
+        (tp.period = 'allTime')
         )
         GROUP BY
-        tp.time_period;
+        tp.period;
     </select>
 </mapper>

+ 4 - 4
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/dmp/service/IGADailyReportService.java

@@ -16,18 +16,18 @@ import java.util.List;
 public interface IGADailyReportService extends IService<GADailyReport> {
 
     /**
-     * 查询指定时间区间内的{@DailyStatsVO}
+     * 查询指定时间区间内的{@link DailyStatsVO}
      *
      * <p>如数据库中某天数据缺失,需填充空数据
      *
      * <p>填充每日询盘数据
      */
-    List<DailyStatsVO> getDailyStatsWithinDateRange(String siteCode, Date start, Date end);
+    List<DailyStatsVO> getDailyStatsForDateRange(String siteCode, Date start, Date end);
 
     /**
-     * 查询分时间段的{@PeriodicStatsVO},如今天,昨天,本周,上周,本月,上月,全部 *
+     * 查询分时间段的{@link PeriodicStatsVO} - 今天,昨天,本周,上周,本月,上月,全部
      *
-     * <p>填充每日询盘数据
+     * <p>填充各时间段询盘数据
      */
     List<PeriodicStatsVO> getPeriodicStats(String siteCode);
 }

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

@@ -14,6 +14,7 @@ import org.jeecg.modules.adweb.common.util.DateUtil;
 import org.jeecg.modules.adweb.dmp.entity.GADailyReport;
 import org.jeecg.modules.adweb.dmp.mapper.GADailyReportMapper;
 import org.jeecg.modules.adweb.dmp.service.IGADailyReportService;
+import org.jeecg.modules.adweb.dmp.vo.report.PeriodicStatsVO;
 import org.jeecg.modules.adweb.enquiry.mapper.AdwebEnquiryMapper;
 import org.jeecg.modules.adweb.site.service.IAdwebSiteService;
 import org.jeecg.modules.redis.CacheConfig;
@@ -34,10 +35,12 @@ public class GADailyReportServiceImpl extends ServiceImpl<GADailyReportMapper, G
 
     @Autowired private IAdwebSiteService adwebSiteService;
 
+    @Autowired private GADailyReportMapper gaDailyReportMapper;
+
     @Autowired private AdwebEnquiryMapper adwebEnquiryMapper;
 
     /**
-     * 查询指定时间区间内的{@DailyStatsVO}
+     * 查询指定时间区间内的{@link DailyStatsVO}
      *
      * <p>如数据库中某天数据缺失,需填充空数据
      *
@@ -50,7 +53,7 @@ public class GADailyReportServiceImpl extends ServiceImpl<GADailyReportMapper, G
                     "getDailyStatsWithinPeriod"
                             + TTLCacheManager.TTL_SPLITTER
                             + 60 * 30) // Redis TTL为半小时
-    public List<DailyStatsVO> getDailyStatsWithinPeriod(String siteCode, Date start, Date end) {
+    public List<DailyStatsVO> getDailyStatsForDateRange(String siteCode, Date start, Date end) {
         Map<String, DailyStatsVO> dailyStatsVOs = Maps.newHashMap();
 
         // 0. 起止时间为空时,设置默认区间 - start = 网站发布日期 & end = 今天
@@ -114,4 +117,18 @@ public class GADailyReportServiceImpl extends ServiceImpl<GADailyReportMapper, G
                 .sorted(Comparator.comparing(DailyStatsVO::getDate)) // 排日期升序排序
                 .collect(Collectors.toList()); // 使用toList()方法返回UnmodifiableList,导致Redis类型解析异常
     }
+
+    /**
+     * 查询分时间段的{@link PeriodicStatsVO} - 今天,昨天,本周,上周,本月,上月,全部
+     *
+     * <p>填充各时间段询盘数据
+     */
+    @Override
+    @Cacheable(
+            cacheManager = CacheConfig.TTL_CACHE_MANAGER,
+            cacheNames =
+                    "getPeriodicStats" + TTLCacheManager.TTL_SPLITTER + 60 * 30) // Redis TTL为半小时
+    public List<PeriodicStatsVO> getPeriodicStats(String siteCode) {
+        return gaDailyReportMapper.getPeriodicStats(siteCode);
+    }
 }

+ 4 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/dmp/vo/report/PeriodicStatsVO.java

@@ -10,4 +10,8 @@ public class PeriodicStatsVO {
     private int totalUsers;
 
     private int pageViews;
+
+    private int enquires;
+
+    private String enquiryConversionRate; // UV到询盘转化率
 }