sync_to_ck_task.py 2.4 KB

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