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) diff --git a/internal/rpc/group/group.go b/internal/rpc/group/group.go index 615e69efa..a58e6728a 100644 --- a/internal/rpc/group/group.go +++ b/internal/rpc/group/group.go @@ -453,12 +453,15 @@ 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 } 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) 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 } 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..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 @@ -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,11 +24,17 @@ 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 + + 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) + } else { + return nil } - return nil } func InsertIntoGroupRequest(toInsertInfo GroupRequest) error { @@ -35,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 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"`