sync_to_ck_task.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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].replace(' ','')
  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. if __name__ == '__main__':
  56. # order_sync_ck('2020-11-03')
  57. # dw_order_channel_cost_sync_ck(dt.get_n_days(-2))
  58. # for i in dt.getDateLists('2019-03-18','2020-12-17'):
  59. # # order(i)
  60. # dw_order_channel_sync_ck(i)
  61. print(ck.getColumns(f"dw_daily_channel_cost"))