AppKuaishouAccountBaseInfoDsD.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. # Author zhaohailiang
  2. # coding=utf-8
  3. # @Time : 2022/01/19 21:10 下午
  4. # @Site :
  5. # @File : AppKuaishouAccountBaseInfoDsD.py
  6. # @Software: PyCharm
  7. # @contact: zhaohailiang@c-top.com.cn
  8. # @Tel 18201631162
  9. import logging
  10. from Apietl.conn.TidbConn import TidbConn
  11. from Apietl.utlis.Utils import Utils
  12. class AppKuaishouAccountBaseInfoDsD:
  13. def __init__(self):
  14. self.conn = TidbConn.get_connection()
  15. self.parm = Utils.get_task_args()
  16. self.date_time = self.parm[0]
  17. def taskHandler(self):
  18. try:
  19. sql = """
  20. replace into `application`.`app_kuaishou_account_base_info_d`
  21. (
  22. stat_date,
  23. account_id,
  24. account_name,
  25. project_id,
  26. project_name,
  27. product_id,
  28. product_name,
  29. user_id,
  30. user_name,
  31. leader_id,
  32. leader_name,
  33. company_id,
  34. company_name,
  35. dept_id,
  36. dept_name,
  37. all_campaign_num,
  38. new_campaign_num,
  39. all_unit_num,
  40. new_unit_num,
  41. all_video_num,
  42. new_video_num,
  43. effect_num,
  44. new_effect_num,
  45. hot_num,
  46. new_hot_num,
  47. put_campaign_num,
  48. put_unit_num,
  49. trust_campaign_num,
  50. trust_unit_num
  51. )
  52. select * from (
  53. select
  54. {date_time} stat_date,
  55. t1.account_id,
  56. bei.account_name,
  57. bei.project_id,
  58. bei.project_name,
  59. bei.product_id,
  60. bei.product_name,
  61. bei.user_id,
  62. bei.user_name,
  63. bei.leader_id,
  64. bei.leader_name,
  65. bei.company_id,
  66. bei.company_name,
  67. bei.dept_id,
  68. bei.dept_name,
  69. t2.cam_num as all_campaign_num ,
  70. t2.cam_num new_campaign_num,
  71. t2.unit_num as all_ad_num,
  72. t2.unit_num new_ad_num,
  73. t3.day_num as all_video_num,
  74. t3.day_num new_video_num,
  75. 0 as effect_num,
  76. 0 as new_effect_num,
  77. 0 as hot_num,
  78. 0 as new_hot_num,
  79. 0 put_campaign_num,
  80. 0 put_unit_num,
  81. trush_cam_num,
  82. trush_unit_num
  83. from
  84. (select account_id from `jeecg-boot`.ctop_user_allocation where media_id=2)t1
  85. left join
  86. (select advertiser_id account_id,count(distinct campaign_id) cam_num ,count(unit_id) unit_num from `media_api`.kuaishou_ad_unit_list where date_format(create_time,'%Y%m%d')={date_time}
  87. and (unit_source!=1 or unit_source is null)
  88. group by advertiser_id) t2
  89. on t1.account_id=t2.account_id
  90. left join
  91. (select account_id,count(distinct signature) day_num from `media_api`.kuaishou_video_list
  92. where date_format(stat_date,'%Y%m%d')={date_time} group by account_id) t3
  93. on t1.account_id=t3.account_id
  94. left join
  95. (
  96. select advertiser_id account_id,count(unit_id) trush_unit_num, count(distinct campaign_id) trush_cam_num from `media_api`.kuaishou_ad_unit_list where date_format(create_time,'%Y%m%d')={date_time}
  97. and unit_source=1
  98. group by advertiser_id
  99. )trush
  100. on t1.account_id=trush.account_id
  101. left join
  102. (
  103. SELECT
  104. cua.account_id id,
  105. cua.account_id,
  106. cp.id project_id,
  107. product.id product_id,
  108. product.product_name,
  109. ca.id advertiser_id,
  110. uc.company_id company_id,
  111. cua.auth_name account_name,
  112. cp.project_name project_name,
  113. ca.`name` advertiser_name,
  114. uc.company_name company_name,
  115. cp.sale_id sale_id,
  116. su.id user_id,
  117. su.realname user_name,
  118. su.leader_id,
  119. lea.realname leader_name,
  120. su.org_code org_code,
  121. dep.dep_id dept_id,
  122. part.depart_name dept_name
  123. FROM
  124. `jeecg-boot`.ctop_user_allocation cua
  125. LEFT JOIN `jeecg-boot`.ctop_project cp ON cua.project_id = cp.id
  126. LEFT JOIN `jeecg-boot`.ctop_advertiser ca ON ca.id = cua.advertiser_id
  127. LEFT JOIN `jeecg-boot`.sys_user su ON su.id = cua.user_id
  128. LEFT JOIN `jeecg-boot`.sys_user lea ON lea.id = su.leader_id
  129. LEFT JOIN `jeecg-boot`.user_company uc ON uc.user_id = cua.user_id
  130. LEFT JOIN `jeecg-boot`.ctop_product product ON product.id = cp.product_id
  131. LEFT JOIN `jeecg-boot`.sys_user_depart dep ON cua.user_id=dep.user_id
  132. LEFT JOIN `jeecg-boot`.sys_depart part ON dep.dep_id=part.id
  133. WHERE
  134. cua.account_id IS NOT NULL and cua.account_status=0 and cua.media_id=2
  135. ) bei
  136. ON t1.account_id = bei.account_id where bei.account_id is not null) m
  137. group by account_id;
  138. """.format(date_time=self.date_time)
  139. print(sql)
  140. TidbConn.upsert(conn=self.conn, sql_buff=sql)
  141. self.conn.commit()
  142. TidbConn.conn_close(conn=self.conn)
  143. return 0
  144. except Exception as e:
  145. logging.error(e)
  146. return -1
  147. if __name__ == '__main__':
  148. status = AppKuaishouAccountBaseInfoDsD().taskHandler()
  149. if status == 0:
  150. print("作业执行成功")
  151. exit(0)
  152. else:
  153. print("作业执行失败")
  154. exit(-1)