| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- from database import MySqlDatabaseHelper
- from sqlalchemy import text
- import pandas as pd
- class MySqlDao:
- _instance = None
-
- def __new__(cls):
- if not cls._instance:
- cls._instance = super(MySqlDao, cls).__new__(cls)
- cls._instance._initialized = False
- return cls._instance
-
- def __init__(self):
- if self._initialized:
- return
-
- self.db_helper = MySqlDatabaseHelper()
-
- self._cust_table_name = "tads_brandcul_retail_cust_label" # 商户信息表
- self._analysis_table_name = "tads_brandcul_analysis_index" # 指标分析表
-
- self.cust_table_dao = self.CustTableDao(self.db_helper, self._cust_table_name)
-
- self._initialized = True
-
- class CustTableDao:
- """商户数据操作类"""
- def __init__(self, db_helper: MySqlDatabaseHelper, tablename):
- self.db_helper = db_helper
- self.tablename = tablename
-
- def load_data(self, features, corp_uuid):
- """读取商户数据"""
- features_column = ",".join(features)
-
- query = f"SELECT {features_column} FROM {self.tablename} WHERE corp_uuid = :corp_uuid"
- params = {"corp_uuid": corp_uuid}
-
- data = self.db_helper.load_data_with_page(query, params)
-
- return data
-
- def get_column_unique_value(self, column, corp_uuid):
- """获取指定列的唯一值列表"""
- query = f"SELECT {column} FROM {self.tablename} WHERE corp_uuid = :corp_uuid"
- params = {"corp_uuid", corp_uuid}
-
- data = self.db_helper.load_data_with_page(query, params)
-
- return data
-
-
-
-
-
- if __name__ == '__main__':
- features = ["cust_code", "cust_name", "busi_place_area_section"]
-
- dao = MySqlDao()
- corp_uuid = "00000000000000000000000011440101"
-
- data = dao.cust_table_dao.get_column_unique_value("busi_place_area_section", corp_uuid)
- print(data)
-
|