AppBytedanceAgentReport.py 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. # Author zhaohailiang
  2. # coding=utf-8
  3. # @Time : 2021/12/20 2:22 下午
  4. # @Site :
  5. # @File : AppBytedanceAgentReport.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 AppBytedanceAgentReport:
  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_bytedance_agent_report_d
  22. (account_id, stat_datetime, project_id, product_id, advertiser_id, company_id, account_name, project_name,
  23. advertiser_name, company_name, sale_id, user_id, org_code, agent_id, agent_name, second_industry, first_industry,
  24. account_source, audit_pass_time, account_status, account_company_id, account_company_name, register_time, cost,
  25. cash_cost, bid_cost, brand_cost, grants_cost, cpc_cost, cpm_cost, ocpc_cost, cpa_cost, ocpm_cost, cpv_cost, cpt_cost,
  26. gd_cost, `show`, cpm, click, ctr, cpc, transfer_count, today_cost, transfer_amount, history_cost, register_days,
  27. first_cost_time)
  28. select report.advertiser_id as account_id,
  29. report.stat_datetime,
  30. project_id,
  31. product_id,
  32. bei.advertiser_id,
  33. bei.company_id,
  34. account_name,
  35. project_name,
  36. bei.advertiser_name,
  37. bei.company_name,
  38. sale_id,
  39. user_id,
  40. org_code,
  41. agent_id,
  42. agent_name,
  43. second_industry,
  44. first_industry,
  45. account_source,
  46. audit_pass_time,
  47. account_status,
  48. report.company_id as account_company_id,
  49. report.company_name as account_company_name,
  50. register_time,
  51. cost,
  52. cash_cost,
  53. bid_cost,
  54. brand_cost,
  55. grants_cost,
  56. cpc_cost,
  57. cpm_cost,
  58. ocpc_cost,
  59. cpa_cost,
  60. ocpm_cost,
  61. cpv_cost,
  62. cpt_cost,
  63. gd_cost,
  64. `show`,
  65. cpm,
  66. click,
  67. ctr,
  68. cpc,
  69. transfer_count,
  70. today_cost,
  71. transfer_amount,
  72. history_cost,
  73. register_days,
  74. first_cost_time
  75. from media_api.bytedance_agent_report_daily report
  76. LEFT JOIN (
  77. SELECT cua.account_id id,
  78. cua.account_id account_id,
  79. cp.id project_id,
  80. product.id product_id,
  81. ca.id advertiser_id,
  82. uc.company_id company_id,
  83. cua.auth_name account_name,
  84. cp.project_name project_name,
  85. ca.`name` advertiser_name,
  86. uc.company_name company_name,
  87. cp.sale_id sale_id,
  88. sale.realname sale_name,
  89. su.id user_id,
  90. su.realname user_name,
  91. su.leader_id,
  92. lea.realname leader_name,
  93. su.org_code org_code
  94. FROM `jeecg-boot`.ctop_user_allocation cua
  95. LEFT JOIN `jeecg-boot`.ctop_project cp ON cua.project_id = cp.id
  96. LEFT JOIN `jeecg-boot`.ctop_advertiser ca ON ca.id = cua.advertiser_id
  97. LEFT JOIN `jeecg-boot`.sys_user su ON su.id = cua.user_id
  98. LEFT JOIN `jeecg-boot`.sys_user sale ON sale.id = cp.sale_id
  99. LEFT JOIN `jeecg-boot`.sys_user lea ON lea.id = su.leader_id
  100. LEFT JOIN `jeecg-boot`.user_company uc ON uc.user_id = cua.user_id
  101. LEFT JOIN `jeecg-boot`.ctop_product product ON product.id = cp.product_id
  102. WHERE cua.account_id IS NOT NULL) bei
  103. on report.advertiser_id = bei.account_id
  104. where report.stat_datetime={date_time}
  105. """.format(date_time=self.date_time)
  106. print(sql)
  107. TidbConn.upsert(conn=self.conn, sql_buff=sql)
  108. self.conn.commit()
  109. TidbConn.conn_close(conn=self.conn)
  110. return 0
  111. except Exception as e:
  112. logging.error(e)
  113. return -1
  114. if __name__ == '__main__':
  115. status = AppBytedanceAgentReport().taskHandler()
  116. if status == 0:
  117. print("作业执行成功")
  118. exit(0)
  119. else:
  120. print("作业执行失败")