mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-08-31 03:05:43 +08:00
1
This commit is contained in:
parent
1d428785d1
commit
58866c1b41
@ -4,9 +4,7 @@ import (
|
||||
chat "Open_IM/internal/rpc/msg"
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db"
|
||||
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
rocksCache "Open_IM/pkg/common/db/rocks_cache"
|
||||
"Open_IM/pkg/common/db/mysql"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/middleware"
|
||||
promePkg "Open_IM/pkg/common/prometheus"
|
||||
@ -37,26 +35,27 @@ type friendServer struct {
|
||||
rpcRegisterName string
|
||||
etcdSchema string
|
||||
etcdAddr []string
|
||||
friendModel *imdb.Friend
|
||||
friendRequestModel *imdb.FriendRequest
|
||||
blackModel *imdb.Black
|
||||
friendModel *mysql.Friend
|
||||
friendRequestModel *mysql.FriendRequest
|
||||
blackModel *mysql.Black
|
||||
}
|
||||
|
||||
func NewFriendServer(port int) *friendServer {
|
||||
log.NewPrivateLog(constant.LogFileName)
|
||||
DB := db.DB.MysqlDB.DefaultGormDB()
|
||||
return &friendServer{
|
||||
rpcPort: port,
|
||||
rpcRegisterName: config.Config.RpcRegisterName.OpenImFriendName,
|
||||
etcdSchema: config.Config.Etcd.EtcdSchema,
|
||||
etcdAddr: config.Config.Etcd.EtcdAddr,
|
||||
friendModel: imdb.NewFriend(DB),
|
||||
friendRequestModel: imdb.NewFriendRequest(DB),
|
||||
blackModel: imdb.NewBlack(DB),
|
||||
rpcPort: port,
|
||||
rpcRegisterName: config.Config.RpcRegisterName.OpenImFriendName,
|
||||
etcdSchema: config.Config.Etcd.EtcdSchema,
|
||||
etcdAddr: config.Config.Etcd.EtcdAddr,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *friendServer) Run() {
|
||||
db := mysql.ConnectToDB()
|
||||
s.friendModel = mysql.NewFriend(db)
|
||||
s.friendRequestModel = mysql.NewFriendRequest(db)
|
||||
s.blackModel = mysql.NewBlack(db)
|
||||
|
||||
log.NewInfo("0", "friendServer run...")
|
||||
|
||||
listenIP := ""
|
||||
|
@ -57,18 +57,18 @@ package mysql
|
||||
//}
|
||||
//
|
||||
//func GetUserFriendsCMS(ownerUserID, friendUserName string, pageNumber, showNumber int32) (friendUserList []*FriendUser, count int64, err error) {
|
||||
// db := FriendDB.Table("friends").
|
||||
// DB := FriendDB.Table("friends").
|
||||
// Select("friends.*, users.name").
|
||||
// Where("friends.owner_user_id=?", ownerUserID).Limit(int(showNumber)).
|
||||
// Joins("left join users on friends.friend_user_id = users.user_id").
|
||||
// Offset(int(showNumber * (pageNumber - 1)))
|
||||
// if friendUserName != "" {
|
||||
// db = db.Where("users.name like ?", fmt.Sprintf("%%%s%%", friendUserName))
|
||||
// DB = DB.Where("users.name like ?", fmt.Sprintf("%%%s%%", friendUserName))
|
||||
// }
|
||||
// if err = db.Count(&count).Error; err != nil {
|
||||
// if err = DB.Count(&count).Error; err != nil {
|
||||
// return
|
||||
// }
|
||||
// err = db.Find(&friendUserList).Error
|
||||
// err = DB.Find(&friendUserList).Error
|
||||
// return
|
||||
//}
|
||||
//
|
||||
|
@ -16,25 +16,27 @@ type Friend struct {
|
||||
AddSource int32 `gorm:"column:add_source"`
|
||||
OperatorUserID string `gorm:"column:operator_user_id;size:64"`
|
||||
Ex string `gorm:"column:ex;size:1024"`
|
||||
db *gorm.DB `gorm:"-"`
|
||||
DB *gorm.DB `gorm:"-"`
|
||||
}
|
||||
|
||||
func NewFriend(db *gorm.DB) *Friend {
|
||||
return &Friend{db: db}
|
||||
var friend Friend
|
||||
friend.DB = initModel(db, friend)
|
||||
return &friend
|
||||
}
|
||||
|
||||
func (f *Friend) Create(ctx context.Context, friends []*Friend) (err error) {
|
||||
defer func() {
|
||||
trace_log.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "friends", friends)
|
||||
}()
|
||||
return utils.Wrap(f.db.Create(&friends).Error, "")
|
||||
return utils.Wrap(f.DB.Create(&friends).Error, "")
|
||||
}
|
||||
|
||||
func (f *Friend) Delete(ctx context.Context, ownerUserID string, friendUserIDs string) (err error) {
|
||||
defer func() {
|
||||
trace_log.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "ownerUserID", ownerUserID, "friendUserIDs", friendUserIDs)
|
||||
}()
|
||||
err = utils.Wrap(f.db.Where("owner_user_id = ? and friend_user_id = ?", ownerUserID, friendUserIDs).Delete(&Friend{}).Error, "")
|
||||
err = utils.Wrap(f.DB.Where("owner_user_id = ? and friend_user_id = ?", ownerUserID, friendUserIDs).Delete(&Friend{}).Error, "")
|
||||
return err
|
||||
}
|
||||
|
||||
@ -42,39 +44,39 @@ func (f *Friend) UpdateByMap(ctx context.Context, ownerUserID string, args map[s
|
||||
defer func() {
|
||||
trace_log.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "ownerUserID", ownerUserID, "args", args)
|
||||
}()
|
||||
return utils.Wrap(f.db.Where("owner_user_id = ?", ownerUserID).Updates(args).Error, "")
|
||||
return utils.Wrap(f.DB.Where("owner_user_id = ?", ownerUserID).Updates(args).Error, "")
|
||||
}
|
||||
|
||||
func (f *Friend) Update(ctx context.Context, friends []*Friend) (err error) {
|
||||
defer func() {
|
||||
trace_log.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "friends", friends)
|
||||
}()
|
||||
return utils.Wrap(f.db.Updates(&friends).Error, "")
|
||||
return utils.Wrap(f.DB.Updates(&friends).Error, "")
|
||||
}
|
||||
|
||||
func (f *Friend) UpdateRemark(ctx context.Context, ownerUserID, friendUserID, remark string) (err error) {
|
||||
defer func() {
|
||||
trace_log.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "ownerUserID", ownerUserID, "friendUserID", friendUserID, "remark", remark)
|
||||
}()
|
||||
return utils.Wrap(f.db.Model(f).Where("owner_user_id = ? and friend_user_id = ?", ownerUserID, friendUserID).Update("remark", remark).Error, "")
|
||||
return utils.Wrap(f.DB.Model(f).Where("owner_user_id = ? and friend_user_id = ?", ownerUserID, friendUserID).Update("remark", remark).Error, "")
|
||||
}
|
||||
|
||||
func (f *Friend) Find(ctx context.Context, ownerUserID string) (friends []*Friend, err error) {
|
||||
defer func() {
|
||||
trace_log.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "ownerUserID", ownerUserID, "friends", friends)
|
||||
}()
|
||||
return friends, utils.Wrap(f.db.Where("owner_user_id = ?", ownerUserID).Find(&friends).Error, "")
|
||||
return friends, utils.Wrap(f.DB.Where("owner_user_id = ?", ownerUserID).Find(&friends).Error, "")
|
||||
}
|
||||
|
||||
func (f *Friend) Take(ctx context.Context, ownerUserID, friendUserID string) (friend *Friend, err error) {
|
||||
friend = &Friend{}
|
||||
defer trace_log.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "ownerUserID", ownerUserID, "friendUserID", friendUserID, "friend", friend)
|
||||
return friend, utils.Wrap(f.db.Where("owner_user_id = ? and friend_user_id", ownerUserID, friendUserID).Take(friend).Error, "")
|
||||
return friend, utils.Wrap(f.DB.Where("owner_user_id = ? and friend_user_id", ownerUserID, friendUserID).Take(friend).Error, "")
|
||||
}
|
||||
|
||||
func (f *Friend) FindUserState(ctx context.Context, userID1, userID2 string) (friends []*Friend, err error) {
|
||||
defer func() {
|
||||
trace_log.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "userID1", userID1, "userID2", userID2)
|
||||
}()
|
||||
return friends, utils.Wrap(f.db.Where("(owner_user_id = ? and friend_user_id = ?) or (owner_user_id = ? and friend_user_id = ?)", userID1, userID2, userID2, userID1).Find(&friends).Error, "")
|
||||
return friends, utils.Wrap(f.DB.Where("(owner_user_id = ? and friend_user_id = ?) or (owner_user_id = ? and friend_user_id = ?)", userID1, userID2, userID2, userID1).Find(&friends).Error, "")
|
||||
}
|
||||
|
@ -20,18 +20,20 @@ type FriendRequest struct {
|
||||
HandleMsg string `gorm:"column:handle_msg;size:255"`
|
||||
HandleTime time.Time `gorm:"column:handle_time"`
|
||||
Ex string `gorm:"column:ex;size:1024"`
|
||||
db *gorm.DB `gorm:"-"`
|
||||
DB *gorm.DB `gorm:"-"`
|
||||
}
|
||||
|
||||
func NewFriendRequest(db *gorm.DB) *FriendRequest {
|
||||
return &FriendRequest{db: db}
|
||||
var fr FriendRequest
|
||||
fr.DB = initModel(db, &fr)
|
||||
return &fr
|
||||
}
|
||||
|
||||
func (f *FriendRequest) Create(ctx context.Context, friends []*FriendRequest) (err error) {
|
||||
defer func() {
|
||||
trace_log.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "friends", friends)
|
||||
}()
|
||||
err = utils.Wrap(f.db.Create(&friends).Error, "")
|
||||
err = utils.Wrap(f.DB.Create(&friends).Error, "")
|
||||
return err
|
||||
}
|
||||
|
||||
@ -39,7 +41,7 @@ func (f *FriendRequest) Delete(ctx context.Context, fromUserID, toUserID string)
|
||||
defer func() {
|
||||
trace_log.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "fromUserID", fromUserID, "toUserID", toUserID)
|
||||
}()
|
||||
err = utils.Wrap(f.db.Where("from_user_id = ? and to_user_id = ?", fromUserID, toUserID).Delete(&FriendRequest{}).Error, "")
|
||||
err = utils.Wrap(f.DB.Where("from_user_id = ? and to_user_id = ?", fromUserID, toUserID).Delete(&FriendRequest{}).Error, "")
|
||||
return err
|
||||
}
|
||||
|
||||
@ -47,28 +49,28 @@ func (f *FriendRequest) UpdateByMap(ctx context.Context, ownerUserID string, arg
|
||||
defer func() {
|
||||
trace_log.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "ownerUserID", ownerUserID, "args", args)
|
||||
}()
|
||||
return utils.Wrap(f.db.Where("owner_user_id = ?", ownerUserID).Updates(args).Error, "")
|
||||
return utils.Wrap(f.DB.Where("owner_user_id = ?", ownerUserID).Updates(args).Error, "")
|
||||
}
|
||||
|
||||
func (f *FriendRequest) Update(ctx context.Context, friends []*FriendRequest) (err error) {
|
||||
defer func() {
|
||||
trace_log.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "friends", friends)
|
||||
}()
|
||||
return utils.Wrap(f.db.Updates(&friends).Error, "")
|
||||
return utils.Wrap(f.DB.Updates(&friends).Error, "")
|
||||
}
|
||||
|
||||
func (f *FriendRequest) Find(ctx context.Context, ownerUserID string) (friends []*FriendRequest, err error) {
|
||||
defer func() {
|
||||
trace_log.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "ownerUserID", ownerUserID, "friends", friends)
|
||||
}()
|
||||
err = utils.Wrap(f.db.Where("owner_user_id = ?", ownerUserID).Find(&friends).Error, "")
|
||||
err = utils.Wrap(f.DB.Where("owner_user_id = ?", ownerUserID).Find(&friends).Error, "")
|
||||
return friends, err
|
||||
}
|
||||
|
||||
func (f *FriendRequest) Take(ctx context.Context, fromUserID, toUserID string) (friend *FriendRequest, err error) {
|
||||
friend = &FriendRequest{}
|
||||
defer trace_log.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "fromUserID", fromUserID, "toUserID", toUserID, "friend", friend)
|
||||
err = utils.Wrap(f.db.Where("from_user_id = ? and to_user_id", fromUserID, toUserID).Take(friend).Error, "")
|
||||
err = utils.Wrap(f.DB.Where("from_user_id = ? and to_user_id", fromUserID, toUserID).Take(friend).Error, "")
|
||||
return friend, err
|
||||
}
|
||||
|
||||
@ -76,14 +78,14 @@ func (f *FriendRequest) FindToUserID(ctx context.Context, toUserID string) (frie
|
||||
defer func() {
|
||||
trace_log.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "toUserID", toUserID, "friends", friends)
|
||||
}()
|
||||
return friends, utils.Wrap(f.db.Where("to_user_id = ?", toUserID).Find(&friends).Error, "")
|
||||
return friends, utils.Wrap(f.DB.Where("to_user_id = ?", toUserID).Find(&friends).Error, "")
|
||||
}
|
||||
|
||||
func (f *FriendRequest) FindFromUserID(ctx context.Context, fromUserID string) (friends []*FriendRequest, err error) {
|
||||
defer func() {
|
||||
trace_log.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "fromUserID", fromUserID, "friends", friends)
|
||||
}()
|
||||
return friends, utils.Wrap(f.db.Where("from_user_id = ?", fromUserID).Find(&friends).Error, "")
|
||||
return friends, utils.Wrap(f.DB.Where("from_user_id = ?", fromUserID).Find(&friends).Error, "")
|
||||
}
|
||||
|
||||
// who apply to add me
|
||||
|
@ -18,7 +18,7 @@ package mysql
|
||||
// toInsertInfo.RoleLevel = constant.GroupOrdinaryUsers
|
||||
// }
|
||||
// toInsertInfo.MuteEndTime = time.Unix(int64(time.Now().Second()), 0)
|
||||
// err := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Create(toInsertInfo).Error
|
||||
// err := DB.DB.MysqlDB.DefaultGormDB().Table("group_members").Create(toInsertInfo).Error
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
@ -33,13 +33,13 @@ package mysql
|
||||
// }
|
||||
// toInsertInfo.MuteEndTime = time.Unix(int64(time.Now().Second()), 0)
|
||||
// }
|
||||
// return db.DB.MysqlDB.DefaultGormDB().Create(toInsertInfoList).Error
|
||||
// return DB.DB.MysqlDB.DefaultGormDB().Create(toInsertInfoList).Error
|
||||
//
|
||||
//}
|
||||
//
|
||||
//func GetGroupMemberListByUserID(userID string) ([]GroupMember, error) {
|
||||
// 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 {
|
||||
// return nil, err
|
||||
// }
|
||||
@ -48,7 +48,7 @@ package mysql
|
||||
//
|
||||
//func GetGroupMemberListByGroupID(groupID string) ([]GroupMember, error) {
|
||||
// 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 {
|
||||
// return nil, err
|
||||
// }
|
||||
@ -57,7 +57,7 @@ package mysql
|
||||
//
|
||||
//func GetGroupMemberIDListByGroupID(groupID string) ([]string, error) {
|
||||
// var groupMemberIDList []string
|
||||
// err := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=?", groupID).Pluck("user_id", &groupMemberIDList).Error
|
||||
// err := DB.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=?", groupID).Pluck("user_id", &groupMemberIDList).Error
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
@ -66,7 +66,7 @@ package mysql
|
||||
//
|
||||
//func GetGroupMemberListByGroupIDAndRoleLevel(groupID string, roleLevel int32) ([]GroupMember, error) {
|
||||
// var groupMemberList []GroupMember
|
||||
// err := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=? and role_level=?", groupID, roleLevel).Find(&groupMemberList).Error
|
||||
// err := DB.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=? and role_level=?", groupID, roleLevel).Find(&groupMemberList).Error
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
@ -75,7 +75,7 @@ package mysql
|
||||
//
|
||||
//func GetGroupMemberInfoByGroupIDAndUserID(groupID, userID string) (*GroupMember, error) {
|
||||
// var groupMember GroupMember
|
||||
// err := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=? and user_id=? ", groupID, userID).Limit(1).Take(&groupMember).Error
|
||||
// err := DB.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=? and user_id=? ", groupID, userID).Limit(1).Take(&groupMember).Error
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
@ -83,24 +83,24 @@ package mysql
|
||||
//}
|
||||
//
|
||||
//func DeleteGroupMemberByGroupIDAndUserID(groupID, userID string) error {
|
||||
// return db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=? and user_id=? ", groupID, userID).Delete(GroupMember{}).Error
|
||||
// return DB.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=? and user_id=? ", groupID, userID).Delete(GroupMember{}).Error
|
||||
//}
|
||||
//
|
||||
//func DeleteGroupMemberByGroupID(groupID string) error {
|
||||
// return db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=? ", groupID).Delete(GroupMember{}).Error
|
||||
// return DB.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=? ", groupID).Delete(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 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) ([]GroupMember, error) {
|
||||
// var groupMemberList []GroupMember
|
||||
// err := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=? and role_level>?", groupID, constant.GroupOrdinaryUsers).Find(&groupMemberList).Error
|
||||
// err := DB.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=? and role_level>?", groupID, constant.GroupOrdinaryUsers).Find(&groupMemberList).Error
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
@ -109,7 +109,7 @@ package mysql
|
||||
//
|
||||
//func GetGroupMemberNumByGroupID(groupID string) (int64, error) {
|
||||
// var number int64
|
||||
// err := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=?", groupID).Count(&number).Error
|
||||
// err := DB.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=?", groupID).Count(&number).Error
|
||||
// if err != nil {
|
||||
// return 0, utils.Wrap(err, "")
|
||||
// }
|
||||
@ -131,7 +131,7 @@ package mysql
|
||||
//
|
||||
//func IsExistGroupMember(groupID, userID string) bool {
|
||||
// var number int64
|
||||
// err := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id = ? and user_id = ?", groupID, userID).Count(&number).Error
|
||||
// err := DB.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id = ? and user_id = ?", groupID, userID).Count(&number).Error
|
||||
// if err != nil {
|
||||
// return false
|
||||
// }
|
||||
@ -193,7 +193,7 @@ package mysql
|
||||
//
|
||||
//func GetGroupMembersByGroupIdCMS(groupId string, userName string, showNumber, pageNumber int32) ([]GroupMember, error) {
|
||||
// var groupMembers []GroupMember
|
||||
// err := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=?", groupId).Where(fmt.Sprintf(" nickname like '%%%s%%' ", userName)).Limit(int(showNumber)).Offset(int(showNumber * (pageNumber - 1))).Find(&groupMembers).Error
|
||||
// err := DB.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=?", groupId).Where(fmt.Sprintf(" nickname like '%%%s%%' ", userName)).Limit(int(showNumber)).Offset(int(showNumber * (pageNumber - 1))).Find(&groupMembers).Error
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
@ -202,21 +202,21 @@ package mysql
|
||||
//
|
||||
//func GetGroupMembersCount(groupID, userName string) (int64, error) {
|
||||
// var count int64
|
||||
// if err := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=?", groupID).Where(fmt.Sprintf(" nickname like '%%%s%%' ", userName)).Count(&count).Error; err != nil {
|
||||
// if err := DB.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=?", groupID).Where(fmt.Sprintf(" nickname like '%%%s%%' ", userName)).Count(&count).Error; err != nil {
|
||||
// return count, err
|
||||
// }
|
||||
// return count, nil
|
||||
//}
|
||||
//
|
||||
//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
|
||||
//}
|
||||
|
||||
//
|
||||
//func SelectGroupList(groupID string) ([]string, error) {
|
||||
// var groupUserID string
|
||||
// var groupList []string
|
||||
// dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
// dbConn, err := DB.DB.MysqlDB.DefaultGormDB()
|
||||
// if err != nil {
|
||||
// return groupList, err
|
||||
// }
|
||||
|
@ -5,7 +5,7 @@ package mysql
|
||||
// if groupRequest.HandledTime.Unix() < 0 {
|
||||
// groupRequest.HandledTime = utils.UnixSecondToTime(0)
|
||||
// }
|
||||
// return db.DB.MysqlDB.DefaultGormDB().Table("group_requests").Where("group_id=? and user_id=?", groupRequest.GroupID, groupRequest.UserID).Updates(&groupRequest).Error
|
||||
// return DB.DB.MysqlDB.DefaultGormDB().Table("group_requests").Where("group_id=? and user_id=?", groupRequest.GroupID, groupRequest.UserID).Updates(&groupRequest).Error
|
||||
//}
|
||||
//
|
||||
//func InsertIntoGroupRequest(toInsertInfo GroupRequest) error {
|
||||
@ -13,7 +13,7 @@ package mysql
|
||||
// if toInsertInfo.HandledTime.Unix() < 0 {
|
||||
// toInsertInfo.HandledTime = utils.UnixSecondToTime(0)
|
||||
// }
|
||||
// u := db.DB.MysqlDB.DefaultGormDB().Table("group_requests").Where("group_id=? and user_id=?", toInsertInfo.GroupID, toInsertInfo.UserID).Updates(&toInsertInfo)
|
||||
// u := DB.DB.MysqlDB.DefaultGormDB().Table("group_requests").Where("group_id=? and user_id=?", toInsertInfo.GroupID, toInsertInfo.UserID).Updates(&toInsertInfo)
|
||||
// if u.RowsAffected != 0 {
|
||||
// return nil
|
||||
// }
|
||||
@ -23,7 +23,7 @@ package mysql
|
||||
// toInsertInfo.HandledTime = utils.UnixSecondToTime(0)
|
||||
// }
|
||||
//
|
||||
// err := db.DB.MysqlDB.DefaultGormDB().Table("group_requests").Create(&toInsertInfo).Error
|
||||
// err := DB.DB.MysqlDB.DefaultGormDB().Table("group_requests").Create(&toInsertInfo).Error
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
@ -32,7 +32,7 @@ package mysql
|
||||
//
|
||||
//func GetGroupRequestByGroupIDAndUserID(groupID, userID string) (*GroupRequest, error) {
|
||||
// var groupRequest GroupRequest
|
||||
// err := db.DB.MysqlDB.DefaultGormDB().Table("group_requests").Where("user_id=? and group_id=?", userID, groupID).Take(&groupRequest).Error
|
||||
// err := DB.DB.MysqlDB.DefaultGormDB().Table("group_requests").Where("user_id=? and group_id=?", userID, groupID).Take(&groupRequest).Error
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
@ -40,12 +40,12 @@ package mysql
|
||||
//}
|
||||
//
|
||||
//func DelGroupRequestByGroupIDAndUserID(groupID, userID string) error {
|
||||
// return db.DB.MysqlDB.DefaultGormDB().Table("group_requests").Where("group_id=? and user_id=?", groupID, userID).Delete(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) ([]GroupRequest, error) {
|
||||
// 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 {
|
||||
// return nil, err
|
||||
// }
|
||||
@ -73,7 +73,7 @@ package mysql
|
||||
//
|
||||
//func GetUserReqGroupByUserID(userID string) ([]GroupRequest, error) {
|
||||
// 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
|
||||
//}
|
||||
//
|
||||
@ -89,7 +89,7 @@ package mysql
|
||||
// return nil, errors.New("insufficient permissions")
|
||||
// }
|
||||
//
|
||||
// dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
// dbConn, err := DB.DB.MysqlDB.DefaultGormDB()
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
@ -140,7 +140,7 @@ package mysql
|
||||
//}
|
||||
//
|
||||
//func FindGroupBeInvitedRequestInfoByUidAndGroupID(groupId, uid string) (*GroupRequest, error) {
|
||||
// dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
// dbConn, err := DB.DB.MysqlDB.DefaultGormDB()
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
|
@ -57,7 +57,7 @@ func ConnectToDB() *gorm.DB {
|
||||
//models := []interface{}{&Friend{}, &FriendRequest{}, &Group{}, &GroupMember{}, &GroupRequest{},
|
||||
// &User{}, &Black{}, &ChatLog{}, &Conversation{}, &AppVersion{}}
|
||||
|
||||
func InitModel(db *gorm.DB, model interface{}) *gorm.DB {
|
||||
func initModel(db *gorm.DB, model interface{}) *gorm.DB {
|
||||
db.AutoMigrate(model)
|
||||
db.Set("gorm:table_options", "CHARSET=utf8")
|
||||
db.Set("gorm:table_options", "collation=utf8_unicode_ci")
|
||||
|
@ -15,18 +15,20 @@ type Black struct {
|
||||
AddSource int32 `gorm:"column:add_source"`
|
||||
OperatorUserID string `gorm:"column:operator_user_id;size:64"`
|
||||
Ex string `gorm:"column:ex;size:1024"`
|
||||
db *gorm.DB `gorm:"-"`
|
||||
DB *gorm.DB `gorm:"-"`
|
||||
}
|
||||
|
||||
func NewBlack(db *gorm.DB) *Black {
|
||||
return &Black{db: db}
|
||||
var black Black
|
||||
black.DB = initModel(db, &black)
|
||||
return &black
|
||||
}
|
||||
|
||||
func (b *Black) Create(ctx context.Context, blacks []*Black) (err error) {
|
||||
defer func() {
|
||||
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "blacks", blacks)
|
||||
}()
|
||||
return utils.Wrap(b.db.Create(&blacks).Error, "")
|
||||
return utils.Wrap(b.DB.Create(&blacks).Error, "")
|
||||
}
|
||||
|
||||
func (b *Black) Delete(ctx context.Context, blacks []*Black) (err error) {
|
||||
@ -40,14 +42,14 @@ func (b *Black) UpdateByMap(ctx context.Context, ownerUserID, blockUserID string
|
||||
defer func() {
|
||||
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "ownerUserID", ownerUserID, "blockUserID", blockUserID, "args", args)
|
||||
}()
|
||||
return utils.Wrap(b.db.Where("block_user_id = ? and block_user_id = ?", ownerUserID, blockUserID).Updates(args).Error, "")
|
||||
return utils.Wrap(b.DB.Where("block_user_id = ? and block_user_id = ?", ownerUserID, blockUserID).Updates(args).Error, "")
|
||||
}
|
||||
|
||||
func (b *Black) Update(ctx context.Context, blacks []*Black) (err error) {
|
||||
defer func() {
|
||||
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "blacks", blacks)
|
||||
}()
|
||||
return utils.Wrap(b.db.Updates(&blacks).Error, "")
|
||||
return utils.Wrap(b.DB.Updates(&blacks).Error, "")
|
||||
}
|
||||
|
||||
func (b *Black) Find(ctx context.Context, blacks []Black) (blackList []*Black, err error) {
|
||||
@ -66,7 +68,7 @@ func (b *Black) Take(ctx context.Context, blackID string) (black *Black, err err
|
||||
defer func() {
|
||||
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "blackID", blackID, "black", *black)
|
||||
}()
|
||||
return black, utils.Wrap(b.db.Where("black_id = ?", blackID).Take(black).Error, "")
|
||||
return black, utils.Wrap(b.DB.Where("black_id = ?", blackID).Take(black).Error, "")
|
||||
}
|
||||
|
||||
func (b *Black) FindByOwnerUserID(ctx context.Context, ownerUserID string) (blackList []*Black, err error) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user