修复消息统计

This commit is contained in:
HibiKier 2023-03-01 23:24:56 +08:00
parent 83c3f44ae7
commit edc68921c9
2 changed files with 14 additions and 13 deletions

View File

@ -43,10 +43,13 @@ class ChatHistory(Model):
:param order: 排序类型descdes :param order: 排序类型descdes
:param date_scope: 日期范围 :param date_scope: 日期范围
""" """
o = "-" if order == "DESC" else ""
query = cls.filter(group_id=gid)
if date_scope:
query = query.filter(create_time__range=date_scope)
return list( return list(
await cls.filter(group_id=gid, create_time__range=date_scope) await query.annotate(count=Count("user_qq"))
.annotate(count=Count("user_qq")) .order_by(o + "count")
.order_by(order)
.group_by("user_qq") .group_by("user_qq")
.limit(limit) .limit(limit)
.values_list("user_qq", "count") .values_list("user_qq", "count")
@ -107,9 +110,8 @@ class ChatHistory(Model):
@classmethod @classmethod
async def _run_script(cls): async def _run_script(cls):
await cls.raw("alter table chat_history alter group_id drop not null;") return [
"""允许 group_id 为空""" "alter table chat_history alter group_id drop not null;", # 允许 group_id 为空
await cls.raw("alter table chat_history alter text drop not null;") "alter table chat_history alter text drop not null;", # 允许 text 为空
"""允许 text 为空""" "alter table chat_history alter plain_text drop not null;", # 允许 plain_text 为空
await cls.raw("alter table chat_history alter plain_text drop not null;") ]
"""允许 plain_text 为空"""

View File

@ -105,7 +105,6 @@ class GroupInfoUser(Model):
@classmethod @classmethod
async def _run_script(cls): async def _run_script(cls):
await cls.raw( return [
"alter table group_info_users alter user_join_time drop not null;" "alter table group_info_users alter user_join_time drop not null;" # 允许 user_join_time 为空
) ]
"""允许 user_join_time 为空"""