Explorar el Código

Merge branch 'period' of wangfan/adweb3-server into master

wangfan hace 6 días
padre
commit
28ea69787a

+ 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));

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

@@ -1,16 +1,16 @@
 package org.jeecg.modules.adweb.dmp.mapper;
 
-
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 
 import org.jeecg.modules.adweb.dmp.entity.GADailyReport;
+import org.jeecg.modules.adweb.dmp.vo.report.PeriodicStatsVO;
+
+import java.util.List;
 
 /**
- * @Description: dmp_ga_daily_report
- * @Author: jeecg-boot
- * @Date:   2024-10-10
- * @Version: V1.0
+ * @Description: dmp_ga_daily_report @Author: jeecg-boot @Date: 2024-10-10 @Version: V1.0
  */
 public interface GADailyReportMapper extends BaseMapper<GADailyReport> {
 
+    List<PeriodicStatsVO> getPeriodicStats(String siteCode);
 }

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

@@ -1,5 +1,37 @@
 <?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.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 period
+        UNION ALL SELECT 'yesterday'
+        UNION ALL SELECT 'thisWeek'
+        UNION ALL SELECT 'lastWeek'
+        UNION ALL SELECT 'thisMonth'
+        UNION ALL SELECT 'lastMonth'
+        UNION ALL SELECT 'allTime'
+        ) tp
+        LEFT JOIN
+        dmp_ga_daily_report d
+        ON
+        d.site_code = #{siteCode}
+        AND (
+        (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.period = 'allTime')
+        )
+        GROUP BY
+        tp.period;
+    </select>
 </mapper>

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

@@ -5,6 +5,7 @@ import static org.jeecg.modules.adweb.dmp.vo.report.SiteOverviewStatsVO.DailySta
 import com.baomidou.mybatisplus.extension.service.IService;
 
 import org.jeecg.modules.adweb.dmp.entity.GADailyReport;
+import org.jeecg.modules.adweb.dmp.vo.report.PeriodicStatsVO;
 
 import java.util.Date;
 import java.util.List;
@@ -15,11 +16,18 @@ import java.util.List;
 public interface IGADailyReportService extends IService<GADailyReport> {
 
     /**
-     * 查询指定时间区间内的{@DailyStatsVO}
+     * 查询指定时间区间内的{@link DailyStatsVO}
      *
      * <p>如数据库中某天数据缺失,需填充空数据
      *
      * <p>填充每日询盘数据
      */
-    List<DailyStatsVO> getDailyStatsWithinPeriod(String siteCode, Date start, Date end);
+    List<DailyStatsVO> getDailyStatsForDateRange(String siteCode, Date start, Date end);
+
+    /**
+     * 查询分时间段的{@link PeriodicStatsVO} - 今天,昨天,本周,上周,本月,上月,全部
+     *
+     * <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);
+    }
 }

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

@@ -0,0 +1,17 @@
+package org.jeecg.modules.adweb.dmp.vo.report;
+
+import lombok.Data;
+
+@Data
+public class PeriodicStatsVO {
+
+    private String period;
+
+    private int totalUsers;
+
+    private int pageViews;
+
+    private int enquires;
+
+    private String enquiryConversionRate; // UV到询盘转化率
+}