|
@@ -14,6 +14,7 @@ import pymysql.cursors
|
|
|
import configs
|
|
|
from database import MySQLManager
|
|
|
|
|
|
+
|
|
|
class UserManager(abc.ABC):
|
|
|
@abc.abstractmethod
|
|
|
def get_user_profile(self, user_id) -> Dict:
|
|
@@ -62,6 +63,9 @@ class UserManager(abc.ABC):
|
|
|
default_profile[key] = value
|
|
|
return default_profile
|
|
|
|
|
|
+ def list_users(self, **kwargs) -> List[Dict]:
|
|
|
+ pass
|
|
|
+
|
|
|
class UserRelationManager(abc.ABC):
|
|
|
@abc.abstractmethod
|
|
|
def list_staffs(self):
|
|
@@ -108,6 +112,8 @@ class LocalUserManager(UserManager):
|
|
|
def get_staff_profile(self, staff_id) -> Dict:
|
|
|
return {}
|
|
|
|
|
|
+ def list_users(self, **kwargs) -> List[Dict]:
|
|
|
+ pass
|
|
|
|
|
|
class MySQLUserManager(UserManager):
|
|
|
def __init__(self, db_config, table_name, staff_table):
|
|
@@ -169,6 +175,19 @@ class MySQLUserManager(UserManager):
|
|
|
profile['agent_gender'] = gender_map[profile['agent_gender']]
|
|
|
return profile
|
|
|
|
|
|
+ def list_users(self, **kwargs) -> List[Dict]:
|
|
|
+ user_union_id = kwargs.get('user_union_id', None)
|
|
|
+ user_name = kwargs.get('user_name', None)
|
|
|
+ if not user_union_id and not user_name:
|
|
|
+ raise Exception("user_union_id or user_name is required")
|
|
|
+ sql = f"SELECT third_party_user_id, wxid, name, iconurl, gender FROM {self.table_name} WHERE 1=1 "
|
|
|
+ if user_name:
|
|
|
+ sql += f"AND name = '{user_name}' COLLATE utf8mb4_bin "
|
|
|
+ if user_union_id:
|
|
|
+ sql += f"AND wxid = '{user_union_id}' "
|
|
|
+ data = self.db.select(sql, pymysql.cursors.DictCursor)
|
|
|
+ return data
|
|
|
+
|
|
|
|
|
|
class MySQLUserRelationManager(UserRelationManager):
|
|
|
def __init__(self, agent_db_config, wecom_db_config,
|
|
@@ -184,7 +203,9 @@ class MySQLUserRelationManager(UserRelationManager):
|
|
|
self.user_table = user_table
|
|
|
|
|
|
def list_staffs(self):
|
|
|
- return []
|
|
|
+ sql = f"SELECT third_party_user_id, name, wxid, agent_name FROM {self.agent_staff_table} WHERE status = 1"
|
|
|
+ data = self.agent_db.select(sql, pymysql.cursors.DictCursor)
|
|
|
+ return data
|
|
|
|
|
|
def list_users(self, staff_id: str, page: int = 1, page_size: int = 100):
|
|
|
return []
|