新增潜水排行
This commit is contained in:
@@ -712,3 +712,30 @@ class ContactsDBOperator(BaseDBOperator):
|
||||
except Exception as e:
|
||||
self.LOG.error(f"更新群{chatroom_id}成员{wxid}活跃时间失败: {e}")
|
||||
return False
|
||||
|
||||
def get_inactive_members_rank(self, chatroom_id: str, days: int = 60, limit: int = 10) -> List[Dict]:
|
||||
try:
|
||||
sql = """
|
||||
SELECT
|
||||
wxid,
|
||||
COALESCE(NULLIF(display_name,''), nick_name, wxid) AS nick_name,
|
||||
latest_active_time,
|
||||
CASE
|
||||
WHEN latest_active_time IS NULL THEN 999999
|
||||
ELSE TIMESTAMPDIFF(DAY, latest_active_time, NOW())
|
||||
END AS inactivity_days
|
||||
FROM t_chatroom_member
|
||||
WHERE chatroom_id = %s
|
||||
AND (latest_active_time IS NULL OR latest_active_time <= DATE_SUB(NOW(), INTERVAL %s DAY))
|
||||
ORDER BY inactivity_days DESC
|
||||
LIMIT %s
|
||||
"""
|
||||
results = self.execute_query(sql, (chatroom_id, days, limit))
|
||||
for row in results:
|
||||
dt = row.get("latest_active_time")
|
||||
if isinstance(dt, datetime):
|
||||
row["latest_active_time"] = dt.strftime("%Y-%m-%d %H:%M:%S")
|
||||
return results
|
||||
except Exception as e:
|
||||
self.LOG.error(f"获取群{chatroom_id}潜水排行失败: {e}")
|
||||
return []
|
||||
|
||||
Reference in New Issue
Block a user