Error code standardization

test-errcode
skiffer-git 2 years ago
parent ae40c8c8c0
commit 5751062605

@ -67,7 +67,7 @@ func (m *msgServer) sendMsgSingleChat(ctx context.Context, req *msg.SendMsgReq)
if err != nil {
return nil, err
}
isSend, err := modifyMessageByUserMessageReceiveOpt(req.MsgData.RecvID, req.MsgData.SendID, constant.SingleChatType, req)
isSend, err := m.modifyMessageByUserMessageReceiveOpt(ctx, req.MsgData.RecvID, req.MsgData.SendID, constant.SingleChatType, req)
if err != nil {
return nil, err
}

@ -4,6 +4,7 @@ import (
"Open_IM/internal/common/check"
"Open_IM/internal/common/convert"
"Open_IM/internal/common/notification"
"Open_IM/pkg/common/config"
"Open_IM/pkg/common/constant"
"Open_IM/pkg/common/db/controller"
"Open_IM/pkg/common/db/relation"
@ -36,12 +37,21 @@ func Start(client *openKeeper.ZkClient, server *grpc.Server) error {
if err := gormDB.AutoMigrate(&tablerelation.UserModel{}); err != nil {
return err
}
pbuser.RegisterUserServer(server, &userServer{
u := &userServer{
UserInterface: controller.NewUserController(controller.NewUserDatabase(relation.NewUserGorm(gormDB))),
notification: notification.NewCheck(client),
userCheck: check.NewUserCheck(client),
RegisterCenter: client,
})
}
pbuser.RegisterUserServer(server, u)
users := make([]*tablerelation.UserModel, 0)
if len(config.Config.Manager.AppManagerUid) != len(config.Config.Manager.Nickname) {
return constant.ErrConfig.Wrap("len(config.Config.Manager.AppManagerUid) != len(config.Config.Manager.Nickname)")
}
for k, v := range config.Config.Manager.AppManagerUid {
users = append(users, &tablerelation.UserModel{UserID: v, Nickname: config.Config.Manager.Nickname[k]})
}
u.UserInterface.InitOnce(context.Background(), users)
return nil
}

@ -214,8 +214,8 @@ type config struct {
}
Manager struct {
AppManagerUid []string `yaml:"appManagerUid"`
Secrets []string `yaml:"secrets"`
AppSysNotificationName string `yaml:"appSysNotificationName"`
// AppSysNotificationName string `yaml:"appSysNotificationName"`
Nickname []string `yaml:"nickname"`
}
Kafka struct {

@ -319,8 +319,4 @@ const BigVersion = "v2"
const LogFileName = "OpenIM.log"
const StatisticsTimeInterval = 60
const MaxNotificationNum = 500
const CurrentVersion = "v2.3.4-rc0"

@ -58,6 +58,8 @@ var (
ErrConnArgsErr = &ErrInfo{ConnArgsErr, "args err, need token, sendID, platformID", ""}
ErrConnUpdateErr = &ErrInfo{ConnArgsErr, "upgrade http conn err", ""}
ErrConfig = &ErrInfo{ConfigError, "ConfigError", ""}
)
const (
@ -91,6 +93,8 @@ const (
DataError = 90007 //数据错误
IdentityError = 90008 // 身份错误 非管理员token且token中userID与请求userID不一致
ConfigError = 90009
)
// 账号错误码

@ -2,4 +2,6 @@ package constant
const (
ShowNumber = 1000
StatisticsTimeInterval = 60
MaxNotificationNum = 500
)

@ -49,6 +49,8 @@ type MsgInterface interface {
SetGroupUserMinSeq(ctx context.Context, groupID, userID string, minSeq int64) (err error)
// 设置用户最小seq 直接调用cache
SetUserMinSeq(ctx context.Context, userID string, minSeq int64) (err error)
MsgToMQ(ctx context.Context, key string, data *pbMsg.MsgDataToMQ) (err error)
}
func NewMsgController(mgo *mongo.Client, rdb redis.UniversalClient) MsgInterface {

@ -3,6 +3,7 @@ package controller
import (
"Open_IM/pkg/common/constant"
"Open_IM/pkg/common/db/table/relation"
"Open_IM/pkg/utils"
"context"
)
@ -23,6 +24,8 @@ type UserInterface interface {
IsExist(ctx context.Context, userIDs []string) (exist bool, err error)
//获取所有用户ID
GetAllUserID(ctx context.Context) ([]string, error)
//函数内部先查询db中是否存在存在则什么都不做不存在则插入
InitOnce(ctx context.Context, users []*relation.UserModel) (err error)
}
type UserController struct {
@ -60,6 +63,10 @@ func (u *UserController) GetAllUserID(ctx context.Context) ([]string, error) {
return u.database.GetAllUserID(ctx)
}
func (u *UserController) InitOnce(ctx context.Context, users []*relation.UserModel) (err error) {
return u.database.InitOnce(ctx, users)
}
func NewUserController(database UserDatabaseInterface) UserInterface {
return &UserController{database}
}
@ -81,6 +88,8 @@ type UserDatabaseInterface interface {
IsExist(ctx context.Context, userIDs []string) (exist bool, err error)
//获取所有用户ID
GetAllUserID(ctx context.Context) ([]string, error)
//函数内部先查询db中是否存在存在则什么都不做不存在则插入
InitOnce(ctx context.Context, users []*relation.UserModel) (err error)
}
type UserDatabase struct {
@ -91,6 +100,17 @@ func NewUserDatabase(userDB relation.UserModelInterface) *UserDatabase {
return &UserDatabase{userDB: userDB}
}
func (u *UserDatabase) InitOnce(ctx context.Context, users []*relation.UserModel) (err error) {
userIDs := utils.Slice(users, func(e *relation.UserModel) string {
return e.UserID
})
result, err := u.userDB.Find(ctx, userIDs)
if err != nil {
return err
}
}
// 获取指定用户的信息 如有userID未找到 也返回错误
func (u *UserDatabase) FindWithError(ctx context.Context, userIDs []string) (users []*relation.UserModel, err error) {

@ -68,12 +68,3 @@ type Writer struct{}
func (w Writer) Printf(format string, args ...interface{}) {
fmt.Printf(format, args...)
}
//func getDBConn(db *gorm.DB, tx []any) *gorm.DB {
// if len(tx) > 0 {
// if txDB, ok := tx[0].(*gorm.DB); ok {
// return txDB
// }
// }
// return db
//}

@ -20,7 +20,7 @@ type UserModel struct {
Email string `gorm:"column:email;size:64"`
Ex string `gorm:"column:ex;size:1024"`
CreateTime time.Time `gorm:"column:create_time;index:create_time; autoCreateTime"`
AppMangerLevel int32 `gorm:"column:app_manger_level"`
AppMangerLevel int32 `gorm:"column:app_manger_level;default:18"`
GlobalRecvMsgOpt int32 `gorm:"column:global_recv_msg_opt"`
}

@ -5,6 +5,28 @@ import (
"sort"
)
// SliceSub a中存在,b中不存在 (a-b)
func SliceSub[E comparable](a, b []E) []E {
k := make(map[E]struct{})
for i := 0; i < len(b); i++ {
k[b[i]] = struct{}{}
}
t := make(map[E]struct{})
rs := make([]E, 0, len(a))
for i := 0; i < len(a); i++ {
e := a[i]
if _, ok := t[e]; ok {
continue
}
if _, ok := k[e]; ok {
continue
}
rs = append(rs, e)
t[e] = struct{}{}
}
return rs
}
// DistinctAny 去重
func DistinctAny[E any, K comparable](es []E, fn func(e E) K) []E {
v := make([]E, 0, len(es))

Loading…
Cancel
Save