ruff
This commit is contained in:
@@ -141,14 +141,14 @@ class PersonInfoManager:
|
||||
"""[新] 根据 platform 和 user_id 获取用户信息字典"""
|
||||
if not platform or not user_id:
|
||||
return None
|
||||
|
||||
|
||||
person_id = PersonInfoManager.get_person_id(platform, user_id)
|
||||
crud = CRUDBase(PersonInfo)
|
||||
record = await crud.get_by(person_id=person_id)
|
||||
|
||||
|
||||
if not record:
|
||||
return None
|
||||
|
||||
|
||||
# 将 SQLAlchemy 模型对象转换为字典
|
||||
return {c.name: getattr(record, c.name) for c in record.__table__.columns}
|
||||
|
||||
@@ -158,13 +158,13 @@ class PersonInfoManager:
|
||||
"""[新] 根据 person_id 获取用户信息字典"""
|
||||
if not person_id:
|
||||
return None
|
||||
|
||||
|
||||
crud = CRUDBase(PersonInfo)
|
||||
record = await crud.get_by(person_id=person_id)
|
||||
|
||||
|
||||
if not record:
|
||||
return None
|
||||
|
||||
|
||||
# 将 SQLAlchemy 模型对象转换为字典
|
||||
return {c.name: getattr(record, c.name) for c in record.__table__.columns}
|
||||
|
||||
@@ -175,12 +175,12 @@ class PersonInfoManager:
|
||||
return None
|
||||
|
||||
crud = CRUDBase(PersonInfo)
|
||||
|
||||
|
||||
# 1. 按 person_name 查询
|
||||
records = await crud.get_multi(person_name=name, limit=1)
|
||||
if records:
|
||||
return records[0].person_id
|
||||
|
||||
|
||||
# 2. 按 nickname 查询
|
||||
records = await crud.get_multi(nickname=name, limit=1)
|
||||
if records:
|
||||
@@ -218,7 +218,7 @@ class PersonInfoManager:
|
||||
updates = {}
|
||||
if nickname and record.nickname != nickname:
|
||||
updates["nickname"] = nickname
|
||||
|
||||
|
||||
if updates:
|
||||
await crud.update(record.id, updates)
|
||||
logger.debug(f"用户 {person_id} 信息已更新: {updates}")
|
||||
@@ -226,7 +226,7 @@ class PersonInfoManager:
|
||||
# 用户不存在,创建新用户
|
||||
logger.info(f"新用户 {platform}:{user_id},将创建记录。")
|
||||
unique_person_name = await PersonInfoManager._generate_unique_person_name(effective_name)
|
||||
|
||||
|
||||
new_person_data = {
|
||||
"person_id": person_id,
|
||||
"platform": platform,
|
||||
@@ -555,7 +555,7 @@ class PersonInfoManager:
|
||||
# 使用CRUD接口获取所有已存在的名称
|
||||
crud = CRUDBase(PersonInfo)
|
||||
all_records = await crud.get_multi(limit=1000) # 限制数量避免性能问题
|
||||
current_name_set = set(record.person_name for record in all_records if record.person_name)
|
||||
current_name_set = {record.person_name for record in all_records if record.person_name}
|
||||
except Exception as e:
|
||||
logger.warning(f"获取现有名称列表失败: {e}")
|
||||
current_name_set = set()
|
||||
|
||||
Reference in New Issue
Block a user