From 86bf207e0275bbcd7e0d9dc04fe846d8af13d59f Mon Sep 17 00:00:00 2001 From: skiffer-git <44203734@qq.com> Date: Wed, 4 Jan 2023 17:22:55 +0800 Subject: [PATCH] Error code standardization --- internal/demo/register/ip_limit.go | 9 +- internal/rpc/admin_cms/admin_cms.go | 3 +- internal/rpc/auth/auth.go | 3 +- internal/rpc/conversation/conversaion.go | 4 +- internal/rpc/friend/friend.go | 17 +- internal/rpc/group/callback.go | 4 +- internal/rpc/group/group.go | 52 +++--- internal/rpc/msg/tag_send_msg.go | 4 +- internal/rpc/office/office.go | 2 +- internal/rpc/organization/organization.go | 17 +- internal/rpc/user/user.go | 18 +- pkg/common/constant/error.go | 5 +- pkg/common/db/mysql.go | 103 +++++------ .../im_mysql_model/client_config.go | 10 +- .../im_mysql_model/conversation_model.go | 54 +++--- .../mysql_model/im_mysql_model/demo_model.go | 30 ++-- .../mysql_model/im_mysql_model/file_model.go | 10 +- .../im_mysql_model/friend_model.go | 16 +- .../im_mysql_model/friend_request_model.go | 20 +-- .../im_mysql_model/group_member_model.go | 44 ++--- .../mysql_model/im_mysql_model/group_model.go | 18 +- .../im_mysql_model/group_request_model.go | 22 +-- .../db/mysql_model/im_mysql_model/group_sk.go | 32 ++++ .../im_mysql_model/invitation_model.go | 14 +- .../db/mysql_model/im_mysql_model/ip_model.go | 42 ++--- .../mysql_model/im_mysql_model/message_cms.go | 4 +- .../im_mysql_model}/model_struct.go | 170 +++++++++--------- .../im_mysql_model/organization_model.go | 60 +++---- .../im_mysql_model/statistics_model.go | 4 +- .../im_mysql_model/user_black_list_model.go | 10 +- .../mysql_model/im_mysql_model/user_model.go | 62 +++---- .../im_mysql_msg_model/chat_log_model.go | 3 +- pkg/common/db/rocks_cache/rocks_cache.go | 44 ++--- pkg/common/utils/utils.go | 32 ++-- 34 files changed, 490 insertions(+), 452 deletions(-) create mode 100644 pkg/common/db/mysql_model/im_mysql_model/group_sk.go rename pkg/common/db/{ => mysql_model/im_mysql_model}/model_struct.go (85%) diff --git a/internal/demo/register/ip_limit.go b/internal/demo/register/ip_limit.go index 401927613..3569bc8fb 100644 --- a/internal/demo/register/ip_limit.go +++ b/internal/demo/register/ip_limit.go @@ -3,7 +3,6 @@ package register import ( //api "Open_IM/pkg/base_info" "Open_IM/pkg/common/constant" - "Open_IM/pkg/common/db" imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model" "Open_IM/pkg/common/log" "Open_IM/pkg/utils" @@ -75,7 +74,7 @@ func AddIPLimit(c *gin.Context) { return } log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req:", req) - if err := imdb.InsertOneIntoIpLimits(db.IpLimit{ + if err := imdb.InsertOneIntoIpLimits(imdb.IpLimit{ Ip: req.IP, LimitRegister: 1, LimitLogin: 1, @@ -162,8 +161,8 @@ func AddUserIPLimitLogin(c *gin.Context) { return } log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req:", req) - userIp := db.UserIpLimit{UserID: req.UserID, Ip: req.IP} - err := imdb.UpdateUserInfo(db.User{ + userIp := imdb.UserIpLimit{UserID: req.UserID, Ip: req.IP} + err := imdb.UpdateUserInfo(imdb.User{ UserID: req.UserID, // LoginLimit: 1, }) @@ -211,7 +210,7 @@ func RemoveUserIPLimitLogin(c *gin.Context) { return } if len(ips) == 0 { - err := imdb.UpdateUserInfoByMap(db.User{ + err := imdb.UpdateUserInfoByMap(imdb.User{ UserID: req.UserID, }, map[string]interface{}{"login_limit": 0}) if err != nil { diff --git a/internal/rpc/admin_cms/admin_cms.go b/internal/rpc/admin_cms/admin_cms.go index fe7ff68f6..7521bafe9 100644 --- a/internal/rpc/admin_cms/admin_cms.go +++ b/internal/rpc/admin_cms/admin_cms.go @@ -3,7 +3,6 @@ package admin_cms import ( "Open_IM/pkg/common/config" "Open_IM/pkg/common/constant" - "Open_IM/pkg/common/db" imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model" "Open_IM/pkg/common/log" promePkg "Open_IM/pkg/common/prometheus" @@ -215,7 +214,7 @@ func (s *adminCMSServer) GetUserRegisterAddFriendIDList(_ context.Context, req * func (s *adminCMSServer) GetChatLogs(_ context.Context, req *pbAdminCMS.GetChatLogsReq) (*pbAdminCMS.GetChatLogsResp, error) { log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "GetChatLogs", req.String()) resp := &pbAdminCMS.GetChatLogsResp{CommonResp: &pbAdminCMS.CommonResp{}, Pagination: &server_api_params.ResponsePagination{}} - chatLog := db.ChatLog{ + chatLog := imdb.ChatLog{ Content: req.Content, ContentType: req.ContentType, SessionType: req.SessionType, diff --git a/internal/rpc/auth/auth.go b/internal/rpc/auth/auth.go index 5c47713c0..d2ba6bab3 100644 --- a/internal/rpc/auth/auth.go +++ b/internal/rpc/auth/auth.go @@ -2,7 +2,6 @@ package auth import ( "Open_IM/pkg/common/constant" - "Open_IM/pkg/common/db" imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model" "Open_IM/pkg/common/log" promePkg "Open_IM/pkg/common/prometheus" @@ -26,7 +25,7 @@ import ( func (rpc *rpcAuth) UserRegister(_ context.Context, req *pbAuth.UserRegisterReq) (*pbAuth.UserRegisterResp, error) { log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc args ", req.String()) - var user db.User + var user imdb.User utils.CopyStructFields(&user, req.UserInfo) if req.UserInfo.BirthStr != "" { time, err := utils.TimeStringToTime(req.UserInfo.BirthStr) diff --git a/internal/rpc/conversation/conversaion.go b/internal/rpc/conversation/conversaion.go index c6ffb8580..819bd8796 100644 --- a/internal/rpc/conversation/conversaion.go +++ b/internal/rpc/conversation/conversaion.go @@ -48,7 +48,7 @@ func (rpc *rpcConversation) ModifyConversationField(c context.Context, req *pbCo return resp, nil } } - var conversation db.Conversation + var conversation imdb.Conversation if err := utils.CopyStructFields(&conversation, req.Conversation); err != nil { log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", *req.Conversation, err.Error()) } @@ -132,7 +132,7 @@ func (rpc *rpcConversation) ModifyConversationField(c context.Context, req *pbCo return resp, nil } func syncPeerUserConversation(conversation *pbConversation.Conversation, operationID string) error { - peerUserConversation := db.Conversation{ + peerUserConversation := imdb.Conversation{ OwnerUserID: conversation.UserID, ConversationID: utils.GetConversationIDBySessionType(conversation.OwnerUserID, constant.SingleChatType), ConversationType: constant.SingleChatType, diff --git a/internal/rpc/friend/friend.go b/internal/rpc/friend/friend.go index 412f858da..01e849dbb 100644 --- a/internal/rpc/friend/friend.go +++ b/internal/rpc/friend/friend.go @@ -4,7 +4,6 @@ import ( chat "Open_IM/internal/rpc/msg" "Open_IM/pkg/common/config" "Open_IM/pkg/common/constant" - "Open_IM/pkg/common/db" imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model" rocksCache "Open_IM/pkg/common/db/rocks_cache" "Open_IM/pkg/common/log" @@ -108,7 +107,7 @@ func (s *friendServer) AddBlacklist(ctx context.Context, req *pbFriend.AddBlackl log.NewError(req.CommID.OperationID, err.Error(), req.CommID.OpUserID, req.CommID.FromUserID) return &pbFriend.AddBlacklistResp{CommonResp: constant.Error2CommResp(constant.ErrNoPermission, err)}, nil } - black := db.Black{OwnerUserID: req.CommID.FromUserID, BlockUserID: req.CommID.ToUserID, OperatorUserID: req.CommID.OpUserID} + black := imdb.Black{OwnerUserID: req.CommID.FromUserID, BlockUserID: req.CommID.ToUserID, OperatorUserID: req.CommID.OpUserID} err := imdb.InsertInToUserBlackList(black) if err != nil { @@ -192,7 +191,7 @@ func (s *friendServer) AddFriend(ctx context.Context, req *pbFriend.AddFriendReq log.NewError(req.CommID.OperationID, "GetUserByUserID failed ", err.Error(), req.CommID.ToUserID) return &pbFriend.AddFriendResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil } - friendRequest := db.FriendRequest{ + friendRequest := imdb.FriendRequest{ HandleResult: 0, ReqMsg: req.ReqMsg, CreateTime: time.Now()} utils.CopyStructFields(&friendRequest, req.CommID) // {openIM001 openIM002 0 test add friend 0001-01-01 00:00:00 +0000 UTC 0001-01-01 00:00:00 +0000 UTC }] @@ -247,14 +246,14 @@ func (s *friendServer) ImportFriend(ctx context.Context, req *pbFriend.ImportFri } else { if _, err := imdb.GetFriendRelationshipFromFriend(req.FromUserID, v); err != nil { //Establish two single friendship - toInsertFollow := db.Friend{OwnerUserID: req.FromUserID, FriendUserID: v} + toInsertFollow := imdb.Friend{OwnerUserID: req.FromUserID, FriendUserID: v} err1 := imdb.InsertToFriend(&toInsertFollow) if err1 != nil { log.NewError(req.OperationID, "InsertToFriend failed ", err1.Error(), toInsertFollow) resp.UserIDResultList = append(resp.UserIDResultList, &pbFriend.UserIDResult{UserID: v, Result: -1}) continue } - toInsertFollow = db.Friend{OwnerUserID: v, FriendUserID: req.FromUserID} + toInsertFollow = imdb.Friend{OwnerUserID: v, FriendUserID: req.FromUserID} err2 := imdb.InsertToFriend(&toInsertFollow) if err2 != nil { log.NewError(req.OperationID, "InsertToFriend failed ", err2.Error(), toInsertFollow) @@ -320,7 +319,7 @@ func (s *friendServer) ImportFriend(ctx context.Context, req *pbFriend.ImportFri return &resp, nil } -//process Friend application +// process Friend application func (s *friendServer) AddFriendResponse(ctx context.Context, req *pbFriend.AddFriendResponseReq) (*pbFriend.AddFriendResponseResp, error) { log.NewInfo(req.CommID.OperationID, "AddFriendResponse args ", req.String()) if !token_verify.CheckAccess(req.CommID.OpUserID, req.CommID.FromUserID) { @@ -355,7 +354,7 @@ func (s *friendServer) AddFriendResponse(ctx context.Context, req *pbFriend.AddF log.NewWarn(req.CommID.OperationID, "GetFriendRelationshipFromFriend exist", req.CommID.FromUserID, req.CommID.ToUserID) } else { //Establish two single friendship - toInsertFollow := db.Friend{OwnerUserID: req.CommID.FromUserID, FriendUserID: req.CommID.ToUserID, OperatorUserID: req.CommID.OpUserID} + toInsertFollow := imdb.Friend{OwnerUserID: req.CommID.FromUserID, FriendUserID: req.CommID.ToUserID, OperatorUserID: req.CommID.OpUserID} err = imdb.InsertToFriend(&toInsertFollow) if err != nil { log.NewError(req.CommID.OperationID, "InsertToFriend failed ", err.Error(), toInsertFollow) @@ -368,7 +367,7 @@ func (s *friendServer) AddFriendResponse(ctx context.Context, req *pbFriend.AddF if err == nil { log.NewWarn(req.CommID.OperationID, "GetFriendRelationshipFromFriend exist", req.CommID.ToUserID, req.CommID.FromUserID) } else { - toInsertFollow := db.Friend{OwnerUserID: req.CommID.ToUserID, FriendUserID: req.CommID.FromUserID, OperatorUserID: req.CommID.OpUserID} + toInsertFollow := imdb.Friend{OwnerUserID: req.CommID.ToUserID, FriendUserID: req.CommID.FromUserID, OperatorUserID: req.CommID.OpUserID} err = imdb.InsertToFriend(&toInsertFollow) if err != nil { log.NewError(req.CommID.OperationID, "InsertToFriend failed ", err.Error(), toInsertFollow) @@ -619,7 +618,7 @@ func (s *friendServer) GetFriendList(ctx context.Context, req *pbFriend.GetFrien return &pbFriend.GetFriendListResp{FriendInfoList: userInfoList}, nil } -//received +// received func (s *friendServer) GetFriendApplyList(ctx context.Context, req *pbFriend.GetFriendApplyListReq) (*pbFriend.GetFriendApplyListResp, error) { log.NewInfo(req.CommID.OperationID, "GetFriendApplyList args ", req.String()) //Parse token, to find current user information diff --git a/internal/rpc/group/callback.go b/internal/rpc/group/callback.go index 5bf450a69..af2268322 100644 --- a/internal/rpc/group/callback.go +++ b/internal/rpc/group/callback.go @@ -4,7 +4,7 @@ import ( cbApi "Open_IM/pkg/call_back_struct" "Open_IM/pkg/common/config" "Open_IM/pkg/common/constant" - "Open_IM/pkg/common/db" + "Open_IM/pkg/common/db/mysql_model/im_mysql_model" "Open_IM/pkg/common/http" "Open_IM/pkg/common/log" pbGroup "Open_IM/pkg/proto/group" @@ -83,7 +83,7 @@ func callbackBeforeCreateGroup(req *pbGroup.CreateGroupReq) cbApi.CommonCallback return callbackResp } -func CallbackBeforeMemberJoinGroup(operationID string, groupMember *db.GroupMember, groupEx string) cbApi.CommonCallbackResp { +func CallbackBeforeMemberJoinGroup(operationID string, groupMember *im_mysql_model.GroupMember, groupEx string) cbApi.CommonCallbackResp { callbackResp := cbApi.CommonCallbackResp{OperationID: operationID} if !config.Config.Callback.CallbackBeforeMemberJoinGroup.Enable { return callbackResp diff --git a/internal/rpc/group/group.go b/internal/rpc/group/group.go index 650c6805c..a9daaac07 100644 --- a/internal/rpc/group/group.go +++ b/internal/rpc/group/group.go @@ -143,7 +143,7 @@ func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupR groupId = bi.String() } //to group - groupInfo := db.Group{} + groupInfo := imdb.Group{} utils.CopyStructFields(&groupInfo, req.GroupInfo) groupInfo.CreatorUserID = req.OpUserID groupInfo.GroupID = groupId @@ -158,8 +158,8 @@ func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupR } var okUserIDList []string resp := &pbGroup.CreateGroupResp{GroupInfo: &open_im_sdk.GroupInfo{}} - groupMember := db.GroupMember{} - us := &db.User{} + groupMember := imdb.GroupMember{} + us := &imdb.User{} if req.OwnerUserID != "" { var userIDList []string for _, v := range req.InitMemberList { @@ -177,7 +177,7 @@ func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupR return &pbGroup.CreateGroupResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, nil } //to group member - groupMember = db.GroupMember{GroupID: groupId, RoleLevel: constant.GroupOwner, OperatorUserID: req.OpUserID, JoinSource: constant.JoinByInvitation, InviterUserID: req.OpUserID} + groupMember = imdb.GroupMember{GroupID: groupId, RoleLevel: constant.GroupOwner, OperatorUserID: req.OpUserID, JoinSource: constant.JoinByInvitation, InviterUserID: req.OpUserID} utils.CopyStructFields(&groupMember, us) callbackResp := CallbackBeforeMemberJoinGroup(req.OperationID, &groupMember, groupInfo.Ex) if callbackResp.ErrCode != 0 { @@ -367,7 +367,7 @@ func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbGroup.Invite var resp pbGroup.InviteUserToGroupResp joinReq := pbGroup.JoinGroupReq{} for _, v := range req.InvitedUserIDList { - var groupRequest db.GroupRequest + var groupRequest imdb.GroupRequest groupRequest.UserID = v groupRequest.GroupID = req.GroupID groupRequest.JoinSource = constant.JoinByInvitation @@ -423,7 +423,7 @@ func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbGroup.Invite resp.Id2ResultList = append(resp.Id2ResultList, &resultNode) continue } - var toInsertInfo db.GroupMember + var toInsertInfo imdb.GroupMember utils.CopyStructFields(&toInsertInfo, toUserInfo) toInsertInfo.GroupID = req.GroupID toInsertInfo.RoleLevel = constant.GroupOrdinaryUsers @@ -867,17 +867,23 @@ func (s *groupServer) GetGroupsInfo(ctx context.Context, req *pbGroup.GetGroupsI return &resp, nil } -func (s *groupServer) GroupApplicationResponse(_ context.Context, req *pbGroup.GroupApplicationResponseReq) (*pbGroup.GroupApplicationResponseResp, error) { - log.NewInfo(req.OperationID, "GroupApplicationResponse args ", req.String()) - groupRequest := db.GroupRequest{} - utils.CopyStructFields(&groupRequest, req) - groupRequest.UserID = req.FromUserID - groupRequest.HandleUserID = req.OpUserID - groupRequest.HandledTime = time.Now() +func CheckAppManagerAndGroupAdmin(string) { + +} +func (s *groupServer) GroupApplicationResponse(ctx context.Context, req *pbGroup.GroupApplicationResponseReq) (*pbGroup.GroupApplicationResponseResp, error) { + nCtx := trace_log.NewRpcCtx(ctx, utils.GetSelfFuncName(), req.OperationID) + trace_log.SetRpcReqInfo(nCtx, utils.GetSelfFuncName(), req.String()) + defer trace_log.ShowLog(nCtx) if !token_verify.IsManagerUserID(req.OpUserID) && !imdb.IsGroupOwnerAdmin(req.GroupID, req.OpUserID) { log.NewError(req.OperationID, "IsManagerUserID IsGroupOwnerAdmin false ", req.GroupID, req.OpUserID) return &pbGroup.GroupApplicationResponseResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}}, nil } + groupRequest := imdb.GroupRequest{} + utils.CopyStructFields(&groupRequest, req) + groupRequest.UserID = req.FromUserID + groupRequest.HandleUserID = req.OpUserID + groupRequest.HandledTime = time.Now() + err := imdb.UpdateGroupRequest(groupRequest) if err != nil { log.NewError(req.OperationID, "GroupApplicationResponse failed ", err.Error(), groupRequest) @@ -899,7 +905,7 @@ func (s *groupServer) GroupApplicationResponse(_ context.Context, req *pbGroup.G log.NewError(req.OperationID, "GroupApplicationResponse failed ", err.Error(), req.FromUserID) return &pbGroup.GroupApplicationResponseResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil } - member := db.GroupMember{} + member := imdb.GroupMember{} member.GroupID = req.GroupID member.UserID = req.FromUserID member.RoleLevel = constant.GroupOrdinaryUsers @@ -1038,7 +1044,7 @@ func (s *groupServer) JoinGroup(ctx context.Context, req *pbGroup.JoinGroupReq) return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil } //to group member - groupMember := db.GroupMember{GroupID: req.GroupID, RoleLevel: constant.GroupOrdinaryUsers, OperatorUserID: req.OpUserID} + groupMember := imdb.GroupMember{GroupID: req.GroupID, RoleLevel: constant.GroupOrdinaryUsers, OperatorUserID: req.OpUserID} utils.CopyStructFields(&groupMember, us) callbackResp := CallbackBeforeMemberJoinGroup(req.OperationID, &groupMember, groupInfo.Ex) if callbackResp.ErrCode != 0 { @@ -1107,7 +1113,7 @@ func (s *groupServer) JoinGroup(ctx context.Context, req *pbGroup.JoinGroupReq) return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrArgs.ErrCode, ErrMsg: constant.ErrArgs.ErrMsg}}, nil } } - var groupRequest db.GroupRequest + var groupRequest imdb.GroupRequest groupRequest.UserID = req.OpUserID groupRequest.ReqMsg = req.ReqMessage groupRequest.GroupID = req.GroupID @@ -1295,7 +1301,7 @@ func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbGroup.SetGroupInf // //} //only administrators can set group information - var groupInfo db.Group + var groupInfo imdb.Group utils.CopyStructFields(&groupInfo, req.GroupInfoForSet) if req.GroupInfoForSet.Notification != "" { groupInfo.NotificationUserID = req.OpUserID @@ -1392,13 +1398,13 @@ func (s *groupServer) TransferGroupOwner(_ context.Context, req *pbGroup.Transfe return &pbGroup.TransferGroupOwnerResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: err.Error()}}, nil } - groupMemberInfo := db.GroupMember{GroupID: req.GroupID, UserID: req.OldOwnerUserID, RoleLevel: constant.GroupOrdinaryUsers} + groupMemberInfo := imdb.GroupMember{GroupID: req.GroupID, UserID: req.OldOwnerUserID, RoleLevel: constant.GroupOrdinaryUsers} err = imdb.UpdateGroupMemberInfo(groupMemberInfo) if err != nil { log.NewError(req.OperationID, "UpdateGroupMemberInfo failed ", groupMemberInfo) return &pbGroup.TransferGroupOwnerResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil } - groupMemberInfo = db.GroupMember{GroupID: req.GroupID, UserID: req.NewOwnerUserID, RoleLevel: constant.GroupOwner} + groupMemberInfo = imdb.GroupMember{GroupID: req.GroupID, UserID: req.NewOwnerUserID, RoleLevel: constant.GroupOwner} err = imdb.UpdateGroupMemberInfo(groupMemberInfo) if err != nil { log.NewError(req.OperationID, "UpdateGroupMemberInfo failed ", groupMemberInfo) @@ -1652,7 +1658,7 @@ func (s *groupServer) MuteGroupMember(ctx context.Context, req *pbGroup.MuteGrou log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID, req.UserID) return &pbGroup.MuteGroupMemberResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: err.Error()}}, nil } - groupMemberInfo := db.GroupMember{GroupID: req.GroupID, UserID: req.UserID} + groupMemberInfo := imdb.GroupMember{GroupID: req.GroupID, UserID: req.UserID} groupMemberInfo.MuteEndTime = time.Unix(int64(time.Now().Second())+int64(req.MutedSeconds), time.Now().UnixNano()) err = imdb.UpdateGroupMemberInfo(groupMemberInfo) if err != nil { @@ -1697,7 +1703,7 @@ func (s *groupServer) CancelMuteGroupMember(ctx context.Context, req *pbGroup.Ca return &pbGroup.CancelMuteGroupMemberResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: err.Error()}}, nil } - groupMemberInfo := db.GroupMember{GroupID: req.GroupID, UserID: req.UserID} + groupMemberInfo := imdb.GroupMember{GroupID: req.GroupID, UserID: req.UserID} groupMemberInfo.MuteEndTime = time.Unix(0, 0) err = imdb.UpdateGroupMemberInfo(groupMemberInfo) if err != nil { @@ -1828,7 +1834,7 @@ func (s *groupServer) SetGroupMemberNickname(ctx context.Context, req *pbGroup.S } nickName := cbReq.Nickname.Value - groupMemberInfo := db.GroupMember{} + groupMemberInfo := imdb.GroupMember{} groupMemberInfo.UserID = req.UserID groupMemberInfo.GroupID = req.GroupID if nickName == "" { @@ -1884,7 +1890,7 @@ func (s *groupServer) SetGroupMemberInfo(ctx context.Context, req *pbGroup.SetGr }, nil } - groupMember := db.GroupMember{ + groupMember := imdb.GroupMember{ GroupID: req.GroupID, UserID: req.UserID, } diff --git a/internal/rpc/msg/tag_send_msg.go b/internal/rpc/msg/tag_send_msg.go index 0783d740e..c4e2843fe 100644 --- a/internal/rpc/msg/tag_send_msg.go +++ b/internal/rpc/msg/tag_send_msg.go @@ -3,7 +3,7 @@ package msg import ( "Open_IM/pkg/common/config" "Open_IM/pkg/common/constant" - "Open_IM/pkg/common/db" + "Open_IM/pkg/common/db/mysql_model/im_mysql_model" "Open_IM/pkg/common/log" "Open_IM/pkg/grpc-etcdv3/getcdv3" pbChat "Open_IM/pkg/proto/msg" @@ -13,7 +13,7 @@ import ( "strings" ) -func TagSendMessage(operationID string, user *db.User, recvID, content string, senderPlatformID int32) { +func TagSendMessage(operationID string, user *im_mysql_model.User, recvID, content string, senderPlatformID int32) { log.NewInfo(operationID, utils.GetSelfFuncName(), "args: ", user.UserID, recvID, content) var req pbChat.SendMsgReq var msgData pbCommon.MsgData diff --git a/internal/rpc/office/office.go b/internal/rpc/office/office.go index ac997805c..f0d204ea1 100644 --- a/internal/rpc/office/office.go +++ b/internal/rpc/office/office.go @@ -109,7 +109,7 @@ func (s *officeServer) Run() { type tagSendStruct struct { operationID string - user *db.User + user *imdb.User userID string content string senderPlatformID int32 diff --git a/internal/rpc/organization/organization.go b/internal/rpc/organization/organization.go index d024d3060..9bf1f88f9 100644 --- a/internal/rpc/organization/organization.go +++ b/internal/rpc/organization/organization.go @@ -4,7 +4,6 @@ import ( chat "Open_IM/internal/rpc/msg" "Open_IM/pkg/common/config" "Open_IM/pkg/common/constant" - "Open_IM/pkg/common/db" imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model" rocksCache "Open_IM/pkg/common/db/rocks_cache" "Open_IM/pkg/common/log" @@ -106,7 +105,7 @@ func (s *organizationServer) CreateDepartment(ctx context.Context, req *rpc.Crea return &rpc.CreateDepartmentResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: errMsg}, nil } - department := db.Department{} + department := imdb.Department{} utils.CopyStructFields(&department, req.DepartmentInfo) if department.DepartmentID == "" { department.DepartmentID = utils.Md5(strconv.FormatInt(time.Now().UnixNano(), 10)) @@ -184,7 +183,7 @@ func (s *organizationServer) UpdateDepartment(ctx context.Context, req *rpc.Upda return &rpc.UpdateDepartmentResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: errMsg}, nil } - department := db.Department{} + department := imdb.Department{} utils.CopyStructFields(&department, req.DepartmentInfo) log.Debug(req.OperationID, "dst ", department, "src ", req.DepartmentInfo) if err := imdb.UpdateDepartment(&department, nil); err != nil { @@ -205,7 +204,7 @@ func (s *organizationServer) UpdateDepartment(ctx context.Context, req *rpc.Upda func (s *organizationServer) GetSubDepartment(ctx context.Context, req *rpc.GetSubDepartmentReq) (*rpc.GetSubDepartmentResp, error) { log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc args ", req.String()) - var departmentList []db.Department + var departmentList []imdb.Department var err error if req.DepartmentID == "-1" { departmentList, err = rocksCache.GetAllDepartmentsFromCache() @@ -301,7 +300,7 @@ func (s *organizationServer) CreateOrganizationUser(ctx context.Context, req *rp log.Error(req.OperationID, errMsg) return &rpc.CreateOrganizationUserResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: errMsg}, nil } - organizationUser := db.OrganizationUser{} + organizationUser := imdb.OrganizationUser{} utils.CopyStructFields(&organizationUser, req.OrganizationUser) organizationUser.Birth = utils.UnixSecondToTime(int64(req.OrganizationUser.Birth)) log.Debug(req.OperationID, "src ", *req.OrganizationUser, "dst ", organizationUser) @@ -325,7 +324,7 @@ func (s *organizationServer) UpdateOrganizationUser(ctx context.Context, req *rp log.Error(req.OperationID, errMsg) return &rpc.UpdateOrganizationUserResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: errMsg}, nil } - organizationUser := db.OrganizationUser{} + organizationUser := imdb.OrganizationUser{} utils.CopyStructFields(&organizationUser, req.OrganizationUser) if req.OrganizationUser.Birth != 0 { organizationUser.Birth = utils.UnixSecondToTime(int64(req.OrganizationUser.Birth)) @@ -361,7 +360,7 @@ func (s *organizationServer) CreateDepartmentMember(ctx context.Context, req *rp return &rpc.CreateDepartmentMemberResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: errMsg}, nil } - departmentMember := db.DepartmentMember{} + departmentMember := imdb.DepartmentMember{} utils.CopyStructFields(&departmentMember, req.DepartmentMember) log.Debug(req.OperationID, "src ", *req.DepartmentMember, "dst ", departmentMember) err = imdb.CreateDepartmentMember(&departmentMember) @@ -439,7 +438,7 @@ func (s *organizationServer) UpdateUserInDepartment(ctx context.Context, req *rp log.Error(req.OperationID, errMsg) return &rpc.UpdateUserInDepartmentResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: errMsg}, nil } - departmentMember := &db.DepartmentMember{} + departmentMember := &imdb.DepartmentMember{} utils.CopyStructFields(departmentMember, req.DepartmentMember) log.Debug(req.OperationID, "dst ", departmentMember, "src ", req.DepartmentMember) err := imdb.UpdateUserInDepartment(departmentMember, nil) @@ -497,7 +496,7 @@ func (s *organizationServer) DeleteOrganizationUser(ctx context.Context, req *rp func (s *organizationServer) GetDepartmentMember(ctx context.Context, req *rpc.GetDepartmentMemberReq) (*rpc.GetDepartmentMemberResp, error) { log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc args ", req.String()) - var departmentMemberList []db.DepartmentMember + var departmentMemberList []imdb.DepartmentMember var err error if req.DepartmentID == "-1" { departmentMemberList, err = rocksCache.GetAllDepartmentMembersFromCache() diff --git a/internal/rpc/user/user.go b/internal/rpc/user/user.go index b6a55ca0f..92fdabf20 100644 --- a/internal/rpc/user/user.go +++ b/internal/rpc/user/user.go @@ -100,7 +100,7 @@ func (s *userServer) Run() { } func syncPeerUserConversation(conversation *pbConversation.Conversation, operationID string) error { - peerUserConversation := db.Conversation{ + peerUserConversation := imdb.Conversation{ OwnerUserID: conversation.UserID, ConversationID: utils.GetConversationIDBySessionType(conversation.OwnerUserID, constant.SingleChatType), ConversationType: constant.SingleChatType, @@ -152,7 +152,7 @@ func (s *userServer) BatchSetConversations(ctx context.Context, req *pbUser.Batc } resp := &pbUser.BatchSetConversationsResp{} for _, v := range req.Conversations { - conversation := db.Conversation{} + conversation := imdb.Conversation{} if err := utils.CopyStructFields(&conversation, v); err != nil { log.NewDebug(req.OperationID, utils.GetSelfFuncName(), v.String(), "CopyStructFields failed", err.Error()) } @@ -265,7 +265,7 @@ func (s *userServer) SetConversation(ctx context.Context, req *pbUser.SetConvers return resp, nil } } - var conversation db.Conversation + var conversation imdb.Conversation if err := utils.CopyStructFields(&conversation, req.Conversation); err != nil { log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", *req.Conversation, err.Error()) } @@ -308,7 +308,7 @@ func (s *userServer) SetConversation(ctx context.Context, req *pbUser.SetConvers func (s *userServer) SetRecvMsgOpt(ctx context.Context, req *pbUser.SetRecvMsgOptReq) (*pbUser.SetRecvMsgOptResp, error) { log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String()) resp := &pbUser.SetRecvMsgOptResp{} - var conversation db.Conversation + var conversation imdb.Conversation if err := utils.CopyStructFields(&conversation, req); err != nil { log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", *req, err.Error()) } @@ -408,7 +408,7 @@ func (s *userServer) UpdateUserInfo(ctx context.Context, req *pbUser.UpdateUserI oldNickname = u.Nickname } } - var user db.User + var user imdb.User utils.CopyStructFields(&user, req.UserInfo) if req.UserInfo.BirthStr != "" { @@ -465,7 +465,7 @@ func (s *userServer) UpdateUserInfo(ctx context.Context, req *pbUser.UpdateUserI func (s *userServer) SetGlobalRecvMessageOpt(ctx context.Context, req *pbUser.SetGlobalRecvMessageOptReq) (*pbUser.SetGlobalRecvMessageOptResp, error) { log.NewInfo(req.OperationID, "SetGlobalRecvMessageOpt args ", req.String()) - var user db.User + var user imdb.User user.UserID = req.UserID m := make(map[string]interface{}, 1) @@ -496,7 +496,7 @@ func (s *userServer) SyncJoinedGroupMemberFaceURL(userID string, faceURL string, return } for _, groupID := range joinedGroupIDList { - groupMemberInfo := db.GroupMember{UserID: userID, GroupID: groupID, FaceURL: faceURL} + groupMemberInfo := imdb.GroupMember{UserID: userID, GroupID: groupID, FaceURL: faceURL} if err := imdb.UpdateGroupMemberInfo(groupMemberInfo); err != nil { log.NewError(operationID, utils.GetSelfFuncName(), err.Error(), groupMemberInfo) continue @@ -526,7 +526,7 @@ func (s *userServer) SyncJoinedGroupMemberNickname(userID string, newNickname, o continue } if member.Nickname == oldNickname { - groupMemberInfo := db.GroupMember{UserID: userID, GroupID: v, Nickname: newNickname} + groupMemberInfo := imdb.GroupMember{UserID: userID, GroupID: v, Nickname: newNickname} if err := imdb.UpdateGroupMemberInfo(groupMemberInfo); err != nil { log.NewError(operationID, utils.GetSelfFuncName(), err.Error(), groupMemberInfo) continue @@ -545,7 +545,7 @@ func (s *userServer) SyncJoinedGroupMemberNickname(userID string, newNickname, o func (s *userServer) GetUsers(ctx context.Context, req *pbUser.GetUsersReq) (*pbUser.GetUsersResp, error) { log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String()) - var usersDB []db.User + var usersDB []imdb.User var err error resp := &pbUser.GetUsersResp{CommonResp: &pbUser.CommonResp{}, Pagination: &sdkws.ResponsePagination{CurrentPage: req.Pagination.PageNumber, ShowNumber: req.Pagination.ShowNumber}} if req.UserID != "" { diff --git a/pkg/common/constant/error.go b/pkg/common/constant/error.go index 1f4934c95..2bad4baa6 100644 --- a/pkg/common/constant/error.go +++ b/pkg/common/constant/error.go @@ -8,8 +8,9 @@ import ( ) type ErrInfo struct { - ErrCode int32 - ErrMsg string + ErrCode int32 + ErrMsg string + WrapErrMsg string } func (e ErrInfo) Error() string { diff --git a/pkg/common/db/mysql.go b/pkg/common/db/mysql.go index 9c8bc93df..5ecdc302d 100644 --- a/pkg/common/db/mysql.go +++ b/pkg/common/db/mysql.go @@ -2,6 +2,7 @@ package db import ( "Open_IM/pkg/common/config" + "Open_IM/pkg/common/db/mysql_model/im_mysql_model" "fmt" "time" @@ -68,80 +69,80 @@ func initMysqlDB() { sqlDB.SetMaxIdleConns(config.Config.Mysql.DBMaxIdleConns) db.AutoMigrate( - &Register{}, - &Friend{}, - &FriendRequest{}, - &Group{}, - &GroupMember{}, - &GroupRequest{}, - &User{}, - &Black{}, &ChatLog{}, &Register{}, &Conversation{}, &AppVersion{}, &Department{}, &BlackList{}, &IpLimit{}, &UserIpLimit{}, &Invitation{}, &RegisterAddFriend{}, - &ClientInitConfig{}, &UserIpRecord{}) + &im_mysql_model.Register{}, + &im_mysql_model.Friend{}, + &im_mysql_model.FriendRequest{}, + &im_mysql_model.Group{}, + &im_mysql_model.GroupMember{}, + &im_mysql_model.GroupRequest{}, + &im_mysql_model.User{}, + &im_mysql_model.Black{}, &im_mysql_model.ChatLog{}, &im_mysql_model.Register{}, &im_mysql_model.Conversation{}, &im_mysql_model.AppVersion{}, &im_mysql_model.Department{}, &im_mysql_model.BlackList{}, &im_mysql_model.IpLimit{}, &im_mysql_model.UserIpLimit{}, &im_mysql_model.Invitation{}, &im_mysql_model.RegisterAddFriend{}, + &im_mysql_model.ClientInitConfig{}, &im_mysql_model.UserIpRecord{}) db.Set("gorm:table_options", "CHARSET=utf8") db.Set("gorm:table_options", "collation=utf8_unicode_ci") - if !db.Migrator().HasTable(&Friend{}) { - db.Migrator().CreateTable(&Friend{}) + if !db.Migrator().HasTable(&im_mysql_model.Friend{}) { + db.Migrator().CreateTable(&im_mysql_model.Friend{}) } - if !db.Migrator().HasTable(&FriendRequest{}) { - db.Migrator().CreateTable(&FriendRequest{}) + if !db.Migrator().HasTable(&im_mysql_model.FriendRequest{}) { + db.Migrator().CreateTable(&im_mysql_model.FriendRequest{}) } - if !db.Migrator().HasTable(&Group{}) { - db.Migrator().CreateTable(&Group{}) + if !db.Migrator().HasTable(&im_mysql_model.Group{}) { + db.Migrator().CreateTable(&im_mysql_model.Group{}) } - if !db.Migrator().HasTable(&GroupMember{}) { - db.Migrator().CreateTable(&GroupMember{}) + if !db.Migrator().HasTable(&im_mysql_model.GroupMember{}) { + db.Migrator().CreateTable(&im_mysql_model.GroupMember{}) } - if !db.Migrator().HasTable(&GroupRequest{}) { - db.Migrator().CreateTable(&GroupRequest{}) + if !db.Migrator().HasTable(&im_mysql_model.GroupRequest{}) { + db.Migrator().CreateTable(&im_mysql_model.GroupRequest{}) } - if !db.Migrator().HasTable(&User{}) { - db.Migrator().CreateTable(&User{}) + if !db.Migrator().HasTable(&im_mysql_model.User{}) { + db.Migrator().CreateTable(&im_mysql_model.User{}) } - if !db.Migrator().HasTable(&Black{}) { - db.Migrator().CreateTable(&Black{}) + if !db.Migrator().HasTable(&im_mysql_model.Black{}) { + db.Migrator().CreateTable(&im_mysql_model.Black{}) } - if !db.Migrator().HasTable(&ChatLog{}) { - db.Migrator().CreateTable(&ChatLog{}) + if !db.Migrator().HasTable(&im_mysql_model.ChatLog{}) { + db.Migrator().CreateTable(&im_mysql_model.ChatLog{}) } - if !db.Migrator().HasTable(&Register{}) { - db.Migrator().CreateTable(&Register{}) + if !db.Migrator().HasTable(&im_mysql_model.Register{}) { + db.Migrator().CreateTable(&im_mysql_model.Register{}) } - if !db.Migrator().HasTable(&Conversation{}) { - db.Migrator().CreateTable(&Conversation{}) + if !db.Migrator().HasTable(&im_mysql_model.Conversation{}) { + db.Migrator().CreateTable(&im_mysql_model.Conversation{}) } - if !db.Migrator().HasTable(&Department{}) { - db.Migrator().CreateTable(&Department{}) + if !db.Migrator().HasTable(&im_mysql_model.Department{}) { + db.Migrator().CreateTable(&im_mysql_model.Department{}) } - if !db.Migrator().HasTable(&OrganizationUser{}) { - db.Migrator().CreateTable(&OrganizationUser{}) + if !db.Migrator().HasTable(&im_mysql_model.OrganizationUser{}) { + db.Migrator().CreateTable(&im_mysql_model.OrganizationUser{}) } - if !db.Migrator().HasTable(&DepartmentMember{}) { - db.Migrator().CreateTable(&DepartmentMember{}) + if !db.Migrator().HasTable(&im_mysql_model.DepartmentMember{}) { + db.Migrator().CreateTable(&im_mysql_model.DepartmentMember{}) } - if !db.Migrator().HasTable(&AppVersion{}) { - db.Migrator().CreateTable(&AppVersion{}) + if !db.Migrator().HasTable(&im_mysql_model.AppVersion{}) { + db.Migrator().CreateTable(&im_mysql_model.AppVersion{}) } - if !db.Migrator().HasTable(&BlackList{}) { - db.Migrator().CreateTable(&BlackList{}) + if !db.Migrator().HasTable(&im_mysql_model.BlackList{}) { + db.Migrator().CreateTable(&im_mysql_model.BlackList{}) } - if !db.Migrator().HasTable(&IpLimit{}) { - db.Migrator().CreateTable(&IpLimit{}) + if !db.Migrator().HasTable(&im_mysql_model.IpLimit{}) { + db.Migrator().CreateTable(&im_mysql_model.IpLimit{}) } - if !db.Migrator().HasTable(&UserIpLimit{}) { - db.Migrator().CreateTable(&UserIpLimit{}) + if !db.Migrator().HasTable(&im_mysql_model.UserIpLimit{}) { + db.Migrator().CreateTable(&im_mysql_model.UserIpLimit{}) } - if !db.Migrator().HasTable(&RegisterAddFriend{}) { - db.Migrator().CreateTable(&RegisterAddFriend{}) + if !db.Migrator().HasTable(&im_mysql_model.RegisterAddFriend{}) { + db.Migrator().CreateTable(&im_mysql_model.RegisterAddFriend{}) } - if !db.Migrator().HasTable(&Invitation{}) { - db.Migrator().CreateTable(&Invitation{}) + if !db.Migrator().HasTable(&im_mysql_model.Invitation{}) { + db.Migrator().CreateTable(&im_mysql_model.Invitation{}) } - if !db.Migrator().HasTable(&ClientInitConfig{}) { - db.Migrator().CreateTable(&ClientInitConfig{}) + if !db.Migrator().HasTable(&im_mysql_model.ClientInitConfig{}) { + db.Migrator().CreateTable(&im_mysql_model.ClientInitConfig{}) } - if !db.Migrator().HasTable(&UserIpRecord{}) { - db.Migrator().CreateTable(&UserIpRecord{}) + if !db.Migrator().HasTable(&im_mysql_model.UserIpRecord{}) { + db.Migrator().CreateTable(&im_mysql_model.UserIpRecord{}) } DB.MysqlDB.db = db } diff --git a/pkg/common/db/mysql_model/im_mysql_model/client_config.go b/pkg/common/db/mysql_model/im_mysql_model/client_config.go index 08300cefe..8558c13c7 100644 --- a/pkg/common/db/mysql_model/im_mysql_model/client_config.go +++ b/pkg/common/db/mysql_model/im_mysql_model/client_config.go @@ -3,20 +3,20 @@ package im_mysql_model import "Open_IM/pkg/common/db" func SetClientInitConfig(m map[string]interface{}) error { - result := db.DB.MysqlDB.DefaultGormDB().Model(&db.ClientInitConfig{}).Where("1=1").Updates(m) + result := db.DB.MysqlDB.DefaultGormDB().Model(&ClientInitConfig{}).Where("1=1").Updates(m) if result.Error != nil { return result.Error } if result.RowsAffected == 0 { - err := db.DB.MysqlDB.DefaultGormDB().Model(&db.ClientInitConfig{}).Create(m).Error + err := db.DB.MysqlDB.DefaultGormDB().Model(&ClientInitConfig{}).Create(m).Error return err } return nil } -func GetClientInitConfig() (db.ClientInitConfig, error) { - var config db.ClientInitConfig - err := db.DB.MysqlDB.DefaultGormDB().Model(&db.ClientInitConfig{}).First(&config).Error +func GetClientInitConfig() (ClientInitConfig, error) { + var config ClientInitConfig + err := db.DB.MysqlDB.DefaultGormDB().Model(&ClientInitConfig{}).First(&config).Error return config, err } diff --git a/pkg/common/db/mysql_model/im_mysql_model/conversation_model.go b/pkg/common/db/mysql_model/im_mysql_model/conversation_model.go index ac1be495f..2cdda359a 100644 --- a/pkg/common/db/mysql_model/im_mysql_model/conversation_model.go +++ b/pkg/common/db/mysql_model/im_mysql_model/conversation_model.go @@ -6,12 +6,12 @@ import ( "Open_IM/pkg/utils" ) -func SetConversation(conversation db.Conversation) (bool, error) { +func SetConversation(conversation Conversation) (bool, error) { var isUpdate bool newConversation := conversation - if db.DB.MysqlDB.DefaultGormDB().Model(&db.Conversation{}).Find(&newConversation).RowsAffected == 0 { + if db.DB.MysqlDB.DefaultGormDB().Model(&Conversation{}).Find(&newConversation).RowsAffected == 0 { log.NewDebug("", utils.GetSelfFuncName(), "conversation", conversation, "not exist in db, create") - return isUpdate, db.DB.MysqlDB.DefaultGormDB().Model(&db.Conversation{}).Create(&conversation).Error + return isUpdate, db.DB.MysqlDB.DefaultGormDB().Model(&Conversation{}).Create(&conversation).Error // if exist, then update record } else { log.NewDebug("", utils.GetSelfFuncName(), "conversation", conversation, "exist in db, update") @@ -22,16 +22,16 @@ func SetConversation(conversation db.Conversation) (bool, error) { "group_at_type": conversation.GroupAtType, "is_not_in_group": conversation.IsNotInGroup}).Error } } -func SetOneConversation(conversation db.Conversation) error { - return db.DB.MysqlDB.DefaultGormDB().Model(&db.Conversation{}).Create(&conversation).Error +func SetOneConversation(conversation Conversation) error { + return db.DB.MysqlDB.DefaultGormDB().Model(&Conversation{}).Create(&conversation).Error } -func PeerUserSetConversation(conversation db.Conversation) error { +func PeerUserSetConversation(conversation Conversation) error { newConversation := conversation - if db.DB.MysqlDB.DefaultGormDB().Model(&db.Conversation{}).Find(&newConversation).RowsAffected == 0 { + if db.DB.MysqlDB.DefaultGormDB().Model(&Conversation{}).Find(&newConversation).RowsAffected == 0 { log.NewDebug("", utils.GetSelfFuncName(), "conversation", conversation, "not exist in db, create") - return db.DB.MysqlDB.DefaultGormDB().Model(&db.Conversation{}).Create(&conversation).Error + return db.DB.MysqlDB.DefaultGormDB().Model(&Conversation{}).Create(&conversation).Error // if exist, then update record } log.NewDebug("", utils.GetSelfFuncName(), "conversation", conversation, "exist in db, update") @@ -41,12 +41,12 @@ func PeerUserSetConversation(conversation db.Conversation) error { } -func SetRecvMsgOpt(conversation db.Conversation) (bool, error) { +func SetRecvMsgOpt(conversation Conversation) (bool, error) { var isUpdate bool newConversation := conversation - if db.DB.MysqlDB.DefaultGormDB().Model(&db.Conversation{}).Find(&newConversation).RowsAffected == 0 { + if db.DB.MysqlDB.DefaultGormDB().Model(&Conversation{}).Find(&newConversation).RowsAffected == 0 { log.NewDebug("", utils.GetSelfFuncName(), "conversation", conversation, "not exist in db, create") - return isUpdate, db.DB.MysqlDB.DefaultGormDB().Model(&db.Conversation{}).Create(&conversation).Error + return isUpdate, db.DB.MysqlDB.DefaultGormDB().Model(&Conversation{}).Create(&conversation).Error // if exist, then update record } else { log.NewDebug("", utils.GetSelfFuncName(), "conversation", conversation, "exist in db, update") @@ -57,14 +57,14 @@ func SetRecvMsgOpt(conversation db.Conversation) (bool, error) { } } -func GetUserAllConversations(ownerUserID string) ([]db.Conversation, error) { - var conversations []db.Conversation - err := db.DB.MysqlDB.DefaultGormDB().Model(&db.Conversation{}).Where("owner_user_id=?", ownerUserID).Find(&conversations).Error +func GetUserAllConversations(ownerUserID string) ([]Conversation, error) { + var conversations []Conversation + err := db.DB.MysqlDB.DefaultGormDB().Model(&Conversation{}).Where("owner_user_id=?", ownerUserID).Find(&conversations).Error return conversations, err } -func GetMultipleUserConversationByConversationID(ownerUserIDList []string, conversationID string) ([]db.Conversation, error) { - var conversations []db.Conversation - err := db.DB.MysqlDB.DefaultGormDB().Model(&db.Conversation{}).Where("owner_user_id IN ? and conversation_id=?", ownerUserIDList, conversationID).Find(&conversations).Error +func GetMultipleUserConversationByConversationID(ownerUserIDList []string, conversationID string) ([]Conversation, error) { + var conversations []Conversation + err := db.DB.MysqlDB.DefaultGormDB().Model(&Conversation{}).Where("owner_user_id IN ? and conversation_id=?", ownerUserIDList, conversationID).Find(&conversations).Error return conversations, err } func GetExistConversationUserIDList(ownerUserIDList []string, conversationID string) ([]string, error) { @@ -76,31 +76,31 @@ func GetExistConversationUserIDList(ownerUserIDList []string, conversationID str return resultArr, nil } -func GetConversation(OwnerUserID, conversationID string) (db.Conversation, error) { - var conversation db.Conversation +func GetConversation(OwnerUserID, conversationID string) (Conversation, error) { + var conversation Conversation err := db.DB.MysqlDB.DefaultGormDB().Table("conversations").Where("owner_user_id=? and conversation_id=?", OwnerUserID, conversationID).Take(&conversation).Error return conversation, err } -func GetConversations(OwnerUserID string, conversationIDs []string) ([]db.Conversation, error) { - var conversations []db.Conversation - err := db.DB.MysqlDB.DefaultGormDB().Model(&db.Conversation{}).Where("conversation_id IN (?) and owner_user_id=?", conversationIDs, OwnerUserID).Find(&conversations).Error +func GetConversations(OwnerUserID string, conversationIDs []string) ([]Conversation, error) { + var conversations []Conversation + err := db.DB.MysqlDB.DefaultGormDB().Model(&Conversation{}).Where("conversation_id IN (?) and owner_user_id=?", conversationIDs, OwnerUserID).Find(&conversations).Error return conversations, err } -func GetConversationsByConversationIDMultipleOwner(OwnerUserIDList []string, conversationID string) ([]db.Conversation, error) { - var conversations []db.Conversation - err := db.DB.MysqlDB.DefaultGormDB().Model(&db.Conversation{}).Where("owner_user_id IN (?) and conversation_id=?", OwnerUserIDList, conversationID).Find(&conversations).Error +func GetConversationsByConversationIDMultipleOwner(OwnerUserIDList []string, conversationID string) ([]Conversation, error) { + var conversations []Conversation + err := db.DB.MysqlDB.DefaultGormDB().Model(&Conversation{}).Where("owner_user_id IN (?) and conversation_id=?", OwnerUserIDList, conversationID).Find(&conversations).Error return conversations, err } func UpdateColumnsConversations(ownerUserIDList []string, conversationID string, args map[string]interface{}) error { - return db.DB.MysqlDB.DefaultGormDB().Model(&db.Conversation{}).Where("owner_user_id IN (?) and conversation_id=?", ownerUserIDList, conversationID).Updates(args).Error + return db.DB.MysqlDB.DefaultGormDB().Model(&Conversation{}).Where("owner_user_id IN (?) and conversation_id=?", ownerUserIDList, conversationID).Updates(args).Error } func GetConversationIDListByUserID(userID string) ([]string, error) { var IDList []string - err := db.DB.MysqlDB.DefaultGormDB().Model(&db.Conversation{}).Where("owner_user_id=?", userID).Pluck("conversation_id", &IDList).Error + err := db.DB.MysqlDB.DefaultGormDB().Model(&Conversation{}).Where("owner_user_id=?", userID).Pluck("conversation_id", &IDList).Error return IDList, err } diff --git a/pkg/common/db/mysql_model/im_mysql_model/demo_model.go b/pkg/common/db/mysql_model/im_mysql_model/demo_model.go index b023d2b40..2812e788e 100644 --- a/pkg/common/db/mysql_model/im_mysql_model/demo_model.go +++ b/pkg/common/db/mysql_model/im_mysql_model/demo_model.go @@ -7,19 +7,19 @@ import ( _ "gorm.io/gorm" ) -func GetRegister(account, areaCode, userID string) (*db.Register, error) { - var r db.Register +func GetRegister(account, areaCode, userID string) (*Register, error) { + var r Register return &r, db.DB.MysqlDB.DefaultGormDB().Table("registers").Where("user_id = ? and user_id != ? or account = ? or account =? and area_code=?", userID, "", account, account, areaCode).Take(&r).Error } -func GetRegisterInfo(userID string) (*db.Register, error) { - var r db.Register +func GetRegisterInfo(userID string) (*Register, error) { + var r Register return &r, db.DB.MysqlDB.DefaultGormDB().Table("registers").Where("user_id = ?", userID).Take(&r).Error } func SetPassword(account, password, ex, userID, areaCode, ip string) error { - r := db.Register{ + r := Register{ Account: account, Password: password, Ex: ex, @@ -31,7 +31,7 @@ func SetPassword(account, password, ex, userID, areaCode, ip string) error { } func ResetPassword(account, password string) error { - r := db.Register{ + r := Register{ Password: password, } return db.DB.MysqlDB.DefaultGormDB().Table("registers").Where("account = ?", account).Updates(&r).Error @@ -40,7 +40,7 @@ func ResetPassword(account, password string) error { func GetRegisterAddFriendList(showNumber, pageNumber int32) ([]string, error) { var IDList []string var err error - model := db.DB.MysqlDB.DefaultGormDB().Model(&db.RegisterAddFriend{}) + model := db.DB.MysqlDB.DefaultGormDB().Model(&RegisterAddFriend{}) if showNumber == 0 { err = model.Pluck("user_id", &IDList).Error } else { @@ -50,9 +50,9 @@ func GetRegisterAddFriendList(showNumber, pageNumber int32) ([]string, error) { } func AddUserRegisterAddFriendIDList(userIDList ...string) error { - var list []db.RegisterAddFriend + var list []RegisterAddFriend for _, v := range userIDList { - list = append(list, db.RegisterAddFriend{UserID: v}) + list = append(list, RegisterAddFriend{UserID: v}) } result := db.DB.MysqlDB.DefaultGormDB().Create(list) if int(result.RowsAffected) < len(userIDList) { @@ -63,22 +63,22 @@ func AddUserRegisterAddFriendIDList(userIDList ...string) error { } func ReduceUserRegisterAddFriendIDList(userIDList ...string) error { - var list []db.RegisterAddFriend + var list []RegisterAddFriend for _, v := range userIDList { - list = append(list, db.RegisterAddFriend{UserID: v}) + list = append(list, RegisterAddFriend{UserID: v}) } err := db.DB.MysqlDB.DefaultGormDB().Delete(list).Error return err } func DeleteAllRegisterAddFriendIDList() error { - err := db.DB.MysqlDB.DefaultGormDB().Where("1 = 1").Delete(&db.RegisterAddFriend{}).Error + err := db.DB.MysqlDB.DefaultGormDB().Where("1 = 1").Delete(&RegisterAddFriend{}).Error return err } -func GetUserIPLimit(userID string) (db.UserIpLimit, error) { - var limit db.UserIpLimit +func GetUserIPLimit(userID string) (UserIpLimit, error) { + var limit UserIpLimit limit.UserID = userID - err := db.DB.MysqlDB.DefaultGormDB().Model(&db.UserIpLimit{}).Take(&limit).Error + err := db.DB.MysqlDB.DefaultGormDB().Model(&UserIpLimit{}).Take(&limit).Error return limit, err } diff --git a/pkg/common/db/mysql_model/im_mysql_model/file_model.go b/pkg/common/db/mysql_model/im_mysql_model/file_model.go index 959bb6cf1..fc42ebc24 100644 --- a/pkg/common/db/mysql_model/im_mysql_model/file_model.go +++ b/pkg/common/db/mysql_model/im_mysql_model/file_model.go @@ -7,7 +7,7 @@ import ( func UpdateAppVersion(appType int, version string, forceUpdate bool, fileName, yamlName, updateLog string) error { updateTime := int(time.Now().Unix()) - app := db.AppVersion{ + app := AppVersion{ Version: version, Type: appType, UpdateTime: updateTime, @@ -16,7 +16,7 @@ func UpdateAppVersion(appType int, version string, forceUpdate bool, fileName, y ForceUpdate: forceUpdate, UpdateLog: updateLog, } - result := db.DB.MysqlDB.DefaultGormDB().Model(db.AppVersion{}).Where("type = ?", appType).Updates(map[string]interface{}{"force_update": forceUpdate, + result := db.DB.MysqlDB.DefaultGormDB().Model(AppVersion{}).Where("type = ?", appType).Updates(map[string]interface{}{"force_update": forceUpdate, "version": version, "update_time": int(time.Now().Unix()), "file_name": fileName, "yaml_name": yamlName, "type": appType, "update_log": updateLog}) if result.Error != nil { return result.Error @@ -28,7 +28,7 @@ func UpdateAppVersion(appType int, version string, forceUpdate bool, fileName, y return nil } -func GetNewestVersion(appType int) (*db.AppVersion, error) { - app := db.AppVersion{} - return &app, db.DB.MysqlDB.DefaultGormDB().Model(db.AppVersion{}).First(&app, appType).Error +func GetNewestVersion(appType int) (*AppVersion, error) { + app := AppVersion{} + return &app, db.DB.MysqlDB.DefaultGormDB().Model(AppVersion{}).First(&app, appType).Error } diff --git a/pkg/common/db/mysql_model/im_mysql_model/friend_model.go b/pkg/common/db/mysql_model/im_mysql_model/friend_model.go index 4e4340d84..1cb41d1f3 100644 --- a/pkg/common/db/mysql_model/im_mysql_model/friend_model.go +++ b/pkg/common/db/mysql_model/im_mysql_model/friend_model.go @@ -6,7 +6,7 @@ import ( "time" ) -func InsertToFriend(toInsertFollow *db.Friend) error { +func InsertToFriend(toInsertFollow *Friend) error { toInsertFollow.CreateTime = time.Now() err := db.DB.MysqlDB.DefaultGormDB().Table("friends").Create(toInsertFollow).Error if err != nil { @@ -15,8 +15,8 @@ func InsertToFriend(toInsertFollow *db.Friend) error { return nil } -func GetFriendRelationshipFromFriend(OwnerUserID, FriendUserID string) (*db.Friend, error) { - var friend db.Friend +func GetFriendRelationshipFromFriend(OwnerUserID, FriendUserID string) (*Friend, error) { + var friend Friend err := db.DB.MysqlDB.DefaultGormDB().Table("friends").Where("owner_user_id=? and friend_user_id=?", OwnerUserID, FriendUserID).Take(&friend).Error if err != nil { return nil, err @@ -24,9 +24,9 @@ func GetFriendRelationshipFromFriend(OwnerUserID, FriendUserID string) (*db.Frie return &friend, err } -func GetFriendListByUserID(OwnerUserID string) ([]db.Friend, error) { - var friends []db.Friend - var x db.Friend +func GetFriendListByUserID(OwnerUserID string) ([]Friend, error) { + var friends []Friend + var x Friend x.OwnerUserID = OwnerUserID err := db.DB.MysqlDB.DefaultGormDB().Table("friends").Where("owner_user_id=?", OwnerUserID).Find(&friends).Error if err != nil { @@ -49,11 +49,11 @@ func UpdateFriendComment(OwnerUserID, FriendUserID, Remark string) error { } func DeleteSingleFriendInfo(OwnerUserID, FriendUserID string) error { - return db.DB.MysqlDB.DefaultGormDB().Table("friends").Where("owner_user_id=? and friend_user_id=?", OwnerUserID, FriendUserID).Delete(db.Friend{}).Error + return db.DB.MysqlDB.DefaultGormDB().Table("friends").Where("owner_user_id=? and friend_user_id=?", OwnerUserID, FriendUserID).Delete(Friend{}).Error } type FriendUser struct { - db.Friend + Friend Nickname string `gorm:"column:name;size:255"` } 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 633f605e1..0602814bb 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 @@ -19,8 +19,8 @@ import ( //} // who apply to add me -func GetReceivedFriendsApplicationListByUserID(ToUserID string) ([]db.FriendRequest, error) { - var usersInfo []db.FriendRequest +func GetReceivedFriendsApplicationListByUserID(ToUserID string) ([]FriendRequest, error) { + var usersInfo []FriendRequest err := db.DB.MysqlDB.DefaultGormDB().Table("friend_requests").Where("to_user_id=?", ToUserID).Find(&usersInfo).Error if err != nil { return nil, err @@ -28,9 +28,9 @@ func GetReceivedFriendsApplicationListByUserID(ToUserID string) ([]db.FriendRequ return usersInfo, nil } -//I apply to add somebody -func GetSendFriendApplicationListByUserID(FromUserID string) ([]db.FriendRequest, error) { - var usersInfo []db.FriendRequest +// I apply to add somebody +func GetSendFriendApplicationListByUserID(FromUserID string) ([]FriendRequest, error) { + var usersInfo []FriendRequest err := db.DB.MysqlDB.DefaultGormDB().Table("friend_requests").Where("from_user_id=?", FromUserID).Find(&usersInfo).Error if err != nil { return nil, err @@ -38,9 +38,9 @@ func GetSendFriendApplicationListByUserID(FromUserID string) ([]db.FriendRequest return usersInfo, nil } -//FromUserId apply to add ToUserID -func GetFriendApplicationByBothUserID(FromUserID, ToUserID string) (*db.FriendRequest, error) { - var friendRequest db.FriendRequest +// FromUserId apply to add ToUserID +func GetFriendApplicationByBothUserID(FromUserID, ToUserID string) (*FriendRequest, error) { + var friendRequest FriendRequest err := db.DB.MysqlDB.DefaultGormDB().Table("friend_requests").Where("from_user_id=? and to_user_id=?", FromUserID, ToUserID).Take(&friendRequest).Error if err != nil { return nil, err @@ -48,13 +48,13 @@ func GetFriendApplicationByBothUserID(FromUserID, ToUserID string) (*db.FriendRe return &friendRequest, nil } -func UpdateFriendApplication(friendRequest *db.FriendRequest) error { +func UpdateFriendApplication(friendRequest *FriendRequest) error { friendRequest.CreateTime = time.Now() return db.DB.MysqlDB.DefaultGormDB().Table("friend_requests").Where("from_user_id=? and to_user_id=?", friendRequest.FromUserID, friendRequest.ToUserID).Updates(&friendRequest).Error } -func InsertFriendApplication(friendRequest *db.FriendRequest, args map[string]interface{}) error { +func InsertFriendApplication(friendRequest *FriendRequest, args map[string]interface{}) error { if err := db.DB.MysqlDB.DefaultGormDB().Table("friend_requests").Create(friendRequest).Error; err == nil { return nil } 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 607f8fabe..d3187d88c 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 @@ -20,7 +20,7 @@ import ( // Ex string `gorm:"column:ex"` //} -func InsertIntoGroupMember(toInsertInfo db.GroupMember) error { +func InsertIntoGroupMember(toInsertInfo GroupMember) error { toInsertInfo.JoinTime = time.Now() if toInsertInfo.RoleLevel == 0 { toInsertInfo.RoleLevel = constant.GroupOrdinaryUsers @@ -33,7 +33,7 @@ func InsertIntoGroupMember(toInsertInfo db.GroupMember) error { return nil } -func BatchInsertIntoGroupMember(toInsertInfoList []*db.GroupMember) error { +func BatchInsertIntoGroupMember(toInsertInfoList []*GroupMember) error { for _, toInsertInfo := range toInsertInfoList { toInsertInfo.JoinTime = time.Now() if toInsertInfo.RoleLevel == 0 { @@ -45,8 +45,8 @@ func BatchInsertIntoGroupMember(toInsertInfoList []*db.GroupMember) error { } -func GetGroupMemberListByUserID(userID string) ([]db.GroupMember, error) { - var groupMemberList []db.GroupMember +func GetGroupMemberListByUserID(userID string) ([]GroupMember, error) { + var groupMemberList []GroupMember err := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("user_id=?", userID).Find(&groupMemberList).Error if err != nil { return nil, err @@ -54,8 +54,8 @@ func GetGroupMemberListByUserID(userID string) ([]db.GroupMember, error) { return groupMemberList, nil } -func GetGroupMemberListByGroupID(groupID string) ([]db.GroupMember, error) { - var groupMemberList []db.GroupMember +func GetGroupMemberListByGroupID(groupID string) ([]GroupMember, error) { + var groupMemberList []GroupMember err := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=?", groupID).Find(&groupMemberList).Error if err != nil { return nil, err @@ -72,8 +72,8 @@ func GetGroupMemberIDListByGroupID(groupID string) ([]string, error) { return groupMemberIDList, nil } -func GetGroupMemberListByGroupIDAndRoleLevel(groupID string, roleLevel int32) ([]db.GroupMember, error) { - var groupMemberList []db.GroupMember +func GetGroupMemberListByGroupIDAndRoleLevel(groupID string, roleLevel int32) ([]GroupMember, error) { + var groupMemberList []GroupMember err := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=? and role_level=?", groupID, roleLevel).Find(&groupMemberList).Error if err != nil { return nil, err @@ -81,8 +81,8 @@ func GetGroupMemberListByGroupIDAndRoleLevel(groupID string, roleLevel int32) ([ return groupMemberList, nil } -func GetGroupMemberInfoByGroupIDAndUserID(groupID, userID string) (*db.GroupMember, error) { - var groupMember db.GroupMember +func GetGroupMemberInfoByGroupIDAndUserID(groupID, userID string) (*GroupMember, error) { + var groupMember GroupMember err := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=? and user_id=? ", groupID, userID).Limit(1).Take(&groupMember).Error if err != nil { return nil, err @@ -91,23 +91,23 @@ func GetGroupMemberInfoByGroupIDAndUserID(groupID, userID string) (*db.GroupMemb } func DeleteGroupMemberByGroupIDAndUserID(groupID, userID string) error { - return db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=? and user_id=? ", groupID, userID).Delete(db.GroupMember{}).Error + return db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=? and user_id=? ", groupID, userID).Delete(GroupMember{}).Error } func DeleteGroupMemberByGroupID(groupID string) error { - return db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=? ", groupID).Delete(db.GroupMember{}).Error + return db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=? ", groupID).Delete(GroupMember{}).Error } -func UpdateGroupMemberInfo(groupMemberInfo db.GroupMember) error { +func UpdateGroupMemberInfo(groupMemberInfo GroupMember) error { return db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=? and user_id=?", groupMemberInfo.GroupID, groupMemberInfo.UserID).Updates(&groupMemberInfo).Error } -func UpdateGroupMemberInfoByMap(groupMemberInfo db.GroupMember, m map[string]interface{}) error { +func UpdateGroupMemberInfoByMap(groupMemberInfo GroupMember, m map[string]interface{}) error { return db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=? and user_id=?", groupMemberInfo.GroupID, groupMemberInfo.UserID).Updates(m).Error } -func GetOwnerManagerByGroupID(groupID string) ([]db.GroupMember, error) { - var groupMemberList []db.GroupMember +func GetOwnerManagerByGroupID(groupID string) ([]GroupMember, error) { + var groupMemberList []GroupMember err := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=? and role_level>?", groupID, constant.GroupOrdinaryUsers).Find(&groupMemberList).Error if err != nil { return nil, err @@ -124,7 +124,7 @@ func GetGroupMemberNumByGroupID(groupID string) (int64, error) { return number, nil } -func GetGroupOwnerInfoByGroupID(groupID string) (*db.GroupMember, error) { +func GetGroupOwnerInfoByGroupID(groupID string) (*GroupMember, error) { omList, err := GetOwnerManagerByGroupID(groupID) if err != nil { return nil, err @@ -149,8 +149,8 @@ func IsExistGroupMember(groupID, userID string) bool { return true } -func GetGroupMemberByGroupID(groupID string, filter int32, begin int32, maxNumber int32) ([]db.GroupMember, error) { - var memberList []db.GroupMember +func GetGroupMemberByGroupID(groupID string, filter int32, begin int32, maxNumber int32) ([]GroupMember, error) { + var memberList []GroupMember var err error if filter >= 0 { memberList, err = GetGroupMemberListByGroupIDAndRoleLevel(groupID, filter) //sorted by join time @@ -199,8 +199,8 @@ func IsGroupOwnerAdmin(groupID, UserID string) bool { return false } -func GetGroupMembersByGroupIdCMS(groupId string, userName string, showNumber, pageNumber int32) ([]db.GroupMember, error) { - var groupMembers []db.GroupMember +func GetGroupMembersByGroupIdCMS(groupId string, userName string, showNumber, pageNumber int32) ([]GroupMember, error) { + var groupMembers []GroupMember err := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=?", groupId).Where(fmt.Sprintf(" nickname like '%%%s%%' ", userName)).Limit(int(showNumber)).Offset(int(showNumber * (pageNumber - 1))).Find(&groupMembers).Error if err != nil { return nil, err @@ -216,7 +216,7 @@ func GetGroupMembersCount(groupID, userName string) (int64, error) { return count, nil } -func UpdateGroupMemberInfoDefaultZero(groupMemberInfo db.GroupMember, args map[string]interface{}) error { +func UpdateGroupMemberInfoDefaultZero(groupMemberInfo GroupMember, args map[string]interface{}) error { return db.DB.MysqlDB.DefaultGormDB().Model(groupMemberInfo).Updates(args).Error } diff --git a/pkg/common/db/mysql_model/im_mysql_model/group_model.go b/pkg/common/db/mysql_model/im_mysql_model/group_model.go index ac90e6882..0be29c817 100644 --- a/pkg/common/db/mysql_model/im_mysql_model/group_model.go +++ b/pkg/common/db/mysql_model/im_mysql_model/group_model.go @@ -22,7 +22,7 @@ import ( // Ex string `gorm:"column:ex"` //} -func InsertIntoGroup(groupInfo db.Group) error { +func InsertIntoGroup(groupInfo Group) error { if groupInfo.GroupName == "" { groupInfo.GroupName = "Group Chat" } @@ -38,24 +38,24 @@ func InsertIntoGroup(groupInfo db.Group) error { return nil } -func TakeGroupInfoByGroupID(groupID string) (*db.Group, error) { - var groupInfo db.Group +func TakeGroupInfoByGroupID(groupID string) (*Group, error) { + var groupInfo Group err := db.DB.MysqlDB.DefaultGormDB().Table("groups").Where("group_id=?", groupID).Take(&groupInfo).Error return &groupInfo, err } -func GetGroupInfoByGroupID(groupID string) (*db.Group, error) { - var groupInfo db.Group +func GetGroupInfoByGroupID(groupID string) (*Group, error) { + var groupInfo Group err := db.DB.MysqlDB.DefaultGormDB().Table("groups").Where("group_id=?", groupID).Take(&groupInfo).Error return &groupInfo, err } -func SetGroupInfo(groupInfo db.Group) error { +func SetGroupInfo(groupInfo Group) error { return db.DB.MysqlDB.DefaultGormDB().Table("groups").Where("group_id=?", groupInfo.GroupID).Updates(&groupInfo).Error } type GroupWithNum struct { - db.Group + Group MemberCount int `gorm:"column:num"` } @@ -81,7 +81,7 @@ func GetGroups(pageNumber, showNumber int) ([]GroupWithNum, error) { } func OperateGroupStatus(groupId string, groupStatus int32) error { - group := db.Group{ + group := Group{ GroupID: groupId, Status: groupStatus, } @@ -91,7 +91,7 @@ func OperateGroupStatus(groupId string, groupStatus int32) error { return nil } -func GetGroupsCountNum(group db.Group) (int32, error) { +func GetGroupsCountNum(group Group) (int32, error) { var count int64 if err := db.DB.MysqlDB.DefaultGormDB().Table("groups").Where(" name like ? ", fmt.Sprintf("%%%s%%", group.GroupName)).Count(&count).Error; err != nil { return 0, 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 c13ca29f1..d14506eb9 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 @@ -19,14 +19,14 @@ import ( // Ex string `gorm:"column:ex"` //} -func UpdateGroupRequest(groupRequest db.GroupRequest) error { +func UpdateGroupRequest(groupRequest GroupRequest) error { if groupRequest.HandledTime.Unix() < 0 { groupRequest.HandledTime = utils.UnixSecondToTime(0) } return db.DB.MysqlDB.DefaultGormDB().Table("group_requests").Where("group_id=? and user_id=?", groupRequest.GroupID, groupRequest.UserID).Updates(&groupRequest).Error } -func InsertIntoGroupRequest(toInsertInfo db.GroupRequest) error { +func InsertIntoGroupRequest(toInsertInfo GroupRequest) error { DelGroupRequestByGroupIDAndUserID(toInsertInfo.GroupID, toInsertInfo.UserID) if toInsertInfo.HandledTime.Unix() < 0 { toInsertInfo.HandledTime = utils.UnixSecondToTime(0) @@ -48,8 +48,8 @@ func InsertIntoGroupRequest(toInsertInfo db.GroupRequest) error { return nil } -func GetGroupRequestByGroupIDAndUserID(groupID, userID string) (*db.GroupRequest, error) { - var groupRequest db.GroupRequest +func GetGroupRequestByGroupIDAndUserID(groupID, userID string) (*GroupRequest, error) { + var groupRequest GroupRequest err := db.DB.MysqlDB.DefaultGormDB().Table("group_requests").Where("user_id=? and group_id=?", userID, groupID).Take(&groupRequest).Error if err != nil { return nil, err @@ -58,11 +58,11 @@ func GetGroupRequestByGroupIDAndUserID(groupID, userID string) (*db.GroupRequest } func DelGroupRequestByGroupIDAndUserID(groupID, userID string) error { - return db.DB.MysqlDB.DefaultGormDB().Table("group_requests").Where("group_id=? and user_id=?", groupID, userID).Delete(db.GroupRequest{}).Error + return db.DB.MysqlDB.DefaultGormDB().Table("group_requests").Where("group_id=? and user_id=?", groupID, userID).Delete(GroupRequest{}).Error } -func GetGroupRequestByGroupID(groupID string) ([]db.GroupRequest, error) { - var groupRequestList []db.GroupRequest +func GetGroupRequestByGroupID(groupID string) ([]GroupRequest, error) { + var groupRequestList []GroupRequest err := db.DB.MysqlDB.DefaultGormDB().Table("group_requests").Where("group_id=?", groupID).Find(&groupRequestList).Error if err != nil { return nil, err @@ -71,8 +71,8 @@ func GetGroupRequestByGroupID(groupID string) ([]db.GroupRequest, error) { } // received -func GetRecvGroupApplicationList(userID string) ([]db.GroupRequest, error) { - var groupRequestList []db.GroupRequest +func GetRecvGroupApplicationList(userID string) ([]GroupRequest, error) { + var groupRequestList []GroupRequest memberList, err := GetGroupMemberListByUserID(userID) if err != nil { return nil, utils.Wrap(err, utils.GetSelfFuncName()) @@ -89,8 +89,8 @@ func GetRecvGroupApplicationList(userID string) ([]db.GroupRequest, error) { return groupRequestList, nil } -func GetUserReqGroupByUserID(userID string) ([]db.GroupRequest, error) { - var groupRequestList []db.GroupRequest +func GetUserReqGroupByUserID(userID string) ([]GroupRequest, error) { + var groupRequestList []GroupRequest err := db.DB.MysqlDB.DefaultGormDB().Table("group_requests").Where("user_id=?", userID).Find(&groupRequestList).Error return groupRequestList, err } diff --git a/pkg/common/db/mysql_model/im_mysql_model/group_sk.go b/pkg/common/db/mysql_model/im_mysql_model/group_sk.go new file mode 100644 index 000000000..e449333cf --- /dev/null +++ b/pkg/common/db/mysql_model/im_mysql_model/group_sk.go @@ -0,0 +1,32 @@ +package im_mysql_model + +func (tb *Group) Create(groups []*Group) error { + return nil +} +func (tb *Group) Take(groupIDs []string) (*Group, error) { + return nil, nil +} +func (tb *Group) Get(groupIDs []string) (*Group, error) { + return nil, nil +} +func (tb *Group) Update(groups []*Group) error { + return nil +} +func (tb *Group) GetByName(groupName string, pageNumber, showNumber int32) ([]GroupWithNum, int64, error) { + +} +func (tb *Group) GetGroups(pageNumber, showNumber int) ([]GroupWithNum, error) { +} +func (tb *Group) OperateGroupStatus(groupId string, groupStatus int32) error { +} + +func (tb *Group) GetCountsNum(groupIDs []string) ([]int32, error) { + +} + +func (tb *Group) UpdateDefaultZero(groupID string, args map[string]interface{}) error { +} + +func (tb *Group) GetGroupIDsByGroupType(groupType int) ([]string, error) { + +} diff --git a/pkg/common/db/mysql_model/im_mysql_model/invitation_model.go b/pkg/common/db/mysql_model/im_mysql_model/invitation_model.go index 80d2f768a..f8725d11e 100644 --- a/pkg/common/db/mysql_model/im_mysql_model/invitation_model.go +++ b/pkg/common/db/mysql_model/im_mysql_model/invitation_model.go @@ -18,7 +18,7 @@ func BatchCreateInvitationCodes(CodeNums int, CodeLen int) ([]string, error) { break } code := CreateRandomString(CodeLen) - invitation := new(db.Invitation) + invitation := new(Invitation) invitation.CreateTime = time.Now() invitation.InvitationCode = code invitation.LastTime = time.Now() @@ -40,7 +40,7 @@ func BatchCreateInvitationCodes(CodeNums int, CodeLen int) ([]string, error) { * 检查邀请码 */ func CheckInvitationCode(code string) error { - var invitationCode db.Invitation + var invitationCode Invitation err := db.DB.MysqlDB.DefaultGormDB().Table("invitations").Where("invitation_code=?", code).Take(&invitationCode).Error if err != nil { return err @@ -82,8 +82,8 @@ func FinishInvitationCode(Code string, UserId string) bool { return result.RowsAffected > 0 } -func GetInvitationCode(code string) (*db.Invitation, error) { - invitation := &db.Invitation{ +func GetInvitationCode(code string) (*Invitation, error) { + invitation := &Invitation{ InvitationCode: code, } err := db.DB.MysqlDB.DefaultGormDB().Model(invitation).Find(invitation).Error @@ -101,9 +101,9 @@ func CreateRandomString(strlen int) string { return string(result) } -func GetInvitationCodes(showNumber, pageNumber, status int32) ([]db.Invitation, int64, error) { - var invitationList []db.Invitation - db := db.DB.MysqlDB.DefaultGormDB().Model(db.Invitation{}).Where("status=?", status) +func GetInvitationCodes(showNumber, pageNumber, status int32) ([]Invitation, int64, error) { + var invitationList []Invitation + db := db.DB.MysqlDB.DefaultGormDB().Model(Invitation{}).Where("status=?", status) var count int64 err := db.Count(&count).Error err = db.Limit(int(showNumber)).Offset(int(showNumber * (pageNumber - 1))). diff --git a/pkg/common/db/mysql_model/im_mysql_model/ip_model.go b/pkg/common/db/mysql_model/im_mysql_model/ip_model.go index d87a08796..9db108b06 100644 --- a/pkg/common/db/mysql_model/im_mysql_model/ip_model.go +++ b/pkg/common/db/mysql_model/im_mysql_model/ip_model.go @@ -44,58 +44,58 @@ func IsLimitUserLoginIp(userID string, loginIp string) (limit bool, err error) { return count > 0, nil } -func QueryIPLimits(ip string) (*db.IpLimit, error) { - var ipLimit db.IpLimit - err := db.DB.MysqlDB.DefaultGormDB().Model(&db.IpLimit{}).Where("ip=?", ip).First(&ipLimit).Error +func QueryIPLimits(ip string) (*IpLimit, error) { + var ipLimit IpLimit + err := db.DB.MysqlDB.DefaultGormDB().Model(&IpLimit{}).Where("ip=?", ip).First(&ipLimit).Error return &ipLimit, err } -func QueryUserIPLimits(ip string) ([]db.UserIpLimit, error) { - var ips []db.UserIpLimit - err := db.DB.MysqlDB.DefaultGormDB().Model(&db.UserIpLimit{}).Where("ip=?", ip).Find(&ips).Error +func QueryUserIPLimits(ip string) ([]UserIpLimit, error) { + var ips []UserIpLimit + err := db.DB.MysqlDB.DefaultGormDB().Model(&UserIpLimit{}).Where("ip=?", ip).Find(&ips).Error return ips, err } -func InsertOneIntoIpLimits(ipLimits db.IpLimit) error { - return db.DB.MysqlDB.DefaultGormDB().Model(&db.IpLimit{}).Create(ipLimits).Error +func InsertOneIntoIpLimits(ipLimits IpLimit) error { + return db.DB.MysqlDB.DefaultGormDB().Model(&IpLimit{}).Create(ipLimits).Error } func DeleteOneFromIpLimits(ip string) error { - ipLimits := &db.IpLimit{Ip: ip} + ipLimits := &IpLimit{Ip: ip} return db.DB.MysqlDB.DefaultGormDB().Model(ipLimits).Where("ip=?", ip).Delete(ipLimits).Error } -func GetIpLimitsLoginByUserID(userID string) ([]db.UserIpLimit, error) { - var ips []db.UserIpLimit - err := db.DB.MysqlDB.DefaultGormDB().Model(&db.UserIpLimit{}).Where("user_id=?", userID).Find(&ips).Error +func GetIpLimitsLoginByUserID(userID string) ([]UserIpLimit, error) { + var ips []UserIpLimit + err := db.DB.MysqlDB.DefaultGormDB().Model(&UserIpLimit{}).Where("user_id=?", userID).Find(&ips).Error return ips, err } -func InsertUserIpLimitsLogin(userIp *db.UserIpLimit) error { +func InsertUserIpLimitsLogin(userIp *UserIpLimit) error { userIp.CreateTime = time.Now() - return db.DB.MysqlDB.DefaultGormDB().Model(&db.UserIpLimit{}).Create(userIp).Error + return db.DB.MysqlDB.DefaultGormDB().Model(&UserIpLimit{}).Create(userIp).Error } func DeleteUserIpLimitsLogin(userID, ip string) error { - userIp := db.UserIpLimit{UserID: userID, Ip: ip} - return db.DB.MysqlDB.DefaultGormDB().Model(&db.UserIpLimit{}).Delete(&userIp).Error + userIp := UserIpLimit{UserID: userID, Ip: ip} + return db.DB.MysqlDB.DefaultGormDB().Model(&UserIpLimit{}).Delete(&userIp).Error } func GetRegisterUserNum(ip string) ([]string, error) { var userIDList []string - err := db.DB.MysqlDB.DefaultGormDB().Model(&db.Register{}).Where("register_ip=?", ip).Pluck("user_id", &userIDList).Error + err := db.DB.MysqlDB.DefaultGormDB().Model(&Register{}).Where("register_ip=?", ip).Pluck("user_id", &userIDList).Error return userIDList, err } func InsertIpRecord(userID, createIp string) error { - record := &db.UserIpRecord{UserID: userID, CreateIp: createIp, LastLoginTime: time.Now(), LoginTimes: 1} - err := db.DB.MysqlDB.DefaultGormDB().Model(&db.UserIpRecord{}).Create(record).Error + record := &UserIpRecord{UserID: userID, CreateIp: createIp, LastLoginTime: time.Now(), LoginTimes: 1} + err := db.DB.MysqlDB.DefaultGormDB().Model(&UserIpRecord{}).Create(record).Error return err } func UpdateIpReocord(userID, ip string) (err error) { - record := &db.UserIpRecord{UserID: userID, LastLoginIp: ip, LastLoginTime: time.Now()} - result := db.DB.MysqlDB.DefaultGormDB().Model(&db.UserIpRecord{}).Where("user_id=?", userID).Updates(record).Update("login_times", gorm.Expr("login_times+?", 1)) + record := &UserIpRecord{UserID: userID, LastLoginIp: ip, LastLoginTime: time.Now()} + result := db.DB.MysqlDB.DefaultGormDB().Model(&UserIpRecord{}).Where("user_id=?", userID).Updates(record).Update("login_times", gorm.Expr("login_times+?", 1)) if result.Error != nil { return utils.Wrap(result.Error, "") } diff --git a/pkg/common/db/mysql_model/im_mysql_model/message_cms.go b/pkg/common/db/mysql_model/im_mysql_model/message_cms.go index 2add70b12..d4bfa0134 100644 --- a/pkg/common/db/mysql_model/im_mysql_model/message_cms.go +++ b/pkg/common/db/mysql_model/im_mysql_model/message_cms.go @@ -6,7 +6,7 @@ import ( "fmt" ) -func GetChatLog(chatLog *db.ChatLog, pageNumber, showNumber int32, contentTypeList []int32) (int64, []db.ChatLog, error) { +func GetChatLog(chatLog *ChatLog, pageNumber, showNumber int32, contentTypeList []int32) (int64, []ChatLog, error) { mdb := db.DB.MysqlDB.DefaultGormDB().Table("chat_logs") if chatLog.SendTime.Unix() > 0 { mdb = mdb.Where("send_time > ? and send_time < ?", chatLog.SendTime, chatLog.SendTime.AddDate(0, 0, 1)) @@ -35,7 +35,7 @@ func GetChatLog(chatLog *db.ChatLog, pageNumber, showNumber int32, contentTypeLi if err := mdb.Count(&count).Error; err != nil { return 0, nil, err } - var chatLogs []db.ChatLog + var chatLogs []ChatLog mdb = mdb.Limit(int(showNumber)).Offset(int(showNumber * (pageNumber - 1))) if err := mdb.Find(&chatLogs).Error; err != nil { return 0, nil, err diff --git a/pkg/common/db/model_struct.go b/pkg/common/db/mysql_model/im_mysql_model/model_struct.go similarity index 85% rename from pkg/common/db/model_struct.go rename to pkg/common/db/mysql_model/im_mysql_model/model_struct.go index 882ae6b46..a7a444cb4 100644 --- a/pkg/common/db/model_struct.go +++ b/pkg/common/db/mysql_model/im_mysql_model/model_struct.go @@ -1,6 +1,9 @@ -package db +package im_mysql_model -import "time" +import ( + "gorm.io/gorm" + "time" +) type Register struct { Account string `gorm:"column:account;primary_key;type:char(255)" json:"account"` @@ -20,17 +23,16 @@ type Invitation struct { Status int32 `gorm:"column:status"` } -// -//message FriendInfo{ -//string OwnerUserID = 1; -//string Remark = 2; -//int64 CreateTime = 3; -//UserInfo FriendUser = 4; -//int32 AddSource = 5; -//string OperatorUserID = 6; -//string Ex = 7; -//} -//open_im_sdk.FriendInfo(FriendUser) != imdb.Friend(FriendUserID) +// message FriendInfo{ +// string OwnerUserID = 1; +// string Remark = 2; +// int64 CreateTime = 3; +// UserInfo FriendUser = 4; +// int32 AddSource = 5; +// string OperatorUserID = 6; +// string Ex = 7; +// } +// open_im_sdk.FriendInfo(FriendUser) != imdb.Friend(FriendUserID) type Friend struct { OwnerUserID string `gorm:"column:owner_user_id;primary_key;size:64"` FriendUserID string `gorm:"column:friend_user_id;primary_key;size:64"` @@ -41,18 +43,18 @@ type Friend struct { Ex string `gorm:"column:ex;size:1024"` } -//message FriendRequest{ -//string FromUserID = 1; -//string ToUserID = 2; -//int32 HandleResult = 3; -//string ReqMsg = 4; -//int64 CreateTime = 5; -//string HandlerUserID = 6; -//string HandleMsg = 7; -//int64 HandleTime = 8; -//string Ex = 9; -//} -//open_im_sdk.FriendRequest(nickname, farce url ...) != imdb.FriendRequest +// message FriendRequest{ +// string FromUserID = 1; +// string ToUserID = 2; +// int32 HandleResult = 3; +// string ReqMsg = 4; +// int64 CreateTime = 5; +// string HandlerUserID = 6; +// string HandleMsg = 7; +// int64 HandleTime = 8; +// string Ex = 9; +// } +// open_im_sdk.FriendRequest(nickname, farce url ...) != imdb.FriendRequest type FriendRequest struct { FromUserID string `gorm:"column:from_user_id;primary_key;size:64"` ToUserID string `gorm:"column:to_user_id;primary_key;size:64"` @@ -69,21 +71,22 @@ func (FriendRequest) TableName() string { return "friend_requests" } -//message GroupInfo{ -// string GroupID = 1; -// string GroupName = 2; -// string Notification = 3; -// string Introduction = 4; -// string FaceUrl = 5; -// string OwnerUserID = 6; -// uint32 MemberCount = 8; -// int64 CreateTime = 7; -// string Ex = 9; -// int32 Status = 10; -// string CreatorUserID = 11; -// int32 GroupType = 12; -//} -// open_im_sdk.GroupInfo (OwnerUserID , MemberCount )> imdb.Group +// message GroupInfo{ +// string GroupID = 1; +// string GroupName = 2; +// string Notification = 3; +// string Introduction = 4; +// string FaceUrl = 5; +// string OwnerUserID = 6; +// uint32 MemberCount = 8; +// int64 CreateTime = 7; +// string Ex = 9; +// int32 Status = 10; +// string CreatorUserID = 11; +// int32 GroupType = 12; +// } +// +// open_im_sdk.GroupInfo (OwnerUserID , MemberCount )> imdb.Group type Group struct { //`json:"operationID" binding:"required"` //`protobuf:"bytes,1,opt,name=GroupID" json:"GroupID,omitempty"` `json:"operationID" binding:"required"` @@ -102,20 +105,21 @@ type Group struct { ApplyMemberFriend int32 `gorm:"column:apply_member_friend" json:"applyMemberFriend"` NotificationUpdateTime time.Time `gorm:"column:notification_update_time"` NotificationUserID string `gorm:"column:notification_user_id;size:64"` + DB *gorm.DB `gorm:"-" json:"-"` } -//message GroupMemberFullInfo { -//string GroupID = 1 ; -//string UserID = 2 ; -//int32 roleLevel = 3; -//int64 JoinTime = 4; -//string NickName = 5; -//string FaceUrl = 6; -//int32 JoinSource = 8; -//string OperatorUserID = 9; -//string Ex = 10; -//int32 AppMangerLevel = 7; //if >0 -//} open_im_sdk.GroupMemberFullInfo(AppMangerLevel) > imdb.GroupMember +// message GroupMemberFullInfo { +// string GroupID = 1 ; +// string UserID = 2 ; +// int32 roleLevel = 3; +// int64 JoinTime = 4; +// string NickName = 5; +// string FaceUrl = 6; +// int32 JoinSource = 8; +// string OperatorUserID = 9; +// string Ex = 10; +// int32 AppMangerLevel = 7; //if >0 +// } open_im_sdk.GroupMemberFullInfo(AppMangerLevel) > imdb.GroupMember type GroupMember struct { GroupID string `gorm:"column:group_id;primary_key;size:64"` UserID string `gorm:"column:user_id;primary_key;size:64"` @@ -130,17 +134,17 @@ type GroupMember struct { Ex string `gorm:"column:ex;size:1024"` } -//message GroupRequest{ -//string UserID = 1; -//string GroupID = 2; -//string HandleResult = 3; -//string ReqMsg = 4; -//string HandleMsg = 5; -//int64 ReqTime = 6; -//string HandleUserID = 7; -//int64 HandleTime = 8; -//string Ex = 9; -//}open_im_sdk.GroupRequest == imdb.GroupRequest +// message GroupRequest{ +// string UserID = 1; +// string GroupID = 2; +// string HandleResult = 3; +// string ReqMsg = 4; +// string HandleMsg = 5; +// int64 ReqTime = 6; +// string HandleUserID = 7; +// int64 HandleTime = 8; +// string Ex = 9; +// }open_im_sdk.GroupRequest == imdb.GroupRequest type GroupRequest struct { UserID string `gorm:"column:user_id;primary_key;size:64"` GroupID string `gorm:"column:group_id;primary_key;size:64"` @@ -155,18 +159,18 @@ type GroupRequest struct { Ex string `gorm:"column:ex;size:1024"` } -//string UserID = 1; -//string Nickname = 2; -//string FaceUrl = 3; -//int32 Gender = 4; -//string PhoneNumber = 5; -//string Birth = 6; -//string Email = 7; -//string Ex = 8; -//string CreateIp = 9; -//int64 CreateTime = 10; -//int32 AppMangerLevel = 11; -//open_im_sdk.User == imdb.User +// string UserID = 1; +// string Nickname = 2; +// string FaceUrl = 3; +// int32 Gender = 4; +// string PhoneNumber = 5; +// string Birth = 6; +// string Email = 7; +// string Ex = 8; +// string CreateIp = 9; +// int64 CreateTime = 10; +// int32 AppMangerLevel = 11; +// open_im_sdk.User == imdb.User type User struct { UserID string `gorm:"column:user_id;primary_key;size:64"` Nickname string `gorm:"column:name;size:255"` @@ -207,14 +211,14 @@ type UserIpLimit struct { CreateTime time.Time `gorm:"column:create_time"` } -//message BlackInfo{ -//string OwnerUserID = 1; -//int64 CreateTime = 2; -//PublicUserInfo BlackUserInfo = 4; -//int32 AddSource = 5; -//string OperatorUserID = 6; -//string Ex = 7; -//} +// message BlackInfo{ +// string OwnerUserID = 1; +// int64 CreateTime = 2; +// PublicUserInfo BlackUserInfo = 4; +// int32 AddSource = 5; +// string OperatorUserID = 6; +// string Ex = 7; +// } // open_im_sdk.BlackInfo(BlackUserInfo) != imdb.Black (BlockUserID) type Black struct { OwnerUserID string `gorm:"column:owner_user_id;primary_key;size:64"` diff --git a/pkg/common/db/mysql_model/im_mysql_model/organization_model.go b/pkg/common/db/mysql_model/im_mysql_model/organization_model.go index 0d1a56a12..5e935775e 100644 --- a/pkg/common/db/mysql_model/im_mysql_model/organization_model.go +++ b/pkg/common/db/mysql_model/im_mysql_model/organization_model.go @@ -7,18 +7,18 @@ import ( "time" ) -func CreateDepartment(department *db.Department) error { +func CreateDepartment(department *Department) error { department.CreateTime = time.Now() return db.DB.MysqlDB.DefaultGormDB().Table("departments").Create(department).Error } -func GetDepartment(departmentID string) (*db.Department, error) { - var department db.Department +func GetDepartment(departmentID string) (*Department, error) { + var department Department err := db.DB.MysqlDB.DefaultGormDB().Table("departments").Where("department_id=?", departmentID).Find(&department).Error return &department, err } -func UpdateDepartment(department *db.Department, args map[string]interface{}) error { +func UpdateDepartment(department *Department, args map[string]interface{}) error { if err := db.DB.MysqlDB.DefaultGormDB().Table("departments").Where("department_id=?", department.DepartmentID).Updates(department).Error; err != nil { return err } @@ -28,8 +28,8 @@ func UpdateDepartment(department *db.Department, args map[string]interface{}) er return nil } -func GetSubDepartmentList(departmentID string) ([]db.Department, error) { - var departmentList []db.Department +func GetSubDepartmentList(departmentID string) ([]Department, error) { + var departmentList []Department var err error if departmentID == "-1" { err = db.DB.MysqlDB.DefaultGormDB().Table("departments").Find(&departmentList).Error @@ -42,33 +42,33 @@ func GetSubDepartmentList(departmentID string) ([]db.Department, error) { func DeleteDepartment(departmentID string) error { var err error - if err = db.DB.MysqlDB.DefaultGormDB().Table("departments").Where("department_id=?", departmentID).Delete(db.Department{}).Error; err != nil { + if err = db.DB.MysqlDB.DefaultGormDB().Table("departments").Where("department_id=?", departmentID).Delete(Department{}).Error; err != nil { return err } - if err = db.DB.MysqlDB.DefaultGormDB().Table("department_members").Where("department_id=?", departmentID).Delete(db.DepartmentMember{}).Error; err != nil { + if err = db.DB.MysqlDB.DefaultGormDB().Table("department_members").Where("department_id=?", departmentID).Delete(DepartmentMember{}).Error; err != nil { return err } return nil } -func CreateOrganizationUser(organizationUser *db.OrganizationUser) error { +func CreateOrganizationUser(organizationUser *OrganizationUser) error { organizationUser.CreateTime = time.Now() return db.DB.MysqlDB.DefaultGormDB().Table("organization_users").Create(organizationUser).Error } -func GetOrganizationUser(userID string) (error, *db.OrganizationUser) { - organizationUser := db.OrganizationUser{} +func GetOrganizationUser(userID string) (error, *OrganizationUser) { + organizationUser := OrganizationUser{} err := db.DB.MysqlDB.DefaultGormDB().Table("organization_users").Where("user_id=?", userID).Take(&organizationUser).Error return err, &organizationUser } -func GetOrganizationUsers(userIDList []string) ([]*db.OrganizationUser, error) { - var organizationUserList []*db.OrganizationUser +func GetOrganizationUsers(userIDList []string) ([]*OrganizationUser, error) { + var organizationUserList []*OrganizationUser err := db.DB.MysqlDB.DefaultGormDB().Table("organization_users").Where("user_id in (?)", userIDList).Find(&organizationUserList).Error return organizationUserList, err } -func UpdateOrganizationUser(organizationUser *db.OrganizationUser, args map[string]interface{}) error { +func UpdateOrganizationUser(organizationUser *OrganizationUser, args map[string]interface{}) error { if err := db.DB.MysqlDB.DefaultGormDB().Table("organization_users").Where("user_id=?", organizationUser.UserID).Updates(organizationUser).Error; err != nil { return err } @@ -78,18 +78,18 @@ func UpdateOrganizationUser(organizationUser *db.OrganizationUser, args map[stri return nil } -func CreateDepartmentMember(departmentMember *db.DepartmentMember) error { +func CreateDepartmentMember(departmentMember *DepartmentMember) error { departmentMember.CreateTime = time.Now() return db.DB.MysqlDB.DefaultGormDB().Table("department_members").Create(departmentMember).Error } -func GetUserInDepartment(userID string) (error, []db.DepartmentMember) { - var departmentMemberList []db.DepartmentMember +func GetUserInDepartment(userID string) (error, []DepartmentMember) { + var departmentMemberList []DepartmentMember err := db.DB.MysqlDB.DefaultGormDB().Table("department_members").Where("user_id=?", userID).Find(&departmentMemberList).Error return err, departmentMemberList } -func UpdateUserInDepartment(departmentMember *db.DepartmentMember, args map[string]interface{}) error { +func UpdateUserInDepartment(departmentMember *DepartmentMember, args map[string]interface{}) error { if err := db.DB.MysqlDB.DefaultGormDB().Table("department_members").Where("department_id=? AND user_id=?", departmentMember.DepartmentID, departmentMember.UserID). Updates(departmentMember).Error; err != nil { return err @@ -102,22 +102,22 @@ func UpdateUserInDepartment(departmentMember *db.DepartmentMember, args map[stri } func DeleteUserInDepartment(departmentID, userID string) error { - return db.DB.MysqlDB.DefaultGormDB().Table("department_members").Where("department_id=? AND user_id=?", departmentID, userID).Delete(db.DepartmentMember{}).Error + return db.DB.MysqlDB.DefaultGormDB().Table("department_members").Where("department_id=? AND user_id=?", departmentID, userID).Delete(DepartmentMember{}).Error } func DeleteUserInAllDepartment(userID string) error { - return db.DB.MysqlDB.DefaultGormDB().Table("department_members").Where("user_id=?", userID).Delete(db.DepartmentMember{}).Error + return db.DB.MysqlDB.DefaultGormDB().Table("department_members").Where("user_id=?", userID).Delete(DepartmentMember{}).Error } func DeleteOrganizationUser(OrganizationUserID string) error { if err := DeleteUserInAllDepartment(OrganizationUserID); err != nil { return err } - return db.DB.MysqlDB.DefaultGormDB().Table("organization_users").Where("user_id=?", OrganizationUserID).Delete(db.OrganizationUser{}).Error + return db.DB.MysqlDB.DefaultGormDB().Table("organization_users").Where("user_id=?", OrganizationUserID).Delete(OrganizationUser{}).Error } func GetDepartmentMemberUserIDList(departmentID string) (error, []string) { - var departmentMemberList []db.DepartmentMember + var departmentMemberList []DepartmentMember err := db.DB.MysqlDB.DefaultGormDB().Table("department_members").Where("department_id=?", departmentID).Take(&departmentMemberList).Error if err != nil { return err, nil @@ -129,8 +129,8 @@ func GetDepartmentMemberUserIDList(departmentID string) (error, []string) { return err, userIDList } -func GetDepartmentMemberList(departmentID string) ([]db.DepartmentMember, error) { - var departmentMemberList []db.DepartmentMember +func GetDepartmentMemberList(departmentID string) ([]DepartmentMember, error) { + var departmentMemberList []DepartmentMember var err error if departmentID == "-1" { err = db.DB.MysqlDB.DefaultGormDB().Table("department_members").Find(&departmentMemberList).Error @@ -145,7 +145,7 @@ func GetDepartmentMemberList(departmentID string) ([]db.DepartmentMember, error) } func GetAllOrganizationUserID() (error, []string) { - var OrganizationUser db.OrganizationUser + var OrganizationUser OrganizationUser var result []string return db.DB.MysqlDB.DefaultGormDB().Model(&OrganizationUser).Pluck("user_id", &result).Error, result } @@ -170,7 +170,7 @@ func GetSubDepartmentNum(departmentID string) (error, uint32) { } func SetDepartmentRelatedGroupID(groupID, departmentID string) error { - department := &db.Department{RelatedGroupID: groupID} + department := &Department{RelatedGroupID: groupID} return db.DB.MysqlDB.DefaultGormDB().Model(&department).Where("department_id=?", departmentID).Updates(department).Error } @@ -180,9 +180,9 @@ func GetDepartmentRelatedGroupIDList(departmentIDList []string) ([]string, error return groupIDList, err } -func getDepartmentParent(departmentID string, dbConn *gorm.DB) (*db.Department, error) { - var department db.Department - var parentDepartment db.Department +func getDepartmentParent(departmentID string, dbConn *gorm.DB) (*Department, error) { + var department Department + var parentDepartment Department //var parentID string err := db.DB.MysqlDB.DefaultGormDB().Model(&department).Where("department_id=?", departmentID).Select("parent_id").First(&department).Error if err != nil { @@ -217,7 +217,7 @@ func GetDepartmentParentIDList(departmentID string) ([]string, error) { } func GetRandomDepartmentID() (string, error) { - department := &db.Department{} + department := &Department{} err := db.DB.MysqlDB.DefaultGormDB().Model(department).Order("RAND()").Where("related_group_id != ? AND department_id != ? AND department_type = ?", "", "0", 1).First(department).Error return department.DepartmentID, err } diff --git a/pkg/common/db/mysql_model/im_mysql_model/statistics_model.go b/pkg/common/db/mysql_model/im_mysql_model/statistics_model.go index bdd06f662..0e826a93c 100644 --- a/pkg/common/db/mysql_model/im_mysql_model/statistics_model.go +++ b/pkg/common/db/mysql_model/im_mysql_model/statistics_model.go @@ -70,7 +70,7 @@ func GetActiveGroups(from, to time.Time, limit int) ([]*activeGroup, error) { var activeGroups []*activeGroup err := db.DB.MysqlDB.DefaultGormDB().Table("chat_logs").Select("recv_id, count(*) as message_num").Where("send_time >= ? and send_time <= ? and session_type in (?)", from, to, []int{constant.GroupChatType, constant.SuperGroupChatType}).Group("recv_id").Limit(limit).Order("message_num DESC").Find(&activeGroups).Error for _, activeGroup := range activeGroups { - group := db.Group{ + group := Group{ GroupID: activeGroup.Id, } db.DB.MysqlDB.DefaultGormDB().Table("groups").Where("group_id= ? ", group.GroupID).Find(&group) @@ -89,7 +89,7 @@ func GetActiveUsers(from, to time.Time, limit int) ([]*activeUser, error) { var activeUsers []*activeUser err := db.DB.MysqlDB.DefaultGormDB().Table("chat_logs").Select("send_id, count(*) as message_num").Where("send_time >= ? and send_time <= ? and session_type = ?", from, to, constant.SingleChatType).Group("send_id").Limit(limit).Order("message_num DESC").Find(&activeUsers).Error for _, activeUser := range activeUsers { - user := db.User{ + user := User{ UserID: activeUser.ID, } err = db.DB.MysqlDB.DefaultGormDB().Table("users").Select("user_id, name").Find(&user).Error diff --git a/pkg/common/db/mysql_model/im_mysql_model/user_black_list_model.go b/pkg/common/db/mysql_model/im_mysql_model/user_black_list_model.go index b848bff41..8d956ce40 100644 --- a/pkg/common/db/mysql_model/im_mysql_model/user_black_list_model.go +++ b/pkg/common/db/mysql_model/im_mysql_model/user_black_list_model.go @@ -6,7 +6,7 @@ import ( "time" ) -func InsertInToUserBlackList(black db.Black) error { +func InsertInToUserBlackList(black Black) error { black.CreateTime = time.Now() return db.DB.MysqlDB.DefaultGormDB().Table("blacks").Create(black).Error } @@ -21,17 +21,17 @@ func InsertInToUserBlackList(black db.Black) error { // } func CheckBlack(ownerUserID, blockUserID string) error { - var black db.Black + var black Black return db.DB.MysqlDB.DefaultGormDB().Table("blacks").Where("owner_user_id=? and block_user_id=?", ownerUserID, blockUserID).Find(&black).Error } func RemoveBlackList(ownerUserID, blockUserID string) error { - err := db.DB.MysqlDB.DefaultGormDB().Table("blacks").Where("owner_user_id=? and block_user_id=?", ownerUserID, blockUserID).Delete(db.Black{}).Error + err := db.DB.MysqlDB.DefaultGormDB().Table("blacks").Where("owner_user_id=? and block_user_id=?", ownerUserID, blockUserID).Delete(Black{}).Error return utils.Wrap(err, "RemoveBlackList failed") } -func GetBlackListByUserID(ownerUserID string) ([]db.Black, error) { - var blackListUsersInfo []db.Black +func GetBlackListByUserID(ownerUserID string) ([]Black, error) { + var blackListUsersInfo []Black err := db.DB.MysqlDB.DefaultGormDB().Table("blacks").Where("owner_user_id=?", ownerUserID).Find(&blackListUsersInfo).Error if err != nil { return nil, err diff --git a/pkg/common/db/mysql_model/im_mysql_model/user_model.go b/pkg/common/db/mysql_model/im_mysql_model/user_model.go index e139e729f..3dee521a6 100644 --- a/pkg/common/db/mysql_model/im_mysql_model/user_model.go +++ b/pkg/common/db/mysql_model/im_mysql_model/user_model.go @@ -17,7 +17,7 @@ func init() { } else { continue } - var appMgr db.User + var appMgr User appMgr.UserID = v if k == 0 { appMgr.Nickname = config.Config.Manager.AppSysNotificationName @@ -34,7 +34,7 @@ func init() { } } -func UserRegister(user db.User) error { +func UserRegister(user User) error { user.CreateTime = time.Now() if user.AppMangerLevel == 0 { user.AppMangerLevel = constant.AppOrdinaryUsers @@ -49,14 +49,14 @@ func UserRegister(user db.User) error { return nil } -func GetAllUser() ([]db.User, error) { - var userList []db.User +func GetAllUser() ([]User, error) { + var userList []User err := db.DB.MysqlDB.DefaultGormDB().Table("users").Find(&userList).Error return userList, err } -func TakeUserByUserID(userID string) (*db.User, error) { - var user db.User +func TakeUserByUserID(userID string) (*User, error) { + var user User err := db.DB.MysqlDB.DefaultGormDB().Table("users").Where("user_id=?", userID).Take(&user).Error if err != nil { return nil, err @@ -64,8 +64,8 @@ func TakeUserByUserID(userID string) (*db.User, error) { return &user, nil } -func GetUserByUserID(userID string) (*db.User, error) { - var user db.User +func GetUserByUserID(userID string) (*User, error) { + var user User err := db.DB.MysqlDB.DefaultGormDB().Table("users").Where("user_id=?", userID).Take(&user).Error if err != nil { return nil, err @@ -73,14 +73,14 @@ func GetUserByUserID(userID string) (*db.User, error) { return &user, nil } -func GetUsersByUserIDList(userIDList []string) ([]*db.User, error) { - var userList []*db.User +func GetUsersByUserIDList(userIDList []string) ([]*User, error) { + var userList []*User err := db.DB.MysqlDB.DefaultGormDB().Table("users").Where("user_id in (?)", userIDList).Find(&userList).Error return userList, err } func GetUserNameByUserID(userID string) (string, error) { - var user db.User + var user User err := db.DB.MysqlDB.DefaultGormDB().Table("users").Select("name").Where("user_id=?", userID).First(&user).Error if err != nil { return "", err @@ -88,11 +88,11 @@ func GetUserNameByUserID(userID string) (string, error) { return user.Nickname, nil } -func UpdateUserInfo(user db.User) error { +func UpdateUserInfo(user User) error { return db.DB.MysqlDB.DefaultGormDB().Table("users").Where("user_id=?", user.UserID).Updates(&user).Error } -func UpdateUserInfoByMap(user db.User, m map[string]interface{}) error { +func UpdateUserInfoByMap(user User, m map[string]interface{}) error { err := db.DB.MysqlDB.DefaultGormDB().Table("users").Where("user_id=?", user.UserID).Updates(m).Error return err } @@ -115,8 +115,8 @@ func SelectSomeUserID(userIDList []string) ([]string, error) { return resultArr, nil } -func GetUsers(showNumber, pageNumber int32) ([]db.User, error) { - var users []db.User +func GetUsers(showNumber, pageNumber int32) ([]User, error) { + var users []User err := db.DB.MysqlDB.DefaultGormDB().Table("users").Limit(int(showNumber)).Offset(int(showNumber * (pageNumber - 1))).Find(&users).Error if err != nil { return users, err @@ -129,7 +129,7 @@ func AddUser(userID string, phoneNumber string, name string, email string, gende if err != nil { return err } - user := db.User{ + user := User{ UserID: userID, Nickname: name, FaceURL: faceURL, @@ -145,7 +145,7 @@ func AddUser(userID string, phoneNumber string, name string, email string, gende } func UserIsBlock(userId string) (bool, error) { - var user db.BlackList + var user BlackList rows := db.DB.MysqlDB.DefaultGormDB().Table("black_lists").Where("uid=?", userId).First(&user).RowsAffected if rows >= 1 { return user.EndDisableTime.After(time.Now()), nil @@ -170,13 +170,13 @@ func BlockUser(userID, endDisableTime string) error { if end.Before(time.Now()) { return errors.New("endDisableTime is before now") } - var blockUser db.BlackList + var blockUser BlackList db.DB.MysqlDB.DefaultGormDB().Table("black_lists").Where("uid=?", userID).First(&blockUser) if blockUser.UserId != "" { db.DB.MysqlDB.DefaultGormDB().Model(&blockUser).Where("uid=?", blockUser.UserId).Update("end_disable_time", end) return nil } - blockUser = db.BlackList{ + blockUser = BlackList{ UserId: userID, BeginDisableTime: time.Now(), EndDisableTime: end, @@ -186,24 +186,24 @@ func BlockUser(userID, endDisableTime string) error { } func UnBlockUser(userID string) error { - return db.DB.MysqlDB.DefaultGormDB().Where("uid=?", userID).Delete(&db.BlackList{}).Error + return db.DB.MysqlDB.DefaultGormDB().Where("uid=?", userID).Delete(&BlackList{}).Error } type BlockUserInfo struct { - User db.User + User User BeginDisableTime time.Time EndDisableTime time.Time } func GetBlockUserByID(userId string) (BlockUserInfo, error) { var blockUserInfo BlockUserInfo - blockUser := db.BlackList{ + blockUser := BlackList{ UserId: userId, } if err := db.DB.MysqlDB.DefaultGormDB().Table("black_lists").Where("uid=?", userId).Find(&blockUser).Error; err != nil { return blockUserInfo, err } - user := db.User{ + user := User{ UserID: blockUser.UserId, } if err := db.DB.MysqlDB.DefaultGormDB().Find(&user).Error; err != nil { @@ -223,15 +223,15 @@ func GetBlockUserByID(userId string) (BlockUserInfo, error) { func GetBlockUsers(showNumber, pageNumber int32) ([]BlockUserInfo, error) { var blockUserInfos []BlockUserInfo - var blockUsers []db.BlackList + var blockUsers []BlackList if err := db.DB.MysqlDB.DefaultGormDB().Limit(int(showNumber)).Offset(int(showNumber * (pageNumber - 1))).Find(&blockUsers).Error; err != nil { return blockUserInfos, err } for _, blockUser := range blockUsers { - var user db.User + var user User if err := db.DB.MysqlDB.DefaultGormDB().Table("users").Where("user_id=?", blockUser.UserId).First(&user).Error; err == nil { blockUserInfos = append(blockUserInfos, BlockUserInfo{ - User: db.User{ + User: User{ UserID: user.UserID, Nickname: user.Nickname, FaceURL: user.FaceURL, @@ -248,14 +248,14 @@ func GetBlockUsers(showNumber, pageNumber int32) ([]BlockUserInfo, error) { return blockUserInfos, nil } -func GetUserByName(userName string, showNumber, pageNumber int32) ([]db.User, error) { - var users []db.User +func GetUserByName(userName string, showNumber, pageNumber int32) ([]User, error) { + var users []User err := db.DB.MysqlDB.DefaultGormDB().Table("users").Where(" name like ?", fmt.Sprintf("%%%s%%", userName)).Limit(int(showNumber)).Offset(int(showNumber * (pageNumber - 1))).Find(&users).Error return users, err } -func GetUsersByNameAndID(content string, showNumber, pageNumber int32) ([]db.User, int64, error) { - var users []db.User +func GetUsersByNameAndID(content string, showNumber, pageNumber int32) ([]User, int64, error) { + var users []User var count int64 db := db.DB.MysqlDB.DefaultGormDB().Table("users").Where(" name like ? or user_id = ? ", fmt.Sprintf("%%%s%%", content), content) if err := db.Count(&count).Error; err != nil { @@ -291,7 +291,7 @@ func GetUsersCount(userName string) (int32, error) { func GetBlockUsersNumCount() (int32, error) { var count int64 - if err := db.DB.MysqlDB.DefaultGormDB().Model(&db.BlackList{}).Count(&count).Error; err != nil { + if err := db.DB.MysqlDB.DefaultGormDB().Model(&BlackList{}).Count(&count).Error; err != nil { return 0, err } return int32(count), nil diff --git a/pkg/common/db/mysql_model/im_mysql_msg_model/chat_log_model.go b/pkg/common/db/mysql_model/im_mysql_msg_model/chat_log_model.go index be617b798..e11ef2866 100644 --- a/pkg/common/db/mysql_model/im_mysql_msg_model/chat_log_model.go +++ b/pkg/common/db/mysql_model/im_mysql_msg_model/chat_log_model.go @@ -9,6 +9,7 @@ package im_mysql_msg_model import ( "Open_IM/pkg/common/constant" "Open_IM/pkg/common/db" + "Open_IM/pkg/common/db/mysql_model/im_mysql_model" "Open_IM/pkg/common/log" pbMsg "Open_IM/pkg/proto/msg" "Open_IM/pkg/proto/sdk_ws" @@ -19,7 +20,7 @@ import ( ) func InsertMessageToChatLog(msg pbMsg.MsgDataToMQ) error { - chatLog := new(db.ChatLog) + chatLog := new(im_mysql_model.ChatLog) copier.Copy(chatLog, msg.MsgData) switch msg.MsgData.SessionType { case constant.GroupChatType, constant.SuperGroupChatType: diff --git a/pkg/common/db/rocks_cache/rocks_cache.go b/pkg/common/db/rocks_cache/rocks_cache.go index 3b054d37f..dabbcc747 100644 --- a/pkg/common/db/rocks_cache/rocks_cache.go +++ b/pkg/common/db/rocks_cache/rocks_cache.go @@ -184,7 +184,7 @@ func DelGroupMemberIDListFromCache(groupID string) error { return err } -func GetUserInfoFromCache(userID string) (*db.User, error) { +func GetUserInfoFromCache(userID string) (*imdb.User, error) { getUserInfo := func() (string, error) { userInfo, err := imdb.GetUserByUserID(userID) if err != nil { @@ -200,7 +200,7 @@ func GetUserInfoFromCache(userID string) (*db.User, error) { if err != nil { return nil, utils.Wrap(err, "") } - userInfo := &db.User{} + userInfo := &imdb.User{} err = json.Unmarshal([]byte(userInfoStr), userInfo) return userInfo, utils.Wrap(err, "") } @@ -209,7 +209,7 @@ func DelUserInfoFromCache(userID string) error { return db.DB.Rc.TagAsDeleted(userInfoCache + userID) } -func GetGroupMemberInfoFromCache(groupID, userID string) (*db.GroupMember, error) { +func GetGroupMemberInfoFromCache(groupID, userID string) (*imdb.GroupMember, error) { getGroupMemberInfo := func() (string, error) { groupMemberInfo, err := imdb.GetGroupMemberInfoByGroupIDAndUserID(groupID, userID) if err != nil { @@ -225,7 +225,7 @@ func GetGroupMemberInfoFromCache(groupID, userID string) (*db.GroupMember, error if err != nil { return nil, utils.Wrap(err, "") } - groupMember := &db.GroupMember{} + groupMember := &imdb.GroupMember{} err = json.Unmarshal([]byte(groupMemberInfoStr), groupMember) return groupMember, utils.Wrap(err, "") } @@ -234,7 +234,7 @@ func DelGroupMemberInfoFromCache(groupID, userID string) error { return db.DB.Rc.TagAsDeleted(groupMemberInfoCache + groupID + "-" + userID) } -func GetGroupMembersInfoFromCache(count, offset int32, groupID string) ([]*db.GroupMember, error) { +func GetGroupMembersInfoFromCache(count, offset int32, groupID string) ([]*imdb.GroupMember, error) { groupMemberIDList, err := GetGroupMemberIDListFromCache(groupID) if err != nil { return nil, err @@ -242,7 +242,7 @@ func GetGroupMembersInfoFromCache(count, offset int32, groupID string) ([]*db.Gr if count < 0 || offset < 0 { return nil, nil } - var groupMemberList []*db.GroupMember + var groupMemberList []*imdb.GroupMember var start, stop int32 start = offset stop = offset + count @@ -278,7 +278,7 @@ func GetGroupMembersInfoFromCache(count, offset int32, groupID string) ([]*db.Gr return groupMemberList, nil } -func GetAllGroupMembersInfoFromCache(groupID string) ([]*db.GroupMember, error) { +func GetAllGroupMembersInfoFromCache(groupID string) ([]*imdb.GroupMember, error) { getGroupMemberInfo := func() (string, error) { groupMembers, err := imdb.GetGroupMemberListByGroupID(groupID) if err != nil { @@ -294,7 +294,7 @@ func GetAllGroupMembersInfoFromCache(groupID string) ([]*db.GroupMember, error) if err != nil { return nil, utils.Wrap(err, "") } - var groupMembers []*db.GroupMember + var groupMembers []*imdb.GroupMember err = json.Unmarshal([]byte(groupMembersStr), &groupMembers) return groupMembers, utils.Wrap(err, "") } @@ -303,7 +303,7 @@ func DelAllGroupMembersInfoFromCache(groupID string) error { return db.DB.Rc.TagAsDeleted(groupAllMemberInfoCache + groupID) } -func GetGroupInfoFromCache(groupID string) (*db.Group, error) { +func GetGroupInfoFromCache(groupID string) (*imdb.Group, error) { getGroupInfo := func() (string, error) { groupInfo, err := imdb.GetGroupInfoByGroupID(groupID) if err != nil { @@ -319,7 +319,7 @@ func GetGroupInfoFromCache(groupID string) (*db.Group, error) { if err != nil { return nil, utils.Wrap(err, "") } - groupInfo := &db.Group{} + groupInfo := &imdb.Group{} err = json.Unmarshal([]byte(groupInfoStr), groupInfo) return groupInfo, utils.Wrap(err, "") } @@ -328,7 +328,7 @@ func DelGroupInfoFromCache(groupID string) error { return db.DB.Rc.TagAsDeleted(groupInfoCache + groupID) } -func GetAllFriendsInfoFromCache(userID string) ([]*db.Friend, error) { +func GetAllFriendsInfoFromCache(userID string) ([]*imdb.Friend, error) { getAllFriendInfo := func() (string, error) { friendInfoList, err := imdb.GetFriendListByUserID(userID) if err != nil { @@ -344,7 +344,7 @@ func GetAllFriendsInfoFromCache(userID string) ([]*db.Friend, error) { if err != nil { return nil, utils.Wrap(err, "") } - var friendInfoList []*db.Friend + var friendInfoList []*imdb.Friend err = json.Unmarshal([]byte(allFriendInfoStr), &friendInfoList) return friendInfoList, utils.Wrap(err, "") } @@ -353,7 +353,7 @@ func DelAllFriendsInfoFromCache(userID string) error { return db.DB.Rc.TagAsDeleted(allFriendInfoCache + userID) } -func GetAllDepartmentsFromCache() ([]db.Department, error) { +func GetAllDepartmentsFromCache() ([]imdb.Department, error) { getAllDepartments := func() (string, error) { departmentList, err := imdb.GetSubDepartmentList("-1") if err != nil { @@ -369,7 +369,7 @@ func GetAllDepartmentsFromCache() ([]db.Department, error) { if err != nil { return nil, utils.Wrap(err, "") } - var allDepartments []db.Department + var allDepartments []imdb.Department err = json.Unmarshal([]byte(allDepartmentsStr), &allDepartments) return allDepartments, utils.Wrap(err, "") } @@ -378,7 +378,7 @@ func DelAllDepartmentsFromCache() error { return db.DB.Rc.TagAsDeleted(allDepartmentCache) } -func GetAllDepartmentMembersFromCache() ([]db.DepartmentMember, error) { +func GetAllDepartmentMembersFromCache() ([]imdb.DepartmentMember, error) { getAllDepartmentMembers := func() (string, error) { departmentMembers, err := imdb.GetDepartmentMemberList("-1") if err != nil { @@ -394,7 +394,7 @@ func GetAllDepartmentMembersFromCache() ([]db.DepartmentMember, error) { if err != nil { return nil, utils.Wrap(err, "") } - var allDepartmentMembers []db.DepartmentMember + var allDepartmentMembers []imdb.DepartmentMember err = json.Unmarshal([]byte(allDepartmentMembersStr), &allDepartmentMembers) return allDepartmentMembers, utils.Wrap(err, "") } @@ -510,7 +510,7 @@ func DelUserConversationIDListFromCache(userID string) error { return utils.Wrap(db.DB.Rc.TagAsDeleted(conversationIDListCache+userID), "DelUserConversationIDListFromCache err") } -func GetConversationFromCache(ownerUserID, conversationID string) (*db.Conversation, error) { +func GetConversationFromCache(ownerUserID, conversationID string) (*imdb.Conversation, error) { getConversation := func() (string, error) { conversation, err := imdb.GetConversation(ownerUserID, conversationID) if err != nil { @@ -526,7 +526,7 @@ func GetConversationFromCache(ownerUserID, conversationID string) (*db.Conversat if err != nil { return nil, utils.Wrap(err, "Fetch failed") } - conversation := db.Conversation{} + conversation := imdb.Conversation{} err = json.Unmarshal([]byte(conversationStr), &conversation) if err != nil { return nil, utils.Wrap(err, "Unmarshal failed") @@ -534,8 +534,8 @@ func GetConversationFromCache(ownerUserID, conversationID string) (*db.Conversat return &conversation, nil } -func GetConversationsFromCache(ownerUserID string, conversationIDList []string) ([]db.Conversation, error) { - var conversationList []db.Conversation +func GetConversationsFromCache(ownerUserID string, conversationIDList []string) ([]imdb.Conversation, error) { + var conversationList []imdb.Conversation for _, conversationID := range conversationIDList { conversation, err := GetConversationFromCache(ownerUserID, conversationID) if err != nil { @@ -546,12 +546,12 @@ func GetConversationsFromCache(ownerUserID string, conversationIDList []string) return conversationList, nil } -func GetUserAllConversationList(ownerUserID string) ([]db.Conversation, error) { +func GetUserAllConversationList(ownerUserID string) ([]imdb.Conversation, error) { IDList, err := GetUserConversationIDListFromCache(ownerUserID) if err != nil { return nil, err } - var conversationList []db.Conversation + var conversationList []imdb.Conversation log.NewDebug("", utils.GetSelfFuncName(), IDList) for _, conversationID := range IDList { conversation, err := GetConversationFromCache(ownerUserID, conversationID) diff --git a/pkg/common/utils/utils.go b/pkg/common/utils/utils.go index 00c86c454..fd8d43fac 100644 --- a/pkg/common/utils/utils.go +++ b/pkg/common/utils/utils.go @@ -1,7 +1,6 @@ package utils import ( - db "Open_IM/pkg/common/db" imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model" "Open_IM/pkg/common/token_verify" open_im_sdk "Open_IM/pkg/proto/sdk_ws" @@ -15,13 +14,13 @@ func OperationIDGenerator() string { return strconv.FormatInt(time.Now().UnixNano()+int64(rand.Uint32()), 10) } -func FriendOpenIMCopyDB(dst *db.Friend, src *open_im_sdk.FriendInfo) { +func FriendOpenIMCopyDB(dst *imdb.Friend, src *open_im_sdk.FriendInfo) { utils.CopyStructFields(dst, src) dst.FriendUserID = src.FriendUser.UserID dst.CreateTime = utils.UnixSecondToTime(int64(src.CreateTime)) } -func FriendDBCopyOpenIM(dst *open_im_sdk.FriendInfo, src *db.Friend) error { +func FriendDBCopyOpenIM(dst *open_im_sdk.FriendInfo, src *imdb.Friend) error { utils.CopyStructFields(dst, src) user, err := imdb.GetUserByUserID(src.FriendUserID) if err != nil { @@ -36,14 +35,13 @@ func FriendDBCopyOpenIM(dst *open_im_sdk.FriendInfo, src *db.Friend) error { return nil } -// -func FriendRequestOpenIMCopyDB(dst *db.FriendRequest, src *open_im_sdk.FriendRequest) { +func FriendRequestOpenIMCopyDB(dst *imdb.FriendRequest, src *open_im_sdk.FriendRequest) { utils.CopyStructFields(dst, src) dst.CreateTime = utils.UnixSecondToTime(int64(src.CreateTime)) dst.HandleTime = utils.UnixSecondToTime(int64(src.HandleTime)) } -func FriendRequestDBCopyOpenIM(dst *open_im_sdk.FriendRequest, src *db.FriendRequest) error { +func FriendRequestDBCopyOpenIM(dst *open_im_sdk.FriendRequest, src *imdb.FriendRequest) error { utils.CopyStructFields(dst, src) user, err := imdb.GetUserByUserID(src.FromUserID) if err != nil { @@ -64,13 +62,13 @@ func FriendRequestDBCopyOpenIM(dst *open_im_sdk.FriendRequest, src *db.FriendReq return nil } -func BlackOpenIMCopyDB(dst *db.Black, src *open_im_sdk.BlackInfo) { +func BlackOpenIMCopyDB(dst *imdb.Black, src *open_im_sdk.BlackInfo) { utils.CopyStructFields(dst, src) dst.BlockUserID = src.BlackUserInfo.UserID dst.CreateTime = utils.UnixSecondToTime(int64(src.CreateTime)) } -func BlackDBCopyOpenIM(dst *open_im_sdk.BlackInfo, src *db.Black) error { +func BlackDBCopyOpenIM(dst *open_im_sdk.BlackInfo, src *imdb.Black) error { utils.CopyStructFields(dst, src) dst.CreateTime = uint32(src.CreateTime.Unix()) user, err := imdb.GetUserByUserID(src.BlockUserID) @@ -81,11 +79,11 @@ func BlackDBCopyOpenIM(dst *open_im_sdk.BlackInfo, src *db.Black) error { return nil } -func GroupOpenIMCopyDB(dst *db.Group, src *open_im_sdk.GroupInfo) { +func GroupOpenIMCopyDB(dst *imdb.Group, src *open_im_sdk.GroupInfo) { utils.CopyStructFields(dst, src) } -func GroupDBCopyOpenIM(dst *open_im_sdk.GroupInfo, src *db.Group) error { +func GroupDBCopyOpenIM(dst *open_im_sdk.GroupInfo, src *imdb.Group) error { utils.CopyStructFields(dst, src) user, err := imdb.GetGroupOwnerInfoByGroupID(src.GroupID) if err != nil { @@ -106,11 +104,11 @@ func GroupDBCopyOpenIM(dst *open_im_sdk.GroupInfo, src *db.Group) error { return nil } -func GroupMemberOpenIMCopyDB(dst *db.GroupMember, src *open_im_sdk.GroupMemberFullInfo) { +func GroupMemberOpenIMCopyDB(dst *imdb.GroupMember, src *open_im_sdk.GroupMemberFullInfo) { utils.CopyStructFields(dst, src) } -func GroupMemberDBCopyOpenIM(dst *open_im_sdk.GroupMemberFullInfo, src *db.GroupMember) error { +func GroupMemberDBCopyOpenIM(dst *open_im_sdk.GroupMemberFullInfo, src *imdb.GroupMember) error { utils.CopyStructFields(dst, src) if token_verify.IsManagerUserID(src.UserID) { u, err := imdb.GetUserByUserID(src.UserID) @@ -134,29 +132,29 @@ func GroupMemberDBCopyOpenIM(dst *open_im_sdk.GroupMemberFullInfo, src *db.Group return nil } -func GroupRequestOpenIMCopyDB(dst *db.GroupRequest, src *open_im_sdk.GroupRequest) { +func GroupRequestOpenIMCopyDB(dst *imdb.GroupRequest, src *open_im_sdk.GroupRequest) { utils.CopyStructFields(dst, src) } -func GroupRequestDBCopyOpenIM(dst *open_im_sdk.GroupRequest, src *db.GroupRequest) { +func GroupRequestDBCopyOpenIM(dst *open_im_sdk.GroupRequest, src *imdb.GroupRequest) { utils.CopyStructFields(dst, src) dst.ReqTime = uint32(src.ReqTime.Unix()) dst.HandleTime = uint32(src.HandledTime.Unix()) } -func UserOpenIMCopyDB(dst *db.User, src *open_im_sdk.UserInfo) { +func UserOpenIMCopyDB(dst *imdb.User, src *open_im_sdk.UserInfo) { utils.CopyStructFields(dst, src) dst.Birth, _ = utils.TimeStringToTime(src.BirthStr) dst.CreateTime = utils.UnixSecondToTime(int64(src.CreateTime)) } -func UserDBCopyOpenIM(dst *open_im_sdk.UserInfo, src *db.User) { +func UserDBCopyOpenIM(dst *open_im_sdk.UserInfo, src *imdb.User) { utils.CopyStructFields(dst, src) dst.CreateTime = uint32(src.CreateTime.Unix()) //dst.Birth = uint32(src.Birth.Unix()) dst.BirthStr = utils.TimeToString(src.Birth) } -func UserDBCopyOpenIMPublicUser(dst *open_im_sdk.PublicUserInfo, src *db.User) { +func UserDBCopyOpenIMPublicUser(dst *open_im_sdk.PublicUserInfo, src *imdb.User) { utils.CopyStructFields(dst, src) }