Jelajahi Sumber

cps IAA、IAP消耗数据清洗

ZHAOXIAN 1 tahun lalu
induk
melakukan
499cbb5379

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

@@ -22,53 +22,147 @@
         pay_counts,
         pay_counts,
         order_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 *
+        FROM (SELECT t1.consume_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 consume_date,
+                           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', 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
+                       LEFT JOIN thirtpart.ly_link t0 ON t0.id = t1.link_id
+                       LEFT JOIN (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 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 t1.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', 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'
+              union all
 
 
-                            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
+              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,
+                                         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'
+                                  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) t
+        GROUP BY t.id
     </insert>
     </insert>
 
 
     <insert id="cleanCPSIaaDailyReports">
     <insert id="cleanCPSIaaDailyReports">