|
@@ -26,6 +26,11 @@ class UserManager(abc.ABC):
|
|
|
def list_all_users(self):
|
|
|
pass
|
|
|
|
|
|
+ @abc.abstractmethod
|
|
|
+ def get_staff_profile(self, staff_id) -> Dict:
|
|
|
+ #FIXME(zhoutian): 重新设计用户和员工数据管理模型
|
|
|
+ pass
|
|
|
+
|
|
|
@staticmethod
|
|
|
def get_default_profile(**kwargs) -> Dict:
|
|
|
default_profile = {
|
|
@@ -94,11 +99,16 @@ class LocalUserManager(UserManager):
|
|
|
user_ids.append(os.path.splitext(file)[0])
|
|
|
return user_ids
|
|
|
|
|
|
+ def get_staff_profile(self, staff_id) -> Dict:
|
|
|
+ return {}
|
|
|
+
|
|
|
+
|
|
|
|
|
|
class MySQLUserManager(UserManager):
|
|
|
- def __init__(self, db_config, table_name):
|
|
|
+ def __init__(self, db_config, table_name, staff_table):
|
|
|
self.db = MySQLManager(db_config)
|
|
|
self.table_name = table_name
|
|
|
+ self.staff_table = staff_table
|
|
|
|
|
|
def get_user_profile(self, user_id) -> Dict:
|
|
|
sql = f"SELECT name, wxid, profile_data_v1 FROM {self.table_name} WHERE third_party_user_id = {user_id}"
|
|
@@ -126,6 +136,18 @@ class MySQLUserManager(UserManager):
|
|
|
data = self.db.select(sql, pymysql.cursors.DictCursor)
|
|
|
return [user['third_party_user_id'] for user in data]
|
|
|
|
|
|
+ def get_staff_profile(self, staff_id) -> Dict:
|
|
|
+ if not self.staff_table:
|
|
|
+ raise Exception("staff_table is not set")
|
|
|
+ sql = f"SELECT agent_name, agent_age, agent_region " \
|
|
|
+ f"FROM {self.staff_table} WHERE third_party_user_id = '{staff_id}'"
|
|
|
+ data = self.db.select(sql, pymysql.cursors.DictCursor)
|
|
|
+ if not data:
|
|
|
+ logging.error(f"staff[{staff_id}] not found")
|
|
|
+ return {}
|
|
|
+ profile = data[0]
|
|
|
+ return profile
|
|
|
+
|
|
|
|
|
|
class MySQLUserRelationManager(UserRelationManager):
|
|
|
def __init__(self, agent_db_config, wecom_db_config,
|
|
@@ -199,7 +221,8 @@ class MySQLUserRelationManager(UserRelationManager):
|
|
|
if __name__ == '__main__':
|
|
|
config = configs.get()
|
|
|
user_db_config = config['storage']['user']
|
|
|
- user_manager = MySQLUserManager(user_db_config['mysql'], user_db_config['table'])
|
|
|
+ staff_db_config = config['storage']['staff']
|
|
|
+ user_manager = MySQLUserManager(user_db_config['mysql'], user_db_config['table'], staff_db_config['table'])
|
|
|
user_profile = user_manager.get_user_profile('7881301263964433')
|
|
|
print(user_profile)
|
|
|
|