report_push.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. class ReportPush(object):
  2. """
  3. 报表推送功能实现类
  4. """
  5. pass
  6. # 数据一,周数据概览
  7. sql_1 = """
  8. 待定
  9. """
  10. # 1.默认值/001_大麦/项目排行榜/小程序排行榜TOP_N
  11. sql_2_1 = """
  12. SELECT
  13. a.*,
  14. b.house_name,
  15. c.interested_num,
  16. d.wx_num,
  17. e.new_cust_num
  18. FROM
  19. (
  20. SELECT
  21. house_id,
  22. count(
  23. DISTINCT ifnull(user_id, idfa)
  24. ) uv,
  25. sum(session_times) session_times,
  26. sum(sum_session_time) sum_session_time,
  27. sum(pv) pv,
  28. sum(page_num) page_num
  29. FROM
  30. a_idfa_behavior_sum
  31. WHERE
  32. report_d >= '2020-03-01'
  33. AND report_d < '2020-03-05'
  34. GROUP BY
  35. house_id
  36. ) a
  37. JOIN d_house b ON a.house_id = b.house_id
  38. LEFT JOIN (
  39. SELECT
  40. house_id,
  41. count(*) interested_num
  42. FROM
  43. f_interested_custlist
  44. WHERE
  45. report_d >= '2020-03-01'
  46. AND report_d <'2020-03-05'
  47. GROUP BY
  48. house_id
  49. ) c ON a.house_id = c.house_id
  50. LEFT JOIN (
  51. SELECT
  52. house_id,
  53. count(*) wx_num
  54. FROM
  55. f_customer_dynamic
  56. WHERE
  57. dynamic = 1
  58. AND report_d >= '2020-03-01'
  59. AND report_d <= '2020-03-05'
  60. GROUP BY
  61. house_id
  62. ) d ON a.house_id = d.house_id
  63. LEFT JOIN (
  64. SELECT
  65. house_id,
  66. count(*) new_cust_num
  67. FROM
  68. d_user
  69. WHERE
  70. created >= '2020-03-01'
  71. AND created < '2020-03-05' # 时间需要加一天!!!!
  72. GROUP BY
  73. house_id
  74. ) e ON a.house_id = e.house_id
  75. """
  76. # 2.默认值/006_大麦(集团)/集团项目排行榜v1.3/集团排行榜
  77. sql_2_2 = """
  78. 待定
  79. """
  80. # 默认值/001_大麦/场景_用户来源渠道/用户来源渠道—明细
  81. sql_3_1 = """
  82. SELECT
  83. *
  84. FROM
  85. d_user_attr a
  86. LEFT JOIN d_scene b ON a.scene = b. CODE
  87. WHERE
  88. a.source IN (1, 2, 3, 4, 10)
  89. AND a.report_d >= '2020-03-01'
  90. AND a.report_d <= '2020-03-04'
  91. """
  92. # 默认值/006_大麦(集团)/场景(集团)_用户来源渠道_v1.1/用户来源渠道—明细
  93. sql_3_2 = """
  94. SELECT
  95. a.scene,
  96. a.brand_id,
  97. b.*, a.share_brand_customer_id,
  98. '2' adviser_agent,
  99. a.house_id house_id,
  100. c.house_name house_name,
  101. c.brand_name
  102. FROM
  103. (
  104. SELECT
  105. scene,
  106. brand_id,
  107. share_brand_customer_id,
  108. house_id
  109. FROM
  110. d_brand_app_customer
  111. WHERE
  112. created >='2020-03-01'
  113. AND created < DATE_ADD(
  114. '2020-03-04', INTERVAL 1 DAY
  115. )
  116. UNION ALL
  117. SELECT
  118. scene,
  119. brand_id,
  120. share_brand_customer_id,
  121. brand_id house_id
  122. FROM
  123. d_brand_app_customer
  124. WHERE
  125. created >= '2020-03-01'
  126. AND created < DATE_ADD(
  127. '2020-03-04', INTERVAL 1 DAY
  128. )
  129. ) a
  130. LEFT JOIN d_scene b ON a.scene = b. CODE
  131. JOIN d_house c ON a.house_id = c.house_id
  132. AND a.brand_id = c.brand_id
  133. """