From 99a8eaea9133ce590638aaf6df7c6e65b4ddbddd Mon Sep 17 00:00:00 2001 From: wenxu12345 <44203734@qq.com> Date: Wed, 19 Jan 2022 18:02:57 +0800 Subject: [PATCH] Refactor code --- .../db/mysql_model/im_mysql_model/friend_request_model.go | 8 ++++++++ .../db/mysql_model/im_mysql_model/group_request_model.go | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/pkg/common/db/mysql_model/im_mysql_model/friend_request_model.go b/pkg/common/db/mysql_model/im_mysql_model/friend_request_model.go index 2591426a2..0aeb2967e 100644 --- a/pkg/common/db/mysql_model/im_mysql_model/friend_request_model.go +++ b/pkg/common/db/mysql_model/im_mysql_model/friend_request_model.go @@ -76,6 +76,14 @@ func InsertFriendApplication(friendRequest *db.FriendRequest) error { if err != nil { return err } + + friendRequest.CreateTime = time.Now() + u := dbConn.Table("friend_requests").Where("from_user_id=? and to_user_id=?", + friendRequest.FromUserID, friendRequest.ToUserID).Update(&friendRequest) + if u.RowsAffected != 0 { + return nil + } + if friendRequest.CreateTime.Unix() < 0 { friendRequest.CreateTime = time.Now() } diff --git a/pkg/common/db/mysql_model/im_mysql_model/group_request_model.go b/pkg/common/db/mysql_model/im_mysql_model/group_request_model.go index 84988a3f4..a4e3ab37f 100644 --- a/pkg/common/db/mysql_model/im_mysql_model/group_request_model.go +++ b/pkg/common/db/mysql_model/im_mysql_model/group_request_model.go @@ -36,6 +36,14 @@ func InsertIntoGroupRequest(toInsertInfo db.GroupRequest) error { return err } + if toInsertInfo.HandledTime.Unix() < 0 { + toInsertInfo.HandledTime = utils.UnixSecondToTime(0) + } + u := dbConn.Table("group_requests").Where("group_id=? and user_id=?", toInsertInfo.GroupID, toInsertInfo.UserID).Update(&toInsertInfo) + if u.RowsAffected != 0 { + return nil + } + toInsertInfo.ReqTime = time.Now() if toInsertInfo.HandledTime.Unix() < 0 { toInsertInfo.HandledTime = utils.UnixSecondToTime(0)