AppKuaishouCompanyUserReportBusi.py 19 KB

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