AppBytedanceVideoReportBusiMonth.py 32 KB

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