EtlFirstDeliveryValidMaterials.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. # Author renyupeng
  2. # coding=utf-8
  3. # @Time : 2022/3/24 9:53 上午
  4. # @Site :
  5. # @File : EtlFirstDeliveryValidMaterials.py
  6. # @Software: PyCharm
  7. # @contact: renyupeng@c-top.com.cn
  8. # @Tel 1501435553
  9. import datetime
  10. import logging
  11. from Apietl.conn.TidbConn import TidbConn
  12. class EtlFirstDeliveryValidMaterials:
  13. def __init__(self):
  14. self.conn = TidbConn.get_connection()
  15. self.stat_date = (datetime.date.today() + datetime.timedelta(0)).strftime("%Y%m%d")
  16. def handler(self):
  17. try:
  18. sql = """truncate table `jeecg-boot`.`first_delivery_valid_materials`"""
  19. TidbConn.exec_sql(self.conn, sql)
  20. sql = """
  21. replace into `jeecg-boot`.`etl_first_delivery_valid_materials`
  22. select `delivery_month`,
  23. `operation_label`,
  24. a.`material_id`,
  25. e.signature,
  26. `shot_leader_id`,
  27. `shot_leader_name`,
  28. f.`shot_id`,
  29. f.`plan_id`,
  30. f.`leader_id`,
  31. f.`clip_name`,
  32. f.`shot_name`,
  33. f.`plan_name`,
  34. f.`leader_name`,
  35. c.id as `project_id`,
  36. c.project_name,
  37. c.responsible_id project_leader_id,
  38. d.realname as project_leader_name,
  39. `stat_date`,
  40. `customer_name`,
  41. `rebate_type`,
  42. `settlement_1l`,
  43. `settlement_2l`,
  44. `first_valid`,
  45. `cost_7day`,
  46. `cost`,
  47. date_format(stat_date,'%Y') as `delivery_year`,
  48. c.design_responsible_id as project_design_leader_id,
  49. h.realname as project_design_leader_name,
  50. f.clip_id as clip_id
  51. from `jeecg-boot`.first_delivery_valid_materials a
  52. left join `jeecg-boot`.ctop_user_allocation b
  53. on a.account_id = b.account_id
  54. left join `jeecg-boot`.ctop_project c
  55. on b.project_id = c.id
  56. left join `jeecg-boot`.sys_user d
  57. on c.responsible_id = d.id
  58. left join application.bytedance_video_get e
  59. on a.material_id = e.material_id
  60. left join application.app_bytedance_material_info f
  61. on e.signature = f.material_id
  62. left join `jeecg-boot`.ctop_material_ascription g
  63. on e.signature = g.material_id
  64. left join `jeecg-boot`.sys_user h
  65. on c.design_responsible_id = h.id
  66. where c.id is not null
  67. group by a.delivery_month, a.material_id, signature, b.project_id, settlement_2l, delivery_year
  68. """.format(stat_date=self.stat_date)
  69. print(sql)
  70. TidbConn.upsert(conn=self.conn, sql_buff=sql)
  71. self.conn.commit()
  72. TidbConn.conn_close(conn=self.conn)
  73. return 0
  74. except Exception as e:
  75. logging.error(e)
  76. return -1