renyupeng 1 年之前
父节点
当前提交
20e88bb4ce
共有 1 个文件被更改,包括 84 次插入142 次删除
  1. 84 142
      Apietl/task/AppBytedanceAccountBaseInfoDsD.py

+ 84 - 142
Apietl/task/AppBytedanceAccountBaseInfoDsD.py

@@ -22,40 +22,38 @@ class AppBytedanceAccountBaseInfoDsD:
         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_account_base_info_d`
-            (
-            stat_date,
-            account_id,
-            account_name,
-            project_id,
-            project_name,
-            product_id,
-            product_name,
-            user_id,
-            user_name,
-            leader_id,
-            leader_name,
-            company_id,
-            company_name,
-            dept_id,
-            dept_name,
-            all_campaign_num,
-            new_campaign_num,
-            all_ad_num,
-            new_ad_num,
-            all_video_num,
-            new_video_num,
-            effect_num,
-            new_effect_num,
-            hot_num,
-            new_hot_num,
-            put_campaign_num,
-            put_unit_num,
-            trust_campaign_num,
-            trust_unit_num,
-            new_cpd_project_num,
-            promotion_num
-            )
+replace into `application`.`app_bytedance_account_base_info_d`
+(stat_date,
+ account_id,
+ account_name,
+ project_id,
+ project_name,
+ product_id,
+ product_name,
+ user_id,
+ user_name,
+ leader_id,
+ leader_name,
+ company_id,
+ company_name,
+ dept_id,
+ dept_name,
+ all_campaign_num,
+ new_campaign_num,
+ all_ad_num,
+ new_ad_num,
+ all_video_num,
+ new_video_num,
+ effect_num,
+ new_effect_num,
+ hot_num,
+ new_hot_num,
+ put_campaign_num,
+ put_unit_num,
+ trust_campaign_num,
+ trust_unit_num,
+ new_cpd_project_num,
+ promotion_num)
 select {date_time}                       stat_date,
        t1.account_id,
        bei.account_name,
@@ -71,100 +69,46 @@ select {date_time}                       stat_date,
        bei.company_name,
        bei.dept_id,
        bei.dept_name,
-       sum_cam.cam_num                as all_campaign_num,
-       cam.campain_num                   new_campaign_num,
-       sum_ad.ad_num                  as all_ad_num,
-       t2.ad_num                         new_ad_num,
-       video_num                      as all_video_num,
+       0                              as all_campaign_num,
+       0                                 new_campaign_num,
+       0                              as all_ad_num,
+       0                                 new_ad_num,
+       0                              as all_video_num,
        t3.day_num                        new_video_num,
-       sum_eff.new_eff_material          effect_num,
-       ifnull(t4.new_eff_material, 0) as new_effect_num,
+       0                                 effect_num,
+       0                              as new_effect_num,
        sum_hot.new_hot_material       as hot_num,
        ifnull(t5.new_hot_material, 0) as new_hot_num,
        0                              as put_campaign_num,
        0                              as put_unit_num,
        0                              as trust_campaign_num,
        0                              as trust_unit_num,
-       project_num as new_cpd_project_num,
-       promotion_num as promotion_num
+       project_num                    as new_cpd_project_num,
+       promotion_num                  as promotion_num
 from (select * from `jeecg-boot`.ctop_user_allocation where media_id = 1) t1
          left join
-     (select account_id, count(id) ad_num
-      from `media_api`.bytedance_ad_get
-      where date_format(ad_create_time, '%Y%m%d') = {date_time}
-      group by account_id) t2
-     on t1.account_id = t2.account_id
-         left join(
-    select account_id, count(id) ad_num
-    from `media_api`.bytedance_ad_get
-    where date_format(ad_create_time, '%Y%m%d') <= {date_time}
-    group by account_id
-) sum_ad on t1.account_id = sum_ad.account_id
-         left join (select advertiser_id, count(campaign_id) campain_num
-                    from media_api.bytedance_campaign_get
-                    where date_format(campaign_create_time, '%Y%m%d') = {date_time}
-                    group by advertiser_id) cam
-                   on t1.account_id = cam.advertiser_id
-         left join(
-    select advertiser_id, count(campaign_id) cam_num
-    from `media_api`.bytedance_campaign_get
-    where date_format(campaign_create_time, '%Y%m%d') <= {date_time}
-    group by advertiser_id
-) sum_cam on t1.account_id = sum_cam.advertiser_id
-         left join
      (select advertiser_id account_id, count(distinct signature) day_num
       from `media_api`.bytedance_file_video_get
       where date_format(create_time, '%Y%m%d') = {date_time}
       group by advertiser_id) t3
      on t1.account_id = t3.account_id
-         left join
-     (select advertiser_id account_id, count(distinct signature) video_num
-      from `media_api`.bytedance_file_video_get
-      where date_format(create_time, '%Y%m%d') <= {date_time}
+         left join(select advertiser_id, count(distinct project_id) as project_num
+                   from media_api.bytedance_cdp_project
+                   where date_format(project_create_time, '%Y%m%d') = {date_time}
+                   group by advertiser_id) pro
+                  on t1.account_id = pro.advertiser_id
 
-      group by advertiser_id) all_video
-     on t1.account_id = all_video.account_id
-         left join
-     (select t2.account_id, count(distinct t1.signature) new_eff_material
-      from (select signature from application.effect_material where effect_date = {date_time}) t1
-               left join
-           (select distinct advertiser_id account_id, signature
-            from `media_api`.bytedance_file_video_get
-            where date_format(create_time, '%Y%m%d') >=
-                  date_sub({date_time}, INTERVAL 29 DAY)) t2
-           on t1.signature = t2.signature
-      group by t2.account_id) t4
-     on t1.account_id = t4.account_id
 
-         left join
-     (select t2.account_id, count(distinct t1.signature) new_eff_material
-      from (select signature from application.effect_material where effect_date <= {date_time}) t1
-               left join
-           (select distinct advertiser_id account_id, signature
-            from `media_api`.bytedance_file_video_get
-            where date_format(create_time, '%Y%m%d') <= {date_time}) t2
-           on t1.signature = t2.signature
-      group by t2.account_id) sum_eff
-     on t1.account_id = sum_eff.account_id
-    left join(
-        select advertiser_id,count(distinct project_id) as project_num from media_api.bytedance_cdp_project
-          where date_format(project_create_time, '%Y%m%d') = {date_time}
-      group by advertiser_id
-    )pro
-    on t1.account_id=pro.advertiser_id
-    
-    
-        left join(
-        select advertiser_id,count(distinct promotion_id) as promotion_num from media_api.bytedance_promotion_list
-          where date_format(promotion_create_time, '%Y%m%d') = {date_time}
-      group by advertiser_id
-    )promotion
-    on t1.account_id=promotion.advertiser_id
+         left join(select advertiser_id, count(distinct promotion_id) as promotion_num
+                   from media_api.bytedance_promotion_list
+                   where date_format(promotion_create_time, '%Y%m%d') = {date_time}
+                   group by advertiser_id) promotion
+                  on t1.account_id = promotion.advertiser_id
 
 
          left join
      (select t2.account_id, count(distinct t1.signature) new_hot_material
-      from (select signature from application.hot_material where hot_date = {date_time} and media_id=1) t1
+      from (select signature from application.hot_material where hot_date = {date_time} and media_id = 1) t1
                left join
            (select distinct advertiser_id account_id, signature
             from `media_api`.bytedance_file_video_get
@@ -177,7 +121,7 @@ from (select * from `jeecg-boot`.ctop_user_allocation where media_id = 1) t1
 
          left join
      (select t2.account_id, count(distinct t1.signature) new_hot_material
-      from (select signature from application.hot_material where  hot_date<= {date_time}) t1
+      from (select signature from application.hot_material where hot_date <= {date_time}) t1
                left join
            (select distinct advertiser_id account_id, signature
             from `media_api`.bytedance_file_video_get
@@ -188,39 +132,37 @@ from (select * from `jeecg-boot`.ctop_user_allocation where media_id = 1) t1
 
 
          left join
-     (
-         SELECT cua.account_id   id,
-                cua.account_id,
-                cp.id            project_id,
-                product.id       product_id,
-                product.product_name,
-                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.realname      user_name,
-                su.leader_id,
-                lea.realname     leader_name,
-                su.org_code      org_code,
-                dep.dep_id       dept_id,
-                part.depart_name dept_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`.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 lea ON lea.id = su.leader_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
-                  LEFT JOIN `jeecg-boot`.sys_user_depart dep ON cua.user_id = dep.user_id
-                  LEFT JOIN `jeecg-boot`.sys_depart part ON dep.dep_id = part.id
-         WHERE cua.account_id IS NOT NULL
-           and cua.account_status = 0
-           and cua.media_id = 1
-     ) bei
+     (SELECT cua.account_id   id,
+             cua.account_id,
+             cp.id            project_id,
+             product.id       product_id,
+             product.product_name,
+             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.realname      user_name,
+             su.leader_id,
+             lea.realname     leader_name,
+             su.org_code      org_code,
+             dep.dep_id       dept_id,
+             part.depart_name dept_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`.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 lea ON lea.id = su.leader_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
+               LEFT JOIN `jeecg-boot`.sys_user_depart dep ON cua.user_id = dep.user_id
+               LEFT JOIN `jeecg-boot`.sys_depart part ON dep.dep_id = part.id
+      WHERE cua.account_id IS NOT NULL
+        and cua.account_status = 0
+        and cua.media_id = 1) bei
      ON t1.account_id = bei.account_id
 where bei.account_id is not null
             """.format(date_time=self.date_time)