AppBytedanceCompanyUserReportBusi.py 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  1. # Author renyupeng
  2. # coding=utf-8
  3. # @Time : 2021/11/10 3:37 下午
  4. # @Site :
  5. # @File : AppBytedanceCompanyUserReportBusi.py
  6. # @Software: PyCharm
  7. # @contact: renyupeng@c-top.com.cn
  8. # @Tel 1501435553
  9. import logging
  10. from Apietl.conn.TidbConn import TidbConn
  11. from Apietl.utlis.Utils import Utils
  12. class AppBytedanceCompanyUserReportBusi:
  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. self.day_count = self.parm[1]
  18. def taskHandler(self):
  19. try:
  20. sql = """
  21. SET sql_mode = 'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
  22. REPLACE INTO application.app_bytedance_company_user_report_busi_{day_count}d
  23. SELECT
  24. new.start_end_time ,
  25. new.company_id ,
  26. new.company_name ,
  27. new.org_code ,
  28. new.org_type ,
  29. new.dep_id ,
  30. new.dep_name ,
  31. new.leader_id,
  32. new.leader_name,
  33. new.account_num,
  34. new.cost ,
  35. ifnull(ratio.cost,0) last_cost,
  36. ifnull(round((new.cost-ratio.cost)/ratio.cost*100,3),0) cost_ratio,
  37. new.show ,
  38. new.avg_show_cost,
  39. new.click,
  40. new.avg_click_cost ,
  41. new.ctr,
  42. new.convert,
  43. new.convert_cost ,
  44. new.convert_rate ,
  45. new.deep_convert ,
  46. new.deep_convert_cost,
  47. new.deep_convert_rate,
  48. new.attribution_convert,
  49. new.attribution_convert_cost ,
  50. new.attribution_deep_convert ,
  51. new.attribution_deep_convert_cost,
  52. new.download_start ,
  53. new.download_start_cost,
  54. new.download_start_rate,
  55. new.download_finish,
  56. new.download_finish_cost ,
  57. new.download_finish_rate ,
  58. new.click_install,
  59. new.install_finish ,
  60. new.install_finish_cost,
  61. new.install_finish_rate,
  62. new.active ,
  63. new.active_cost,
  64. new.active_rate,
  65. new.register ,
  66. new.active_register_cost ,
  67. new.active_register_rate ,
  68. new.next_day_open,
  69. new.next_day_open_cost ,
  70. new.next_day_open_rate ,
  71. new.attribution_next_day_open_cnt,
  72. new.attribution_next_day_open_cost ,
  73. new.attribution_next_day_open_rate ,
  74. new.game_addiction ,
  75. new.game_addiction_cost,
  76. new.game_addiction_rate,
  77. new.pay_count,
  78. new.active_pay_cost,
  79. new.active_pay_rate,
  80. new.loan_completion,
  81. new.loan_completion_cost ,
  82. new.loan_completion_rate ,
  83. new.pre_loan_credit,
  84. new.pre_loan_credit_cost ,
  85. new.loan_credit,
  86. new.loan_credit_cost ,
  87. new.loan_credit_rate ,
  88. new.in_app_uv,
  89. new.in_app_detail_uv ,
  90. new.in_app_cart,
  91. new.in_app_pay ,
  92. new.in_app_order ,
  93. new.attribution_game_pay_7d_count,
  94. new.attribution_game_pay_7d_cost ,
  95. new.attribution_active_pay_7d_per_count,
  96. new.game_pay_cost,
  97. new.game_pay_count ,
  98. new.phone,
  99. new.form ,
  100. new.map_search ,
  101. new.button ,
  102. new.view ,
  103. new.download ,
  104. new.qq ,
  105. new.lottery,
  106. new.vote ,
  107. new.message,
  108. new.redirect ,
  109. new.shopping ,
  110. new.consult,
  111. new.wechat ,
  112. new.phone_confirm,
  113. new.phone_connect,
  114. new.consult_effective,
  115. new.coupon ,
  116. new.coupon_single_page ,
  117. new.redirect_to_shop ,
  118. new.poi_collect,
  119. new.poi_address_click,
  120. new.luban_order_cnt,
  121. new.luban_order_stat_amount,
  122. new.luban_order_roi,
  123. new.luban_live_enter_cnt ,
  124. new.live_watch_one_minute_count,
  125. new.luban_live_follow_cnt,
  126. new.live_fans_club_join_cnt,
  127. new.luban_live_comment_cnt ,
  128. new.luban_live_share_cnt ,
  129. new.luban_live_gift_cnt,
  130. new.luban_live_gift_amount ,
  131. new.luban_live_slidecart_click_cnt ,
  132. new.luban_live_click_product_cnt ,
  133. new.luban_live_pay_order_count ,
  134. new.luban_live_pay_order_stat_cost ,
  135. new.live_component_click_count ,
  136. new.live_component_click_cost,
  137. new.live_component_click_rate,
  138. new.wechat_login_count ,
  139. new.attribution_wechat_login_30d_count ,
  140. new.wechat_login_cost,
  141. new.attribution_wechat_login_30d_cost,
  142. new.wechat_first_pay_count ,
  143. new.attribution_wechat_first_pay_30d_count ,
  144. new.wechat_first_pay_cost,
  145. new.attribution_wechat_first_pay_30d_cost,
  146. new.wechat_first_pay_rate,
  147. new.attribution_wechat_first_pay_30d_rate,
  148. new.wechat_pay_amount,
  149. new.attribution_wechat_pay_30d_amount,
  150. new.attribution_wechat_pay_30d_roi ,
  151. new.phone_effective,
  152. new.total_play ,
  153. new.valid_play ,
  154. new.valid_play_cost,
  155. new.valid_play_rate,
  156. new.play_25_feed_break ,
  157. new.play_50_feed_break ,
  158. new.play_75_feed_break ,
  159. new.play_100_feed_break,
  160. new.average_play_time_per_play ,
  161. new.play_over_rate ,
  162. new.wifi_play_rate ,
  163. new.wifi_play,
  164. new.play_duration_sum,
  165. new.advanced_creative_phone_click,
  166. new.advanced_creative_counsel_click,
  167. new.advanced_creative_form_click ,
  168. new.advanced_creative_coupon_addition,
  169. new.advanced_creative_form_submit,
  170. new.card_show,
  171. new.share,
  172. new.comment,
  173. new.like ,
  174. new.follow ,
  175. new.home_visited ,
  176. new.ies_challenge_click,
  177. new.ies_music_click,
  178. new.location_click ,
  179. new.message_action ,
  180. new.click_landing_page ,
  181. new.click_shopwindow ,
  182. new.click_website,
  183. new.click_download ,
  184. new.click_call_dy,
  185. new.submit_certification_count ,
  186. new.approval_count ,
  187. new.first_rental_order_count ,
  188. new.first_order_count,
  189. new.commute_first_pay_count
  190. from (
  191. SELECT
  192. concat(date_format(date_sub({date_time}, INTERVAL ({day_count} -1 ) DAY),'%Y%m%d'),'-',{date_time}) start_end_time,
  193. ifnull(company_id,'-') company_id,
  194. company_name,
  195. org_code,
  196. org_type,
  197. dep_id,
  198. depart_name dep_name,
  199. ifnull(leader_id,'-') leader_id,
  200. trim(leader_name) leader_name,
  201. count(DISTINCT account_id) account_num,
  202. sum(cost) cost,
  203. sum(`show`) `show`,
  204. ifnull(round(sum(cost) / sum(`show`), 3),0) avg_show_cost,
  205. sum(click) click,
  206. ifnull(round(sum(cost) / sum(`click`), 3),0) avg_click_cost,
  207. ifnull(round(sum(click) / sum(`show`) * 100,3),0) ctr,
  208. sum(`convert`) `convert`,
  209. ifnull(round(sum(cost) / sum(`convert`), 3),0) convert_cost,
  210. ifnull(round(sum(`convert`) / sum(click) * 100,3),0) convert_rate,
  211. sum(deep_convert) deep_convert,
  212. ifnull(round(sum(cost) / sum(deep_convert),3),0) deep_convert_cost,
  213. ifnull(round(sum(deep_convert) / sum(`convert`) * 100,3),0) deep_convert_rate,
  214. sum(attribution_convert) attribution_convert,
  215. ifnull(round(sum(cost) / sum(attribution_convert),3),0) attribution_convert_cost,
  216. sum(attribution_deep_convert) attribution_deep_convert,
  217. ifnull(round(sum(cost) / sum(attribution_deep_convert),3),0) attribution_deep_convert_cost,
  218. sum(download_start) download_start,
  219. ifnull(round(sum(cost) / sum(download_start),3),0) download_start_cost,
  220. ifnull(round(sum(download_start) / sum(click),3),0) download_start_rate,
  221. sum(download_finish) download_finish,
  222. ifnull(round(sum(cost) / sum(download_finish),3),0) download_finish_cost,
  223. ifnull(round(sum(download_finish) / sum(download_start) * 100,3),0) download_finish_rate,
  224. sum(click_install) click_install,
  225. sum(install_finish) install_finish,
  226. ifnull(round(sum(cost) / sum(install_finish),3),0) install_finish_cost,
  227. ifnull(round(sum(install_finish) / sum(download_finish) * 100,3),0) install_finish_rate,
  228. sum(active) active,
  229. ifnull(round(sum(cost) / sum(active), 3),0) active_cost,
  230. ifnull(round(sum(active) / sum(click) * 100,3),0) active_rate,
  231. sum(register) register,
  232. ifnull(round(sum(cost) / sum(register), 3),0) active_register_cost,
  233. ifnull(round(sum(active_register_rate)/{day_count} * 100,3),0) active_register_rate,
  234. sum(next_day_open) next_day_open,
  235. ifnull(round(sum(cost) / sum(next_day_open),3),0) next_day_open_cost,
  236. ifnull(round(sum(next_day_open) / sum(active) * 100,3),0) next_day_open_rate,
  237. sum(attribution_next_day_open_cnt) attribution_next_day_open_cnt,
  238. ifnull(round(sum(cost) / sum(attribution_next_day_open_cnt),3),0) attribution_next_day_open_cost,
  239. ifnull(round(sum(attribution_next_day_open_cnt) / sum(active) * 100,3),0) attribution_next_day_open_rate,
  240. sum(game_addiction) game_addiction,
  241. ifnull(round(sum(cost) / sum(game_addiction),3),0) game_addiction_cost,
  242. ifnull(round(sum(game_addiction_rate)/{day_count} * 100,3),0) game_addiction_rate,
  243. sum(pay_count) pay_count,
  244. ifnull(round(sum(cost) / sum(pay_count), 3),0) active_pay_cost,
  245. ifnull(round(sum(pay_count) / sum(active) * 100,3),0) active_pay_rate,
  246. sum(loan_completion) loan_completion,
  247. ifnull(round(sum(cost) / sum(loan_completion),3),0) loan_completion_cost,
  248. ifnull(round(sum(loan_completion) / sum(register) * 100,3),0) loan_completion_rate,
  249. ifnull(round(sum(pre_loan_credit), 3),0) pre_loan_credit,
  250. ifnull(round(sum(cost) / sum(pre_loan_credit),3),0) pre_loan_credit_cost,
  251. sum(loan_credit) loan_credit,
  252. ifnull(round(sum(cost) / sum(loan_credit),3),0) loan_credit_cost,
  253. ifnull(round(sum(loan_credit) / sum(loan_completion) * 100,3),0) loan_credit_rate,
  254. sum(in_app_uv) in_app_uv,
  255. sum(in_app_detail_uv) in_app_detail_uv,
  256. sum(in_app_cart) in_app_cart,
  257. sum(in_app_pay) in_app_pay,
  258. sum(in_app_order) in_app_order,
  259. ifnull(round(sum(attribution_game_pay_7d_count)/{day_count},3),0) attribution_game_pay_7d_count,
  260. ifnull(round(sum(attribution_game_pay_7d_cost)/{day_count},3),0) attribution_game_pay_7d_cost,
  261. ifnull(round(sum(attribution_active_pay_7d_per_count)/{day_count},3),0) attribution_active_pay_7d_per_count,
  262. sum(game_pay_cost) game_pay_cost,
  263. sum(game_pay_count) game_pay_count,
  264. sum(phone) phone,
  265. sum(form) form,
  266. sum(map_search) map_search,
  267. sum(button) button,
  268. sum(`view`) `view`,
  269. sum(download) download,
  270. sum(qq) qq,
  271. sum(lottery) lottery,
  272. sum(vote) vote,
  273. sum(message) message,
  274. sum(redirect) redirect,
  275. sum(shopping) shopping,
  276. sum(consult) consult,
  277. sum(wechat) wechat,
  278. sum(phone_confirm) phone_confirm,
  279. sum(phone_connect) phone_connect,
  280. sum(consult_effective) consult_effective,
  281. sum(coupon) coupon,
  282. sum(coupon_single_page) coupon_single_page,
  283. sum(redirect_to_shop) redirect_to_shop,
  284. sum(poi_collect) poi_collect,
  285. sum(poi_address_click) poi_address_click,
  286. sum(luban_order_cnt) luban_order_cnt,
  287. sum(luban_order_stat_amount) luban_order_stat_amount,
  288. sum(luban_order_roi) luban_order_roi,
  289. sum(luban_live_enter_cnt) luban_live_enter_cnt,
  290. sum(live_watch_one_minute_count) live_watch_one_minute_count,
  291. sum(luban_live_follow_cnt) luban_live_follow_cnt,
  292. sum(live_fans_club_join_cnt) live_fans_club_join_cnt,
  293. sum(luban_live_comment_cnt) luban_live_comment_cnt,
  294. sum(luban_live_share_cnt) luban_live_share_cnt,
  295. sum(luban_live_gift_cnt) luban_live_gift_cnt,
  296. sum(luban_live_gift_amount) luban_live_gift_amount,
  297. sum(luban_live_slidecart_click_cnt) luban_live_slidecart_click_cnt,
  298. sum(luban_live_click_product_cnt) luban_live_click_product_cnt,
  299. sum(luban_live_pay_order_count) luban_live_pay_order_count,
  300. sum(luban_live_pay_order_stat_cost) luban_live_pay_order_stat_cost,
  301. sum(live_component_click_count) live_component_click_count,
  302. ifnull(round(sum(cost) / sum(live_component_click_count),3),0) live_component_click_cost,
  303. ifnull(round(sum(live_component_click_count)/{day_count} * 100,3),0) live_component_click_rate,
  304. sum(wechat_login_count) wechat_login_count,
  305. sum(attribution_wechat_login_30d_count) attribution_wechat_login_30d_count,
  306. ifnull(round(sum(cost) / sum(wechat_login_count),3),0) wechat_login_cost,
  307. ifnull(round(sum(cost) / sum(attribution_wechat_login_30d_count),3),0) attribution_wechat_login_30d_cost,
  308. sum(wechat_first_pay_count) wechat_first_pay_count,
  309. sum(attribution_wechat_first_pay_30d_count) attribution_wechat_first_pay_30d_count,
  310. ifnull(round(sum(cost) / sum(wechat_first_pay_count),3),0) wechat_first_pay_cost,
  311. ifnull(round(sum(cost) / sum(attribution_wechat_first_pay_30d_count),3),0) attribution_wechat_first_pay_30d_cost,
  312. ifnull(round(sum(wechat_first_pay_count) / sum(wechat_login_count) * 100,3),0) wechat_first_pay_rate,
  313. ifnull(round(sum(attribution_wechat_first_pay_30d_count) / sum(attribution_wechat_login_30d_count) * 100,3),0) attribution_wechat_first_pay_30d_rate,
  314. sum(wechat_pay_amount) wechat_pay_amount,
  315. sum(attribution_wechat_pay_30d_amount) attribution_wechat_pay_30d_amount,
  316. sum(attribution_wechat_pay_30d_roi) attribution_wechat_pay_30d_roi,
  317. sum(phone_effective) phone_effective,
  318. sum(total_play) total_play,
  319. sum(valid_play) valid_play,
  320. ifnull(round(sum(cost) / sum(valid_play),3),0) valid_play_cost,
  321. ifnull(round(sum(valid_play) / sum(`show`) * 100,3),0) valid_play_rate,
  322. sum(play_25_feed_break) play_25_feed_break,
  323. sum(play_50_feed_break) play_50_feed_break,
  324. sum(play_75_feed_break) play_75_feed_break,
  325. sum(play_100_feed_break) play_100_feed_break,
  326. ifnull(round(sum(average_play_time_per_play)/{day_count},3),0) average_play_time_per_play,
  327. ifnull(round(sum(play_over_rate)/{day_count} * 100,3),0) play_over_rate,
  328. ifnull(round(sum(wifi_play) / sum(total_play) * 100,3),0) wifi_play_rate,
  329. sum(wifi_play) wifi_play,
  330. ifnull(round(sum(play_duration_sum)/{day_count}, 3),0) play_duration_sum,
  331. sum(advanced_creative_phone_click) advanced_creative_phone_click,
  332. sum(advanced_creative_counsel_click) advanced_creative_counsel_click,
  333. sum(advanced_creative_form_click) advanced_creative_form_click,
  334. sum(advanced_creative_coupon_addition) advanced_creative_coupon_addition,
  335. sum(advanced_creative_form_submit) advanced_creative_form_submit,
  336. sum(card_show) card_show,
  337. sum(`share`) `share`,
  338. sum(`comment`) `comment`,
  339. sum(`like`) `like`,
  340. sum(follow) follow,
  341. sum(home_visited) home_visited,
  342. sum(ies_challenge_click) ies_challenge_click,
  343. sum(ies_music_click) ies_music_click,
  344. sum(location_click) location_click,
  345. sum(message_action) message_action,
  346. sum(click_landing_page) click_landing_page,
  347. sum(click_shopwindow) click_shopwindow,
  348. sum(click_website) click_website,
  349. sum(click_download) click_download,
  350. sum(click_call_dy) click_call_dy,
  351. sum(submit_certification_count) submit_certification_count,
  352. sum(approval_count) approval_count,
  353. sum(first_order_count) first_rental_order_count,
  354. sum(first_rental_order_count) first_order_count,
  355. sum(commute_first_pay_count) commute_first_pay_count
  356. FROM
  357. (
  358. SELECT
  359. report.advertiser_id account_id,
  360. dep.company_id,
  361. CASE
  362. WHEN dep.company_id = 'd57fecdcf7a94d009736d9c850731582' THEN
  363. '北京汇创思拓数字科技有限公司'
  364. WHEN dep.company_id = '6608ed13c0dd42de93c790dbdf124234' THEN
  365. '广州汇创思拓数字科技有限公司'
  366. WHEN dep.company_id = '4b10089775c040119e139087517aed88' THEN
  367. '上海汇创思拓数字科技有限公司'
  368. ELSE
  369. dep.company_name
  370. END company_name,
  371. dep.org_code,
  372. dep.org_type,
  373. dep.dep_id,
  374. dep.depart_name,
  375. dep.user_id,
  376. dep.realname,
  377. dep.leader_id,
  378. dep.leader_name,
  379. report.cost,
  380. report.`show`,
  381. report.avg_show_cost,
  382. report.click,
  383. report.avg_click_cost,
  384. report.ctr,
  385. report.`convert`,
  386. report.convert_cost,
  387. report.convert_rate,
  388. report.deep_convert,
  389. report.deep_convert_cost,
  390. report.deep_convert_rate,
  391. report.attribution_convert,
  392. report.attribution_convert_cost,
  393. report.attribution_deep_convert,
  394. report.attribution_deep_convert_cost,
  395. report.download_start,
  396. report.download_start_cost,
  397. report.download_start_rate,
  398. report.download_finish,
  399. report.download_finish_cost,
  400. report.download_finish_rate,
  401. report.click_install,
  402. report.install_finish,
  403. report.install_finish_cost,
  404. report.install_finish_rate,
  405. report.active,
  406. report.active_cost,
  407. report.active_rate,
  408. report.register,
  409. report.active_register_cost,
  410. report.active_register_rate,
  411. report.next_day_open,
  412. report.next_day_open_cost,
  413. report.next_day_open_rate,
  414. report.attribution_next_day_open_cnt,
  415. report.attribution_next_day_open_cost,
  416. report.attribution_next_day_open_rate,
  417. report.game_addiction,
  418. report.game_addiction_cost,
  419. report.game_addiction_rate,
  420. report.pay_count,
  421. report.active_pay_cost,
  422. report.active_pay_rate,
  423. report.loan_completion,
  424. report.loan_completion_cost,
  425. report.loan_completion_rate,
  426. report.pre_loan_credit,
  427. report.pre_loan_credit_cost,
  428. report.loan_credit,
  429. report.loan_credit_cost,
  430. report.loan_credit_rate,
  431. report.in_app_uv,
  432. report.in_app_detail_uv,
  433. report.in_app_cart,
  434. report.in_app_pay,
  435. report.in_app_order,
  436. report.attribution_game_pay_7d_count,
  437. report.attribution_game_pay_7d_cost,
  438. report.attribution_active_pay_7d_per_count,
  439. report.game_pay_cost,
  440. report.game_pay_count,
  441. report.phone,
  442. report.form,
  443. report.map_search,
  444. report.button,
  445. report.`view`,
  446. report.download,
  447. report.qq,
  448. report.lottery,
  449. report.vote,
  450. report.message,
  451. report.redirect,
  452. report.shopping,
  453. report.consult,
  454. report.wechat,
  455. report.phone_confirm,
  456. report.phone_connect,
  457. report.consult_effective,
  458. report.coupon,
  459. report.coupon_single_page,
  460. report.redirect_to_shop,
  461. report.poi_collect,
  462. report.poi_address_click,
  463. report.luban_order_cnt,
  464. report.luban_order_stat_amount,
  465. report.luban_order_roi,
  466. report.luban_live_enter_cnt,
  467. report.live_watch_one_minute_count,
  468. report.luban_live_follow_cnt,
  469. report.live_fans_club_join_cnt,
  470. report.luban_live_comment_cnt,
  471. report.luban_live_share_cnt,
  472. report.luban_live_gift_cnt,
  473. report.luban_live_gift_amount,
  474. report.luban_live_slidecart_click_cnt,
  475. report.luban_live_click_product_cnt,
  476. report.luban_live_pay_order_count,
  477. report.luban_live_pay_order_stat_cost,
  478. report.live_component_click_count,
  479. report.live_component_click_cost,
  480. report.live_component_click_rate,
  481. report.wechat_login_count,
  482. report.attribution_wechat_login_30d_count,
  483. report.wechat_login_cost,
  484. report.attribution_wechat_login_30d_cost,
  485. report.wechat_first_pay_count,
  486. report.attribution_wechat_first_pay_30d_count,
  487. report.wechat_first_pay_cost,
  488. report.attribution_wechat_first_pay_30d_cost,
  489. report.wechat_first_pay_rate,
  490. report.attribution_wechat_first_pay_30d_rate,
  491. report.wechat_pay_amount,
  492. report.attribution_wechat_pay_30d_amount,
  493. report.attribution_wechat_pay_30d_roi,
  494. report.phone_effective,
  495. report.total_play,
  496. report.valid_play,
  497. report.valid_play_cost,
  498. report.valid_play_rate,
  499. report.play_25_feed_break,
  500. report.play_50_feed_break,
  501. report.play_75_feed_break,
  502. report.play_100_feed_break,
  503. report.average_play_time_per_play,
  504. report.play_over_rate,
  505. report.wifi_play_rate,
  506. report.wifi_play,
  507. report.play_duration_sum,
  508. report.advanced_creative_phone_click,
  509. report.advanced_creative_counsel_click,
  510. report.advanced_creative_form_click,
  511. report.advanced_creative_coupon_addition,
  512. report.advanced_creative_form_submit,
  513. report.card_show,
  514. report.`share`,
  515. report.`comment`,
  516. report.`like`,
  517. report.follow,
  518. report.home_visited,
  519. report.ies_challenge_click,
  520. report.ies_music_click,
  521. report.location_click,
  522. report.message_action,
  523. report.click_landing_page,
  524. report.click_shopwindow,
  525. report.click_website,
  526. report.click_download,
  527. report.click_call_dy,
  528. report.submit_certification_count,
  529. report.approval_count,
  530. report.first_rental_order_count,
  531. report.first_order_count,
  532. report.commute_first_pay_count
  533. FROM
  534. (
  535. SELECT
  536. *
  537. FROM
  538. media_api.bytedance_advertiser_report_daily
  539. WHERE
  540. stat_datetime >= date_format(
  541. date_sub({date_time}, INTERVAL ({day_count} -1 ) DAY),
  542. '%Y%m%d'
  543. )
  544. ) report
  545. LEFT JOIN (
  546. SELECT
  547. cua.account_id,
  548. uc.company_id,
  549. uc.company_name,
  550. pa.org_code,
  551. pa.org_type,
  552. pa.id dep_id,
  553. pa.depart_name,
  554. cua.user_id,
  555. su.realname ,
  556. cp.sale_id,
  557. su.leader_id,
  558. se.realname as leader_name
  559. FROM
  560. `jeecg-boot`.ctop_user_allocation cua
  561. LEFT JOIN `jeecg-boot`.ctop_project cp ON cua.project_id = cp.id
  562. LEFT JOIN `jeecg-boot`.user_company uc ON uc.user_id = cua.user_id
  563. LEFT JOIN `jeecg-boot`.sys_user su ON su.id = cua.user_id
  564. LEFT JOIN `jeecg-boot`.sys_user se ON se.id = su.leader_id
  565. LEFT JOIN `jeecg-boot`.sys_user_depart de ON su.leader_id = de.user_id
  566. LEFT JOIN `jeecg-boot`.sys_depart pa ON pa.id = de.dep_id
  567. ) dep ON report.advertiser_id = dep.account_id
  568. ) info
  569. GROUP BY
  570. company_id,
  571. leader_id) new
  572. LEFT JOIN
  573. (select ifnull(su.leader_id,'-') leader_id,sum(report.cost) cost from
  574. (select advertiser_id account_id,sum(cost) cost from media_api.bytedance_advertiser_report_daily
  575. where stat_datetime between date_format(date_sub(date_format(date_sub({date_time}, INTERVAL {day_count} DAY),'%Y%m%d'), INTERVAL {day_count}-1 DAY),'%Y%m%d')
  576. and date_format(date_sub({date_time}, INTERVAL {day_count} DAY),'%Y%m%d')
  577. group by advertiser_id) report
  578. LEFT JOIN `jeecg-boot`.ctop_user_allocation cua
  579. ON report.account_id = cua.account_id
  580. LEFT JOIN `jeecg-boot`.sys_user su
  581. ON su.id = cua.user_id
  582. group by su.leader_id) ratio
  583. ON new.leader_id=ratio.leader_id ;
  584. """.format(date_time=self.date_time, day_count=self.day_count)
  585. TidbConn.upsert(conn=self.conn, sql_buff=sql)
  586. self.conn.commit()
  587. TidbConn.conn_close(conn=self.conn)
  588. return 0
  589. except Exception as e:
  590. logging.error(e)
  591. return -1
  592. if __name__ == '__main__':
  593. status = AppBytedanceCompanyUserReportBusi().taskHandler()
  594. if status == 0:
  595. print("作业执行成功")
  596. exit(0)
  597. else:
  598. print("作业执行失败")
  599. exit(-1)