mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-08-30 18:49:50 +08:00
Merge remote-tracking branch 'origin/errcode' into errcode
This commit is contained in:
commit
12514a632d
@ -206,7 +206,33 @@ func (db *DBGroupRequest) convert() (*sdk.GroupRequest, error) {
|
||||
return dst, nil
|
||||
}
|
||||
|
||||
func UserOpenIMCopyDB(dst *imdb.User, src *open_im_sdk.UserInfo) {
|
||||
type DBUser struct {
|
||||
*imdb
|
||||
}
|
||||
|
||||
type PBUser struct {
|
||||
*sdk.UserInfo
|
||||
}
|
||||
|
||||
func (pb *PBUser) convert() (*DBUser, error) {
|
||||
dst := &DBUser{}
|
||||
utils.CopyStructFields(dst, pb)
|
||||
|
||||
utils.CopyStructFields(dst, src)
|
||||
dst.Birth, _ = utils.TimeStringToTime(src.BirthStr)
|
||||
dst.CreateTime = utils.UnixSecondToTime(int64(src.CreateTime))
|
||||
|
||||
return dst, nil
|
||||
}
|
||||
func (db *DBUser) convert() (*PBUser, error) {
|
||||
dst := &sdk.GroupRequest{}
|
||||
utils.CopyStructFields(dst, db)
|
||||
dst.ReqTime = uint32(db.ReqTime.Unix())
|
||||
dst.HandleTime = uint32(db.HandledTime.Unix())
|
||||
return dst, nil
|
||||
}
|
||||
|
||||
func UserOpenIMCopyDB(dst *imdb.User, src *sdk.UserInfo) {
|
||||
utils.CopyStructFields(dst, src)
|
||||
dst.Birth, _ = utils.TimeStringToTime(src.BirthStr)
|
||||
dst.CreateTime = utils.UnixSecondToTime(int64(src.CreateTime))
|
||||
|
23
pkg/common/db/model/user.go
Normal file
23
pkg/common/db/model/user.go
Normal file
@ -0,0 +1,23 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/db/mysql"
|
||||
"context"
|
||||
)
|
||||
|
||||
type UserModel struct {
|
||||
db *mysql.User
|
||||
}
|
||||
|
||||
func NewGroupUser(ctx context.Context) {
|
||||
var userModel UserModel
|
||||
userModel.db = mysql.NewUserDB()
|
||||
}
|
||||
|
||||
func (u *UserModel) Find(ctx context.Context, userIDs []string) (users []*mysql.User, err error) {
|
||||
return u.db.Find(ctx, userIDs)
|
||||
}
|
||||
|
||||
func (u *UserModel) Create(ctx context.Context, users []*mysql.User) error {
|
||||
return u.db.Create(ctx, users)
|
||||
}
|
@ -8,8 +8,6 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
var userDB *gorm.DB
|
||||
|
||||
type User struct {
|
||||
UserID string `gorm:"column:user_id;primary_key;size:64"`
|
||||
Nickname string `gorm:"column:name;size:255"`
|
||||
@ -23,44 +21,51 @@ type User struct {
|
||||
AppMangerLevel int32 `gorm:"column:app_manger_level"`
|
||||
GlobalRecvMsgOpt int32 `gorm:"column:global_recv_msg_opt"`
|
||||
|
||||
status int32 `gorm:"column:status"`
|
||||
status int32 `gorm:"column:status"`
|
||||
DB *gorm.DB `gorm:"-" json:"-"`
|
||||
}
|
||||
|
||||
func (*User) Create(ctx context.Context, users []*User) (err error) {
|
||||
func NewUserDB() *User {
|
||||
var user User
|
||||
user.DB = initMysqlDB(&user)
|
||||
return &user
|
||||
}
|
||||
|
||||
func (u *User) Create(ctx context.Context, users []*User) (err error) {
|
||||
defer func() {
|
||||
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "users", users)
|
||||
}()
|
||||
err = utils.Wrap(userDB.Create(&users).Error, "")
|
||||
err = utils.Wrap(u.DB.Create(&users).Error, "")
|
||||
return err
|
||||
}
|
||||
|
||||
func (*User) UpdateByMap(ctx context.Context, userID string, args map[string]interface{}) (err error) {
|
||||
func (u *User) UpdateByMap(ctx context.Context, userID string, args map[string]interface{}) (err error) {
|
||||
defer func() {
|
||||
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "userID", userID, "args", args)
|
||||
}()
|
||||
return utils.Wrap(userDB.Where("user_id = ?", userID).Updates(args).Error, "")
|
||||
return utils.Wrap(u.DB.Where("user_id = ?", userID).Updates(args).Error, "")
|
||||
}
|
||||
|
||||
func (*User) Update(ctx context.Context, users []*User) (err error) {
|
||||
func (u *User) Update(ctx context.Context, users []*User) (err error) {
|
||||
defer func() {
|
||||
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "users", users)
|
||||
}()
|
||||
return utils.Wrap(userDB.Updates(&users).Error, "")
|
||||
return utils.Wrap(u.DB.Updates(&users).Error, "")
|
||||
}
|
||||
|
||||
func (*User) Find(ctx context.Context, userIDs []string) (users []*User, err error) {
|
||||
func (u *User) Find(ctx context.Context, userIDs []string) (users []*User, err error) {
|
||||
defer func() {
|
||||
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "userIDs", userIDs, "users", users)
|
||||
}()
|
||||
err = utils.Wrap(userDB.Where("user_id in (?)", userIDs).Find(&users).Error, "")
|
||||
err = utils.Wrap(u.DB.Where("user_id in (?)", userIDs).Find(&users).Error, "")
|
||||
return users, err
|
||||
}
|
||||
|
||||
func (*User) Take(ctx context.Context, userID string) (user *User, err error) {
|
||||
func (u *User) Take(ctx context.Context, userID string) (user *User, err error) {
|
||||
user = &User{}
|
||||
defer func() {
|
||||
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "userID", userID, "user", *user)
|
||||
}()
|
||||
err = utils.Wrap(userDB.Where("user_id = ?", userID).Take(&user).Error, "")
|
||||
err = utils.Wrap(u.DB.Where("user_id = ?", userID).Take(&user).Error, "")
|
||||
return user, err
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user