renyupeng 2 years ago
parent
commit
97af566f16

+ 6 - 5
Apietl/task/AppBytedanceMaterialProjectRalation.py

@@ -25,8 +25,9 @@ class AppBytedanceMaterialProjectRalation:
                 try:
                     sql = """
 replace into application.bytedance_project_material_relation
-select project_id, signature
-from (select advertiser_id, signature
+select project_id, signature, date_format(create_time,'%Y%m%d') from(
+select project_id, signature,create_time,row_number() over (partition by signature order by create_time desc) as rn
+from (select advertiser_id, signature,create_time
       from media_api.bytedance_file_video_get where  advertiser_id ={account_id} 
       and create_time>=date_format(date_sub(now(),interval 3 day),'%Y-%m-%d')
       and signature is not null
@@ -34,9 +35,9 @@ from (select advertiser_id, signature
          left join
      (select account_id, project_id from `jeecg-boot`.ctop_user_allocation where media_id != 2) b
      on a.advertiser_id = b.account_id
-group by project_id, signature
-
-                    """.format(account_id=account_id[0])
+group by project_id, signature)t 
+where rn <=1
+""".format(account_id=account_id[0])
                     print(sql)
                     TidbConn.upsert(conn=self.conn, sql_buff=sql)
                     self.conn.commit()

+ 9 - 7
Apietl/task/AppKuaishouMaterialProjectRelation.py

@@ -18,23 +18,25 @@ class AppKuaishouMaterialProjectRelation:
     def handler(self):
         try:
             sql = """select account_id from media_api.kuaishou_video_list 
-                  where stat_date>=date_format(date_sub(now(),interval 7 day),'%Y-%m-%d')
+                  where stat_date>=date_format(date_sub(now(),interval 3 day),'%Y-%m-%d')
             group by account_id"""
             account_list = TidbConn.quary(self.conn, sql)
             for account_id in account_list:
                 try:
                     sql = """
-                    replace into application.kuaishou_project_material_relation
-select project_id, signature
-from (select account_id, signature
+replace into application.kuaishou_project_material_relation
+select project_id, signature, date_format(stat_date,'%Y%m%d') as create_time from(
+select project_id, signature,stat_date,row_number() over (partition by signature order by stat_date desc) as rn
+from (select account_id, signature,stat_date
       from media_api.kuaishou_video_list where  account_id ={account_id} 
-      and stat_date>=date_format(date_sub(now(),interval 7 day),'%Y-%m-%d')
+      and stat_date>=date_format(date_sub(now(),interval 3 day),'%Y-%m-%d')
       and signature is not null
-      group by account_id, signature) a
+      group by stat_date, signature) a
          left join
      (select account_id, project_id from `jeecg-boot`.ctop_user_allocation where media_id = 2) b
      on a.account_id = b.account_id
-group by project_id, signature
+group by project_id, signature)t
+where rn <=1
                     """.format(account_id=account_id[0])
                     print(sql)
                     TidbConn.upsert(conn=self.conn, sql_buff=sql)

+ 5 - 7
Apietl/task/BytedanceNewMaterialNumInProject.py

@@ -21,13 +21,11 @@ class BytedanceNewMaterialNumInProject:
     def taskHandler(self):
         try:
             sql = """
-            replace into application.new_material_num_in_project
-select media_time as stat_date, 1 as media_id,project_id,count(*) as material_num from (
-select media_time,project_id,signature from application.bytedance_project_material_relation a
-left join application.app_bytedance_material_info b
-on a.signature=b.material_id
-where media_time={date_time})t
-group by media_time,project_id
+                   replace into application.new_material_num_in_project
+select create_time as stat_date, 1 as media_id,project_id,count(*) as material_num from (
+select create_time,project_id,signature from application.bytedance_project_material_relation a
+where create_time={date_time})t
+group by create_time,project_id
             """.format(date_time=self.date_time)
             print(sql)
             TidbConn.upsert(conn=self.conn, sql_buff=sql)

+ 4 - 6
Apietl/task/KuaishouNewMaterialNumInProject.py

@@ -22,12 +22,10 @@ class KuaishouNewMaterialNumInProject:
         try:
             sql = """
             replace into application.new_material_num_in_project
-select media_time, 2 as media_id,project_id,count(*) from (
-select media_time,project_id,signature from application.kuaishou_project_material_relation a
-left join application.app_kuaishou_material_info b
-on a.signature=b.material_id
-where media_time={date_time})t
-group by media_time,project_id
+select create_time as stat_date, 2 as media_id,project_id,count(*) as material_num from (
+select create_time,project_id,signature from application.kuaishou_project_material_relation a
+where create_time={date_time})t
+group by create_time,project_id
             """.format(date_time=self.date_time)
             print(sql)
             TidbConn.upsert(conn=self.conn, sql_buff=sql)