AppBytedanceCompanyDesignReportBusi.py 28 KB

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