dao.py 2.1 KB

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