Przeglądaj źródła

cps IAA、IAP消耗数据清洗 2

ZHAOXIAN 1 rok temu
rodzic
commit
32a40e7487

+ 64 - 43
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/data/mapper/xml/CPSReportMapper.xml

@@ -81,14 +81,15 @@
                 new_iaa_amount,
                 new_iaa_amount,
                 iaa_users,
                 iaa_users,
                 iaa_counts,
                 iaa_counts,
-                iaa_amount
+                iaa_amount,
+				active_users
                 )
                 )
         select
         select
-            t.stat_date,
-            t0.official_account_id,
-            t0.responsibility_person_id,
-            t2.app_id,
-            t0.id,
+            t.date,
+            t.official_account_id,
+            t.responsibility_person_id,
+            t.app_id,
+            t.link_id,
             t1.new_users,
             t1.new_users,
             t3.new_pay_users,
             t3.new_pay_users,
             t3.new_pay_counts,
             t3.new_pay_counts,
@@ -99,17 +100,46 @@
             t3.xn_pay_amount,
             t3.xn_pay_amount,
             t3.pay_users,
             t3.pay_users,
             t3.pay_counts,
             t3.pay_counts,
-            order_counts,
-            count(distinct case when SUBSTR(dying_time,1,10) = SUBSTR(event_time,1,10) then uid end) 'new_iaa_users',
-                sum(if(SUBSTR(dying_time,1,10) = SUBSTR(event_time,1,10) ,1,0)) 'new_iaa_counts',
-                IFNULL(ROUND(sum(if(SUBSTR(dying_time,1,10) = SUBSTR(event_time,1,10) ,cost/100000,0)),2),0.00) 'new_iaa_amount',
-                count(distinct uid) 'iaa_users',
-                sum(1) 'iaa_counts',
-                IFNULL(ROUND(sum(cost/100000),2),0.00)  'iaa_amount'
+            t3.order_counts,
+            t0.new_iaa_users,
+            t0.new_iaa_counts,
+            t0.new_iaa_amount,
+            t0.iaa_users,
+            t0.iaa_counts,
+            t0.iaa_amount,
+            t.active_users
         FROM
         FROM
-            media_api.bytedance_webhook_ma_ecpm t
-                LEFT JOIN  thirtpart.ly_link t0 ON t0.id = t.link_id
-                LEFT JOIN thirtpart.ly_official_accounts t2 ON t0.official_account_id = t2.id
+            (
+                SELECT
+                    t.date,
+                    t.link_id,
+                    t.official_account_id,
+                    t0.responsibility_person_id,
+                    t2.app_id,
+                    COUNT( DISTINCT t.uid) as 'active_users'
+                FROM thirtpart.ly_user_login_record t
+                         LEFT JOIN  thirtpart.ly_link t0 ON t0.id = t.link_id
+                         LEFT JOIN thirtpart.ly_official_accounts t2 ON t.official_account_id = t2.id
+                where date = #{nowDate}
+                  AND link_id >0
+                  AND t0.responsibility_person_id is not null
+                GROUP BY link_id
+                ) t
+                LEFT JOIN
+                (
+                SELECT
+                    t.link_id,
+                    count(distinct case when SUBSTR(dying_time,1,10) = SUBSTR(event_time,1,10) then uid end) 'new_iaa_users',
+                        sum(if(SUBSTR(dying_time,1,10) = SUBSTR(event_time,1,10) ,1,0)) 'new_iaa_counts',
+                        IFNULL(ROUND(sum(if(SUBSTR(dying_time,1,10) = SUBSTR(event_time,1,10) ,cost/100000,0)),2),0.00) 'new_iaa_amount',
+                        count(distinct uid) 'iaa_users',
+                        sum(1) 'iaa_counts',
+                        IFNULL(ROUND(sum(cost/100000),2),0.00)  'iaa_amount'
+                FROM
+                    media_api.bytedance_webhook_ma_ecpm t
+                where t.stat_date = #{nowDate}
+                GROUP BY t.link_id
+            ) t0 ON t.link_id = t0.link_id
                 LEFT JOIN (
                 LEFT JOIN (
                 SELECT
                 SELECT
                     t0.id,
                     t0.id,
@@ -118,35 +148,26 @@
                     count(DISTINCT t.uid) AS 'new_users'
                     count(DISTINCT t.uid) AS 'new_users'
                 FROM thirtpart.ly_user_activation_info t
                 FROM thirtpart.ly_user_activation_info t
                          LEFT JOIN thirtpart.ly_link t0 ON t.link_id = t0.id
                          LEFT JOIN thirtpart.ly_link t0 ON t.link_id = t0.id
-                WHERE DATE_FORMAT(t.activation_time, '%Y%m%d') = #{nowDate}
-                GROUP BY t0.id, t0.official_account_id, t0.responsibility_person_id
-            ) t1 ON t0.id = t1.id
-                AND t0.official_account_id = t1.official_account_id
-                AND t0.responsibility_person_id = t1.responsibility_person_id
-                LEFT JOIN (
-                SELECT stat_date,
-                       official_account_id,
-                       responsibility_person_id,
-                       ma_appid,
-                       link_id,
-                       new_users,
-                       new_pay_users,
-                       new_pay_counts,
-                       new_order_counts,
-                       new_pay_amount,
-                       new_xn_pay_amount,
-                       pay_amount,
-                       xn_pay_amount,
-                       pay_users,
-                       pay_counts,order_counts
+                WHERE DATE_FORMAT(t.activation_time, '%Y%m%d') =#{nowDate}
+                GROUP BY t0.id
+            ) t1 ON t.link_id = t1.id
+                LEFT JOIN
+            (
+                SELECT
+                    link_id,
+                    new_pay_users,
+                    new_pay_counts,
+                    new_order_counts,
+                    new_pay_amount,
+                    new_xn_pay_amount,
+                    pay_amount,
+                    xn_pay_amount,
+                    pay_users,
+                    pay_counts,order_counts
                 FROM thirtpart.cps_link_data_report WHERE
                 FROM thirtpart.cps_link_data_report WHERE
                     stat_date = #{nowDate}
                     stat_date = #{nowDate}
-            ) t3 ON t3.link_id = t.link_id and t0.official_account_id = t3.official_account_id and t0.responsibility_person_id = t3.responsibility_person_id
-        where t.stat_date = #{nowDate}
-          AND t.link_id in (
-            SELECT id FROM thirtpart.ly_link
-        )
-        GROUP BY t0.id,t0.official_account_id,t0.responsibility_person_id
+            ) t3 ON t3.link_id = t.link_id
+        GROUP BY t.link_id
     </insert>
     </insert>
 
 
 </mapper>
 </mapper>