renyupeng 3 anni fa
parent
commit
9f9884eb3c

+ 226 - 0
Apietl/kwai_etl/report/AccountDailyReport.py

@@ -0,0 +1,226 @@
+# Author renyupeng
+# coding=utf-8
+# @Time    : 2021/9/27 10:50 上午
+# @Site    : 
+# @File    : AccountDailyReport.py
+# @Software: PyCharm
+# @contact: renyupeng@c-top.com.cn
+# @Tel 1501435553
+import logging
+from math import ceil
+
+from Apietl.utlis.Logger import Logger
+from Apietl.utlis.Utils import Utils
+from TidbConn import TidbConn
+
+
+class AccountDailyReport:
+    def __init__(self):
+        self.conn = TidbConn.get_connection()
+        self.parm = Utils.get_args()
+        self.start_time = self.parm[0]
+        self.end_time = self.parm[1]
+
+    def daily_report(self):
+        try:
+            sql = """select count(1) from media_api.kuaishou_account_report_daily where 
+            stat_date between {start_time} and {end_time}""".format(
+                start_time=self.start_time, end_time=self.end_time)
+            totalNum = TidbConn.quary(sql)[0][0]
+            pageCount = ceil(totalNum / 20000)
+            for i in range(pageCount):
+                sql = """
+            replace into application.kuaishou_account_report_daily_dw
+(account_id, stat_date, project_id, product_id, advertiser_id, company_id, account_name, project_name, advertiser_name,
+ company_name, sale_id, user_id, org_code, charge, `show`, photo_click, aclick, bclick, photo_click_ratio,
+ play_3s_ratio, action_ratio, impression_1k_cost, photo_click_cost, action_cost, share, comment, `like`, follow,
+ cancel_follow, report, block, negative, submit, download_started, download_completed, activation, event_pay_first_day,
+ event_pay_purchase_amount_first_day, event_pay_first_day_roi, event_pay, event_pay_purchase_amount, event_pay_roi,
+ event_register, event_register_cost, event_register_ratio, event_jin_jian_app, event_jin_jian_app_cost,
+ event_credit_grant_app, event_credit_grant_app_cost, event_credit_grant_app_ratio, event_order_paid,
+ event_order_paid_purchase_amount, event_order_paid_cost, event_next_day_stay, event_next_day_stay_cost,
+ event_next_day_stay_ratio, form_count, form_cost, form_action_ratio, event_jin_jian_landing_page,
+ event_jin_jian_landing_page_cost, event_credit_grant_landing_page, event_credit_grant_landing_page_cost,
+ event_credit_grant_landing_page_ratio, event_valid_clues, event_valid_clues_cost, event_add_wechat,
+ event_add_wechat_cost, event_add_wechat_ratio, event_get_through, event_get_through_cost, event_get_through_ratio,
+ event_app_invoked, event_app_invoked_cost, event_app_invoked_ratio, event_credit_grant_landing_ratio, play_5s_ratio,
+ play_end_ratio, event_new_user_pay, event_new_user_pay_cost, event_new_user_pay_ratio, click_1k_cost, ad_product_cnt,
+ event_goods_view, merchant_reco_fans, event_order_amount_roi, event_goods_view_cost, merchant_reco_fans_cost,
+ event_button_click, event_button_click_cost, event_button_click_ratio, event_order_paid_roi,
+ event_new_user_jinjian_app, event_new_user_jinjian_app_cost, event_new_user_jinjian_app_roi,
+ event_new_user_credit_grant_app, event_new_user_credit_grant_app_cost, event_new_user_credit_grant_app_roi,
+ event_new_user_jinjian_page, event_new_user_jinjian_page_cost, event_new_user_jinjian_page_roi,
+ event_new_user_credit_grant_page, event_new_user_credit_grant_page_cost, event_new_user_credit_grant_page_roi,
+ event_appoint_form, event_appoint_form_cost, event_appoint_form_ratio, event_appoint_jump_click,
+ event_appoint_jump_click_cost, event_appoint_jump_click_ratio, union_event_pay_purchase_amount_7d,
+ union_event_pay_purchase_amount_7d_roi, placement_type, ad_scene, event_order_successed, ad_photo_played_10s_ratio,
+ key_action_cost, event_add_shopping_cart_cost, event_ad_watch_times_ratio, event_outbound_call_cost,
+ event_outbound_call, action_new_ratio, event_watch_app_ad, event_multi_conversion_cost, event_phone_card_activate,
+ ad_photo_played_75percent_ratio, key_action_ratio, event_ad_watch_times_cost, event_add_shopping_cart, key_action,
+ event_multi_conversion, event_wechat_connected, event_dsp_gift_form, event_intention_confirmed,
+ event_phone_get_through, event_multi_conversion_ratio, event_measurement_house, ad_photo_played_2s_ratio,
+ event_outbound_call_ratio, event_ad_watch_times)
+        select report.advertiser_id as account_id,
+               stat_date,
+               project_id,
+               product_id,
+               sys.advertiser_id,
+               company_id,
+               account_name,
+               project_name,
+               advertiser_name,
+               company_name,
+               sale_id,
+               user_id,
+               org_code,
+               charge,
+               `show`,
+               photo_click,
+               aclick,
+               bclick,
+               photo_click_ratio,
+               play_3s_ratio,
+               action_ratio,
+               impression_1k_cost,
+               photo_click_cost,
+               action_cost,
+               share,
+               comment,
+               `like`,
+               follow,
+               cancel_follow,
+               report,
+               block,
+               negative,
+               submit,
+               download_started,
+               download_completed,
+               activation,
+               event_pay_first_day,
+               event_pay_purchase_amount_first_day,
+               event_pay_first_day_roi,
+               event_pay,
+               event_pay_purchase_amount,
+               event_pay_roi,
+               event_register,
+               event_register_cost,
+               event_register_ratio,
+               event_jin_jian_app,
+               event_jin_jian_app_cost,
+               event_credit_grant_app,
+               event_credit_grant_app_cost,
+               event_credit_grant_app_ratio,
+               event_order_paid,
+               event_order_paid_purchase_amount,
+               event_order_paid_cost,
+               event_next_day_stay,
+               event_next_day_stay_cost,
+               event_next_day_stay_ratio,
+               form_count,
+               form_cost,
+               form_action_ratio,
+               event_jin_jian_landing_page,
+               event_jin_jian_landing_page_cost,
+               event_credit_grant_landing_page,
+               event_credit_grant_landing_page_cost,
+               event_credit_grant_landing_page_ratio,
+               event_valid_clues,
+               event_valid_clues_cost,
+               event_add_wechat,
+               event_add_wechat_cost,
+               event_add_wechat_ratio,
+               event_get_through,
+               event_get_through_cost,
+               event_get_through_ratio,
+               event_app_invoked,
+               event_app_invoked_cost,
+               event_app_invoked_ratio,
+               event_credit_grant_landing_ratio,
+               play_5s_ratio,
+               play_end_ratio,
+               event_new_user_pay,
+               event_new_user_pay_cost,
+               event_new_user_pay_ratio,
+               click_1k_cost,
+               ad_product_cnt,
+               event_goods_view,
+               merchant_reco_fans,
+               event_order_amount_roi,
+               event_goods_view_cost,
+               merchant_reco_fans_cost,
+               event_button_click,
+               event_button_click_cost,
+               event_button_click_ratio,
+               event_order_paid_roi,
+               event_new_user_jinjian_app,
+               event_new_user_jinjian_app_cost,
+               event_new_user_jinjian_app_roi,
+               event_new_user_credit_grant_app,
+               event_new_user_credit_grant_app_cost,
+               event_new_user_credit_grant_app_roi,
+               event_new_user_jinjian_page,
+               event_new_user_jinjian_page_cost,
+               event_new_user_jinjian_page_roi,
+               event_new_user_credit_grant_page,
+               event_new_user_credit_grant_page_cost,
+               event_new_user_credit_grant_page_roi,
+               event_appoint_form,
+               event_appoint_form_cost,
+               event_appoint_form_ratio,
+               event_appoint_jump_click,
+               event_appoint_jump_click_cost,
+               event_appoint_jump_click_ratio,
+               union_event_pay_purchase_amount_7d,
+               union_event_pay_purchase_amount_7d_roi,
+               placement_type,
+               ad_scene,
+               event_order_successed,
+               ad_photo_played_10s_ratio,
+               key_action_cost,
+               event_add_shopping_cart_cost,
+               event_ad_watch_times_ratio,
+               event_outbound_call_cost,
+               event_outbound_call,
+               action_new_ratio,
+               event_watch_app_ad,
+               event_multi_conversion_cost,
+               event_phone_card_activate,
+               ad_photo_played_75percent_ratio,
+               key_action_ratio,
+               event_ad_watch_times_cost,
+               event_add_shopping_cart,
+               key_action,
+               event_multi_conversion,
+               event_wechat_connected,
+               event_dsp_gift_form,
+               event_intention_confirmed,
+               event_phone_get_through,
+               event_multi_conversion_ratio,
+               event_measurement_house,
+               ad_photo_played_2s_ratio,
+               event_outbound_call_ratio,
+               event_ad_watch_times
+        from media_api.kuaishou_account_report_daily report
+                 left join
+             `jeecg-boot`.ctop_account_attribution_info sys
+             on report.advertiser_id = sys.account_id
+        where report.stat_date between {start_date} and {end_date}
+        order by account_id,stat_date limit {num},20000
+        """.format(start_time=self.start_time, end_time=self.end_time,num=i * 20000)
+                print(sql)
+                TidbConn.exec_sql(self.conn, sql)
+                self.conn.commit()
+            return 0
+        except Exception as e:
+            logging.error(e)
+            return -1
+
+
+if __name__ == '__main__':
+    status = AccountDailyReport().daily_report()
+    if status == 0:
+        print("作业执行成功")
+        exit(0)
+    else:
+        print("作业执行失败")
+        exit(-1)

+ 227 - 0
Apietl/kwai_etl/report/AccountHourlyReport.py

@@ -0,0 +1,227 @@
+# Author renyupeng
+# coding=utf-8
+# @Time    : 2021/9/27 10:50 上午
+# @Site    : 
+# @File    : AccountHourlyReport.py
+# @Software: PyCharm
+# @contact: renyupeng@c-top.com.cn
+# @Tel 1501435553
+import logging
+from math import ceil
+
+from Apietl.utlis.Logger import Logger
+from Apietl.utlis.Utils import Utils
+from TidbConn import TidbConn
+
+
+class AccountHourlyReport:
+    def __init__(self):
+        self.conn = TidbConn.get_connection()
+        self.parm = Utils.get_args()
+        self.start_time = self.parm[0]
+        self.end_time = self.parm[1]
+
+    def daily_report(self):
+        try:
+            sql = """select count(1) from media_api.kuaishou_account_report_hourly where 
+            stat_date between {start_time} and {end_time}""".format(
+                start_time=self.start_time, end_time=self.end_time)
+            totalNum = TidbConn.quary(sql)[0][0]
+            pageCount = ceil(totalNum / 20000)
+            for i in range(pageCount):
+                sql = """
+            replace into application.kuaishou_account_report_hourly_dw
+(account_id, stat_date, `hour`, project_id, product_id, advertiser_id, company_id, account_name, project_name, advertiser_name,
+ company_name, sale_id, user_id, org_code, charge, `show`, photo_click, aclick, bclick, photo_click_ratio,
+ play_3s_ratio, action_ratio, impression_1k_cost, photo_click_cost, action_cost, share, comment, `like`, follow,
+ cancel_follow, report, block, negative, submit, download_started, download_completed, activation, event_pay_first_day,
+ event_pay_purchase_amount_first_day, event_pay_first_day_roi, event_pay, event_pay_purchase_amount, event_pay_roi,
+ event_register, event_register_cost, event_register_ratio, event_jin_jian_app, event_jin_jian_app_cost,
+ event_credit_grant_app, event_credit_grant_app_cost, event_credit_grant_app_ratio, event_order_paid,
+ event_order_paid_purchase_amount, event_order_paid_cost, event_next_day_stay, event_next_day_stay_cost,
+ event_next_day_stay_ratio, form_count, form_cost, form_action_ratio, event_jin_jian_landing_page,
+ event_jin_jian_landing_page_cost, event_credit_grant_landing_page, event_credit_grant_landing_page_cost,
+ event_credit_grant_landing_page_ratio, event_valid_clues, event_valid_clues_cost, event_add_wechat,
+ event_add_wechat_cost, event_add_wechat_ratio, event_get_through, event_get_through_cost, event_get_through_ratio,
+ event_app_invoked, event_app_invoked_cost, event_app_invoked_ratio, event_credit_grant_landing_ratio, play_5s_ratio,
+ play_end_ratio, event_new_user_pay, event_new_user_pay_cost, event_new_user_pay_ratio, click_1k_cost, ad_product_cnt,
+ event_goods_view, merchant_reco_fans, event_order_amount_roi, event_goods_view_cost, merchant_reco_fans_cost,
+ event_button_click, event_button_click_cost, event_button_click_ratio, event_order_paid_roi,
+ event_new_user_jinjian_app, event_new_user_jinjian_app_cost, event_new_user_jinjian_app_roi,
+ event_new_user_credit_grant_app, event_new_user_credit_grant_app_cost, event_new_user_credit_grant_app_roi,
+ event_new_user_jinjian_page, event_new_user_jinjian_page_cost, event_new_user_jinjian_page_roi,
+ event_new_user_credit_grant_page, event_new_user_credit_grant_page_cost, event_new_user_credit_grant_page_roi,
+ event_appoint_form, event_appoint_form_cost, event_appoint_form_ratio, event_appoint_jump_click,
+ event_appoint_jump_click_cost, event_appoint_jump_click_ratio, union_event_pay_purchase_amount_7d,
+ union_event_pay_purchase_amount_7d_roi, placement_type, ad_scene, event_order_successed, ad_photo_played_10s_ratio,
+ key_action_cost, event_add_shopping_cart_cost, event_ad_watch_times_ratio, event_outbound_call_cost,
+ event_outbound_call, action_new_ratio, event_watch_app_ad, event_multi_conversion_cost, event_phone_card_activate,
+ ad_photo_played_75percent_ratio, key_action_ratio, event_ad_watch_times_cost, event_add_shopping_cart, key_action,
+ event_multi_conversion, event_wechat_connected, event_dsp_gift_form, event_intention_confirmed,
+ event_phone_get_through, event_multi_conversion_ratio, event_measurement_house, ad_photo_played_2s_ratio,
+ event_outbound_call_ratio, event_ad_watch_times)
+        select report.advertiser_id as account_id,
+               stat_date,
+                `hour`,
+               project_id,
+               product_id,
+               sys.advertiser_id,
+               company_id,
+               account_name,
+               project_name,
+               advertiser_name,
+               company_name,
+               sale_id,
+               user_id,
+               org_code,
+               charge,
+               `show`,
+               photo_click,
+               aclick,
+               bclick,
+               photo_click_ratio,
+               play_3s_ratio,
+               action_ratio,
+               impression_1k_cost,
+               photo_click_cost,
+               action_cost,
+               share,
+               comment,
+               `like`,
+               follow,
+               cancel_follow,
+               report,
+               block,
+               negative,
+               submit,
+               download_started,
+               download_completed,
+               activation,
+               event_pay_first_day,
+               event_pay_purchase_amount_first_day,
+               event_pay_first_day_roi,
+               event_pay,
+               event_pay_purchase_amount,
+               event_pay_roi,
+               event_register,
+               event_register_cost,
+               event_register_ratio,
+               event_jin_jian_app,
+               event_jin_jian_app_cost,
+               event_credit_grant_app,
+               event_credit_grant_app_cost,
+               event_credit_grant_app_ratio,
+               event_order_paid,
+               event_order_paid_purchase_amount,
+               event_order_paid_cost,
+               event_next_day_stay,
+               event_next_day_stay_cost,
+               event_next_day_stay_ratio,
+               form_count,
+               form_cost,
+               form_action_ratio,
+               event_jin_jian_landing_page,
+               event_jin_jian_landing_page_cost,
+               event_credit_grant_landing_page,
+               event_credit_grant_landing_page_cost,
+               event_credit_grant_landing_page_ratio,
+               event_valid_clues,
+               event_valid_clues_cost,
+               event_add_wechat,
+               event_add_wechat_cost,
+               event_add_wechat_ratio,
+               event_get_through,
+               event_get_through_cost,
+               event_get_through_ratio,
+               event_app_invoked,
+               event_app_invoked_cost,
+               event_app_invoked_ratio,
+               event_credit_grant_landing_ratio,
+               play_5s_ratio,
+               play_end_ratio,
+               event_new_user_pay,
+               event_new_user_pay_cost,
+               event_new_user_pay_ratio,
+               click_1k_cost,
+               ad_product_cnt,
+               event_goods_view,
+               merchant_reco_fans,
+               event_order_amount_roi,
+               event_goods_view_cost,
+               merchant_reco_fans_cost,
+               event_button_click,
+               event_button_click_cost,
+               event_button_click_ratio,
+               event_order_paid_roi,
+               event_new_user_jinjian_app,
+               event_new_user_jinjian_app_cost,
+               event_new_user_jinjian_app_roi,
+               event_new_user_credit_grant_app,
+               event_new_user_credit_grant_app_cost,
+               event_new_user_credit_grant_app_roi,
+               event_new_user_jinjian_page,
+               event_new_user_jinjian_page_cost,
+               event_new_user_jinjian_page_roi,
+               event_new_user_credit_grant_page,
+               event_new_user_credit_grant_page_cost,
+               event_new_user_credit_grant_page_roi,
+               event_appoint_form,
+               event_appoint_form_cost,
+               event_appoint_form_ratio,
+               event_appoint_jump_click,
+               event_appoint_jump_click_cost,
+               event_appoint_jump_click_ratio,
+               union_event_pay_purchase_amount_7d,
+               union_event_pay_purchase_amount_7d_roi,
+               placement_type,
+               ad_scene,
+               event_order_successed,
+               ad_photo_played_10s_ratio,
+               key_action_cost,
+               event_add_shopping_cart_cost,
+               event_ad_watch_times_ratio,
+               event_outbound_call_cost,
+               event_outbound_call,
+               action_new_ratio,
+               event_watch_app_ad,
+               event_multi_conversion_cost,
+               event_phone_card_activate,
+               ad_photo_played_75percent_ratio,
+               key_action_ratio,
+               event_ad_watch_times_cost,
+               event_add_shopping_cart,
+               key_action,
+               event_multi_conversion,
+               event_wechat_connected,
+               event_dsp_gift_form,
+               event_intention_confirmed,
+               event_phone_get_through,
+               event_multi_conversion_ratio,
+               event_measurement_house,
+               ad_photo_played_2s_ratio,
+               event_outbound_call_ratio,
+               event_ad_watch_times
+        from media_api.kuaishou_account_report_daily report
+                 left join
+             `jeecg-boot`.ctop_account_attribution_info sys
+             on report.advertiser_id = sys.account_id
+        where report.stat_date between {start_date} and {end_date}
+               order by account_id,hour,stat_date limit {num},20000
+        """.format(start_time=self.start_time, end_time=self.end_time, num=i * 20000)
+                print(sql)
+                TidbConn.exec_sql(self.conn, sql)
+                self.conn.commit()
+            return 0
+        except Exception as e:
+            logging.error(e)
+            return -1
+
+
+if __name__ == '__main__':
+    status = AccountHourlyReport().daily_report()
+    if status == 0:
+        print("作业执行成功")
+        exit(0)
+    else:
+        print("作业执行失败")
+        exit(-1)

+ 35 - 30
Apietl/kwai_etl/report/MateirialVideoDailyReport.py

@@ -115,28 +115,28 @@ class MateirialVideoDailyReport:
        video_name,
        channel_name,
        clip_company_id)
-select report.advertiser_id as account_id,
-       project_id,
-       product_id,
-       sys.advertiser_id,
-       company_id,
+select report.advertiser_id                                                                     as account_id,
+       cp.id                                                                                    as project_id,
+       product.id                                                                               as product_id,
+       ca.id                                                                                    as advertiser_id,
+       uc.company_id,
        account_name,
-       project_name,
-       advertiser_name,
-       company_name,
-       sale_id,
-       user_id,
+       cp.project_name                                                                          as project_name,
+       ca.name                                                                                  as advertiser_name,
+       uc.company_name,
+       cp.sale_id,
+       cua.user_id,
        clip_id,
        shot_id,
        plan_id,
-       leader_id,
-       org_code,
-        report.photo_url,
+       cma.leader_id,
+       su.org_code,
+       report.photo_url,
        report.photo_id,
-        report.cover_url,
-        report.image_token,
-        report.photo_caption,
-       stat_date,
+       report.cover_url,
+       report.image_token,
+       report.photo_caption,
+       report.stat_date,
        charge,
        `show`,
        photo_click,
@@ -265,20 +265,25 @@ select report.advertiser_id as account_id,
        event_outbound_call_ratio,
        event_ad_watch_times,
        video.signature,
-       sys.channel_type ,
-       sys.clip_name,
-       sys.shot_name,
-       sys.plan_name,
-       sys.leader_name,
-       sys.video_name,
-       sys.channel_name,
-       sys.company_id
+       case when video.channel_type = 1 then '素造' else '内部' end,
+       cma.clip_name,
+       cma.shot_name,
+       cma.plan_name,
+       cma.leader_name,
+       case when cmi.material_name is not null then cmi.material_name else video.photo_name end as video_name,
+       uc.company_id
 from media_api.kuaishou_material_video_report_daily report
-    left join media_api.kuaishou_video_list video
-    on report.advertiser_id=video.advertiser_id and report.photo_id=video.photo_id
-         left join
-     `jeecg-boot`.ctop_material_attribution_info sys
-     on report.advertiser_id = sys.account_id
+         inner join media_api.kuaishou_video_list video
+                    on report.advertiser_id = video.account_id and report.photo_id = video.photo_id
+         left join `jeecg-boot`.ctop_material_info cmi on video.signature = cmi.code
+         left join `jeecg-boot`.ctop_material_ascription cma on cma.code = video.signature
+         left join `jeecg-boot`.ctop_user_allocation cua on cua.account_id = video.account_id
+         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`.sys_user clip on clip.id = cma.clip_id
+         left join `jeecg-boot`.user_company uc on uc.user_id = clip.id
+         left join `jeecg-boot`.ctop_product product on product.id = cp.product_id
  where report.stat_date between {start_time} and {end_time} and  report.photo_id!=0
   order by advertiser_id,photo_id ,stat_date limit {num},20000""".format(
                     start_time=self.start_time, end_time=self.end_time, num=i * 20000)

+ 38 - 32
Apietl/kwai_etl/report/MateirialVideoHourlyReport.py

@@ -29,13 +29,13 @@ class MateirialVideoHourlyReport:
             totalNum = TidbConn.quary(sql)[0][0]
             pageCount = ceil(totalNum / 20000)
             for i in range(pageCount):
-                sql = """replace into application.kuaishou_material_video_report_daily_dw
+                sql = """replace into application.kuaishou_material_video_report_hourl_dw
 (account_id, project_id, product_id, advertiser_id,
  company_id, account_name, project_name,
  advertiser_name, company_name, sale_id, user_id,
  clip_id, shot_id, plan_id, leader_id, org_code,
  photo_url, photo_id, cover_url, image_token,
- photo_caption, stat_date, charge, `show`, photo_click,
+ photo_caption, stat_date, `hour`,charge, `show`, photo_click,
  aclick, bclick, photo_click_ratio, play_3s_ratio,
  action_ratio, impression_1k_cost, photo_click_cost,
  action_cost, share, comment, `like`, follow,
@@ -115,28 +115,29 @@ class MateirialVideoHourlyReport:
        video_name,
        channel_name,
        clip_company_id)
-select report.advertiser_id as account_id,
-       project_id,
-       product_id,
-       sys.advertiser_id,
-       company_id,
+select report.advertiser_id                                                                     as account_id,
+       cp.id                                                                                    as project_id,
+       product.id                                                                               as product_id,
+       ca.id                                                                                    as advertiser_id,
+       uc.company_id,
        account_name,
-       project_name,
-       advertiser_name,
-       company_name,
-       sale_id,
-       user_id,
+       cp.project_name                                                                          as project_name,
+       ca.name                                                                                  as advertiser_name,
+       uc.company_name,
+       cp.sale_id,
+       cua.user_id,
        clip_id,
        shot_id,
        plan_id,
-       leader_id,
-       org_code,
-        report.photo_url,
+       cma.leader_id,
+       su.org_code,
+       report.photo_url,
        report.photo_id,
-        report.cover_url,
-        report.image_token,
-        report.photo_caption,
-       stat_date,
+       report.cover_url,
+       report.image_token,
+       report.photo_caption,
+       report.stat_date,
+       report.`hour`,
        charge,
        `show`,
        photo_click,
@@ -265,20 +266,25 @@ select report.advertiser_id as account_id,
        event_outbound_call_ratio,
        event_ad_watch_times,
        video.signature,
-       sys.channel_type ,
-       sys.clip_name,
-       sys.shot_name,
-       sys.plan_name,
-       sys.leader_name,
-       sys.video_name,
-       sys.channel_name,
-       sys.company_id
+       case when video.channel_type = 1 then '素造' else '内部' end,
+       cma.clip_name,
+       cma.shot_name,
+       cma.plan_name,
+       cma.leader_name,
+       case when cmi.material_name is not null then cmi.material_name else video.photo_name end as video_name,
+       uc.company_id
 from media_api.kuaishou_material_video_report_hourly report
-    left join media_api.kuaishou_video_list video
-    on report.advertiser_id=video.advertiser_id and report.photo_id=video.photo_id
-         left join
-     `jeecg-boot`.ctop_material_attribution_info sys
-     on report.advertiser_id = sys.account_id
+         inner join media_api.kuaishou_video_list video
+                    on report.advertiser_id = video.account_id and report.photo_id = video.photo_id
+         left join `jeecg-boot`.ctop_material_info cmi on video.signature = cmi.code
+         left join `jeecg-boot`.ctop_material_ascription cma on cma.code = video.signature
+         left join `jeecg-boot`.ctop_user_allocation cua on cua.account_id = video.account_id
+         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`.sys_user clip on clip.id = cma.clip_id
+         left join `jeecg-boot`.user_company uc on uc.user_id = clip.id
+         left join `jeecg-boot`.ctop_product product on product.id = cp.product_id
  where report.stat_date between {start_time} and {end_time} and  report.photo_id!=0
   order by advertiser_id,photo_id ,stat_date,`hour` limit {num},20000""".format(
                     start_time=self.start_time, end_time=self.end_time, num=i * 20000)