sync_to_ck_task.py 2.5 KB

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