Quellcode durchsuchen

人群报表视图数据—数据查询优化处理。

zhaoxian vor 4 Jahren
Ursprung
Commit
12b161e0ef

+ 3 - 1
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/entity/KuaishouAudienceReportDailyAccount.java

@@ -7,6 +7,8 @@ import lombok.Data;
 import lombok.EqualsAndHashCode;
 import lombok.experimental.Accessors;
 
+import java.util.List;
+
 /**
  * 人群分析报表
  *
@@ -26,5 +28,5 @@ public class KuaishouAudienceReportDailyAccount extends KuaishouAudienceReportDa
     private java.lang.String audienceType;
 
     @TableField(exist = false)
-    private java.lang.Integer count;
+    private List<String> busTypes;
 }

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

@@ -19,7 +19,7 @@ public interface KuaishouAudienceReportDailyAccountMapper extends BaseMapper<Kua
 
     List<JSONObject> queryAllReportForm(KuaishouAudienceReportDailyAccount audienceReport);
 
-    int querybusinessTypeCount(KuaishouAudienceReportDailyAccount audienceReport);
+    List<String> querybusinessTypeCount(KuaishouAudienceReportDailyAccount audienceReport);
 
     List<JSONObject> querybusinessTypeReportForm(KuaishouAudienceReportDailyAccount audienceReport);
 }

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

@@ -135,7 +135,7 @@
         IFNULL(ROUND(SUM(bclick)/SUM(aclick)*100,2),0) as actionRatio
         FROM ctop_kuaishou_audience_report_daily_account
         where 1=1
-        <if test="count > 0 ">
+        <if test="busTypes !=null and busTypes.size() == 9 ">
             AND business_interest_tags != '其他'
         </if>
         <if test="accountId != null">
@@ -152,7 +152,7 @@
         ORDER BY totalCost desc
         limit 9
         )
-        <if test="count > 0 ">
+        <if test="busTypes !=null and busTypes.size() == 9 ">
             union all
             SELECT
             statDate as statDate,
@@ -187,20 +187,24 @@
                 AND stat_date &lt;= #{endTime}
             </if>
             AND audience_type = 'businessInterestTags'
+            AND business_interest_tags not in
+            <foreach collection="busTypes" item="item" index="index" open="(" separator="," close=")">
+                #{item}
+            </foreach>
             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 id="querybusinessTypeCount" resultType="java.lang.String">
+        SELECT businessInterestTags FROM (
         SELECT
-        1
+        sum(charge) as totalCost,
+        business_interest_tags as businessInterestTags
         FROM ctop_kuaishou_audience_report_daily_account
-        where 1=1
+        where audience_type = 'businessInterestTags'
+        AND business_interest_tags != '其他'
         <if test="accountId != null">
             and account_id = #{accountId}
         </if>
@@ -210,10 +214,9 @@
         <if test="endTime != null">
             AND stat_date &lt;= #{endTime}
         </if>
-        <if test="audienceType == 'businessInterestTags' ">
-            AND audience_type = #{audienceType}
-            GROUP BY business_interest_tags
-        </if>
-        ) as tt
+        GROUP BY business_interest_tags
+        ORDER BY totalCost desc
+        limit 9
+        ) t1
     </select>
 </mapper>

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

@@ -39,7 +39,7 @@ public class KuaishouAudienceReportDailyAccountServiceImpl extends ServiceImpl<K
             pageSize = 10;
         }
         PageHelper.startPage(pageNo, pageSize);
-        List<JSONObject>jsonObjects = accountMapper.queryPageLists(audienceReport);
+        List<JSONObject> jsonObjects = accountMapper.queryPageLists(audienceReport);
         return new PageInfo<>(jsonObjects);
     }
 
@@ -75,8 +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<String> busTypes = accountMapper.querybusinessTypeCount(audienceReport);
+        audienceReport.setBusTypes(busTypes);
         List<JSONObject> bussiness = accountMapper.querybusinessTypeReportForm(audienceReport);
         if (!Check.isNull(bussiness)) {
             data.put("businessInterestTags", bussiness);