diff --git a/cmd/rpc/group/main.go b/cmd/rpc/group/main.go index 2ccae9e6b..89451b6ef 100644 --- a/cmd/rpc/group/main.go +++ b/cmd/rpc/group/main.go @@ -7,5 +7,5 @@ import ( ) func main() { - startrpc.Start(config.Config.RpcPort.OpenImGroupPort[0], config.Config.RpcRegisterName.OpenImGroupName, config.Config.Prometheus.GroupPrometheusPort[0], group.Start) + startrpc.Start(config.Config.RpcPort.OpenImGroupPort, config.Config.RpcRegisterName.OpenImGroupName, config.Config.Prometheus.GroupPrometheusPort, group.Start) } diff --git a/internal/rpc/group/callback.go b/internal/rpc/group/callback.go index 0c174b8bf..47fe90da4 100644 --- a/internal/rpc/group/callback.go +++ b/internal/rpc/group/callback.go @@ -12,6 +12,7 @@ import ( "Open_IM/pkg/utils" "context" "google.golang.org/protobuf/types/known/wrapperspb" + "time" ) func CallbackBeforeCreateGroup(ctx context.Context, req *group.CreateGroupReq) (err error) { @@ -21,72 +22,44 @@ func CallbackBeforeCreateGroup(ctx context.Context, req *group.CreateGroupReq) ( defer func() { tracelog.SetCtxInfo(ctx, utils.GetFuncName(1), err, "req", req) }() - operationID := tracelog.GetOperationID(ctx) - commonCallbackReq := &callbackstruct.CallbackBeforeCreateGroupReq{ + cbReq := &callbackstruct.CallbackBeforeCreateGroupReq{ CallbackCommand: constant.CallbackBeforeCreateGroupCommand, - OperationID: operationID, + OperationID: tracelog.GetOperationID(ctx), GroupInfo: *req.GroupInfo, } - commonCallbackReq.InitMemberList = append(commonCallbackReq.InitMemberList, &apistruct.GroupAddMemberInfo{ + cbReq.InitMemberList = append(cbReq.InitMemberList, &apistruct.GroupAddMemberInfo{ UserID: req.OwnerUserID, RoleLevel: constant.GroupOwner, }) for _, userID := range req.AdminUserIDs { - commonCallbackReq.InitMemberList = append(commonCallbackReq.InitMemberList, &apistruct.GroupAddMemberInfo{ + cbReq.InitMemberList = append(cbReq.InitMemberList, &apistruct.GroupAddMemberInfo{ UserID: userID, RoleLevel: constant.GroupAdmin, }) } for _, userID := range req.AdminUserIDs { - commonCallbackReq.InitMemberList = append(commonCallbackReq.InitMemberList, &apistruct.GroupAddMemberInfo{ + cbReq.InitMemberList = append(cbReq.InitMemberList, &apistruct.GroupAddMemberInfo{ UserID: userID, RoleLevel: constant.GroupOrdinaryUsers, }) } - resp := &callbackstruct.CallbackBeforeCreateGroupResp{ - CommonCallbackResp: &callbackstruct.CommonCallbackResp{OperationID: operationID}, - } - err = http.CallBackPostReturn(config.Config.Callback.CallbackUrl, constant.CallbackBeforeCreateGroupCommand, commonCallbackReq, resp, config.Config.Callback.CallbackBeforeCreateGroup) + resp := &callbackstruct.CallbackBeforeCreateGroupResp{} + err = http.CallBackPostReturnV2(config.Config.Callback.CallbackUrl, cbReq, resp, config.Config.Callback.CallbackBeforeCreateGroup) if err != nil { return err } - - if resp.GroupID != nil { - req.GroupInfo.GroupID = *resp.GroupID - } - if resp.GroupName != nil { - req.GroupInfo.GroupName = *resp.GroupName - } - if resp.Notification != nil { - req.GroupInfo.Notification = *resp.Notification - } - if resp.Introduction != nil { - req.GroupInfo.Introduction = *resp.Introduction - } - if resp.FaceURL != nil { - req.GroupInfo.FaceURL = *resp.FaceURL - } - if resp.OwnerUserID != nil { - req.GroupInfo.OwnerUserID = *resp.OwnerUserID - } - if resp.Ex != nil { - req.GroupInfo.Ex = *resp.Ex - } - if resp.Status != nil { - req.GroupInfo.Status = *resp.Status - } - if resp.CreatorUserID != nil { - req.GroupInfo.CreatorUserID = *resp.CreatorUserID - } - if resp.GroupType != nil { - req.GroupInfo.GroupType = *resp.GroupType - } - if resp.NeedVerification != nil { - req.GroupInfo.NeedVerification = *resp.NeedVerification - } - if resp.LookMemberInfo != nil { - req.GroupInfo.LookMemberInfo = *resp.LookMemberInfo - } + utils.NotNilReplace(&req.GroupInfo.GroupID, resp.GroupID) + utils.NotNilReplace(&req.GroupInfo.GroupName, resp.GroupName) + utils.NotNilReplace(&req.GroupInfo.Notification, resp.Notification) + utils.NotNilReplace(&req.GroupInfo.Introduction, resp.Introduction) + utils.NotNilReplace(&req.GroupInfo.FaceURL, resp.FaceURL) + utils.NotNilReplace(&req.GroupInfo.OwnerUserID, resp.OwnerUserID) + utils.NotNilReplace(&req.GroupInfo.Ex, resp.Ex) + utils.NotNilReplace(&req.GroupInfo.Status, resp.Status) + utils.NotNilReplace(&req.GroupInfo.CreatorUserID, resp.CreatorUserID) + utils.NotNilReplace(&req.GroupInfo.GroupType, resp.GroupType) + utils.NotNilReplace(&req.GroupInfo.NeedVerification, resp.NeedVerification) + utils.NotNilReplace(&req.GroupInfo.LookMemberInfo, resp.LookMemberInfo) return nil } @@ -97,39 +70,26 @@ func CallbackBeforeMemberJoinGroup(ctx context.Context, groupMember *relation.Gr defer func() { tracelog.SetCtxInfo(ctx, utils.GetFuncName(1), err, "groupMember", *groupMember, "groupEx", groupEx) }() - operationID := tracelog.GetOperationID(ctx) - callbackResp := callbackstruct.CommonCallbackResp{OperationID: operationID} - callbackReq := callbackstruct.CallbackBeforeMemberJoinGroupReq{ + callbackReq := &callbackstruct.CallbackBeforeMemberJoinGroupReq{ CallbackCommand: constant.CallbackBeforeMemberJoinGroupCommand, - OperationID: operationID, + OperationID: tracelog.GetOperationID(ctx), GroupID: groupMember.GroupID, UserID: groupMember.UserID, Ex: groupMember.Ex, GroupEx: groupEx, } - resp := &callbackstruct.CallbackBeforeMemberJoinGroupResp{ - CommonCallbackResp: &callbackResp, - } - err = http.CallBackPostReturn(config.Config.Callback.CallbackUrl, constant.CallbackBeforeMemberJoinGroupCommand, callbackReq, - resp, config.Config.Callback.CallbackBeforeMemberJoinGroup) + resp := &callbackstruct.CallbackBeforeMemberJoinGroupResp{} + err = http.CallBackPostReturnV2(config.Config.Callback.CallbackUrl, callbackReq, resp, config.Config.Callback.CallbackBeforeMemberJoinGroup) if err != nil { return err } if resp.MuteEndTime != nil { - groupMember.MuteEndTime = utils.UnixSecondToTime(*resp.MuteEndTime) - } - if resp.FaceURL != nil { - groupMember.FaceURL = *resp.FaceURL - } - if resp.Ex != nil { - groupMember.Ex = *resp.Ex - } - if resp.NickName != nil { - groupMember.Nickname = *resp.NickName - } - if resp.RoleLevel != nil { - groupMember.RoleLevel = *resp.RoleLevel + groupMember.MuteEndTime = time.UnixMilli(*resp.MuteEndTime) } + utils.NotNilReplace(&groupMember.FaceURL, resp.FaceURL) + utils.NotNilReplace(&groupMember.Ex, resp.Ex) + utils.NotNilReplace(&groupMember.Nickname, resp.Nickname) + utils.NotNilReplace(&groupMember.RoleLevel, resp.RoleLevel) return nil } @@ -140,44 +100,40 @@ func CallbackBeforeSetGroupMemberInfo(ctx context.Context, req *group.SetGroupMe defer func() { tracelog.SetCtxInfo(ctx, utils.GetFuncName(1), err, "req", *req) }() - operationID := tracelog.GetOperationID(ctx) - callbackResp := callbackstruct.CommonCallbackResp{OperationID: operationID} callbackReq := callbackstruct.CallbackBeforeSetGroupMemberInfoReq{ CallbackCommand: constant.CallbackBeforeSetGroupMemberInfoCommand, - OperationID: operationID, + OperationID: tracelog.GetOperationID(ctx), GroupID: req.GroupID, UserID: req.UserID, } if req.Nickname != nil { - callbackReq.Nickname = req.Nickname.Value + callbackReq.Nickname = &req.Nickname.Value } if req.FaceURL != nil { - callbackReq.FaceURL = req.FaceURL.Value + callbackReq.FaceURL = &req.FaceURL.Value } if req.RoleLevel != nil { - callbackReq.RoleLevel = req.RoleLevel.Value + callbackReq.RoleLevel = &req.RoleLevel.Value } if req.Ex != nil { - callbackReq.Ex = req.Ex.Value + callbackReq.Ex = &req.Ex.Value } - resp := &callbackstruct.CallbackBeforeSetGroupMemberInfoResp{ - CommonCallbackResp: &callbackResp, - } - err = http.CallBackPostReturn(config.Config.Callback.CallbackUrl, constant.CallbackBeforeSetGroupMemberInfoCommand, callbackReq, resp, config.Config.Callback.CallbackBeforeSetGroupMemberInfo) + resp := &callbackstruct.CallbackBeforeSetGroupMemberInfoResp{} + err = http.CallBackPostReturnV2(config.Config.Callback.CallbackUrl, callbackReq, resp, config.Config.Callback.CallbackBeforeSetGroupMemberInfo) if err != nil { return err } if resp.FaceURL != nil { - req.FaceURL = &wrapperspb.StringValue{Value: *resp.FaceURL} + req.FaceURL = wrapperspb.String(*resp.FaceURL) } if resp.Nickname != nil { - req.Nickname = &wrapperspb.StringValue{Value: *resp.Nickname} + req.Nickname = wrapperspb.String(*resp.Nickname) } if resp.RoleLevel != nil { - req.RoleLevel = &wrapperspb.Int32Value{Value: *resp.RoleLevel} + req.RoleLevel = wrapperspb.Int32(*resp.RoleLevel) } if resp.Ex != nil { - req.Ex = &wrapperspb.StringValue{Value: *resp.Ex} + req.Ex = wrapperspb.String(*resp.Ex) } - return err + return nil } diff --git a/internal/rpc/group/group.go b/internal/rpc/group/group.go index 55e6d90fd..dfa58f7ef 100644 --- a/internal/rpc/group/group.go +++ b/internal/rpc/group/group.go @@ -28,11 +28,11 @@ import ( ) func Start(client *openKeeper.ZkClient, server *grpc.Server) error { - mysql, err := relation.NewGormDB() + db, err := relation.NewGormDB() if err != nil { return err } - if err := mysql.AutoMigrate(&relationTb.GroupModel{}, &relationTb.GroupMemberModel{}, &relationTb.GroupRequestModel{}); err != nil { + if err := db.AutoMigrate(&relationTb.GroupModel{}, &relationTb.GroupMemberModel{}, &relationTb.GroupRequestModel{}); err != nil { return err } redis, err := cache.NewRedis() @@ -44,7 +44,7 @@ func Start(client *openKeeper.ZkClient, server *grpc.Server) error { return err } pbGroup.RegisterGroupServer(server, &groupServer{ - GroupInterface: controller.NewGroupInterface(mysql, redis.GetClient(), mongo.GetClient()), + GroupInterface: controller.NewGroupInterface(controller.NewGroupDatabase(db, redis.GetClient(), mongo.GetClient())), UserCheck: check.NewUserCheck(client), ConversationChecker: check.NewConversationChecker(client), }) diff --git a/internal/startrpc/start.go b/internal/startrpc/start.go index 0bdc2a51e..1a487d2b7 100644 --- a/internal/startrpc/start.go +++ b/internal/startrpc/start.go @@ -15,15 +15,13 @@ import ( "net" ) -func start(rpcPort int, rpcRegisterName string, prometheusPort int, rpcFn func(client *openKeeper.ZkClient, server *grpc.Server) error, options []grpc.ServerOption) error { - flagRpcPort := flag.Int("port", rpcPort, "get RpcGroupPort from cmd,default 16000 as port") - flagPrometheusPort := flag.Int("prometheus_port", prometheusPort, "groupPrometheusPort default listen port") +func start(rpcPorts []int, rpcRegisterName string, prometheusPorts []int, rpcFn func(client *openKeeper.ZkClient, server *grpc.Server) error, options []grpc.ServerOption) error { + flagRpcPort := flag.Int("port", rpcPorts[0], "get RpcGroupPort from cmd,default 16000 as port") + flagPrometheusPort := flag.Int("prometheus_port", prometheusPorts[0], "groupPrometheusPort default listen port") flag.Parse() - rpcPort = *flagRpcPort - prometheusPort = *flagPrometheusPort - fmt.Println("start group rpc server, port: ", rpcPort, ", OpenIM version: ", constant.CurrentVersion) + fmt.Println("start group rpc server, port: ", *flagRpcPort, ", OpenIM version: ", constant.CurrentVersion) log.NewPrivateLog(constant.LogFileName) - listener, err := net.Listen("tcp", fmt.Sprintf("%s:%d", config.Config.ListenIP, rpcPort)) + listener, err := net.Listen("tcp", fmt.Sprintf("%s:%d", config.Config.ListenIP, *flagRpcPort)) if err != nil { return err } @@ -50,12 +48,12 @@ func start(rpcPort int, rpcRegisterName string, prometheusPort int, rpcFn func(c } srv := grpc.NewServer(options...) defer srv.GracefulStop() - err = zkClient.Register(rpcRegisterName, registerIP, rpcPort) + err = zkClient.Register(rpcRegisterName, registerIP, *flagRpcPort) if err != nil { return err } if config.Config.Prometheus.Enable { - err := promePkg.StartPromeSrv(prometheusPort) + err := promePkg.StartPromeSrv(*flagPrometheusPort) if err != nil { return err } @@ -63,7 +61,7 @@ func start(rpcPort int, rpcRegisterName string, prometheusPort int, rpcFn func(c return rpcFn(zkClient, srv) } -func Start(rpcPort int, rpcRegisterName string, prometheusPort int, rpcFn func(client *openKeeper.ZkClient, server *grpc.Server) error, options ...grpc.ServerOption) { - err := start(rpcPort, rpcRegisterName, prometheusPort, rpcFn, options) +func Start(rpcPorts []int, rpcRegisterName string, prometheusPorts []int, rpcFn func(client *openKeeper.ZkClient, server *grpc.Server) error, options ...grpc.ServerOption) { + err := start(rpcPorts, rpcRegisterName, prometheusPorts, rpcFn, options) fmt.Println("end", err) } diff --git a/pkg/callbackstruct/common.go b/pkg/callbackstruct/common.go index 2f589fc91..098dc8135 100644 --- a/pkg/callbackstruct/common.go +++ b/pkg/callbackstruct/common.go @@ -41,13 +41,9 @@ type CommonCallbackResp struct { ActionCode int `json:"actionCode"` ErrCode int32 `json:"errCode"` ErrMsg string `json:"errMsg"` - //OperationID string `json:"operationID"` } -func (c *CommonCallbackResp) Parse() error { - if c == nil { - return constant.ErrData.Wrap("callback common is nil") - } +func (c CommonCallbackResp) Parse() error { if c.ActionCode != constant.NoError || c.ErrCode != constant.NoError { newErr := constant.ErrCallback newErr.ErrCode = c.ErrCode diff --git a/pkg/callbackstruct/friend.go b/pkg/callbackstruct/friend.go index fa1cffe28..9967707f3 100644 --- a/pkg/callbackstruct/friend.go +++ b/pkg/callbackstruct/friend.go @@ -9,5 +9,5 @@ type CallbackBeforeAddFriendReq struct { } type CallbackBeforeAddFriendResp struct { - *CommonCallbackResp + CommonCallbackResp } diff --git a/pkg/callbackstruct/group.go b/pkg/callbackstruct/group.go index a84753326..136386297 100644 --- a/pkg/callbackstruct/group.go +++ b/pkg/callbackstruct/group.go @@ -5,15 +5,21 @@ import ( common "Open_IM/pkg/proto/sdkws" ) +type CallbackCommand string + +func (c CallbackCommand) GetCallbackCommand() string { + return string(c) +} + type CallbackBeforeCreateGroupReq struct { - CallbackCommand string `json:"callbackCommand"` OperationID string `json:"operationID"` + CallbackCommand `json:"callbackCommand"` common.GroupInfo InitMemberList []*apistruct.GroupAddMemberInfo `json:"initMemberList"` } type CallbackBeforeCreateGroupResp struct { - *CommonCallbackResp + CommonCallbackResp GroupID *string `json:"groupID"` GroupName *string `json:"groupName"` Notification *string `json:"notification"` @@ -30,7 +36,7 @@ type CallbackBeforeCreateGroupResp struct { } type CallbackBeforeMemberJoinGroupReq struct { - CallbackCommand string `json:"callbackCommand"` + CallbackCommand `json:"callbackCommand"` OperationID string `json:"operationID"` GroupID string `json:"groupID"` UserID string `json:"userID"` @@ -39,8 +45,8 @@ type CallbackBeforeMemberJoinGroupReq struct { } type CallbackBeforeMemberJoinGroupResp struct { - *CommonCallbackResp - NickName *string `json:"nickName"` + CommonCallbackResp + Nickname *string `json:"nickname"` FaceURL *string `json:"faceURL"` RoleLevel *int32 `json:"roleLevel"` MuteEndTime *int64 `json:"muteEndTime"` @@ -48,18 +54,18 @@ type CallbackBeforeMemberJoinGroupResp struct { } type CallbackBeforeSetGroupMemberInfoReq struct { - CallbackCommand string `json:"callbackCommand"` - OperationID string `json:"operationID"` - GroupID string `json:"groupID"` - UserID string `json:"userID"` - Nickname string `json:"nickName"` - FaceURL string `json:"faceURL"` - RoleLevel int32 `json:"roleLevel"` - Ex string `json:"ex"` + CallbackCommand `json:"callbackCommand"` + OperationID string `json:"operationID"` + GroupID string `json:"groupID"` + UserID string `json:"userID"` + Nickname *string `json:"nickName"` + FaceURL *string `json:"faceURL"` + RoleLevel *int32 `json:"roleLevel"` + Ex *string `json:"ex"` } type CallbackBeforeSetGroupMemberInfoResp struct { - *CommonCallbackResp + CommonCallbackResp Ex *string `json:"ex"` Nickname *string `json:"nickName"` FaceURL *string `json:"faceURL"` diff --git a/pkg/callbackstruct/message.go b/pkg/callbackstruct/message.go index efb26f4a3..39276cdb1 100644 --- a/pkg/callbackstruct/message.go +++ b/pkg/callbackstruct/message.go @@ -11,7 +11,7 @@ type CallbackBeforeSendSingleMsgReq struct { } type CallbackBeforeSendSingleMsgResp struct { - *CommonCallbackResp + CommonCallbackResp } type CallbackAfterSendSingleMsgReq struct { @@ -20,7 +20,7 @@ type CallbackAfterSendSingleMsgReq struct { } type CallbackAfterSendSingleMsgResp struct { - *CommonCallbackResp + CommonCallbackResp } type CallbackBeforeSendGroupMsgReq struct { @@ -29,7 +29,7 @@ type CallbackBeforeSendGroupMsgReq struct { } type CallbackBeforeSendGroupMsgResp struct { - *CommonCallbackResp + CommonCallbackResp } type CallbackAfterSendGroupMsgReq struct { @@ -38,7 +38,7 @@ type CallbackAfterSendGroupMsgReq struct { } type CallbackAfterSendGroupMsgResp struct { - *CommonCallbackResp + CommonCallbackResp } type CallbackMsgModifyCommandReq struct { @@ -46,7 +46,7 @@ type CallbackMsgModifyCommandReq struct { } type CallbackMsgModifyCommandResp struct { - *CommonCallbackResp + CommonCallbackResp Content *string `json:"content"` RecvID *string `json:"recvID"` GroupID *string `json:"groupID"` @@ -79,7 +79,7 @@ type CallbackBeforeSetMessageReactionExtReq struct { MsgFirstModifyTime int64 `json:"msgFirstModifyTime"` } type CallbackBeforeSetMessageReactionExtResp struct { - *CommonCallbackResp + CommonCallbackResp ResultReactionExtensionList []*msg.KeyValueResp `json:"resultReactionExtensionList"` MsgFirstModifyTime int64 `json:"msgFirstModifyTime"` } @@ -95,7 +95,7 @@ type CallbackDeleteMessageReactionExtReq struct { MsgFirstModifyTime int64 `json:"msgFirstModifyTime"` } type CallbackDeleteMessageReactionExtResp struct { - *CommonCallbackResp + CommonCallbackResp ResultReactionExtensionList []*msg.KeyValueResp `json:"resultReactionExtensionList"` MsgFirstModifyTime int64 `json:"msgFirstModifyTime"` } diff --git a/pkg/callbackstruct/msg_gateway.go b/pkg/callbackstruct/msg_gateway.go index 02509ac3f..34bb14e69 100644 --- a/pkg/callbackstruct/msg_gateway.go +++ b/pkg/callbackstruct/msg_gateway.go @@ -9,7 +9,7 @@ type CallbackUserOnlineReq struct { } type CallbackUserOnlineResp struct { - *CommonCallbackResp + CommonCallbackResp } type CallbackUserOfflineReq struct { @@ -19,7 +19,7 @@ type CallbackUserOfflineReq struct { } type CallbackUserOfflineResp struct { - *CommonCallbackResp + CommonCallbackResp } type CallbackUserKickOffReq struct { @@ -28,5 +28,5 @@ type CallbackUserKickOffReq struct { } type CallbackUserKickOffResp struct { - *CommonCallbackResp + CommonCallbackResp } diff --git a/pkg/callbackstruct/push.go b/pkg/callbackstruct/push.go index 483a2dffb..9a686b011 100644 --- a/pkg/callbackstruct/push.go +++ b/pkg/callbackstruct/push.go @@ -15,7 +15,7 @@ type CallbackBeforePushReq struct { } type CallbackBeforePushResp struct { - *CommonCallbackResp + CommonCallbackResp UserIDList []string `json:"userIDList"` OfflinePushInfo *common.OfflinePushInfo `json:"offlinePushInfo"` } @@ -34,7 +34,7 @@ type CallbackBeforeSuperGroupOnlinePushReq struct { } type CallbackBeforeSuperGroupOnlinePushResp struct { - *CommonCallbackResp + CommonCallbackResp UserIDList []string `json:"userIDList"` OfflinePushInfo *common.OfflinePushInfo `json:"offlinePushInfo"` } diff --git a/pkg/common/db/controller/group.go b/pkg/common/db/controller/group.go index 8a39442c8..2fb6a8551 100644 --- a/pkg/common/db/controller/group.go +++ b/pkg/common/db/controller/group.go @@ -55,8 +55,8 @@ type GroupInterface interface { var _ GroupInterface = (*GroupController)(nil) -func NewGroupInterface(db *gorm.DB, rdb redis.UniversalClient, mgoClient *mongo.Client) GroupInterface { - return &GroupController{database: NewGroupDatabase(db, rdb, mgoClient)} +func NewGroupInterface(database GroupDataBaseInterface) GroupInterface { + return &GroupController{database: database} } type GroupController struct { @@ -72,7 +72,7 @@ func (g *GroupController) CreateGroup(ctx context.Context, groups []*relationTb. } func (g *GroupController) TakeGroup(ctx context.Context, groupID string) (group *relationTb.GroupModel, err error) { - return g.TakeGroup(ctx, groupID) + return g.database.TakeGroup(ctx, groupID) } func (g *GroupController) FindGroup(ctx context.Context, groupIDs []string) (groups []*relationTb.GroupModel, err error) { @@ -175,6 +175,53 @@ func (g *GroupController) CreateSuperGroupMember(ctx context.Context, groupID st return g.database.CreateSuperGroupMember(ctx, groupID, userIDs) } +type Group interface { + CreateGroup(ctx context.Context, groups []*relationTb.GroupModel, groupMembers []*relationTb.GroupMemberModel) error + TakeGroup(ctx context.Context, groupID string) (group *relationTb.GroupModel, err error) + FindGroup(ctx context.Context, groupIDs []string) (groups []*relationTb.GroupModel, err error) + SearchGroup(ctx context.Context, keyword string, pageNumber, showNumber int32) (uint32, []*relationTb.GroupModel, error) + UpdateGroup(ctx context.Context, groupID string, data map[string]any) error + DismissGroup(ctx context.Context, groupID string) error // 解散群,并删除群成员 +} + +type GroupMember interface { + TakeGroupMember(ctx context.Context, groupID string, userID string) (groupMember *relationTb.GroupMemberModel, err error) + TakeGroupOwner(ctx context.Context, groupID string) (*relationTb.GroupMemberModel, error) + FindGroupMember(ctx context.Context, groupIDs []string, userIDs []string, roleLevels []int32) ([]*relationTb.GroupMemberModel, error) + FindGroupMemberUserID(ctx context.Context, groupID string) ([]string, error) + PageGroupMember(ctx context.Context, groupIDs []string, userIDs []string, roleLevels []int32, pageNumber, showNumber int32) (uint32, []*relationTb.GroupMemberModel, error) + SearchGroupMember(ctx context.Context, keyword string, groupIDs []string, userIDs []string, roleLevels []int32, pageNumber, showNumber int32) (uint32, []*relationTb.GroupMemberModel, error) + HandlerGroupRequest(ctx context.Context, groupID string, userID string, handledMsg string, handleResult int32, member *relationTb.GroupMemberModel) error + DeleteGroupMember(ctx context.Context, groupID string, userIDs []string) error + MapGroupMemberUserID(ctx context.Context, groupIDs []string) (map[string]*relationTb.GroupSimpleUserID, error) + MapGroupMemberNum(ctx context.Context, groupIDs []string) (map[string]uint32, error) + TransferGroupOwner(ctx context.Context, groupID string, oldOwnerUserID, newOwnerUserID string, roleLevel int32) error // 转让群 + UpdateGroupMember(ctx context.Context, groupID string, userID string, data map[string]any) error + UpdateGroupMembers(ctx context.Context, data []*relationTb.BatchUpdateGroupMember) error +} + +type GroupRequest interface { + CreateGroupRequest(ctx context.Context, requests []*relationTb.GroupRequestModel) error + TakeGroupRequest(ctx context.Context, groupID string, userID string) (*relationTb.GroupRequestModel, error) + PageGroupRequestUser(ctx context.Context, userID string, pageNumber, showNumber int32) (uint32, []*relationTb.GroupRequestModel, error) +} + +type SuperGroup interface { + FindSuperGroup(ctx context.Context, groupIDs []string) ([]*unrelationTb.SuperGroupModel, error) + FindJoinSuperGroup(ctx context.Context, userID string) (*unrelationTb.UserToSuperGroupModel, error) + CreateSuperGroup(ctx context.Context, groupID string, initMemberIDList []string) error + DeleteSuperGroup(ctx context.Context, groupID string) error + DeleteSuperGroupMember(ctx context.Context, groupID string, userIDs []string) error + CreateSuperGroupMember(ctx context.Context, groupID string, userIDs []string) error +} + +type GroupDataBase1 interface { + Group + GroupMember + GroupRequest + SuperGroup +} + type GroupDataBaseInterface interface { CreateGroup(ctx context.Context, groups []*relationTb.GroupModel, groupMembers []*relationTb.GroupMemberModel) error TakeGroup(ctx context.Context, groupID string) (group *relationTb.GroupModel, err error) @@ -291,7 +338,10 @@ func (g *GroupDataBase) CreateGroup(ctx context.Context, groups []*relationTb.Gr } func (g *GroupDataBase) TakeGroup(ctx context.Context, groupID string) (group *relationTb.GroupModel, err error) { - return g.cache.GetGroupInfo(ctx, groupID) + //return g.cache.GetGroupInfo(ctx, groupID) + return cache.GetCache(ctx, g.rcClient, g.getGroupInfoKey(groupID), g.expireTime, func(ctx context.Context) (*relationTb.GroupModel, error) { + return g.group.Take(ctx, groupID) + }) } func (g *GroupDataBase) FindGroup(ctx context.Context, groupIDs []string) (groups []*relationTb.GroupModel, err error) {