EtlFirstDeliveryValidMaterials.py 3.0 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 utils.mysql_utils import MysqlUtils
  12. class EtlFirstDeliveryValidMaterials:
  13. def __init__(self):
  14. self.stat_date = (datetime.date.today() + datetime.timedelta(0)).strftime("%Y%m%d")
  15. def handler(self):
  16. try:
  17. sql = """
  18. replace into `jeecg-boot`.`etl_first_delivery_valid_materials`
  19. select `delivery_month`,
  20. `operation_label`,
  21. a.`material_id`,
  22. e.signature,
  23. `shot_leader_id`,
  24. `shot_leader_name`,
  25. f.`shot_id`,
  26. f.`plan_id`,
  27. f.`leader_id`,
  28. f.`clip_name`,
  29. f.`shot_name`,
  30. f.`plan_name`,
  31. f.`leader_name`,
  32. c.id as `project_id`,
  33. c.project_name,
  34. c.responsible_id project_leader_id,
  35. d.realname as project_leader_name,
  36. `stat_date`,
  37. `customer_name`,
  38. `rebate_type`,
  39. `settlement_1l`,
  40. `settlement_2l`,
  41. `first_valid`,
  42. `cost_7day`,
  43. `cost`,
  44. date_format(stat_date,'%Y') as `delivery_year`,
  45. c.design_responsible_id as project_design_leader_id,
  46. h.realname as project_design_leader_name,
  47. f.clip_id as clip_id
  48. from `jeecg-boot`.first_delivery_valid_materials a
  49. left join `jeecg-boot`.ctop_user_allocation b
  50. on a.account_id = b.account_id
  51. left join `jeecg-boot`.ctop_project c
  52. on b.project_id = c.id
  53. left join `jeecg-boot`.sys_user d
  54. on c.responsible_id = d.id
  55. left join application.bytedance_video_get e
  56. on a.material_id = e.material_id
  57. left join application.app_bytedance_material_info f
  58. on e.signature = f.material_id
  59. left join `jeecg-boot`.ctop_material_ascription g
  60. on e.signature = g.material_id
  61. left join `jeecg-boot`.sys_user h
  62. on c.design_responsible_id = h.id
  63. where c.id is not null
  64. group by a.delivery_month, a.material_id, signature, b.project_id, settlement_2l, delivery_year
  65. """.format(stat_date=self.stat_date)
  66. print(sql)
  67. MysqlUtils().Operate(sql=sql)
  68. truncate_sql = "truncate table `jeecg-boot`.first_delivery_valid_materials"
  69. MysqlUtils().Operate(sql=truncate_sql)
  70. return 0
  71. except Exception as e:
  72. logging.error(e)
  73. return -1
  74. if __name__ == '__main__':
  75. EtlFirstDeliveryValidMaterials().handler()