Преглед на файлове

人群报表视图数据——商业维度数据取10条数据优化处理。

zhaoxian преди 4 години
родител
ревизия
39be48ecbc

+ 63 - 12
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/xml/KuaishouAudienceReportDailyAccountMapper.xml

@@ -7,14 +7,14 @@
         account_id as accountId,
         province,
         age_segment as ageSegment,
-        business_interest_tags as businessInterestTags ,
+        business_interest_tags as businessInterestTags,
         city,
         client,
         gender,
         SUM(charge) as charge,
         SUM(activation) as activation,
         SUM(event_next_day_stay) as eventNextDayStay,
-        ROUND(SUM(event_next_day_stay)/SUM(activation)*100,2)as eventNextDayStayRatio
+        IFNULL(ROUND(SUM(event_next_day_stay)/SUM(activation)*100,2),0) as eventNextDayStayRatio
         FROM ctop_kuaishou_audience_report_daily_account
         where 1=1
         <if test="accountId != null">
@@ -50,8 +50,17 @@
             AND audience_type = #{audienceType}
             GROUP BY business_interest_tags
         </if>
-        <if test="orderType!= null">
-            ORDER BY #{orderType}
+        <if test="orderType == 'charge' ">
+            ORDER BY charge
+        </if>
+        <if test="orderType == 'activation' ">
+            ORDER BY activation
+        </if>
+        <if test="orderType == 'eventNextDayStayRatio'">
+            ORDER BY eventNextDayStayRatio
+        </if>
+        <if test="orderType == 'eventNextDayStay'">
+            ORDER BY eventNextDayStay
         </if>
         <if test="upOrDown == 'desc' || upOrDown == 'DESC'">
             DESC
@@ -73,8 +82,8 @@
         SUM(photo_click) as photoClick,
         SUM(aclick) as aclick,
         SUM(bclick) as bclick,
-        ROUND(SUM(photo_click)/SUM(photo_show)*100,2) as photoClickRatio,
-        ROUND(SUM(bclick)/SUM(aclick)*100,2) as actionRatio
+        IFNULL(ROUND(SUM(photo_click)/SUM(photo_show)*100,2),0) as photoClickRatio,
+        IFNULL(ROUND(SUM(bclick)/SUM(aclick)*100,2),0) as actionRatio
         FROM ctop_kuaishou_audience_report_daily_account
         where 1=1
         <if test="accountId != null">
@@ -113,7 +122,7 @@
     </select>
 
     <select id="querybusinessTypeReportForm" resultType="com.alibaba.fastjson.JSONObject">
-        SELECT
+        (SELECT
         stat_date as statDate,
         account_id as accountId,
         business_interest_tags as businessInterestTags ,
@@ -122,10 +131,11 @@
         sum(charge) as totalCost,
         SUM(aclick) as aclick,
         SUM(bclick) as bclick,
-        ROUND(SUM(photo_click)/SUM(photo_show)*100,2) as photoClickRatio,
-        ROUND(SUM(bclick)/SUM(aclick)*100,2) as actionRatio
+        IFNULL(ROUND(SUM(photo_click)/SUM(photo_show)*100,2),0) as photoClickRatio,
+        IFNULL(ROUND(SUM(bclick)/SUM(aclick)*100,2),0) as actionRatio
         FROM ctop_kuaishou_audience_report_daily_account
         where 1=1
+        AND business_interest_tags != '其他'
         <if test="accountId != null">
             and account_id = #{accountId}
         </if>
@@ -137,13 +147,54 @@
         </if>
         AND audience_type = 'businessInterestTags'
         GROUP BY business_interest_tags
-        ORDER BY totalCost  desc
-        limit 10
+        ORDER BY totalCost desc
+        limit 9
+        )
+        <if test="count > 0 ">
+            union all
+            SELECT
+            statDate as statDate,
+            accountId as accountId,
+            businessInterestTags as businessInterestTags,
+            SUM(photoShow) as photoShow,
+            SUM(photoClick) as photoClick,
+            sum(charge) AS totalCost,
+            SUM(aclick) as aclick,
+            SUM(bclick) as bclick,
+            ROUND(SUM(photoClick)/SUM(photoShow)*100,2) as photoClickRatio,
+            ROUND(SUM(bclick)/SUM(aclick)*100,2) as actionRatio
+            FROM (
+            SELECT
+            stat_date as statDate,
+            account_id as accountId,
+            '其他' as businessInterestTags,
+            SUM(photo_show) as photoShow,
+            SUM(photo_click) as photoClick,
+            sum(charge) AS charge,
+            SUM(aclick) as aclick,
+            SUM(bclick) as bclick
+            FROM ctop_kuaishou_audience_report_daily_account t
+            where 1=1
+            <if test="accountId != null">
+                and account_id = #{accountId}
+            </if>
+            <if test="startTime != null">
+                AND stat_date &gt;= #{startTime}
+            </if>
+            <if test="endTime != null">
+                AND stat_date &lt;= #{endTime}
+            </if>
+            AND audience_type = 'businessInterestTags'
+            GROUP BY business_interest_tags
+            ORDER BY charge
+            limit 0,#{count}
+            ) t1
+        </if>
     </select>
 
 
     <select id="querybusinessTypeCount" resultType="java.lang.Integer">
-        SELECT count(1) FROM(
+        SELECT count(1) FROM (
         SELECT
         1
         FROM ctop_kuaishou_audience_report_daily_account

+ 2 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/service/impl/KuaishouAudienceReportDailyAccountServiceImpl.java

@@ -75,6 +75,8 @@ public class KuaishouAudienceReportDailyAccountServiceImpl extends ServiceImpl<K
             data.put("client", clients);
         }
         audienceReport.setAudienceType("businessInterestTags");
+        int count = accountMapper.querybusinessTypeCount(audienceReport);
+        audienceReport.setCount(count - 9);
         List<JSONObject> bussiness = accountMapper.querybusinessTypeReportForm(audienceReport);
         if (!Check.isNull(bussiness)) {
             data.put("businessInterestTags", bussiness);