dao.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. from dao import Mysql
  2. def load_order_data_from_mysql(city_uuid):
  3. """从数据库中读取订单数据"""
  4. client = Mysql()
  5. tablename = "tads_brandcul_cust_order"
  6. query_text = "*"
  7. city_uuid = "00000000000000000000000011441801"
  8. df = client.load_data(tablename, query_text, "city_uuid", city_uuid)
  9. # df = client.load_mock_data(tablename, query_text)
  10. if len(df) == 0:
  11. return None
  12. df.drop('stat_month', axis=1, inplace=True)
  13. df.drop('city_uuid', axis=1, inplace=True)
  14. # 去除重复值和填补缺失值
  15. df.drop_duplicates(inplace=True)
  16. df.fillna(0, inplace=True)
  17. return df
  18. def load_cust_data_from_mysql(city_uuid):
  19. """从数据库中读取商户信息数据"""
  20. client = Mysql()
  21. tablename = "tads_brandcul_cust_info"
  22. query_text = "*"
  23. df = client.load_data(tablename, query_text, "BA_CITY_ORG_CODE", city_uuid)
  24. if len(df) == 0:
  25. return None
  26. return df
  27. def load_product_data_from_mysql(city_uuid):
  28. """从数据库中读取商品信息"""
  29. client = Mysql()
  30. tablename = "tads_brandcul_product_info"
  31. query_text = "*"
  32. df = client.load_data(tablename, query_text, "city_uuid", city_uuid)
  33. if len(df) == 0:
  34. return None
  35. return df
  36. def get_product_by_id(city_uuid, product_id):
  37. client = Mysql()
  38. res = client.get_product_by_id(city_uuid, product_id)
  39. if len(res) == 0:
  40. return None
  41. return res
  42. def get_custs_by_ids(city_uuid, cust_ids):
  43. client = Mysql()
  44. res = client.get_cust_by_ids(city_uuid, cust_ids)
  45. if len(res) == 0:
  46. return None
  47. return res
  48. if __name__ == '__main__':
  49. data = load_order_data_from_mysql("00000000000000000000000011445301")
  50. print(data)