Просмотр исходного кода

cps IAA、IAP消耗数据清洗

ZHAOXIAN 1 год назад
Родитель
Сommit
e159a45667

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

@@ -22,78 +22,58 @@
         pay_counts,
         order_counts
         )
-        SELECT
-            t3.date,
-            t0.official_account_id,
-            t0.responsibility_person_id,
-            t2.app_id,
-            t0.id,
-            t3.new_users,
-            t1.new_pay_users,
-            t1.new_pay_counts,
-            t1.new_order_counts,
-            t1.new_pay_amount,
-            t1.new_xn_pay_amount,
-            t1.pay_amount,
-            t1.xn_pay_amount,
-            t1.pay_users,
-            t1.pay_counts,
-            t1.order_counts
-        FROM
-            (
-                SELECT
-                    DATE_FORMAT( activation_time, '%Y%m%d' ) as 'date',
-                        link_id,
-                    count( DISTINCT uid ) AS 'new_users'
-                FROM
-                    thirtpart.ly_user_activation_info
-                WHERE
-                    DATE_FORMAT( activation_time, '%Y%m%d' ) = #{nowDate}
-                GROUP BY
-                    link_id
-            ) t3
-                LEFT JOIN	thirtpart.ly_link t0 ON t0.id = t3.link_id
-                LEFT JOIN (
-                SELECT
-                    consume_date,
+        SELECT t3.date,
+               t0.official_account_id,
+               t0.responsibility_person_id,
+               t2.app_id,
+               t0.id,
+               t3.new_users,
+               t1.new_pay_users,
+               t1.new_pay_counts,
+               t1.new_order_counts,
+               t1.new_pay_amount,
+               t1.new_xn_pay_amount,
+               t1.pay_amount,
+               t1.xn_pay_amount,
+               t1.pay_users,
+               t1.pay_counts,
+               t1.order_counts
+        FROM (SELECT DATE_FORMAT(activation_time, '%Y%m%d') as 'date', link_id,
+                     count(DISTINCT uid) AS 'new_users'
+              FROM thirtpart.ly_user_activation_info
+              WHERE DATE_FORMAT(activation_time, '%Y%m%d') = #{nowDate}
+              GROUP BY link_id) t3
+                 LEFT JOIN thirtpart.ly_link t0 ON t0.id = t3.link_id
+                 LEFT JOIN (SELECT consume_date,
 
-                    link_id,
+                                   link_id,
 
-                    count( DISTINCT CASE WHEN t1.consume_date = DATE_FORMAT( t1.activation_time, '%Y%m%d' ) AND t1.STATUS = 1 THEN t1.uid END ) AS 'new_pay_users',
+                                   count(DISTINCT CASE
+                                                      WHEN t1.consume_date =
+                                                           DATE_FORMAT(t1.activation_time, '%Y%m%d') AND t1.STATUS = 1
+                                                          THEN t1.uid END) AS 'new_pay_users', SUM(IF(
+                        t1.consume_date = DATE_FORMAT(t1.activation_time, '%Y%m%d') AND t1.STATUS = 1, 1,
+                        0)) AS 'new_pay_counts', SUM(IF(t1.consume_date = DATE_FORMAT(t1.activation_time, '%Y%m%d'), 1,
+                                                        0)) AS 'new_order_counts', IFNULL( ROUND(
+                        SUM(IF(t1.consume_date = DATE_FORMAT(t1.activation_time, '%Y%m%d') AND t1.STATUS = 1,
+                               t1.total_fee, 0)), 2),0.00 ) AS 'new_pay_amount', IFNULL(ROUND(SUM(IF(
+                        t1.consume_date = DATE_FORMAT(t1.activation_time, '%Y%m%d') AND t1.STATUS = 1 AND
+                        (t1.pay_merchant = 15 OR pay_type = 20), total_fee, 0)),
+                                                                                              2),0.00 ) AS 'new_xn_pay_amount', IFNULL( ROUND(SUM(if(t1.STATUS = 1, t1.total_fee, 0)), 2), 0.00 ) AS 'pay_amount', IFNULL( ROUND(
+                        SUM(IF(t1.STATUS = 1 AND (t1.pay_merchant = 15 OR pay_type = 20), total_fee, 0)),
+                        2), 0.00 ) AS 'xn_pay_amount', count(DISTINCT CASE WHEN t1.STATUS = 1 THEN t1.uid END ) AS 'pay_users', SUM(IF(t1.STATUS = 1, 1, 0)) AS 'pay_counts', count( t1.order_no ) AS 'order_counts'
 
-                        SUM(IF( t1.consume_date = DATE_FORMAT( t1.activation_time, '%Y%m%d' ) AND t1.STATUS = 1, 1, 0 )) AS 'new_pay_counts',
-
-                        SUM(IF( t1.consume_date = DATE_FORMAT( t1.activation_time, '%Y%m%d' ), 1, 0 )) AS 'new_order_counts',
-
-                        IFNULL(	ROUND( SUM( IF ( t1.consume_date = DATE_FORMAT( t1.activation_time, '%Y%m%d' ) AND t1.STATUS = 1, t1.total_fee, 0 )), 2 ),0.00 ) AS 'new_pay_amount',
-
-                        IFNULL(ROUND(SUM(IF(t1.consume_date = DATE_FORMAT( t1.activation_time, '%Y%m%d') AND t1.STATUS = 1 AND ( t1.pay_merchant = 15 OR pay_type = 20 ),	total_fee,0 )),	2 ),0.00 ) AS 'new_xn_pay_amount',
-
-                        IFNULL( ROUND( SUM( if(t1.STATUS = 1 ,t1.total_fee,0) ), 2 ), 0.00 ) AS 'pay_amount',
-
-                        IFNULL( ROUND( SUM( IF (t1.STATUS = 1 AND ( t1.pay_merchant = 15 OR pay_type = 20), total_fee, 0 )), 2 ), 0.00 ) AS 'xn_pay_amount',
-
-                        count(DISTINCT CASE WHEN t1.STATUS = 1 THEN t1.uid END ) AS 'pay_users',
-
-                        SUM(IF( t1.STATUS = 1, 1, 0 )) AS 'pay_counts',
-
-                        count( t1.order_no ) AS 'order_counts'
-
-                FROM
-                    thirtpart.ly_pay_record t1
-                WHERE
-                    consume_date = #{nowDate}
-                GROUP BY
-                    link_id
-            ) t1 ON  t3.link_id = t1.link_id
-                LEFT JOIN thirtpart.ly_official_accounts t2 ON t0.official_account_id = t2.id
+                            FROM thirtpart.ly_pay_record t1
+                            WHERE consume_date = #{nowDate}
+                            GROUP BY link_id) t1 ON t3.link_id = t1.link_id
+                 LEFT JOIN thirtpart.ly_official_accounts t2 ON t0.official_account_id = t2.id
         WHERE official_account_id is not null
-        GROUP BY
-            t3.link_id
+        GROUP BY t3.link_id
     </insert>
 
     <insert id="cleanCPSIaaDailyReports">
-        replace into thirtpart.cps_link_data_report
+        replace
+        into thirtpart.cps_link_data_report
         (
                 stat_date,
                 official_account_id,
@@ -118,90 +98,79 @@
                 iaa_amount,
 				active_users
                 )
-        select
-            t.date,
-            t.official_account_id,
-            t.responsibility_person_id,
-            t.app_id,
-            t.link_id,
-            t1.new_users,
-            t3.new_pay_users,
-            t3.new_pay_counts,
-            t3.new_order_counts,
-            t3.new_pay_amount,
-            t3.new_xn_pay_amount,
-            t3.pay_amount,
-            t3.xn_pay_amount,
-            t3.pay_users,
-            t3.pay_counts,
-            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
-            (
-                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 (
-                SELECT
-                    t0.id,
-                    t0.official_account_id,
-                    t0.responsibility_person_id,
-                    count(DISTINCT t.uid) AS 'new_users'
-                FROM thirtpart.ly_user_activation_info t
-                         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
-            ) 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
-                    stat_date = #{nowDate}
-            ) t3 ON t3.link_id = t.link_id
-        GROUP BY t.link_id
+        SELECT IFNULL(t.date, t0.date),
+               tt.official_account_id,
+               tt.responsibility_person_id,
+               tt.app_id,
+               tt.id,
+               t1.new_users,
+               t3.new_pay_users,
+               t3.new_pay_counts,
+               t3.new_order_counts,
+               t3.new_pay_amount,
+               t3.new_xn_pay_amount,
+               t3.pay_amount,
+               t3.xn_pay_amount,
+               t3.pay_users,
+               t3.pay_counts,
+               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 (SELECT t0.id,
+                     t0.responsibility_person_id,
+                     t0.official_account_id,
+                     t2.app_id
+              FROM thirtpart.ly_link t0
+                       LEFT JOIN thirtpart.ly_official_accounts t2 ON t0.official_account_id = t2.id) tt
+                 LEFT JOIN
+             (SELECT t.date, t.link_id, COUNT(DISTINCT t.uid) as 'active_users'
+              FROM thirtpart.ly_user_login_record t
+              where date = 20250601
+                AND link_id
+                  >0
+              GROUP BY link_id) t ON tt.id = t.link_id
+                 LEFT JOIN
+             (SELECT t.stat_date as 'date', 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
+                       LEFT JOIN thirtpart.ly_link t0 ON t.link_id = t0.id
+              where t.stat_date = 20250601
+                AND official_account_id = 146
+              GROUP BY t.link_id
+              ORDER BY t.link_id) t0 ON tt.id = t0.link_id
+                 LEFT JOIN (SELECT t0.id,
+                                   DATE_FORMAT(t.activation_time, '%Y%m%d') as 'date', t0.official_account_id,
+                                   t0.responsibility_person_id,
+                                   count(DISTINCT t.uid) AS 'new_users'
+                            FROM thirtpart.ly_user_activation_info t
+                                     LEFT JOIN thirtpart.ly_link t0 ON t.link_id = t0.id
+                            WHERE DATE_FORMAT(t.activation_time, '%Y%m%d') = 20250601
+                            GROUP BY t0.id) t1 ON tt.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 stat_date = 20250601) t3 ON t3.link_id = tt.id
+        WHERE t0.iaa_amount is not null
+        GROUP BY tt.id
     </insert>
 
 </mapper>