renyupeng 3 tahun lalu
induk
melakukan
0efe76c975

+ 2 - 2
Apietl/bytedance_etl/Q4Task/AppBytedanceAdReportBusi.py

@@ -28,7 +28,7 @@ group by project_id """
                 try:
                     sql = """SET sql_mode = 'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
                     REPLACE INTO application.app_bytedance_ad_report_busi_{day_count}d 
-                    SELECT concat(date_format(date_sub({date_time}, INTERVAL 6 DAY),'%Y%m%d'),'-',{date_time}) start_end_time,
+                    SELECT concat(date_format(date_sub({date_time}, INTERVAL ({day_count} -1)  DAY),'%Y%m%d'),'-',{date_time}) start_end_time,
                     report.account_id,
                     report.campaign_id,
                     report.ad_id,
@@ -536,7 +536,7 @@ group by project_id """
                        `media_api`.bytedance_ad_report_daily
                       WHERE
                        stat_datetime >= date_format(
-                        date_sub({date_time}, INTERVAL 6 DAY),
+                        date_sub({date_time}, INTERVAL ({day_count} -1)  DAY),
                         '%Y%m%d'
                        )
                       GROUP BY

+ 597 - 0
Apietl/bytedance_etl/Q4Task/AppBytedanceAdReportBusiMonth.py

@@ -0,0 +1,597 @@
+# Author renyupeng
+# coding=utf-8
+# @Time    : 2021/11/10 3:37 下午
+# @Site    : 
+# @File    : AppBytedanceAdReportBusiMonth.py
+# @Software: PyCharm
+# @contact: renyupeng@c-top.com.cn
+# @Tel 1501435553
+import logging
+
+from Apietl.conn.TidbConn import TidbConn
+from Apietl.utlis.Utils import Utils
+
+
+class AppBytedanceAdReportBusiMonth:
+    def __init__(self):
+        self.conn = TidbConn.get_connection()
+        self.parm = Utils.get_task_args()
+        self.day_count = Utils.get_days()
+        self.date_time = self.parm[0]
+
+    def taskHandler(self):
+        try:
+            sql_porject = """select project_id from `jeecg-boot`.ctop_user_allocation where media_id=1
+group by project_id """
+            project_list = TidbConn.quary(self.conn, sql_porject)
+            for project_id in project_list:
+                try:
+                    sql = """SET sql_mode = 'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
+                    REPLACE INTO application.app_bytedance_ad_report_busi_m 
+                   select 
+                    date_format({date_time},'%Y%m'),
+                    report.account_id,
+                    report.campaign_id,
+                    report.ad_id,
+                    report.ad_name,
+                     bei.project_id project_id,
+                     bei.product_id product_id,
+                     bei.advertiser_id advertiser_id,
+                     bei.company_id company_id,
+                     bei.account_name account_name,
+                     bei.project_name project_name,
+                     bei.advertiser_name advertiser_name,
+                     bei.company_name company_name,
+                     bei.sale_id sale_id,
+                     bei.user_id user_id,
+                     bei.leader_id leader_id,
+                     bei.org_code org_code,
+                     report.cost,
+                     report. `SHOW`,
+                     report.avg_show_cost,
+                     report.click,
+                     report.avg_click_cost,
+                     report.ctr,
+                     report. `CONVERT`,
+                     report.convert_cost,
+                     report.convert_rate,
+                     report.deep_convert,
+                     report.deep_convert_cost,
+                     report.deep_convert_rate,
+                     report.attribution_convert,
+                     report.attribution_convert_cost,
+                     report.attribution_deep_convert,
+                     report.attribution_deep_convert_cost,
+                     report.download_start,
+                     report.download_start_cost,
+                     report.download_start_rate,
+                     report.download_finish,
+                     report.download_finish_cost,
+                     report.download_finish_rate,
+                     report.click_install,
+                     report.install_finish,
+                     report.install_finish_cost,
+                     report.install_finish_rate,
+                     report.active,
+                     report.active_cost,
+                     report.active_rate,
+                     report.register,
+                     report.active_register_cost,
+                     report.active_register_rate,
+                     report.next_day_open,
+                     report.next_day_open_cost,
+                     report.next_day_open_rate,
+                     report.attribution_next_day_open_cnt,
+                     report.attribution_next_day_open_cost,
+                     report.attribution_next_day_open_rate,
+                     report.game_addiction,
+                     report.game_addiction_cost,
+                     report.game_addiction_rate,
+                     report.pay_count,
+                     report.active_pay_cost,
+                     report.active_pay_rate,
+                     report.loan_completion,
+                     report.loan_completion_cost,
+                     report.loan_completion_rate,
+                     report.pre_loan_credit,
+                     report.pre_loan_credit_cost,
+                     report.loan_credit,
+                     report.loan_credit_cost,
+                     report.loan_credit_rate,
+                     report.in_app_uv,
+                     report.in_app_detail_uv,
+                     report.in_app_cart,
+                     report.in_app_pay,
+                     report.in_app_order,
+                     report.attribution_game_pay_7d_count,
+                     report.attribution_game_pay_7d_cost,
+                     report.attribution_active_pay_7d_per_count,
+                     report.game_pay_cost,
+                     report.game_pay_count,
+                     report.phone,
+                     report.form,
+                     report.map_search,
+                     report.button,
+                     report.`VIEW`,
+                     report.download,
+                     report.qq,
+                     report.lottery,
+                     report.vote,
+                     report.message,
+                     report.redirect,
+                     report.shopping,
+                     report.consult,
+                     report.wechat,
+                     report.phone_confirm,
+                     report.phone_connect,
+                     report.consult_effective,
+                     report.coupon,
+                     report.coupon_single_page,
+                     report.redirect_to_shop,
+                     report.poi_collect,
+                     report.poi_address_click,
+                     report.luban_order_cnt,
+                     report.luban_order_stat_amount,
+                     report.luban_order_roi,
+                     report.luban_live_enter_cnt,
+                     report.live_watch_one_minute_count,
+                     report.luban_live_follow_cnt,
+                     report.live_fans_club_join_cnt,
+                     report.luban_live_comment_cnt,
+                     report.luban_live_share_cnt,
+                     report.luban_live_gift_cnt,
+                     report.luban_live_gift_amount,
+                     report.luban_live_slidecart_click_cnt,
+                     report.luban_live_click_product_cnt,
+                     report.luban_live_pay_order_count,
+                     report.luban_live_pay_order_stat_cost,
+                     report.live_component_click_count,
+                     report.live_component_click_cost,
+                     report.live_component_click_rate,
+                     report.wechat_login_count,
+                     report.attribution_wechat_login_30d_count,
+                     report.wechat_login_cost,
+                     report.attribution_wechat_login_30d_cost,
+                     report.wechat_first_pay_count,
+                     report.attribution_wechat_first_pay_30d_count,
+                     report.wechat_first_pay_cost,
+                     report.attribution_wechat_first_pay_30d_cost,
+                     report.wechat_first_pay_rate,
+                     report.attribution_wechat_first_pay_30d_rate,
+                     report.wechat_pay_amount,
+                     report.attribution_wechat_pay_30d_amount,
+                     report.attribution_wechat_pay_30d_roi,
+                     report.phone_effective,
+                     report.total_play,
+                     report.valid_play,
+                     report.valid_play_cost,
+                     report.valid_play_rate,
+                     report.play_25_feed_break,
+                     report.play_50_feed_break,
+                     report.play_75_feed_break,
+                     report.play_100_feed_break,
+                     report.average_play_time_per_play,
+                     report.play_over_rate,
+                     report.wifi_play_rate,
+                     report.wifi_play,
+                     report.play_duration_sum,
+                     report.advanced_creative_phone_click,
+                     report.advanced_creative_counsel_click,
+                     report.advanced_creative_form_click,
+                     report.advanced_creative_coupon_addition,
+                     report.advanced_creative_form_submit,
+                     report.card_show,
+                     report.`SHARE`,
+                     report.`COMMENT`,
+                     report.`LIKE`,
+                     report.follow,
+                     report.home_visited,
+                     report.ies_challenge_click,
+                     report.ies_music_click,
+                     report.location_click,
+                     report.message_action,
+                     report.click_landing_page,
+                     report.click_shopwindow,
+                     report.click_website,
+                     report.click_download,
+                     report.click_call_dy,
+                     report.submit_certification_count,
+                     report.approval_count,
+                     report.first_rental_order_count,
+                     report.first_order_count,
+                     report.commute_first_pay_count
+                    FROM
+                     (
+                      SELECT
+                    advertiser_id account_id,
+                    campaign_id campaign_id,
+                    ad_id,
+                    ad_name,
+                       sum(cost) cost,
+                       sum(`show`) `show`,
+                       round(sum(cost) / sum(`show`), 3) avg_show_cost,
+                       sum(click) click,
+                       round(sum(cost) / sum(`click`), 3) avg_click_cost,
+                       round(
+                        sum(click) / sum(`show`) * 100,
+                        3
+                       ) ctr,
+                       sum(`convert`) `convert`,
+                       round(sum(cost) / sum(`convert`), 3) convert_cost,
+                       round(
+                        sum(`convert`) / sum(click) * 100,
+                        3
+                       ) convert_rate,
+                       sum(deep_convert) deep_convert,
+                       round(
+                        sum(cost) / sum(deep_convert),
+                        3
+                       ) deep_convert_cost,
+                       round(
+                        sum(deep_convert) / sum(`convert`) * 100,
+                        3
+                       ) deep_convert_rate,
+                       sum(attribution_convert) attribution_convert,
+                       round(
+                        sum(cost) / sum(attribution_convert),
+                        3
+                       ) attribution_convert_cost,
+                       sum(attribution_deep_convert) attribution_deep_convert,
+                       round(
+                        sum(cost) / sum(attribution_deep_convert),
+                        3
+                       ) attribution_deep_convert_cost,
+                       sum(download_start) download_start,
+                       round(
+                        sum(cost) / sum(download_start),
+                        3
+                       ) download_start_cost,
+                       round(
+                        sum(download_start) / sum(click),
+                        3
+                       ) download_start_rate,
+                       sum(download_finish) download_finish,
+                       round(
+                        sum(cost) / sum(download_finish),
+                        3
+                       ) download_finish_cost,
+                       round(
+                        sum(download_finish) / sum(download_start) * 100,
+                        3
+                       ) download_finish_rate,
+                       sum(click_install) click_install,
+                       sum(install_finish) install_finish,
+                       round(
+                        sum(cost) / sum(install_finish),
+                        3
+                       ) install_finish_cost,
+                       round(
+                        sum(install_finish) / sum(download_finish) * 100,
+                        3
+                       ) install_finish_rate,
+                       sum(active) active,
+                       round(sum(cost) / sum(active), 3) active_cost,
+                       round(
+                        sum(active) / sum(click) * 100,
+                        3
+                       ) active_rate,
+                       sum(register) register,
+                       round(sum(cost) / sum(register), 3) active_register_cost,
+                       round(
+                        sum(active_register_rate) / {day_count} * 100,
+                        3
+                       ) active_register_rate,
+                       sum(next_day_open) next_day_open,
+                       round(
+                        sum(cost) / sum(next_day_open),
+                        3
+                       ) next_day_open_cost,
+                       round(
+                        sum(next_day_open) / sum(active) * 100,
+                        3
+                       ) next_day_open_rate,
+                       sum(
+                        attribution_next_day_open_cnt
+                       ) attribution_next_day_open_cnt,
+                       round(
+                        sum(cost) / sum(
+                         attribution_next_day_open_cnt
+                        ),
+                        3
+                       ) attribution_next_day_open_cost,
+                       round(
+                        sum(
+                         attribution_next_day_open_cnt
+                        ) / sum(active) * 100,
+                        3
+                       ) attribution_next_day_open_rate,
+                       sum(game_addiction) game_addiction,
+                       round(
+                        sum(cost) / sum(game_addiction),
+                        3
+                       ) game_addiction_cost,
+                       round(
+                        sum(game_addiction_rate) / {day_count} * 100,
+                        3
+                       ) game_addiction_rate,
+                       sum(pay_count) pay_count,
+                       round(sum(cost) / sum(pay_count), 3) active_pay_cost,
+                       round(
+                        sum(pay_count) / sum(active) * 100,
+                        3
+                       ) active_pay_rate,
+                       sum(loan_completion) loan_completion,
+                       round(
+                        sum(cost) / sum(loan_completion),
+                        3
+                       ) loan_completion_cost,
+                       round(
+                        sum(loan_completion) / sum(register) * 100,
+                        3
+                       ) loan_completion_rate,
+                       round(sum(pre_loan_credit), 3) pre_loan_credit,
+                       round(
+                        sum(cost) / sum(pre_loan_credit),
+                        3
+                       ) pre_loan_credit_cost,
+                       sum(loan_credit) loan_credit,
+                       round(
+                        sum(cost) / sum(loan_credit),
+                        3
+                       ) loan_credit_cost,
+                       round(
+                        sum(loan_credit) / sum(loan_completion) * 100,
+                        3
+                       ) loan_credit_rate,
+                       sum(in_app_uv) in_app_uv,
+                       sum(in_app_detail_uv) in_app_detail_uv,
+                       sum(in_app_cart) in_app_cart,
+                       sum(in_app_pay) in_app_pay,
+                       sum(in_app_order) in_app_order,
+                       round(
+                        sum(
+                         attribution_game_pay_7d_count
+                        ) / {day_count},
+                        3
+                       ) attribution_game_pay_7d_count,
+                       round(
+                        sum(
+                         attribution_game_pay_7d_cost
+                        ) / {day_count},
+                        3
+                       ) attribution_game_pay_7d_cost,
+                       round(
+                        sum(
+                         attribution_active_pay_7d_per_count
+                        ) / {day_count},
+                        3
+                       ) attribution_active_pay_7d_per_count,
+                       sum(game_pay_cost) game_pay_cost,
+                       sum(game_pay_count) game_pay_count,
+                       sum(phone) phone,
+                       sum(form) form,
+                       sum(map_search) map_search,
+                       sum(button) button,
+                       sum(`view`) `view`,
+                       sum(download) download,
+                       sum(qq) qq,
+                       sum(lottery) lottery,
+                       sum(vote) vote,
+                       sum(message) message,
+                       sum(redirect) redirect,
+                       sum(shopping) shopping,
+                       sum(consult) consult,
+                       sum(wechat) wechat,
+                       sum(phone_confirm) phone_confirm,
+                       sum(phone_connect) phone_connect,
+                       sum(consult_effective) consult_effective,
+                       sum(coupon) coupon,
+                       sum(coupon_single_page) coupon_single_page,
+                       sum(redirect_to_shop) redirect_to_shop,
+                       sum(poi_collect) poi_collect,
+                       sum(poi_address_click) poi_address_click,
+                       sum(luban_order_cnt) luban_order_cnt,
+                       sum(luban_order_stat_amount) luban_order_stat_amount,
+                       sum(luban_order_roi) luban_order_roi,
+                       sum(luban_live_enter_cnt) luban_live_enter_cnt,
+                       sum(
+                        live_watch_one_minute_count
+                       ) live_watch_one_minute_count,
+                       sum(luban_live_follow_cnt) luban_live_follow_cnt,
+                       sum(live_fans_club_join_cnt) live_fans_club_join_cnt,
+                       sum(luban_live_comment_cnt) luban_live_comment_cnt,
+                       sum(luban_live_share_cnt) luban_live_share_cnt,
+                       sum(luban_live_gift_cnt) luban_live_gift_cnt,
+                       sum(luban_live_gift_amount) luban_live_gift_amount,
+                       sum(
+                        luban_live_slidecart_click_cnt
+                       ) luban_live_slidecart_click_cnt,
+                       sum(
+                        luban_live_click_product_cnt
+                       ) luban_live_click_product_cnt,
+                       sum(luban_live_pay_order_count) luban_live_pay_order_count,
+                       sum(
+                        luban_live_pay_order_stat_cost
+                       ) luban_live_pay_order_stat_cost,
+                       sum(live_component_click_count) live_component_click_count,
+                       round(
+                        sum(cost) / sum(live_component_click_count),
+                        3
+                       ) live_component_click_cost,
+                       round(
+                        sum(live_component_click_count) / {day_count} * 100,
+                        3
+                       ) live_component_click_rate,
+                       sum(wechat_login_count) wechat_login_count,
+                       sum(
+                        attribution_wechat_login_30d_count
+                       ) attribution_wechat_login_30d_count,
+                       round(
+                        sum(cost) / sum(wechat_login_count),
+                        3
+                       ) wechat_login_cost,
+                       round(
+                        sum(cost) / sum(
+                         attribution_wechat_login_30d_count
+                        ),
+                        3
+                       ) attribution_wechat_login_30d_cost,
+                       sum(wechat_first_pay_count) wechat_first_pay_count,
+                       sum(
+                        attribution_wechat_first_pay_30d_count
+                       ) attribution_wechat_first_pay_30d_count,
+                       round(
+                        sum(cost) / sum(wechat_first_pay_count),
+                        3
+                       ) wechat_first_pay_cost,
+                       round(
+                        sum(cost) / sum(
+                         attribution_wechat_first_pay_30d_count
+                        ),
+                        3
+                       ) attribution_wechat_first_pay_30d_cost,
+                       round(
+                        sum(wechat_first_pay_count) / sum(wechat_login_count) * 100,
+                        3
+                       ) wechat_first_pay_rate,
+                       round(
+                        sum(
+                         attribution_wechat_first_pay_30d_count
+                        ) / sum(
+                         attribution_wechat_login_30d_count
+                        ) * 100,
+                        3
+                       ) attribution_wechat_first_pay_30d_rate,
+                       sum(wechat_pay_amount) wechat_pay_amount,
+                       sum(
+                        attribution_wechat_pay_30d_amount
+                       ) attribution_wechat_pay_30d_amount,
+                       sum(
+                        attribution_wechat_pay_30d_roi
+                       ) attribution_wechat_pay_30d_roi,
+                       sum(phone_effective) phone_effective,
+                       sum(total_play) total_play,
+                       sum(valid_play) valid_play,
+                       round(
+                        sum(cost) / sum(valid_play),
+                        3
+                       ) valid_play_cost,
+                       round(
+                        sum(valid_play) / sum(`show`) * 100,
+                        3
+                       ) valid_play_rate,
+                       sum(play_25_feed_break) play_25_feed_break,
+                       sum(play_50_feed_break) play_50_feed_break,
+                       sum(play_75_feed_break) play_75_feed_break,
+                       sum(play_100_feed_break) play_100_feed_break,
+                       round(
+                        sum(average_play_time_per_play) / {day_count},
+                        3
+                       ) average_play_time_per_play,
+                       round(
+                        sum(play_over_rate) / {day_count} * 100,
+                        3
+                       ) play_over_rate,
+                       round(
+                        sum(wifi_play) / sum(total_play) * 100,
+                        3
+                       ) wifi_play_rate,
+                       sum(wifi_play) wifi_play,
+                       round(sum(play_duration_sum) / {day_count}, 3) play_duration_sum,
+                       sum(
+                        advanced_creative_phone_click
+                       ) advanced_creative_phone_click,
+                       sum(
+                        advanced_creative_counsel_click
+                       ) advanced_creative_counsel_click,
+                       sum(
+                        advanced_creative_form_click
+                       ) advanced_creative_form_click,
+                       sum(
+                        advanced_creative_coupon_addition
+                       ) advanced_creative_coupon_addition,
+                       sum(
+                        advanced_creative_form_submit
+                       ) advanced_creative_form_submit,
+                       sum(card_show) card_show,
+                       sum(`share`) `share`,
+                       sum(`comment`) `comment`,
+                       sum(`like`) `like`,
+                       sum(follow) follow,
+                       sum(home_visited) home_visited,
+                       sum(ies_challenge_click) ies_challenge_click,
+                       sum(ies_music_click) ies_music_click,
+                       sum(location_click) location_click,
+                       sum(message_action) message_action,
+                       sum(click_landing_page) click_landing_page,
+                       sum(click_shopwindow) click_shopwindow,
+                       sum(click_website) click_website,
+                       sum(click_download) click_download,
+                       sum(click_call_dy) click_call_dy,
+                       sum(submit_certification_count) submit_certification_count,
+                       sum(approval_count) approval_count,
+                       sum(first_order_count) first_rental_order_count,
+                       sum(first_rental_order_count) first_order_count,
+                       sum(commute_first_pay_count) commute_first_pay_count
+                      FROM
+                       `media_api`.bytedance_ad_report_daily
+                      WHERE
+                       stat_datetime >= date_format(
+                        date_sub({date_time}, INTERVAL {day_count} DAY),
+                        '%Y%m%d'
+                       )
+                      GROUP BY
+                    advertiser_id,
+                    campaign_id,
+                    ad_id,
+                    ad_name
+                     ) report
+                    LEFT JOIN (
+                     SELECT
+                      cua.account_id id,
+                      cua.account_id account_id,
+                      cp.id project_id,
+                      product.id product_id,
+                      ca.id advertiser_id,
+                      uc.company_id company_id,
+                      cua.auth_name account_name,
+                      cp.project_name project_name,
+                      ca.`name` advertiser_name,
+                      uc.company_name company_name,
+                      cp.sale_id sale_id,
+                      su.id user_id,
+                      su.leader_id,
+                      su.org_code org_code
+                     FROM
+                      `jeecg-boot`.ctop_user_allocation cua
+                     LEFT JOIN `jeecg-boot`.ctop_project cp ON cua.project_id = cp.id
+                     LEFT JOIN `jeecg-boot`.ctop_advertiser ca ON ca.id = cua.advertiser_id
+                     LEFT JOIN `jeecg-boot`.sys_user su ON su.id = cua.user_id
+                     LEFT JOIN `jeecg-boot`.user_company uc ON uc.user_id = cua.user_id
+                     LEFT JOIN `jeecg-boot`.ctop_product product ON product.id = cp.product_id
+                     WHERE
+                      cua.account_id IS NOT NULL
+                    ) bei ON report.account_id = bei.account_id
+                    where bei.project_id={project_id}""".format(date_time=self.date_time,
+                                                                day_count=self.day_count, project_id=project_id[0])
+                    print(sql)
+                    TidbConn.upsert(conn=self.conn, sql_buff=sql)
+                    self.conn.commit()
+                except Exception as e:
+                    logging.error(e)
+                    return -1
+            TidbConn.conn_close(conn=self.conn)
+            return 0
+        except Exception as e:
+            logging.error(e)
+            return -1
+
+
+if __name__ == '__main__':
+    status = AppBytedanceAdReportBusiMonth().taskHandler()
+    if status == 0:
+        print("作业执行成功")
+        exit(0)
+    else:
+        print("作业执行失败")
+        exit(-1)

+ 2 - 2
Apietl/bytedance_etl/Q4Task/AppBytedanceAdvertiserReportBusi.py

@@ -24,7 +24,7 @@ class AppBytedanceAdReportBusi:
             sql = """
             SET sql_mode = 'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
 REPLACE INTO application.app_bytedance_advertiser_report_busi_{day_count}d
-SELECT concat(date_format(date_sub({date_time}, INTERVAL 6 DAY),'%Y%m%d'),'-',{date_time})  start_end_time,
+SELECT concat(date_format(date_sub({date_time}, INTERVAL ({day_count} -1)  DAY),'%Y%m%d'),'-',{date_time})  start_end_time,
        report.account_id,
        bei.project_id      project_id,
        bei.product_id      product_id,
@@ -522,7 +522,7 @@ FROM (
                 sum(commute_first_pay_count)         commute_first_pay_count
          FROM `media_api`.bytedance_advertiser_report_daily
          WHERE stat_datetime >= date_format(
-                 date_sub({date_time}, INTERVAL 6 DAY),
+                 date_sub({date_time}, INTERVAL ({day_count} -1)  DAY),
                  '%Y%m%d'
              )
          GROUP BY advertiser_id

+ 570 - 0
Apietl/bytedance_etl/Q4Task/AppBytedanceAdvertiserReportBusiMonth.py

@@ -0,0 +1,570 @@
+# Author renyupeng
+# coding=utf-8
+# @Time    : 2021/11/10 3:37 下午
+# @Site    : 
+# @File    : AppBytedanceAdvertiserReportBusiMonth.py
+# @Software: PyCharm
+# @contact: renyupeng@c-top.com.cn
+# @Tel 1501435553
+import logging
+
+from Apietl.conn.TidbConn import TidbConn
+from Apietl.utlis.Utils import Utils
+
+
+class AppBytedanceAdvertiserReportBusiMonth:
+    def __init__(self):
+        self.conn = TidbConn.get_connection()
+        self.parm = Utils.get_task_args()
+        self.date_time = self.parm[0]
+        self.day_count = Utils.get_days()
+
+    def taskHandler(self):
+        try:
+            sql = """
+            SET sql_mode = 'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
+REPLACE INTO application.app_bytedance_advertiser_report_busi_m
+SELECT date_format({date_time},'%Y%m') as stat_mon,
+       report.account_id,
+       bei.project_id      project_id,
+       bei.product_id      product_id,
+       bei.advertiser_id   advertiser_id,
+       bei.company_id      company_id,
+       bei.account_name    account_name,
+       bei.project_name    project_name,
+       bei.advertiser_name advertiser_name,
+       bei.company_name    company_name,
+       bei.sale_id         sale_id,
+       bei.user_id         user_id,
+       bei.leader_id       leader_id,
+       bei.org_code        org_code,
+       report.cost,
+       report.`show`,
+       report.avg_show_cost,
+       report.click,
+       report.avg_click_cost,
+       report.ctr,
+       report.`convert`,
+       report.convert_cost,
+       report.convert_rate,
+       report.deep_convert,
+       report.deep_convert_cost,
+       report.deep_convert_rate,
+       report.attribution_convert,
+       report.attribution_convert_cost,
+       report.attribution_deep_convert,
+       report.attribution_deep_convert_cost,
+       report.download_start,
+       report.download_start_cost,
+       report.download_start_rate,
+       report.download_finish,
+       report.download_finish_cost,
+       report.download_finish_rate,
+       report.click_install,
+       report.install_finish,
+       report.install_finish_cost,
+       report.install_finish_rate,
+       report.active,
+       report.active_cost,
+       report.active_rate,
+       report.register,
+       report.active_register_cost,
+       report.active_register_rate,
+       report.next_day_open,
+       report.next_day_open_cost,
+       report.next_day_open_rate,
+       report.attribution_next_day_open_cnt,
+       report.attribution_next_day_open_cost,
+       report.attribution_next_day_open_rate,
+       report.game_addiction,
+       report.game_addiction_cost,
+       report.game_addiction_rate,
+       report.pay_count,
+       report.active_pay_cost,
+       report.active_pay_rate,
+       report.loan_completion,
+       report.loan_completion_cost,
+       report.loan_completion_rate,
+       report.pre_loan_credit,
+       report.pre_loan_credit_cost,
+       report.loan_credit,
+       report.loan_credit_cost,
+       report.loan_credit_rate,
+       report.in_app_uv,
+       report.in_app_detail_uv,
+       report.in_app_cart,
+       report.in_app_pay,
+       report.in_app_order,
+       report.attribution_game_pay_7d_count,
+       report.attribution_game_pay_7d_cost,
+       report.attribution_active_pay_7d_per_count,
+       report.game_pay_cost,
+       report.game_pay_count,
+       report.phone,
+       report.form,
+       report.map_search,
+       report.button,
+       report.`view`,
+       report.download,
+       report.qq,
+       report.lottery,
+       report.vote,
+       report.message,
+       report.redirect,
+       report.shopping,
+       report.consult,
+       report.wechat,
+       report.phone_confirm,
+       report.phone_connect,
+       report.consult_effective,
+       report.coupon,
+       report.coupon_single_page,
+       report.redirect_to_shop,
+       report.poi_collect,
+       report.poi_address_click,
+       report.luban_order_cnt,
+       report.luban_order_stat_amount,
+       report.luban_order_roi,
+       report.luban_live_enter_cnt,
+       report.live_watch_one_minute_count,
+       report.luban_live_follow_cnt,
+       report.live_fans_club_join_cnt,
+       report.luban_live_comment_cnt,
+       report.luban_live_share_cnt,
+       report.luban_live_gift_cnt,
+       report.luban_live_gift_amount,
+       report.luban_live_slidecart_click_cnt,
+       report.luban_live_click_product_cnt,
+       report.luban_live_pay_order_count,
+       report.luban_live_pay_order_stat_cost,
+       report.live_component_click_count,
+       report.live_component_click_cost,
+       report.live_component_click_rate,
+       report.wechat_login_count,
+       report.attribution_wechat_login_30d_count,
+       report.wechat_login_cost,
+       report.attribution_wechat_login_30d_cost,
+       report.wechat_first_pay_count,
+       report.attribution_wechat_first_pay_30d_count,
+       report.wechat_first_pay_cost,
+       report.attribution_wechat_first_pay_30d_cost,
+       report.wechat_first_pay_rate,
+       report.attribution_wechat_first_pay_30d_rate,
+       report.wechat_pay_amount,
+       report.attribution_wechat_pay_30d_amount,
+       report.attribution_wechat_pay_30d_roi,
+       report.phone_effective,
+       report.total_play,
+       report.valid_play,
+       report.valid_play_cost,
+       report.valid_play_rate,
+       report.play_25_feed_break,
+       report.play_50_feed_break,
+       report.play_75_feed_break,
+       report.play_100_feed_break,
+       report.average_play_time_per_play,
+       report.play_over_rate,
+       report.wifi_play_rate,
+       report.wifi_play,
+       report.play_duration_sum,
+       report.advanced_creative_phone_click,
+       report.advanced_creative_counsel_click,
+       report.advanced_creative_form_click,
+       report.advanced_creative_coupon_addition,
+       report.advanced_creative_form_submit,
+       report.card_show,
+       report.`share`,
+       report.`comment`,
+       report.`like`,
+       report.follow,
+       report.home_visited,
+       report.ies_challenge_click,
+       report.ies_music_click,
+       report.location_click,
+       report.message_action,
+       report.click_landing_page,
+       report.click_shopwindow,
+       report.click_website,
+       report.click_download,
+       report.click_call_dy,
+       report.submit_certification_count,
+       report.approval_count,
+       report.first_rental_order_count,
+       report.first_order_count,
+       report.commute_first_pay_count
+FROM (
+         SELECT advertiser_id                        account_id,
+                sum(cost)                            cost,
+                sum(`show`)                          `show`,
+                round(sum(cost) / sum(`show`), 3)    avg_show_cost,
+                sum(click)                           click,
+                round(sum(cost) / sum(`click`), 3)   avg_click_cost,
+                round(
+                        sum(click) / sum(`show`) * 100,
+                        3
+                    )                                ctr,
+                sum(`convert`)                       `convert`,
+                round(sum(cost) / sum(`convert`), 3) convert_cost,
+                round(
+                        sum(`convert`) / sum(click) * 100,
+                        3
+                    )                                convert_rate,
+                sum(deep_convert)                    deep_convert,
+                round(
+                        sum(cost) / sum(deep_convert),
+                        3
+                    )                                deep_convert_cost,
+                round(
+                        sum(deep_convert) / sum(`convert`) * 100,
+                        3
+                    )                                deep_convert_rate,
+                sum(attribution_convert)             attribution_convert,
+                round(
+                        sum(cost) / sum(attribution_convert),
+                        3
+                    )                                attribution_convert_cost,
+                sum(attribution_deep_convert)        attribution_deep_convert,
+                round(
+                        sum(cost) / sum(attribution_deep_convert),
+                        3
+                    )                                attribution_deep_convert_cost,
+                sum(download_start)                  download_start,
+                round(
+                        sum(cost) / sum(download_start),
+                        3
+                    )                                download_start_cost,
+                round(
+                        sum(download_start) / sum(click),
+                        3
+                    )                                download_start_rate,
+                sum(download_finish)                 download_finish,
+                round(
+                        sum(cost) / sum(download_finish),
+                        3
+                    )                                download_finish_cost,
+                round(
+                        sum(download_finish) / sum(download_start) * 100,
+                        3
+                    )                                download_finish_rate,
+                sum(click_install)                   click_install,
+                sum(install_finish)                  install_finish,
+                round(
+                        sum(cost) / sum(install_finish),
+                        3
+                    )                                install_finish_cost,
+                round(
+                        sum(install_finish) / sum(download_finish) * 100,
+                        3
+                    )                                install_finish_rate,
+                sum(active)                          active,
+                round(sum(cost) / sum(active), 3)    active_cost,
+                round(
+                        sum(active) / sum(click) * 100,
+                        3
+                    )                                active_rate,
+                sum(register)                        register,
+                round(sum(cost) / sum(register), 3)  active_register_cost,
+                round(
+                        sum(active_register_rate) /{day_count} * 100,
+                        3
+                    )                                active_register_rate,
+                sum(next_day_open)                   next_day_open,
+                round(
+                        sum(cost) / sum(next_day_open),
+                        3
+                    )                                next_day_open_cost,
+                round(
+                        sum(next_day_open) / sum(active) * 100,
+                        3
+                    )                                next_day_open_rate,
+                sum(
+                        attribution_next_day_open_cnt
+                    )                                attribution_next_day_open_cnt,
+                round(
+                            sum(cost) / sum(
+                                attribution_next_day_open_cnt
+                            ),
+                            3
+                    )                                attribution_next_day_open_cost,
+                round(
+                                sum(
+                                        attribution_next_day_open_cnt
+                                    ) / sum(active) * 100,
+                                3
+                    )                                attribution_next_day_open_rate,
+                sum(game_addiction)                  game_addiction,
+                round(
+                        sum(cost) / sum(game_addiction),
+                        3
+                    )                                game_addiction_cost,
+                round(
+                        sum(game_addiction_rate) /{day_count} * 100,
+                        3
+                    )                                game_addiction_rate,
+                sum(pay_count)                       pay_count,
+                round(sum(cost) / sum(pay_count), 3) active_pay_cost,
+                round(
+                        sum(pay_count) / sum(active) * 100,
+                        3
+                    )                                active_pay_rate,
+                sum(loan_completion)                 loan_completion,
+                round(
+                        sum(cost) / sum(loan_completion),
+                        3
+                    )                                loan_completion_cost,
+                round(
+                        sum(loan_completion) / sum(register) * 100,
+                        3
+                    )                                loan_completion_rate,
+                round(sum(pre_loan_credit), 3)       pre_loan_credit,
+                round(
+                        sum(cost) / sum(pre_loan_credit),
+                        3
+                    )                                pre_loan_credit_cost,
+                sum(loan_credit)                     loan_credit,
+                round(
+                        sum(cost) / sum(loan_credit),
+                        3
+                    )                                loan_credit_cost,
+                round(
+                        sum(loan_credit) / sum(loan_completion) * 100,
+                        3
+                    )                                loan_credit_rate,
+                sum(in_app_uv)                       in_app_uv,
+                sum(in_app_detail_uv)                in_app_detail_uv,
+                sum(in_app_cart)                     in_app_cart,
+                sum(in_app_pay)                      in_app_pay,
+                sum(in_app_order)                    in_app_order,
+                round(
+                            sum(
+                                    attribution_game_pay_7d_count
+                                ) /{day_count},
+                            3
+                    )                                attribution_game_pay_7d_count,
+                round(
+                            sum(
+                                    attribution_game_pay_7d_cost
+                                ) /{day_count},
+                            3
+                    )                                attribution_game_pay_7d_cost,
+                round(
+                            sum(
+                                    attribution_active_pay_7d_per_count
+                                ) /{day_count},
+                            3
+                    )                                attribution_active_pay_7d_per_count,
+                sum(game_pay_cost)                   game_pay_cost,
+                sum(game_pay_count)                  game_pay_count,
+                sum(phone)                           phone,
+                sum(form)                            form,
+                sum(map_search)                      map_search,
+                sum(button)                          button,
+                sum(`view`)                          `view`,
+                sum(download)                        download,
+                sum(qq)                              qq,
+                sum(lottery)                         lottery,
+                sum(vote)                            vote,
+                sum(message)                         message,
+                sum(redirect)                        redirect,
+                sum(shopping)                        shopping,
+                sum(consult)                         consult,
+                sum(wechat)                          wechat,
+                sum(phone_confirm)                   phone_confirm,
+                sum(phone_connect)                   phone_connect,
+                sum(consult_effective)               consult_effective,
+                sum(coupon)                          coupon,
+                sum(coupon_single_page)              coupon_single_page,
+                sum(redirect_to_shop)                redirect_to_shop,
+                sum(poi_collect)                     poi_collect,
+                sum(poi_address_click)               poi_address_click,
+                sum(luban_order_cnt)                 luban_order_cnt,
+                sum(luban_order_stat_amount)         luban_order_stat_amount,
+                sum(luban_order_roi)                 luban_order_roi,
+                sum(luban_live_enter_cnt)            luban_live_enter_cnt,
+                sum(
+                        live_watch_one_minute_count
+                    )                                live_watch_one_minute_count,
+                sum(luban_live_follow_cnt)           luban_live_follow_cnt,
+                sum(live_fans_club_join_cnt)         live_fans_club_join_cnt,
+                sum(luban_live_comment_cnt)          luban_live_comment_cnt,
+                sum(luban_live_share_cnt)            luban_live_share_cnt,
+                sum(luban_live_gift_cnt)             luban_live_gift_cnt,
+                sum(luban_live_gift_amount)          luban_live_gift_amount,
+                sum(
+                        luban_live_slidecart_click_cnt
+                    )                                luban_live_slidecart_click_cnt,
+                sum(
+                        luban_live_click_product_cnt
+                    )                                luban_live_click_product_cnt,
+                sum(luban_live_pay_order_count)      luban_live_pay_order_count,
+                sum(
+                        luban_live_pay_order_stat_cost
+                    )                                luban_live_pay_order_stat_cost,
+                sum(live_component_click_count)      live_component_click_count,
+                round(
+                        sum(cost) / sum(live_component_click_count),
+                        3
+                    )                                live_component_click_cost,
+                round(
+                        sum(live_component_click_count) /{day_count} * 100,
+                        3
+                    )                                live_component_click_rate,
+                sum(wechat_login_count)              wechat_login_count,
+                sum(
+                        attribution_wechat_login_30d_count
+                    )                                attribution_wechat_login_30d_count,
+                round(
+                        sum(cost) / sum(wechat_login_count),
+                        3
+                    )                                wechat_login_cost,
+                round(
+                            sum(cost) / sum(
+                                attribution_wechat_login_30d_count
+                            ),
+                            3
+                    )                                attribution_wechat_login_30d_cost,
+                sum(wechat_first_pay_count)          wechat_first_pay_count,
+                sum(
+                        attribution_wechat_first_pay_30d_count
+                    )                                attribution_wechat_first_pay_30d_count,
+                round(
+                        sum(cost) / sum(wechat_first_pay_count),
+                        3
+                    )                                wechat_first_pay_cost,
+                round(
+                            sum(cost) / sum(
+                                attribution_wechat_first_pay_30d_count
+                            ),
+                            3
+                    )                                attribution_wechat_first_pay_30d_cost,
+                round(
+                        sum(wechat_first_pay_count) / sum(wechat_login_count) * 100,
+                        3
+                    )                                wechat_first_pay_rate,
+                round(
+                                sum(
+                                        attribution_wechat_first_pay_30d_count
+                                    ) / sum(
+                                        attribution_wechat_login_30d_count
+                                    ) * 100,
+                                3
+                    )                                attribution_wechat_first_pay_30d_rate,
+                sum(wechat_pay_amount)               wechat_pay_amount,
+                sum(
+                        attribution_wechat_pay_30d_amount
+                    )                                attribution_wechat_pay_30d_amount,
+                sum(
+                        attribution_wechat_pay_30d_roi
+                    )                                attribution_wechat_pay_30d_roi,
+                sum(phone_effective)                 phone_effective,
+                sum(total_play)                      total_play,
+                sum(valid_play)                      valid_play,
+                round(
+                        sum(cost) / sum(valid_play),
+                        3
+                    )                                valid_play_cost,
+                round(
+                        sum(valid_play) / sum(`show`) * 100,
+                        3
+                    )                                valid_play_rate,
+                sum(play_25_feed_break)              play_25_feed_break,
+                sum(play_50_feed_break)              play_50_feed_break,
+                sum(play_75_feed_break)              play_75_feed_break,
+                sum(play_100_feed_break)             play_100_feed_break,
+                round(
+                        sum(average_play_time_per_play) /{day_count},
+                        3
+                    )                                average_play_time_per_play,
+                round(
+                        sum(play_over_rate) /{day_count} * 100,
+                        3
+                    )                                play_over_rate,
+                round(
+                        sum(wifi_play) / sum(total_play) * 100,
+                        3
+                    )                                wifi_play_rate,
+                sum(wifi_play)                       wifi_play,
+                round(sum(play_duration_sum) /{day_count}, 3) play_duration_sum,
+                sum(
+                        advanced_creative_phone_click
+                    )                                advanced_creative_phone_click,
+                sum(
+                        advanced_creative_counsel_click
+                    )                                advanced_creative_counsel_click,
+                sum(
+                        advanced_creative_form_click
+                    )                                advanced_creative_form_click,
+                sum(
+                        advanced_creative_coupon_addition
+                    )                                advanced_creative_coupon_addition,
+                sum(
+                        advanced_creative_form_submit
+                    )                                advanced_creative_form_submit,
+                sum(card_show)                       card_show,
+                sum(`share`)                         `share`,
+                sum(`comment`)                       `comment`,
+                sum(`like`)                          `like`,
+                sum(follow)                          follow,
+                sum(home_visited)                    home_visited,
+                sum(ies_challenge_click)             ies_challenge_click,
+                sum(ies_music_click)                 ies_music_click,
+                sum(location_click)                  location_click,
+                sum(message_action)                  message_action,
+                sum(click_landing_page)              click_landing_page,
+                sum(click_shopwindow)                click_shopwindow,
+                sum(click_website)                   click_website,
+                sum(click_download)                  click_download,
+                sum(click_call_dy)                   click_call_dy,
+                sum(submit_certification_count)      submit_certification_count,
+                sum(approval_count)                  approval_count,
+                sum(first_order_count)               first_rental_order_count,
+                sum(first_rental_order_count)        first_order_count,
+                sum(commute_first_pay_count)         commute_first_pay_count
+         FROM `media_api`.bytedance_advertiser_report_daily
+         WHERE stat_datetime >= date_format(
+                 date_sub({date_time}, INTERVAL {day_count}  DAY),
+                 '%Y%m%d'
+             )
+         GROUP BY advertiser_id
+     ) report
+         LEFT JOIN (
+    SELECT cua.account_id  id,
+           cua.account_id  account_id,
+           cp.id           project_id,
+           product.id      product_id,
+           ca.id           advertiser_id,
+           uc.company_id   company_id,
+           cua.auth_name   account_name,
+           cp.project_name project_name,
+           ca.`name`       advertiser_name,
+           uc.company_name company_name,
+           cp.sale_id      sale_id,
+           su.id           user_id,
+           su.leader_id,
+           su.org_code     org_code
+    FROM `jeecg-boot`.ctop_user_allocation cua
+             LEFT JOIN `jeecg-boot`.ctop_project cp ON cua.project_id = cp.id
+             LEFT JOIN `jeecg-boot`.ctop_advertiser ca ON ca.id = cua.advertiser_id
+             LEFT JOIN `jeecg-boot`.sys_user su ON su.id = cua.user_id
+             LEFT JOIN `jeecg-boot`.user_company uc ON uc.user_id = cua.user_id
+             LEFT JOIN `jeecg-boot`.ctop_product product ON product.id = cp.product_id
+    WHERE cua.account_id IS NOT NULL
+) bei ON report.account_id = bei.account_id;
+            """.format(date_time=self.date_time, day_count=self.day_count)
+            TidbConn.upsert(conn=self.conn, sql_buff=sql)
+            self.conn.commit()
+            TidbConn.conn_close(conn=self.conn)
+            return 0
+        except Exception as e:
+            logging.error(e)
+            return -1
+
+
+if __name__ == '__main__':
+    status = AppBytedanceAdvertiserReportBusiMonth().taskHandler()
+    if status == 0:
+        print("作业执行成功")
+        exit(0)
+    else:
+        print("作业执行失败")
+        exit(-1)

+ 2 - 2
Apietl/bytedance_etl/Q4Task/AppBytedanceCampaignReportBusi.py

@@ -23,7 +23,7 @@ class AppBytedanceCampaignReportBusi:
         try:
             sql = """SET sql_mode = 'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
 REPLACE INTO application.app_bytedance_campaign_report_busi_{day_count}d 
-SELECT concat(date_format(date_sub({date_time}, INTERVAL 6 DAY),'%Y%m%d'),'-',{date_time}) start_end_time,
+SELECT concat(date_format(date_sub({date_time}, INTERVAL ({day_count} -1)  DAY),'%Y%m%d'),'-',{date_time}) start_end_time,
 report.account_id,
  report.campaign_id,
  report.campaign_name,
@@ -529,7 +529,7 @@ FROM
    `media_api`.bytedance_campaign_report_daily
   WHERE
    stat_datetime >= date_format(
-    date_sub({date_time}, INTERVAL 6 DAY),
+    date_sub({date_time}, INTERVAL ({day_count} -1)  DAY),
     '%Y%m%d'
    )
   GROUP BY

+ 582 - 0
Apietl/bytedance_etl/Q4Task/AppBytedanceCampaignReportBusiMonth.py

@@ -0,0 +1,582 @@
+# Author renyupeng
+# coding=utf-8
+# @Time    : 2021/11/10 3:37 下午
+# @Site    : 
+# @File    : AppBytedanceCampaignReportBusiMonth.py
+# @Software: PyCharm
+# @contact: renyupeng@c-top.com.cn
+# @Tel 1501435553
+import logging
+
+from Apietl.conn.TidbConn import TidbConn
+from Apietl.utlis.Utils import Utils
+
+
+class AppBytedanceCampaignReportBusiMonth:
+    def __init__(self):
+        self.conn = TidbConn.get_connection()
+        self.parm = Utils.get_task_args()
+        self.date_time = self.parm[0]
+        self.day_count = Utils.get_days()
+
+    def taskHandler(self):
+        try:
+            sql = """SET sql_mode = 'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
+REPLACE INTO application.app_bytedance_campaign_report_busi_m
+SELECT date_format({date_time},'%Y%m%d'), start_end_time,
+report.account_id,
+ report.campaign_id,
+ report.campaign_name,
+ bei.project_id project_id,
+ bei.product_id product_id,
+ bei.advertiser_id advertiser_id,
+ bei.company_id company_id,
+ bei.account_name account_name,
+ bei.project_name project_name,
+ bei.advertiser_name advertiser_name,
+ bei.company_name company_name,
+ bei.sale_id sale_id,
+ bei.user_id user_id,
+ bei.leader_id leader_id,
+ bei.org_code org_code,
+ report.cost,
+ report. `SHOW`,
+ report.avg_show_cost,
+ report.click,
+ report.avg_click_cost,
+ report.ctr,
+ report. `CONVERT`,
+ report.convert_cost,
+ report.convert_rate,
+ report.deep_convert,
+ report.deep_convert_cost,
+ report.deep_convert_rate,
+ report.attribution_convert,
+ report.attribution_convert_cost,
+ report.attribution_deep_convert,
+ report.attribution_deep_convert_cost,
+ report.download_start,
+ report.download_start_cost,
+ report.download_start_rate,
+ report.download_finish,
+ report.download_finish_cost,
+ report.download_finish_rate,
+ report.click_install,
+ report.install_finish,
+ report.install_finish_cost,
+ report.install_finish_rate,
+ report.active,
+ report.active_cost,
+ report.active_rate,
+ report.register,
+ report.active_register_cost,
+ report.active_register_rate,
+ report.next_day_open,
+ report.next_day_open_cost,
+ report.next_day_open_rate,
+ report.attribution_next_day_open_cnt,
+ report.attribution_next_day_open_cost,
+ report.attribution_next_day_open_rate,
+ report.game_addiction,
+ report.game_addiction_cost,
+ report.game_addiction_rate,
+ report.pay_count,
+ report.active_pay_cost,
+ report.active_pay_rate,
+ report.loan_completion,
+ report.loan_completion_cost,
+ report.loan_completion_rate,
+ report.pre_loan_credit,
+ report.pre_loan_credit_cost,
+ report.loan_credit,
+ report.loan_credit_cost,
+ report.loan_credit_rate,
+ report.in_app_uv,
+ report.in_app_detail_uv,
+ report.in_app_cart,
+ report.in_app_pay,
+ report.in_app_order,
+ report.attribution_game_pay_7d_count,
+ report.attribution_game_pay_7d_cost,
+ report.attribution_active_pay_7d_per_count,
+ report.game_pay_cost,
+ report.game_pay_count,
+ report.phone,
+ report.form,
+ report.map_search,
+ report.button,
+ report.`VIEW`,
+ report.download,
+ report.qq,
+ report.lottery,
+ report.vote,
+ report.message,
+ report.redirect,
+ report.shopping,
+ report.consult,
+ report.wechat,
+ report.phone_confirm,
+ report.phone_connect,
+ report.consult_effective,
+ report.coupon,
+ report.coupon_single_page,
+ report.redirect_to_shop,
+ report.poi_collect,
+ report.poi_address_click,
+ report.luban_order_cnt,
+ report.luban_order_stat_amount,
+ report.luban_order_roi,
+ report.luban_live_enter_cnt,
+ report.live_watch_one_minute_count,
+ report.luban_live_follow_cnt,
+ report.live_fans_club_join_cnt,
+ report.luban_live_comment_cnt,
+ report.luban_live_share_cnt,
+ report.luban_live_gift_cnt,
+ report.luban_live_gift_amount,
+ report.luban_live_slidecart_click_cnt,
+ report.luban_live_click_product_cnt,
+ report.luban_live_pay_order_count,
+ report.luban_live_pay_order_stat_cost,
+ report.live_component_click_count,
+ report.live_component_click_cost,
+ report.live_component_click_rate,
+ report.wechat_login_count,
+ report.attribution_wechat_login_30d_count,
+ report.wechat_login_cost,
+ report.attribution_wechat_login_30d_cost,
+ report.wechat_first_pay_count,
+ report.attribution_wechat_first_pay_30d_count,
+ report.wechat_first_pay_cost,
+ report.attribution_wechat_first_pay_30d_cost,
+ report.wechat_first_pay_rate,
+ report.attribution_wechat_first_pay_30d_rate,
+ report.wechat_pay_amount,
+ report.attribution_wechat_pay_30d_amount,
+ report.attribution_wechat_pay_30d_roi,
+ report.phone_effective,
+ report.total_play,
+ report.valid_play,
+ report.valid_play_cost,
+ report.valid_play_rate,
+ report.play_25_feed_break,
+ report.play_50_feed_break,
+ report.play_75_feed_break,
+ report.play_100_feed_break,
+ report.average_play_time_per_play,
+ report.play_over_rate,
+ report.wifi_play_rate,
+ report.wifi_play,
+ report.play_duration_sum,
+ report.advanced_creative_phone_click,
+ report.advanced_creative_counsel_click,
+ report.advanced_creative_form_click,
+ report.advanced_creative_coupon_addition,
+ report.advanced_creative_form_submit,
+ report.card_show,
+ report.`SHARE`,
+ report.`COMMENT`,
+ report.`LIKE`,
+ report.follow,
+ report.home_visited,
+ report.ies_challenge_click,
+ report.ies_music_click,
+ report.location_click,
+ report.message_action,
+ report.click_landing_page,
+ report.click_shopwindow,
+ report.click_website,
+ report.click_download,
+ report.click_call_dy,
+ report.submit_certification_count,
+ report.approval_count,
+ report.first_rental_order_count,
+ report.first_order_count,
+ report.commute_first_pay_count
+FROM
+ (
+  SELECT
+   advertiser_id account_id,
+   campaign_id campaign_id,
+   campaign_name campaign_name,
+   sum(cost) cost,
+   sum(`show`) `show`,
+   round(sum(cost) / sum(`show`), 3) avg_show_cost,
+   sum(click) click,
+   round(sum(cost) / sum(`click`), 3) avg_click_cost,
+   round(
+    sum(click) / sum(`show`) * 100,
+    3
+   ) ctr,
+   sum(`convert`) `convert`,
+   round(sum(cost) / sum(`convert`), 3) convert_cost,
+   round(
+    sum(`convert`) / sum(click) * 100,
+    3
+   ) convert_rate,
+   sum(deep_convert) deep_convert,
+   round(
+    sum(cost) / sum(deep_convert),
+    3
+   ) deep_convert_cost,
+   round(
+    sum(deep_convert) / sum(`convert`) * 100,
+    3
+   ) deep_convert_rate,
+   sum(attribution_convert) attribution_convert,
+   round(
+    sum(cost) / sum(attribution_convert),
+    3
+   ) attribution_convert_cost,
+   sum(attribution_deep_convert) attribution_deep_convert,
+   round(
+    sum(cost) / sum(attribution_deep_convert),
+    3
+   ) attribution_deep_convert_cost,
+   sum(download_start) download_start,
+   round(
+    sum(cost) / sum(download_start),
+    3
+   ) download_start_cost,
+   round(
+    sum(download_start) / sum(click),
+    3
+   ) download_start_rate,
+   sum(download_finish) download_finish,
+   round(
+    sum(cost) / sum(download_finish),
+    3
+   ) download_finish_cost,
+   round(
+    sum(download_finish) / sum(download_start) * 100,
+    3
+   ) download_finish_rate,
+   sum(click_install) click_install,
+   sum(install_finish) install_finish,
+   round(
+    sum(cost) / sum(install_finish),
+    3
+   ) install_finish_cost,
+   round(
+    sum(install_finish) / sum(download_finish) * 100,
+    3
+   ) install_finish_rate,
+   sum(active) active,
+   round(sum(cost) / sum(active), 3) active_cost,
+   round(
+    sum(active) / sum(click) * 100,
+    3
+   ) active_rate,
+   sum(register) register,
+   round(sum(cost) / sum(register), 3) active_register_cost,
+   round(
+    sum(active_register_rate) / {day_count} * 100,
+    3
+   ) active_register_rate,
+   sum(next_day_open) next_day_open,
+   round(
+    sum(cost) / sum(next_day_open),
+    3
+   ) next_day_open_cost,
+   round(
+    sum(next_day_open) / sum(active) * 100,
+    3
+   ) next_day_open_rate,
+   sum(
+    attribution_next_day_open_cnt
+   ) attribution_next_day_open_cnt,
+   round(
+    sum(cost) / sum(
+     attribution_next_day_open_cnt
+    ),
+    3
+   ) attribution_next_day_open_cost,
+   round(
+    sum(
+     attribution_next_day_open_cnt
+    ) / sum(active) * 100,
+    3
+   ) attribution_next_day_open_rate,
+   sum(game_addiction) game_addiction,
+   round(
+    sum(cost) / sum(game_addiction),
+    3
+   ) game_addiction_cost,
+   round(
+    sum(game_addiction_rate) / {day_count} * 100,
+    3
+   ) game_addiction_rate,
+   sum(pay_count) pay_count,
+   round(sum(cost) / sum(pay_count), 3) active_pay_cost,
+   round(
+    sum(pay_count) / sum(active) * 100,
+    3
+   ) active_pay_rate,
+   sum(loan_completion) loan_completion,
+   round(
+    sum(cost) / sum(loan_completion),
+    3
+   ) loan_completion_cost,
+   round(
+    sum(loan_completion) / sum(register) * 100,
+    3
+   ) loan_completion_rate,
+   round(sum(pre_loan_credit), 3) pre_loan_credit,
+   round(
+    sum(cost) / sum(pre_loan_credit),
+    3
+   ) pre_loan_credit_cost,
+   sum(loan_credit) loan_credit,
+   round(
+    sum(cost) / sum(loan_credit),
+    3
+   ) loan_credit_cost,
+   round(
+    sum(loan_credit) / sum(loan_completion) * 100,
+    3
+   ) loan_credit_rate,
+   sum(in_app_uv) in_app_uv,
+   sum(in_app_detail_uv) in_app_detail_uv,
+   sum(in_app_cart) in_app_cart,
+   sum(in_app_pay) in_app_pay,
+   sum(in_app_order) in_app_order,
+   round(
+    sum(
+     attribution_game_pay_7d_count
+    ) / {day_count},
+    3
+   ) attribution_game_pay_7d_count,
+   round(
+    sum(
+     attribution_game_pay_7d_cost
+    ) / {day_count},
+    3
+   ) attribution_game_pay_7d_cost,
+   round(
+    sum(
+     attribution_active_pay_7d_per_count
+    ) / {day_count},
+    3
+   ) attribution_active_pay_7d_per_count,
+   sum(game_pay_cost) game_pay_cost,
+   sum(game_pay_count) game_pay_count,
+   sum(phone) phone,
+   sum(form) form,
+   sum(map_search) map_search,
+   sum(button) button,
+   sum(`view`) `view`,
+   sum(download) download,
+   sum(qq) qq,
+   sum(lottery) lottery,
+   sum(vote) vote,
+   sum(message) message,
+   sum(redirect) redirect,
+   sum(shopping) shopping,
+   sum(consult) consult,
+   sum(wechat) wechat,
+   sum(phone_confirm) phone_confirm,
+   sum(phone_connect) phone_connect,
+   sum(consult_effective) consult_effective,
+   sum(coupon) coupon,
+   sum(coupon_single_page) coupon_single_page,
+   sum(redirect_to_shop) redirect_to_shop,
+   sum(poi_collect) poi_collect,
+   sum(poi_address_click) poi_address_click,
+   sum(luban_order_cnt) luban_order_cnt,
+   sum(luban_order_stat_amount) luban_order_stat_amount,
+   sum(luban_order_roi) luban_order_roi,
+   sum(luban_live_enter_cnt) luban_live_enter_cnt,
+   sum(
+    live_watch_one_minute_count
+   ) live_watch_one_minute_count,
+   sum(luban_live_follow_cnt) luban_live_follow_cnt,
+   sum(live_fans_club_join_cnt) live_fans_club_join_cnt,
+   sum(luban_live_comment_cnt) luban_live_comment_cnt,
+   sum(luban_live_share_cnt) luban_live_share_cnt,
+   sum(luban_live_gift_cnt) luban_live_gift_cnt,
+   sum(luban_live_gift_amount) luban_live_gift_amount,
+   sum(
+    luban_live_slidecart_click_cnt
+   ) luban_live_slidecart_click_cnt,
+   sum(
+    luban_live_click_product_cnt
+   ) luban_live_click_product_cnt,
+   sum(luban_live_pay_order_count) luban_live_pay_order_count,
+   sum(
+    luban_live_pay_order_stat_cost
+   ) luban_live_pay_order_stat_cost,
+   sum(live_component_click_count) live_component_click_count,
+   round(
+    sum(cost) / sum(live_component_click_count),
+    3
+   ) live_component_click_cost,
+   round(
+    sum(live_component_click_count) / {day_count} * 100,
+    3
+   ) live_component_click_rate,
+   sum(wechat_login_count) wechat_login_count,
+   sum(
+    attribution_wechat_login_30d_count
+   ) attribution_wechat_login_30d_count,
+   round(
+    sum(cost) / sum(wechat_login_count),
+    3
+   ) wechat_login_cost,
+   round(
+    sum(cost) / sum(
+     attribution_wechat_login_30d_count
+    ),
+    3
+   ) attribution_wechat_login_30d_cost,
+   sum(wechat_first_pay_count) wechat_first_pay_count,
+   sum(
+    attribution_wechat_first_pay_30d_count
+   ) attribution_wechat_first_pay_30d_count,
+   round(
+    sum(cost) / sum(wechat_first_pay_count),
+    3
+   ) wechat_first_pay_cost,
+   round(
+    sum(cost) / sum(
+     attribution_wechat_first_pay_30d_count
+    ),
+    3
+   ) attribution_wechat_first_pay_30d_cost,
+   round(
+    sum(wechat_first_pay_count) / sum(wechat_login_count) * 100,
+    3
+   ) wechat_first_pay_rate,
+   round(
+    sum(
+     attribution_wechat_first_pay_30d_count
+    ) / sum(
+     attribution_wechat_login_30d_count
+    ) * 100,
+    3
+   ) attribution_wechat_first_pay_30d_rate,
+   sum(wechat_pay_amount) wechat_pay_amount,
+   sum(
+    attribution_wechat_pay_30d_amount
+   ) attribution_wechat_pay_30d_amount,
+   sum(
+    attribution_wechat_pay_30d_roi
+   ) attribution_wechat_pay_30d_roi,
+   sum(phone_effective) phone_effective,
+   sum(total_play) total_play,
+   sum(valid_play) valid_play,
+   round(
+    sum(cost) / sum(valid_play),
+    3
+   ) valid_play_cost,
+   round(
+    sum(valid_play) / sum(`show`) * 100,
+    3
+   ) valid_play_rate,
+   sum(play_25_feed_break) play_25_feed_break,
+   sum(play_50_feed_break) play_50_feed_break,
+   sum(play_75_feed_break) play_75_feed_break,
+   sum(play_100_feed_break) play_100_feed_break,
+   round(
+    sum(average_play_time_per_play) / {day_count},
+    3
+   ) average_play_time_per_play,
+   round(
+    sum(play_over_rate) / {day_count} * 100,
+    3
+   ) play_over_rate,
+   round(
+    sum(wifi_play) / sum(total_play) * 100,
+    3
+   ) wifi_play_rate,
+   sum(wifi_play) wifi_play,
+   round(sum(play_duration_sum) / {day_count}, 3) play_duration_sum,
+   sum(
+    advanced_creative_phone_click
+   ) advanced_creative_phone_click,
+   sum(
+    advanced_creative_counsel_click
+   ) advanced_creative_counsel_click,
+   sum(
+    advanced_creative_form_click
+   ) advanced_creative_form_click,
+   sum(
+    advanced_creative_coupon_addition
+   ) advanced_creative_coupon_addition,
+   sum(
+    advanced_creative_form_submit
+   ) advanced_creative_form_submit,
+   sum(card_show) card_show,
+   sum(`share`) `share`,
+   sum(`comment`) `comment`,
+   sum(`like`) `like`,
+   sum(follow) follow,
+   sum(home_visited) home_visited,
+   sum(ies_challenge_click) ies_challenge_click,
+   sum(ies_music_click) ies_music_click,
+   sum(location_click) location_click,
+   sum(message_action) message_action,
+   sum(click_landing_page) click_landing_page,
+   sum(click_shopwindow) click_shopwindow,
+   sum(click_website) click_website,
+   sum(click_download) click_download,
+   sum(click_call_dy) click_call_dy,
+   sum(submit_certification_count) submit_certification_count,
+   sum(approval_count) approval_count,
+   sum(first_order_count) first_rental_order_count,
+   sum(first_rental_order_count) first_order_count,
+   sum(commute_first_pay_count) commute_first_pay_count
+  FROM
+   `media_api`.bytedance_campaign_report_daily
+  WHERE
+   stat_datetime >= date_format(
+    date_sub({date_time}, INTERVAL {day_count}  DAY),
+    '%Y%m%d'
+   )
+  GROUP BY
+   advertiser_id,
+   campaign_id,
+   campaign_name
+ ) report
+LEFT JOIN (
+ SELECT
+  cua.account_id id,
+  cua.account_id account_id,
+  cp.id project_id,
+  product.id product_id,
+  ca.id advertiser_id,
+  uc.company_id company_id,
+  cua.auth_name account_name,
+  cp.project_name project_name,
+  ca.`name` advertiser_name,
+  uc.company_name company_name,
+  cp.sale_id sale_id,
+  su.id user_id,
+  su.leader_id,
+  su.org_code org_code
+ FROM
+  `jeecg-boot`.ctop_user_allocation cua
+ LEFT JOIN `jeecg-boot`.ctop_project cp ON cua.project_id = cp.id
+ LEFT JOIN `jeecg-boot`.ctop_advertiser ca ON ca.id = cua.advertiser_id
+ LEFT JOIN `jeecg-boot`.sys_user su ON su.id = cua.user_id
+ LEFT JOIN `jeecg-boot`.user_company uc ON uc.user_id = cua.user_id
+ LEFT JOIN `jeecg-boot`.ctop_product product ON product.id = cp.product_id
+ WHERE
+  cua.account_id IS NOT NULL
+) bei ON report.account_id = bei.account_id""".format(date_time=self.date_time, day_count=self.day_count)
+            TidbConn.upsert(conn=self.conn, sql_buff=sql)
+            self.conn.commit()
+            TidbConn.conn_close(conn=self.conn)
+            return 0
+        except Exception as e:
+            logging.error(e)
+            return -1
+
+
+if __name__ == '__main__':
+    status = AppBytedanceCampaignReportBusiMonth().taskHandler()
+    if status == 0:
+        print("作业执行成功")
+        exit(0)
+    else:
+        print("作业执行失败")
+        exit(-1)

+ 3 - 3
Apietl/bytedance_etl/Q4Task/AppBytedanceCompanyDesignReportBusi.py

@@ -26,7 +26,7 @@ SET sql_mode = 'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_AUTO_CREATE_
 REPLACE INTO application.app_bytedance_company_design_report_busi_{day_count}d
 SELECT concat(
                date_format(
-                       date_sub({date_time}, INTERVAL 6 DAY),
+                       date_sub({date_time}, INTERVAL ({day_count} -1 )  DAY),
                        '%Y%m%d'
                    ),
                '-',
@@ -424,7 +424,7 @@ FROM (
                         uc.company_name
                     END                                                              company_name,
                 cma.leader_id,
-                us.realname as leader_name,
+                us. as leader_name,
                 ur.org_type,
                 ur.org_code,
                 ur.id,
@@ -647,7 +647,7 @@ FROM (
                               'CREATIVE_IMAGE_MODE_UNION_SPLASH_VIDEO'
              )
            AND stat_datetime >= date_format(
-                 date_sub({date_time}, INTERVAL 6 DAY),
+                 date_sub({date_time}, INTERVAL ({day_count} -1 )  DAY),
                  '%Y%m%d'
              )
      ) info

+ 673 - 0
Apietl/bytedance_etl/Q4Task/AppBytedanceCompanyDesignReportBusiMonth.py

@@ -0,0 +1,673 @@
+# Author renyupeng
+# coding=utf-8
+# @Time    : 2021/11/10 3:37 下午
+# @Site    :
+# @File    : AppBytedanceCompanyDesignReportBusi.py
+# @Software: PyCharm
+# @contact: renyupeng@c-top.com.cn
+# @Tel 1501435553
+import logging
+
+from Apietl.conn.TidbConn import TidbConn
+from Apietl.utlis.Utils import Utils
+
+
+class AppBytedanceCompanyDesignReportBusi:
+    def __init__(self):
+        self.conn = TidbConn.get_connection()
+        self.parm = Utils.get_task_args()
+        self.date_time = self.parm[0]
+        self.day_count = Utils.get_days()
+
+    def taskHandler(self):
+        try:
+            sql = """
+delete from application.app_bytedance_company_design_report_busi_m where stat_mon=date_format({date_time},'%Y%m');
+SET sql_mode = 'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
+REPLACE INTO application.app_bytedance_company_design_report_busi_m
+SELECT concat(
+               date_format({date_time},'%Y%m')    as  stat_mon,
+       company_id,
+       company_name,
+       org_code,
+       org_type,
+       id,
+       depart_name,
+       leader_id,
+       leader_name,
+       count(DISTINCT signature)            num,
+       count(distinct innovate_code)        innovate_num,
+       sum(cost)                            cost,
+       sum(`show`)                          `show`,
+       round(sum(cost) / sum(`show`), 3)    avg_show_cost,
+       sum(click)                           click,
+       round(sum(cost) / sum(`click`), 3)   avg_click_cost,
+       round(
+               sum(click) / sum(`show`) * 100,
+               3
+           )                                ctr,
+       sum(`convert`)                       `convert`,
+       round(sum(cost) / sum(`convert`), 3) convert_cost,
+       round(
+               sum(`convert`) / sum(click) * 100,
+               3
+           )                                convert_rate,
+       sum(deep_convert)                    deep_convert,
+       round(
+               sum(cost) / sum(deep_convert),
+               3
+           )                                deep_convert_cost,
+       round(
+               sum(deep_convert) / sum(`convert`) * 100,
+               3
+           )                                deep_convert_rate,
+       sum(attribution_convert)             attribution_convert,
+       round(
+               sum(cost) / sum(attribution_convert),
+               3
+           )                                attribution_convert_cost,
+       sum(attribution_deep_convert)        attribution_deep_convert,
+       round(
+               sum(cost) / sum(attribution_deep_convert),
+               3
+           )                                attribution_deep_convert_cost,
+       sum(download_start)                  download_start,
+       round(
+               sum(cost) / sum(download_start),
+               3
+           )                                download_start_cost,
+       round(
+               sum(download_start) / sum(click),
+               3
+           )                                download_start_rate,
+       sum(download_finish)                 download_finish,
+       round(
+               sum(cost) / sum(download_finish),
+               3
+           )                                download_finish_cost,
+       round(
+               sum(download_finish) / sum(download_start) * 100,
+               3
+           )                                download_finish_rate,
+       sum(click_install)                   click_install,
+       sum(install_finish)                  install_finish,
+       round(
+               sum(cost) / sum(install_finish),
+               3
+           )                                install_finish_cost,
+       round(
+               sum(install_finish) / sum(download_finish) * 100,
+               3
+           )                                install_finish_rate,
+       sum(active)                          active,
+       round(sum(cost) / sum(active), 3)    active_cost,
+       round(
+               sum(active) / sum(click) * 100,
+               3
+           )                                active_rate,
+       sum(register)                        register,
+       round(sum(cost) / sum(register), 3)  active_register_cost,
+       round(
+               sum(active_register_rate) / {day_count} * 100,
+               3
+           )                                active_register_rate,
+       sum(active_pay_amount)               active_pay_amount,
+       sum(next_day_open)                   next_day_open,
+       round(
+               sum(cost) / sum(next_day_open),
+               3
+           )                                next_day_open_cost,
+       round(
+               sum(next_day_open) / sum(active) * 100,
+               3
+           )                                next_day_open_rate,
+       sum(
+               attribution_next_day_open_cnt
+           )                                attribution_next_day_open_cnt,
+       round(
+                   sum(cost) / sum(
+                       attribution_next_day_open_cnt
+                   ),
+                   3
+           )                                attribution_next_day_open_cost,
+       round(
+                       sum(
+                               attribution_next_day_open_cnt
+                           ) / sum(active) * 100,
+                       3
+           )                                attribution_next_day_open_rate,
+       sum(game_addiction)                  game_addiction,
+       round(
+               sum(cost) / sum(game_addiction),
+               3
+           )                                game_addiction_cost,
+       round(
+               sum(game_addiction_rate) / {day_count} * 100,
+               3
+           )                                game_addiction_rate,
+       sum(pay_count)                       pay_count,
+       round(sum(cost) / sum(pay_count), 3) active_pay_cost,
+       round(
+               sum(pay_count) / sum(active) * 100,
+               3
+           )                                active_pay_rate,
+       sum(loan_completion)                 loan_completion,
+       round(
+               sum(cost) / sum(loan_completion),
+               3
+           )                                loan_completion_cost,
+       round(
+               sum(loan_completion) / sum(register) * 100,
+               3
+           )                                loan_completion_rate,
+       round(sum(pre_loan_credit), 3)       pre_loan_credit,
+       round(
+               sum(cost) / sum(pre_loan_credit),
+               3
+           )                                pre_loan_credit_cost,
+       sum(loan_credit)                     loan_credit,
+       round(
+               sum(cost) / sum(loan_credit),
+               3
+           )                                loan_credit_cost,
+       round(
+               sum(loan_credit) / sum(loan_completion) * 100,
+               3
+           )                                loan_credit_rate,
+       sum(in_app_uv)                       in_app_uv,
+       sum(in_app_detail_uv)                in_app_detail_uv,
+       sum(in_app_cart)                     in_app_cart,
+       sum(in_app_pay)                      in_app_pay,
+       sum(in_app_order)                    in_app_order,
+       round(
+                   sum(
+                           attribution_game_pay_7d_count
+                       ) / {day_count},
+                   3
+           )                                attribution_game_pay_7d_count,
+       round(
+                   sum(
+                           attribution_game_pay_7d_cost
+                       ) / {day_count},
+                   3
+           )                                attribution_game_pay_7d_cost,
+       round(
+                   sum(
+                           attribution_active_pay_7d_per_count
+                       ) / {day_count},
+                   3
+           )                                attribution_active_pay_7d_per_count,
+       sum(game_pay_cost)                   game_pay_cost,
+       sum(game_pay_count)                  game_pay_count,
+       sum(phone)                           phone,
+       sum(form)                            form,
+       sum(map_search)                      map_search,
+       sum(button)                          button,
+       sum(`view`)                          `view`,
+       sum(download)                        download,
+       sum(qq)                              qq,
+       sum(lottery)                         lottery,
+       sum(vote)                            vote,
+       sum(message)                         message,
+       sum(redirect)                        redirect,
+       sum(shopping)                        shopping,
+       sum(consult)                         consult,
+       sum(wechat)                          wechat,
+       sum(phone_confirm)                   phone_confirm,
+       sum(phone_connect)                   phone_connect,
+       sum(consult_effective)               consult_effective,
+       sum(coupon)                          coupon,
+       sum(coupon_single_page)              coupon_single_page,
+       sum(redirect_to_shop)                redirect_to_shop,
+       sum(poi_collect)                     poi_collect,
+       sum(poi_address_click)               poi_address_click,
+       sum(luban_order_cnt)                 luban_order_cnt,
+       sum(luban_order_stat_amount)         luban_order_stat_amount,
+       sum(luban_order_roi)                 luban_order_roi,
+       sum(luban_live_enter_cnt)            luban_live_enter_cnt,
+       sum(
+               live_watch_one_minute_count
+           )                                live_watch_one_minute_count,
+       sum(luban_live_follow_cnt)           luban_live_follow_cnt,
+       sum(live_fans_club_join_cnt)         live_fans_club_join_cnt,
+       sum(luban_live_comment_cnt)          luban_live_comment_cnt,
+       sum(luban_live_share_cnt)            luban_live_share_cnt,
+       sum(luban_live_gift_cnt)             luban_live_gift_cnt,
+       sum(luban_live_gift_amount)          luban_live_gift_amount,
+       sum(
+               luban_live_slidecart_click_cnt
+           )                                luban_live_slidecart_click_cnt,
+       sum(
+               luban_live_click_product_cnt
+           )                                luban_live_click_product_cnt,
+       sum(luban_live_pay_order_count)      luban_live_pay_order_count,
+       sum(
+               luban_live_pay_order_stat_cost
+           )                                luban_live_pay_order_stat_cost,
+       sum(wechat_login_count)              wechat_login_count,
+       sum(
+               attribution_wechat_login_30d_count
+           )                                attribution_wechat_login_30d_count,
+       round(
+               sum(cost) / sum(wechat_login_count),
+               3
+           )                                wechat_login_cost,
+       round(
+                   sum(cost) / sum(
+                       attribution_wechat_login_30d_count
+                   ),
+                   3
+           )                                attribution_wechat_login_30d_cost,
+       sum(wechat_first_pay_count)          wechat_first_pay_count,
+       sum(
+               attribution_wechat_first_pay_30d_count
+           )                                attribution_wechat_first_pay_30d_count,
+       round(
+               sum(cost) / sum(wechat_first_pay_count),
+               3
+           )                                wechat_first_pay_cost,
+       round(
+                   sum(cost) / sum(
+                       attribution_wechat_first_pay_30d_count
+                   ),
+                   3
+           )                                attribution_wechat_first_pay_30d_cost,
+       round(
+               sum(wechat_first_pay_count) / sum(wechat_login_count) * 100,
+               3
+           )                                wechat_first_pay_rate,
+       round(
+                       sum(
+                               attribution_wechat_first_pay_30d_count
+                           ) / sum(
+                               attribution_wechat_login_30d_count
+                           ) * 100,
+                       3
+           )                                attribution_wechat_first_pay_30d_rate,
+       sum(wechat_pay_amount)               wechat_pay_amount,
+       sum(
+               attribution_wechat_pay_30d_amount
+           )                                attribution_wechat_pay_30d_amount,
+       sum(
+               attribution_wechat_pay_30d_roi
+           )                                attribution_wechat_pay_30d_roi,
+       sum(phone_effective)                 phone_effective,
+       sum(total_play)                      total_play,
+       sum(valid_play)                      valid_play,
+       round(
+               sum(cost) / sum(valid_play),
+               3
+           )                                valid_play_cost,
+       round(
+               sum(valid_play) / sum(`show`) * 100,
+               3
+           )                                valid_play_rate,
+       sum(play_25_feed_break)              play_25_feed_break,
+       sum(play_50_feed_break)              play_50_feed_break,
+       sum(play_75_feed_break)              play_75_feed_break,
+       sum(play_100_feed_break)             play_100_feed_break,
+       round(
+               sum(average_play_time_per_play) / {day_count},
+               3
+           )                                average_play_time_per_play,
+       round(
+               sum(play_over_rate) / {day_count} * 100,
+               3
+           )                                play_over_rate,
+       round(
+               sum(wifi_play) / sum(total_play) * 100,
+               3
+           )                                wifi_play_rate,
+       sum(wifi_play)                       wifi_play,
+       round(sum(play_duration_sum) / {day_count}, 3) play_duration_sum,
+       sum(
+               advanced_creative_phone_click
+           )                                advanced_creative_phone_click,
+       sum(
+               advanced_creative_counsel_click
+           )                                advanced_creative_counsel_click,
+       sum(
+               advanced_creative_form_click
+           )                                advanced_creative_form_click,
+       sum(
+               advanced_creative_coupon_addition
+           )                                advanced_creative_coupon_addition,
+       sum(
+               advanced_creative_form_submit
+           )                                advanced_creative_form_submit,
+       sum(card_show)                       card_show,
+       sum(`share`)                         `share`,
+       sum(`comment`)                       `comment`,
+       sum(`like`)                          `like`,
+       sum(follow)                          follow,
+       sum(home_visited)                    home_visited,
+       sum(ies_challenge_click)             ies_challenge_click,
+       sum(ies_music_click)                 ies_music_click,
+       sum(location_click)                  location_click,
+       sum(message_action)                  message_action,
+       sum(click_landing_page)              click_landing_page,
+       sum(click_shopwindow)                click_shopwindow,
+       sum(click_website)                   click_website,
+       sum(click_download)                  click_download,
+       sum(click_call_dy)                   click_call_dy,
+       sum(cpc)                             cpc,
+       sum(cpm)                             cpm,
+       sum(cpa)                             cpa,
+       round(sum(interact_per_cost) / {day_count}, 3) interact_per_cost,
+       round(sum(convert_show_rate) / {day_count}, 3) convert_show_rate,
+       round(
+               sum(round(play_duration_10s)) / sum(total_play) * 100,
+               3
+           )                                play_duration_10s_rate,
+       round(
+               sum(play_50_feed_break) / sum(total_play) * 100,
+               3
+           )                                play_50_feed_break_rate,
+       round(
+               sum(play_25_feed_break) / sum(total_play) * 100,
+               3
+           )                                play_25_feed_break_rate,
+       round(
+               sum(play_duration_5s_rate) / {day_count},
+               3
+           )                                play_duration_5s_rate,
+       round(
+               sum(play_duration_2s) / sum(total_play) * 100,
+               3
+           )                                play_duration_2s_rate,
+       round(
+               sum(average_play_progress) / {day_count},
+               3
+           )                                average_play_progress,
+       round(
+               sum(play_100_feed_break) / sum(total_play) * 100,
+               3
+           )                                play_100_feed_break_rate,
+       round(
+               sum(play_duration_3s) / sum(total_play) * 100,
+               3
+           )                                play_duration_3s_rate,
+       round(
+               sum(play_75_feed_break) / sum(total_play) * 100,
+               3
+           )                                play_75_feed_break_rate,
+       sum(play_duration)                   play_duration,
+       sum(play_duration_3s)                play_duration_3s,
+       sum(play_duration_2s)                play_duration_2s,
+       sum(play_duration_10s)               play_duration_10s,
+       round(
+               sum(average_video_play) / {day_count},
+               3
+           )                                average_video_play,
+       sum(avg_rank)                        avg_rank,
+       sum(submit_certification_count)      submit_certification_count,
+       sum(approval_count)                  approval_count,
+       sum(first_order_count)               first_rental_order_count,
+       sum(first_rental_order_count)        first_order_count,
+       sum(commute_first_pay_count)         commute_first_pay_count
+FROM (
+         SELECT video.signature,
+                uc.company_id,
+                CASE
+                    WHEN uc.company_id = 'd57fecdcf7a94d009736d9c850731582' THEN
+                        '北京汇创思拓数字科技有限公司'
+                    WHEN uc.company_id = '6608ed13c0dd42de93c790dbdf124234' THEN
+                        '广州汇创思拓数字科技有限公司'
+                    WHEN uc.company_id = '4b10089775c040119e139087517aed88' THEN
+                        '上海汇创思拓数字科技有限公司'
+                    ELSE
+                        uc.company_name
+                    END                                                              company_name,
+                cma.leader_id,
+                us. as leader_name,
+                ur.org_type,
+                ur.org_code,
+                ur.id,
+                ur.depart_name,
+                case when cmi.material_innovate = 2 then video.signature else '' end innovate_code,
+                report.cost,
+                report.`show`,
+                report.avg_show_cost,
+                report.click,
+                report.avg_click_cost,
+                report.ctr,
+                report.`convert`,
+                report.convert_cost,
+                report.convert_rate,
+                report.deep_convert,
+                report.deep_convert_cost,
+                report.deep_convert_rate,
+                report.attribution_convert,
+                report.attribution_convert_cost,
+                report.attribution_deep_convert,
+                report.attribution_deep_convert_cost,
+                report.download_start,
+                report.download_start_cost,
+                report.download_start_rate,
+                report.download_finish,
+                report.download_finish_cost,
+                report.download_finish_rate,
+                report.click_install,
+                report.install_finish,
+                report.install_finish_cost,
+                report.install_finish_rate,
+                report.active,
+                report.active_cost,
+                report.active_rate,
+                report.register,
+                report.active_register_cost,
+                report.active_register_rate,
+                report.active_pay_amount,
+                report.next_day_open,
+                report.next_day_open_cost,
+                report.next_day_open_rate,
+                report.attribution_next_day_open_cnt,
+                report.attribution_next_day_open_cost,
+                report.attribution_next_day_open_rate,
+                report.game_addiction,
+                report.game_addiction_cost,
+                report.game_addiction_rate,
+                report.pay_count,
+                report.active_pay_cost,
+                report.active_pay_rate,
+                report.loan_completion,
+                report.loan_completion_cost,
+                report.loan_completion_rate,
+                report.pre_loan_credit,
+                report.pre_loan_credit_cost,
+                report.loan_credit,
+                report.loan_credit_cost,
+                report.loan_credit_rate,
+                report.in_app_uv,
+                report.in_app_detail_uv,
+                report.in_app_cart,
+                report.in_app_pay,
+                report.in_app_order,
+                report.attribution_game_pay_7d_count,
+                report.attribution_game_pay_7d_cost,
+                report.attribution_active_pay_7d_per_count,
+                report.game_pay_cost,
+                report.game_pay_count,
+                report.phone,
+                report.form,
+                report.map_search,
+                report.button,
+                report.`view`,
+                report.download,
+                report.qq,
+                report.lottery,
+                report.vote,
+                report.message,
+                report.redirect,
+                report.shopping,
+                report.consult,
+                report.wechat,
+                report.phone_confirm,
+                report.phone_connect,
+                report.consult_effective,
+                report.coupon,
+                report.coupon_single_page,
+                report.redirect_to_shop,
+                report.poi_collect,
+                report.poi_address_click,
+                report.luban_order_cnt,
+                report.luban_order_stat_amount,
+                report.luban_order_roi,
+                report.luban_live_enter_cnt,
+                report.live_watch_one_minute_count,
+                report.luban_live_follow_cnt,
+                report.live_fans_club_join_cnt,
+                report.luban_live_comment_cnt,
+                report.luban_live_share_cnt,
+                report.luban_live_gift_cnt,
+                report.luban_live_gift_amount,
+                report.luban_live_slidecart_click_cnt,
+                report.luban_live_click_product_cnt,
+                report.luban_live_pay_order_count,
+                report.luban_live_pay_order_stat_cost,
+                report.wechat_login_count,
+                report.attribution_wechat_login_30d_count,
+                report.wechat_login_cost,
+                report.attribution_wechat_login_30d_cost,
+                report.wechat_first_pay_count,
+                report.attribution_wechat_first_pay_30d_count,
+                report.wechat_first_pay_cost,
+                report.attribution_wechat_first_pay_30d_cost,
+                report.wechat_first_pay_rate,
+                report.attribution_wechat_first_pay_30d_rate,
+                report.wechat_pay_amount,
+                report.attribution_wechat_pay_30d_amount,
+                report.attribution_wechat_pay_30d_roi,
+                report.phone_effective,
+                report.total_play,
+                report.valid_play,
+                report.valid_play_cost,
+                report.valid_play_rate,
+                report.play_25_feed_break,
+                report.play_50_feed_break,
+                report.play_75_feed_break,
+                report.play_100_feed_break,
+                report.average_play_time_per_play,
+                report.play_over_rate,
+                report.wifi_play_rate,
+                report.wifi_play,
+                report.play_duration_sum,
+                report.advanced_creative_phone_click,
+                report.advanced_creative_counsel_click,
+                report.advanced_creative_form_click,
+                report.advanced_creative_coupon_addition,
+                report.advanced_creative_form_submit,
+                report.card_show,
+                report.`share`,
+                report.`comment`,
+                report.`like`,
+                report.follow,
+                report.home_visited,
+                report.ies_challenge_click,
+                report.ies_music_click,
+                report.location_click,
+                report.message_action,
+                report.click_landing_page,
+                report.click_shopwindow,
+                report.click_website,
+                report.click_download,
+                report.click_call_dy,
+                report.`cpc`,
+                report.`cpm`,
+                report.`cpa`,
+                report.`interact_per_cost`,
+                report.`convert_show_rate`,
+                report.`play_duration_10s_rate`,
+                report.`play_50_feed_break_rate`,
+                report.`play_25_feed_break_rate`,
+                report.`play_duration_5s_rate`,
+                report.`play_duration_2s_rate`,
+                report.`average_play_progress`,
+                report.`play_100_feed_break_rate`,
+                report.`play_duration_3s_rate`,
+                report.`play_75_feed_break_rate`,
+                report.`play_duration`,
+                report.`play_duration_3s`,
+                report.`play_duration_2s`,
+                report.`play_duration_10s`,
+                report.`average_video_play`,
+                report.`avg_rank`,
+                report.submit_certification_count,
+                report.approval_count,
+                report.first_rental_order_count,
+                report.first_order_count,
+                report.commute_first_pay_count
+         FROM media_api.bytedance_material_report_daily report
+                  LEFT JOIN (
+             SELECT advertiser_id,
+                    signature,
+                    material_id
+             FROM `media_api`.bytedance_file_video_get
+             GROUP BY advertiser_id,
+                      signature,
+                      material_id
+         ) video ON report.advertiser_id = video.advertiser_id
+             AND report.material_id = video.material_id
+                  LEFT JOIN (
+             SELECT CODE,
+                    material_innovate,
+                    cover_url
+             FROM `jeecg-boot`.ctop_material_info
+             GROUP BY CODE,
+                      material_innovate,
+                      cover_url
+         ) cmi ON video.signature = cmi.CODE
+                  LEFT JOIN (
+             SELECT material_id,
+                    leader_id
+             FROM (
+                      SELECT material_id,
+                             leader_id,
+                             row_number() over (
+                                 PARTITION BY material_id
+                                 ORDER BY
+                                     create_time
+                                 ) rn
+                      FROM `jeecg-boot`.ctop_material_ascription
+                  ) m
+             WHERE rn = 1
+         ) cma ON video.signature = cma.material_id
+                  LEFT JOIN `jeecg-boot`.user_company uc ON cma.leader_id = uc.user_id
+                  LEFT JOIN `jeecg-boot`.sys_user_depart de ON cma.leader_id = de.user_id
+                  LEFT JOIN `jeecg-boot`.sys_depart ur ON de.dep_id = ur.id
+                  LEFT JOIN  `jeecg-boot`.sys_user us on us.id =cma.leader_id
+         WHERE image_mode IN (
+                              'CREATIVE_IMAGE_MODE_VIDEO',
+                              'CREATIVE_IMAGE_MODE_VIDEO_VERTICAL',
+                              'CREATIVE_IMAGE_MODE_UNION_SPLASH_VIDEO'
+             )
+           AND stat_datetime >= date_format(
+                 date_sub({date_time}, INTERVAL {day_count}   DAY),
+                 '%Y%m%d'
+             )
+     ) info
+GROUP BY company_id,
+         company_name,
+         leader_id,
+         org_type,
+         org_code,
+         id,
+         depart_name;
+            """.format(date_time=self.date_time, day_count=self.day_count)
+            TidbConn.upsert(conn=self.conn, sql_buff=sql)
+            self.conn.commit()
+            TidbConn.conn_close(conn=self.conn)
+            return 0
+        except Exception as e:
+            logging.error(e)
+            return -1
+
+
+if __name__ == '__main__':
+    status = AppBytedanceCompanyDesignReportBusi().taskHandler()
+    if status == 0:
+        print("作业执行成功")
+        exit(0)
+    else:
+        print("作业执行失败")
+        exit(-1)

+ 2 - 2
Apietl/bytedance_etl/Q4Task/AppBytedanceCompanyUserReportBusi.py

@@ -26,7 +26,7 @@ SET sql_mode = 'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_AUTO_CREATE_
 REPLACE INTO application.app_bytedance_company_user_report_busi_{day_count}d SELECT
 concat(
 date_format(
-date_sub({date_time}, INTERVAL 6 DAY),
+date_sub({date_time}, INTERVAL ({day_count} -1 )  DAY),
 '%Y%m%d'
 ),
 '-',
@@ -552,7 +552,7 @@ FROM
 media_api.bytedance_advertiser_report_daily
 WHERE
 stat_datetime >= date_format(
-date_sub({date_time}, INTERVAL 6 DAY),
+date_sub({date_time}, INTERVAL ({day_count} -1 )  DAY),
 '%Y%m%d'
 )
 ) report

+ 603 - 0
Apietl/bytedance_etl/Q4Task/AppBytedanceCompanyUserReportBusiMonth.py

@@ -0,0 +1,603 @@
+# Author renyupeng
+# coding=utf-8
+# @Time    : 2021/11/10 3:37 下午
+# @Site    :
+# @File    : AppBytedanceCompanyUserReportBusiMonth.py
+# @Software: PyCharm
+# @contact: renyupeng@c-top.com.cn
+# @Tel 1501435553
+import logging
+from Apietl.conn.TidbConn import TidbConn
+from Apietl.utlis.Utils import Utils
+
+
+class AppBytedanceCompanyUserReportBusiMonth:
+    def __init__(self):
+        self.conn = TidbConn.get_connection()
+        self.parm = Utils.get_task_args()
+        self.date_time = self.parm[0]
+        self.day_count = Utils.get_days()
+
+    def taskHandler(self):
+        try:
+            sql = """
+SET sql_mode = 'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
+REPLACE INTO application.app_bytedance_company_user_report_busi_m SELECT
+date_format({date_time},'%Y%m') stat_mon,
+company_id,
+company_name,
+org_code,
+org_type,
+dep_id,
+depart_name,
+leader_id,
+trim(leader_name) leader_name,
+count(DISTINCT account_id),
+sum(cost) cost,
+sum(`show`) `show`,
+round(sum(cost) / sum(`show`), 3) avg_show_cost,
+sum(click) click,
+round(sum(cost) / sum(`click`), 3) avg_click_cost,
+round(
+sum(click) / sum(`show`) * 100,
+3
+) ctr,
+sum(`convert`) `convert`,
+round(sum(cost) / sum(`convert`), 3) convert_cost,
+round(
+sum(`convert`) / sum(click) * 100,
+3
+) convert_rate,
+sum(deep_convert) deep_convert,
+round(
+sum(cost) / sum(deep_convert),
+3
+) deep_convert_cost,
+round(
+sum(deep_convert) / sum(`convert`) * 100,
+3
+) deep_convert_rate,
+sum(attribution_convert) attribution_convert,
+round(
+sum(cost) / sum(attribution_convert),
+3
+) attribution_convert_cost,
+sum(attribution_deep_convert) attribution_deep_convert,
+round(
+sum(cost) / sum(attribution_deep_convert),
+3
+) attribution_deep_convert_cost,
+sum(download_start) download_start,
+round(
+sum(cost) / sum(download_start),
+3
+) download_start_cost,
+round(
+sum(download_start) / sum(click),
+3
+) download_start_rate,
+sum(download_finish) download_finish,
+round(
+sum(cost) / sum(download_finish),
+3
+) download_finish_cost,
+round(
+sum(download_finish) / sum(download_start) * 100,
+3
+) download_finish_rate,
+sum(click_install) click_install,
+sum(install_finish) install_finish,
+round(
+sum(cost) / sum(install_finish),
+3
+) install_finish_cost,
+round(
+sum(install_finish) / sum(download_finish) * 100,
+3
+) install_finish_rate,
+sum(active) active,
+round(sum(cost) / sum(active), 3) active_cost,
+round(
+sum(active) / sum(click) * 100,
+3
+) active_rate,
+sum(register) register,
+round(sum(cost) / sum(register), 3) active_register_cost,
+round(
+sum(active_register_rate)/ {day_count} * 100,
+3
+) active_register_rate,
+sum(next_day_open) next_day_open,
+round(
+sum(cost) / sum(next_day_open),
+3
+) next_day_open_cost,
+round(
+sum(next_day_open) / sum(active) * 100,
+3
+) next_day_open_rate,
+sum(
+attribution_next_day_open_cnt
+) attribution_next_day_open_cnt,
+round(
+sum(cost) / sum(
+attribution_next_day_open_cnt
+),
+3
+) attribution_next_day_open_cost,
+round(
+sum(
+attribution_next_day_open_cnt
+) / sum(active) * 100,
+3
+) attribution_next_day_open_rate,
+sum(game_addiction) game_addiction,
+round(
+sum(cost) / sum(game_addiction),
+3
+) game_addiction_cost,
+round(
+sum(game_addiction_rate)/ {day_count} * 100,
+3
+) game_addiction_rate,
+sum(pay_count) pay_count,
+round(sum(cost) / sum(pay_count), 3) active_pay_cost,
+round(
+sum(pay_count) / sum(active) * 100,
+3
+) active_pay_rate,
+sum(loan_completion) loan_completion,
+round(
+sum(cost) / sum(loan_completion),
+3
+) loan_completion_cost,
+round(
+sum(loan_completion) / sum(register) * 100,
+3
+) loan_completion_rate,
+round(sum(pre_loan_credit), 3) pre_loan_credit,
+round(
+sum(cost) / sum(pre_loan_credit),
+3
+) pre_loan_credit_cost,
+sum(loan_credit) loan_credit,
+round(
+sum(cost) / sum(loan_credit),
+3
+) loan_credit_cost,
+round(
+sum(loan_credit) / sum(loan_completion) * 100,
+3
+) loan_credit_rate,
+sum(in_app_uv) in_app_uv,
+sum(in_app_detail_uv) in_app_detail_uv,
+sum(in_app_cart) in_app_cart,
+sum(in_app_pay) in_app_pay,
+sum(in_app_order) in_app_order,
+round(
+sum(
+attribution_game_pay_7d_count
+)/ {day_count},
+3
+) attribution_game_pay_7d_count,
+round(
+sum(
+attribution_game_pay_7d_cost
+)/ {day_count},
+3
+) attribution_game_pay_7d_cost,
+round(
+sum(
+attribution_active_pay_7d_per_count
+)/ {day_count},
+3
+) attribution_active_pay_7d_per_count,
+sum(game_pay_cost) game_pay_cost,
+sum(game_pay_count) game_pay_count,
+sum(phone) phone,
+sum(form) form,
+sum(map_search) map_search,
+sum(button) button,
+sum(`view`) `view`,
+sum(download) download,
+sum(qq) qq,
+sum(lottery) lottery,
+sum(vote) vote,
+sum(message) message,
+sum(redirect) redirect,
+sum(shopping) shopping,
+sum(consult) consult,
+sum(wechat) wechat,
+sum(phone_confirm) phone_confirm,
+sum(phone_connect) phone_connect,
+sum(consult_effective) consult_effective,
+sum(coupon) coupon,
+sum(coupon_single_page) coupon_single_page,
+sum(redirect_to_shop) redirect_to_shop,
+sum(poi_collect) poi_collect,
+sum(poi_address_click) poi_address_click,
+sum(luban_order_cnt) luban_order_cnt,
+sum(luban_order_stat_amount) luban_order_stat_amount,
+sum(luban_order_roi) luban_order_roi,
+sum(luban_live_enter_cnt) luban_live_enter_cnt,
+sum(
+live_watch_one_minute_count
+) live_watch_one_minute_count,
+sum(luban_live_follow_cnt) luban_live_follow_cnt,
+sum(live_fans_club_join_cnt) live_fans_club_join_cnt,
+sum(luban_live_comment_cnt) luban_live_comment_cnt,
+sum(luban_live_share_cnt) luban_live_share_cnt,
+sum(luban_live_gift_cnt) luban_live_gift_cnt,
+sum(luban_live_gift_amount) luban_live_gift_amount,
+sum(
+luban_live_slidecart_click_cnt
+) luban_live_slidecart_click_cnt,
+sum(
+luban_live_click_product_cnt
+) luban_live_click_product_cnt,
+sum(luban_live_pay_order_count) luban_live_pay_order_count,
+sum(
+luban_live_pay_order_stat_cost
+) luban_live_pay_order_stat_cost,
+sum(live_component_click_count) live_component_click_count,
+round(
+sum(cost) / sum(live_component_click_count),
+3
+) live_component_click_cost,
+round(
+sum(live_component_click_count)/ {day_count} * 100,
+3
+) live_component_click_rate,
+sum(wechat_login_count) wechat_login_count,
+sum(
+attribution_wechat_login_30d_count
+) attribution_wechat_login_30d_count,
+round(
+sum(cost) / sum(wechat_login_count),
+3
+) wechat_login_cost,
+round(
+sum(cost) / sum(
+attribution_wechat_login_30d_count
+),
+3
+) attribution_wechat_login_30d_cost,
+sum(wechat_first_pay_count) wechat_first_pay_count,
+sum(
+attribution_wechat_first_pay_30d_count
+) attribution_wechat_first_pay_30d_count,
+round(
+sum(cost) / sum(wechat_first_pay_count),
+3
+) wechat_first_pay_cost,
+round(
+sum(cost) / sum(
+attribution_wechat_first_pay_30d_count
+),
+3
+) attribution_wechat_first_pay_30d_cost,
+round(
+sum(wechat_first_pay_count) / sum(wechat_login_count) * 100,
+3
+) wechat_first_pay_rate,
+round(
+sum(
+attribution_wechat_first_pay_30d_count
+) / sum(
+attribution_wechat_login_30d_count
+) * 100,
+3
+) attribution_wechat_first_pay_30d_rate,
+sum(wechat_pay_amount) wechat_pay_amount,
+sum(
+attribution_wechat_pay_30d_amount
+) attribution_wechat_pay_30d_amount,
+sum(
+attribution_wechat_pay_30d_roi
+) attribution_wechat_pay_30d_roi,
+sum(phone_effective) phone_effective,
+sum(total_play) total_play,
+sum(valid_play) valid_play,
+round(
+sum(cost) / sum(valid_play),
+3
+) valid_play_cost,
+round(
+sum(valid_play) / sum(`show`) * 100,
+3
+) valid_play_rate,
+sum(play_25_feed_break) play_25_feed_break,
+sum(play_50_feed_break) play_50_feed_break,
+sum(play_75_feed_break) play_75_feed_break,
+sum(play_100_feed_break) play_100_feed_break,
+round(
+sum(average_play_time_per_play)/ {day_count},
+3
+) average_play_time_per_play,
+round(
+sum(play_over_rate)/ {day_count} * 100,
+3
+) play_over_rate,
+round(
+sum(wifi_play) / sum(total_play) * 100,
+3
+) wifi_play_rate,
+sum(wifi_play) wifi_play,
+round(sum(play_duration_sum)/ {day_count}, 3) play_duration_sum,
+sum(
+advanced_creative_phone_click
+) advanced_creative_phone_click,
+sum(
+advanced_creative_counsel_click
+) advanced_creative_counsel_click,
+sum(
+advanced_creative_form_click
+) advanced_creative_form_click,
+sum(
+advanced_creative_coupon_addition
+) advanced_creative_coupon_addition,
+sum(
+advanced_creative_form_submit
+) advanced_creative_form_submit,
+sum(card_show) card_show,
+sum(`share`) `share`,
+sum(`comment`) `comment`,
+sum(`like`) `like`,
+sum(follow) follow,
+sum(home_visited) home_visited,
+sum(ies_challenge_click) ies_challenge_click,
+sum(ies_music_click) ies_music_click,
+sum(location_click) location_click,
+sum(message_action) message_action,
+sum(click_landing_page) click_landing_page,
+sum(click_shopwindow) click_shopwindow,
+sum(click_website) click_website,
+sum(click_download) click_download,
+sum(click_call_dy) click_call_dy,
+sum(submit_certification_count) submit_certification_count,
+sum(approval_count) approval_count,
+sum(first_order_count) first_rental_order_count,
+sum(first_rental_order_count) first_order_count,
+sum(commute_first_pay_count) commute_first_pay_count
+FROM
+(
+SELECT
+report.advertiser_id account_id,
+dep.company_id,
+CASE
+WHEN dep.company_id = 'd57fecdcf7a94d009736d9c850731582' THEN
+'北京汇创思拓数字科技有限公司'
+WHEN dep.company_id = '6608ed13c0dd42de93c790dbdf124234' THEN
+'广州汇创思拓数字科技有限公司'
+WHEN dep.company_id = '4b10089775c040119e139087517aed88' THEN
+'上海汇创思拓数字科技有限公司'
+ELSE
+dep.company_name
+END company_name,
+dep.org_code,
+dep.org_type,
+dep.dep_id,
+dep.depart_name,
+dep.user_id,
+dep.realname,
+dep.leader_id,
+dep.leader_name,
+report.cost,
+report.`show`,
+report.avg_show_cost,
+report.click,
+report.avg_click_cost,
+report.ctr,
+report.`convert`,
+report.convert_cost,
+report.convert_rate,
+report.deep_convert,
+report.deep_convert_cost,
+report.deep_convert_rate,
+report.attribution_convert,
+report.attribution_convert_cost,
+report.attribution_deep_convert,
+report.attribution_deep_convert_cost,
+report.download_start,
+report.download_start_cost,
+report.download_start_rate,
+report.download_finish,
+report.download_finish_cost,
+report.download_finish_rate,
+report.click_install,
+report.install_finish,
+report.install_finish_cost,
+report.install_finish_rate,
+report.active,
+report.active_cost,
+report.active_rate,
+report.register,
+report.active_register_cost,
+report.active_register_rate,
+report.next_day_open,
+report.next_day_open_cost,
+report.next_day_open_rate,
+report.attribution_next_day_open_cnt,
+report.attribution_next_day_open_cost,
+report.attribution_next_day_open_rate,
+report.game_addiction,
+report.game_addiction_cost,
+report.game_addiction_rate,
+report.pay_count,
+report.active_pay_cost,
+report.active_pay_rate,
+report.loan_completion,
+report.loan_completion_cost,
+report.loan_completion_rate,
+report.pre_loan_credit,
+report.pre_loan_credit_cost,
+report.loan_credit,
+report.loan_credit_cost,
+report.loan_credit_rate,
+report.in_app_uv,
+report.in_app_detail_uv,
+report.in_app_cart,
+report.in_app_pay,
+report.in_app_order,
+report.attribution_game_pay_7d_count,
+report.attribution_game_pay_7d_cost,
+report.attribution_active_pay_7d_per_count,
+report.game_pay_cost,
+report.game_pay_count,
+report.phone,
+report.form,
+report.map_search,
+report.button,
+report.`view`,
+report.download,
+report.qq,
+report.lottery,
+report.vote,
+report.message,
+report.redirect,
+report.shopping,
+report.consult,
+report.wechat,
+report.phone_confirm,
+report.phone_connect,
+report.consult_effective,
+report.coupon,
+report.coupon_single_page,
+report.redirect_to_shop,
+report.poi_collect,
+report.poi_address_click,
+report.luban_order_cnt,
+report.luban_order_stat_amount,
+report.luban_order_roi,
+report.luban_live_enter_cnt,
+report.live_watch_one_minute_count,
+report.luban_live_follow_cnt,
+report.live_fans_club_join_cnt,
+report.luban_live_comment_cnt,
+report.luban_live_share_cnt,
+report.luban_live_gift_cnt,
+report.luban_live_gift_amount,
+report.luban_live_slidecart_click_cnt,
+report.luban_live_click_product_cnt,
+report.luban_live_pay_order_count,
+report.luban_live_pay_order_stat_cost,
+report.live_component_click_count,
+report.live_component_click_cost,
+report.live_component_click_rate,
+report.wechat_login_count,
+report.attribution_wechat_login_30d_count,
+report.wechat_login_cost,
+report.attribution_wechat_login_30d_cost,
+report.wechat_first_pay_count,
+report.attribution_wechat_first_pay_30d_count,
+report.wechat_first_pay_cost,
+report.attribution_wechat_first_pay_30d_cost,
+report.wechat_first_pay_rate,
+report.attribution_wechat_first_pay_30d_rate,
+report.wechat_pay_amount,
+report.attribution_wechat_pay_30d_amount,
+report.attribution_wechat_pay_30d_roi,
+report.phone_effective,
+report.total_play,
+report.valid_play,
+report.valid_play_cost,
+report.valid_play_rate,
+report.play_25_feed_break,
+report.play_50_feed_break,
+report.play_75_feed_break,
+report.play_100_feed_break,
+report.average_play_time_per_play,
+report.play_over_rate,
+report.wifi_play_rate,
+report.wifi_play,
+report.play_duration_sum,
+report.advanced_creative_phone_click,
+report.advanced_creative_counsel_click,
+report.advanced_creative_form_click,
+report.advanced_creative_coupon_addition,
+report.advanced_creative_form_submit,
+report.card_show,
+report.`share`,
+report.`comment`,
+report.`like`,
+report.follow,
+report.home_visited,
+report.ies_challenge_click,
+report.ies_music_click,
+report.location_click,
+report.message_action,
+report.click_landing_page,
+report.click_shopwindow,
+report.click_website,
+report.click_download,
+report.click_call_dy,
+report.submit_certification_count,
+report.approval_count,
+report.first_rental_order_count,
+report.first_order_count,
+report.commute_first_pay_count
+FROM
+(
+SELECT
+*
+FROM
+media_api.bytedance_advertiser_report_daily
+WHERE
+stat_datetime >= date_format(
+date_sub({date_time}, INTERVAL ({day_count} -1 )  DAY),
+'%Y%m%d'
+)
+) report
+LEFT JOIN (
+SELECT
+cua.account_id,
+uc.company_id,
+uc.company_name,
+pa.org_code,
+pa.org_type,
+pa.id dep_id,
+pa.depart_name,
+cua.user_id,
+su.realname ,
+cp.sale_id,
+su.leader_id,
+se.realname as leader_name
+FROM
+`jeecg-boot`.ctop_user_allocation cua
+LEFT JOIN `jeecg-boot`.ctop_project cp ON cua.project_id = cp.id
+LEFT JOIN `jeecg-boot`.user_company uc ON uc.user_id = cua.user_id
+LEFT JOIN `jeecg-boot`.sys_user su ON su.id = cua.user_id
+LEFT JOIN `jeecg-boot`.sys_user se ON se.id = su.leader_id
+LEFT JOIN `jeecg-boot`.sys_user_depart de ON su.leader_id = de.user_id
+LEFT JOIN `jeecg-boot`.sys_depart pa ON pa.id = de.dep_id
+) dep ON report.advertiser_id = dep.account_id
+) info
+GROUP BY
+company_id,
+company_name,
+org_code,
+org_type,
+dep_id,
+depart_name,
+leader_id,
+trim(leader_name)
+HAVING
+sum(cost) >= 0;
+            """.format(date_time=self.date_time, day_count=self.day_count)
+            TidbConn.upsert(conn=self.conn, sql_buff=sql)
+            self.conn.commit()
+            TidbConn.conn_close(conn=self.conn)
+            return 0
+        except Exception as e:
+            logging.error(e)
+            return -1
+
+
+if __name__ == '__main__':
+    status = AppBytedanceCompanyUserReportBusiMonth().taskHandler()
+    if status == 0:
+        print("作业执行成功")
+        exit(0)
+    else:
+        print("作业执行失败")
+        exit(-1)

+ 2 - 2
Apietl/bytedance_etl/Q4Task/AppBytedanceImageReportBusi.py

@@ -28,7 +28,7 @@ group by project_id """
                 try:
                     sql = """SET sql_mode = 'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
 REPLACE INTO application.app_bytedance_image_report_busi_{day_count}d
-SELECT concat(date_format(date_sub({date_time}, INTERVAL 6 DAY),'%Y%m%d'),'-',{date_time})           time,
+SELECT concat(date_format(date_sub({date_time}, INTERVAL ({day_count} -1 )  DAY),'%Y%m%d'),'-',{date_time})           time,
        report.account_id,
        #'账户ID'
        report.material_id,
@@ -626,7 +626,7 @@ FROM (
     'CREATIVE_IMAGE_MODE_UNION_SPLASH'
              )
            AND stat_datetime >= date_format(
-                 date_sub({date_time}, INTERVAL 6 DAY),
+                 date_sub({date_time}, INTERVAL ({day_count} -1 )  DAY),
                  '%Y%m%d'
              )
          GROUP BY advertiser_id,

+ 671 - 0
Apietl/bytedance_etl/Q4Task/AppBytedanceImageReportBusiMonth.py

@@ -0,0 +1,671 @@
+# Author renyupeng
+# coding=utf-8
+# @Time    : 2021/11/10 3:37 下午
+# @Site    : 
+# @File    : AppBytedanceImageReportBusiMonth.py
+# @Software: PyCharm
+# @contact: renyupeng@c-top.com.cn
+# @Tel 1501435553
+import logging
+
+from Apietl.conn.TidbConn import TidbConn
+from Apietl.utlis.Utils import Utils
+
+
+class AppBytedanceImageReportBusiMonth:
+    def __init__(self):
+        self.conn = TidbConn.get_connection()
+        self.parm = Utils.get_task_args()
+        self.date_time = self.parm[0]
+        self.day_count = Utils.get_days()
+
+    def taskHandler(self):
+        try:
+            sql_porject = """select project_id from `jeecg-boot`.ctop_user_allocation where media_id=1
+group by project_id """
+            project_list = TidbConn.quary(self.conn,sql_porject)
+            for project_id in project_list:
+                try:
+                    sql = """SET sql_mode = 'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
+REPLACE INTO application.app_bytedance_image_report_busi_m
+SELECT date_format({date_time},'%Y%m')          stat_non,
+       report.account_id,
+       #'账户ID'
+       report.material_id,
+       #头条素材id
+       report.image_mode,
+       #素材类型
+       report.inventory,
+       #广告位
+       cua.project_id,
+       #项目id
+       product.id    product_id,
+       #项目中产品id
+       cua.advertiser_id,
+       #广告主id
+       uc.company_id,
+       #运营人的公司id
+       cua.auth_name account_name,
+       #账户名称
+       cp.project_name,
+       #项目名称
+       ca.`name`     advertiser_name,
+       #广告主名称
+       uc.company_name,
+       #运营人的公司名称
+       cp.sale_id,
+       #项目里的销售id
+       cua.user_id,
+       #运营id
+       su.org_code,
+       #机构编码
+       video.signature    signature,
+       #素材id
+       CASE
+           WHEN cmi.material_name IS NOT NULL THEN
+               cmi.material_name
+           ELSE
+               video.filename
+           END AS    video_name,
+       report.cost,
+       report.`show`,
+       report.avg_show_cost,
+       report.click,
+       report.avg_click_cost,
+       report.ctr,
+       report.`convert`,
+       report.convert_cost,
+       report.convert_rate,
+       report.deep_convert,
+       report.deep_convert_cost,
+       report.deep_convert_rate,
+       report.attribution_convert,
+       report.attribution_convert_cost,
+       report.attribution_deep_convert,
+       report.attribution_deep_convert_cost,
+       report.download_start,
+       report.download_start_cost,
+       report.download_start_rate,
+       report.download_finish,
+       report.download_finish_cost,
+       report.download_finish_rate,
+       report.click_install,
+       report.install_finish,
+       report.install_finish_cost,
+       report.install_finish_rate,
+       report.active,
+       report.active_cost,
+       report.active_rate,
+       report.register,
+       report.active_register_cost,
+       report.active_register_rate,
+       report.active_pay_amount,
+       report.next_day_open,
+       report.next_day_open_cost,
+       report.next_day_open_rate,
+       report.attribution_next_day_open_cnt,
+       report.attribution_next_day_open_cost,
+       report.attribution_next_day_open_rate,
+       report.game_addiction,
+       report.game_addiction_cost,
+       report.game_addiction_rate,
+       report.pay_count,
+       report.active_pay_cost,
+       report.active_pay_rate,
+       report.loan_completion,
+       report.loan_completion_cost,
+       report.loan_completion_rate,
+       report.pre_loan_credit,
+       report.pre_loan_credit_cost,
+       report.loan_credit,
+       report.loan_credit_cost,
+       report.loan_credit_rate,
+       report.in_app_uv,
+       report.in_app_detail_uv,
+       report.in_app_cart,
+       report.in_app_pay,
+       report.in_app_order,
+       report.attribution_game_pay_7d_count,
+       report.attribution_game_pay_7d_cost,
+       report.attribution_active_pay_7d_per_count,
+       report.game_pay_cost,
+       report.game_pay_count,
+       report.phone,
+       report.form,
+       report.map_search,
+       report.button,
+       report.`view`,
+       report.download,
+       report.qq,
+       report.lottery,
+       report.vote,
+       report.message,
+       report.redirect,
+       report.shopping,
+       report.consult,
+       report.wechat,
+       report.phone_confirm,
+       report.phone_connect,
+       report.consult_effective,
+       report.coupon,
+       report.coupon_single_page,
+       report.redirect_to_shop,
+       report.poi_collect,
+       report.poi_address_click,
+       report.luban_order_cnt,
+       report.luban_order_stat_amount,
+       report.luban_order_roi,
+       report.luban_live_enter_cnt,
+       report.live_watch_one_minute_count,
+       report.luban_live_follow_cnt,
+       report.live_fans_club_join_cnt,
+       report.luban_live_comment_cnt,
+       report.luban_live_share_cnt,
+       report.luban_live_gift_cnt,
+       report.luban_live_gift_amount,
+       report.luban_live_slidecart_click_cnt,
+       report.luban_live_click_product_cnt,
+       report.luban_live_pay_order_count,
+       report.luban_live_pay_order_stat_cost,
+       report.wechat_login_count,
+       report.attribution_wechat_login_30d_count,
+       report.wechat_login_cost,
+       report.attribution_wechat_login_30d_cost,
+       report.wechat_first_pay_count,
+       report.attribution_wechat_first_pay_30d_count,
+       report.wechat_first_pay_cost,
+       report.attribution_wechat_first_pay_30d_cost,
+       report.wechat_first_pay_rate,
+       report.attribution_wechat_first_pay_30d_rate,
+       report.wechat_pay_amount,
+       report.attribution_wechat_pay_30d_amount,
+       report.attribution_wechat_pay_30d_roi,
+       report.phone_effective,
+       report.total_play,
+       report.valid_play,
+       report.valid_play_cost,
+       report.valid_play_rate,
+       report.play_25_feed_break,
+       report.play_50_feed_break,
+       report.play_75_feed_break,
+       report.play_100_feed_break,
+       report.average_play_time_per_play,
+       report.play_over_rate,
+       report.wifi_play_rate,
+       report.wifi_play,
+       report.play_duration_sum,
+       report.advanced_creative_phone_click,
+       report.advanced_creative_counsel_click,
+       report.advanced_creative_form_click,
+       report.advanced_creative_coupon_addition,
+       report.advanced_creative_form_submit,
+       report.card_show,
+       report.`share`,
+       report.`comment`,
+       report.`like`,
+       report.follow,
+       report.home_visited,
+       report.ies_challenge_click,
+       report.ies_music_click,
+       report.location_click,
+       report.message_action,
+       report.click_landing_page,
+       report.click_shopwindow,
+       report.click_website,
+       report.click_download,
+       report.click_call_dy,
+       report.`cpc`,
+       report.`cpm`,
+       report.`cpa`,
+       report.`interact_per_cost`,
+       report.`convert_show_rate`,
+       report.`play_duration_10s_rate`,
+       report.`play_50_feed_break_rate`,
+       report.`play_25_feed_break_rate`,
+       report.`play_duration_5s_rate`,
+       report.`play_duration_2s_rate`,
+       report.`average_play_progress`,
+       report.`play_100_feed_break_rate`,
+       report.`play_duration_3s_rate`,
+       report.`play_75_feed_break_rate`,
+       report.`play_duration`,
+       report.`play_duration_3s`,
+       report.`play_duration_2s`,
+       report.`play_duration_10s`,
+       report.`average_video_play`,
+       report.`avg_rank`,
+       report.submit_certification_count,
+       report.approval_count,
+       report.first_rental_order_count,
+       report.first_order_count,
+       report.commute_first_pay_count,
+       video.`video_url`,
+       cmi.`cover_url`
+FROM (
+         SELECT advertiser_id                        account_id,
+                material_id,
+                image_mode,
+                inventory,
+                sum(cost)                            cost,
+                sum(`show`)                          `show`,
+                round(sum(cost) / sum(`show`), 3)    avg_show_cost,
+                sum(click)                           click,
+                round(sum(cost) / sum(`click`), 3)   avg_click_cost,
+                round(
+                        sum(click) / sum(`show`) * 100,
+                        3
+                    )                                ctr,
+                sum(`convert`)                       `convert`,
+                round(sum(cost) / sum(`convert`), 3) convert_cost,
+                round(
+                        sum(`convert`) / sum(click) * 100,
+                        3
+                    )                                convert_rate,
+                sum(deep_convert)                    deep_convert,
+                round(
+                        sum(cost) / sum(deep_convert),
+                        3
+                    )                                deep_convert_cost,
+                round(
+                        sum(deep_convert) / sum(`convert`) * 100,
+                        3
+                    )                                deep_convert_rate,
+                sum(attribution_convert)             attribution_convert,
+                round(
+                        sum(cost) / sum(attribution_convert),
+                        3
+                    )                                attribution_convert_cost,
+                sum(attribution_deep_convert)        attribution_deep_convert,
+                round(
+                        sum(cost) / sum(attribution_deep_convert),
+                        3
+                    )                                attribution_deep_convert_cost,
+                sum(download_start)                  download_start,
+                round(
+                        sum(cost) / sum(download_start),
+                        3
+                    )                                download_start_cost,
+                round(
+                        sum(download_start) / sum(click),
+                        3
+                    )                                download_start_rate,
+                sum(download_finish)                 download_finish,
+                round(
+                        sum(cost) / sum(download_finish),
+                        3
+                    )                                download_finish_cost,
+                round(
+                        sum(download_finish) / sum(download_start) * 100,
+                        3
+                    )                                download_finish_rate,
+                sum(click_install)                   click_install,
+                sum(install_finish)                  install_finish,
+                round(
+                        sum(cost) / sum(install_finish),
+                        3
+                    )                                install_finish_cost,
+                round(
+                        sum(install_finish) / sum(download_finish) * 100,
+                        3
+                    )                                install_finish_rate,
+                sum(active)                          active,
+                round(sum(cost) / sum(active), 3)    active_cost,
+                round(
+                        sum(active) / sum(click) * 100,
+                        3
+                    )                                active_rate,
+                sum(register)                        register,
+                round(sum(cost) / sum(register), 3)  active_register_cost,
+                round(
+                        sum(active_register_rate) / {day_count} * 100,
+                        3
+                    )                                active_register_rate,
+                sum(active_pay_amount)               active_pay_amount,
+                sum(next_day_open)                   next_day_open,
+                round(
+                        sum(cost) / sum(next_day_open),
+                        3
+                    )                                next_day_open_cost,
+                round(
+                        sum(next_day_open) / sum(active) * 100,
+                        3
+                    )                                next_day_open_rate,
+                sum(
+                        attribution_next_day_open_cnt
+                    )                                attribution_next_day_open_cnt,
+                round(
+                            sum(cost) / sum(
+                                attribution_next_day_open_cnt
+                            ),
+                            3
+                    )                                attribution_next_day_open_cost,
+                round(
+                                sum(
+                                        attribution_next_day_open_cnt
+                                    ) / sum(active) * 100,
+                                3
+                    )                                attribution_next_day_open_rate,
+                sum(game_addiction)                  game_addiction,
+                round(
+                        sum(cost) / sum(game_addiction),
+                        3
+                    )                                game_addiction_cost,
+                round(
+                        sum(game_addiction_rate) / {day_count} * 100,
+                        3
+                    )                                game_addiction_rate,
+                sum(pay_count)                       pay_count,
+                round(sum(cost) / sum(pay_count), 3) active_pay_cost,
+                round(
+                        sum(pay_count) / sum(active) * 100,
+                        3
+                    )                                active_pay_rate,
+                sum(loan_completion)                 loan_completion,
+                round(
+                        sum(cost) / sum(loan_completion),
+                        3
+                    )                                loan_completion_cost,
+                round(
+                        sum(loan_completion) / sum(register) * 100,
+                        3
+                    )                                loan_completion_rate,
+                round(sum(pre_loan_credit), 3)       pre_loan_credit,
+                round(
+                        sum(cost) / sum(pre_loan_credit),
+                        3
+                    )                                pre_loan_credit_cost,
+                sum(loan_credit)                     loan_credit,
+                round(
+                        sum(cost) / sum(loan_credit),
+                        3
+                    )                                loan_credit_cost,
+                round(
+                        sum(loan_credit) / sum(loan_completion) * 100,
+                        3
+                    )                                loan_credit_rate,
+                sum(in_app_uv)                       in_app_uv,
+                sum(in_app_detail_uv)                in_app_detail_uv,
+                sum(in_app_cart)                     in_app_cart,
+                sum(in_app_pay)                      in_app_pay,
+                sum(in_app_order)                    in_app_order,
+                round(
+                            sum(
+                                    attribution_game_pay_7d_count
+                                ) / {day_count},
+                            3
+                    )                                attribution_game_pay_7d_count,
+                round(
+                            sum(
+                                    attribution_game_pay_7d_cost
+                                ) / {day_count},
+                            3
+                    )                                attribution_game_pay_7d_cost,
+                round(
+                            sum(
+                                    attribution_active_pay_7d_per_count
+                                ) / {day_count},
+                            3
+                    )                                attribution_active_pay_7d_per_count,
+                sum(game_pay_cost)                   game_pay_cost,
+                sum(game_pay_count)                  game_pay_count,
+                sum(phone)                           phone,
+                sum(form)                            form,
+                sum(map_search)                      map_search,
+                sum(button)                          button,
+                sum(`view`)                          `view`,
+                sum(download)                        download,
+                sum(qq)                              qq,
+                sum(lottery)                         lottery,
+                sum(vote)                            vote,
+                sum(message)                         message,
+                sum(redirect)                        redirect,
+                sum(shopping)                        shopping,
+                sum(consult)                         consult,
+                sum(wechat)                          wechat,
+                sum(phone_confirm)                   phone_confirm,
+                sum(phone_connect)                   phone_connect,
+                sum(consult_effective)               consult_effective,
+                sum(coupon)                          coupon,
+                sum(coupon_single_page)              coupon_single_page,
+                sum(redirect_to_shop)                redirect_to_shop,
+                sum(poi_collect)                     poi_collect,
+                sum(poi_address_click)               poi_address_click,
+                sum(luban_order_cnt)                 luban_order_cnt,
+                sum(luban_order_stat_amount)         luban_order_stat_amount,
+                sum(luban_order_roi)                 luban_order_roi,
+                sum(luban_live_enter_cnt)            luban_live_enter_cnt,
+                sum(
+                        live_watch_one_minute_count
+                    )                                live_watch_one_minute_count,
+                sum(luban_live_follow_cnt)           luban_live_follow_cnt,
+                sum(live_fans_club_join_cnt)         live_fans_club_join_cnt,
+                sum(luban_live_comment_cnt)          luban_live_comment_cnt,
+                sum(luban_live_share_cnt)            luban_live_share_cnt,
+                sum(luban_live_gift_cnt)             luban_live_gift_cnt,
+                sum(luban_live_gift_amount)          luban_live_gift_amount,
+                sum(
+                        luban_live_slidecart_click_cnt
+                    )                                luban_live_slidecart_click_cnt,
+                sum(
+                        luban_live_click_product_cnt
+                    )                                luban_live_click_product_cnt,
+                sum(luban_live_pay_order_count)      luban_live_pay_order_count,
+                sum(
+                        luban_live_pay_order_stat_cost
+                    )                                luban_live_pay_order_stat_cost,
+                sum(wechat_login_count)              wechat_login_count,
+                sum(
+                        attribution_wechat_login_30d_count
+                    )                                attribution_wechat_login_30d_count,
+                round(
+                        sum(cost) / sum(wechat_login_count),
+                        3
+                    )                                wechat_login_cost,
+                round(
+                            sum(cost) / sum(
+                                attribution_wechat_login_30d_count
+                            ),
+                            3
+                    )                                attribution_wechat_login_30d_cost,
+                sum(wechat_first_pay_count)          wechat_first_pay_count,
+                sum(
+                        attribution_wechat_first_pay_30d_count
+                    )                                attribution_wechat_first_pay_30d_count,
+                round(
+                        sum(cost) / sum(wechat_first_pay_count),
+                        3
+                    )                                wechat_first_pay_cost,
+                round(
+                            sum(cost) / sum(
+                                attribution_wechat_first_pay_30d_count
+                            ),
+                            3
+                    )                                attribution_wechat_first_pay_30d_cost,
+                round(
+                        sum(wechat_first_pay_count) / sum(wechat_login_count) * 100,
+                        3
+                    )                                wechat_first_pay_rate,
+                round(
+                                sum(
+                                        attribution_wechat_first_pay_30d_count
+                                    ) / sum(
+                                        attribution_wechat_login_30d_count
+                                    ) * 100,
+                                3
+                    )                                attribution_wechat_first_pay_30d_rate,
+                sum(wechat_pay_amount)               wechat_pay_amount,
+                sum(
+                        attribution_wechat_pay_30d_amount
+                    )                                attribution_wechat_pay_30d_amount,
+                sum(
+                        attribution_wechat_pay_30d_roi
+                    )                                attribution_wechat_pay_30d_roi,
+                sum(phone_effective)                 phone_effective,
+                sum(total_play)                      total_play,
+                sum(valid_play)                      valid_play,
+                round(
+                        sum(cost) / sum(valid_play),
+                        3
+                    )                                valid_play_cost,
+                round(
+                        sum(valid_play) / sum(`show`) * 100,
+                        3
+                    )                                valid_play_rate,
+                sum(play_25_feed_break)              play_25_feed_break,
+                sum(play_50_feed_break)              play_50_feed_break,
+                sum(play_75_feed_break)              play_75_feed_break,
+                sum(play_100_feed_break)             play_100_feed_break,
+                round(
+                        sum(average_play_time_per_play) / {day_count},
+                        3
+                    )                                average_play_time_per_play,
+                round(
+                        sum(play_over_rate) / {day_count} * 100,
+                        3
+                    )                                play_over_rate,
+                round(
+                        sum(wifi_play) / sum(total_play) * 100,
+                        3
+                    )                                wifi_play_rate,
+                sum(wifi_play)                       wifi_play,
+                round(sum(play_duration_sum) / {day_count}, 3) play_duration_sum,
+                sum(
+                        advanced_creative_phone_click
+                    )                                advanced_creative_phone_click,
+                sum(
+                        advanced_creative_counsel_click
+                    )                                advanced_creative_counsel_click,
+                sum(
+                        advanced_creative_form_click
+                    )                                advanced_creative_form_click,
+                sum(
+                        advanced_creative_coupon_addition
+                    )                                advanced_creative_coupon_addition,
+                sum(
+                        advanced_creative_form_submit
+                    )                                advanced_creative_form_submit,
+                sum(card_show)                       card_show,
+                sum(`share`)                         `share`,
+                sum(`comment`)                       `comment`,
+                sum(`like`)                          `like`,
+                sum(follow)                          follow,
+                sum(home_visited)                    home_visited,
+                sum(ies_challenge_click)             ies_challenge_click,
+                sum(ies_music_click)                 ies_music_click,
+                sum(location_click)                  location_click,
+                sum(message_action)                  message_action,
+                sum(click_landing_page)              click_landing_page,
+                sum(click_shopwindow)                click_shopwindow,
+                sum(click_website)                   click_website,
+                sum(click_download)                  click_download,
+                sum(click_call_dy)                   click_call_dy,
+                sum(cpc)                             cpc,
+                sum(cpm)                             cpm,
+                sum(cpa)                             cpa,
+                round(sum(interact_per_cost) / {day_count}, 3) interact_per_cost,
+                round(sum(convert_show_rate) / {day_count}, 3) convert_show_rate,
+                round(
+                        sum(round(play_duration_10s)) / sum(total_play) * 100,
+                        3
+                    )                                play_duration_10s_rate,
+                round(
+                        sum(play_50_feed_break) / sum(total_play) * 100,
+                        3
+                    )                                play_50_feed_break_rate,
+                round(
+                        sum(play_25_feed_break) / sum(total_play) * 100,
+                        3
+                    )                                play_25_feed_break_rate,
+                round(
+                        sum(play_duration_5s_rate) / {day_count},
+                        3
+                    )                                play_duration_5s_rate,
+                round(
+                        sum(play_duration_2s) / sum(total_play) * 100,
+                        3
+                    )                                play_duration_2s_rate,
+                round(
+                        sum(average_play_progress) / {day_count},
+                        3
+                    )                                average_play_progress,
+                round(
+                        sum(play_100_feed_break) / sum(total_play) * 100,
+                        3
+                    )                                play_100_feed_break_rate,
+                round(
+                        sum(play_duration_3s) / sum(total_play) * 100,
+                        3
+                    )                                play_duration_3s_rate,
+                round(
+                        sum(play_75_feed_break) / sum(total_play) * 100,
+                        3
+                    )                                play_75_feed_break_rate,
+                sum(play_duration)                   play_duration,
+                sum(play_duration_3s)                play_duration_3s,
+                sum(play_duration_2s)                play_duration_2s,
+                sum(play_duration_10s)               play_duration_10s,
+                round(
+                        sum(average_video_play) / {day_count},
+                        3
+                    )                                average_video_play,
+                sum(avg_rank)                        avg_rank,
+                sum(submit_certification_count)      submit_certification_count,
+                sum(approval_count)                  approval_count,
+                sum(first_order_count)               first_rental_order_count,
+                sum(first_rental_order_count)        first_order_count,
+                sum(commute_first_pay_count)         commute_first_pay_count
+         FROM media_api.bytedance_material_report_daily zhubiao
+         WHERE image_mode IN (
+    'CREATIVE_IMAGE_MODE_SMALL',
+    'CREATIVE_IMAGE_MODE_LARGE',
+    'CREATIVE_IMAGE_MODE_LARGE_VERTICAL',
+    'CREATIVE_IMAGE_MODE_GROUP',
+    'CREATIVE_IMAGE_MODE_GIF',
+    'TOUTIAO_SEARCH_AD_IMAGE',
+    'SEARCH_AD_SMALL_IMAGE',
+    'CREATIVE_IMAGE_MODE_UNION_SPLASH'
+             )
+           AND stat_datetime >= date_format(
+                 date_sub({date_time}, INTERVAL {day_count}  DAY),
+                 '%Y%m%d'
+             )
+         GROUP BY advertiser_id,
+                  material_id,
+                  image_mode,
+                  inventory
+     ) report
+        LEFT JOIN (select advertiser_id,signature,material_id,filename,image_url from  `media_api`.bytedance_file_image_get group by advertiser_id,signature,material_id,filename,image_url)  video 
+ON report.account_id = video.advertiser_id AND report.material_id = video.material_id
+          LEFT JOIN `jeecg-boot`.ctop_user_allocation cua
+                   ON report.advertiser_id = cua.account_id
+          LEFT JOIN `jeecg-boot`.ctop_advertiser ca
+                   ON cua.advertiser_id = ca.id
+          LEFT JOIN `jeecg-boot`.ctop_project cp
+                   ON cua.project_id = cp.id
+          LEFT JOIN `jeecg-boot`.user_company uc
+                   ON cua.user_id = uc.user_id
+          LEFT JOIN `jeecg-boot`.ctop_product product
+                   ON cp.product_id = product.id
+         LEFT JOIN `jeecg-boot`.sys_user su
+                   ON cua.user_id = su.id
+""".format(date_time=self.date_time, day_count=self.day_count, project_id=project_id[0])
+                    TidbConn.upsert(conn=self.conn, sql_buff=sql)
+                    self.conn.commit()
+                except Exception as e:
+                    logging.error(e)
+                    return -1
+            TidbConn.conn_close(conn=self.conn)
+            return 0
+        except Exception as e:
+            logging.error(e)
+            return -1
+
+
+if __name__ == '__main__':
+    status = AppBytedanceImageReportBusiMonth().taskHandler()
+    if status == 0:
+        print("作业执行成功")
+        exit(0)
+    else:
+        print("作业执行失败")
+        exit(-1)

+ 2 - 2
Apietl/bytedance_etl/Q4Task/AppBytedanceProductReportBusi.py

@@ -26,7 +26,7 @@ SET sql_mode = 'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_AUTO_CREATE_
 REPLACE INTO application.app_bytedance_product_report_busi_{day_count}d
 SELECT concat(
                date_format(
-                       date_sub({date_time}, INTERVAL 6 DAY),
+                       date_sub({date_time}, INTERVAL ({day_count} -1 )  DAY),
                        '%Y%m%d'
                    ),
                '-',
@@ -376,7 +376,7 @@ FROM (
          SELECT *
          FROM media_api.bytedance_advertiser_report_daily
          WHERE stat_datetime >= date_format(
-                 date_sub({date_time}, INTERVAL 6 DAY),
+                 date_sub({date_time}, INTERVAL ({day_count} -1 )  DAY),
                  '%Y%m%d'
              )
      ) report

+ 412 - 0
Apietl/bytedance_etl/Q4Task/AppBytedanceProductReportBusiMonth.py

@@ -0,0 +1,412 @@
+# Author renyupeng
+# coding=utf-8
+# @Time    : 2021/11/10 3:37 下午
+# @Site    :
+# @File    : AppBytedanceProductReportBusiMonth.py
+# @Software: PyCharm
+# @contact: renyupeng@c-top.com.cn
+# @Tel 1501435553
+import logging
+
+from Apietl.conn.TidbConn import TidbConn
+from Apietl.utlis.Utils import Utils
+
+
+class AppBytedanceProductReportBusiMonth:
+    def __init__(self):
+        self.conn = TidbConn.get_connection()
+        self.parm = Utils.get_task_args()
+        self.date_time = self.parm[0]
+        self.day_count = Utils.get_days()
+
+    def taskHandler(self):
+        try:
+            sql = """
+SET sql_mode = 'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
+REPLACE INTO application.app_bytedance_product_report_busi_m
+SELECT concat(
+               date_format({date_time},'%Y%m')         as          stat_mon,
+       uc.company_id,
+       CASE
+           WHEN uc.company_id = 'd57fecdcf7a94d009736d9c850731582' THEN
+               '北京汇创思拓数字科技有限公司'
+           WHEN uc.company_id = '6608ed13c0dd42de93c790dbdf124234' THEN
+               '广州汇创思拓数字科技有限公司'
+           WHEN uc.company_id = '4b10089775c040119e139087517aed88' THEN
+               '上海汇创思拓数字科技有限公司'
+           ELSE
+               uc.company_name
+           END                              company_name,
+       cn.id                                product_id,
+       cn.product_name,
+       count(report.advertiser_id)          account_count,
+       sum(cost)                            cost,
+       sum(`show`)                          `show`,
+       round(sum(cost) / sum(`show`), 3)    avg_show_cost,
+       sum(click)                           click,
+       round(sum(cost) / sum(`click`), 3)   avg_click_cost,
+       round(
+               sum(click) / sum(`show`) * 100,
+               3
+           )                                ctr,
+       sum(`convert`)                       `convert`,
+       round(sum(cost) / sum(`convert`), 3) convert_cost,
+       round(
+               sum(`convert`) / sum(click) * 100,
+               3
+           )                                convert_rate,
+       sum(deep_convert)                    deep_convert,
+       round(
+               sum(cost) / sum(deep_convert),
+               3
+           )                                deep_convert_cost,
+       round(
+               sum(deep_convert) / sum(`convert`) * 100,
+               3
+           )                                deep_convert_rate,
+       sum(attribution_convert)             attribution_convert,
+       round(
+               sum(cost) / sum(attribution_convert),
+               3
+           )                                attribution_convert_cost,
+       sum(attribution_deep_convert)        attribution_deep_convert,
+       round(
+               sum(cost) / sum(attribution_deep_convert),
+               3
+           )                                attribution_deep_convert_cost,
+       sum(download_start)                  download_start,
+       round(
+               sum(cost) / sum(download_start),
+               3
+           )                                download_start_cost,
+       round(
+               sum(download_start) / sum(click),
+               3
+           )                                download_start_rate,
+       sum(download_finish)                 download_finish,
+       round(
+               sum(cost) / sum(download_finish),
+               3
+           )                                download_finish_cost,
+       round(
+               sum(download_finish) / sum(download_start) * 100,
+               3
+           )                                download_finish_rate,
+       sum(click_install)                   click_install,
+       sum(install_finish)                  install_finish,
+       round(
+               sum(cost) / sum(install_finish),
+               3
+           )                                install_finish_cost,
+       round(
+               sum(install_finish) / sum(download_finish) * 100,
+               3
+           )                                install_finish_rate,
+       sum(active)                          active,
+       round(sum(cost) / sum(active), 3)    active_cost,
+       round(
+               sum(active) / sum(click) * 100,
+               3
+           )                                active_rate,
+       sum(register)                        register,
+       round(sum(cost) / sum(register), 3)  active_register_cost,
+       round(
+               sum(active_register_rate) / {day_count} * 100,
+               3
+           )                                active_register_rate,
+       sum(next_day_open)                   next_day_open,
+       round(
+               sum(cost) / sum(next_day_open),
+               3
+           )                                next_day_open_cost,
+       round(
+               sum(next_day_open) / sum(active) * 100,
+               3
+           )                                next_day_open_rate,
+       sum(
+               attribution_next_day_open_cnt
+           )                                attribution_next_day_open_cnt,
+       round(
+                   sum(cost) / sum(
+                       attribution_next_day_open_cnt
+                   ),
+                   3
+           )                                attribution_next_day_open_cost,
+       round(
+                       sum(
+                               attribution_next_day_open_cnt
+                           ) / sum(active) * 100,
+                       3
+           )                                attribution_next_day_open_rate,
+       sum(game_addiction)                  game_addiction,
+       round(
+               sum(cost) / sum(game_addiction),
+               3
+           )                                game_addiction_cost,
+       round(
+               sum(game_addiction_rate) / {day_count} * 100,
+               3
+           )                                game_addiction_rate,
+       sum(pay_count)                       pay_count,
+       round(sum(cost) / sum(pay_count), 3) active_pay_cost,
+       round(
+               sum(pay_count) / sum(active) * 100,
+               3
+           )                                active_pay_rate,
+       sum(loan_completion)                 loan_completion,
+       round(
+               sum(cost) / sum(loan_completion),
+               3
+           )                                loan_completion_cost,
+       round(
+               sum(loan_completion) / sum(register) * 100,
+               3
+           )                                loan_completion_rate,
+       round(sum(pre_loan_credit), 3)       pre_loan_credit,
+       round(
+               sum(cost) / sum(pre_loan_credit),
+               3
+           )                                pre_loan_credit_cost,
+       sum(loan_credit)                     loan_credit,
+       round(
+               sum(cost) / sum(loan_credit),
+               3
+           )                                loan_credit_cost,
+       round(
+               sum(loan_credit) / sum(loan_completion) * 100,
+               3
+           )                                loan_credit_rate,
+       sum(in_app_uv)                       in_app_uv,
+       sum(in_app_detail_uv)                in_app_detail_uv,
+       sum(in_app_cart)                     in_app_cart,
+       sum(in_app_pay)                      in_app_pay,
+       sum(in_app_order)                    in_app_order,
+       round(
+                   sum(
+                           attribution_game_pay_7d_count
+                       ) / {day_count},
+                   3
+           )                                attribution_game_pay_7d_count,
+       round(
+                   sum(
+                           attribution_game_pay_7d_cost
+                       ) / {day_count},
+                   3
+           )                                attribution_game_pay_7d_cost,
+       round(
+                   sum(
+                           attribution_active_pay_7d_per_count
+                       ) / {day_count},
+                   3
+           )                                attribution_active_pay_7d_per_count,
+       sum(game_pay_cost)                   game_pay_cost,
+       sum(game_pay_count)                  game_pay_count,
+       sum(phone)                           phone,
+       sum(form)                            form,
+       sum(map_search)                      map_search,
+       sum(button)                          button,
+       sum(`view`)                          `view`,
+       sum(download)                        download,
+       sum(qq)                              qq,
+       sum(lottery)                         lottery,
+       sum(vote)                            vote,
+       sum(message)                         message,
+       sum(redirect)                        redirect,
+       sum(shopping)                        shopping,
+       sum(consult)                         consult,
+       sum(wechat)                          wechat,
+       sum(phone_confirm)                   phone_confirm,
+       sum(phone_connect)                   phone_connect,
+       sum(consult_effective)               consult_effective,
+       sum(coupon)                          coupon,
+       sum(coupon_single_page)              coupon_single_page,
+       sum(redirect_to_shop)                redirect_to_shop,
+       sum(poi_collect)                     poi_collect,
+       sum(poi_address_click)               poi_address_click,
+       sum(luban_order_cnt)                 luban_order_cnt,
+       sum(luban_order_stat_amount)         luban_order_stat_amount,
+       sum(luban_order_roi)                 luban_order_roi,
+       sum(luban_live_enter_cnt)            luban_live_enter_cnt,
+       sum(
+               live_watch_one_minute_count
+           )                                live_watch_one_minute_count,
+       sum(luban_live_follow_cnt)           luban_live_follow_cnt,
+       sum(live_fans_club_join_cnt)         live_fans_club_join_cnt,
+       sum(luban_live_comment_cnt)          luban_live_comment_cnt,
+       sum(luban_live_share_cnt)            luban_live_share_cnt,
+       sum(luban_live_gift_cnt)             luban_live_gift_cnt,
+       sum(luban_live_gift_amount)          luban_live_gift_amount,
+       sum(
+               luban_live_slidecart_click_cnt
+           )                                luban_live_slidecart_click_cnt,
+       sum(
+               luban_live_click_product_cnt
+           )                                luban_live_click_product_cnt,
+       sum(luban_live_pay_order_count)      luban_live_pay_order_count,
+       sum(
+               luban_live_pay_order_stat_cost
+           )                                luban_live_pay_order_stat_cost,
+       sum(live_component_click_count)      live_component_click_count,
+       round(
+               sum(cost) / sum(live_component_click_count),
+               3
+           )                                live_component_click_cost,
+       round(
+               sum(live_component_click_count) / {day_count} * 100,
+               3
+           )                                live_component_click_rate,
+       sum(wechat_login_count)              wechat_login_count,
+       sum(
+               attribution_wechat_login_30d_count
+           )                                attribution_wechat_login_30d_count,
+       round(
+               sum(cost) / sum(wechat_login_count),
+               3
+           )                                wechat_login_cost,
+       round(
+                   sum(cost) / sum(
+                       attribution_wechat_login_30d_count
+                   ),
+                   3
+           )                                attribution_wechat_login_30d_cost,
+       sum(wechat_first_pay_count)          wechat_first_pay_count,
+       sum(
+               attribution_wechat_first_pay_30d_count
+           )                                attribution_wechat_first_pay_30d_count,
+       round(
+               sum(cost) / sum(wechat_first_pay_count),
+               3
+           )                                wechat_first_pay_cost,
+       round(
+                   sum(cost) / sum(
+                       attribution_wechat_first_pay_30d_count
+                   ),
+                   3
+           )                                attribution_wechat_first_pay_30d_cost,
+       round(
+               sum(wechat_first_pay_count) / sum(wechat_login_count) * 100,
+               3
+           )                                wechat_first_pay_rate,
+       round(
+                       sum(
+                               attribution_wechat_first_pay_30d_count
+                           ) / sum(
+                               attribution_wechat_login_30d_count
+                           ) * 100,
+                       3
+           )                                attribution_wechat_first_pay_30d_rate,
+       sum(wechat_pay_amount)               wechat_pay_amount,
+       sum(
+               attribution_wechat_pay_30d_amount
+           )                                attribution_wechat_pay_30d_amount,
+       sum(
+               attribution_wechat_pay_30d_roi
+           )                                attribution_wechat_pay_30d_roi,
+       sum(phone_effective)                 phone_effective,
+       sum(total_play)                      total_play,
+       sum(valid_play)                      valid_play,
+       round(
+               sum(cost) / sum(valid_play),
+               3
+           )                                valid_play_cost,
+       round(
+               sum(valid_play) / sum(`show`) * 100,
+               3
+           )                                valid_play_rate,
+       sum(play_25_feed_break)              play_25_feed_break,
+       sum(play_50_feed_break)              play_50_feed_break,
+       sum(play_75_feed_break)              play_75_feed_break,
+       sum(play_100_feed_break)             play_100_feed_break,
+       round(
+               sum(average_play_time_per_play) / {day_count},
+               3
+           )                                average_play_time_per_play,
+       round(
+               sum(play_over_rate) / {day_count} * 100,
+               3
+           )                                play_over_rate,
+       round(
+               sum(wifi_play) / sum(total_play) * 100,
+               3
+           )                                wifi_play_rate,
+       sum(wifi_play)                       wifi_play,
+       round(sum(play_duration_sum) / {day_count}, 3) play_duration_sum,
+       sum(
+               advanced_creative_phone_click
+           )                                advanced_creative_phone_click,
+       sum(
+               advanced_creative_counsel_click
+           )                                advanced_creative_counsel_click,
+       sum(
+               advanced_creative_form_click
+           )                                advanced_creative_form_click,
+       sum(
+               advanced_creative_coupon_addition
+           )                                advanced_creative_coupon_addition,
+       sum(
+               advanced_creative_form_submit
+           )                                advanced_creative_form_submit,
+       sum(card_show)                       card_show,
+       sum(`share`)                         `share`,
+       sum(`comment`)                       `comment`,
+       sum(`like`)                          `like`,
+       sum(follow)                          follow,
+       sum(home_visited)                    home_visited,
+       sum(ies_challenge_click)             ies_challenge_click,
+       sum(ies_music_click)                 ies_music_click,
+       sum(location_click)                  location_click,
+       sum(message_action)                  message_action,
+       sum(click_landing_page)              click_landing_page,
+       sum(click_shopwindow)                click_shopwindow,
+       sum(click_website)                   click_website,
+       sum(click_download)                  click_download,
+       sum(click_call_dy)                   click_call_dy,
+       sum(submit_certification_count)      submit_certification_count,
+       sum(approval_count)                  approval_count,
+       sum(first_order_count)               first_rental_order_count,
+       sum(first_rental_order_count)        first_order_count,
+       sum(commute_first_pay_count)         commute_first_pay_count
+FROM (
+         SELECT *
+         FROM media_api.bytedance_advertiser_report_daily
+         WHERE stat_datetime >= date_format(
+                 date_sub({date_time}, INTERVAL {day_count} DAY),
+                 '%Y%m%d'
+             )
+     ) report
+         LEFT JOIN `jeecg-boot`.ctop_user_allocation cua ON report.advertiser_id = cua.account_id
+         LEFT JOIN `jeecg-boot`.ctop_project cp ON cua.project_id = cp.id
+         LEFT JOIN `jeecg-boot`.ctop_product cn ON cp.product_id = cn.id
+         LEFT JOIN `jeecg-boot`.user_company uc ON uc.user_id = cua.user_id
+where cn.id is not null
+GROUP BY uc.company_id,
+         CASE
+             WHEN uc.company_id = 'd57fecdcf7a94d009736d9c850731582' THEN
+                 '北京汇创思拓数字科技有限公司'
+             WHEN uc.company_id = '6608ed13c0dd42de93c790dbdf124234' THEN
+                 '广州汇创思拓数字科技有限公司'
+             WHEN uc.company_id = '4b10089775c040119e139087517aed88' THEN
+                 '上海汇创思拓数字科技有限公司'
+             ELSE
+                 uc.company_name
+             END,
+         cn.id,
+         cn.product_name;
+""".format(date_time=self.date_time, day_count=self.day_count)
+            TidbConn.upsert(conn=self.conn, sql_buff=sql)
+            self.conn.commit()
+            TidbConn.conn_close(conn=self.conn)
+            return 0
+        except Exception as e:
+            logging.error(e)
+            return -1
+
+
+if __name__ == '__main__':
+    status = AppBytedanceProductReportBusiMonth().taskHandler()
+    if status == 0:
+        print("作业执行成功")
+        exit(0)
+    else:
+        print("作业执行失败")
+        exit(-1)

+ 2 - 2
Apietl/bytedance_etl/Q4Task/AppBytedanceProjectReportBusi.py

@@ -25,7 +25,7 @@ class AppBytedanceCompanyUserReportBusi:
 SET sql_mode = 'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
 REPLACE INTO application.app_bytedance_project_report_busi_{day_count}d 
 SELECT
-concat(date_format(date_sub({date_time}, INTERVAL 6 DAY),'%Y%m%d'),'-',{date_time}) time,
+concat(date_format(date_sub({date_time}, INTERVAL ({day_count} -1 )  DAY),'%Y%m%d'),'-',{date_time}) time,
 uc.company_id,
 CASE
 WHEN uc.company_id = 'd57fecdcf7a94d009736d9c850731582' THEN
@@ -376,7 +376,7 @@ FROM
 media_api.bytedance_advertiser_report_daily
 WHERE
 stat_datetime >= date_format(
-date_sub({date_time}, INTERVAL 6 DAY),
+date_sub({date_time}, INTERVAL ({day_count} -1 )  DAY),
 '%Y%m%d'
 )
 ) report

+ 417 - 0
Apietl/bytedance_etl/Q4Task/AppBytedanceProjectReportBusiMonth.py

@@ -0,0 +1,417 @@
+# Author renyupeng
+# coding=utf-8
+# @Time    : 2021/11/10 3:37 下午
+# @Site    :
+# @File    : AppBytedanceProjectReportBusiMonth.py
+# @Software: PyCharm
+# @contact: renyupeng@c-top.com.cn
+# @Tel 1501435553
+import logging
+
+from Apietl.conn.TidbConn import TidbConn
+from Apietl.utlis.Utils import Utils
+
+
+class AppBytedanceProjectReportBusiMonth:
+    def __init__(self):
+        self.conn = TidbConn.get_connection()
+        self.parm = Utils.get_task_args()
+        self.date_time = self.parm[0]
+        self.day_count = Utils.get_days()
+
+    def taskHandler(self):
+        try:
+            sql = """
+SET sql_mode = 'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
+REPLACE INTO application.app_bytedance_project_report_busi_m
+SELECT
+date_format({date_time},'%Y%m') stat_mon,
+uc.company_id,
+CASE
+WHEN uc.company_id = 'd57fecdcf7a94d009736d9c850731582' THEN
+'北京汇创思拓数字科技有限公司'
+WHEN uc.company_id = '6608ed13c0dd42de93c790dbdf124234' THEN
+'广州汇创思拓数字科技有限公司'
+WHEN uc.company_id = '4b10089775c040119e139087517aed88' THEN
+'上海汇创思拓数字科技有限公司'
+ELSE
+uc.company_name
+END company_name,
+ cp.product_id,
+ cn.product_name,
+ cua.project_id,
+ cp.project_name,
+ count(report.advertiser_id) account_num,
+ sum(cost) cost,
+ sum(`show`) `show`,
+ round(sum(cost) / sum(`show`), 3) avg_show_cost,
+ sum(click) click,
+ round(sum(cost) / sum(`click`), 3) avg_click_cost,
+ round(
+sum(click) / sum(`show`) * 100,
+3
+) ctr,
+ sum(`convert`) `convert`,
+ round(sum(cost) / sum(`convert`), 3) convert_cost,
+ round(
+sum(`convert`) / sum(click) * 100,
+3
+) convert_rate,
+ sum(deep_convert) deep_convert,
+ round(
+sum(cost) / sum(deep_convert),
+3
+) deep_convert_cost,
+ round(
+sum(deep_convert) / sum(`convert`) * 100,
+3
+) deep_convert_rate,
+ sum(attribution_convert) attribution_convert,
+ round(
+sum(cost) / sum(attribution_convert),
+3
+) attribution_convert_cost,
+ sum(attribution_deep_convert) attribution_deep_convert,
+ round(
+sum(cost) / sum(attribution_deep_convert),
+3
+) attribution_deep_convert_cost,
+ sum(download_start) download_start,
+ round(
+sum(cost) / sum(download_start),
+3
+) download_start_cost,
+ round(
+sum(download_start) / sum(click),
+3
+) download_start_rate,
+ sum(download_finish) download_finish,
+ round(
+sum(cost) / sum(download_finish),
+3
+) download_finish_cost,
+ round(
+sum(download_finish) / sum(download_start) * 100,
+3
+) download_finish_rate,
+ sum(click_install) click_install,
+ sum(install_finish) install_finish,
+ round(
+sum(cost) / sum(install_finish),
+3
+) install_finish_cost,
+ round(
+sum(install_finish) / sum(download_finish) * 100,
+3
+) install_finish_rate,
+ sum(active) active,
+ round(sum(cost) / sum(active), 3) active_cost,
+ round(
+sum(active) / sum(click) * 100,
+3
+) active_rate,
+ sum(register) register,
+ round(sum(cost) / sum(register), 3) active_register_cost,
+ round(
+sum(active_register_rate) / {day_count} * 100,
+3
+) active_register_rate,
+ sum(next_day_open) next_day_open,
+ round(
+sum(cost) / sum(next_day_open),
+3
+) next_day_open_cost,
+ round(
+sum(next_day_open) / sum(active) * 100,
+3
+) next_day_open_rate,
+ sum(
+attribution_next_day_open_cnt
+) attribution_next_day_open_cnt,
+ round(
+sum(cost) / sum(
+attribution_next_day_open_cnt
+),
+3
+) attribution_next_day_open_cost,
+ round(
+sum(
+attribution_next_day_open_cnt
+) / sum(active) * 100,
+3
+) attribution_next_day_open_rate,
+ sum(game_addiction) game_addiction,
+ round(
+sum(cost) / sum(game_addiction),
+3
+) game_addiction_cost,
+ round(
+sum(game_addiction_rate) / {day_count} * 100,
+3
+) game_addiction_rate,
+ sum(pay_count) pay_count,
+ round(sum(cost) / sum(pay_count), 3) active_pay_cost,
+ round(
+sum(pay_count) / sum(active) * 100,
+3
+) active_pay_rate,
+ sum(loan_completion) loan_completion,
+ round(
+sum(cost) / sum(loan_completion),
+3
+) loan_completion_cost,
+ round(
+sum(loan_completion) / sum(register) * 100,
+3
+) loan_completion_rate,
+ round(sum(pre_loan_credit), 3) pre_loan_credit,
+ round(
+sum(cost) / sum(pre_loan_credit),
+3
+) pre_loan_credit_cost,
+ sum(loan_credit) loan_credit,
+ round(
+sum(cost) / sum(loan_credit),
+3
+) loan_credit_cost,
+ round(
+sum(loan_credit) / sum(loan_completion) * 100,
+3
+) loan_credit_rate,
+ sum(in_app_uv) in_app_uv,
+ sum(in_app_detail_uv) in_app_detail_uv,
+ sum(in_app_cart) in_app_cart,
+ sum(in_app_pay) in_app_pay,
+ sum(in_app_order) in_app_order,
+ round(
+sum(
+attribution_game_pay_7d_count
+) / {day_count},
+3
+) attribution_game_pay_7d_count,
+ round(
+sum(
+attribution_game_pay_7d_cost
+) / {day_count},
+3
+) attribution_game_pay_7d_cost,
+ round(
+sum(
+attribution_active_pay_7d_per_count
+) / {day_count},
+3
+) attribution_active_pay_7d_per_count,
+ sum(game_pay_cost) game_pay_cost,
+ sum(game_pay_count) game_pay_count,
+ sum(phone) phone,
+ sum(form) form,
+ sum(map_search) map_search,
+ sum(button) button,
+ sum(`view`) `view`,
+ sum(download) download,
+ sum(qq) qq,
+ sum(lottery) lottery,
+ sum(vote) vote,
+ sum(message) message,
+ sum(redirect) redirect,
+ sum(shopping) shopping,
+ sum(consult) consult,
+ sum(wechat) wechat,
+ sum(phone_confirm) phone_confirm,
+ sum(phone_connect) phone_connect,
+ sum(consult_effective) consult_effective,
+ sum(coupon) coupon,
+ sum(coupon_single_page) coupon_single_page,
+ sum(redirect_to_shop) redirect_to_shop,
+ sum(poi_collect) poi_collect,
+ sum(poi_address_click) poi_address_click,
+ sum(luban_order_cnt) luban_order_cnt,
+ sum(luban_order_stat_amount) luban_order_stat_amount,
+ sum(luban_order_roi) luban_order_roi,
+ sum(luban_live_enter_cnt) luban_live_enter_cnt,
+ sum(
+live_watch_one_minute_count
+) live_watch_one_minute_count,
+ sum(luban_live_follow_cnt) luban_live_follow_cnt,
+ sum(live_fans_club_join_cnt) live_fans_club_join_cnt,
+ sum(luban_live_comment_cnt) luban_live_comment_cnt,
+ sum(luban_live_share_cnt) luban_live_share_cnt,
+ sum(luban_live_gift_cnt) luban_live_gift_cnt,
+ sum(luban_live_gift_amount) luban_live_gift_amount,
+ sum(
+luban_live_slidecart_click_cnt
+) luban_live_slidecart_click_cnt,
+ sum(
+luban_live_click_product_cnt
+) luban_live_click_product_cnt,
+ sum(luban_live_pay_order_count) luban_live_pay_order_count,
+ sum(
+luban_live_pay_order_stat_cost
+) luban_live_pay_order_stat_cost,
+ sum(live_component_click_count) live_component_click_count,
+ round(
+sum(cost) / sum(live_component_click_count),
+3
+) live_component_click_cost,
+ round(
+sum(live_component_click_count) / {day_count} * 100,
+3
+) live_component_click_rate,
+ sum(wechat_login_count) wechat_login_count,
+ sum(
+attribution_wechat_login_30d_count
+) attribution_wechat_login_30d_count,
+ round(
+sum(cost) / sum(wechat_login_count),
+3
+) wechat_login_cost,
+ round(
+sum(cost) / sum(
+attribution_wechat_login_30d_count
+),
+3
+) attribution_wechat_login_30d_cost,
+ sum(wechat_first_pay_count) wechat_first_pay_count,
+ sum(
+attribution_wechat_first_pay_30d_count
+) attribution_wechat_first_pay_30d_count,
+ round(
+sum(cost) / sum(wechat_first_pay_count),
+3
+) wechat_first_pay_cost,
+ round(
+sum(cost) / sum(
+attribution_wechat_first_pay_30d_count
+),
+3
+) attribution_wechat_first_pay_30d_cost,
+ round(
+sum(wechat_first_pay_count) / sum(wechat_login_count) * 100,
+3
+) wechat_first_pay_rate,
+ round(
+sum(
+attribution_wechat_first_pay_30d_count
+) / sum(
+attribution_wechat_login_30d_count
+) * 100,
+3
+) attribution_wechat_first_pay_30d_rate,
+ sum(wechat_pay_amount) wechat_pay_amount,
+ sum(
+attribution_wechat_pay_30d_amount
+) attribution_wechat_pay_30d_amount,
+ sum(
+attribution_wechat_pay_30d_roi
+) attribution_wechat_pay_30d_roi,
+ sum(phone_effective) phone_effective,
+ sum(total_play) total_play,
+ sum(valid_play) valid_play,
+ round(
+sum(cost) / sum(valid_play),
+3
+) valid_play_cost,
+ round(
+sum(valid_play) / sum(`show`) * 100,
+3
+) valid_play_rate,
+ sum(play_25_feed_break) play_25_feed_break,
+ sum(play_50_feed_break) play_50_feed_break,
+ sum(play_75_feed_break) play_75_feed_break,
+ sum(play_100_feed_break) play_100_feed_break,
+ round(
+sum(average_play_time_per_play) / {day_count},
+3
+) average_play_time_per_play,
+ round(
+sum(play_over_rate) / {day_count} * 100,
+3
+) play_over_rate,
+ round(
+sum(wifi_play) / sum(total_play) * 100,
+3
+) wifi_play_rate,
+ sum(wifi_play) wifi_play,
+ round(sum(play_duration_sum) / {day_count}, 3) play_duration_sum,
+ sum(
+advanced_creative_phone_click
+) advanced_creative_phone_click,
+ sum(
+advanced_creative_counsel_click
+) advanced_creative_counsel_click,
+ sum(
+advanced_creative_form_click
+) advanced_creative_form_click,
+ sum(
+advanced_creative_coupon_addition
+) advanced_creative_coupon_addition,
+ sum(
+advanced_creative_form_submit
+) advanced_creative_form_submit,
+ sum(card_show) card_show,
+ sum(`share`) `share`,
+ sum(`comment`) `comment`,
+ sum(`like`) `like`,
+ sum(follow) follow,
+ sum(home_visited) home_visited,
+ sum(ies_challenge_click) ies_challenge_click,
+ sum(ies_music_click) ies_music_click,
+ sum(location_click) location_click,
+ sum(message_action) message_action,
+ sum(click_landing_page) click_landing_page,
+ sum(click_shopwindow) click_shopwindow,
+ sum(click_website) click_website,
+ sum(click_download) click_download,
+ sum(click_call_dy) click_call_dy,
+ sum(submit_certification_count) submit_certification_count,
+ sum(approval_count) approval_count,
+ sum(first_order_count) first_rental_order_count,
+ sum(first_rental_order_count) first_order_count,
+ sum(commute_first_pay_count) commute_first_pay_count
+FROM
+(
+SELECT
+*
+FROM
+media_api.bytedance_advertiser_report_daily
+WHERE
+stat_datetime >= date_format(
+date_sub({date_time}, INTERVAL {day_count}  DAY),
+'%Y%m%d'
+)
+) report
+LEFT JOIN `jeecg-boot`.ctop_user_allocation cua ON report.advertiser_id = cua.account_id
+LEFT JOIN `jeecg-boot`.ctop_project cp ON cua.project_id = cp.id
+LEFT JOIN `jeecg-boot`.ctop_product cn ON cp.product_id = cn.id
+LEFT JOIN `jeecg-boot`.user_company uc ON uc.user_id = cua.user_id
+GROUP BY
+uc.company_id,
+CASE
+WHEN uc.company_id = 'd57fecdcf7a94d009736d9c850731582' THEN
+'北京汇创思拓数字科技有限公司'
+WHEN uc.company_id = '6608ed13c0dd42de93c790dbdf124234' THEN
+'广州汇创思拓数字科技有限公司'
+WHEN uc.company_id = '4b10089775c040119e139087517aed88' THEN
+'上海汇创思拓数字科技有限公司'
+ELSE
+uc.company_name
+END,cua.project_id,
+cp.project_name
+having sum(cost)>0""".format(date_time=self.date_time, day_count=self.day_count)
+            TidbConn.upsert(conn=self.conn, sql_buff=sql)
+            self.conn.commit()
+            TidbConn.conn_close(conn=self.conn)
+            return 0
+        except Exception as e:
+            logging.error(e)
+            return -1
+
+
+if __name__ == '__main__':
+    status = AppBytedanceProjectReportBusiMonth().taskHandler()
+    if status == 0:
+        print("作业执行成功")
+        exit(0)
+    else:
+        print("作业执行失败")
+        exit(-1)

+ 2 - 2
Apietl/bytedance_etl/Q4Task/AppBytedanceVideoReportBusi.py

@@ -28,7 +28,7 @@ group by project_id """
                 try:
                     sql = """SET sql_mode = 'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
 REPLACE INTO application.app_bytedance_video_report_busi_{day_count}d
-SELECT concat(date_format(date_sub({date_time}, INTERVAL 6 DAY),'%Y%m%d'),'-',{date_time})           time,
+SELECT concat(date_format(date_sub({date_time}, INTERVAL ({day_count} -1 )  DAY),'%Y%m%d'),'-',{date_time})           time,
        report.account_id,
        #'账户ID'                                                                                                                                                                                                                                                                    
        report.material_id,
@@ -644,7 +644,7 @@ FROM (
                               'CREATIVE_IMAGE_MODE_UNION_SPLASH_VIDEO'
              )
            AND stat_datetime >= date_format(
-                 date_sub({date_time}, INTERVAL 6 DAY),
+                 date_sub({date_time}, INTERVAL ({day_count} -1 )  DAY),
                  '%Y%m%d'
              )
          GROUP BY advertiser_id,

+ 703 - 0
Apietl/bytedance_etl/Q4Task/AppBytedanceVideoReportBusiMonth.py

@@ -0,0 +1,703 @@
+# Author renyupeng
+# coding=utf-8
+# @Time    : 2021/11/10 3:37 下午
+# @Site    : 
+# @File    : AppBytedanceVideoReportBusiMonth.py
+# @Software: PyCharm
+# @contact: renyupeng@c-top.com.cn
+# @Tel 1501435553
+import logging
+
+from Apietl.conn.TidbConn import TidbConn
+from Apietl.utlis.Utils import Utils
+
+
+class AppBytedanceVideoReportBusiMonth:
+    def __init__(self):
+        self.conn = TidbConn.get_connection()
+        self.parm = Utils.get_task_args()
+        self.date_time = self.parm[0]
+        self.day_count = Utils.get_days()
+
+    def taskHandler(self):
+        try:
+            sql_porject = """select project_id from `jeecg-boot`.ctop_user_allocation where media_id=1
+group by project_id """
+            project_list = TidbConn.quary(self.conn,sql_porject)
+            for project_id in project_list:
+                try:
+                    sql = """SET sql_mode = 'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
+REPLACE INTO application.app_bytedance_video_report_busi_m
+SELECT date_format({date_time},'%Y%m')         stat_mon,
+       report.account_id,
+       #'账户ID'                                                                                                                                                                                                                                                                    
+       report.material_id,
+       #头条素材id                                                                                                                                                                                                                                
+       report.image_mode,
+       #素材类型                                                                                                                                                                                                                               
+       report.inventory,
+       #广告位                                                                                                                                                                                                                                
+       cua.project_id,
+       #项目id  
+       product.id      product_id,
+       #项目中产品id
+       cua.advertiser_id,
+       #广告主id
+       uc.company_id,
+       #运营人的公司id                      
+       cua.auth_name   account_name,
+       #账户名称
+       cp.project_name,
+       #项目名称  
+       ca.`name`       advertiser_name,
+       #广告主名称
+       uc.company_name,
+       #运营人的公司名称
+       cp.sale_id,
+       #项目里的销售id
+       cua.user_id,
+       #运营id                                                                                                          
+       cma.clip_id,
+       #剪辑id
+       cma.shot_id,
+       #拍摄id
+       cma.plan_id,
+       #编导id
+       cma.leader_id,
+       #负责人id
+       su.org_code,
+       #机构编码
+       video.signature,
+       #素材id  
+       NULL            chl_type,
+       #渠道类型
+       clip.realname   clip_name,
+       #剪辑名称
+       shot.realname   shot_name,
+       #拍摄名称
+       plan.realname   plan_name,
+       #编导名称
+       leader.realname lead_name,
+       #负责人名称
+       CASE
+           WHEN cmi.material_name IS NOT NULL THEN
+               cmi.material_name
+           ELSE
+               video.filename
+           END AS      video_name,
+       ##视频名称
+       NULL            chl_name,
+       #渠道名称
+       up.company_id   clip_company_id,
+       #剪辑公司
+       report.cost,
+       report.`show`,
+       report.avg_show_cost,
+       report.click,
+       report.avg_click_cost,
+       report.ctr,
+       report.`convert`,
+       report.convert_cost,
+       report.convert_rate,
+       report.deep_convert,
+       report.deep_convert_cost,
+       report.deep_convert_rate,
+       report.attribution_convert,
+       report.attribution_convert_cost,
+       report.attribution_deep_convert,
+       report.attribution_deep_convert_cost,
+       report.download_start,
+       report.download_start_cost,
+       report.download_start_rate,
+       report.download_finish,
+       report.download_finish_cost,
+       report.download_finish_rate,
+       report.click_install,
+       report.install_finish,
+       report.install_finish_cost,
+       report.install_finish_rate,
+       report.active,
+       report.active_cost,
+       report.active_rate,
+       report.register,
+       report.active_register_cost,
+       report.active_register_rate,
+       report.active_pay_amount,
+       report.next_day_open,
+       report.next_day_open_cost,
+       report.next_day_open_rate,
+       report.attribution_next_day_open_cnt,
+       report.attribution_next_day_open_cost,
+       report.attribution_next_day_open_rate,
+       report.game_addiction,
+       report.game_addiction_cost,
+       report.game_addiction_rate,
+       report.pay_count,
+       report.active_pay_cost,
+       report.active_pay_rate,
+       report.loan_completion,
+       report.loan_completion_cost,
+       report.loan_completion_rate,
+       report.pre_loan_credit,
+       report.pre_loan_credit_cost,
+       report.loan_credit,
+       report.loan_credit_cost,
+       report.loan_credit_rate,
+       report.in_app_uv,
+       report.in_app_detail_uv,
+       report.in_app_cart,
+       report.in_app_pay,
+       report.in_app_order,
+       report.attribution_game_pay_7d_count,
+       report.attribution_game_pay_7d_cost,
+       report.attribution_active_pay_7d_per_count,
+       report.game_pay_cost,
+       report.game_pay_count,
+       report.phone,
+       report.form,
+       report.map_search,
+       report.button,
+       report.`view`,
+       report.download,
+       report.qq,
+       report.lottery,
+       report.vote,
+       report.message,
+       report.redirect,
+       report.shopping,
+       report.consult,
+       report.wechat,
+       report.phone_confirm,
+       report.phone_connect,
+       report.consult_effective,
+       report.coupon,
+       report.coupon_single_page,
+       report.redirect_to_shop,
+       report.poi_collect,
+       report.poi_address_click,
+       report.luban_order_cnt,
+       report.luban_order_stat_amount,
+       report.luban_order_roi,
+       report.luban_live_enter_cnt,
+       report.live_watch_one_minute_count,
+       report.luban_live_follow_cnt,
+       report.live_fans_club_join_cnt,
+       report.luban_live_comment_cnt,
+       report.luban_live_share_cnt,
+       report.luban_live_gift_cnt,
+       report.luban_live_gift_amount,
+       report.luban_live_slidecart_click_cnt,
+       report.luban_live_click_product_cnt,
+       report.luban_live_pay_order_count,
+       report.luban_live_pay_order_stat_cost,
+       report.wechat_login_count,
+       report.attribution_wechat_login_30d_count,
+       report.wechat_login_cost,
+       report.attribution_wechat_login_30d_cost,
+       report.wechat_first_pay_count,
+       report.attribution_wechat_first_pay_30d_count,
+       report.wechat_first_pay_cost,
+       report.attribution_wechat_first_pay_30d_cost,
+       report.wechat_first_pay_rate,
+       report.attribution_wechat_first_pay_30d_rate,
+       report.wechat_pay_amount,
+       report.attribution_wechat_pay_30d_amount,
+       report.attribution_wechat_pay_30d_roi,
+       report.phone_effective,
+       report.total_play,
+       report.valid_play,
+       report.valid_play_cost,
+       report.valid_play_rate,
+       report.play_25_feed_break,
+       report.play_50_feed_break,
+       report.play_75_feed_break,
+       report.play_100_feed_break,
+       report.average_play_time_per_play,
+       report.play_over_rate,
+       report.wifi_play_rate,
+       report.wifi_play,
+       report.play_duration_sum,
+       report.advanced_creative_phone_click,
+       report.advanced_creative_counsel_click,
+       report.advanced_creative_form_click,
+       report.advanced_creative_coupon_addition,
+       report.advanced_creative_form_submit,
+       report.card_show,
+       report.`share`,
+       report.`comment`,
+       report.`like`,
+       report.follow,
+       report.home_visited,
+       report.ies_challenge_click,
+       report.ies_music_click,
+       report.location_click,
+       report.message_action,
+       report.click_landing_page,
+       report.click_shopwindow,
+       report.click_website,
+       report.click_download,
+       report.click_call_dy,
+       report.`cpc`,
+       report.`cpm`,
+       report.`cpa`,
+       report.`interact_per_cost`,
+       report.`convert_show_rate`,
+       report.`play_duration_10s_rate`,
+       report.`play_50_feed_break_rate`,
+       report.`play_25_feed_break_rate`,
+       report.`play_duration_5s_rate`,
+       report.`play_duration_2s_rate`,
+       report.`average_play_progress`,
+       report.`play_100_feed_break_rate`,
+       report.`play_duration_3s_rate`,
+       report.`play_75_feed_break_rate`,
+       report.`play_duration`,
+       report.`play_duration_3s`,
+       report.`play_duration_2s`,
+       report.`play_duration_10s`,
+       report.`average_video_play`,
+       report.`avg_rank`,
+       report.submit_certification_count,
+       report.approval_count,
+       report.first_rental_order_count,
+       report.first_order_count,
+       report.commute_first_pay_count,
+       video.`video_url`,
+       cmi.`cover_url`
+FROM (
+         SELECT advertiser_id                        account_id,
+                material_id,
+                image_mode,
+                inventory,
+                sum(cost)                            cost,
+                sum(`show`)                          `show`,
+                round(sum(cost) / sum(`show`), 3)    avg_show_cost,
+                sum(click)                           click,
+                round(sum(cost) / sum(`click`), 3)   avg_click_cost,
+                round(
+                        sum(click) / sum(`show`) * 100,
+                        3
+                    )                                ctr,
+                sum(`convert`)                       `convert`,
+                round(sum(cost) / sum(`convert`), 3) convert_cost,
+                round(
+                        sum(`convert`) / sum(click) * 100,
+                        3
+                    )                                convert_rate,
+                sum(deep_convert)                    deep_convert,
+                round(
+                        sum(cost) / sum(deep_convert),
+                        3
+                    )                                deep_convert_cost,
+                round(
+                        sum(deep_convert) / sum(`convert`) * 100,
+                        3
+                    )                                deep_convert_rate,
+                sum(attribution_convert)             attribution_convert,
+                round(
+                        sum(cost) / sum(attribution_convert),
+                        3
+                    )                                attribution_convert_cost,
+                sum(attribution_deep_convert)        attribution_deep_convert,
+                round(
+                        sum(cost) / sum(attribution_deep_convert),
+                        3
+                    )                                attribution_deep_convert_cost,
+                sum(download_start)                  download_start,
+                round(
+                        sum(cost) / sum(download_start),
+                        3
+                    )                                download_start_cost,
+                round(
+                        sum(download_start) / sum(click),
+                        3
+                    )                                download_start_rate,
+                sum(download_finish)                 download_finish,
+                round(
+                        sum(cost) / sum(download_finish),
+                        3
+                    )                                download_finish_cost,
+                round(
+                        sum(download_finish) / sum(download_start) * 100,
+                        3
+                    )                                download_finish_rate,
+                sum(click_install)                   click_install,
+                sum(install_finish)                  install_finish,
+                round(
+                        sum(cost) / sum(install_finish),
+                        3
+                    )                                install_finish_cost,
+                round(
+                        sum(install_finish) / sum(download_finish) * 100,
+                        3
+                    )                                install_finish_rate,
+                sum(active)                          active,
+                round(sum(cost) / sum(active), 3)    active_cost,
+                round(
+                        sum(active) / sum(click) * 100,
+                        3
+                    )                                active_rate,
+                sum(register)                        register,
+                round(sum(cost) / sum(register), 3)  active_register_cost,
+                round(
+                        sum(active_register_rate) / {day_count} * 100,
+                        3
+                    )                                active_register_rate,
+                sum(active_pay_amount)               active_pay_amount,
+                sum(next_day_open)                   next_day_open,
+                round(
+                        sum(cost) / sum(next_day_open),
+                        3
+                    )                                next_day_open_cost,
+                round(
+                        sum(next_day_open) / sum(active) * 100,
+                        3
+                    )                                next_day_open_rate,
+                sum(
+                        attribution_next_day_open_cnt
+                    )                                attribution_next_day_open_cnt,
+                round(
+                            sum(cost) / sum(
+                                attribution_next_day_open_cnt
+                            ),
+                            3
+                    )                                attribution_next_day_open_cost,
+                round(
+                                sum(
+                                        attribution_next_day_open_cnt
+                                    ) / sum(active) * 100,
+                                3
+                    )                                attribution_next_day_open_rate,
+                sum(game_addiction)                  game_addiction,
+                round(
+                        sum(cost) / sum(game_addiction),
+                        3
+                    )                                game_addiction_cost,
+                round(
+                        sum(game_addiction_rate) / {day_count} * 100,
+                        3
+                    )                                game_addiction_rate,
+                sum(pay_count)                       pay_count,
+                round(sum(cost) / sum(pay_count), 3) active_pay_cost,
+                round(
+                        sum(pay_count) / sum(active) * 100,
+                        3
+                    )                                active_pay_rate,
+                sum(loan_completion)                 loan_completion,
+                round(
+                        sum(cost) / sum(loan_completion),
+                        3
+                    )                                loan_completion_cost,
+                round(
+                        sum(loan_completion) / sum(register) * 100,
+                        3
+                    )                                loan_completion_rate,
+                round(sum(pre_loan_credit), 3)       pre_loan_credit,
+                round(
+                        sum(cost) / sum(pre_loan_credit),
+                        3
+                    )                                pre_loan_credit_cost,
+                sum(loan_credit)                     loan_credit,
+                round(
+                        sum(cost) / sum(loan_credit),
+                        3
+                    )                                loan_credit_cost,
+                round(
+                        sum(loan_credit) / sum(loan_completion) * 100,
+                        3
+                    )                                loan_credit_rate,
+                sum(in_app_uv)                       in_app_uv,
+                sum(in_app_detail_uv)                in_app_detail_uv,
+                sum(in_app_cart)                     in_app_cart,
+                sum(in_app_pay)                      in_app_pay,
+                sum(in_app_order)                    in_app_order,
+                round(
+                            sum(
+                                    attribution_game_pay_7d_count
+                                ) / {day_count},
+                            3
+                    )                                attribution_game_pay_7d_count,
+                round(
+                            sum(
+                                    attribution_game_pay_7d_cost
+                                ) / {day_count},
+                            3
+                    )                                attribution_game_pay_7d_cost,
+                round(
+                            sum(
+                                    attribution_active_pay_7d_per_count
+                                ) / {day_count},
+                            3
+                    )                                attribution_active_pay_7d_per_count,
+                sum(game_pay_cost)                   game_pay_cost,
+                sum(game_pay_count)                  game_pay_count,
+                sum(phone)                           phone,
+                sum(form)                            form,
+                sum(map_search)                      map_search,
+                sum(button)                          button,
+                sum(`view`)                          `view`,
+                sum(download)                        download,
+                sum(qq)                              qq,
+                sum(lottery)                         lottery,
+                sum(vote)                            vote,
+                sum(message)                         message,
+                sum(redirect)                        redirect,
+                sum(shopping)                        shopping,
+                sum(consult)                         consult,
+                sum(wechat)                          wechat,
+                sum(phone_confirm)                   phone_confirm,
+                sum(phone_connect)                   phone_connect,
+                sum(consult_effective)               consult_effective,
+                sum(coupon)                          coupon,
+                sum(coupon_single_page)              coupon_single_page,
+                sum(redirect_to_shop)                redirect_to_shop,
+                sum(poi_collect)                     poi_collect,
+                sum(poi_address_click)               poi_address_click,
+                sum(luban_order_cnt)                 luban_order_cnt,
+                sum(luban_order_stat_amount)         luban_order_stat_amount,
+                sum(luban_order_roi)                 luban_order_roi,
+                sum(luban_live_enter_cnt)            luban_live_enter_cnt,
+                sum(
+                        live_watch_one_minute_count
+                    )                                live_watch_one_minute_count,
+                sum(luban_live_follow_cnt)           luban_live_follow_cnt,
+                sum(live_fans_club_join_cnt)         live_fans_club_join_cnt,
+                sum(luban_live_comment_cnt)          luban_live_comment_cnt,
+                sum(luban_live_share_cnt)            luban_live_share_cnt,
+                sum(luban_live_gift_cnt)             luban_live_gift_cnt,
+                sum(luban_live_gift_amount)          luban_live_gift_amount,
+                sum(
+                        luban_live_slidecart_click_cnt
+                    )                                luban_live_slidecart_click_cnt,
+                sum(
+                        luban_live_click_product_cnt
+                    )                                luban_live_click_product_cnt,
+                sum(luban_live_pay_order_count)      luban_live_pay_order_count,
+                sum(
+                        luban_live_pay_order_stat_cost
+                    )                                luban_live_pay_order_stat_cost,
+                sum(wechat_login_count)              wechat_login_count,
+                sum(
+                        attribution_wechat_login_30d_count
+                    )                                attribution_wechat_login_30d_count,
+                round(
+                        sum(cost) / sum(wechat_login_count),
+                        3
+                    )                                wechat_login_cost,
+                round(
+                            sum(cost) / sum(
+                                attribution_wechat_login_30d_count
+                            ),
+                            3
+                    )                                attribution_wechat_login_30d_cost,
+                sum(wechat_first_pay_count)          wechat_first_pay_count,
+                sum(
+                        attribution_wechat_first_pay_30d_count
+                    )                                attribution_wechat_first_pay_30d_count,
+                round(
+                        sum(cost) / sum(wechat_first_pay_count),
+                        3
+                    )                                wechat_first_pay_cost,
+                round(
+                            sum(cost) / sum(
+                                attribution_wechat_first_pay_30d_count
+                            ),
+                            3
+                    )                                attribution_wechat_first_pay_30d_cost,
+                round(
+                        sum(wechat_first_pay_count) / sum(wechat_login_count) * 100,
+                        3
+                    )                                wechat_first_pay_rate,
+                round(
+                                sum(
+                                        attribution_wechat_first_pay_30d_count
+                                    ) / sum(
+                                        attribution_wechat_login_30d_count
+                                    ) * 100,
+                                3
+                    )                                attribution_wechat_first_pay_30d_rate,
+                sum(wechat_pay_amount)               wechat_pay_amount,
+                sum(
+                        attribution_wechat_pay_30d_amount
+                    )                                attribution_wechat_pay_30d_amount,
+                sum(
+                        attribution_wechat_pay_30d_roi
+                    )                                attribution_wechat_pay_30d_roi,
+                sum(phone_effective)                 phone_effective,
+                sum(total_play)                      total_play,
+                sum(valid_play)                      valid_play,
+                round(
+                        sum(cost) / sum(valid_play),
+                        3
+                    )                                valid_play_cost,
+                round(
+                        sum(valid_play) / sum(`show`) * 100,
+                        3
+                    )                                valid_play_rate,
+                sum(play_25_feed_break)              play_25_feed_break,
+                sum(play_50_feed_break)              play_50_feed_break,
+                sum(play_75_feed_break)              play_75_feed_break,
+                sum(play_100_feed_break)             play_100_feed_break,
+                round(
+                        sum(average_play_time_per_play) / {day_count},
+                        3
+                    )                                average_play_time_per_play,
+                round(
+                        sum(play_over_rate) / {day_count} * 100,
+                        3
+                    )                                play_over_rate,
+                round(
+                        sum(wifi_play) / sum(total_play) * 100,
+                        3
+                    )                                wifi_play_rate,
+                sum(wifi_play)                       wifi_play,
+                round(sum(play_duration_sum) / {day_count}, 3) play_duration_sum,
+                sum(
+                        advanced_creative_phone_click
+                    )                                advanced_creative_phone_click,
+                sum(
+                        advanced_creative_counsel_click
+                    )                                advanced_creative_counsel_click,
+                sum(
+                        advanced_creative_form_click
+                    )                                advanced_creative_form_click,
+                sum(
+                        advanced_creative_coupon_addition
+                    )                                advanced_creative_coupon_addition,
+                sum(
+                        advanced_creative_form_submit
+                    )                                advanced_creative_form_submit,
+                sum(card_show)                       card_show,
+                sum(`share`)                         `share`,
+                sum(`comment`)                       `comment`,
+                sum(`like`)                          `like`,
+                sum(follow)                          follow,
+                sum(home_visited)                    home_visited,
+                sum(ies_challenge_click)             ies_challenge_click,
+                sum(ies_music_click)                 ies_music_click,
+                sum(location_click)                  location_click,
+                sum(message_action)                  message_action,
+                sum(click_landing_page)              click_landing_page,
+                sum(click_shopwindow)                click_shopwindow,
+                sum(click_website)                   click_website,
+                sum(click_download)                  click_download,
+                sum(click_call_dy)                   click_call_dy,
+                sum(cpc)                             cpc,
+                sum(cpm)                             cpm,
+                sum(cpa)                             cpa,
+                round(sum(interact_per_cost) / {day_count}, 3) interact_per_cost,
+                round(sum(convert_show_rate) / {day_count}, 3) convert_show_rate,
+                round(
+                        sum(round(play_duration_10s)) / sum(total_play) * 100,
+                        3
+                    )                                play_duration_10s_rate,
+                round(
+                        sum(play_50_feed_break) / sum(total_play) * 100,
+                        3
+                    )                                play_50_feed_break_rate,
+                round(
+                        sum(play_25_feed_break) / sum(total_play) * 100,
+                        3
+                    )                                play_25_feed_break_rate,
+                round(
+                        sum(play_duration_5s_rate) / {day_count},
+                        3
+                    )                                play_duration_5s_rate,
+                round(
+                        sum(play_duration_2s) / sum(total_play) * 100,
+                        3
+                    )                                play_duration_2s_rate,
+                round(
+                        sum(average_play_progress) / {day_count},
+                        3
+                    )                                average_play_progress,
+                round(
+                        sum(play_100_feed_break) / sum(total_play) * 100,
+                        3
+                    )                                play_100_feed_break_rate,
+                round(
+                        sum(play_duration_3s) / sum(total_play) * 100,
+                        3
+                    )                                play_duration_3s_rate,
+                round(
+                        sum(play_75_feed_break) / sum(total_play) * 100,
+                        3
+                    )                                play_75_feed_break_rate,
+                sum(play_duration)                   play_duration,
+                sum(play_duration_3s)                play_duration_3s,
+                sum(play_duration_2s)                play_duration_2s,
+                sum(play_duration_10s)               play_duration_10s,
+                round(
+                        sum(average_video_play) / {day_count},
+                        3
+                    )                                average_video_play,
+                sum(avg_rank)                        avg_rank,
+                sum(submit_certification_count)      submit_certification_count,
+                sum(approval_count)                  approval_count,
+                sum(first_order_count)               first_rental_order_count,
+                sum(first_rental_order_count)        first_order_count,
+                sum(commute_first_pay_count)         commute_first_pay_count
+         FROM media_api.bytedance_material_report_daily zhubiao
+         WHERE image_mode IN (
+                              'CREATIVE_IMAGE_MODE_VIDEO',
+                              'CREATIVE_IMAGE_MODE_VIDEO_VERTICAL',
+                              'CREATIVE_IMAGE_MODE_UNION_SPLASH_VIDEO'
+             )
+           AND stat_datetime >= date_format(
+                 date_sub({date_time}, INTERVAL {day_count}  DAY),
+                 '%Y%m%d'
+             )
+         GROUP BY advertiser_id,
+                  material_id,
+                  image_mode,
+                  inventory
+     ) report
+         LEFT JOIN (select advertiser_id, signature, material_id, filename, video_url
+                    from `media_api`.bytedance_file_video_get
+                    group by advertiser_id, signature, material_id, filename, video_url) video
+                   ON report.account_id = video.advertiser_id AND report.material_id = video.material_id
+         LEFT JOIN `jeecg-boot`.ctop_material_info cmi ON video.signature = cmi.code
+         LEFT JOIN (select material_id, clip_id, shot_id, plan_id, leader_id
+                    from (
+                             select material_id,
+                                    clip_id,
+                                    shot_id,
+                                    plan_id,
+                                    leader_id,
+                                    row_number() over (partition by material_id order by create_time) rn
+                             from `jeecg-boot`.ctop_material_ascription) m
+                    where rn = 1) cma
+                   ON video.signature = cma.material_id
+         LEFT JOIN `jeecg-boot`.ctop_user_allocation cua ON report.account_id = cua.account_id
+         LEFT JOIN `jeecg-boot`.ctop_advertiser ca ON cua.advertiser_id = ca.id
+         LEFT JOIN `jeecg-boot`.ctop_project cp ON cua.project_id = cp.id
+         LEFT JOIN `jeecg-boot`.user_company uc ON cua.user_id = uc.user_id
+         LEFT JOIN `jeecg-boot`.ctop_product product ON cp.product_id = product.id
+         LEFT JOIN `jeecg-boot`.sys_user su ON cua.user_id = su.id
+         LEFT JOIN `jeecg-boot`.sys_user clip ON clip.id = cma.clip_id
+         LEFT JOIN `jeecg-boot`.sys_user shot ON shot.id = cma.shot_id
+         LEFT JOIN `jeecg-boot`.sys_user plan ON plan.id = cma.plan_id
+         LEFT JOIN `jeecg-boot`.sys_user leader ON leader.id = cma.leader_id
+         LEFT JOIN `jeecg-boot`.user_company up ON up.user_id = cma.clip_id;""".format(date_time=self.date_time,
+                                                                                       day_count=self.day_count,
+                                                                                       project_id=project_id[0])
+                    TidbConn.upsert(conn=self.conn, sql_buff=sql)
+                    self.conn.commit()
+                except Exception as e:
+                    logging.error(e)
+                    return -1
+            TidbConn.conn_close(conn=self.conn)
+            return 0
+        except Exception as e:
+            logging.error(e)
+            return -1
+
+
+if __name__ == '__main__':
+    status = AppBytedanceVideoReportBusiMonth().taskHandler()
+    if status == 0:
+        print("作业执行成功")
+        exit(0)
+    else:
+        print("作业执行失败")
+        exit(-1)

+ 342 - 0
Apietl/kwai_etl/Q4Task/AppKuaishouAccountReportBusiMonth.py

@@ -0,0 +1,342 @@
+# Author renyupeng
+# coding=utf-8
+# @Time    : 2021/11/10 3:37 下午
+# @Site    :
+# @File    : AppKuaishouAccountReportBusiMonth.py
+# @Software: PyCharm
+# @contact: renyupeng@c-top.com.cn
+# @Tel 1501435553
+import logging
+
+from Apietl.conn.TidbConn import TidbConn
+from Apietl.utlis.Utils import Utils
+
+
+class AppKuaishouAccountReportBusiMonth:
+    def __init__(self):
+        self.conn = TidbConn.get_connection()
+        self.parm = Utils.get_task_args()
+        self.date_time = self.parm[0]
+        self.day_count = Utils.get_days()
+
+    def taskHandler(self):
+        try:
+            sql = """
+            SET sql_mode = 'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
+REPLACE INTO application.app_kuaishou_account_report_busi_m
+SELECT
+date_format({date_time},'%Y%m') stat_mon,
+report.account_id,
+bei.project_id,
+bei.product_id,
+bei.advertiser_id,
+bei.company_id,
+bei.account_name,
+bei.project_name,
+bei.advertiser_name,
+bei.company_name,
+bei.sale_id,
+bei.user_id,
+bei.leader_id,
+bei.org_code,
+report.charge,
+report.`show`,
+report.photo_click,
+report.aclick,
+report.bclick,
+report.photo_click_ratio,
+report.play_3s_ratio,
+report.action_ratio,
+report.impression_1k_cost,
+report.photo_click_cost,
+report.action_cost,
+report.`share`,
+report.`comment`,
+report.`like`,
+report.follow,
+report.cancel_follow,
+report.report,
+report.block,
+report.negative,
+report.submit,
+report.download_started,
+report.download_completed,
+report.activation,
+report.event_pay_first_day,
+report.event_pay_purchase_amount_first_day,
+report.event_pay_first_day_roi,
+report.event_pay,
+report.event_pay_purchase_amount,
+report.event_pay_roi,
+report.event_register,
+report.event_register_cost,
+report.event_register_ratio,
+report.event_jin_jian_app,
+report.event_jin_jian_app_cost,
+report.event_credit_grant_app,
+report.event_credit_grant_app_cost,
+report.event_credit_grant_app_ratio,
+report.event_order_paid,
+report.event_order_paid_purchase_amount,
+report.event_order_paid_cost,
+report.event_next_day_stay,
+report.event_next_day_stay_cost,
+report.event_next_day_stay_ratio,
+report.form_count,
+report.form_cost,
+report.form_action_ratio,
+report.event_jin_jian_landing_page,
+report.event_jin_jian_landing_page_cost,
+report.event_credit_grant_landing_page,
+report.event_credit_grant_landing_page_cost,
+report.event_credit_grant_landing_page_ratio,
+report.event_valid_clues,
+report.event_valid_clues_cost,
+report.event_add_wechat,
+report.event_add_wechat_cost,
+report.event_add_wechat_ratio,
+report.event_get_through,
+report.event_get_through_cost,
+report.event_get_through_ratio,
+report.event_app_invoked,
+report.event_app_invoked_cost,
+report.event_app_invoked_ratio,
+report.event_credit_grant_landing_ratio,
+report.play_5s_ratio,
+report.play_end_ratio,
+report.event_new_user_pay,
+report.event_new_user_pay_cost,
+report.event_new_user_pay_ratio,
+report.click_1k_cost,
+report.ad_product_cnt,
+report.event_goods_view,
+report.merchant_reco_fans,
+report.event_order_amount_roi,
+report.event_goods_view_cost,
+report.merchant_reco_fans_cost,
+report.event_button_click,
+report.event_button_click_cost,
+report.event_button_click_ratio,
+report.event_order_paid_roi,
+report.event_new_user_jinjian_app,
+report.event_new_user_jinjian_app_cost,
+report.event_new_user_jinjian_app_roi,
+report.event_new_user_credit_grant_app,
+report.event_new_user_credit_grant_app_cost,
+report.event_new_user_credit_grant_app_roi,
+report.event_new_user_jinjian_page,
+report.event_new_user_jinjian_page_cost,
+report.event_new_user_jinjian_page_roi,
+report.event_new_user_credit_grant_page,
+report.event_new_user_credit_grant_page_cost,
+report.event_new_user_credit_grant_page_roi,
+report.event_appoint_form,
+report.event_appoint_form_cost,
+report.event_appoint_form_ratio,
+report.event_appoint_jump_click,
+report.event_appoint_jump_click_cost,
+report.event_appoint_jump_click_ratio,
+report.union_event_pay_purchase_amount_7d,
+report.union_event_pay_purchase_amount_7d_roi,
+report.event_order_successed,
+report.ad_photo_played_10s_ratio,
+report.key_action_cost,
+report.event_add_shopping_cart_cost,
+report.event_ad_watch_times_ratio,
+report.event_outbound_call_cost,
+report.event_outbound_call,
+report.action_new_ratio,
+report.event_watch_app_ad,
+report.event_multi_conversion_cost,
+report.event_phone_card_activate,
+report.ad_photo_played_75percent_ratio,
+report.key_action_ratio,
+report.event_ad_watch_times_cost,
+report.event_add_shopping_cart,
+report.key_action,
+report.event_multi_conversion,
+report.event_wechat_connected,
+report.event_dsp_gift_form,
+report.event_intention_confirmed,
+report.event_phone_get_through,
+report.event_multi_conversion_ratio,
+report.event_measurement_house,
+report.ad_photo_played_2s_ratio,
+report.event_outbound_call_ratio,
+report.event_ad_watch_times
+from 
+(select 
+advertiser_id account_id,
+sum(charge) charge,
+sum(`show`) `show`,
+sum(photo_click)photo_click,
+sum(aclick)  aclick,
+sum(bclick) bclick,
+round(sum(photo_click)/sum(`show`),3) photo_click_ratio,
+round(sum(play_3s_ratio)/ {day_count}*100,3)  play_3s_ratio,
+round(sum(bclick)/sum(aclick)*100,3) action_ratio,
+round(sum(impression_1k_cost)/ {day_count},3) impression_1k_cost,
+round(sum(charge)/sum(photo_click),3) photo_click_cost,
+round(sum(charge)/sum(bclick),3) action_cost,
+sum(`share`) `share`,
+sum(`comment`) `comment`,
+sum(`like`)  `like`,
+sum(follow) follow,
+sum(cancel_follow)  cancel_follow,
+sum(report) report,
+sum(block) block,
+sum(negative) negative,
+sum(submit) submit,
+sum(download_started) download_started,
+sum(download_completed) download_completed,
+sum(activation) activation,
+sum(event_pay_first_day) event_pay_first_day,
+sum(event_pay_purchase_amount_first_day) event_pay_purchase_amount_first_day,
+round(sum(event_pay_purchase_amount_first_day)/sum(charge)*100,3) event_pay_first_day_roi ,
+sum(event_pay) event_pay,
+sum(event_pay_purchase_amount) event_pay_purchase_amount,
+round(sum(event_pay_purchase_amount)/sum(charge)*100,3) event_pay_roi,
+sum(event_register) event_register,
+round(sum(charge)/sum(event_register),3) event_register_cost,
+round(sum(event_register)/sum(activation)*100,3) event_register_ratio,
+sum(event_jin_jian_app) event_jin_jian_app,
+round(sum(charge)/sum(event_jin_jian_app),3) event_jin_jian_app_cost,
+sum(event_credit_grant_app) event_credit_grant_app,
+round(sum(charge)/sum(event_credit_grant_app),3) event_credit_grant_app_cost ,
+round(sum(event_credit_grant_app_ratio)/ {day_count}*100,3) event_credit_grant_app_ratio,
+sum(event_order_paid) event_order_paid,
+sum(event_order_paid_purchase_amount) event_order_paid_purchase_amount,
+round(sum(event_order_paid_purchase_amount)/sum(event_order_paid) ,3) event_order_paid_cost,
+sum(event_next_day_stay) event_next_day_stay,
+round(sum(charge)/sum(event_next_day_stay),3) event_next_day_stay_cost,
+round(sum(event_next_day_stay)/sum(activation)*100,3) event_next_day_stay_ratio,
+sum(form_count) form_count,
+round(sum(charge)/sum(form_count),3) form_cost,
+round(sum(form_count)/sum(`bclick`)*100,3) form_action_ratio,
+sum(event_jin_jian_landing_page) event_jin_jian_landing_page,
+round(sum(charge)/sum(event_jin_jian_landing_page),3) event_jin_jian_landing_page_cost,
+sum(event_credit_grant_landing_page) event_credit_grant_landing_page,
+round(sum(charge)/sum(event_credit_grant_landing_page),3) event_credit_grant_landing_page_cost,
+round(sum(event_credit_grant_landing_page)/ {day_count}*100,3) event_credit_grant_landing_page_ratio,
+sum(event_valid_clues) event_valid_clues,
+round(sum(charge)/sum(event_valid_clues),3) event_valid_clues_cost,
+sum(event_add_wechat) event_add_wechat,
+round(sum(charge)/sum(event_add_wechat),3) event_add_wechat_cost,
+round(sum(event_add_wechat)/sum(bclick)*100,3) event_add_wechat_ratio,
+sum(event_get_through) event_get_through,
+round(sum(charge)/sum(event_get_through),3) event_get_through_cost,
+round(sum(event_get_through)/sum(bclick)*100,3) event_get_through_ratio,
+sum(event_app_invoked) event_app_invoked,
+round(sum(charge)/sum(event_app_invoked),3) event_app_invoked_cost ,
+round(sum(event_app_invoked)/sum(bclick)*100,3) event_app_invoked_ratio,
+round(sum(event_credit_grant_landing_ratio)/ {day_count}*100,3) event_credit_grant_landing_ratio,
+round(sum(play_5s_ratio)/ {day_count}*100,3) play_5s_ratio,
+round(sum(play_end_ratio)/ {day_count}*100,3) play_end_ratio,
+sum(event_new_user_pay) event_new_user_pay,
+round(sum(charge)/sum(event_new_user_pay),3) event_new_user_pay_cost,
+round(sum(event_new_user_pay)/sum(activation)*100,3) event_new_user_pay_ratio,
+round(sum(click_1k_cost)/ {day_count}*100) click_1k_cost,
+sum(ad_product_cnt) ad_product_cnt,
+sum(event_goods_view) event_goods_view,
+sum(merchant_reco_fans) merchant_reco_fans,
+round(sum(event_order_amount_roi)/ {day_count}*100,3) event_order_amount_roi,
+round(sum(charge)/sum(event_goods_view) ,3) event_goods_view_cost,
+round(sum(charge)/sum(merchant_reco_fans),3) merchant_reco_fans_cost,
+sum(event_button_click) event_button_click,
+round(sum(charge)/sum(event_button_click),3) event_button_click_cost,
+round(sum(event_button_click)/sum(bclick)*100,3) event_button_click_ratio ,
+round(sum(event_order_paid_roi)/ {day_count}*100,3) event_order_paid_roi,
+sum(event_new_user_jinjian_app) event_new_user_jinjian_app,
+round(sum(charge)/sum(event_new_user_jinjian_app),3) event_new_user_jinjian_app_cost,
+round(sum(event_new_user_jinjian_app)/sum(form_count)*100,3) event_new_user_jinjian_app_roi ,
+sum(event_new_user_credit_grant_app) event_new_user_credit_grant_app,
+round(sum(charge)/sum(event_new_user_credit_grant_app),3)  event_new_user_credit_grant_app_cost,
+round(sum(event_new_user_credit_grant_app)/sum(form_count)*100,3) event_new_user_credit_grant_app_roi,
+sum(event_new_user_jinjian_page) event_new_user_jinjian_page,
+round(sum(charge)/sum(event_new_user_jinjian_page),3) event_new_user_jinjian_page_cost,
+round(sum(event_new_user_jinjian_page)/sum(form_count)*100,3) event_new_user_jinjian_page_roi ,
+sum(event_new_user_credit_grant_page) event_new_user_credit_grant_page,
+round(sum(charge)/sum(event_new_user_credit_grant_page) ,3) event_new_user_credit_grant_page_cost,
+round(sum(event_new_user_credit_grant_page)/sum(form_count)*100,3) event_new_user_credit_grant_page_roi,
+sum(event_appoint_form)  event_appoint_form,
+round(sum(charge)/sum(event_appoint_form),3) event_appoint_form_cost,
+round(sum(event_appoint_form)/sum(form_count)*100,3) event_appoint_form_ratio,
+sum(event_appoint_jump_click) event_appoint_jump_click,
+round(sum(charge)/sum(event_appoint_jump_click),3)  event_appoint_jump_click_cost,
+round(sum(event_appoint_jump_click_cost)/sum(form_count)*100,3) event_appoint_jump_click_ratio,
+sum(union_event_pay_purchase_amount_7d) union_event_pay_purchase_amount_7d,
+round(sum(union_event_pay_purchase_amount_7d_roi)/ {day_count}*100,3) union_event_pay_purchase_amount_7d_roi,
+sum(event_order_successed) event_order_successed,
+round(sum(ad_photo_played_10s_ratio)/ {day_count}*100,3) ad_photo_played_10s_ratio,
+round(sum(charge)/sum(key_action),3) key_action_cost,
+round(sum(charge)/sum(event_add_shopping_cart) ,3) event_add_shopping_cart_cost ,
+round(sum(event_ad_watch_times)/sum(bclick)*100,3) event_ad_watch_times_ratio,
+round(sum(charge)/sum(event_outbound_call),3) event_outbound_call_cost,
+sum(event_outbound_call) event_outbound_call,
+round(sum(action_new_ratio)/ {day_count}*100,3) action_new_ratio,
+sum(event_watch_app_ad) event_watch_app_ad,
+round(sum(charge)/sum(event_multi_conversion) ,3) event_multi_conversion_cost,
+sum(event_phone_card_activate) event_phone_card_activate,
+round(sum(ad_photo_played_75percent_ratio)/ {day_count}*100,3) ad_photo_played_75percent_ratio,
+round(sum(key_action)/sum(activation)*100,3) key_action_ratio ,
+round(sum(charge)/sum(event_ad_watch_times),3) event_ad_watch_times_cost,
+sum(event_add_shopping_cart) event_add_shopping_cart,
+sum(key_action) key_action,
+sum(event_multi_conversion) event_multi_conversion,
+sum(event_wechat_connected) event_wechat_connected,
+sum(event_dsp_gift_form) event_dsp_gift_form,
+sum(event_intention_confirmed) event_intention_confirmed,
+sum(event_phone_get_through) event_phone_get_through,
+round(sum(event_multi_conversion)/sum(activation)*100,3)  event_multi_conversion_ratio,
+sum(event_measurement_house) event_measurement_house,
+round(sum(ad_photo_played_2s_ratio)/ {day_count}*100,3) ad_photo_played_2s_ratio,
+round(sum(event_outbound_call_ratio)/sum(activation)*100,3) event_outbound_call_ratio,
+sum(event_ad_watch_times) event_ad_watch_times
+from 
+ media_api.kuaishou_account_report_daily a 
+where stat_date >= date_format(date_sub({date_time},INTERVAL {day_count} DAY),'%Y%m%d')
+ group by advertiser_id) report
+LEFT JOIN (
+SELECT
+cua.account_id id,
+cua.account_id account_id,
+cp.id project_id,
+product.id product_id,
+ca.id advertiser_id,
+uc.company_id company_id,
+cua.auth_name account_name,
+cp.project_name project_name,
+ca.`name` advertiser_name,
+uc.company_name company_name,
+cp.sale_id sale_id,
+su.id user_id,
+su.leader_id,
+su.org_code org_code
+FROM
+`jeecg-boot`.ctop_user_allocation cua
+LEFT JOIN `jeecg-boot`.ctop_project cp ON cua.project_id = cp.id
+LEFT JOIN `jeecg-boot`.ctop_advertiser ca ON ca.id = cua.advertiser_id
+LEFT JOIN `jeecg-boot`.sys_user su ON su.id = cua.user_id
+LEFT JOIN `jeecg-boot`.user_company uc ON uc.user_id = cua.user_id
+LEFT JOIN `jeecg-boot`.ctop_product product ON product.id = cp.product_id
+WHERE
+cua.account_id IS NOT NULL) bei 
+ON report.account_id = bei.account_id;
+            """.format(date_time=self.date_time, day_count=self.day_count)
+            TidbConn.upsert(conn=self.conn, sql_buff=sql)
+            self.conn.commit()
+            TidbConn.conn_close(conn=self.conn)
+            return 0
+        except Exception as e:
+            logging.error(e)
+            return -1
+
+
+if __name__ == '__main__':
+    status = AppKuaishouAccountReportBusiMonth().taskHandler()
+    if status == 0:
+        print("作业执行成功")
+        exit(0)
+    else:
+        print("作业执行失败")
+        exit(-1)