AppKuaiShouAgentReport.py 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. # Author zhaohailiang
  2. # coding=utf-8
  3. # @Time : 2021/12/20 2:22 下午
  4. # @Site :
  5. # @File : AppKuaishouAgentReport.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 AppKuaishouAgentReport:
  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. SET sql_mode = 'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
  21. replace into `application`.`app_kuaishou_agent_report_d`
  22. (
  23. account_id,
  24. agent_id,
  25. kuaishou_id,
  26. stat_date,
  27. project_id,
  28. product_id,
  29. advertiser_id,
  30. company_id,
  31. account_name,
  32. project_name,
  33. advertiser_name,
  34. company_name,
  35. sale_id,
  36. sale_name,
  37. user_id,
  38. user_name,
  39. leader_id,
  40. leader_name,
  41. org_code,
  42. total_charged_in_yuan,
  43. total_balance_in_yuan,
  44. real_charged_in_yuan,
  45. total_rebate_real_charged_in_yuan,
  46. contract_rebate_real_charged_in_yuan,
  47. direct_rebate_real_charged_in_yuan,
  48. credit_real_charged_in_yuan,
  49. charge_day_on_day_percent,
  50. ad_photo_impression,
  51. ad_photo_click,
  52. ad_item_impression,
  53. ad_item_click,
  54. photo_click_ratio,
  55. item_click_ratio,
  56. charged_campaign_count,
  57. product_name,
  58. corporation_name,
  59. first_cost_day,
  60. industry,
  61. second_industry,
  62. union_event_pay_purchase_amount_7d,
  63. union_event_pay_purchase_amount_7d_roi
  64. )
  65. select
  66. report.advertiser_id account_id,
  67. report.agent_id,
  68. report.user_id kuaishou_id,
  69. report.stat_date,
  70. bei.project_id,
  71. bei.product_id,
  72. bei.advertiser_id,
  73. bei.company_id,
  74. report.account_name,
  75. bei.project_name,
  76. bei.advertiser_name,
  77. bei.company_name,
  78. bei.sale_id,
  79. bei.sale_name,
  80. bei.user_id,
  81. bei.user_name,
  82. bei.leader_id,
  83. bei.leader_name,
  84. bei.org_code,
  85. report.total_charged_in_yuan,
  86. report.total_balance_in_yuan,
  87. report.real_charged_in_yuan,
  88. report.total_rebate_real_charged_in_yuan,
  89. report.contract_rebate_real_charged_in_yuan,
  90. report.direct_rebate_real_charged_in_yuan,
  91. report.credit_real_charged_in_yuan,
  92. report.charge_day_on_day_percent,
  93. report.ad_photo_impression,
  94. report.ad_photo_click,
  95. report.ad_item_impression,
  96. report.ad_item_click,
  97. report.photo_click_ratio,
  98. report.item_click_ratio,
  99. report.charged_campaign_count,
  100. report.product_name,
  101. report.corporation_name,
  102. report.first_cost_day,
  103. report.industry,
  104. report.second_industry,
  105. report.union_event_pay_purchase_amount_7d,
  106. report.union_event_pay_purchase_amount_7d_roi
  107. from (select * from media_api.kuaishou_agent_report_daily where stat_date={date_time}) report
  108. LEFT JOIN (
  109. SELECT
  110. cua.account_id id,
  111. cua.account_id account_id,
  112. cp.id project_id,
  113. product.id product_id,
  114. ca.id advertiser_id,
  115. uc.company_id company_id,
  116. cua.auth_name account_name,
  117. cp.project_name project_name,
  118. ca.`name` advertiser_name,
  119. uc.company_name company_name,
  120. cp.sale_id sale_id,
  121. sale.realname sale_name,
  122. su.id user_id,
  123. su.realname user_name,
  124. su.leader_id,
  125. lea.realname leader_name,
  126. su.org_code org_code
  127. FROM
  128. `jeecg-boot`.ctop_user_allocation cua
  129. LEFT JOIN `jeecg-boot`.ctop_project cp ON cua.project_id = cp.id
  130. LEFT JOIN `jeecg-boot`.ctop_advertiser ca ON ca.id = cua.advertiser_id
  131. LEFT JOIN `jeecg-boot`.sys_user su ON su.id = cua.user_id
  132. LEFT JOIN `jeecg-boot`.sys_user sale ON sale.id = cp.sale_id
  133. LEFT JOIN `jeecg-boot`.sys_user lea ON lea.id = su.leader_id
  134. LEFT JOIN `jeecg-boot`.user_company uc ON uc.user_id = cua.user_id
  135. LEFT JOIN `jeecg-boot`.ctop_product product ON product.id = cp.product_id
  136. WHERE
  137. cua.account_id IS NOT NULL) bei
  138. ON report.advertiser_id = bei.account_id;
  139. """.format(date_time=self.date_time)
  140. print(sql)
  141. TidbConn.upsert(conn=self.conn, sql_buff=sql)
  142. self.conn.commit()
  143. TidbConn.conn_close(conn=self.conn)
  144. return 0
  145. except Exception as e:
  146. logging.error(e)
  147. return -1
  148. if __name__ == '__main__':
  149. status = AppKuaishouAgentReport().taskHandler()
  150. if status == 0:
  151. print("作业执行成功")
  152. exit(0)
  153. else:
  154. print("作业执行失败")