|
@@ -1,6 +1,7 @@
|
|
|
from database import MySqlDatabaseHelper
|
|
from database import MySqlDatabaseHelper
|
|
|
-from sqlalchemy import text
|
|
|
|
|
-import pandas as pd
|
|
|
|
|
|
|
+import json
|
|
|
|
|
+from database import CustConfig
|
|
|
|
|
+import numpy as np
|
|
|
|
|
|
|
|
class MySqlDao:
|
|
class MySqlDao:
|
|
|
_instance = None
|
|
_instance = None
|
|
@@ -44,22 +45,49 @@ class MySqlDao:
|
|
|
def get_column_unique_value(self, column, corp_uuid):
|
|
def get_column_unique_value(self, column, corp_uuid):
|
|
|
"""获取指定列的唯一值列表"""
|
|
"""获取指定列的唯一值列表"""
|
|
|
query = f"SELECT {column} FROM {self.tablename} WHERE corp_uuid = :corp_uuid"
|
|
query = f"SELECT {column} FROM {self.tablename} WHERE corp_uuid = :corp_uuid"
|
|
|
- params = {"corp_uuid", corp_uuid}
|
|
|
|
|
|
|
+ params = {"corp_uuid": corp_uuid}
|
|
|
|
|
|
|
|
data = self.db_helper.load_data_with_page(query, params)
|
|
data = self.db_helper.load_data_with_page(query, params)
|
|
|
|
|
+ data = data[column].unique()
|
|
|
|
|
+
|
|
|
|
|
+ # 将numpy array转换为Python列表,并确保所有元素都是Python原生类型
|
|
|
|
|
+ if data is not None:
|
|
|
|
|
+ # 处理numpy数据类型
|
|
|
|
|
+ data = data.tolist()
|
|
|
|
|
+ # 如果有numpy标量,转换为Python类型
|
|
|
|
|
+ data = [self._convert_to_python_type(item) for item in data]
|
|
|
|
|
|
|
|
return data
|
|
return data
|
|
|
|
|
+
|
|
|
|
|
+ def _convert_to_python_type(self, item):
|
|
|
|
|
+ """将numpy/pandas类型转换为Python原生类型"""
|
|
|
|
|
+ if isinstance(item, (np.integer, np.floating)):
|
|
|
|
|
+ return item.item()
|
|
|
|
|
+ elif isinstance(item, np.bool_):
|
|
|
|
|
+ return bool(item)
|
|
|
|
|
+ elif isinstance(item, np.ndarray):
|
|
|
|
|
+ return item.tolist()
|
|
|
|
|
+ else:
|
|
|
|
|
+ return item
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
if __name__ == '__main__':
|
|
|
- features = ["cust_code", "cust_name", "busi_place_area_section"]
|
|
|
|
|
|
|
+ features = ["busi_place_area_section"]
|
|
|
|
|
|
|
|
dao = MySqlDao()
|
|
dao = MySqlDao()
|
|
|
corp_uuid = "00000000000000000000000011440101"
|
|
corp_uuid = "00000000000000000000000011440101"
|
|
|
|
|
|
|
|
- data = dao.cust_table_dao.get_column_unique_value("busi_place_area_section", corp_uuid)
|
|
|
|
|
- print(data)
|
|
|
|
|
|
|
+ features = CustConfig.FEATURES_COLUMNS
|
|
|
|
|
+ features_countent = {}
|
|
|
|
|
+ for feature in features:
|
|
|
|
|
+ features_countent[feature] = dao.cust_table_dao.get_column_unique_value(feature, corp_uuid)
|
|
|
|
|
+
|
|
|
|
|
+ json_str = json.dumps(features_countent, indent=4, ensure_ascii=False)
|
|
|
|
|
+
|
|
|
|
|
+ print(json_str)
|
|
|
|
|
+ with open('./cust_features_map.json', 'w', encoding='utf-8') as file:
|
|
|
|
|
+ file.write(json_str)
|
|
|
|
|
|