From 3d68f997800b39ed4b202dcb99cab47c14cb058a Mon Sep 17 00:00:00 2001 From: STDquantum <405720329@qq.com> Date: Wed, 13 Dec 2023 14:41:07 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A5MsgSvrID=E4=BD=9C=E4=B8=BA=E5=88=A4?= =?UTF-8?q?=E6=96=AD=E6=B6=88=E6=81=AF=E5=94=AF=E4=B8=80=E6=80=A7=E7=9A=84?= =?UTF-8?q?key=EF=BC=8C=E5=BD=BB=E5=BA=95=E8=A7=A3=E5=86=B3=E6=B6=88?= =?UTF-8?q?=E6=81=AF=E9=87=8D=E5=A4=8D=E5=87=BA=E7=8E=B0=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/DataBase/msg.py | 62 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 47 insertions(+), 15 deletions(-) diff --git a/app/DataBase/msg.py b/app/DataBase/msg.py index a3c525b..a3edea3 100644 --- a/app/DataBase/msg.py +++ b/app/DataBase/msg.py @@ -63,6 +63,7 @@ class Msg: select localId,TalkerId,Type,SubType,IsSender,CreateTime,Status,StrContent,strftime('%Y-%m-%d %H:%M:%S',CreateTime,'unixepoch','localtime') as StrTime,MsgSvrID,BytesExtra,CompressContent from MSG where StrTalker=? + group by MsgSvrID order by CreateTime ''' try: @@ -78,6 +79,7 @@ class Msg: sql = ''' select localId,TalkerId,Type,SubType,IsSender,CreateTime,Status,StrContent,strftime('%Y-%m-%d %H:%M:%S',CreateTime,'unixepoch','localtime') as StrTime,MsgSvrID,BytesExtra,StrTalker,Reserved1,CompressContent from MSG + group by MsgSvrID order by CreateTime ''' if not self.open_flag: @@ -94,6 +96,7 @@ class Msg: def get_messages_length(self): sql = ''' select count(*) + group by MsgSvrID from MSG ''' if not self.open_flag: @@ -113,6 +116,7 @@ class Msg: select localId,TalkerId,Type,SubType,IsSender,CreateTime,Status,StrContent,strftime('%Y-%m-%d %H:%M:%S',CreateTime,'unixepoch','localtime') as StrTime,MsgSvrID,BytesExtra,CompressContent from MSG where StrTalker = ? and localId < ? + group by MsgSvrID order by CreateTime desc limit 20 ''' @@ -138,6 +142,7 @@ class Msg: select localId,TalkerId,Type,SubType,IsSender,CreateTime,Status,StrContent,strftime('%Y-%m-%d %H:%M:%S',CreateTime,'unixepoch','localtime') as StrTime,MsgSvrID,BytesExtra,CompressContent from MSG where StrTalker=? and Type=? and strftime('%Y',CreateTime,'unixepoch','localtime') = ? + group by MsgSvrID order by CreateTime ''' else: @@ -145,6 +150,7 @@ class Msg: select localId,TalkerId,Type,SubType,IsSender,CreateTime,Status,StrContent,strftime('%Y-%m-%d %H:%M:%S',CreateTime,'unixepoch','localtime') as StrTime,MsgSvrID,BytesExtra,CompressContent from MSG where StrTalker=? and Type=? + group by MsgSvrID order by CreateTime ''' try: @@ -165,6 +171,7 @@ class Msg: select localId,TalkerId,Type,SubType,IsSender,CreateTime,Status,StrContent,strftime('%Y-%m-%d %H:%M:%S',CreateTime,'unixepoch','localtime') as StrTime,MsgSvrID,BytesExtra from MSG where StrTalker=? and Type=1 and LENGTH(StrContent) ? and StrTalker=? and Type=1 and IsSender=? + group by MsgSvrID limit 1 ''' self.cursor.execute(sql, [local_id, username_, 1 - is_send]) @@ -205,15 +213,23 @@ class Msg: if is_Annual_report_: sql = ''' SELECT strftime('%Y-%m-%d',CreateTime,'unixepoch','localtime') as days,count(MsgSvrID) - from MSG - where StrTalker = ? and strftime('%Y',CreateTime,'unixepoch','localtime') = ? + from ( + SELECT MsgSvrID, CreateTime + FROM MSG + WHERE StrTalker = ? AND strftime('%Y', CreateTime, 'unixepoch', 'localtime') = ? + GROUP BY MsgSvrID + ) group by days ''' else: sql = ''' SELECT strftime('%Y-%m-%d',CreateTime,'unixepoch','localtime') as days,count(MsgSvrID) - from MSG - where StrTalker = ? + from ( + SELECT MsgSvrID, CreateTime + FROM MSG + WHERE StrTalker = ? + GROUP BY MsgSvrID + ) group by days ''' result = None @@ -233,16 +249,24 @@ class Msg: def get_messages_by_month(self, username_, is_Annual_report_=False, year_='2023'): if is_Annual_report_: sql = ''' - SELECT strftime('%Y-%m',CreateTime,'unixepoch','localtime') as days,count(MsgSvrID) - from MSG - where StrTalker = ? and strftime('%Y',CreateTime,'unixepoch','localtime') = ? - group by days + SELECT strftime('%Y-%m',CreateTime,'unixepoch','localtime') as days,count(MsgSvrID) + from ( + SELECT MsgSvrID, CreateTime + FROM MSG + WHERE StrTalker = ? AND strftime('%Y', CreateTime, 'unixepoch', 'localtime') = ? + GROUP BY MsgSvrID + ) + group by days ''' else: sql = ''' SELECT strftime('%Y-%m',CreateTime,'unixepoch','localtime') as days,count(MsgSvrID) - from MSG - where StrTalker = ? + from ( + SELECT MsgSvrID, CreateTime + FROM MSG + WHERE StrTalker = ? + GROUP BY MsgSvrID + ) group by days ''' result = None @@ -265,16 +289,24 @@ class Msg: def get_messages_by_hour(self, username_, is_Annual_report_=False, year_='2023'): if is_Annual_report_: sql = ''' - SELECT strftime('%H:00',CreateTime,'unixepoch','localtime') as hours,count(MsgSvrID) - from MSG + SELECT strftime('%H:00',CreateTime,'unixepoch','localtime') as hours,count(MsgSvrID) + from ( + SELECT MsgSvrID, CreateTime + FROM MSG where StrTalker = ? and strftime('%Y',CreateTime,'unixepoch','localtime') = ? - group by hours + GROUP BY MsgSvrID + ) + group by hours ''' else: sql = ''' SELECT strftime('%H:00',CreateTime,'unixepoch','localtime') as hours,count(MsgSvrID) - from MSG - where StrTalker = ? + from ( + SELECT MsgSvrID, CreateTime + FROM MSG + where StrTalker = ? + GROUP BY MsgSvrID + ) group by hours ''' result = None