dao.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. from dao import Mysql
  2. def load_order_data_from_mysql(city_uuid):
  3. """从数据库中读取订单数据"""
  4. client = Mysql()
  5. tablename = "yunfu_mock_data"
  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. df = df.infer_objects(copy=False)
  18. return df
  19. def load_cust_data_from_mysql(city_uuid):
  20. """从数据库中读取商户信息数据"""
  21. client = Mysql()
  22. tablename = "tads_brandcul_cust_info"
  23. query_text = "*"
  24. df = client.load_data(tablename, query_text, "BA_CITY_ORG_CODE", city_uuid)
  25. if len(df) == 0:
  26. return None
  27. return df
  28. def get_cust_list_from_database(city_uuid):
  29. client = Mysql()
  30. tablename = "tads_brandcul_cust_info"
  31. query_text = "*"
  32. df = client.load_data(tablename, query_text, "BA_CITY_ORG_CODE", city_uuid)
  33. cust_list = df["BB_RETAIL_CUSTOMER_CODE"].to_list()
  34. if len(cust_list) == 0:
  35. return []
  36. return cust_list
  37. def load_product_data_from_mysql(city_uuid):
  38. """从数据库中读取商品信息"""
  39. client = Mysql()
  40. tablename = "tads_brandcul_product_info"
  41. query_text = "*"
  42. df = client.load_data(tablename, query_text, "city_uuid", city_uuid)
  43. if len(df) == 0:
  44. return None
  45. return df
  46. def get_product_by_id(city_uuid, product_id):
  47. client = Mysql()
  48. res = client.get_product_by_id(city_uuid, product_id)
  49. if len(res) == 0:
  50. return None
  51. return res
  52. def get_custs_by_ids(city_uuid, cust_ids):
  53. client = Mysql()
  54. res = client.get_cust_by_ids(city_uuid, cust_ids)
  55. if len(res) == 0:
  56. return None
  57. return res
  58. if __name__ == '__main__':
  59. data = load_order_data_from_mysql("00000000000000000000000011445301")
  60. print(data)