sync_to_ck_task.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. from model.DataBaseUtils import MysqlUtils,CkUtils
  2. from model.DateUtils import DateUtils
  3. from model.log import logger
  4. log=logger()
  5. db = MysqlUtils()
  6. ck = CkUtils()
  7. dt = DateUtils()
  8. def order_sync_ck(ymd):
  9. log.debug("sync order")
  10. col = "date,stage,platform,channel,channel_id,user_id,order_time,reg_time,amount,from_novel,order_id"
  11. sql ="select * from ods_order where date='{}'".format(ymd)
  12. data = db.quchen_text.getData(sql)
  13. data1 = []
  14. for x in data:
  15. li = list(x)
  16. li[0]=str(li[0])
  17. li[3]='' if li[3]==None else li[3]
  18. li[5]='' if li[5]==None else li[5]
  19. li[6]=str(li[6])
  20. li[7]='0000-00-00 00:00:00' if li[7]==None else str(li[7])
  21. li[9]='' if li[9]==None else li[9]
  22. data1.append(tuple(li))
  23. # 删除分区
  24. ck.execute("alter table order drop partition '{}' ".format(ymd))
  25. ck.insertMany("order", col, tuple(data1))
  26. # 广告计划
  27. def daily_vx_campaign(ymd):
  28. table = 'daily_vx_campaign'
  29. sql = 'select * from ' + table + ' where date="{} 00:00:00" '.format(ymd)
  30. data = db.quchen_text.getData(sql)
  31. data1 = []
  32. for i in data:
  33. li = list(i)
  34. li[1] = str(li[1])
  35. li[5] = round(li[5], 4)
  36. li[6] = round(li[6], 4)
  37. li[7] = round(li[7], 4)
  38. li[8] = round(li[8], 4)
  39. li[12] = round(li[12], 4)
  40. li[13] = round(li[13], 4)
  41. li[15] = round(li[15], 4)
  42. data1.append(tuple(li))
  43. col = db.quchen_text.getColumn("daily_vx_campaign")
  44. ck.execute("alter table order drop partition '{}' ".format(ymd))
  45. ck.insertMany(table, col, tuple(data1))
  46. def adcreative():
  47. """todo:表需要重新设计 无法分区"""
  48. pass
  49. def campaign_vx():
  50. """todo:表需要重新设计 无法分区"""
  51. # table="campaign_vx"
  52. # sql="select * from {}".format(table)
  53. # data=db.quchen_text.getData(sql)
  54. pass
  55. def dw_order_channel_cost_sync_ck(ymd):
  56. table='dw_daily_channel_cost'
  57. sql = f"select * from {table} where dt='{ymd}'"
  58. col=ck.getColumns(f"{table}")
  59. data = db.quchen_text.get_data_list(sql)
  60. data1=[]
  61. for i in data:
  62. i[0]=str(i[0])
  63. i[9]=str(i[9])
  64. data1.append(tuple(i))
  65. ck.execute(f"alter table {table} drop partition '{ymd}' ")
  66. ck.insertMany(f"{table}", col, tuple(data1))
  67. if __name__ == '__main__':
  68. order_sync_ck('2020-12-23')
  69. # dw_order_channel_cost_sync_ck(dt.get_n_days(-2))
  70. # for i in dt.getDateLists('2019-03-18','2020-12-17'):
  71. # # order(i)
  72. # dw_order_channel_sync_ck(i)