sync_to_ck_task.py 2.5 KB

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