This commit is contained in:
wangchuxiao 2022-02-14 00:02:15 +08:00
parent 52579c5fab
commit 7797e47561
6 changed files with 37 additions and 37 deletions

View File

@ -217,7 +217,7 @@ func (s *userServer) UpdateUserInfo(ctx context.Context, req *pbUser.UpdateUserI
return &pbUser.UpdateUserInfoResp{CommonResp: &pbUser.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}}, nil
}
var user db.Users
var user db.User
utils.CopyStructFields(&user, req.UserInfo)
if req.UserInfo.Birth != 0 {
user.Birth = utils.UnixSecondToTime(int64(req.UserInfo.Birth))
@ -267,7 +267,7 @@ func (s *userServer) GetUsersByName(ctx context.Context, req *pbUser.GetUsersByN
IsBlock: isBlock,
})
}
user := db.Users{Nickname:req.UserName}
user := db.User{Nickname: req.UserName}
userNums, err := imdb.GetUsersCount(user)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "", err.Error())
@ -324,14 +324,14 @@ func (s *userServer) GetUsers(ctx context.Context, req *pbUser.GetUsersReq) (*pb
resp.User = append(resp.User, user)
}
}
user := db.Users{}
user := db.User{}
nums, err := imdb.GetUsersCount(user)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUsersCount failed", err.Error())
return resp, errors.WrapError(constant.ErrDB)
}
resp.UserNums = nums
resp.Pagination = &sdkws.ResponsePagination{ShowNumber:req.Pagination.ShowNumber, CurrentPage:req.Pagination.PageNumber}
resp.Pagination = &sdkws.ResponsePagination{ShowNumber: req.Pagination.ShowNumber, CurrentPage: req.Pagination.PageNumber}
return resp, nil
}
@ -343,7 +343,7 @@ func (s *userServer) ResignUser(ctx context.Context, req *pbUser.ResignUserReq)
func (s *userServer) AlterUser(ctx context.Context, req *pbUser.AlterUserReq) (*pbUser.AlterUserResp, error) {
log.NewInfo(req.OperationID, "AlterUser args ", req.String())
resp := &pbUser.AlterUserResp{}
user := db.Users{
user := db.User{
PhoneNumber: strconv.FormatInt(req.PhoneNumber, 10),
Nickname: req.Nickname,
Email: req.Email,
@ -452,4 +452,3 @@ func (s *userServer) DeleteUser(_ context.Context, req *pbUser.DeleteUserReq) (*
}
return resp, nil
}

View File

@ -135,7 +135,7 @@ type GroupRequest struct {
//int64 CreateTime = 9;
//int32 AppMangerLevel = 10;
//open_im_sdk.User == imdb.User
type Users struct {
type User struct {
UserID string `gorm:"column:user_id;primary_key;size:64"`
Nickname string `gorm:"column:name;size:255"`
FaceURL string `gorm:"column:face_url;size:255"`
@ -186,7 +186,7 @@ type ChatLog struct {
}
type BlackList struct {
UserId string `gorm:"column:uid"`
UserId string `gorm:"column:uid"`
BeginDisableTime time.Time `gorm:"column:begin_disable_time"`
EndDisableTime time.Time `gorm:"column:end_disable_time"`
}
EndDisableTime time.Time `gorm:"column:end_disable_time"`
}

View File

@ -4,10 +4,11 @@ import (
"Open_IM/pkg/common/config"
"Open_IM/pkg/common/log"
"fmt"
"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/mysql"
"sync"
"time"
"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/mysql"
)
type mysqlDB struct {
@ -57,7 +58,7 @@ func initMysqlDB() {
&Group{},
&GroupMember{},
&GroupRequest{},
&Users{},
&User{},
&Black{}, &ChatLog{})
db.Set("gorm:table_options", "CHARSET=utf8")

View File

@ -143,10 +143,10 @@ func GetActiveUsers(from, to time.Time, limit int) ([]*activeUser, error) {
dbConn.LogMode(true)
err = dbConn.Table("chat_logs").Select("send_id, count(*) as message_num").Where("create_time >= ? and create_time <= ? and session_type = ?", from, to, 1).Group("send_id").Limit(limit).Order("message_num DESC").Find(&activeUsers).Error
for _, activeUser := range activeUsers {
user := db.Users{
user := db.User{
UserID: activeUser.Id,
}
dbConn.Model(&user).Select("user_id, name").Find(&user)
dbConn.Table("users").Select("user_id, name").Find(&user)
activeUser.Name = user.Nickname
}
return activeUsers, err

View File

@ -20,7 +20,7 @@ func init() {
} else {
continue
}
var appMgr db.Users
var appMgr db.User
appMgr.UserID = v
appMgr.Nickname = "AppManager" + utils.IntToString(k+1)
appMgr.AppMangerLevel = constant.AppAdmin
@ -32,7 +32,7 @@ func init() {
}
}
func UserRegister(user db.Users) error {
func UserRegister(user db.User) error {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return err
@ -68,16 +68,16 @@ func DeleteUser(userID string) (i int64) {
if err != nil {
return 0
}
i = dbConn.Table("users").Where("user_id=?", userID).Delete(db.Users{}).RowsAffected
i = dbConn.Table("users").Where("user_id=?", userID).Delete(db.User{}).RowsAffected
return i
}
func GetUserByUserID(userID string) (*db.Users, error) {
func GetUserByUserID(userID string) (*db.User, error) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return nil, err
}
var user db.Users
var user db.User
err = dbConn.Table("users").Where("user_id=?", userID).First(&user).Error
if err != nil {
return nil, err
@ -85,7 +85,7 @@ func GetUserByUserID(userID string) (*db.Users, error) {
return &user, nil
}
func UpdateUserInfo(user db.Users) error {
func UpdateUserInfo(user db.User) error {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return err
@ -123,14 +123,14 @@ func SelectSomeUserID(userIDList []string) ([]string, error) {
return resultArr, nil
}
func GetUsers(showNumber, pageNumber int32) ([]db.Users, error) {
func GetUsers(showNumber, pageNumber int32) ([]db.User, error) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
var users []db.Users
var users []db.User
if err != nil {
return users, err
}
dbConn.LogMode(true)
err = dbConn.Limit(showNumber).Offset(showNumber * (pageNumber - 1)).Find(&users).Error
err = dbConn.Table("users").Limit(showNumber).Offset(showNumber * (pageNumber - 1)).Find(&users).Error
if err != nil {
return users, err
}
@ -142,14 +142,14 @@ func AddUser(userId, phoneNumber, name string) error {
if err != nil {
return err
}
user := db.Users{
user := db.User{
PhoneNumber: phoneNumber,
Birth: time.Now(),
CreateTime: time.Now(),
UserID: userId,
Nickname: name,
}
result := dbConn.Create(&user)
result := dbConn.Table("users").Create(&user)
return result.Error
}
@ -208,7 +208,7 @@ func UnBlockUser(userId string) error {
}
type BlockUserInfo struct {
User db.Users
User db.User
BeginDisableTime time.Time
EndDisableTime time.Time
}
@ -225,7 +225,7 @@ func GetBlockUserById(userId string) (BlockUserInfo, error) {
if err = dbConn.Table("black_lists").Where("uid=?", userId).Find(&blockUser).Error; err != nil {
return blockUserInfo, err
}
user := db.Users{
user := db.User{
UserID: blockUser.UserId,
}
if err := dbConn.Find(&user).Error; err != nil {
@ -251,10 +251,10 @@ func GetBlockUsers(showNumber, pageNumber int32) ([]BlockUserInfo, error) {
return blockUserInfos, err
}
for _, blockUser := range blockUsers {
var user db.Users
var user db.User
if err := dbConn.Table("users").Where("user_id=?", blockUser.UserId).First(&user).Error; err == nil {
blockUserInfos = append(blockUserInfos, BlockUserInfo{
User: db.Users{
User: db.User{
UserID: user.UserID,
Nickname: user.Nickname,
FaceURL: user.FaceURL,
@ -267,9 +267,9 @@ func GetBlockUsers(showNumber, pageNumber int32) ([]BlockUserInfo, error) {
return blockUserInfos, nil
}
func GetUserByName(userName string, showNumber, pageNumber int32) ([]db.Users, error) {
func GetUserByName(userName string, showNumber, pageNumber int32) ([]db.User, error) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
var users []db.Users
var users []db.User
if err != nil {
return users, err
}
@ -278,14 +278,14 @@ func GetUserByName(userName string, showNumber, pageNumber int32) ([]db.Users, e
return users, err
}
func GetUsersCount(user db.Users) (int32, error) {
func GetUsersCount(user db.User) (int32, error) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return 0, err
}
dbConn.LogMode(true)
var count int32
if err := dbConn.Model(user).Where(fmt.Sprintf(" name like '%%%s%%' ", user.Nickname)).Count(&count).Error; err != nil {
if err := dbConn.Table("users").Where(fmt.Sprintf(" name like '%%%s%%' ", user.Nickname)).Count(&count).Error; err != nil {
return 0, err
}
return count, nil

View File

@ -128,19 +128,19 @@ func GroupRequestDBCopyOpenIM(dst *open_im_sdk.GroupRequest, src *db.GroupReques
dst.HandleTime = uint32(src.HandledTime.Unix())
}
func UserOpenIMCopyDB(dst *db.Users, src *open_im_sdk.UserInfo) {
func UserOpenIMCopyDB(dst *db.User, src *open_im_sdk.UserInfo) {
utils.CopyStructFields(dst, src)
dst.Birth = utils.UnixSecondToTime(int64(src.Birth))
dst.CreateTime = utils.UnixSecondToTime(int64(src.CreateTime))
}
func UserDBCopyOpenIM(dst *open_im_sdk.UserInfo, src *db.Users) {
func UserDBCopyOpenIM(dst *open_im_sdk.UserInfo, src *db.User) {
utils.CopyStructFields(dst, src)
dst.CreateTime = uint32(src.CreateTime.Unix())
dst.Birth = uint32(src.Birth.Unix())
}
func UserDBCopyOpenIMPublicUser(dst *open_im_sdk.PublicUserInfo, src *db.Users) {
func UserDBCopyOpenIMPublicUser(dst *open_im_sdk.PublicUserInfo, src *db.User) {
utils.CopyStructFields(dst, src)
}