Browse Source

Enquiry country report

wfansh 4 months ago
parent
commit
3df4f9d906

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

@@ -10,12 +10,8 @@ import org.apache.commons.lang.StringUtils;
 import org.apache.commons.lang3.tuple.Pair;
 import org.jeecg.common.api.vo.Result;
 import org.jeecg.modules.adweb.common.util.DateUtil;
-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.service.*;
 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;
 import org.springframework.web.bind.annotation.GetMapping;
@@ -43,8 +39,7 @@ public class DMPDataController {
     @Autowired private IGASourceMediumReportService gaSourceMediumReportService;
     @Autowired private IGACountryReportService gaCountryReportService;
     @Autowired private IGAPagePathReportService gaPagePathReportService;
-
-    @Autowired private IAdwebEnquiryService adwebEnquiryService;
+    @Autowired private IEnquiryReportService enquiryReportService;
 
     /** 首页:网站流量按时间段分析统计 - 今天,昨天,本周,上周等 */
     @GetMapping("/site-periodic/stats")
@@ -134,4 +129,21 @@ public class DMPDataController {
                 gaPagePathReportService.getPagePathStats(
                         siteCode, start, end, limit >= 0 ? limit : 10));
     }
+
+    @GetMapping("/enquiry-country/stats")
+    public Result<List<EnquiryCountryStatsVO>> getEnquiryCountryStats(
+            String siteCode,
+            String dateType,
+            @DateTimeFormat(pattern = "yyyy-MM-dd") Date start,
+            @DateTimeFormat(pattern = "yyyy-MM-dd") Date end) {
+        // 1. 计算时间区间
+        if (StringUtils.isNotBlank(dateType)) {
+            Pair<Date, Date> dateRange = DateUtil.getDateRangeByType(dateType);
+            start = dateRange.getLeft();
+            end = dateRange.getRight();
+        }
+
+        // 2. 查询并返回
+        return Result.ok(enquiryReportService.getEnquiryCountryStats(siteCode, start, end));
+    }
 }

+ 14 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/dmp/service/IEnquiryReportService.java

@@ -0,0 +1,14 @@
+package org.jeecg.modules.adweb.dmp.service;
+
+import org.jeecg.modules.adweb.dmp.vo.report.EnquiryCountryStatsVO;
+
+import java.util.Date;
+import java.util.List;
+
+/**
+ * @author wfansh
+ */
+public interface IEnquiryReportService {
+
+    List<EnquiryCountryStatsVO> getEnquiryCountryStats(String siteCode, Date start, Date end);
+}

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

@@ -0,0 +1,64 @@
+package org.jeecg.modules.adweb.dmp.service.impl;
+
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.jeecg.modules.adweb.common.util.NumberUtil;
+import org.jeecg.modules.adweb.dmp.service.IEnquiryReportService;
+import org.jeecg.modules.adweb.dmp.vo.report.EnquiryCountryStatsVO;
+import org.jeecg.modules.adweb.enquiry.mapper.AdwebEnquiryMapper;
+import org.jeecg.modules.redis.CacheConfig;
+import org.jeecg.modules.redis.TTLCacheManager;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.cache.annotation.Cacheable;
+import org.springframework.stereotype.Service;
+
+import java.util.Collections;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * @author wfansh
+ */
+@Service
+public class EnquiryReportServiceImpl implements IEnquiryReportService {
+
+    @Autowired private AdwebEnquiryMapper adwebEnquiryMapper;
+
+    @Override
+    @Cacheable(
+            cacheManager = CacheConfig.TTL_CACHE_MANAGER,
+            cacheNames =
+                    "getEnquiryCountryStats"
+                            + TTLCacheManager.TTL_SPLITTER
+                            + 60 * 10) // Redis TTL为10分钟
+    public List<EnquiryCountryStatsVO> getEnquiryCountryStats(
+            String siteCode, Date start, Date end) {
+        List<EnquiryCountryStatsVO> enquiryCountryStatsVOs =
+                adwebEnquiryMapper.getEnquiryCountryStats(siteCode, start, end);
+        if (CollectionUtils.isEmpty(enquiryCountryStatsVOs)) {
+            return Collections.EMPTY_LIST;
+        }
+
+        // 1. 时间区间内所有国家enquires总数
+        int totalEnquires =
+                enquiryCountryStatsVOs.stream().mapToInt(EnquiryCountryStatsVO::getEnquires).sum();
+
+        // 2. VO数据填充
+        for (EnquiryCountryStatsVO enquiryCountryStatsVO : enquiryCountryStatsVOs) {
+            // adweb_country表无记录时,如EnquiryCountryStatsVO.countryCode为空
+            if (StringUtils.isBlank(enquiryCountryStatsVO.getCountry())
+                    || StringUtils.isBlank(enquiryCountryStatsVO.getCountryName())) {
+                enquiryCountryStatsVO.setCountry(enquiryCountryStatsVO.getCountryCode());
+                enquiryCountryStatsVO.setCountryName(enquiryCountryStatsVO.getCountryCode());
+            }
+
+            enquiryCountryStatsVO.setEnquiresProportion(
+                    NumberUtil.formatPercentage(
+                            NumberUtil.safeDivide(
+                                    enquiryCountryStatsVO.getEnquires(), totalEnquires),
+                            2));
+        }
+
+        return enquiryCountryStatsVOs;
+    }
+}

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

@@ -0,0 +1,24 @@
+package org.jeecg.modules.adweb.dmp.vo.report;
+
+import lombok.Data;
+
+import org.jeecg.modules.adweb.enquiry.entity.AdwebEnquiry;
+
+/**
+ * 询盘国家分布统计数据VO,see {@link AdwebEnquiry}
+ *
+ * @author wfansh
+ */
+@Data
+public class EnquiryCountryStatsVO {
+
+    private String country;
+
+    private String countryName;
+
+    private String countryCode;
+
+    private int enquires;
+
+    private String enquiresProportion;
+}

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

@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
 import org.apache.commons.lang3.tuple.ImmutablePair;
 import org.apache.commons.lang3.tuple.ImmutableTriple;
 import org.apache.ibatis.annotations.Param;
+import org.jeecg.modules.adweb.dmp.vo.report.EnquiryCountryStatsVO;
 import org.jeecg.modules.adweb.enquiry.dto.EnquiryDTO;
 import org.jeecg.modules.adweb.enquiry.dto.param.EnquirySearchDto;
 import org.jeecg.modules.adweb.enquiry.dto.result.EnquiryListDto;
@@ -87,5 +88,10 @@ public interface AdwebEnquiryMapper extends BaseMapper<AdwebEnquiry> {
      */
     List<ImmutablePair<String, Long>> getEnquiryPeriodicCounts(String siteCode);
 
+    /**
+     * 获取按国家分布的询盘数量
+     */
+    List<EnquiryCountryStatsVO> getEnquiryCountryStats(String siteCode, Date start, Date end);
+
     List<EnquiryDTO> getEnquiryList(String siteCode, String startTime, String endTime);
 }

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

@@ -312,7 +312,7 @@
         FROM
         adweb_enquiry
         WHERE
-        `status` != 0
+        status != 0
         AND user_effective != 0
         AND site_code = #{siteCode}
         <if test="start != null">
@@ -360,6 +360,38 @@
         tp.period;
     </select>
 
+    <select id="getEnquiryCountryStats" resultType="org.jeecg.modules.adweb.dmp.vo.report.EnquiryCountryStatsVO">
+        SELECT
+        t1.enquires,
+        LOWER(t1.country_code) country_code,
+        t2.country_name_en country,
+        t2.country_name
+        FROM
+        (
+        SELECT
+        country_code,
+        COUNT(1) enquires
+        FROM
+        adweb_enquiry
+        WHERE
+        status != 0
+        AND user_effective != 0
+        AND site_code = #{siteCode}
+        <if test="start != null">
+            AND record_ctime >= #{start}
+        </if>
+        <if test="end != null">
+            AND record_ctime &lt; DATE_ADD(#{end}, INTERVAL 1 DAY)
+        </if>
+        GROUP BY
+        country_code
+        ) t1
+        LEFT JOIN adweb_country t2 ON t1.country_code = t2.country_iso_code
+        ORDER BY
+        t1.enquires DESC
+    </select>
+
+
     <select id="getEnquiryList" resultType="org.jeecg.modules.adweb.enquiry.dto.EnquiryDTO">
         SELECT
         id,