wfansh 6 days ago
parent
commit
deae026e7c

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

@@ -11,6 +11,7 @@ import com.google.common.collect.Sets;
 
 import org.jeecg.common.util.DateUtils;
 import org.jeecg.modules.adweb.common.util.DateUtil;
+import org.jeecg.modules.adweb.common.util.NumberUtil;
 import org.jeecg.modules.adweb.dmp.entity.GADailyReport;
 import org.jeecg.modules.adweb.dmp.mapper.GADailyReportMapper;
 import org.jeecg.modules.adweb.dmp.service.IGADailyReportService;
@@ -24,6 +25,7 @@ import org.springframework.cache.annotation.Cacheable;
 import org.springframework.stereotype.Service;
 
 import java.util.*;
+import java.util.function.Function;
 import java.util.stream.Collectors;
 
 /**
@@ -106,11 +108,13 @@ public class GADailyReportServiceImpl extends ServiceImpl<GADailyReportMapper, G
         // 3. 询盘数据补充
         List<Pair<String, Integer>> enquiryDailyCounts =
                 adwebEnquiryMapper.getEnquiryDailyCounts(siteCode, start, end);
-        enquiryDailyCounts.forEach(
-                enquiryDailyCount ->
-                        dailyStatsVOs
-                                .get(enquiryDailyCount.getKey())
-                                .setEnquires(enquiryDailyCount.getValue()));
+        enquiryDailyCounts.stream()
+                .filter(enquiryDailyCount -> dailyStatsVOs.containsKey(enquiryDailyCount.getKey()))
+                .forEach(
+                        enquiryDailyCount ->
+                                dailyStatsVOs
+                                        .get(enquiryDailyCount.getKey())
+                                        .setEnquires(enquiryDailyCount.getValue())); // 返回值可能为Long型
 
         // 3. 根据日期排序并返回
         return dailyStatsVOs.values().stream()
@@ -129,6 +133,33 @@ public class GADailyReportServiceImpl extends ServiceImpl<GADailyReportMapper, G
             cacheNames =
                     "getPeriodicStats" + TTLCacheManager.TTL_SPLITTER + 60 * 30) // Redis TTL为半小时
     public List<PeriodicStatsVO> getPeriodicStats(String siteCode) {
-        return gaDailyReportMapper.getPeriodicStats(siteCode);
+        // 1. 查询GA统计数据 - UV,PV等
+        Map<String, PeriodicStatsVO> periodicStatsVOs =
+                gaDailyReportMapper.getPeriodicStats(siteCode).stream()
+                        .collect(
+                                Collectors.toMap(
+                                        PeriodicStatsVO::getPeriod,
+                                        Function.identity(),
+                                        (x, y) -> y,
+                                        LinkedHashMap::new)); // LinkedHashMap保持原查询顺序
+
+        // 2. 询盘数据补充
+        List<Pair<String, Long>> enquiryPeriodicCounts =
+                adwebEnquiryMapper.getEnquiryPeriodicCounts(siteCode);
+        for (Pair<String, Long> enquiryPeriodicCount : enquiryPeriodicCounts) {
+            if (!periodicStatsVOs.containsKey(enquiryPeriodicCount.getKey())) {
+                continue;
+            }
+
+            PeriodicStatsVO periodicStatsVO = periodicStatsVOs.get(enquiryPeriodicCount.getKey());
+            periodicStatsVO.setEnquires(enquiryPeriodicCount.getValue().intValue()); // 返回值可能为Long型
+            periodicStatsVO.setEnquiryConversionRate(
+                    NumberUtil.formatPercentage(
+                            NumberUtil.safeDivide(
+                                    periodicStatsVO.getEnquires(), periodicStatsVO.getTotalUsers()),
+                            2));
+        }
+
+        return periodicStatsVOs.values().stream().collect(Collectors.toList());
     }
 }

+ 8 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/enquiry/mapper/AdwebEnquiryMapper.java

@@ -77,4 +77,12 @@ public interface AdwebEnquiryMapper extends BaseMapper<AdwebEnquiry> {
      * @return
      */
     List<Pair<String, Integer>> getEnquiryDailyCounts(String siteCode, Date start, Date end);
+
+    /**
+     * 获取分时间段的询盘数量 - - 今天,昨天,本周,上周,本月,上月,全部
+     *
+     * @param siteCode
+     * @return
+     */
+    List<Pair<String, Long>> getEnquiryPeriodicCounts(String siteCode);
 }

+ 36 - 1
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/enquiry/mapper/xml/AdwebEnquiryMapper.xml

@@ -303,7 +303,6 @@
         and t1.principal_type != 1
     </update>
 
-
     <select id="getEnquiryDailyCounts" resultType="cn.hutool.core.lang.Pair">
         SELECT
         date_format(record_ctime, '%Y-%m-%d') `date`,
@@ -323,4 +322,40 @@
         GROUP BY date
     </select>
 
+    <select id="getEnquiryPeriodicCounts" resultType="cn.hutool.core.lang.Pair">
+        SELECT
+        tp.period AS period,
+        COALESCE(COUNT(id), 0) AS enquires
+        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
+        adweb_enquiry ae
+        ON ae.status != 0 AND ae.user_effective != 0
+        <if test="siteCode != null">
+            AND ae.site_code = #{siteCode}
+        </if>
+        AND (
+        (tp.period = 'today' AND DATE(ae.record_ctime) = CURDATE()) OR
+        (tp.period = 'yesterday' AND DATE(ae.record_ctime) = CURDATE() - INTERVAL 1 DAY) OR
+        (tp.period = 'thisWeek' AND YEARWEEK(ae.record_ctime, 1) = YEARWEEK(CURDATE(), 1)) OR
+        (tp.period = 'lastWeek' AND YEARWEEK(ae.record_ctime, 1) = YEARWEEK(CURDATE() - INTERVAL 1 WEEK, 1)) OR
+        (tp.period = 'thisMonth' AND YEAR(ae.record_ctime) = YEAR(CURDATE()) AND MONTH(ae.record_ctime) =
+        MONTH(CURDATE())) OR
+        (tp.period = 'lastMonth' AND YEAR(ae.record_ctime) = YEAR(CURDATE() - INTERVAL 1 MONTH) AND
+        MONTH(ae.record_ctime) =
+        MONTH(CURDATE() - INTERVAL 1 MONTH)) OR
+        (tp.period = 'allTime')
+        )
+        GROUP BY
+        tp.period;
+    </select>
+
 </mapper>