Error code standardization

test-errcode
skiffer-git 2 years ago
parent 5a2a57c706
commit 86bf207e02

@ -3,7 +3,6 @@ package register
import ( import (
//api "Open_IM/pkg/base_info" //api "Open_IM/pkg/base_info"
"Open_IM/pkg/common/constant" "Open_IM/pkg/common/constant"
"Open_IM/pkg/common/db"
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model" imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
"Open_IM/pkg/common/log" "Open_IM/pkg/common/log"
"Open_IM/pkg/utils" "Open_IM/pkg/utils"
@ -75,7 +74,7 @@ func AddIPLimit(c *gin.Context) {
return return
} }
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req:", req) log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req:", req)
if err := imdb.InsertOneIntoIpLimits(db.IpLimit{ if err := imdb.InsertOneIntoIpLimits(imdb.IpLimit{
Ip: req.IP, Ip: req.IP,
LimitRegister: 1, LimitRegister: 1,
LimitLogin: 1, LimitLogin: 1,
@ -162,8 +161,8 @@ func AddUserIPLimitLogin(c *gin.Context) {
return return
} }
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req:", req) log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req:", req)
userIp := db.UserIpLimit{UserID: req.UserID, Ip: req.IP} userIp := imdb.UserIpLimit{UserID: req.UserID, Ip: req.IP}
err := imdb.UpdateUserInfo(db.User{ err := imdb.UpdateUserInfo(imdb.User{
UserID: req.UserID, UserID: req.UserID,
// LoginLimit: 1, // LoginLimit: 1,
}) })
@ -211,7 +210,7 @@ func RemoveUserIPLimitLogin(c *gin.Context) {
return return
} }
if len(ips) == 0 { if len(ips) == 0 {
err := imdb.UpdateUserInfoByMap(db.User{ err := imdb.UpdateUserInfoByMap(imdb.User{
UserID: req.UserID, UserID: req.UserID,
}, map[string]interface{}{"login_limit": 0}) }, map[string]interface{}{"login_limit": 0})
if err != nil { if err != nil {

@ -3,7 +3,6 @@ package admin_cms
import ( import (
"Open_IM/pkg/common/config" "Open_IM/pkg/common/config"
"Open_IM/pkg/common/constant" "Open_IM/pkg/common/constant"
"Open_IM/pkg/common/db"
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model" imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
"Open_IM/pkg/common/log" "Open_IM/pkg/common/log"
promePkg "Open_IM/pkg/common/prometheus" 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) { func (s *adminCMSServer) GetChatLogs(_ context.Context, req *pbAdminCMS.GetChatLogsReq) (*pbAdminCMS.GetChatLogsResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "GetChatLogs", req.String()) log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "GetChatLogs", req.String())
resp := &pbAdminCMS.GetChatLogsResp{CommonResp: &pbAdminCMS.CommonResp{}, Pagination: &server_api_params.ResponsePagination{}} resp := &pbAdminCMS.GetChatLogsResp{CommonResp: &pbAdminCMS.CommonResp{}, Pagination: &server_api_params.ResponsePagination{}}
chatLog := db.ChatLog{ chatLog := imdb.ChatLog{
Content: req.Content, Content: req.Content,
ContentType: req.ContentType, ContentType: req.ContentType,
SessionType: req.SessionType, SessionType: req.SessionType,

@ -2,7 +2,6 @@ package auth
import ( import (
"Open_IM/pkg/common/constant" "Open_IM/pkg/common/constant"
"Open_IM/pkg/common/db"
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model" imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
"Open_IM/pkg/common/log" "Open_IM/pkg/common/log"
promePkg "Open_IM/pkg/common/prometheus" promePkg "Open_IM/pkg/common/prometheus"
@ -26,7 +25,7 @@ import (
func (rpc *rpcAuth) UserRegister(_ context.Context, req *pbAuth.UserRegisterReq) (*pbAuth.UserRegisterResp, error) { func (rpc *rpcAuth) UserRegister(_ context.Context, req *pbAuth.UserRegisterReq) (*pbAuth.UserRegisterResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc args ", req.String()) log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc args ", req.String())
var user db.User var user imdb.User
utils.CopyStructFields(&user, req.UserInfo) utils.CopyStructFields(&user, req.UserInfo)
if req.UserInfo.BirthStr != "" { if req.UserInfo.BirthStr != "" {
time, err := utils.TimeStringToTime(req.UserInfo.BirthStr) time, err := utils.TimeStringToTime(req.UserInfo.BirthStr)

@ -48,7 +48,7 @@ func (rpc *rpcConversation) ModifyConversationField(c context.Context, req *pbCo
return resp, nil return resp, nil
} }
} }
var conversation db.Conversation var conversation imdb.Conversation
if err := utils.CopyStructFields(&conversation, req.Conversation); err != nil { if err := utils.CopyStructFields(&conversation, req.Conversation); err != nil {
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", *req.Conversation, err.Error()) 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 return resp, nil
} }
func syncPeerUserConversation(conversation *pbConversation.Conversation, operationID string) error { func syncPeerUserConversation(conversation *pbConversation.Conversation, operationID string) error {
peerUserConversation := db.Conversation{ peerUserConversation := imdb.Conversation{
OwnerUserID: conversation.UserID, OwnerUserID: conversation.UserID,
ConversationID: utils.GetConversationIDBySessionType(conversation.OwnerUserID, constant.SingleChatType), ConversationID: utils.GetConversationIDBySessionType(conversation.OwnerUserID, constant.SingleChatType),
ConversationType: constant.SingleChatType, ConversationType: constant.SingleChatType,

@ -4,7 +4,6 @@ import (
chat "Open_IM/internal/rpc/msg" chat "Open_IM/internal/rpc/msg"
"Open_IM/pkg/common/config" "Open_IM/pkg/common/config"
"Open_IM/pkg/common/constant" "Open_IM/pkg/common/constant"
"Open_IM/pkg/common/db"
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model" imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
rocksCache "Open_IM/pkg/common/db/rocks_cache" rocksCache "Open_IM/pkg/common/db/rocks_cache"
"Open_IM/pkg/common/log" "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) log.NewError(req.CommID.OperationID, err.Error(), req.CommID.OpUserID, req.CommID.FromUserID)
return &pbFriend.AddBlacklistResp{CommonResp: constant.Error2CommResp(constant.ErrNoPermission, err)}, nil 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) err := imdb.InsertInToUserBlackList(black)
if err != nil { 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) 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 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()} HandleResult: 0, ReqMsg: req.ReqMsg, CreateTime: time.Now()}
utils.CopyStructFields(&friendRequest, req.CommID) 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 }] // {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 { } else {
if _, err := imdb.GetFriendRelationshipFromFriend(req.FromUserID, v); err != nil { if _, err := imdb.GetFriendRelationshipFromFriend(req.FromUserID, v); err != nil {
//Establish two single friendship //Establish two single friendship
toInsertFollow := db.Friend{OwnerUserID: req.FromUserID, FriendUserID: v} toInsertFollow := imdb.Friend{OwnerUserID: req.FromUserID, FriendUserID: v}
err1 := imdb.InsertToFriend(&toInsertFollow) err1 := imdb.InsertToFriend(&toInsertFollow)
if err1 != nil { if err1 != nil {
log.NewError(req.OperationID, "InsertToFriend failed ", err1.Error(), toInsertFollow) log.NewError(req.OperationID, "InsertToFriend failed ", err1.Error(), toInsertFollow)
resp.UserIDResultList = append(resp.UserIDResultList, &pbFriend.UserIDResult{UserID: v, Result: -1}) resp.UserIDResultList = append(resp.UserIDResultList, &pbFriend.UserIDResult{UserID: v, Result: -1})
continue continue
} }
toInsertFollow = db.Friend{OwnerUserID: v, FriendUserID: req.FromUserID} toInsertFollow = imdb.Friend{OwnerUserID: v, FriendUserID: req.FromUserID}
err2 := imdb.InsertToFriend(&toInsertFollow) err2 := imdb.InsertToFriend(&toInsertFollow)
if err2 != nil { if err2 != nil {
log.NewError(req.OperationID, "InsertToFriend failed ", err2.Error(), toInsertFollow) log.NewError(req.OperationID, "InsertToFriend failed ", err2.Error(), toInsertFollow)
@ -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) log.NewWarn(req.CommID.OperationID, "GetFriendRelationshipFromFriend exist", req.CommID.FromUserID, req.CommID.ToUserID)
} else { } else {
//Establish two single friendship //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) err = imdb.InsertToFriend(&toInsertFollow)
if err != nil { if err != nil {
log.NewError(req.CommID.OperationID, "InsertToFriend failed ", err.Error(), toInsertFollow) 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 { if err == nil {
log.NewWarn(req.CommID.OperationID, "GetFriendRelationshipFromFriend exist", req.CommID.ToUserID, req.CommID.FromUserID) log.NewWarn(req.CommID.OperationID, "GetFriendRelationshipFromFriend exist", req.CommID.ToUserID, req.CommID.FromUserID)
} else { } 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) err = imdb.InsertToFriend(&toInsertFollow)
if err != nil { if err != nil {
log.NewError(req.CommID.OperationID, "InsertToFriend failed ", err.Error(), toInsertFollow) log.NewError(req.CommID.OperationID, "InsertToFriend failed ", err.Error(), toInsertFollow)

@ -4,7 +4,7 @@ import (
cbApi "Open_IM/pkg/call_back_struct" cbApi "Open_IM/pkg/call_back_struct"
"Open_IM/pkg/common/config" "Open_IM/pkg/common/config"
"Open_IM/pkg/common/constant" "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/http"
"Open_IM/pkg/common/log" "Open_IM/pkg/common/log"
pbGroup "Open_IM/pkg/proto/group" pbGroup "Open_IM/pkg/proto/group"
@ -83,7 +83,7 @@ func callbackBeforeCreateGroup(req *pbGroup.CreateGroupReq) cbApi.CommonCallback
return callbackResp 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} callbackResp := cbApi.CommonCallbackResp{OperationID: operationID}
if !config.Config.Callback.CallbackBeforeMemberJoinGroup.Enable { if !config.Config.Callback.CallbackBeforeMemberJoinGroup.Enable {
return callbackResp return callbackResp

@ -143,7 +143,7 @@ func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupR
groupId = bi.String() groupId = bi.String()
} }
//to group //to group
groupInfo := db.Group{} groupInfo := imdb.Group{}
utils.CopyStructFields(&groupInfo, req.GroupInfo) utils.CopyStructFields(&groupInfo, req.GroupInfo)
groupInfo.CreatorUserID = req.OpUserID groupInfo.CreatorUserID = req.OpUserID
groupInfo.GroupID = groupId groupInfo.GroupID = groupId
@ -158,8 +158,8 @@ func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupR
} }
var okUserIDList []string var okUserIDList []string
resp := &pbGroup.CreateGroupResp{GroupInfo: &open_im_sdk.GroupInfo{}} resp := &pbGroup.CreateGroupResp{GroupInfo: &open_im_sdk.GroupInfo{}}
groupMember := db.GroupMember{} groupMember := imdb.GroupMember{}
us := &db.User{} us := &imdb.User{}
if req.OwnerUserID != "" { if req.OwnerUserID != "" {
var userIDList []string var userIDList []string
for _, v := range req.InitMemberList { 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 return &pbGroup.CreateGroupResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, nil
} }
//to group member //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) utils.CopyStructFields(&groupMember, us)
callbackResp := CallbackBeforeMemberJoinGroup(req.OperationID, &groupMember, groupInfo.Ex) callbackResp := CallbackBeforeMemberJoinGroup(req.OperationID, &groupMember, groupInfo.Ex)
if callbackResp.ErrCode != 0 { if callbackResp.ErrCode != 0 {
@ -367,7 +367,7 @@ func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbGroup.Invite
var resp pbGroup.InviteUserToGroupResp var resp pbGroup.InviteUserToGroupResp
joinReq := pbGroup.JoinGroupReq{} joinReq := pbGroup.JoinGroupReq{}
for _, v := range req.InvitedUserIDList { for _, v := range req.InvitedUserIDList {
var groupRequest db.GroupRequest var groupRequest imdb.GroupRequest
groupRequest.UserID = v groupRequest.UserID = v
groupRequest.GroupID = req.GroupID groupRequest.GroupID = req.GroupID
groupRequest.JoinSource = constant.JoinByInvitation groupRequest.JoinSource = constant.JoinByInvitation
@ -423,7 +423,7 @@ func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbGroup.Invite
resp.Id2ResultList = append(resp.Id2ResultList, &resultNode) resp.Id2ResultList = append(resp.Id2ResultList, &resultNode)
continue continue
} }
var toInsertInfo db.GroupMember var toInsertInfo imdb.GroupMember
utils.CopyStructFields(&toInsertInfo, toUserInfo) utils.CopyStructFields(&toInsertInfo, toUserInfo)
toInsertInfo.GroupID = req.GroupID toInsertInfo.GroupID = req.GroupID
toInsertInfo.RoleLevel = constant.GroupOrdinaryUsers toInsertInfo.RoleLevel = constant.GroupOrdinaryUsers
@ -867,17 +867,23 @@ func (s *groupServer) GetGroupsInfo(ctx context.Context, req *pbGroup.GetGroupsI
return &resp, nil return &resp, nil
} }
func (s *groupServer) GroupApplicationResponse(_ context.Context, req *pbGroup.GroupApplicationResponseReq) (*pbGroup.GroupApplicationResponseResp, error) { func CheckAppManagerAndGroupAdmin(string) {
log.NewInfo(req.OperationID, "GroupApplicationResponse args ", req.String())
groupRequest := db.GroupRequest{} }
utils.CopyStructFields(&groupRequest, req) func (s *groupServer) GroupApplicationResponse(ctx context.Context, req *pbGroup.GroupApplicationResponseReq) (*pbGroup.GroupApplicationResponseResp, error) {
groupRequest.UserID = req.FromUserID nCtx := trace_log.NewRpcCtx(ctx, utils.GetSelfFuncName(), req.OperationID)
groupRequest.HandleUserID = req.OpUserID trace_log.SetRpcReqInfo(nCtx, utils.GetSelfFuncName(), req.String())
groupRequest.HandledTime = time.Now() defer trace_log.ShowLog(nCtx)
if !token_verify.IsManagerUserID(req.OpUserID) && !imdb.IsGroupOwnerAdmin(req.GroupID, req.OpUserID) { if !token_verify.IsManagerUserID(req.OpUserID) && !imdb.IsGroupOwnerAdmin(req.GroupID, req.OpUserID) {
log.NewError(req.OperationID, "IsManagerUserID IsGroupOwnerAdmin false ", 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 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) err := imdb.UpdateGroupRequest(groupRequest)
if err != nil { if err != nil {
log.NewError(req.OperationID, "GroupApplicationResponse failed ", err.Error(), groupRequest) 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) 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 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.GroupID = req.GroupID
member.UserID = req.FromUserID member.UserID = req.FromUserID
member.RoleLevel = constant.GroupOrdinaryUsers 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 return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
} }
//to group member //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) utils.CopyStructFields(&groupMember, us)
callbackResp := CallbackBeforeMemberJoinGroup(req.OperationID, &groupMember, groupInfo.Ex) callbackResp := CallbackBeforeMemberJoinGroup(req.OperationID, &groupMember, groupInfo.Ex)
if callbackResp.ErrCode != 0 { 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 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.UserID = req.OpUserID
groupRequest.ReqMsg = req.ReqMessage groupRequest.ReqMsg = req.ReqMessage
groupRequest.GroupID = req.GroupID groupRequest.GroupID = req.GroupID
@ -1295,7 +1301,7 @@ func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbGroup.SetGroupInf
// //
//} //}
//only administrators can set group information //only administrators can set group information
var groupInfo db.Group var groupInfo imdb.Group
utils.CopyStructFields(&groupInfo, req.GroupInfoForSet) utils.CopyStructFields(&groupInfo, req.GroupInfoForSet)
if req.GroupInfoForSet.Notification != "" { if req.GroupInfoForSet.Notification != "" {
groupInfo.NotificationUserID = req.OpUserID 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 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) err = imdb.UpdateGroupMemberInfo(groupMemberInfo)
if err != nil { if err != nil {
log.NewError(req.OperationID, "UpdateGroupMemberInfo failed ", groupMemberInfo) log.NewError(req.OperationID, "UpdateGroupMemberInfo failed ", groupMemberInfo)
return &pbGroup.TransferGroupOwnerResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil 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) err = imdb.UpdateGroupMemberInfo(groupMemberInfo)
if err != nil { if err != nil {
log.NewError(req.OperationID, "UpdateGroupMemberInfo failed ", groupMemberInfo) 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) 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 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()) groupMemberInfo.MuteEndTime = time.Unix(int64(time.Now().Second())+int64(req.MutedSeconds), time.Now().UnixNano())
err = imdb.UpdateGroupMemberInfo(groupMemberInfo) err = imdb.UpdateGroupMemberInfo(groupMemberInfo)
if err != nil { 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 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) groupMemberInfo.MuteEndTime = time.Unix(0, 0)
err = imdb.UpdateGroupMemberInfo(groupMemberInfo) err = imdb.UpdateGroupMemberInfo(groupMemberInfo)
if err != nil { if err != nil {
@ -1828,7 +1834,7 @@ func (s *groupServer) SetGroupMemberNickname(ctx context.Context, req *pbGroup.S
} }
nickName := cbReq.Nickname.Value nickName := cbReq.Nickname.Value
groupMemberInfo := db.GroupMember{} groupMemberInfo := imdb.GroupMember{}
groupMemberInfo.UserID = req.UserID groupMemberInfo.UserID = req.UserID
groupMemberInfo.GroupID = req.GroupID groupMemberInfo.GroupID = req.GroupID
if nickName == "" { if nickName == "" {
@ -1884,7 +1890,7 @@ func (s *groupServer) SetGroupMemberInfo(ctx context.Context, req *pbGroup.SetGr
}, nil }, nil
} }
groupMember := db.GroupMember{ groupMember := imdb.GroupMember{
GroupID: req.GroupID, GroupID: req.GroupID,
UserID: req.UserID, UserID: req.UserID,
} }

@ -3,7 +3,7 @@ package msg
import ( import (
"Open_IM/pkg/common/config" "Open_IM/pkg/common/config"
"Open_IM/pkg/common/constant" "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/common/log"
"Open_IM/pkg/grpc-etcdv3/getcdv3" "Open_IM/pkg/grpc-etcdv3/getcdv3"
pbChat "Open_IM/pkg/proto/msg" pbChat "Open_IM/pkg/proto/msg"
@ -13,7 +13,7 @@ import (
"strings" "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) log.NewInfo(operationID, utils.GetSelfFuncName(), "args: ", user.UserID, recvID, content)
var req pbChat.SendMsgReq var req pbChat.SendMsgReq
var msgData pbCommon.MsgData var msgData pbCommon.MsgData

@ -109,7 +109,7 @@ func (s *officeServer) Run() {
type tagSendStruct struct { type tagSendStruct struct {
operationID string operationID string
user *db.User user *imdb.User
userID string userID string
content string content string
senderPlatformID int32 senderPlatformID int32

@ -4,7 +4,6 @@ import (
chat "Open_IM/internal/rpc/msg" chat "Open_IM/internal/rpc/msg"
"Open_IM/pkg/common/config" "Open_IM/pkg/common/config"
"Open_IM/pkg/common/constant" "Open_IM/pkg/common/constant"
"Open_IM/pkg/common/db"
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model" imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
rocksCache "Open_IM/pkg/common/db/rocks_cache" rocksCache "Open_IM/pkg/common/db/rocks_cache"
"Open_IM/pkg/common/log" "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 return &rpc.CreateDepartmentResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: errMsg}, nil
} }
department := db.Department{} department := imdb.Department{}
utils.CopyStructFields(&department, req.DepartmentInfo) utils.CopyStructFields(&department, req.DepartmentInfo)
if department.DepartmentID == "" { if department.DepartmentID == "" {
department.DepartmentID = utils.Md5(strconv.FormatInt(time.Now().UnixNano(), 10)) 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 return &rpc.UpdateDepartmentResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: errMsg}, nil
} }
department := db.Department{} department := imdb.Department{}
utils.CopyStructFields(&department, req.DepartmentInfo) utils.CopyStructFields(&department, req.DepartmentInfo)
log.Debug(req.OperationID, "dst ", department, "src ", req.DepartmentInfo) log.Debug(req.OperationID, "dst ", department, "src ", req.DepartmentInfo)
if err := imdb.UpdateDepartment(&department, nil); err != nil { 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) { func (s *organizationServer) GetSubDepartment(ctx context.Context, req *rpc.GetSubDepartmentReq) (*rpc.GetSubDepartmentResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc args ", req.String()) log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc args ", req.String())
var departmentList []db.Department var departmentList []imdb.Department
var err error var err error
if req.DepartmentID == "-1" { if req.DepartmentID == "-1" {
departmentList, err = rocksCache.GetAllDepartmentsFromCache() departmentList, err = rocksCache.GetAllDepartmentsFromCache()
@ -301,7 +300,7 @@ func (s *organizationServer) CreateOrganizationUser(ctx context.Context, req *rp
log.Error(req.OperationID, errMsg) log.Error(req.OperationID, errMsg)
return &rpc.CreateOrganizationUserResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: errMsg}, nil return &rpc.CreateOrganizationUserResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: errMsg}, nil
} }
organizationUser := db.OrganizationUser{} organizationUser := imdb.OrganizationUser{}
utils.CopyStructFields(&organizationUser, req.OrganizationUser) utils.CopyStructFields(&organizationUser, req.OrganizationUser)
organizationUser.Birth = utils.UnixSecondToTime(int64(req.OrganizationUser.Birth)) organizationUser.Birth = utils.UnixSecondToTime(int64(req.OrganizationUser.Birth))
log.Debug(req.OperationID, "src ", *req.OrganizationUser, "dst ", organizationUser) 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) log.Error(req.OperationID, errMsg)
return &rpc.UpdateOrganizationUserResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: errMsg}, nil return &rpc.UpdateOrganizationUserResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: errMsg}, nil
} }
organizationUser := db.OrganizationUser{} organizationUser := imdb.OrganizationUser{}
utils.CopyStructFields(&organizationUser, req.OrganizationUser) utils.CopyStructFields(&organizationUser, req.OrganizationUser)
if req.OrganizationUser.Birth != 0 { if req.OrganizationUser.Birth != 0 {
organizationUser.Birth = utils.UnixSecondToTime(int64(req.OrganizationUser.Birth)) 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 return &rpc.CreateDepartmentMemberResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: errMsg}, nil
} }
departmentMember := db.DepartmentMember{} departmentMember := imdb.DepartmentMember{}
utils.CopyStructFields(&departmentMember, req.DepartmentMember) utils.CopyStructFields(&departmentMember, req.DepartmentMember)
log.Debug(req.OperationID, "src ", *req.DepartmentMember, "dst ", departmentMember) log.Debug(req.OperationID, "src ", *req.DepartmentMember, "dst ", departmentMember)
err = imdb.CreateDepartmentMember(&departmentMember) err = imdb.CreateDepartmentMember(&departmentMember)
@ -439,7 +438,7 @@ func (s *organizationServer) UpdateUserInDepartment(ctx context.Context, req *rp
log.Error(req.OperationID, errMsg) log.Error(req.OperationID, errMsg)
return &rpc.UpdateUserInDepartmentResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: errMsg}, nil return &rpc.UpdateUserInDepartmentResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: errMsg}, nil
} }
departmentMember := &db.DepartmentMember{} departmentMember := &imdb.DepartmentMember{}
utils.CopyStructFields(departmentMember, req.DepartmentMember) utils.CopyStructFields(departmentMember, req.DepartmentMember)
log.Debug(req.OperationID, "dst ", departmentMember, "src ", req.DepartmentMember) log.Debug(req.OperationID, "dst ", departmentMember, "src ", req.DepartmentMember)
err := imdb.UpdateUserInDepartment(departmentMember, nil) 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) { func (s *organizationServer) GetDepartmentMember(ctx context.Context, req *rpc.GetDepartmentMemberReq) (*rpc.GetDepartmentMemberResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc args ", req.String()) log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc args ", req.String())
var departmentMemberList []db.DepartmentMember var departmentMemberList []imdb.DepartmentMember
var err error var err error
if req.DepartmentID == "-1" { if req.DepartmentID == "-1" {
departmentMemberList, err = rocksCache.GetAllDepartmentMembersFromCache() departmentMemberList, err = rocksCache.GetAllDepartmentMembersFromCache()

@ -100,7 +100,7 @@ func (s *userServer) Run() {
} }
func syncPeerUserConversation(conversation *pbConversation.Conversation, operationID string) error { func syncPeerUserConversation(conversation *pbConversation.Conversation, operationID string) error {
peerUserConversation := db.Conversation{ peerUserConversation := imdb.Conversation{
OwnerUserID: conversation.UserID, OwnerUserID: conversation.UserID,
ConversationID: utils.GetConversationIDBySessionType(conversation.OwnerUserID, constant.SingleChatType), ConversationID: utils.GetConversationIDBySessionType(conversation.OwnerUserID, constant.SingleChatType),
ConversationType: constant.SingleChatType, ConversationType: constant.SingleChatType,
@ -152,7 +152,7 @@ func (s *userServer) BatchSetConversations(ctx context.Context, req *pbUser.Batc
} }
resp := &pbUser.BatchSetConversationsResp{} resp := &pbUser.BatchSetConversationsResp{}
for _, v := range req.Conversations { for _, v := range req.Conversations {
conversation := db.Conversation{} conversation := imdb.Conversation{}
if err := utils.CopyStructFields(&conversation, v); err != nil { if err := utils.CopyStructFields(&conversation, v); err != nil {
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), v.String(), "CopyStructFields failed", err.Error()) 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 return resp, nil
} }
} }
var conversation db.Conversation var conversation imdb.Conversation
if err := utils.CopyStructFields(&conversation, req.Conversation); err != nil { if err := utils.CopyStructFields(&conversation, req.Conversation); err != nil {
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", *req.Conversation, err.Error()) 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) { func (s *userServer) SetRecvMsgOpt(ctx context.Context, req *pbUser.SetRecvMsgOptReq) (*pbUser.SetRecvMsgOptResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String()) log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
resp := &pbUser.SetRecvMsgOptResp{} resp := &pbUser.SetRecvMsgOptResp{}
var conversation db.Conversation var conversation imdb.Conversation
if err := utils.CopyStructFields(&conversation, req); err != nil { if err := utils.CopyStructFields(&conversation, req); err != nil {
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", *req, err.Error()) 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 oldNickname = u.Nickname
} }
} }
var user db.User var user imdb.User
utils.CopyStructFields(&user, req.UserInfo) utils.CopyStructFields(&user, req.UserInfo)
if req.UserInfo.BirthStr != "" { 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) { func (s *userServer) SetGlobalRecvMessageOpt(ctx context.Context, req *pbUser.SetGlobalRecvMessageOptReq) (*pbUser.SetGlobalRecvMessageOptResp, error) {
log.NewInfo(req.OperationID, "SetGlobalRecvMessageOpt args ", req.String()) log.NewInfo(req.OperationID, "SetGlobalRecvMessageOpt args ", req.String())
var user db.User var user imdb.User
user.UserID = req.UserID user.UserID = req.UserID
m := make(map[string]interface{}, 1) m := make(map[string]interface{}, 1)
@ -496,7 +496,7 @@ func (s *userServer) SyncJoinedGroupMemberFaceURL(userID string, faceURL string,
return return
} }
for _, groupID := range joinedGroupIDList { 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 { if err := imdb.UpdateGroupMemberInfo(groupMemberInfo); err != nil {
log.NewError(operationID, utils.GetSelfFuncName(), err.Error(), groupMemberInfo) log.NewError(operationID, utils.GetSelfFuncName(), err.Error(), groupMemberInfo)
continue continue
@ -526,7 +526,7 @@ func (s *userServer) SyncJoinedGroupMemberNickname(userID string, newNickname, o
continue continue
} }
if member.Nickname == oldNickname { 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 { if err := imdb.UpdateGroupMemberInfo(groupMemberInfo); err != nil {
log.NewError(operationID, utils.GetSelfFuncName(), err.Error(), groupMemberInfo) log.NewError(operationID, utils.GetSelfFuncName(), err.Error(), groupMemberInfo)
continue 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) { func (s *userServer) GetUsers(ctx context.Context, req *pbUser.GetUsersReq) (*pbUser.GetUsersResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String()) log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
var usersDB []db.User var usersDB []imdb.User
var err error var err error
resp := &pbUser.GetUsersResp{CommonResp: &pbUser.CommonResp{}, Pagination: &sdkws.ResponsePagination{CurrentPage: req.Pagination.PageNumber, ShowNumber: req.Pagination.ShowNumber}} resp := &pbUser.GetUsersResp{CommonResp: &pbUser.CommonResp{}, Pagination: &sdkws.ResponsePagination{CurrentPage: req.Pagination.PageNumber, ShowNumber: req.Pagination.ShowNumber}}
if req.UserID != "" { if req.UserID != "" {

@ -10,6 +10,7 @@ import (
type ErrInfo struct { type ErrInfo struct {
ErrCode int32 ErrCode int32
ErrMsg string ErrMsg string
WrapErrMsg string
} }
func (e ErrInfo) Error() string { func (e ErrInfo) Error() string {

@ -2,6 +2,7 @@ package db
import ( import (
"Open_IM/pkg/common/config" "Open_IM/pkg/common/config"
"Open_IM/pkg/common/db/mysql_model/im_mysql_model"
"fmt" "fmt"
"time" "time"
@ -68,80 +69,80 @@ func initMysqlDB() {
sqlDB.SetMaxIdleConns(config.Config.Mysql.DBMaxIdleConns) sqlDB.SetMaxIdleConns(config.Config.Mysql.DBMaxIdleConns)
db.AutoMigrate( db.AutoMigrate(
&Register{}, &im_mysql_model.Register{},
&Friend{}, &im_mysql_model.Friend{},
&FriendRequest{}, &im_mysql_model.FriendRequest{},
&Group{}, &im_mysql_model.Group{},
&GroupMember{}, &im_mysql_model.GroupMember{},
&GroupRequest{}, &im_mysql_model.GroupRequest{},
&User{}, &im_mysql_model.User{},
&Black{}, &ChatLog{}, &Register{}, &Conversation{}, &AppVersion{}, &Department{}, &BlackList{}, &IpLimit{}, &UserIpLimit{}, &Invitation{}, &RegisterAddFriend{}, &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{},
&ClientInitConfig{}, &UserIpRecord{}) &im_mysql_model.ClientInitConfig{}, &im_mysql_model.UserIpRecord{})
db.Set("gorm:table_options", "CHARSET=utf8") db.Set("gorm:table_options", "CHARSET=utf8")
db.Set("gorm:table_options", "collation=utf8_unicode_ci") db.Set("gorm:table_options", "collation=utf8_unicode_ci")
if !db.Migrator().HasTable(&Friend{}) { if !db.Migrator().HasTable(&im_mysql_model.Friend{}) {
db.Migrator().CreateTable(&Friend{}) db.Migrator().CreateTable(&im_mysql_model.Friend{})
} }
if !db.Migrator().HasTable(&FriendRequest{}) { if !db.Migrator().HasTable(&im_mysql_model.FriendRequest{}) {
db.Migrator().CreateTable(&FriendRequest{}) db.Migrator().CreateTable(&im_mysql_model.FriendRequest{})
} }
if !db.Migrator().HasTable(&Group{}) { if !db.Migrator().HasTable(&im_mysql_model.Group{}) {
db.Migrator().CreateTable(&Group{}) db.Migrator().CreateTable(&im_mysql_model.Group{})
} }
if !db.Migrator().HasTable(&GroupMember{}) { if !db.Migrator().HasTable(&im_mysql_model.GroupMember{}) {
db.Migrator().CreateTable(&GroupMember{}) db.Migrator().CreateTable(&im_mysql_model.GroupMember{})
} }
if !db.Migrator().HasTable(&GroupRequest{}) { if !db.Migrator().HasTable(&im_mysql_model.GroupRequest{}) {
db.Migrator().CreateTable(&GroupRequest{}) db.Migrator().CreateTable(&im_mysql_model.GroupRequest{})
} }
if !db.Migrator().HasTable(&User{}) { if !db.Migrator().HasTable(&im_mysql_model.User{}) {
db.Migrator().CreateTable(&User{}) db.Migrator().CreateTable(&im_mysql_model.User{})
} }
if !db.Migrator().HasTable(&Black{}) { if !db.Migrator().HasTable(&im_mysql_model.Black{}) {
db.Migrator().CreateTable(&Black{}) db.Migrator().CreateTable(&im_mysql_model.Black{})
} }
if !db.Migrator().HasTable(&ChatLog{}) { if !db.Migrator().HasTable(&im_mysql_model.ChatLog{}) {
db.Migrator().CreateTable(&ChatLog{}) db.Migrator().CreateTable(&im_mysql_model.ChatLog{})
} }
if !db.Migrator().HasTable(&Register{}) { if !db.Migrator().HasTable(&im_mysql_model.Register{}) {
db.Migrator().CreateTable(&Register{}) db.Migrator().CreateTable(&im_mysql_model.Register{})
} }
if !db.Migrator().HasTable(&Conversation{}) { if !db.Migrator().HasTable(&im_mysql_model.Conversation{}) {
db.Migrator().CreateTable(&Conversation{}) db.Migrator().CreateTable(&im_mysql_model.Conversation{})
} }
if !db.Migrator().HasTable(&Department{}) { if !db.Migrator().HasTable(&im_mysql_model.Department{}) {
db.Migrator().CreateTable(&Department{}) db.Migrator().CreateTable(&im_mysql_model.Department{})
} }
if !db.Migrator().HasTable(&OrganizationUser{}) { if !db.Migrator().HasTable(&im_mysql_model.OrganizationUser{}) {
db.Migrator().CreateTable(&OrganizationUser{}) db.Migrator().CreateTable(&im_mysql_model.OrganizationUser{})
} }
if !db.Migrator().HasTable(&DepartmentMember{}) { if !db.Migrator().HasTable(&im_mysql_model.DepartmentMember{}) {
db.Migrator().CreateTable(&DepartmentMember{}) db.Migrator().CreateTable(&im_mysql_model.DepartmentMember{})
} }
if !db.Migrator().HasTable(&AppVersion{}) { if !db.Migrator().HasTable(&im_mysql_model.AppVersion{}) {
db.Migrator().CreateTable(&AppVersion{}) db.Migrator().CreateTable(&im_mysql_model.AppVersion{})
} }
if !db.Migrator().HasTable(&BlackList{}) { if !db.Migrator().HasTable(&im_mysql_model.BlackList{}) {
db.Migrator().CreateTable(&BlackList{}) db.Migrator().CreateTable(&im_mysql_model.BlackList{})
} }
if !db.Migrator().HasTable(&IpLimit{}) { if !db.Migrator().HasTable(&im_mysql_model.IpLimit{}) {
db.Migrator().CreateTable(&IpLimit{}) db.Migrator().CreateTable(&im_mysql_model.IpLimit{})
} }
if !db.Migrator().HasTable(&UserIpLimit{}) { if !db.Migrator().HasTable(&im_mysql_model.UserIpLimit{}) {
db.Migrator().CreateTable(&UserIpLimit{}) db.Migrator().CreateTable(&im_mysql_model.UserIpLimit{})
} }
if !db.Migrator().HasTable(&RegisterAddFriend{}) { if !db.Migrator().HasTable(&im_mysql_model.RegisterAddFriend{}) {
db.Migrator().CreateTable(&RegisterAddFriend{}) db.Migrator().CreateTable(&im_mysql_model.RegisterAddFriend{})
} }
if !db.Migrator().HasTable(&Invitation{}) { if !db.Migrator().HasTable(&im_mysql_model.Invitation{}) {
db.Migrator().CreateTable(&Invitation{}) db.Migrator().CreateTable(&im_mysql_model.Invitation{})
} }
if !db.Migrator().HasTable(&ClientInitConfig{}) { if !db.Migrator().HasTable(&im_mysql_model.ClientInitConfig{}) {
db.Migrator().CreateTable(&ClientInitConfig{}) db.Migrator().CreateTable(&im_mysql_model.ClientInitConfig{})
} }
if !db.Migrator().HasTable(&UserIpRecord{}) { if !db.Migrator().HasTable(&im_mysql_model.UserIpRecord{}) {
db.Migrator().CreateTable(&UserIpRecord{}) db.Migrator().CreateTable(&im_mysql_model.UserIpRecord{})
} }
DB.MysqlDB.db = db DB.MysqlDB.db = db
} }

@ -3,20 +3,20 @@ package im_mysql_model
import "Open_IM/pkg/common/db" import "Open_IM/pkg/common/db"
func SetClientInitConfig(m map[string]interface{}) error { 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 { if result.Error != nil {
return result.Error return result.Error
} }
if result.RowsAffected == 0 { 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 err
} }
return nil return nil
} }
func GetClientInitConfig() (db.ClientInitConfig, error) { func GetClientInitConfig() (ClientInitConfig, error) {
var config db.ClientInitConfig var config ClientInitConfig
err := db.DB.MysqlDB.DefaultGormDB().Model(&db.ClientInitConfig{}).First(&config).Error err := db.DB.MysqlDB.DefaultGormDB().Model(&ClientInitConfig{}).First(&config).Error
return config, err return config, err
} }

@ -6,12 +6,12 @@ import (
"Open_IM/pkg/utils" "Open_IM/pkg/utils"
) )
func SetConversation(conversation db.Conversation) (bool, error) { func SetConversation(conversation Conversation) (bool, error) {
var isUpdate bool var isUpdate bool
newConversation := conversation 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") 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 // if exist, then update record
} else { } else {
log.NewDebug("", utils.GetSelfFuncName(), "conversation", conversation, "exist in db, update") 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 "group_at_type": conversation.GroupAtType, "is_not_in_group": conversation.IsNotInGroup}).Error
} }
} }
func SetOneConversation(conversation db.Conversation) error { func SetOneConversation(conversation Conversation) error {
return db.DB.MysqlDB.DefaultGormDB().Model(&db.Conversation{}).Create(&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 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") 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 // if exist, then update record
} }
log.NewDebug("", utils.GetSelfFuncName(), "conversation", conversation, "exist in db, update") 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 var isUpdate bool
newConversation := conversation 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") 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 // if exist, then update record
} else { } else {
log.NewDebug("", utils.GetSelfFuncName(), "conversation", conversation, "exist in db, update") 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) { func GetUserAllConversations(ownerUserID string) ([]Conversation, error) {
var conversations []db.Conversation var conversations []Conversation
err := db.DB.MysqlDB.DefaultGormDB().Model(&db.Conversation{}).Where("owner_user_id=?", ownerUserID).Find(&conversations).Error err := db.DB.MysqlDB.DefaultGormDB().Model(&Conversation{}).Where("owner_user_id=?", ownerUserID).Find(&conversations).Error
return conversations, err return conversations, err
} }
func GetMultipleUserConversationByConversationID(ownerUserIDList []string, conversationID string) ([]db.Conversation, error) { func GetMultipleUserConversationByConversationID(ownerUserIDList []string, conversationID string) ([]Conversation, error) {
var conversations []db.Conversation var conversations []Conversation
err := db.DB.MysqlDB.DefaultGormDB().Model(&db.Conversation{}).Where("owner_user_id IN ? and conversation_id=?", ownerUserIDList, conversationID).Find(&conversations).Error err := db.DB.MysqlDB.DefaultGormDB().Model(&Conversation{}).Where("owner_user_id IN ? and conversation_id=?", ownerUserIDList, conversationID).Find(&conversations).Error
return conversations, err return conversations, err
} }
func GetExistConversationUserIDList(ownerUserIDList []string, conversationID string) ([]string, error) { func GetExistConversationUserIDList(ownerUserIDList []string, conversationID string) ([]string, error) {
@ -76,31 +76,31 @@ func GetExistConversationUserIDList(ownerUserIDList []string, conversationID str
return resultArr, nil return resultArr, nil
} }
func GetConversation(OwnerUserID, conversationID string) (db.Conversation, error) { func GetConversation(OwnerUserID, conversationID string) (Conversation, error) {
var conversation db.Conversation var conversation Conversation
err := db.DB.MysqlDB.DefaultGormDB().Table("conversations").Where("owner_user_id=? and conversation_id=?", OwnerUserID, conversationID).Take(&conversation).Error err := db.DB.MysqlDB.DefaultGormDB().Table("conversations").Where("owner_user_id=? and conversation_id=?", OwnerUserID, conversationID).Take(&conversation).Error
return conversation, err return conversation, err
} }
func GetConversations(OwnerUserID string, conversationIDs []string) ([]db.Conversation, error) { func GetConversations(OwnerUserID string, conversationIDs []string) ([]Conversation, error) {
var conversations []db.Conversation var conversations []Conversation
err := db.DB.MysqlDB.DefaultGormDB().Model(&db.Conversation{}).Where("conversation_id IN (?) and owner_user_id=?", conversationIDs, OwnerUserID).Find(&conversations).Error err := db.DB.MysqlDB.DefaultGormDB().Model(&Conversation{}).Where("conversation_id IN (?) and owner_user_id=?", conversationIDs, OwnerUserID).Find(&conversations).Error
return conversations, err return conversations, err
} }
func GetConversationsByConversationIDMultipleOwner(OwnerUserIDList []string, conversationID string) ([]db.Conversation, error) { func GetConversationsByConversationIDMultipleOwner(OwnerUserIDList []string, conversationID string) ([]Conversation, error) {
var conversations []db.Conversation var conversations []Conversation
err := db.DB.MysqlDB.DefaultGormDB().Model(&db.Conversation{}).Where("owner_user_id IN (?) and conversation_id=?", OwnerUserIDList, conversationID).Find(&conversations).Error err := db.DB.MysqlDB.DefaultGormDB().Model(&Conversation{}).Where("owner_user_id IN (?) and conversation_id=?", OwnerUserIDList, conversationID).Find(&conversations).Error
return conversations, err return conversations, err
} }
func UpdateColumnsConversations(ownerUserIDList []string, conversationID string, args map[string]interface{}) error { 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) { func GetConversationIDListByUserID(userID string) ([]string, error) {
var IDList []string 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 return IDList, err
} }

@ -7,19 +7,19 @@ import (
_ "gorm.io/gorm" _ "gorm.io/gorm"
) )
func GetRegister(account, areaCode, userID string) (*db.Register, error) { func GetRegister(account, areaCode, userID string) (*Register, error) {
var r db.Register var r Register
return &r, db.DB.MysqlDB.DefaultGormDB().Table("registers").Where("user_id = ? and user_id != ? or account = ? or account =? and area_code=?", 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 userID, "", account, account, areaCode).Take(&r).Error
} }
func GetRegisterInfo(userID string) (*db.Register, error) { func GetRegisterInfo(userID string) (*Register, error) {
var r db.Register var r Register
return &r, db.DB.MysqlDB.DefaultGormDB().Table("registers").Where("user_id = ?", userID).Take(&r).Error 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 { func SetPassword(account, password, ex, userID, areaCode, ip string) error {
r := db.Register{ r := Register{
Account: account, Account: account,
Password: password, Password: password,
Ex: ex, Ex: ex,
@ -31,7 +31,7 @@ func SetPassword(account, password, ex, userID, areaCode, ip string) error {
} }
func ResetPassword(account, password string) error { func ResetPassword(account, password string) error {
r := db.Register{ r := Register{
Password: password, Password: password,
} }
return db.DB.MysqlDB.DefaultGormDB().Table("registers").Where("account = ?", account).Updates(&r).Error 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) { func GetRegisterAddFriendList(showNumber, pageNumber int32) ([]string, error) {
var IDList []string var IDList []string
var err error var err error
model := db.DB.MysqlDB.DefaultGormDB().Model(&db.RegisterAddFriend{}) model := db.DB.MysqlDB.DefaultGormDB().Model(&RegisterAddFriend{})
if showNumber == 0 { if showNumber == 0 {
err = model.Pluck("user_id", &IDList).Error err = model.Pluck("user_id", &IDList).Error
} else { } else {
@ -50,9 +50,9 @@ func GetRegisterAddFriendList(showNumber, pageNumber int32) ([]string, error) {
} }
func AddUserRegisterAddFriendIDList(userIDList ...string) error { func AddUserRegisterAddFriendIDList(userIDList ...string) error {
var list []db.RegisterAddFriend var list []RegisterAddFriend
for _, v := range userIDList { for _, v := range userIDList {
list = append(list, db.RegisterAddFriend{UserID: v}) list = append(list, RegisterAddFriend{UserID: v})
} }
result := db.DB.MysqlDB.DefaultGormDB().Create(list) result := db.DB.MysqlDB.DefaultGormDB().Create(list)
if int(result.RowsAffected) < len(userIDList) { if int(result.RowsAffected) < len(userIDList) {
@ -63,22 +63,22 @@ func AddUserRegisterAddFriendIDList(userIDList ...string) error {
} }
func ReduceUserRegisterAddFriendIDList(userIDList ...string) error { func ReduceUserRegisterAddFriendIDList(userIDList ...string) error {
var list []db.RegisterAddFriend var list []RegisterAddFriend
for _, v := range userIDList { 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 err := db.DB.MysqlDB.DefaultGormDB().Delete(list).Error
return err return err
} }
func DeleteAllRegisterAddFriendIDList() error { 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 return err
} }
func GetUserIPLimit(userID string) (db.UserIpLimit, error) { func GetUserIPLimit(userID string) (UserIpLimit, error) {
var limit db.UserIpLimit var limit UserIpLimit
limit.UserID = userID 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 return limit, err
} }

@ -7,7 +7,7 @@ import (
func UpdateAppVersion(appType int, version string, forceUpdate bool, fileName, yamlName, updateLog string) error { func UpdateAppVersion(appType int, version string, forceUpdate bool, fileName, yamlName, updateLog string) error {
updateTime := int(time.Now().Unix()) updateTime := int(time.Now().Unix())
app := db.AppVersion{ app := AppVersion{
Version: version, Version: version,
Type: appType, Type: appType,
UpdateTime: updateTime, UpdateTime: updateTime,
@ -16,7 +16,7 @@ func UpdateAppVersion(appType int, version string, forceUpdate bool, fileName, y
ForceUpdate: forceUpdate, ForceUpdate: forceUpdate,
UpdateLog: updateLog, 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}) "version": version, "update_time": int(time.Now().Unix()), "file_name": fileName, "yaml_name": yamlName, "type": appType, "update_log": updateLog})
if result.Error != nil { if result.Error != nil {
return result.Error return result.Error
@ -28,7 +28,7 @@ func UpdateAppVersion(appType int, version string, forceUpdate bool, fileName, y
return nil return nil
} }
func GetNewestVersion(appType int) (*db.AppVersion, error) { func GetNewestVersion(appType int) (*AppVersion, error) {
app := db.AppVersion{} app := AppVersion{}
return &app, db.DB.MysqlDB.DefaultGormDB().Model(db.AppVersion{}).First(&app, appType).Error return &app, db.DB.MysqlDB.DefaultGormDB().Model(AppVersion{}).First(&app, appType).Error
} }

@ -6,7 +6,7 @@ import (
"time" "time"
) )
func InsertToFriend(toInsertFollow *db.Friend) error { func InsertToFriend(toInsertFollow *Friend) error {
toInsertFollow.CreateTime = time.Now() toInsertFollow.CreateTime = time.Now()
err := db.DB.MysqlDB.DefaultGormDB().Table("friends").Create(toInsertFollow).Error err := db.DB.MysqlDB.DefaultGormDB().Table("friends").Create(toInsertFollow).Error
if err != nil { if err != nil {
@ -15,8 +15,8 @@ func InsertToFriend(toInsertFollow *db.Friend) error {
return nil return nil
} }
func GetFriendRelationshipFromFriend(OwnerUserID, FriendUserID string) (*db.Friend, error) { func GetFriendRelationshipFromFriend(OwnerUserID, FriendUserID string) (*Friend, error) {
var friend db.Friend var friend Friend
err := db.DB.MysqlDB.DefaultGormDB().Table("friends").Where("owner_user_id=? and friend_user_id=?", OwnerUserID, FriendUserID).Take(&friend).Error err := db.DB.MysqlDB.DefaultGormDB().Table("friends").Where("owner_user_id=? and friend_user_id=?", OwnerUserID, FriendUserID).Take(&friend).Error
if err != nil { if err != nil {
return nil, err return nil, err
@ -24,9 +24,9 @@ func GetFriendRelationshipFromFriend(OwnerUserID, FriendUserID string) (*db.Frie
return &friend, err return &friend, err
} }
func GetFriendListByUserID(OwnerUserID string) ([]db.Friend, error) { func GetFriendListByUserID(OwnerUserID string) ([]Friend, error) {
var friends []db.Friend var friends []Friend
var x db.Friend var x Friend
x.OwnerUserID = OwnerUserID x.OwnerUserID = OwnerUserID
err := db.DB.MysqlDB.DefaultGormDB().Table("friends").Where("owner_user_id=?", OwnerUserID).Find(&friends).Error err := db.DB.MysqlDB.DefaultGormDB().Table("friends").Where("owner_user_id=?", OwnerUserID).Find(&friends).Error
if err != nil { if err != nil {
@ -49,11 +49,11 @@ func UpdateFriendComment(OwnerUserID, FriendUserID, Remark string) error {
} }
func DeleteSingleFriendInfo(OwnerUserID, FriendUserID 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 { type FriendUser struct {
db.Friend Friend
Nickname string `gorm:"column:name;size:255"` Nickname string `gorm:"column:name;size:255"`
} }

@ -19,8 +19,8 @@ import (
//} //}
// who apply to add me // who apply to add me
func GetReceivedFriendsApplicationListByUserID(ToUserID string) ([]db.FriendRequest, error) { func GetReceivedFriendsApplicationListByUserID(ToUserID string) ([]FriendRequest, error) {
var usersInfo []db.FriendRequest var usersInfo []FriendRequest
err := db.DB.MysqlDB.DefaultGormDB().Table("friend_requests").Where("to_user_id=?", ToUserID).Find(&usersInfo).Error err := db.DB.MysqlDB.DefaultGormDB().Table("friend_requests").Where("to_user_id=?", ToUserID).Find(&usersInfo).Error
if err != nil { if err != nil {
return nil, err return nil, err
@ -29,8 +29,8 @@ func GetReceivedFriendsApplicationListByUserID(ToUserID string) ([]db.FriendRequ
} }
// I apply to add somebody // I apply to add somebody
func GetSendFriendApplicationListByUserID(FromUserID string) ([]db.FriendRequest, error) { func GetSendFriendApplicationListByUserID(FromUserID string) ([]FriendRequest, error) {
var usersInfo []db.FriendRequest var usersInfo []FriendRequest
err := db.DB.MysqlDB.DefaultGormDB().Table("friend_requests").Where("from_user_id=?", FromUserID).Find(&usersInfo).Error err := db.DB.MysqlDB.DefaultGormDB().Table("friend_requests").Where("from_user_id=?", FromUserID).Find(&usersInfo).Error
if err != nil { if err != nil {
return nil, err return nil, err
@ -39,8 +39,8 @@ func GetSendFriendApplicationListByUserID(FromUserID string) ([]db.FriendRequest
} }
// FromUserId apply to add ToUserID // FromUserId apply to add ToUserID
func GetFriendApplicationByBothUserID(FromUserID, ToUserID string) (*db.FriendRequest, error) { func GetFriendApplicationByBothUserID(FromUserID, ToUserID string) (*FriendRequest, error) {
var friendRequest db.FriendRequest var friendRequest FriendRequest
err := db.DB.MysqlDB.DefaultGormDB().Table("friend_requests").Where("from_user_id=? and to_user_id=?", FromUserID, ToUserID).Take(&friendRequest).Error err := db.DB.MysqlDB.DefaultGormDB().Table("friend_requests").Where("from_user_id=? and to_user_id=?", FromUserID, ToUserID).Take(&friendRequest).Error
if err != nil { if err != nil {
return nil, err return nil, err
@ -48,13 +48,13 @@ func GetFriendApplicationByBothUserID(FromUserID, ToUserID string) (*db.FriendRe
return &friendRequest, nil return &friendRequest, nil
} }
func UpdateFriendApplication(friendRequest *db.FriendRequest) error { func UpdateFriendApplication(friendRequest *FriendRequest) error {
friendRequest.CreateTime = time.Now() friendRequest.CreateTime = time.Now()
return db.DB.MysqlDB.DefaultGormDB().Table("friend_requests").Where("from_user_id=? and to_user_id=?", return db.DB.MysqlDB.DefaultGormDB().Table("friend_requests").Where("from_user_id=? and to_user_id=?",
friendRequest.FromUserID, friendRequest.ToUserID).Updates(&friendRequest).Error 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 { if err := db.DB.MysqlDB.DefaultGormDB().Table("friend_requests").Create(friendRequest).Error; err == nil {
return nil return nil
} }

@ -20,7 +20,7 @@ import (
// Ex string `gorm:"column:ex"` // Ex string `gorm:"column:ex"`
//} //}
func InsertIntoGroupMember(toInsertInfo db.GroupMember) error { func InsertIntoGroupMember(toInsertInfo GroupMember) error {
toInsertInfo.JoinTime = time.Now() toInsertInfo.JoinTime = time.Now()
if toInsertInfo.RoleLevel == 0 { if toInsertInfo.RoleLevel == 0 {
toInsertInfo.RoleLevel = constant.GroupOrdinaryUsers toInsertInfo.RoleLevel = constant.GroupOrdinaryUsers
@ -33,7 +33,7 @@ func InsertIntoGroupMember(toInsertInfo db.GroupMember) error {
return nil return nil
} }
func BatchInsertIntoGroupMember(toInsertInfoList []*db.GroupMember) error { func BatchInsertIntoGroupMember(toInsertInfoList []*GroupMember) error {
for _, toInsertInfo := range toInsertInfoList { for _, toInsertInfo := range toInsertInfoList {
toInsertInfo.JoinTime = time.Now() toInsertInfo.JoinTime = time.Now()
if toInsertInfo.RoleLevel == 0 { if toInsertInfo.RoleLevel == 0 {
@ -45,8 +45,8 @@ func BatchInsertIntoGroupMember(toInsertInfoList []*db.GroupMember) error {
} }
func GetGroupMemberListByUserID(userID string) ([]db.GroupMember, error) { func GetGroupMemberListByUserID(userID string) ([]GroupMember, error) {
var groupMemberList []db.GroupMember var groupMemberList []GroupMember
err := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("user_id=?", userID).Find(&groupMemberList).Error err := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("user_id=?", userID).Find(&groupMemberList).Error
if err != nil { if err != nil {
return nil, err return nil, err
@ -54,8 +54,8 @@ func GetGroupMemberListByUserID(userID string) ([]db.GroupMember, error) {
return groupMemberList, nil return groupMemberList, nil
} }
func GetGroupMemberListByGroupID(groupID string) ([]db.GroupMember, error) { func GetGroupMemberListByGroupID(groupID string) ([]GroupMember, error) {
var groupMemberList []db.GroupMember var groupMemberList []GroupMember
err := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=?", groupID).Find(&groupMemberList).Error err := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=?", groupID).Find(&groupMemberList).Error
if err != nil { if err != nil {
return nil, err return nil, err
@ -72,8 +72,8 @@ func GetGroupMemberIDListByGroupID(groupID string) ([]string, error) {
return groupMemberIDList, nil return groupMemberIDList, nil
} }
func GetGroupMemberListByGroupIDAndRoleLevel(groupID string, roleLevel int32) ([]db.GroupMember, error) { func GetGroupMemberListByGroupIDAndRoleLevel(groupID string, roleLevel int32) ([]GroupMember, error) {
var groupMemberList []db.GroupMember var groupMemberList []GroupMember
err := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=? and role_level=?", groupID, roleLevel).Find(&groupMemberList).Error err := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=? and role_level=?", groupID, roleLevel).Find(&groupMemberList).Error
if err != nil { if err != nil {
return nil, err return nil, err
@ -81,8 +81,8 @@ func GetGroupMemberListByGroupIDAndRoleLevel(groupID string, roleLevel int32) ([
return groupMemberList, nil return groupMemberList, nil
} }
func GetGroupMemberInfoByGroupIDAndUserID(groupID, userID string) (*db.GroupMember, error) { func GetGroupMemberInfoByGroupIDAndUserID(groupID, userID string) (*GroupMember, error) {
var groupMember db.GroupMember var groupMember GroupMember
err := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=? and user_id=? ", groupID, userID).Limit(1).Take(&groupMember).Error err := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=? and user_id=? ", groupID, userID).Limit(1).Take(&groupMember).Error
if err != nil { if err != nil {
return nil, err return nil, err
@ -91,23 +91,23 @@ func GetGroupMemberInfoByGroupIDAndUserID(groupID, userID string) (*db.GroupMemb
} }
func DeleteGroupMemberByGroupIDAndUserID(groupID, userID string) error { 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 { 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 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 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) { func GetOwnerManagerByGroupID(groupID string) ([]GroupMember, error) {
var groupMemberList []db.GroupMember var groupMemberList []GroupMember
err := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=? and role_level>?", groupID, constant.GroupOrdinaryUsers).Find(&groupMemberList).Error err := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=? and role_level>?", groupID, constant.GroupOrdinaryUsers).Find(&groupMemberList).Error
if err != nil { if err != nil {
return nil, err return nil, err
@ -124,7 +124,7 @@ func GetGroupMemberNumByGroupID(groupID string) (int64, error) {
return number, nil return number, nil
} }
func GetGroupOwnerInfoByGroupID(groupID string) (*db.GroupMember, error) { func GetGroupOwnerInfoByGroupID(groupID string) (*GroupMember, error) {
omList, err := GetOwnerManagerByGroupID(groupID) omList, err := GetOwnerManagerByGroupID(groupID)
if err != nil { if err != nil {
return nil, err return nil, err
@ -149,8 +149,8 @@ func IsExistGroupMember(groupID, userID string) bool {
return true return true
} }
func GetGroupMemberByGroupID(groupID string, filter int32, begin int32, maxNumber int32) ([]db.GroupMember, error) { func GetGroupMemberByGroupID(groupID string, filter int32, begin int32, maxNumber int32) ([]GroupMember, error) {
var memberList []db.GroupMember var memberList []GroupMember
var err error var err error
if filter >= 0 { if filter >= 0 {
memberList, err = GetGroupMemberListByGroupIDAndRoleLevel(groupID, filter) //sorted by join time memberList, err = GetGroupMemberListByGroupIDAndRoleLevel(groupID, filter) //sorted by join time
@ -199,8 +199,8 @@ func IsGroupOwnerAdmin(groupID, UserID string) bool {
return false return false
} }
func GetGroupMembersByGroupIdCMS(groupId string, userName string, showNumber, pageNumber int32) ([]db.GroupMember, error) { func GetGroupMembersByGroupIdCMS(groupId string, userName string, showNumber, pageNumber int32) ([]GroupMember, error) {
var groupMembers []db.GroupMember 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 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 { if err != nil {
return nil, err return nil, err
@ -216,7 +216,7 @@ func GetGroupMembersCount(groupID, userName string) (int64, error) {
return count, nil 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 return db.DB.MysqlDB.DefaultGormDB().Model(groupMemberInfo).Updates(args).Error
} }

@ -22,7 +22,7 @@ import (
// Ex string `gorm:"column:ex"` // Ex string `gorm:"column:ex"`
//} //}
func InsertIntoGroup(groupInfo db.Group) error { func InsertIntoGroup(groupInfo Group) error {
if groupInfo.GroupName == "" { if groupInfo.GroupName == "" {
groupInfo.GroupName = "Group Chat" groupInfo.GroupName = "Group Chat"
} }
@ -38,24 +38,24 @@ func InsertIntoGroup(groupInfo db.Group) error {
return nil return nil
} }
func TakeGroupInfoByGroupID(groupID string) (*db.Group, error) { func TakeGroupInfoByGroupID(groupID string) (*Group, error) {
var groupInfo db.Group var groupInfo Group
err := db.DB.MysqlDB.DefaultGormDB().Table("groups").Where("group_id=?", groupID).Take(&groupInfo).Error err := db.DB.MysqlDB.DefaultGormDB().Table("groups").Where("group_id=?", groupID).Take(&groupInfo).Error
return &groupInfo, err return &groupInfo, err
} }
func GetGroupInfoByGroupID(groupID string) (*db.Group, error) { func GetGroupInfoByGroupID(groupID string) (*Group, error) {
var groupInfo db.Group var groupInfo Group
err := db.DB.MysqlDB.DefaultGormDB().Table("groups").Where("group_id=?", groupID).Take(&groupInfo).Error err := db.DB.MysqlDB.DefaultGormDB().Table("groups").Where("group_id=?", groupID).Take(&groupInfo).Error
return &groupInfo, err 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 return db.DB.MysqlDB.DefaultGormDB().Table("groups").Where("group_id=?", groupInfo.GroupID).Updates(&groupInfo).Error
} }
type GroupWithNum struct { type GroupWithNum struct {
db.Group Group
MemberCount int `gorm:"column:num"` MemberCount int `gorm:"column:num"`
} }
@ -81,7 +81,7 @@ func GetGroups(pageNumber, showNumber int) ([]GroupWithNum, error) {
} }
func OperateGroupStatus(groupId string, groupStatus int32) error { func OperateGroupStatus(groupId string, groupStatus int32) error {
group := db.Group{ group := Group{
GroupID: groupId, GroupID: groupId,
Status: groupStatus, Status: groupStatus,
} }
@ -91,7 +91,7 @@ func OperateGroupStatus(groupId string, groupStatus int32) error {
return nil return nil
} }
func GetGroupsCountNum(group db.Group) (int32, error) { func GetGroupsCountNum(group Group) (int32, error) {
var count int64 var count int64
if err := db.DB.MysqlDB.DefaultGormDB().Table("groups").Where(" name like ? ", fmt.Sprintf("%%%s%%", group.GroupName)).Count(&count).Error; err != nil { if err := db.DB.MysqlDB.DefaultGormDB().Table("groups").Where(" name like ? ", fmt.Sprintf("%%%s%%", group.GroupName)).Count(&count).Error; err != nil {
return 0, err return 0, err

@ -19,14 +19,14 @@ import (
// Ex string `gorm:"column:ex"` // Ex string `gorm:"column:ex"`
//} //}
func UpdateGroupRequest(groupRequest db.GroupRequest) error { func UpdateGroupRequest(groupRequest GroupRequest) error {
if groupRequest.HandledTime.Unix() < 0 { if groupRequest.HandledTime.Unix() < 0 {
groupRequest.HandledTime = utils.UnixSecondToTime(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 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) DelGroupRequestByGroupIDAndUserID(toInsertInfo.GroupID, toInsertInfo.UserID)
if toInsertInfo.HandledTime.Unix() < 0 { if toInsertInfo.HandledTime.Unix() < 0 {
toInsertInfo.HandledTime = utils.UnixSecondToTime(0) toInsertInfo.HandledTime = utils.UnixSecondToTime(0)
@ -48,8 +48,8 @@ func InsertIntoGroupRequest(toInsertInfo db.GroupRequest) error {
return nil return nil
} }
func GetGroupRequestByGroupIDAndUserID(groupID, userID string) (*db.GroupRequest, error) { func GetGroupRequestByGroupIDAndUserID(groupID, userID string) (*GroupRequest, error) {
var groupRequest db.GroupRequest var groupRequest GroupRequest
err := db.DB.MysqlDB.DefaultGormDB().Table("group_requests").Where("user_id=? and group_id=?", userID, groupID).Take(&groupRequest).Error err := db.DB.MysqlDB.DefaultGormDB().Table("group_requests").Where("user_id=? and group_id=?", userID, groupID).Take(&groupRequest).Error
if err != nil { if err != nil {
return nil, err return nil, err
@ -58,11 +58,11 @@ func GetGroupRequestByGroupIDAndUserID(groupID, userID string) (*db.GroupRequest
} }
func DelGroupRequestByGroupIDAndUserID(groupID, userID string) error { 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) { func GetGroupRequestByGroupID(groupID string) ([]GroupRequest, error) {
var groupRequestList []db.GroupRequest var groupRequestList []GroupRequest
err := db.DB.MysqlDB.DefaultGormDB().Table("group_requests").Where("group_id=?", groupID).Find(&groupRequestList).Error err := db.DB.MysqlDB.DefaultGormDB().Table("group_requests").Where("group_id=?", groupID).Find(&groupRequestList).Error
if err != nil { if err != nil {
return nil, err return nil, err
@ -71,8 +71,8 @@ func GetGroupRequestByGroupID(groupID string) ([]db.GroupRequest, error) {
} }
// received // received
func GetRecvGroupApplicationList(userID string) ([]db.GroupRequest, error) { func GetRecvGroupApplicationList(userID string) ([]GroupRequest, error) {
var groupRequestList []db.GroupRequest var groupRequestList []GroupRequest
memberList, err := GetGroupMemberListByUserID(userID) memberList, err := GetGroupMemberListByUserID(userID)
if err != nil { if err != nil {
return nil, utils.Wrap(err, utils.GetSelfFuncName()) return nil, utils.Wrap(err, utils.GetSelfFuncName())
@ -89,8 +89,8 @@ func GetRecvGroupApplicationList(userID string) ([]db.GroupRequest, error) {
return groupRequestList, nil return groupRequestList, nil
} }
func GetUserReqGroupByUserID(userID string) ([]db.GroupRequest, error) { func GetUserReqGroupByUserID(userID string) ([]GroupRequest, error) {
var groupRequestList []db.GroupRequest var groupRequestList []GroupRequest
err := db.DB.MysqlDB.DefaultGormDB().Table("group_requests").Where("user_id=?", userID).Find(&groupRequestList).Error err := db.DB.MysqlDB.DefaultGormDB().Table("group_requests").Where("user_id=?", userID).Find(&groupRequestList).Error
return groupRequestList, err return groupRequestList, err
} }

@ -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) {
}

@ -18,7 +18,7 @@ func BatchCreateInvitationCodes(CodeNums int, CodeLen int) ([]string, error) {
break break
} }
code := CreateRandomString(CodeLen) code := CreateRandomString(CodeLen)
invitation := new(db.Invitation) invitation := new(Invitation)
invitation.CreateTime = time.Now() invitation.CreateTime = time.Now()
invitation.InvitationCode = code invitation.InvitationCode = code
invitation.LastTime = time.Now() invitation.LastTime = time.Now()
@ -40,7 +40,7 @@ func BatchCreateInvitationCodes(CodeNums int, CodeLen int) ([]string, error) {
* *
*/ */
func CheckInvitationCode(code 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 err := db.DB.MysqlDB.DefaultGormDB().Table("invitations").Where("invitation_code=?", code).Take(&invitationCode).Error
if err != nil { if err != nil {
return err return err
@ -82,8 +82,8 @@ func FinishInvitationCode(Code string, UserId string) bool {
return result.RowsAffected > 0 return result.RowsAffected > 0
} }
func GetInvitationCode(code string) (*db.Invitation, error) { func GetInvitationCode(code string) (*Invitation, error) {
invitation := &db.Invitation{ invitation := &Invitation{
InvitationCode: code, InvitationCode: code,
} }
err := db.DB.MysqlDB.DefaultGormDB().Model(invitation).Find(invitation).Error err := db.DB.MysqlDB.DefaultGormDB().Model(invitation).Find(invitation).Error
@ -101,9 +101,9 @@ func CreateRandomString(strlen int) string {
return string(result) return string(result)
} }
func GetInvitationCodes(showNumber, pageNumber, status int32) ([]db.Invitation, int64, error) { func GetInvitationCodes(showNumber, pageNumber, status int32) ([]Invitation, int64, error) {
var invitationList []db.Invitation var invitationList []Invitation
db := db.DB.MysqlDB.DefaultGormDB().Model(db.Invitation{}).Where("status=?", status) db := db.DB.MysqlDB.DefaultGormDB().Model(Invitation{}).Where("status=?", status)
var count int64 var count int64
err := db.Count(&count).Error err := db.Count(&count).Error
err = db.Limit(int(showNumber)).Offset(int(showNumber * (pageNumber - 1))). err = db.Limit(int(showNumber)).Offset(int(showNumber * (pageNumber - 1))).

@ -44,58 +44,58 @@ func IsLimitUserLoginIp(userID string, loginIp string) (limit bool, err error) {
return count > 0, nil return count > 0, nil
} }
func QueryIPLimits(ip string) (*db.IpLimit, error) { func QueryIPLimits(ip string) (*IpLimit, error) {
var ipLimit db.IpLimit var ipLimit IpLimit
err := db.DB.MysqlDB.DefaultGormDB().Model(&db.IpLimit{}).Where("ip=?", ip).First(&ipLimit).Error err := db.DB.MysqlDB.DefaultGormDB().Model(&IpLimit{}).Where("ip=?", ip).First(&ipLimit).Error
return &ipLimit, err return &ipLimit, err
} }
func QueryUserIPLimits(ip string) ([]db.UserIpLimit, error) { func QueryUserIPLimits(ip string) ([]UserIpLimit, error) {
var ips []db.UserIpLimit var ips []UserIpLimit
err := db.DB.MysqlDB.DefaultGormDB().Model(&db.UserIpLimit{}).Where("ip=?", ip).Find(&ips).Error err := db.DB.MysqlDB.DefaultGormDB().Model(&UserIpLimit{}).Where("ip=?", ip).Find(&ips).Error
return ips, err return ips, err
} }
func InsertOneIntoIpLimits(ipLimits db.IpLimit) error { func InsertOneIntoIpLimits(ipLimits IpLimit) error {
return db.DB.MysqlDB.DefaultGormDB().Model(&db.IpLimit{}).Create(ipLimits).Error return db.DB.MysqlDB.DefaultGormDB().Model(&IpLimit{}).Create(ipLimits).Error
} }
func DeleteOneFromIpLimits(ip string) 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 return db.DB.MysqlDB.DefaultGormDB().Model(ipLimits).Where("ip=?", ip).Delete(ipLimits).Error
} }
func GetIpLimitsLoginByUserID(userID string) ([]db.UserIpLimit, error) { func GetIpLimitsLoginByUserID(userID string) ([]UserIpLimit, error) {
var ips []db.UserIpLimit var ips []UserIpLimit
err := db.DB.MysqlDB.DefaultGormDB().Model(&db.UserIpLimit{}).Where("user_id=?", userID).Find(&ips).Error err := db.DB.MysqlDB.DefaultGormDB().Model(&UserIpLimit{}).Where("user_id=?", userID).Find(&ips).Error
return ips, err return ips, err
} }
func InsertUserIpLimitsLogin(userIp *db.UserIpLimit) error { func InsertUserIpLimitsLogin(userIp *UserIpLimit) error {
userIp.CreateTime = time.Now() 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 { func DeleteUserIpLimitsLogin(userID, ip string) error {
userIp := db.UserIpLimit{UserID: userID, Ip: ip} userIp := UserIpLimit{UserID: userID, Ip: ip}
return db.DB.MysqlDB.DefaultGormDB().Model(&db.UserIpLimit{}).Delete(&userIp).Error return db.DB.MysqlDB.DefaultGormDB().Model(&UserIpLimit{}).Delete(&userIp).Error
} }
func GetRegisterUserNum(ip string) ([]string, error) { func GetRegisterUserNum(ip string) ([]string, error) {
var userIDList []string 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 return userIDList, err
} }
func InsertIpRecord(userID, createIp string) error { func InsertIpRecord(userID, createIp string) error {
record := &db.UserIpRecord{UserID: userID, CreateIp: createIp, LastLoginTime: time.Now(), LoginTimes: 1} record := &UserIpRecord{UserID: userID, CreateIp: createIp, LastLoginTime: time.Now(), LoginTimes: 1}
err := db.DB.MysqlDB.DefaultGormDB().Model(&db.UserIpRecord{}).Create(record).Error err := db.DB.MysqlDB.DefaultGormDB().Model(&UserIpRecord{}).Create(record).Error
return err return err
} }
func UpdateIpReocord(userID, ip string) (err error) { func UpdateIpReocord(userID, ip string) (err error) {
record := &db.UserIpRecord{UserID: userID, LastLoginIp: ip, LastLoginTime: time.Now()} record := &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)) 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 { if result.Error != nil {
return utils.Wrap(result.Error, "") return utils.Wrap(result.Error, "")
} }

@ -6,7 +6,7 @@ import (
"fmt" "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") mdb := db.DB.MysqlDB.DefaultGormDB().Table("chat_logs")
if chatLog.SendTime.Unix() > 0 { if chatLog.SendTime.Unix() > 0 {
mdb = mdb.Where("send_time > ? and send_time < ?", chatLog.SendTime, chatLog.SendTime.AddDate(0, 0, 1)) 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 { if err := mdb.Count(&count).Error; err != nil {
return 0, nil, err return 0, nil, err
} }
var chatLogs []db.ChatLog var chatLogs []ChatLog
mdb = mdb.Limit(int(showNumber)).Offset(int(showNumber * (pageNumber - 1))) mdb = mdb.Limit(int(showNumber)).Offset(int(showNumber * (pageNumber - 1)))
if err := mdb.Find(&chatLogs).Error; err != nil { if err := mdb.Find(&chatLogs).Error; err != nil {
return 0, nil, err return 0, nil, err

@ -1,6 +1,9 @@
package db package im_mysql_model
import "time" import (
"gorm.io/gorm"
"time"
)
type Register struct { type Register struct {
Account string `gorm:"column:account;primary_key;type:char(255)" json:"account"` Account string `gorm:"column:account;primary_key;type:char(255)" json:"account"`
@ -20,7 +23,6 @@ type Invitation struct {
Status int32 `gorm:"column:status"` Status int32 `gorm:"column:status"`
} }
//
// message FriendInfo{ // message FriendInfo{
// string OwnerUserID = 1; // string OwnerUserID = 1;
// string Remark = 2; // string Remark = 2;
@ -83,6 +85,7 @@ func (FriendRequest) TableName() string {
// string CreatorUserID = 11; // string CreatorUserID = 11;
// int32 GroupType = 12; // int32 GroupType = 12;
// } // }
//
// open_im_sdk.GroupInfo (OwnerUserID , MemberCount )> imdb.Group // open_im_sdk.GroupInfo (OwnerUserID , MemberCount )> imdb.Group
type Group struct { type Group struct {
//`json:"operationID" binding:"required"` //`json:"operationID" binding:"required"`
@ -102,6 +105,7 @@ type Group struct {
ApplyMemberFriend int32 `gorm:"column:apply_member_friend" json:"applyMemberFriend"` ApplyMemberFriend int32 `gorm:"column:apply_member_friend" json:"applyMemberFriend"`
NotificationUpdateTime time.Time `gorm:"column:notification_update_time"` NotificationUpdateTime time.Time `gorm:"column:notification_update_time"`
NotificationUserID string `gorm:"column:notification_user_id;size:64"` NotificationUserID string `gorm:"column:notification_user_id;size:64"`
DB *gorm.DB `gorm:"-" json:"-"`
} }
// message GroupMemberFullInfo { // message GroupMemberFullInfo {

@ -7,18 +7,18 @@ import (
"time" "time"
) )
func CreateDepartment(department *db.Department) error { func CreateDepartment(department *Department) error {
department.CreateTime = time.Now() department.CreateTime = time.Now()
return db.DB.MysqlDB.DefaultGormDB().Table("departments").Create(department).Error return db.DB.MysqlDB.DefaultGormDB().Table("departments").Create(department).Error
} }
func GetDepartment(departmentID string) (*db.Department, error) { func GetDepartment(departmentID string) (*Department, error) {
var department db.Department var department Department
err := db.DB.MysqlDB.DefaultGormDB().Table("departments").Where("department_id=?", departmentID).Find(&department).Error err := db.DB.MysqlDB.DefaultGormDB().Table("departments").Where("department_id=?", departmentID).Find(&department).Error
return &department, err 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 { if err := db.DB.MysqlDB.DefaultGormDB().Table("departments").Where("department_id=?", department.DepartmentID).Updates(department).Error; err != nil {
return err return err
} }
@ -28,8 +28,8 @@ func UpdateDepartment(department *db.Department, args map[string]interface{}) er
return nil return nil
} }
func GetSubDepartmentList(departmentID string) ([]db.Department, error) { func GetSubDepartmentList(departmentID string) ([]Department, error) {
var departmentList []db.Department var departmentList []Department
var err error var err error
if departmentID == "-1" { if departmentID == "-1" {
err = db.DB.MysqlDB.DefaultGormDB().Table("departments").Find(&departmentList).Error 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 { func DeleteDepartment(departmentID string) error {
var err 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 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 err
} }
return nil return nil
} }
func CreateOrganizationUser(organizationUser *db.OrganizationUser) error { func CreateOrganizationUser(organizationUser *OrganizationUser) error {
organizationUser.CreateTime = time.Now() organizationUser.CreateTime = time.Now()
return db.DB.MysqlDB.DefaultGormDB().Table("organization_users").Create(organizationUser).Error return db.DB.MysqlDB.DefaultGormDB().Table("organization_users").Create(organizationUser).Error
} }
func GetOrganizationUser(userID string) (error, *db.OrganizationUser) { func GetOrganizationUser(userID string) (error, *OrganizationUser) {
organizationUser := db.OrganizationUser{} organizationUser := OrganizationUser{}
err := db.DB.MysqlDB.DefaultGormDB().Table("organization_users").Where("user_id=?", userID).Take(&organizationUser).Error err := db.DB.MysqlDB.DefaultGormDB().Table("organization_users").Where("user_id=?", userID).Take(&organizationUser).Error
return err, &organizationUser return err, &organizationUser
} }
func GetOrganizationUsers(userIDList []string) ([]*db.OrganizationUser, error) { func GetOrganizationUsers(userIDList []string) ([]*OrganizationUser, error) {
var organizationUserList []*db.OrganizationUser var organizationUserList []*OrganizationUser
err := db.DB.MysqlDB.DefaultGormDB().Table("organization_users").Where("user_id in (?)", userIDList).Find(&organizationUserList).Error err := db.DB.MysqlDB.DefaultGormDB().Table("organization_users").Where("user_id in (?)", userIDList).Find(&organizationUserList).Error
return organizationUserList, err 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 { if err := db.DB.MysqlDB.DefaultGormDB().Table("organization_users").Where("user_id=?", organizationUser.UserID).Updates(organizationUser).Error; err != nil {
return err return err
} }
@ -78,18 +78,18 @@ func UpdateOrganizationUser(organizationUser *db.OrganizationUser, args map[stri
return nil return nil
} }
func CreateDepartmentMember(departmentMember *db.DepartmentMember) error { func CreateDepartmentMember(departmentMember *DepartmentMember) error {
departmentMember.CreateTime = time.Now() departmentMember.CreateTime = time.Now()
return db.DB.MysqlDB.DefaultGormDB().Table("department_members").Create(departmentMember).Error return db.DB.MysqlDB.DefaultGormDB().Table("department_members").Create(departmentMember).Error
} }
func GetUserInDepartment(userID string) (error, []db.DepartmentMember) { func GetUserInDepartment(userID string) (error, []DepartmentMember) {
var departmentMemberList []db.DepartmentMember var departmentMemberList []DepartmentMember
err := db.DB.MysqlDB.DefaultGormDB().Table("department_members").Where("user_id=?", userID).Find(&departmentMemberList).Error err := db.DB.MysqlDB.DefaultGormDB().Table("department_members").Where("user_id=?", userID).Find(&departmentMemberList).Error
return err, departmentMemberList 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). if err := db.DB.MysqlDB.DefaultGormDB().Table("department_members").Where("department_id=? AND user_id=?", departmentMember.DepartmentID, departmentMember.UserID).
Updates(departmentMember).Error; err != nil { Updates(departmentMember).Error; err != nil {
return err return err
@ -102,22 +102,22 @@ func UpdateUserInDepartment(departmentMember *db.DepartmentMember, args map[stri
} }
func DeleteUserInDepartment(departmentID, userID string) error { 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 { 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 { func DeleteOrganizationUser(OrganizationUserID string) error {
if err := DeleteUserInAllDepartment(OrganizationUserID); err != nil { if err := DeleteUserInAllDepartment(OrganizationUserID); err != nil {
return err 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) { 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 err := db.DB.MysqlDB.DefaultGormDB().Table("department_members").Where("department_id=?", departmentID).Take(&departmentMemberList).Error
if err != nil { if err != nil {
return err, nil return err, nil
@ -129,8 +129,8 @@ func GetDepartmentMemberUserIDList(departmentID string) (error, []string) {
return err, userIDList return err, userIDList
} }
func GetDepartmentMemberList(departmentID string) ([]db.DepartmentMember, error) { func GetDepartmentMemberList(departmentID string) ([]DepartmentMember, error) {
var departmentMemberList []db.DepartmentMember var departmentMemberList []DepartmentMember
var err error var err error
if departmentID == "-1" { if departmentID == "-1" {
err = db.DB.MysqlDB.DefaultGormDB().Table("department_members").Find(&departmentMemberList).Error 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) { func GetAllOrganizationUserID() (error, []string) {
var OrganizationUser db.OrganizationUser var OrganizationUser OrganizationUser
var result []string var result []string
return db.DB.MysqlDB.DefaultGormDB().Model(&OrganizationUser).Pluck("user_id", &result).Error, result 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 { 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 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 return groupIDList, err
} }
func getDepartmentParent(departmentID string, dbConn *gorm.DB) (*db.Department, error) { func getDepartmentParent(departmentID string, dbConn *gorm.DB) (*Department, error) {
var department db.Department var department Department
var parentDepartment db.Department var parentDepartment Department
//var parentID string //var parentID string
err := db.DB.MysqlDB.DefaultGormDB().Model(&department).Where("department_id=?", departmentID).Select("parent_id").First(&department).Error err := db.DB.MysqlDB.DefaultGormDB().Model(&department).Where("department_id=?", departmentID).Select("parent_id").First(&department).Error
if err != nil { if err != nil {
@ -217,7 +217,7 @@ func GetDepartmentParentIDList(departmentID string) ([]string, error) {
} }
func GetRandomDepartmentID() (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 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 return department.DepartmentID, err
} }

@ -70,7 +70,7 @@ func GetActiveGroups(from, to time.Time, limit int) ([]*activeGroup, error) {
var activeGroups []*activeGroup 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 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 { for _, activeGroup := range activeGroups {
group := db.Group{ group := Group{
GroupID: activeGroup.Id, GroupID: activeGroup.Id,
} }
db.DB.MysqlDB.DefaultGormDB().Table("groups").Where("group_id= ? ", group.GroupID).Find(&group) 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 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 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 { for _, activeUser := range activeUsers {
user := db.User{ user := User{
UserID: activeUser.ID, UserID: activeUser.ID,
} }
err = db.DB.MysqlDB.DefaultGormDB().Table("users").Select("user_id, name").Find(&user).Error err = db.DB.MysqlDB.DefaultGormDB().Table("users").Select("user_id, name").Find(&user).Error

@ -6,7 +6,7 @@ import (
"time" "time"
) )
func InsertInToUserBlackList(black db.Black) error { func InsertInToUserBlackList(black Black) error {
black.CreateTime = time.Now() black.CreateTime = time.Now()
return db.DB.MysqlDB.DefaultGormDB().Table("blacks").Create(black).Error 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 { 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 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 { 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") return utils.Wrap(err, "RemoveBlackList failed")
} }
func GetBlackListByUserID(ownerUserID string) ([]db.Black, error) { func GetBlackListByUserID(ownerUserID string) ([]Black, error) {
var blackListUsersInfo []db.Black var blackListUsersInfo []Black
err := db.DB.MysqlDB.DefaultGormDB().Table("blacks").Where("owner_user_id=?", ownerUserID).Find(&blackListUsersInfo).Error err := db.DB.MysqlDB.DefaultGormDB().Table("blacks").Where("owner_user_id=?", ownerUserID).Find(&blackListUsersInfo).Error
if err != nil { if err != nil {
return nil, err return nil, err

@ -17,7 +17,7 @@ func init() {
} else { } else {
continue continue
} }
var appMgr db.User var appMgr User
appMgr.UserID = v appMgr.UserID = v
if k == 0 { if k == 0 {
appMgr.Nickname = config.Config.Manager.AppSysNotificationName 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() user.CreateTime = time.Now()
if user.AppMangerLevel == 0 { if user.AppMangerLevel == 0 {
user.AppMangerLevel = constant.AppOrdinaryUsers user.AppMangerLevel = constant.AppOrdinaryUsers
@ -49,14 +49,14 @@ func UserRegister(user db.User) error {
return nil return nil
} }
func GetAllUser() ([]db.User, error) { func GetAllUser() ([]User, error) {
var userList []db.User var userList []User
err := db.DB.MysqlDB.DefaultGormDB().Table("users").Find(&userList).Error err := db.DB.MysqlDB.DefaultGormDB().Table("users").Find(&userList).Error
return userList, err return userList, err
} }
func TakeUserByUserID(userID string) (*db.User, error) { func TakeUserByUserID(userID string) (*User, error) {
var user db.User var user User
err := db.DB.MysqlDB.DefaultGormDB().Table("users").Where("user_id=?", userID).Take(&user).Error err := db.DB.MysqlDB.DefaultGormDB().Table("users").Where("user_id=?", userID).Take(&user).Error
if err != nil { if err != nil {
return nil, err return nil, err
@ -64,8 +64,8 @@ func TakeUserByUserID(userID string) (*db.User, error) {
return &user, nil return &user, nil
} }
func GetUserByUserID(userID string) (*db.User, error) { func GetUserByUserID(userID string) (*User, error) {
var user db.User var user User
err := db.DB.MysqlDB.DefaultGormDB().Table("users").Where("user_id=?", userID).Take(&user).Error err := db.DB.MysqlDB.DefaultGormDB().Table("users").Where("user_id=?", userID).Take(&user).Error
if err != nil { if err != nil {
return nil, err return nil, err
@ -73,14 +73,14 @@ func GetUserByUserID(userID string) (*db.User, error) {
return &user, nil return &user, nil
} }
func GetUsersByUserIDList(userIDList []string) ([]*db.User, error) { func GetUsersByUserIDList(userIDList []string) ([]*User, error) {
var userList []*db.User var userList []*User
err := db.DB.MysqlDB.DefaultGormDB().Table("users").Where("user_id in (?)", userIDList).Find(&userList).Error err := db.DB.MysqlDB.DefaultGormDB().Table("users").Where("user_id in (?)", userIDList).Find(&userList).Error
return userList, err return userList, err
} }
func GetUserNameByUserID(userID string) (string, error) { 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 err := db.DB.MysqlDB.DefaultGormDB().Table("users").Select("name").Where("user_id=?", userID).First(&user).Error
if err != nil { if err != nil {
return "", err return "", err
@ -88,11 +88,11 @@ func GetUserNameByUserID(userID string) (string, error) {
return user.Nickname, nil 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 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 err := db.DB.MysqlDB.DefaultGormDB().Table("users").Where("user_id=?", user.UserID).Updates(m).Error
return err return err
} }
@ -115,8 +115,8 @@ func SelectSomeUserID(userIDList []string) ([]string, error) {
return resultArr, nil return resultArr, nil
} }
func GetUsers(showNumber, pageNumber int32) ([]db.User, error) { func GetUsers(showNumber, pageNumber int32) ([]User, error) {
var users []db.User var users []User
err := db.DB.MysqlDB.DefaultGormDB().Table("users").Limit(int(showNumber)).Offset(int(showNumber * (pageNumber - 1))).Find(&users).Error err := db.DB.MysqlDB.DefaultGormDB().Table("users").Limit(int(showNumber)).Offset(int(showNumber * (pageNumber - 1))).Find(&users).Error
if err != nil { if err != nil {
return users, err return users, err
@ -129,7 +129,7 @@ func AddUser(userID string, phoneNumber string, name string, email string, gende
if err != nil { if err != nil {
return err return err
} }
user := db.User{ user := User{
UserID: userID, UserID: userID,
Nickname: name, Nickname: name,
FaceURL: faceURL, FaceURL: faceURL,
@ -145,7 +145,7 @@ func AddUser(userID string, phoneNumber string, name string, email string, gende
} }
func UserIsBlock(userId string) (bool, error) { 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 rows := db.DB.MysqlDB.DefaultGormDB().Table("black_lists").Where("uid=?", userId).First(&user).RowsAffected
if rows >= 1 { if rows >= 1 {
return user.EndDisableTime.After(time.Now()), nil return user.EndDisableTime.After(time.Now()), nil
@ -170,13 +170,13 @@ func BlockUser(userID, endDisableTime string) error {
if end.Before(time.Now()) { if end.Before(time.Now()) {
return errors.New("endDisableTime is before 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) db.DB.MysqlDB.DefaultGormDB().Table("black_lists").Where("uid=?", userID).First(&blockUser)
if blockUser.UserId != "" { if blockUser.UserId != "" {
db.DB.MysqlDB.DefaultGormDB().Model(&blockUser).Where("uid=?", blockUser.UserId).Update("end_disable_time", end) db.DB.MysqlDB.DefaultGormDB().Model(&blockUser).Where("uid=?", blockUser.UserId).Update("end_disable_time", end)
return nil return nil
} }
blockUser = db.BlackList{ blockUser = BlackList{
UserId: userID, UserId: userID,
BeginDisableTime: time.Now(), BeginDisableTime: time.Now(),
EndDisableTime: end, EndDisableTime: end,
@ -186,24 +186,24 @@ func BlockUser(userID, endDisableTime string) error {
} }
func UnBlockUser(userID 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 { type BlockUserInfo struct {
User db.User User User
BeginDisableTime time.Time BeginDisableTime time.Time
EndDisableTime time.Time EndDisableTime time.Time
} }
func GetBlockUserByID(userId string) (BlockUserInfo, error) { func GetBlockUserByID(userId string) (BlockUserInfo, error) {
var blockUserInfo BlockUserInfo var blockUserInfo BlockUserInfo
blockUser := db.BlackList{ blockUser := BlackList{
UserId: userId, UserId: userId,
} }
if err := db.DB.MysqlDB.DefaultGormDB().Table("black_lists").Where("uid=?", userId).Find(&blockUser).Error; err != nil { if err := db.DB.MysqlDB.DefaultGormDB().Table("black_lists").Where("uid=?", userId).Find(&blockUser).Error; err != nil {
return blockUserInfo, err return blockUserInfo, err
} }
user := db.User{ user := User{
UserID: blockUser.UserId, UserID: blockUser.UserId,
} }
if err := db.DB.MysqlDB.DefaultGormDB().Find(&user).Error; err != nil { 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) { func GetBlockUsers(showNumber, pageNumber int32) ([]BlockUserInfo, error) {
var blockUserInfos []BlockUserInfo 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 { if err := db.DB.MysqlDB.DefaultGormDB().Limit(int(showNumber)).Offset(int(showNumber * (pageNumber - 1))).Find(&blockUsers).Error; err != nil {
return blockUserInfos, err return blockUserInfos, err
} }
for _, blockUser := range blockUsers { 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 { if err := db.DB.MysqlDB.DefaultGormDB().Table("users").Where("user_id=?", blockUser.UserId).First(&user).Error; err == nil {
blockUserInfos = append(blockUserInfos, BlockUserInfo{ blockUserInfos = append(blockUserInfos, BlockUserInfo{
User: db.User{ User: User{
UserID: user.UserID, UserID: user.UserID,
Nickname: user.Nickname, Nickname: user.Nickname,
FaceURL: user.FaceURL, FaceURL: user.FaceURL,
@ -248,14 +248,14 @@ func GetBlockUsers(showNumber, pageNumber int32) ([]BlockUserInfo, error) {
return blockUserInfos, nil return blockUserInfos, nil
} }
func GetUserByName(userName string, showNumber, pageNumber int32) ([]db.User, error) { func GetUserByName(userName string, showNumber, pageNumber int32) ([]User, error) {
var users []db.User 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 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 return users, err
} }
func GetUsersByNameAndID(content string, showNumber, pageNumber int32) ([]db.User, int64, error) { func GetUsersByNameAndID(content string, showNumber, pageNumber int32) ([]User, int64, error) {
var users []db.User var users []User
var count int64 var count int64
db := db.DB.MysqlDB.DefaultGormDB().Table("users").Where(" name like ? or user_id = ? ", fmt.Sprintf("%%%s%%", content), content) 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 { if err := db.Count(&count).Error; err != nil {
@ -291,7 +291,7 @@ func GetUsersCount(userName string) (int32, error) {
func GetBlockUsersNumCount() (int32, error) { func GetBlockUsersNumCount() (int32, error) {
var count int64 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 0, err
} }
return int32(count), nil return int32(count), nil

@ -9,6 +9,7 @@ package im_mysql_msg_model
import ( import (
"Open_IM/pkg/common/constant" "Open_IM/pkg/common/constant"
"Open_IM/pkg/common/db" "Open_IM/pkg/common/db"
"Open_IM/pkg/common/db/mysql_model/im_mysql_model"
"Open_IM/pkg/common/log" "Open_IM/pkg/common/log"
pbMsg "Open_IM/pkg/proto/msg" pbMsg "Open_IM/pkg/proto/msg"
"Open_IM/pkg/proto/sdk_ws" "Open_IM/pkg/proto/sdk_ws"
@ -19,7 +20,7 @@ import (
) )
func InsertMessageToChatLog(msg pbMsg.MsgDataToMQ) error { func InsertMessageToChatLog(msg pbMsg.MsgDataToMQ) error {
chatLog := new(db.ChatLog) chatLog := new(im_mysql_model.ChatLog)
copier.Copy(chatLog, msg.MsgData) copier.Copy(chatLog, msg.MsgData)
switch msg.MsgData.SessionType { switch msg.MsgData.SessionType {
case constant.GroupChatType, constant.SuperGroupChatType: case constant.GroupChatType, constant.SuperGroupChatType:

@ -184,7 +184,7 @@ func DelGroupMemberIDListFromCache(groupID string) error {
return err return err
} }
func GetUserInfoFromCache(userID string) (*db.User, error) { func GetUserInfoFromCache(userID string) (*imdb.User, error) {
getUserInfo := func() (string, error) { getUserInfo := func() (string, error) {
userInfo, err := imdb.GetUserByUserID(userID) userInfo, err := imdb.GetUserByUserID(userID)
if err != nil { if err != nil {
@ -200,7 +200,7 @@ func GetUserInfoFromCache(userID string) (*db.User, error) {
if err != nil { if err != nil {
return nil, utils.Wrap(err, "") return nil, utils.Wrap(err, "")
} }
userInfo := &db.User{} userInfo := &imdb.User{}
err = json.Unmarshal([]byte(userInfoStr), userInfo) err = json.Unmarshal([]byte(userInfoStr), userInfo)
return userInfo, utils.Wrap(err, "") return userInfo, utils.Wrap(err, "")
} }
@ -209,7 +209,7 @@ func DelUserInfoFromCache(userID string) error {
return db.DB.Rc.TagAsDeleted(userInfoCache + userID) 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) { getGroupMemberInfo := func() (string, error) {
groupMemberInfo, err := imdb.GetGroupMemberInfoByGroupIDAndUserID(groupID, userID) groupMemberInfo, err := imdb.GetGroupMemberInfoByGroupIDAndUserID(groupID, userID)
if err != nil { if err != nil {
@ -225,7 +225,7 @@ func GetGroupMemberInfoFromCache(groupID, userID string) (*db.GroupMember, error
if err != nil { if err != nil {
return nil, utils.Wrap(err, "") return nil, utils.Wrap(err, "")
} }
groupMember := &db.GroupMember{} groupMember := &imdb.GroupMember{}
err = json.Unmarshal([]byte(groupMemberInfoStr), groupMember) err = json.Unmarshal([]byte(groupMemberInfoStr), groupMember)
return groupMember, utils.Wrap(err, "") return groupMember, utils.Wrap(err, "")
} }
@ -234,7 +234,7 @@ func DelGroupMemberInfoFromCache(groupID, userID string) error {
return db.DB.Rc.TagAsDeleted(groupMemberInfoCache + groupID + "-" + userID) 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) groupMemberIDList, err := GetGroupMemberIDListFromCache(groupID)
if err != nil { if err != nil {
return nil, err return nil, err
@ -242,7 +242,7 @@ func GetGroupMembersInfoFromCache(count, offset int32, groupID string) ([]*db.Gr
if count < 0 || offset < 0 { if count < 0 || offset < 0 {
return nil, nil return nil, nil
} }
var groupMemberList []*db.GroupMember var groupMemberList []*imdb.GroupMember
var start, stop int32 var start, stop int32
start = offset start = offset
stop = offset + count stop = offset + count
@ -278,7 +278,7 @@ func GetGroupMembersInfoFromCache(count, offset int32, groupID string) ([]*db.Gr
return groupMemberList, nil return groupMemberList, nil
} }
func GetAllGroupMembersInfoFromCache(groupID string) ([]*db.GroupMember, error) { func GetAllGroupMembersInfoFromCache(groupID string) ([]*imdb.GroupMember, error) {
getGroupMemberInfo := func() (string, error) { getGroupMemberInfo := func() (string, error) {
groupMembers, err := imdb.GetGroupMemberListByGroupID(groupID) groupMembers, err := imdb.GetGroupMemberListByGroupID(groupID)
if err != nil { if err != nil {
@ -294,7 +294,7 @@ func GetAllGroupMembersInfoFromCache(groupID string) ([]*db.GroupMember, error)
if err != nil { if err != nil {
return nil, utils.Wrap(err, "") return nil, utils.Wrap(err, "")
} }
var groupMembers []*db.GroupMember var groupMembers []*imdb.GroupMember
err = json.Unmarshal([]byte(groupMembersStr), &groupMembers) err = json.Unmarshal([]byte(groupMembersStr), &groupMembers)
return groupMembers, utils.Wrap(err, "") return groupMembers, utils.Wrap(err, "")
} }
@ -303,7 +303,7 @@ func DelAllGroupMembersInfoFromCache(groupID string) error {
return db.DB.Rc.TagAsDeleted(groupAllMemberInfoCache + groupID) 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) { getGroupInfo := func() (string, error) {
groupInfo, err := imdb.GetGroupInfoByGroupID(groupID) groupInfo, err := imdb.GetGroupInfoByGroupID(groupID)
if err != nil { if err != nil {
@ -319,7 +319,7 @@ func GetGroupInfoFromCache(groupID string) (*db.Group, error) {
if err != nil { if err != nil {
return nil, utils.Wrap(err, "") return nil, utils.Wrap(err, "")
} }
groupInfo := &db.Group{} groupInfo := &imdb.Group{}
err = json.Unmarshal([]byte(groupInfoStr), groupInfo) err = json.Unmarshal([]byte(groupInfoStr), groupInfo)
return groupInfo, utils.Wrap(err, "") return groupInfo, utils.Wrap(err, "")
} }
@ -328,7 +328,7 @@ func DelGroupInfoFromCache(groupID string) error {
return db.DB.Rc.TagAsDeleted(groupInfoCache + groupID) 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) { getAllFriendInfo := func() (string, error) {
friendInfoList, err := imdb.GetFriendListByUserID(userID) friendInfoList, err := imdb.GetFriendListByUserID(userID)
if err != nil { if err != nil {
@ -344,7 +344,7 @@ func GetAllFriendsInfoFromCache(userID string) ([]*db.Friend, error) {
if err != nil { if err != nil {
return nil, utils.Wrap(err, "") return nil, utils.Wrap(err, "")
} }
var friendInfoList []*db.Friend var friendInfoList []*imdb.Friend
err = json.Unmarshal([]byte(allFriendInfoStr), &friendInfoList) err = json.Unmarshal([]byte(allFriendInfoStr), &friendInfoList)
return friendInfoList, utils.Wrap(err, "") return friendInfoList, utils.Wrap(err, "")
} }
@ -353,7 +353,7 @@ func DelAllFriendsInfoFromCache(userID string) error {
return db.DB.Rc.TagAsDeleted(allFriendInfoCache + userID) return db.DB.Rc.TagAsDeleted(allFriendInfoCache + userID)
} }
func GetAllDepartmentsFromCache() ([]db.Department, error) { func GetAllDepartmentsFromCache() ([]imdb.Department, error) {
getAllDepartments := func() (string, error) { getAllDepartments := func() (string, error) {
departmentList, err := imdb.GetSubDepartmentList("-1") departmentList, err := imdb.GetSubDepartmentList("-1")
if err != nil { if err != nil {
@ -369,7 +369,7 @@ func GetAllDepartmentsFromCache() ([]db.Department, error) {
if err != nil { if err != nil {
return nil, utils.Wrap(err, "") return nil, utils.Wrap(err, "")
} }
var allDepartments []db.Department var allDepartments []imdb.Department
err = json.Unmarshal([]byte(allDepartmentsStr), &allDepartments) err = json.Unmarshal([]byte(allDepartmentsStr), &allDepartments)
return allDepartments, utils.Wrap(err, "") return allDepartments, utils.Wrap(err, "")
} }
@ -378,7 +378,7 @@ func DelAllDepartmentsFromCache() error {
return db.DB.Rc.TagAsDeleted(allDepartmentCache) return db.DB.Rc.TagAsDeleted(allDepartmentCache)
} }
func GetAllDepartmentMembersFromCache() ([]db.DepartmentMember, error) { func GetAllDepartmentMembersFromCache() ([]imdb.DepartmentMember, error) {
getAllDepartmentMembers := func() (string, error) { getAllDepartmentMembers := func() (string, error) {
departmentMembers, err := imdb.GetDepartmentMemberList("-1") departmentMembers, err := imdb.GetDepartmentMemberList("-1")
if err != nil { if err != nil {
@ -394,7 +394,7 @@ func GetAllDepartmentMembersFromCache() ([]db.DepartmentMember, error) {
if err != nil { if err != nil {
return nil, utils.Wrap(err, "") return nil, utils.Wrap(err, "")
} }
var allDepartmentMembers []db.DepartmentMember var allDepartmentMembers []imdb.DepartmentMember
err = json.Unmarshal([]byte(allDepartmentMembersStr), &allDepartmentMembers) err = json.Unmarshal([]byte(allDepartmentMembersStr), &allDepartmentMembers)
return allDepartmentMembers, utils.Wrap(err, "") 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") 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) { getConversation := func() (string, error) {
conversation, err := imdb.GetConversation(ownerUserID, conversationID) conversation, err := imdb.GetConversation(ownerUserID, conversationID)
if err != nil { if err != nil {
@ -526,7 +526,7 @@ func GetConversationFromCache(ownerUserID, conversationID string) (*db.Conversat
if err != nil { if err != nil {
return nil, utils.Wrap(err, "Fetch failed") return nil, utils.Wrap(err, "Fetch failed")
} }
conversation := db.Conversation{} conversation := imdb.Conversation{}
err = json.Unmarshal([]byte(conversationStr), &conversation) err = json.Unmarshal([]byte(conversationStr), &conversation)
if err != nil { if err != nil {
return nil, utils.Wrap(err, "Unmarshal failed") return nil, utils.Wrap(err, "Unmarshal failed")
@ -534,8 +534,8 @@ func GetConversationFromCache(ownerUserID, conversationID string) (*db.Conversat
return &conversation, nil return &conversation, nil
} }
func GetConversationsFromCache(ownerUserID string, conversationIDList []string) ([]db.Conversation, error) { func GetConversationsFromCache(ownerUserID string, conversationIDList []string) ([]imdb.Conversation, error) {
var conversationList []db.Conversation var conversationList []imdb.Conversation
for _, conversationID := range conversationIDList { for _, conversationID := range conversationIDList {
conversation, err := GetConversationFromCache(ownerUserID, conversationID) conversation, err := GetConversationFromCache(ownerUserID, conversationID)
if err != nil { if err != nil {
@ -546,12 +546,12 @@ func GetConversationsFromCache(ownerUserID string, conversationIDList []string)
return conversationList, nil return conversationList, nil
} }
func GetUserAllConversationList(ownerUserID string) ([]db.Conversation, error) { func GetUserAllConversationList(ownerUserID string) ([]imdb.Conversation, error) {
IDList, err := GetUserConversationIDListFromCache(ownerUserID) IDList, err := GetUserConversationIDListFromCache(ownerUserID)
if err != nil { if err != nil {
return nil, err return nil, err
} }
var conversationList []db.Conversation var conversationList []imdb.Conversation
log.NewDebug("", utils.GetSelfFuncName(), IDList) log.NewDebug("", utils.GetSelfFuncName(), IDList)
for _, conversationID := range IDList { for _, conversationID := range IDList {
conversation, err := GetConversationFromCache(ownerUserID, conversationID) conversation, err := GetConversationFromCache(ownerUserID, conversationID)

@ -1,7 +1,6 @@
package utils package utils
import ( import (
db "Open_IM/pkg/common/db"
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model" imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
"Open_IM/pkg/common/token_verify" "Open_IM/pkg/common/token_verify"
open_im_sdk "Open_IM/pkg/proto/sdk_ws" 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) 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) utils.CopyStructFields(dst, src)
dst.FriendUserID = src.FriendUser.UserID dst.FriendUserID = src.FriendUser.UserID
dst.CreateTime = utils.UnixSecondToTime(int64(src.CreateTime)) 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) utils.CopyStructFields(dst, src)
user, err := imdb.GetUserByUserID(src.FriendUserID) user, err := imdb.GetUserByUserID(src.FriendUserID)
if err != nil { if err != nil {
@ -36,14 +35,13 @@ func FriendDBCopyOpenIM(dst *open_im_sdk.FriendInfo, src *db.Friend) error {
return nil return nil
} }
// func FriendRequestOpenIMCopyDB(dst *imdb.FriendRequest, src *open_im_sdk.FriendRequest) {
func FriendRequestOpenIMCopyDB(dst *db.FriendRequest, src *open_im_sdk.FriendRequest) {
utils.CopyStructFields(dst, src) utils.CopyStructFields(dst, src)
dst.CreateTime = utils.UnixSecondToTime(int64(src.CreateTime)) dst.CreateTime = utils.UnixSecondToTime(int64(src.CreateTime))
dst.HandleTime = utils.UnixSecondToTime(int64(src.HandleTime)) 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) utils.CopyStructFields(dst, src)
user, err := imdb.GetUserByUserID(src.FromUserID) user, err := imdb.GetUserByUserID(src.FromUserID)
if err != nil { if err != nil {
@ -64,13 +62,13 @@ func FriendRequestDBCopyOpenIM(dst *open_im_sdk.FriendRequest, src *db.FriendReq
return nil 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) utils.CopyStructFields(dst, src)
dst.BlockUserID = src.BlackUserInfo.UserID dst.BlockUserID = src.BlackUserInfo.UserID
dst.CreateTime = utils.UnixSecondToTime(int64(src.CreateTime)) 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) utils.CopyStructFields(dst, src)
dst.CreateTime = uint32(src.CreateTime.Unix()) dst.CreateTime = uint32(src.CreateTime.Unix())
user, err := imdb.GetUserByUserID(src.BlockUserID) user, err := imdb.GetUserByUserID(src.BlockUserID)
@ -81,11 +79,11 @@ func BlackDBCopyOpenIM(dst *open_im_sdk.BlackInfo, src *db.Black) error {
return nil 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) 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) utils.CopyStructFields(dst, src)
user, err := imdb.GetGroupOwnerInfoByGroupID(src.GroupID) user, err := imdb.GetGroupOwnerInfoByGroupID(src.GroupID)
if err != nil { if err != nil {
@ -106,11 +104,11 @@ func GroupDBCopyOpenIM(dst *open_im_sdk.GroupInfo, src *db.Group) error {
return nil 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) 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) utils.CopyStructFields(dst, src)
if token_verify.IsManagerUserID(src.UserID) { if token_verify.IsManagerUserID(src.UserID) {
u, err := imdb.GetUserByUserID(src.UserID) u, err := imdb.GetUserByUserID(src.UserID)
@ -134,29 +132,29 @@ func GroupMemberDBCopyOpenIM(dst *open_im_sdk.GroupMemberFullInfo, src *db.Group
return nil 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) 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) utils.CopyStructFields(dst, src)
dst.ReqTime = uint32(src.ReqTime.Unix()) dst.ReqTime = uint32(src.ReqTime.Unix())
dst.HandleTime = uint32(src.HandledTime.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) utils.CopyStructFields(dst, src)
dst.Birth, _ = utils.TimeStringToTime(src.BirthStr) dst.Birth, _ = utils.TimeStringToTime(src.BirthStr)
dst.CreateTime = utils.UnixSecondToTime(int64(src.CreateTime)) 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) utils.CopyStructFields(dst, src)
dst.CreateTime = uint32(src.CreateTime.Unix()) dst.CreateTime = uint32(src.CreateTime.Unix())
//dst.Birth = uint32(src.Birth.Unix()) //dst.Birth = uint32(src.Birth.Unix())
dst.BirthStr = utils.TimeToString(src.Birth) 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) utils.CopyStructFields(dst, src)
} }

Loading…
Cancel
Save