AppKuaishouCompanyDesignReportBusi.py 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519
  1. # Author renyupeng
  2. # coding=utf-8
  3. # @Time : 2021/11/10 3:37 下午
  4. # @Site :
  5. # @File : AppKuaishouCompanyDesignReportBusi.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 AppKuaishouCompanyDesignReportBusi:
  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_kuaishou_company_design_report_busi_{day_count}d
  23. select
  24. new.start_end_time,
  25. ifnull(new.company_id,'-') company_id,
  26. new.company_name,
  27. new.org_code,
  28. new.org_type,
  29. new.dep_id,
  30. new.dep_name,
  31. ifnull(new.leader_id,'-') leader_id,
  32. new.leader_name,
  33. new.material_count,
  34. new.innovate_num,
  35. new.charge,
  36. ifnull(ratio.charge,0) last_charge,
  37. ifnull(round((new.charge-ratio.charge)/ratio.charge*100,3),0) charge_ratio,
  38. new.show ,
  39. new.photo_click,
  40. new.aclick,
  41. new.bclick,
  42. new.photo_click_ratio,
  43. new.play_3s_ratio ,
  44. new.action_ratio,
  45. new.impression_1k_cost,
  46. new.photo_click_cost ,
  47. new.action_cost,
  48. new.share,
  49. new.comment ,
  50. new.like ,
  51. new.follow,
  52. new.cancel_follow ,
  53. new.report,
  54. new.block,
  55. new.negative,
  56. new.submit,
  57. new.download_started ,
  58. new.download_completed,
  59. new.activation ,
  60. new.event_pay_first_day ,
  61. new.event_pay_purchase_amount_first_day,
  62. new.event_pay_first_day_roi,
  63. new.event_pay,
  64. new.event_pay_purchase_amount ,
  65. new.event_pay_roi ,
  66. new.event_register,
  67. new.event_register_cost ,
  68. new.event_register_ratio,
  69. new.event_jin_jian_app,
  70. new.event_jin_jian_app_cost,
  71. new.event_credit_grant_app ,
  72. new.event_credit_grant_app_cost,
  73. new.event_credit_grant_app_ratio ,
  74. new.event_order_paid ,
  75. new.event_order_paid_purchase_amount,
  76. new.event_order_paid_cost,
  77. new.event_next_day_stay ,
  78. new.event_next_day_stay_cost,
  79. new.event_next_day_stay_ratio ,
  80. new.form_count ,
  81. new.form_cost,
  82. new.form_action_ratio,
  83. new.event_jin_jian_landing_page,
  84. new.event_jin_jian_landing_page_cost,
  85. new.event_credit_grant_landing_page ,
  86. new.event_credit_grant_landing_page_cost,
  87. new.event_credit_grant_landing_page_ratio ,
  88. new.event_valid_clues,
  89. new.event_valid_clues_cost ,
  90. new.event_add_wechat ,
  91. new.event_add_wechat_cost,
  92. new.event_add_wechat_ratio ,
  93. new.event_get_through,
  94. new.event_get_through_cost ,
  95. new.event_get_through_ratio,
  96. new.event_app_invoked,
  97. new.event_app_invoked_cost ,
  98. new.event_app_invoked_ratio,
  99. new.event_credit_grant_landing_ratio,
  100. new.play_5s_ratio ,
  101. new.play_end_ratio,
  102. new.event_new_user_pay,
  103. new.event_new_user_pay_cost,
  104. new.event_new_user_pay_ratio,
  105. new.click_1k_cost ,
  106. new.ad_product_cnt,
  107. new.event_goods_view ,
  108. new.merchant_reco_fans,
  109. new.event_order_amount_roi ,
  110. new.event_goods_view_cost,
  111. new.merchant_reco_fans_cost,
  112. new.event_button_click,
  113. new.event_button_click_cost,
  114. new.event_button_click_ratio,
  115. new.event_order_paid_roi,
  116. new.event_new_user_jinjian_app,
  117. new.event_new_user_jinjian_app_cost ,
  118. new.event_new_user_jinjian_app_roi,
  119. new.event_new_user_credit_grant_app ,
  120. new.event_new_user_credit_grant_app_cost,
  121. new.event_new_user_credit_grant_app_roi,
  122. new.event_new_user_jinjian_page,
  123. new.event_new_user_jinjian_page_cost,
  124. new.event_new_user_jinjian_page_roi ,
  125. new.event_new_user_credit_grant_page,
  126. new.event_new_user_credit_grant_page_cost ,
  127. new.event_new_user_credit_grant_page_roi,
  128. new.event_appoint_form,
  129. new.event_appoint_form_cost,
  130. new.event_appoint_form_ratio,
  131. new.event_appoint_jump_click,
  132. new.event_appoint_jump_click_cost,
  133. new.event_appoint_jump_click_ratio,
  134. new.union_event_pay_purchase_amount_7d ,
  135. new.union_event_pay_purchase_amount_7d_roi,
  136. new.event_order_successed,
  137. new.ad_photo_played_10s_ratio ,
  138. new.key_action_cost,
  139. new.event_add_shopping_cart_cost ,
  140. new.event_ad_watch_times_ratio,
  141. new.event_outbound_call_cost,
  142. new.event_outbound_call ,
  143. new.action_new_ratio ,
  144. new.event_watch_app_ad,
  145. new.event_multi_conversion_cost,
  146. new.event_phone_card_activate ,
  147. new.ad_photo_played_75percent_ratio ,
  148. new.key_action_ratio ,
  149. new.event_ad_watch_times_cost ,
  150. new.event_add_shopping_cart,
  151. new.key_action ,
  152. new.event_multi_conversion ,
  153. new.event_wechat_connected ,
  154. new.event_dsp_gift_form ,
  155. new.event_intention_confirmed ,
  156. new.event_phone_get_through,
  157. new.event_multi_conversion_ratio ,
  158. new.event_measurement_house,
  159. new.ad_photo_played_2s_ratio,
  160. new.event_outbound_call_ratio ,
  161. new.event_ad_watch_times
  162. from
  163. (select
  164. concat(date_format(date_sub({date_time}, INTERVAL {day_count}-1 DAY),'%Y%m%d'),'-',{date_time}) start_end_time,
  165. company_id,
  166. company_name,
  167. org_code,
  168. org_type,
  169. id dep_id,
  170. depart_name dep_name,
  171. leader_id,
  172. leader_name,
  173. count(DISTINCT signature) material_count,
  174. count(distinct innovate_code) innovate_num,
  175. sum(charge) charge,
  176. sum(`show`) `show`,
  177. sum(photo_click)photo_click,
  178. sum(aclick) aclick,
  179. sum(bclick) bclick,
  180. round(sum(photo_click)/sum(`show`),3) photo_click_ratio,
  181. round(sum(play_3s_ratio)/{day_count}*100,3) play_3s_ratio,
  182. round(sum(bclick)/sum(aclick)*100,3) action_ratio,
  183. round(sum(impression_1k_cost)/{day_count},3) impression_1k_cost,
  184. round(sum(charge)/sum(photo_click),3) photo_click_cost,
  185. round(sum(charge)/sum(bclick),3) action_cost,
  186. sum(`share`) `share`,
  187. sum(`comment`) `comment`,
  188. sum(`like`) `like`,
  189. sum(follow) follow,
  190. sum(cancel_follow) cancel_follow,
  191. sum(report) report,
  192. sum(block) block,
  193. sum(negative) negative,
  194. sum(submit) submit,
  195. sum(download_started) download_started,
  196. sum(download_completed) download_completed,
  197. sum(activation) activation,
  198. sum(event_pay_first_day) event_pay_first_day,
  199. sum(event_pay_purchase_amount_first_day) event_pay_purchase_amount_first_day,
  200. round(sum(event_pay_purchase_amount_first_day)/sum(charge)*100,3) event_pay_first_day_roi ,
  201. sum(event_pay) event_pay,
  202. sum(event_pay_purchase_amount) event_pay_purchase_amount,
  203. round(sum(event_pay_purchase_amount)/sum(charge)*100,3) event_pay_roi,
  204. sum(event_register) event_register,
  205. round(sum(charge)/sum(event_register),3) event_register_cost,
  206. round(sum(event_register)/sum(activation)*100,3) event_register_ratio,
  207. sum(event_jin_jian_app) event_jin_jian_app,
  208. round(sum(charge)/sum(event_jin_jian_app),3) event_jin_jian_app_cost,
  209. sum(event_credit_grant_app) event_credit_grant_app,
  210. round(sum(charge)/sum(event_credit_grant_app),3) event_credit_grant_app_cost ,
  211. round(sum(event_credit_grant_app_ratio)/{day_count}*100,3) event_credit_grant_app_ratio,
  212. sum(event_order_paid) event_order_paid,
  213. sum(event_order_paid_purchase_amount) event_order_paid_purchase_amount,
  214. round(sum(event_order_paid_purchase_amount)/sum(event_order_paid) ,3) event_order_paid_cost,
  215. sum(event_next_day_stay) event_next_day_stay,
  216. round(sum(charge)/sum(event_next_day_stay),3) event_next_day_stay_cost,
  217. round(sum(event_next_day_stay)/sum(activation)*100,3) event_next_day_stay_ratio,
  218. sum(form_count) form_count,
  219. round(sum(charge)/sum(form_count),3) form_cost,
  220. round(sum(form_count)/sum(`bclick`)*100,3) form_action_ratio,
  221. sum(event_jin_jian_landing_page) event_jin_jian_landing_page,
  222. round(sum(charge)/sum(event_jin_jian_landing_page),3) event_jin_jian_landing_page_cost,
  223. sum(event_credit_grant_landing_page) event_credit_grant_landing_page,
  224. round(sum(charge)/sum(event_credit_grant_landing_page),3) event_credit_grant_landing_page_cost,
  225. round(sum(event_credit_grant_landing_page)/{day_count}*100,3) event_credit_grant_landing_page_ratio,
  226. sum(event_valid_clues) event_valid_clues,
  227. round(sum(charge)/sum(event_valid_clues),3) event_valid_clues_cost,
  228. sum(event_add_wechat) event_add_wechat,
  229. round(sum(charge)/sum(event_add_wechat),3) event_add_wechat_cost,
  230. round(sum(event_add_wechat)/sum(bclick)*100,3) event_add_wechat_ratio,
  231. sum(event_get_through) event_get_through,
  232. round(sum(charge)/sum(event_get_through),3) event_get_through_cost,
  233. round(sum(event_get_through)/sum(bclick)*100,3) event_get_through_ratio,
  234. sum(event_app_invoked) event_app_invoked,
  235. round(sum(charge)/sum(event_app_invoked),3) event_app_invoked_cost ,
  236. round(sum(event_app_invoked)/sum(bclick)*100,3) event_app_invoked_ratio,
  237. round(sum(event_credit_grant_landing_ratio)/{day_count}*100,3) event_credit_grant_landing_ratio,
  238. round(sum(play_5s_ratio)/{day_count}*100,3) play_5s_ratio,
  239. round(sum(play_end_ratio)/{day_count}*100,3) play_end_ratio,
  240. sum(event_new_user_pay) event_new_user_pay,
  241. round(sum(charge)/sum(event_new_user_pay),3) event_new_user_pay_cost,
  242. round(sum(event_new_user_pay)/sum(activation)*100,3) event_new_user_pay_ratio,
  243. round(sum(click_1k_cost)/{day_count}*100) click_1k_cost,
  244. sum(ad_product_cnt) ad_product_cnt,
  245. sum(event_goods_view) event_goods_view,
  246. sum(merchant_reco_fans) merchant_reco_fans,
  247. round(sum(event_order_amount_roi)/{day_count}*100,3) event_order_amount_roi,
  248. round(sum(charge)/sum(event_goods_view) ,3) event_goods_view_cost,
  249. round(sum(charge)/sum(merchant_reco_fans),3) merchant_reco_fans_cost,
  250. sum(event_button_click) event_button_click,
  251. round(sum(charge)/sum(event_button_click),3) event_button_click_cost,
  252. round(sum(event_button_click)/sum(bclick)*100,3) event_button_click_ratio ,
  253. round(sum(event_order_paid_roi)/{day_count}*100,3) event_order_paid_roi,
  254. sum(event_new_user_jinjian_app) event_new_user_jinjian_app,
  255. round(sum(charge)/sum(event_new_user_jinjian_app),3) event_new_user_jinjian_app_cost,
  256. round(sum(event_new_user_jinjian_app)/sum(form_count)*100,3) event_new_user_jinjian_app_roi ,
  257. sum(event_new_user_credit_grant_app) event_new_user_credit_grant_app,
  258. round(sum(charge)/sum(event_new_user_credit_grant_app),3) event_new_user_credit_grant_app_cost,
  259. round(sum(event_new_user_credit_grant_app)/sum(form_count)*100,3) event_new_user_credit_grant_app_roi,
  260. sum(event_new_user_jinjian_page) event_new_user_jinjian_page,
  261. round(sum(charge)/sum(event_new_user_jinjian_page),3) event_new_user_jinjian_page_cost,
  262. round(sum(event_new_user_jinjian_page)/sum(form_count)*100,3) event_new_user_jinjian_page_roi ,
  263. sum(event_new_user_credit_grant_page) event_new_user_credit_grant_page,
  264. round(sum(charge)/sum(event_new_user_credit_grant_page) ,3) event_new_user_credit_grant_page_cost,
  265. round(sum(event_new_user_credit_grant_page)/sum(form_count)*100,3) event_new_user_credit_grant_page_roi,
  266. sum(event_appoint_form) event_appoint_form,
  267. round(sum(charge)/sum(event_appoint_form),3) event_appoint_form_cost,
  268. round(sum(event_appoint_form)/sum(form_count)*100,3) event_appoint_form_ratio,
  269. sum(event_appoint_jump_click) event_appoint_jump_click,
  270. round(sum(charge)/sum(event_appoint_jump_click),3) event_appoint_jump_click_cost,
  271. round(sum(event_appoint_jump_click_cost)/sum(form_count)*100,3) event_appoint_jump_click_ratio,
  272. sum(union_event_pay_purchase_amount_7d) union_event_pay_purchase_amount_7d,
  273. round(sum(union_event_pay_purchase_amount_7d_roi)/{day_count}*100,3) union_event_pay_purchase_amount_7d_roi,
  274. sum(event_order_successed) event_order_successed,
  275. round(sum(ad_photo_played_10s_ratio)/{day_count}*100,3) ad_photo_played_10s_ratio,
  276. round(sum(charge)/sum(key_action),3) key_action_cost,
  277. round(sum(charge)/sum(event_add_shopping_cart) ,3) event_add_shopping_cart_cost ,
  278. round(sum(event_ad_watch_times)/sum(bclick)*100,3) event_ad_watch_times_ratio,
  279. round(sum(charge)/sum(event_outbound_call),3) event_outbound_call_cost,
  280. sum(event_outbound_call) event_outbound_call,
  281. round(sum(action_new_ratio)/{day_count}*100,3) action_new_ratio,
  282. sum(event_watch_app_ad) event_watch_app_ad,
  283. round(sum(charge)/sum(event_multi_conversion) ,3) event_multi_conversion_cost,
  284. sum(event_phone_card_activate) event_phone_card_activate,
  285. round(sum(ad_photo_played_75percent_ratio)/{day_count}*100,3) ad_photo_played_75percent_ratio,
  286. round(sum(key_action)/sum(activation)*100,3) key_action_ratio ,
  287. round(sum(charge)/sum(event_ad_watch_times),3) event_ad_watch_times_cost,
  288. sum(event_add_shopping_cart) event_add_shopping_cart,
  289. sum(key_action) key_action,
  290. sum(event_multi_conversion) event_multi_conversion,
  291. sum(event_wechat_connected) event_wechat_connected,
  292. sum(event_dsp_gift_form) event_dsp_gift_form,
  293. sum(event_intention_confirmed) event_intention_confirmed,
  294. sum(event_phone_get_through) event_phone_get_through,
  295. round(sum(event_multi_conversion)/sum(activation)*100,3) event_multi_conversion_ratio,
  296. sum(event_measurement_house) event_measurement_house,
  297. round(sum(ad_photo_played_2s_ratio)/{day_count}*100,3) ad_photo_played_2s_ratio,
  298. round(sum(event_outbound_call_ratio)/sum(activation)*100,3) event_outbound_call_ratio,
  299. sum(event_ad_watch_times) event_ad_watch_times
  300. from
  301. (SELECT
  302. video.signature,
  303. uc.company_id,
  304. CASE WHEN uc.company_id = 'd57fecdcf7a94d009736d9c850731582' THEN '北京汇创思拓数字科技有限公司'
  305. WHEN uc.company_id = '6608ed13c0dd42de93c790dbdf124234' THEN '广州汇创思拓数字科技有限公司'
  306. WHEN uc.company_id = '4b10089775c040119e139087517aed88' THEN '上海汇创思拓数字科技有限公司'
  307. ELSE
  308. uc.company_name
  309. END company_name,
  310. cma.leader_id,
  311. us.realname leader_name,
  312. ur.org_type,
  313. ur.org_code,
  314. ur.id,
  315. ur.depart_name,
  316. case when cmi.material_innovate=2 then video.signature else '' end innovate_code,
  317. report.charge ,
  318. report.`show`,
  319. report.photo_click,
  320. report.aclick ,
  321. report.bclick ,
  322. report.photo_click_ratio,
  323. report.play_3s_ratio,
  324. report.action_ratio ,
  325. report.impression_1k_cost ,
  326. report.photo_click_cost,
  327. report.action_cost,
  328. report.`share`,
  329. report.`comment`,
  330. report.`like`,
  331. report.follow ,
  332. report.cancel_follow,
  333. report.report ,
  334. report.block,
  335. report.negative,
  336. report.submit ,
  337. report.download_started,
  338. report.download_completed ,
  339. report.activation,
  340. report.event_pay_first_day,
  341. report.event_pay_purchase_amount_first_day,
  342. report.event_pay_first_day_roi,
  343. report.event_pay ,
  344. report.event_pay_purchase_amount,
  345. report.event_pay_roi,
  346. report.event_register,
  347. report.event_register_cost,
  348. report.event_register_ratio,
  349. report.event_jin_jian_app ,
  350. report.event_jin_jian_app_cost,
  351. report.event_credit_grant_app,
  352. report.event_credit_grant_app_cost ,
  353. report.event_credit_grant_app_ratio,
  354. report.event_order_paid,
  355. report.event_order_paid_purchase_amount,
  356. report.event_order_paid_cost ,
  357. report.event_next_day_stay,
  358. report.event_next_day_stay_cost ,
  359. report.event_next_day_stay_ratio,
  360. report.form_count,
  361. report.form_cost ,
  362. report.form_action_ratio,
  363. report.event_jin_jian_landing_page ,
  364. report.event_jin_jian_landing_page_cost,
  365. report.event_credit_grant_landing_page,
  366. report.event_credit_grant_landing_page_cost ,
  367. report.event_credit_grant_landing_page_ratio,
  368. report.event_valid_clues,
  369. report.event_valid_clues_cost,
  370. report.event_add_wechat,
  371. report.event_add_wechat_cost ,
  372. report.event_add_wechat_ratio,
  373. report.event_get_through,
  374. report.event_get_through_cost,
  375. report.event_get_through_ratio,
  376. report.event_app_invoked,
  377. report.event_app_invoked_cost,
  378. report.event_app_invoked_ratio,
  379. report.event_credit_grant_landing_ratio,
  380. report.play_5s_ratio,
  381. report.play_end_ratio,
  382. report.event_new_user_pay ,
  383. report.event_new_user_pay_cost,
  384. report.event_new_user_pay_ratio ,
  385. report.click_1k_cost,
  386. report.ad_product_cnt,
  387. report.event_goods_view,
  388. report.merchant_reco_fans ,
  389. report.event_order_amount_roi,
  390. report.event_goods_view_cost ,
  391. report.merchant_reco_fans_cost,
  392. report.event_button_click ,
  393. report.event_button_click_cost,
  394. report.event_button_click_ratio ,
  395. report.event_order_paid_roi,
  396. report.event_new_user_jinjian_app,
  397. report.event_new_user_jinjian_app_cost,
  398. report.event_new_user_jinjian_app_roi ,
  399. report.event_new_user_credit_grant_app,
  400. report.event_new_user_credit_grant_app_cost ,
  401. report.event_new_user_credit_grant_app_roi,
  402. report.event_new_user_jinjian_page ,
  403. report.event_new_user_jinjian_page_cost,
  404. report.event_new_user_jinjian_page_roi,
  405. report.event_new_user_credit_grant_page,
  406. report.event_new_user_credit_grant_page_cost,
  407. report.event_new_user_credit_grant_page_roi ,
  408. report.event_appoint_form ,
  409. report.event_appoint_form_cost,
  410. report.event_appoint_form_ratio ,
  411. report.event_appoint_jump_click ,
  412. report.event_appoint_jump_click_cost,
  413. report.event_appoint_jump_click_ratio ,
  414. report.union_event_pay_purchase_amount_7d,
  415. report.union_event_pay_purchase_amount_7d_roi,
  416. report.placement_type,
  417. report.ad_scene,
  418. report.event_order_successed ,
  419. report.ad_photo_played_10s_ratio,
  420. report.key_action_cost ,
  421. report.event_add_shopping_cart_cost,
  422. report.event_ad_watch_times_ratio,
  423. report.event_outbound_call_cost ,
  424. report.event_outbound_call,
  425. report.action_new_ratio,
  426. report.event_watch_app_ad ,
  427. report.event_multi_conversion_cost ,
  428. report.event_phone_card_activate,
  429. report.ad_photo_played_75percent_ratio,
  430. report.key_action_ratio,
  431. report.event_ad_watch_times_cost,
  432. report.event_add_shopping_cart,
  433. report.key_action,
  434. report.event_multi_conversion,
  435. report.event_wechat_connected,
  436. report.event_dsp_gift_form,
  437. report.event_intention_confirmed,
  438. report.event_phone_get_through,
  439. report.event_multi_conversion_ratio,
  440. report.event_measurement_house,
  441. report.ad_photo_played_2s_ratio ,
  442. report.event_outbound_call_ratio,
  443. report.event_ad_watch_times
  444. FROM
  445. (select * from media_api.kuaishou_material_video_report_daily
  446. where stat_date between date_format(date_sub({date_time}, INTERVAL {day_count}-1 DAY),'%Y%m%d') and {date_time}) report
  447. LEFT JOIN
  448. (select account_id,signature,photo_id from media_api.kuaishou_video_list group by account_id,signature,photo_id) video
  449. ON report.advertiser_id = video.account_id AND report.photo_id = video.photo_id
  450. LEFT JOIN (
  451. SELECT
  452. CODE,
  453. material_innovate,
  454. cover_url
  455. FROM
  456. `jeecg-boot`.ctop_material_info
  457. GROUP BY
  458. CODE,
  459. material_innovate,
  460. cover_url
  461. ) cmi ON video.signature = cmi. CODE
  462. LEFT JOIN (
  463. SELECT
  464. material_id,
  465. leader_id
  466. FROM
  467. (
  468. SELECT
  469. material_id,
  470. leader_id,
  471. row_number () over (PARTITION BY material_id ORDER BY create_time) rn FROM `jeecg-boot`.ctop_material_ascription) m
  472. WHERE rn = 1) cma ON video.signature = cma.material_id
  473. left join `jeecg-boot`.sys_user us on us.id=cma.leader_id
  474. LEFT JOIN `jeecg-boot`.user_company uc ON cma.leader_id = uc.user_id
  475. LEFT JOIN `jeecg-boot`.sys_user_depart de ON cma.leader_id = de.user_id
  476. LEFT JOIN `jeecg-boot`.sys_depart ur ON de.dep_id = ur.id) def
  477. group by
  478. company_id,
  479. company_name,
  480. org_code,
  481. org_type,
  482. id,
  483. depart_name,
  484. leader_id,
  485. leader_name) new
  486. left join
  487. (select ifnull(cma.leader_id,'-') leader_id,sum(report.charge) charge from
  488. (select advertiser_id account_id,photo_id,sum(charge) charge from media_api.kuaishou_material_video_report_daily
  489. where stat_date 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')
  490. and date_format(date_sub({date_time}, INTERVAL {day_count} DAY),'%Y%m%d') group by advertiser_id,photo_id) report
  491. LEFT JOIN
  492. (select account_id,signature,photo_id from media_api.kuaishou_video_list group by account_id,signature,photo_id) video
  493. ON report.account_id = video.account_id AND report.photo_id=video.photo_id
  494. LEFT JOIN (SELECT material_id,leader_id FROM (SELECT material_id,leader_id,row_number () over (PARTITION BY material_id ORDER BY create_time ) rn
  495. FROM `jeecg-boot`.ctop_material_ascription) m WHERE rn = 1 ) cma ON video.signature = cma.material_id
  496. group by cma.leader_id) ratio
  497. on new.leader_id=ratio.leader_id;
  498. """.format(date_time=self.date_time, day_count=self.day_count)
  499. print(sql)
  500. TidbConn.upsert(conn=self.conn, sql_buff=sql)
  501. self.conn.commit()
  502. TidbConn.conn_close(conn=self.conn)
  503. return 0
  504. except Exception as e:
  505. logging.error(e)
  506. return -1
  507. if __name__ == '__main__':
  508. status = AppKuaishouCompanyDesignReportBusi().taskHandler()
  509. if status == 0:
  510. print("作业执行成功")
  511. exit(0)
  512. else:
  513. print("作业执行失败")
  514. exit(-1)