From 3f639e2ffe0254fccfdf0ddba44d631a97920833 Mon Sep 17 00:00:00 2001 From: wenxu12345 <44203734@qq.com> Date: Thu, 30 Dec 2021 09:33:51 +0800 Subject: [PATCH 1/8] Refactor code --- pkg/common/db/mysql_model/im_mysql_model/group_member_model.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/common/db/mysql_model/im_mysql_model/group_member_model.go b/pkg/common/db/mysql_model/im_mysql_model/group_member_model.go index 0c25a7003..7e4afb402 100644 --- a/pkg/common/db/mysql_model/im_mysql_model/group_member_model.go +++ b/pkg/common/db/mysql_model/im_mysql_model/group_member_model.go @@ -116,7 +116,7 @@ func GetOwnerManagerByGroupID(groupID string) ([]GroupMember, error) { return nil, err } var groupMemberList []GroupMember - err = dbConn.Table("group_member").Where("group_id=? and role_level>0", groupID).Find(&groupMemberList).Error + err = dbConn.Table("group_member").Where("group_id=? and role_level>?", groupID, constant.GroupOrdinaryUsers).Find(&groupMemberList).Error if err != nil { return nil, err } From 5ae6e985728eedb36acdb97f6f4eaa12f12356d2 Mon Sep 17 00:00:00 2001 From: wenxu12345 <44203734@qq.com> Date: Thu, 30 Dec 2021 09:34:19 +0800 Subject: [PATCH 2/8] Refactor code --- cmd/open_im_api/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/open_im_api/main.go b/cmd/open_im_api/main.go index 6768191a8..fd703657f 100644 --- a/cmd/open_im_api/main.go +++ b/cmd/open_im_api/main.go @@ -50,7 +50,7 @@ func main() { groupRouterGroup.POST("/create_group", group.CreateGroup) //1 groupRouterGroup.POST("/set_group_info", group.SetGroupInfo) //1 groupRouterGroup.POST("join_group", group.JoinGroup) - groupRouterGroup.POST("/quit_group", group.QuitGroup) + groupRouterGroup.POST("/quit_group", group.QuitGroup) //1 groupRouterGroup.POST("/group_application_response", group.ApplicationGroupResponse) groupRouterGroup.POST("/transfer_group", group.TransferGroupOwner) groupRouterGroup.POST("/get_group_applicationList", group.GetGroupApplicationList) From 6d9ee74360eecd2352c4a1d98737700d3a23e0d0 Mon Sep 17 00:00:00 2001 From: wenxu12345 <44203734@qq.com> Date: Thu, 30 Dec 2021 09:38:07 +0800 Subject: [PATCH 3/8] Refactor code --- internal/rpc/group/group.go | 2 +- .../db/mysql_model/im_mysql_model/group_request_model.go | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/internal/rpc/group/group.go b/internal/rpc/group/group.go index 615e69efa..a959778af 100644 --- a/internal/rpc/group/group.go +++ b/internal/rpc/group/group.go @@ -453,7 +453,7 @@ func (s *groupServer) JoinGroup(ctx context.Context, req *pbGroup.JoinGroupReq) log.NewInfo(req.OperationID, "JoinGroup args ", req.String()) _, err := imdb.GetUserByUserID(req.OpUserID) if err != nil { - log.NewError(req.OperationID, "FindUserByUID failed ", err.Error(), req.OpUserID) + log.NewError(req.OperationID, "GetUserByUserID failed ", err.Error(), req.OpUserID) return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil } 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 cd6cf641f..9e7266b02 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 @@ -23,11 +23,10 @@ func UpdateGroupRequest(groupRequest GroupRequest) error { if err != nil { return err } - err = dbConn.Table("group_request").Where("group_id=? and user_id=?", groupRequest.GroupID, groupRequest.UserID).Update(&groupRequest).Error - if err != nil { - return err + //RowsAffected + if dbConn.Table("group_request").Where("group_id=? and user_id=?", groupRequest.GroupID, groupRequest.UserID).Update(&groupRequest).RowsAffected == 0 { + return InsertIntoGroupRequest(groupRequest) } - return nil } func InsertIntoGroupRequest(toInsertInfo GroupRequest) error { From c0172b0a49a3c2371067de18a3f85f1f9b48db9a Mon Sep 17 00:00:00 2001 From: wenxu12345 <44203734@qq.com> Date: Thu, 30 Dec 2021 09:39:37 +0800 Subject: [PATCH 4/8] Refactor code --- pkg/common/db/mysql_model/im_mysql_model/group_request_model.go | 2 ++ 1 file changed, 2 insertions(+) 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 9e7266b02..c96d1bf63 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 @@ -26,6 +26,8 @@ func UpdateGroupRequest(groupRequest GroupRequest) error { //RowsAffected if dbConn.Table("group_request").Where("group_id=? and user_id=?", groupRequest.GroupID, groupRequest.UserID).Update(&groupRequest).RowsAffected == 0 { return InsertIntoGroupRequest(groupRequest) + } else { + return nil } } From 83874ad4666415309c700e05aa56d0803bd183ab Mon Sep 17 00:00:00 2001 From: wenxu12345 <44203734@qq.com> Date: Thu, 30 Dec 2021 09:46:53 +0800 Subject: [PATCH 5/8] Refactor code --- pkg/common/db/mysql_model/im_mysql_model/model_struct.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/common/db/mysql_model/im_mysql_model/model_struct.go b/pkg/common/db/mysql_model/im_mysql_model/model_struct.go index 8c228cae0..d47ca5334 100644 --- a/pkg/common/db/mysql_model/im_mysql_model/model_struct.go +++ b/pkg/common/db/mysql_model/im_mysql_model/model_struct.go @@ -118,7 +118,7 @@ type GroupRequest struct { GroupID string `gorm:"column:group_id;primaryKey;"` HandleResult int32 `gorm:"column:handle_result"` ReqMsg string `gorm:"column:req_msg"` - HandledMsg string `gorm:"column:handled_msg"` + HandledMsg string `gorm:"column:handle_msg"` ReqTime time.Time `gorm:"column:req_time"` HandleUserID string `gorm:"column:handle_user_id"` HandledTime time.Time `gorm:"column:handle_time"` From b687eb09b4fa573bceefeee1f78814f473c0750b Mon Sep 17 00:00:00 2001 From: wenxu12345 <44203734@qq.com> Date: Thu, 30 Dec 2021 10:14:30 +0800 Subject: [PATCH 6/8] Refactor code --- internal/rpc/group/group.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/internal/rpc/group/group.go b/internal/rpc/group/group.go index a959778af..a58e6728a 100644 --- a/internal/rpc/group/group.go +++ b/internal/rpc/group/group.go @@ -458,7 +458,10 @@ func (s *groupServer) JoinGroup(ctx context.Context, req *pbGroup.JoinGroupReq) } var groupRequest imdb.GroupRequest - utils.CopyStructFields(&groupRequest, req) + groupRequest.UserID = req.OpUserID + groupRequest.ReqMsg = req.ReqMessage + groupRequest.GroupID = req.GroupID + err = imdb.UpdateGroupRequest(groupRequest) if err != nil { log.NewError(req.OperationID, "UpdateGroupRequest ", err.Error(), groupRequest) From cb79b1aea5abfb1ee0a35a2ff55fe5e2cc0481f0 Mon Sep 17 00:00:00 2001 From: wenxu12345 <44203734@qq.com> Date: Thu, 30 Dec 2021 10:18:49 +0800 Subject: [PATCH 7/8] Refactor code --- .../db/mysql_model/im_mysql_model/group_request_model.go | 7 +++++++ 1 file changed, 7 insertions(+) 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 c96d1bf63..76545c35d 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 @@ -3,6 +3,7 @@ package im_mysql_model import ( "Open_IM/pkg/common/constant" "Open_IM/pkg/common/db" + "Open_IM/pkg/utils" "time" ) @@ -23,6 +24,12 @@ func UpdateGroupRequest(groupRequest GroupRequest) error { if err != nil { return err } + groupRequest.ReqTime = time.Now() + + if groupRequest.HandledTime.Unix() < 0 { + groupRequest.HandledTime = utils.UnixSecondToTime(0) + } + //RowsAffected if dbConn.Table("group_request").Where("group_id=? and user_id=?", groupRequest.GroupID, groupRequest.UserID).Update(&groupRequest).RowsAffected == 0 { return InsertIntoGroupRequest(groupRequest) From 7c3e429f22aa4ea42c471a226bd737f52df639ce Mon Sep 17 00:00:00 2001 From: wenxu12345 <44203734@qq.com> Date: Thu, 30 Dec 2021 10:20:16 +0800 Subject: [PATCH 8/8] Refactor code --- .../db/mysql_model/im_mysql_model/group_request_model.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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 76545c35d..e90c2cdd5 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 @@ -24,7 +24,6 @@ func UpdateGroupRequest(groupRequest GroupRequest) error { if err != nil { return err } - groupRequest.ReqTime = time.Now() if groupRequest.HandledTime.Unix() < 0 { groupRequest.HandledTime = utils.UnixSecondToTime(0) @@ -43,7 +42,12 @@ func InsertIntoGroupRequest(toInsertInfo GroupRequest) error { if err != nil { return err } - toInsertInfo.HandledTime = time.Now() + + toInsertInfo.ReqTime = time.Now() + if toInsertInfo.HandledTime.Unix() < 0 { + toInsertInfo.HandledTime = utils.UnixSecondToTime(0) + } + err = dbConn.Table("group_request").Create(&toInsertInfo).Error if err != nil { return err