mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-12-05 03:52:15 +08:00
third
This commit is contained in:
parent
050ad7fa70
commit
358f70895d
@ -120,7 +120,7 @@ func (t *thirdServer) SearchLogs(ctx context.Context, req *third.SearchLogsReq)
|
|||||||
if req.StartTime > req.EndTime {
|
if req.StartTime > req.EndTime {
|
||||||
return nil, errs.ErrArgs.Wrap("startTime>endTime")
|
return nil, errs.ErrArgs.Wrap("startTime>endTime")
|
||||||
}
|
}
|
||||||
total, logs, err := t.thirdDatabase.SearchLogs(ctx, req.Keyword, time.UnixMilli(req.StartTime), time.UnixMilli(req.EndTime), req.Pagination.PageNumber, req.Pagination.ShowNumber)
|
total, logs, err := t.thirdDatabase.SearchLogs(ctx, req.Keyword, time.UnixMilli(req.StartTime), time.UnixMilli(req.EndTime), req.Pagination)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -128,18 +128,16 @@ func (t *thirdServer) SearchLogs(ctx context.Context, req *third.SearchLogsReq)
|
|||||||
for _, log := range logs {
|
for _, log := range logs {
|
||||||
userIDs = append(userIDs, log.UserID)
|
userIDs = append(userIDs, log.UserID)
|
||||||
}
|
}
|
||||||
users, err := t.thirdDatabase.FindUsers(ctx, userIDs)
|
userMap, err := t.userRpcClient.GetUsersInfoMap(ctx, userIDs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
IDtoName := make(map[string]string)
|
|
||||||
for _, user := range users {
|
|
||||||
IDtoName[user.UserID] = user.Nickname
|
|
||||||
}
|
|
||||||
for _, pbLog := range pbLogs {
|
for _, pbLog := range pbLogs {
|
||||||
pbLog.Nickname = IDtoName[pbLog.UserID]
|
if user, ok := userMap[pbLog.UserID]; ok {
|
||||||
|
pbLog.Nickname = user.Nickname
|
||||||
|
}
|
||||||
}
|
}
|
||||||
resp.LogsInfos = pbLogs
|
resp.LogsInfos = pbLogs
|
||||||
resp.Total = total
|
resp.Total = uint32(total)
|
||||||
return &resp, nil
|
return &resp, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@ -64,7 +64,7 @@ func (t *thirdServer) InitiateMultipartUpload(ctx context.Context, req *third.In
|
|||||||
Key: haErr.Object.Key,
|
Key: haErr.Object.Key,
|
||||||
Size: haErr.Object.Size,
|
Size: haErr.Object.Size,
|
||||||
ContentType: req.ContentType,
|
ContentType: req.ContentType,
|
||||||
Cause: req.Cause,
|
Group: req.Cause,
|
||||||
CreateTime: time.Now(),
|
CreateTime: time.Now(),
|
||||||
}
|
}
|
||||||
if err := t.s3dataBase.SetObject(ctx, obj); err != nil {
|
if err := t.s3dataBase.SetObject(ctx, obj); err != nil {
|
||||||
@ -143,7 +143,7 @@ func (t *thirdServer) CompleteMultipartUpload(ctx context.Context, req *third.Co
|
|||||||
Key: result.Key,
|
Key: result.Key,
|
||||||
Size: result.Size,
|
Size: result.Size,
|
||||||
ContentType: req.ContentType,
|
ContentType: req.ContentType,
|
||||||
Cause: req.Cause,
|
Group: req.Cause,
|
||||||
CreateTime: time.Now(),
|
CreateTime: time.Now(),
|
||||||
}
|
}
|
||||||
if err := t.s3dataBase.SetObject(ctx, obj); err != nil {
|
if err := t.s3dataBase.SetObject(ctx, obj); err != nil {
|
||||||
|
|||||||
@ -17,6 +17,8 @@ package third
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/openimsdk/open-im-server/v3/pkg/common/db/newmgo"
|
||||||
|
"github.com/openimsdk/open-im-server/v3/pkg/common/db/unrelation"
|
||||||
"net/url"
|
"net/url"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -33,13 +35,22 @@ import (
|
|||||||
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/common/db/cache"
|
"github.com/openimsdk/open-im-server/v3/pkg/common/db/cache"
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/common/db/controller"
|
"github.com/openimsdk/open-im-server/v3/pkg/common/db/controller"
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/common/db/relation"
|
|
||||||
relationtb "github.com/openimsdk/open-im-server/v3/pkg/common/db/table/relation"
|
|
||||||
|
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/rpcclient"
|
"github.com/openimsdk/open-im-server/v3/pkg/rpcclient"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Start(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) error {
|
func Start(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) error {
|
||||||
|
mongo, err := unrelation.NewMongo()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
logdb, err := newmgo.NewLogMongo(mongo.GetDatabase())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
s3db, err := newmgo.NewS3Mongo(mongo.GetDatabase())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
apiURL := config.Config.Object.ApiURL
|
apiURL := config.Config.Object.ApiURL
|
||||||
if apiURL == "" {
|
if apiURL == "" {
|
||||||
return fmt.Errorf("api url is empty")
|
return fmt.Errorf("api url is empty")
|
||||||
@ -55,13 +66,6 @@ func Start(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) e
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
db, err := relation.NewGormDB()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := db.AutoMigrate(&relationtb.ObjectModel{}); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
// 根据配置文件策略选择 oss 方式
|
// 根据配置文件策略选择 oss 方式
|
||||||
enable := config.Config.Object.Enable
|
enable := config.Config.Object.Enable
|
||||||
var o s3.Interface
|
var o s3.Interface
|
||||||
@ -78,17 +82,11 @@ func Start(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) e
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
//specialerror.AddErrHandler(func(err error) errs.CodeError {
|
|
||||||
// if o.IsNotFound(err) {
|
|
||||||
// return errs.ErrRecordNotFound
|
|
||||||
// }
|
|
||||||
// return nil
|
|
||||||
//})
|
|
||||||
third.RegisterThirdServer(server, &thirdServer{
|
third.RegisterThirdServer(server, &thirdServer{
|
||||||
apiURL: apiURL,
|
apiURL: apiURL,
|
||||||
thirdDatabase: controller.NewThirdDatabase(cache.NewMsgCacheModel(rdb), db),
|
thirdDatabase: controller.NewThirdDatabase(cache.NewMsgCacheModel(rdb), logdb),
|
||||||
userRpcClient: rpcclient.NewUserRpcClient(client),
|
userRpcClient: rpcclient.NewUserRpcClient(client),
|
||||||
s3dataBase: controller.NewS3Database(rdb, o, relation.NewObjectInfo(db)),
|
s3dataBase: controller.NewS3Database(rdb, o, s3db),
|
||||||
defaultExpire: time.Hour * 24 * 7,
|
defaultExpire: time.Hour * 24 * 7,
|
||||||
})
|
})
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@ -78,7 +78,10 @@ func Start(client registry.SvcDiscoveryRegistry, server *grpc.Server) error {
|
|||||||
for k, v := range config.Config.Manager.UserID {
|
for k, v := range config.Config.Manager.UserID {
|
||||||
users = append(users, &tablerelation.UserModel{UserID: v, Nickname: config.Config.Manager.Nickname[k], AppMangerLevel: constant.AppAdmin})
|
users = append(users, &tablerelation.UserModel{UserID: v, Nickname: config.Config.Manager.Nickname[k], AppMangerLevel: constant.AppAdmin})
|
||||||
}
|
}
|
||||||
userDB := newmgo.NewUserMongo(mongo.GetDatabase())
|
userDB, err := newmgo.NewUserMongo(mongo.GetDatabase())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
cache := cache.NewUserCacheRedis(rdb, userDB, cache.GetDefaultOpt())
|
cache := cache.NewUserCacheRedis(rdb, userDB, cache.GetDefaultOpt())
|
||||||
userMongoDB := unrelation.NewUserMongoDriver(mongo.GetDatabase())
|
userMongoDB := unrelation.NewUserMongoDriver(mongo.GetDatabase())
|
||||||
database := controller.NewUserDatabase(userDB, cache, tx.NewMongo(mongo.GetClient()), userMongoDB)
|
database := controller.NewUserDatabase(userDB, cache, tx.NewMongo(mongo.GetClient()), userMongoDB)
|
||||||
|
|||||||
18
pkg/common/db/cache/s3.go
vendored
18
pkg/common/db/cache/s3.go
vendored
@ -14,8 +14,8 @@ import (
|
|||||||
|
|
||||||
type ObjectCache interface {
|
type ObjectCache interface {
|
||||||
metaCache
|
metaCache
|
||||||
GetName(ctx context.Context, name string) (*relationtb.ObjectModel, error)
|
GetName(ctx context.Context, engine string, name string) (*relationtb.ObjectModel, error)
|
||||||
DelObjectName(names ...string) ObjectCache
|
DelObjectName(engine string, names ...string) ObjectCache
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewObjectCacheRedis(rdb redis.UniversalClient, objDB relationtb.ObjectInfoModelInterface) ObjectCache {
|
func NewObjectCacheRedis(rdb redis.UniversalClient, objDB relationtb.ObjectInfoModelInterface) ObjectCache {
|
||||||
@ -44,23 +44,23 @@ func (g *objectCacheRedis) NewCache() ObjectCache {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *objectCacheRedis) DelObjectName(names ...string) ObjectCache {
|
func (g *objectCacheRedis) DelObjectName(engine string, names ...string) ObjectCache {
|
||||||
objectCache := g.NewCache()
|
objectCache := g.NewCache()
|
||||||
keys := make([]string, 0, len(names))
|
keys := make([]string, 0, len(names))
|
||||||
for _, name := range names {
|
for _, name := range names {
|
||||||
keys = append(keys, g.getObjectKey(name))
|
keys = append(keys, g.getObjectKey(name, engine))
|
||||||
}
|
}
|
||||||
objectCache.AddKeys(keys...)
|
objectCache.AddKeys(keys...)
|
||||||
return objectCache
|
return objectCache
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *objectCacheRedis) getObjectKey(name string) string {
|
func (g *objectCacheRedis) getObjectKey(engine string, name string) string {
|
||||||
return "OBJECT:" + name
|
return "OBJECT:" + engine + ":" + name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *objectCacheRedis) GetName(ctx context.Context, name string) (*relationtb.ObjectModel, error) {
|
func (g *objectCacheRedis) GetName(ctx context.Context, engine string, name string) (*relationtb.ObjectModel, error) {
|
||||||
return getCache(ctx, g.rcClient, g.getObjectKey(name), g.expireTime, func(ctx context.Context) (*relationtb.ObjectModel, error) {
|
return getCache(ctx, g.rcClient, g.getObjectKey(name, engine), g.expireTime, func(ctx context.Context) (*relationtb.ObjectModel, error) {
|
||||||
return g.objDB.Take(ctx, name)
|
return g.objDB.Take(ctx, engine, name)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -79,7 +79,7 @@ func (s *s3Database) SetObject(ctx context.Context, info *relation.ObjectModel)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *s3Database) AccessURL(ctx context.Context, name string, expire time.Duration, opt *s3.AccessURLOption) (time.Time, string, error) {
|
func (s *s3Database) AccessURL(ctx context.Context, name string, expire time.Duration, opt *s3.AccessURLOption) (time.Time, string, error) {
|
||||||
obj, err := s.cache.GetName(ctx, name)
|
obj, err := s.cache.GetName(ctx, s.s3.Engine(), name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return time.Time{}, "", err
|
return time.Time{}, "", err
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,12 +16,10 @@ package controller
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"github.com/openimsdk/open-im-server/v3/pkg/common/pagination"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"gorm.io/gorm"
|
|
||||||
|
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/common/db/cache"
|
"github.com/openimsdk/open-im-server/v3/pkg/common/db/cache"
|
||||||
dbimpl "github.com/openimsdk/open-im-server/v3/pkg/common/db/relation"
|
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/common/db/table/relation"
|
"github.com/openimsdk/open-im-server/v3/pkg/common/db/table/relation"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -31,20 +29,13 @@ type ThirdDatabase interface {
|
|||||||
// about log for debug
|
// about log for debug
|
||||||
UploadLogs(ctx context.Context, logs []*relation.Log) error
|
UploadLogs(ctx context.Context, logs []*relation.Log) error
|
||||||
DeleteLogs(ctx context.Context, logID []string, userID string) error
|
DeleteLogs(ctx context.Context, logID []string, userID string) error
|
||||||
SearchLogs(ctx context.Context, keyword string, start time.Time, end time.Time, pageNumber int32, showNumber int32) (uint32, []*relation.Log, error)
|
SearchLogs(ctx context.Context, keyword string, start time.Time, end time.Time, pagination pagination.Pagination) (int64, []*relation.Log, error)
|
||||||
GetLogs(ctx context.Context, LogIDs []string, userID string) ([]*relation.Log, error)
|
GetLogs(ctx context.Context, LogIDs []string, userID string) ([]*relation.Log, error)
|
||||||
FindUsers(ctx context.Context, userIDs []string) ([]*relation.UserModel, error)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type thirdDatabase struct {
|
type thirdDatabase struct {
|
||||||
cache cache.MsgModel
|
cache cache.MsgModel
|
||||||
logdb relation.LogInterface
|
logdb relation.LogInterface
|
||||||
userdb relation.UserModelInterface
|
|
||||||
}
|
|
||||||
|
|
||||||
// FindUsers implements ThirdDatabase.
|
|
||||||
func (t *thirdDatabase) FindUsers(ctx context.Context, userIDs []string) ([]*relation.UserModel, error) {
|
|
||||||
return t.userdb.Find(ctx, userIDs)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteLogs implements ThirdDatabase.
|
// DeleteLogs implements ThirdDatabase.
|
||||||
@ -58,8 +49,8 @@ func (t *thirdDatabase) GetLogs(ctx context.Context, LogIDs []string, userID str
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SearchLogs implements ThirdDatabase.
|
// SearchLogs implements ThirdDatabase.
|
||||||
func (t *thirdDatabase) SearchLogs(ctx context.Context, keyword string, start time.Time, end time.Time, pageNumber int32, showNumber int32) (uint32, []*relation.Log, error) {
|
func (t *thirdDatabase) SearchLogs(ctx context.Context, keyword string, start time.Time, end time.Time, pagination pagination.Pagination) (int64, []*relation.Log, error) {
|
||||||
return t.logdb.Search(ctx, keyword, start, end, pageNumber, showNumber)
|
return t.logdb.Search(ctx, keyword, start, end, pagination)
|
||||||
}
|
}
|
||||||
|
|
||||||
// UploadLogs implements ThirdDatabase.
|
// UploadLogs implements ThirdDatabase.
|
||||||
@ -67,8 +58,8 @@ func (t *thirdDatabase) UploadLogs(ctx context.Context, logs []*relation.Log) er
|
|||||||
return t.logdb.Create(ctx, logs)
|
return t.logdb.Create(ctx, logs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewThirdDatabase(cache cache.MsgModel, db *gorm.DB) ThirdDatabase {
|
func NewThirdDatabase(cache cache.MsgModel, logdb relation.LogInterface) ThirdDatabase {
|
||||||
return &thirdDatabase{cache: cache, logdb: dbimpl.NewLogGorm(db), userdb: dbimpl.NewUserGorm(db)}
|
return &thirdDatabase{cache: cache, logdb: logdb}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *thirdDatabase) FcmUpdateToken(
|
func (t *thirdDatabase) FcmUpdateToken(
|
||||||
|
|||||||
@ -17,8 +17,8 @@ package controller
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"github.com/OpenIMSDK/tools/tx"
|
"github.com/OpenIMSDK/tools/tx"
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/common/db/newmgo/mgotool"
|
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/common/db/table/relation"
|
"github.com/openimsdk/open-im-server/v3/pkg/common/db/table/relation"
|
||||||
|
"github.com/openimsdk/open-im-server/v3/pkg/common/pagination"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/OpenIMSDK/protocol/user"
|
"github.com/OpenIMSDK/protocol/user"
|
||||||
@ -43,11 +43,11 @@ type UserDatabase interface {
|
|||||||
// UpdateByMap update (zero value) external guarantee userID exists
|
// UpdateByMap update (zero value) external guarantee userID exists
|
||||||
UpdateByMap(ctx context.Context, userID string, args map[string]any) (err error)
|
UpdateByMap(ctx context.Context, userID string, args map[string]any) (err error)
|
||||||
// Page If not found, no error is returned
|
// Page If not found, no error is returned
|
||||||
Page(ctx context.Context, pagination mgotool.Pagination) (count int64, users []*relation.UserModel, err error)
|
Page(ctx context.Context, pagination pagination.Pagination) (count int64, users []*relation.UserModel, err error)
|
||||||
// IsExist true as long as one exists
|
// IsExist true as long as one exists
|
||||||
IsExist(ctx context.Context, userIDs []string) (exist bool, err error)
|
IsExist(ctx context.Context, userIDs []string) (exist bool, err error)
|
||||||
// GetAllUserID Get all user IDs
|
// GetAllUserID Get all user IDs
|
||||||
GetAllUserID(ctx context.Context, pagination mgotool.Pagination) (int64, []string, error)
|
GetAllUserID(ctx context.Context, pagination pagination.Pagination) (int64, []string, error)
|
||||||
// InitOnce Inside the function, first query whether it exists in the db, if it exists, do nothing; if it does not exist, insert it
|
// InitOnce Inside the function, first query whether it exists in the db, if it exists, do nothing; if it does not exist, insert it
|
||||||
InitOnce(ctx context.Context, users []*relation.UserModel) (err error)
|
InitOnce(ctx context.Context, users []*relation.UserModel) (err error)
|
||||||
// CountTotal Get the total number of users
|
// CountTotal Get the total number of users
|
||||||
@ -142,7 +142,7 @@ func (u *userDatabase) UpdateByMap(ctx context.Context, userID string, args map[
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Page Gets, returns no error if not found.
|
// Page Gets, returns no error if not found.
|
||||||
func (u *userDatabase) Page(ctx context.Context, pagination mgotool.Pagination) (count int64, users []*relation.UserModel, err error) {
|
func (u *userDatabase) Page(ctx context.Context, pagination pagination.Pagination) (count int64, users []*relation.UserModel, err error) {
|
||||||
return u.userDB.Page(ctx, pagination)
|
return u.userDB.Page(ctx, pagination)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -159,7 +159,7 @@ func (u *userDatabase) IsExist(ctx context.Context, userIDs []string) (exist boo
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetAllUserID Get all user IDs.
|
// GetAllUserID Get all user IDs.
|
||||||
func (u *userDatabase) GetAllUserID(ctx context.Context, pagination mgotool.Pagination) (total int64, userIDs []string, err error) {
|
func (u *userDatabase) GetAllUserID(ctx context.Context, pagination pagination.Pagination) (total int64, userIDs []string, err error) {
|
||||||
return u.userDB.GetAllUserID(ctx, pagination)
|
return u.userDB.GetAllUserID(ctx, pagination)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
49
pkg/common/db/newmgo/log.go
Normal file
49
pkg/common/db/newmgo/log.go
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
package newmgo
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"github.com/openimsdk/open-im-server/v3/pkg/common/db/newmgo/mgotool"
|
||||||
|
"github.com/openimsdk/open-im-server/v3/pkg/common/db/table/relation"
|
||||||
|
"github.com/openimsdk/open-im-server/v3/pkg/common/pagination"
|
||||||
|
"go.mongodb.org/mongo-driver/bson"
|
||||||
|
"go.mongodb.org/mongo-driver/mongo"
|
||||||
|
"go.mongodb.org/mongo-driver/mongo/options"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func NewLogMongo(db *mongo.Database) (relation.LogInterface, error) {
|
||||||
|
lm := &LogMgo{
|
||||||
|
coll: db.Collection("log"),
|
||||||
|
}
|
||||||
|
return lm, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type LogMgo struct {
|
||||||
|
coll *mongo.Collection
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *LogMgo) Create(ctx context.Context, log []*relation.Log) error {
|
||||||
|
return mgotool.InsertMany(ctx, l.coll, log)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *LogMgo) Search(ctx context.Context, keyword string, start time.Time, end time.Time, pagination pagination.Pagination) (int64, []*relation.Log, error) {
|
||||||
|
filter := bson.M{"create_time": bson.M{"$gte": start, "$lte": end}}
|
||||||
|
if keyword != "" {
|
||||||
|
filter["user_id"] = bson.M{"$regex": keyword}
|
||||||
|
}
|
||||||
|
return mgotool.FindPage[*relation.Log](ctx, l.coll, filter, pagination, options.Find().SetSort(bson.M{"create_time": -1}))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *LogMgo) Delete(ctx context.Context, logID []string, userID string) error {
|
||||||
|
if userID == "" {
|
||||||
|
return mgotool.DeleteMany(ctx, l.coll, bson.M{"log_id": bson.M{"$in": logID}})
|
||||||
|
}
|
||||||
|
return mgotool.DeleteMany(ctx, l.coll, bson.M{"log_id": bson.M{"$in": logID}, "user_id": userID})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *LogMgo) Get(ctx context.Context, logIDs []string, userID string) ([]*relation.Log, error) {
|
||||||
|
if userID == "" {
|
||||||
|
return mgotool.Find[*relation.Log](ctx, l.coll, bson.M{"log_id": bson.M{"$in": logIDs}})
|
||||||
|
}
|
||||||
|
return mgotool.Find[*relation.Log](ctx, l.coll, bson.M{"log_id": bson.M{"$in": logIDs}, "user_id": userID})
|
||||||
|
}
|
||||||
@ -3,15 +3,11 @@ package mgotool
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"github.com/OpenIMSDK/tools/errs"
|
"github.com/OpenIMSDK/tools/errs"
|
||||||
|
"github.com/openimsdk/open-im-server/v3/pkg/common/pagination"
|
||||||
"go.mongodb.org/mongo-driver/mongo"
|
"go.mongodb.org/mongo-driver/mongo"
|
||||||
"go.mongodb.org/mongo-driver/mongo/options"
|
"go.mongodb.org/mongo-driver/mongo/options"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Pagination interface {
|
|
||||||
GetPageNumber() int32
|
|
||||||
GetShowNumber() int32
|
|
||||||
}
|
|
||||||
|
|
||||||
func Anys[T any](ts []T) []any {
|
func Anys[T any](ts []T) []any {
|
||||||
val := make([]any, len(ts))
|
val := make([]any, len(ts))
|
||||||
for i := range ts {
|
for i := range ts {
|
||||||
@ -20,6 +16,19 @@ func Anys[T any](ts []T) []any {
|
|||||||
return val
|
return val
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func findOptionToCountOption(opts []*options.FindOptions) *options.CountOptions {
|
||||||
|
countOpt := options.Count()
|
||||||
|
for _, opt := range opts {
|
||||||
|
if opt.Skip != nil {
|
||||||
|
countOpt.SetSkip(*opt.Skip)
|
||||||
|
}
|
||||||
|
if opt.Limit != nil {
|
||||||
|
countOpt.SetLimit(*opt.Limit)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return countOpt
|
||||||
|
}
|
||||||
|
|
||||||
func InsertMany[T any](ctx context.Context, coll *mongo.Collection, val []T, opts ...*options.InsertManyOptions) error {
|
func InsertMany[T any](ctx context.Context, coll *mongo.Collection, val []T, opts ...*options.InsertManyOptions) error {
|
||||||
_, err := coll.InsertMany(ctx, Anys(val), opts...)
|
_, err := coll.InsertMany(ctx, Anys(val), opts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -63,17 +72,8 @@ func FindOne[T any](ctx context.Context, coll *mongo.Collection, filter any, opt
|
|||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func FindPage[T any](ctx context.Context, coll *mongo.Collection, filter any, pagination Pagination, opts ...*options.FindOptions) (int64, []T, error) {
|
func FindPage[T any](ctx context.Context, coll *mongo.Collection, filter any, pagination pagination.Pagination, opts ...*options.FindOptions) (int64, []T, error) {
|
||||||
countOpt := options.Count()
|
count, err := Count(ctx, coll, filter, findOptionToCountOption(opts))
|
||||||
for _, opt := range opts {
|
|
||||||
if opt.Skip != nil {
|
|
||||||
countOpt.SetSkip(*opt.Skip)
|
|
||||||
}
|
|
||||||
if opt.Limit != nil {
|
|
||||||
countOpt.SetLimit(*opt.Limit)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
count, err := Count(ctx, coll, filter, countOpt)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, nil, err
|
return 0, nil, err
|
||||||
}
|
}
|
||||||
@ -104,3 +104,21 @@ func Exist(ctx context.Context, coll *mongo.Collection, filter any, opts ...*opt
|
|||||||
}
|
}
|
||||||
return count > 0, nil
|
return count > 0, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func DeleteOne(ctx context.Context, coll *mongo.Collection, filter any, opts ...*options.DeleteOptions) error {
|
||||||
|
if _, err := coll.DeleteOne(ctx, filter, opts...); err != nil {
|
||||||
|
return errs.Wrap(err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func DeleteMany(ctx context.Context, coll *mongo.Collection, filter any, opts ...*options.DeleteOptions) error {
|
||||||
|
if _, err := coll.DeleteMany(ctx, filter, opts...); err != nil {
|
||||||
|
return errs.Wrap(err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
//func Upsert[T any](ctx context.Context, coll *mongo.Collection, val *T, opts ...*options.InsertManyOptions) error {
|
||||||
|
// return nil
|
||||||
|
//}
|
||||||
|
|||||||
45
pkg/common/db/newmgo/object.go
Normal file
45
pkg/common/db/newmgo/object.go
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
package newmgo
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"github.com/openimsdk/open-im-server/v3/pkg/common/db/newmgo/mgotool"
|
||||||
|
"github.com/openimsdk/open-im-server/v3/pkg/common/db/table/relation"
|
||||||
|
"go.mongodb.org/mongo-driver/bson"
|
||||||
|
"go.mongodb.org/mongo-driver/mongo"
|
||||||
|
"go.mongodb.org/mongo-driver/mongo/options"
|
||||||
|
)
|
||||||
|
|
||||||
|
func NewS3Mongo(db *mongo.Database) (relation.ObjectInfoModelInterface, error) {
|
||||||
|
return &S3Mongo{
|
||||||
|
coll: db.Collection("s3"),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type S3Mongo struct {
|
||||||
|
coll *mongo.Collection
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o *S3Mongo) SetObject(ctx context.Context, obj *relation.ObjectModel) error {
|
||||||
|
filter := bson.M{"name": obj.Name, "engine": obj.Engine}
|
||||||
|
update := bson.M{
|
||||||
|
"name": obj.Name,
|
||||||
|
"engine": obj.Engine,
|
||||||
|
"key": obj.Key,
|
||||||
|
"size": obj.Size,
|
||||||
|
"content_type": obj.ContentType,
|
||||||
|
"group": obj.Group,
|
||||||
|
"create_time": obj.CreateTime,
|
||||||
|
}
|
||||||
|
return mgotool.UpdateOne(ctx, o.coll, filter, bson.M{"$set": update}, false, options.Update().SetUpsert(true))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o *S3Mongo) Take(ctx context.Context, engine string, name string) (*relation.ObjectModel, error) {
|
||||||
|
if engine == "" {
|
||||||
|
return mgotool.FindOne[*relation.ObjectModel](ctx, o.coll, bson.M{"name": name})
|
||||||
|
}
|
||||||
|
return mgotool.FindOne[*relation.ObjectModel](ctx, o.coll, bson.M{"name": name, "engine": engine})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o *S3Mongo) Delete(ctx context.Context, engine string, name string) error {
|
||||||
|
return mgotool.DeleteOne(ctx, o.coll, bson.M{"name": name, "engine": engine})
|
||||||
|
}
|
||||||
@ -1,32 +0,0 @@
|
|||||||
package newmgo
|
|
||||||
|
|
||||||
//import (
|
|
||||||
// "context"
|
|
||||||
// "github.com/openimsdk/open-im-server/v3/pkg/common/db/newmgo/mgotool"
|
|
||||||
// "time"
|
|
||||||
//)
|
|
||||||
//
|
|
||||||
//type UserModel struct {
|
|
||||||
// UserID string `bson:"user_id"`
|
|
||||||
// Nickname string `bson:"nickname"`
|
|
||||||
// FaceURL string `bson:"face_url"`
|
|
||||||
// Ex string `bson:"ex"`
|
|
||||||
// AppMangerLevel int32 `bson:"app_manger_level"`
|
|
||||||
// GlobalRecvMsgOpt int32 `bson:"global_recv_msg_opt"`
|
|
||||||
// CreateTime time.Time `bson:"create_time"`
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//type UserModelInterface interface {
|
|
||||||
// Create(ctx context.Context, users []*UserModel) (err error)
|
|
||||||
// UpdateByMap(ctx context.Context, userID string, args map[string]any) (err error)
|
|
||||||
// Find(ctx context.Context, userIDs []string) (users []*UserModel, err error)
|
|
||||||
// Take(ctx context.Context, userID string) (user *UserModel, err error)
|
|
||||||
// Page(ctx context.Context, pagination mgotool.Pagination) (count int64, users []*UserModel, err error)
|
|
||||||
// Exist(ctx context.Context, userID string) (exist bool, err error)
|
|
||||||
// GetAllUserID(ctx context.Context, pagination mgotool.Pagination) (count int64, userIDs []string, err error)
|
|
||||||
// GetUserGlobalRecvMsgOpt(ctx context.Context, userID string) (opt int, err error)
|
|
||||||
// // 获取用户总数
|
|
||||||
// CountTotal(ctx context.Context, before *time.Time) (count int64, err error)
|
|
||||||
// // 获取范围内用户增量
|
|
||||||
// CountRangeEverydayTotal(ctx context.Context, start time.Time, end time.Time) (map[string]int64, error)
|
|
||||||
//}
|
|
||||||
@ -4,16 +4,17 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/common/db/newmgo/mgotool"
|
"github.com/openimsdk/open-im-server/v3/pkg/common/db/newmgo/mgotool"
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/common/db/table/relation"
|
"github.com/openimsdk/open-im-server/v3/pkg/common/db/table/relation"
|
||||||
|
"github.com/openimsdk/open-im-server/v3/pkg/common/pagination"
|
||||||
"go.mongodb.org/mongo-driver/bson"
|
"go.mongodb.org/mongo-driver/bson"
|
||||||
"go.mongodb.org/mongo-driver/mongo"
|
"go.mongodb.org/mongo-driver/mongo"
|
||||||
"go.mongodb.org/mongo-driver/mongo/options"
|
"go.mongodb.org/mongo-driver/mongo/options"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewUserMongo(db *mongo.Database) relation.UserModelInterface {
|
func NewUserMongo(db *mongo.Database) (relation.UserModelInterface, error) {
|
||||||
return &UserMgo{
|
return &UserMgo{
|
||||||
coll: db.Collection("user"),
|
coll: db.Collection("user"),
|
||||||
}
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type UserMgo struct {
|
type UserMgo struct {
|
||||||
@ -39,11 +40,11 @@ func (u *UserMgo) Take(ctx context.Context, userID string) (user *relation.UserM
|
|||||||
return mgotool.FindOne[*relation.UserModel](ctx, u.coll, bson.M{"user_id": userID})
|
return mgotool.FindOne[*relation.UserModel](ctx, u.coll, bson.M{"user_id": userID})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *UserMgo) Page(ctx context.Context, pagination mgotool.Pagination) (count int64, users []*relation.UserModel, err error) {
|
func (u *UserMgo) Page(ctx context.Context, pagination pagination.Pagination) (count int64, users []*relation.UserModel, err error) {
|
||||||
return mgotool.FindPage[*relation.UserModel](ctx, u.coll, bson.M{}, pagination)
|
return mgotool.FindPage[*relation.UserModel](ctx, u.coll, bson.M{}, pagination)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *UserMgo) GetAllUserID(ctx context.Context, pagination mgotool.Pagination) (int64, []string, error) {
|
func (u *UserMgo) GetAllUserID(ctx context.Context, pagination pagination.Pagination) (int64, []string, error) {
|
||||||
return mgotool.FindPage[string](ctx, u.coll, bson.M{}, pagination, options.Find().SetProjection(bson.M{"user_id": 1}))
|
return mgotool.FindPage[string](ctx, u.coll, bson.M{}, pagination, options.Find().SetProjection(bson.M{"user_id": 1}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,49 +1,49 @@
|
|||||||
package relation
|
package relation
|
||||||
|
|
||||||
import (
|
//import (
|
||||||
"context"
|
// "context"
|
||||||
"time"
|
// "time"
|
||||||
|
//
|
||||||
"github.com/OpenIMSDK/tools/errs"
|
// "github.com/OpenIMSDK/tools/errs"
|
||||||
"github.com/OpenIMSDK/tools/ormutil"
|
// "github.com/OpenIMSDK/tools/ormutil"
|
||||||
"gorm.io/gorm"
|
// "gorm.io/gorm"
|
||||||
|
//
|
||||||
relationtb "github.com/openimsdk/open-im-server/v3/pkg/common/db/table/relation"
|
// relationtb "github.com/openimsdk/open-im-server/v3/pkg/common/db/table/relation"
|
||||||
)
|
//)
|
||||||
|
//
|
||||||
type LogGorm struct {
|
//type LogGorm struct {
|
||||||
db *gorm.DB
|
// db *gorm.DB
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
func (l *LogGorm) Create(ctx context.Context, log []*relationtb.Log) error {
|
//func (l *LogGorm) Create(ctx context.Context, log []*relationtb.Log) error {
|
||||||
return errs.Wrap(l.db.WithContext(ctx).Create(log).Error)
|
// return errs.Wrap(l.db.WithContext(ctx).Create(log).Error)
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
func (l *LogGorm) Search(ctx context.Context, keyword string, start time.Time, end time.Time, pageNumber int32, showNumber int32) (uint32, []*relationtb.Log, error) {
|
//func (l *LogGorm) Search(ctx context.Context, keyword string, start time.Time, end time.Time, pageNumber int32, showNumber int32) (uint32, []*relationtb.Log, error) {
|
||||||
db := l.db.WithContext(ctx).Where("create_time >= ?", start)
|
// db := l.db.WithContext(ctx).Where("create_time >= ?", start)
|
||||||
if end.UnixMilli() != 0 {
|
// if end.UnixMilli() != 0 {
|
||||||
db = l.db.WithContext(ctx).Where("create_time <= ?", end)
|
// db = l.db.WithContext(ctx).Where("create_time <= ?", end)
|
||||||
}
|
// }
|
||||||
db = db.Order("create_time desc")
|
// db = db.Order("create_time desc")
|
||||||
return ormutil.GormSearch[relationtb.Log](db, []string{"user_id"}, keyword, pageNumber, showNumber)
|
// return ormutil.GormSearch[relationtb.Log](db, []string{"user_id"}, keyword, pageNumber, showNumber)
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
func (l *LogGorm) Delete(ctx context.Context, logIDs []string, userID string) error {
|
//func (l *LogGorm) Delete(ctx context.Context, logIDs []string, userID string) error {
|
||||||
if userID == "" {
|
// if userID == "" {
|
||||||
return errs.Wrap(l.db.WithContext(ctx).Where("log_id in ?", logIDs).Delete(&relationtb.Log{}).Error)
|
// return errs.Wrap(l.db.WithContext(ctx).Where("log_id in ?", logIDs).Delete(&relationtb.Log{}).Error)
|
||||||
}
|
// }
|
||||||
return errs.Wrap(l.db.WithContext(ctx).Where("log_id in ? and user_id=?", logIDs, userID).Delete(&relationtb.Log{}).Error)
|
// return errs.Wrap(l.db.WithContext(ctx).Where("log_id in ? and user_id=?", logIDs, userID).Delete(&relationtb.Log{}).Error)
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
func (l *LogGorm) Get(ctx context.Context, logIDs []string, userID string) ([]*relationtb.Log, error) {
|
//func (l *LogGorm) Get(ctx context.Context, logIDs []string, userID string) ([]*relationtb.Log, error) {
|
||||||
var logs []*relationtb.Log
|
// var logs []*relationtb.Log
|
||||||
if userID == "" {
|
// if userID == "" {
|
||||||
return logs, errs.Wrap(l.db.WithContext(ctx).Where("log_id in ?", logIDs).Find(&logs).Error)
|
// return logs, errs.Wrap(l.db.WithContext(ctx).Where("log_id in ?", logIDs).Find(&logs).Error)
|
||||||
}
|
// }
|
||||||
return logs, errs.Wrap(l.db.WithContext(ctx).Where("log_id in ? and user_id=?", logIDs, userID).Find(&logs).Error)
|
// return logs, errs.Wrap(l.db.WithContext(ctx).Where("log_id in ? and user_id=?", logIDs, userID).Find(&logs).Error)
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
func NewLogGorm(db *gorm.DB) relationtb.LogInterface {
|
//func NewLogGorm(db *gorm.DB) relationtb.LogInterface {
|
||||||
db.AutoMigrate(&relationtb.Log{})
|
// db.AutoMigrate(&relationtb.Log{})
|
||||||
return &LogGorm{db: db}
|
// return &LogGorm{db: db}
|
||||||
}
|
//}
|
||||||
|
|||||||
@ -14,40 +14,41 @@
|
|||||||
|
|
||||||
package relation
|
package relation
|
||||||
|
|
||||||
import (
|
//
|
||||||
"context"
|
//import (
|
||||||
|
// "context"
|
||||||
"gorm.io/gorm"
|
//
|
||||||
|
// "gorm.io/gorm"
|
||||||
"github.com/OpenIMSDK/tools/errs"
|
//
|
||||||
|
// "github.com/OpenIMSDK/tools/errs"
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/common/db/table/relation"
|
//
|
||||||
)
|
// "github.com/openimsdk/open-im-server/v3/pkg/common/db/table/relation"
|
||||||
|
//)
|
||||||
type ObjectInfoGorm struct {
|
//
|
||||||
*MetaDB
|
//type ObjectInfoGorm struct {
|
||||||
}
|
// *MetaDB
|
||||||
|
//}
|
||||||
func NewObjectInfo(db *gorm.DB) relation.ObjectInfoModelInterface {
|
//
|
||||||
return &ObjectInfoGorm{
|
//func NewObjectInfo(db *gorm.DB) relation.ObjectInfoModelInterface {
|
||||||
NewMetaDB(db, &relation.ObjectModel{}),
|
// return &ObjectInfoGorm{
|
||||||
}
|
// NewMetaDB(db, &relation.ObjectModel{}),
|
||||||
}
|
// }
|
||||||
|
//}
|
||||||
func (o *ObjectInfoGorm) NewTx(tx any) relation.ObjectInfoModelInterface {
|
//
|
||||||
return &ObjectInfoGorm{
|
//func (o *ObjectInfoGorm) NewTx(tx any) relation.ObjectInfoModelInterface {
|
||||||
NewMetaDB(tx.(*gorm.DB), &relation.ObjectModel{}),
|
// return &ObjectInfoGorm{
|
||||||
}
|
// NewMetaDB(tx.(*gorm.DB), &relation.ObjectModel{}),
|
||||||
}
|
// }
|
||||||
|
//}
|
||||||
func (o *ObjectInfoGorm) SetObject(ctx context.Context, obj *relation.ObjectModel) (err error) {
|
//
|
||||||
if err := o.DB.WithContext(ctx).Where("name = ?", obj.Name).FirstOrCreate(obj).Error; err != nil {
|
//func (o *ObjectInfoGorm) SetObject(ctx context.Context, obj *relation.ObjectModel) (err error) {
|
||||||
return errs.Wrap(err)
|
// if err := o.DB.WithContext(ctx).Where("name = ?", obj.Name).FirstOrCreate(obj).Error; err != nil {
|
||||||
}
|
// return errs.Wrap(err)
|
||||||
return nil
|
// }
|
||||||
}
|
// return nil
|
||||||
|
//}
|
||||||
func (o *ObjectInfoGorm) Take(ctx context.Context, name string) (info *relation.ObjectModel, err error) {
|
//
|
||||||
info = &relation.ObjectModel{}
|
//func (o *ObjectInfoGorm) Take(ctx context.Context, name string) (info *relation.ObjectModel, err error) {
|
||||||
return info, errs.Wrap(o.DB.WithContext(ctx).Where("name = ?", name).Take(info).Error)
|
// info = &relation.ObjectModel{}
|
||||||
}
|
// return info, errs.Wrap(o.DB.WithContext(ctx).Where("name = ?", name).Take(info).Error)
|
||||||
|
//}
|
||||||
|
|||||||
@ -46,6 +46,10 @@ type Controller struct {
|
|||||||
impl s3.Interface
|
impl s3.Interface
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Controller) Engine() string {
|
||||||
|
return c.impl.Engine()
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Controller) HashPath(md5 string) string {
|
func (c *Controller) HashPath(md5 string) string {
|
||||||
return path.Join(hashPath, md5)
|
return path.Join(hashPath, md5)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,24 +2,37 @@ package relation
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"github.com/openimsdk/open-im-server/v3/pkg/common/pagination"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//type Log struct {
|
||||||
|
// LogID string `gorm:"column:log_id;primary_key;type:char(64)"`
|
||||||
|
// Platform string `gorm:"column:platform;type:varchar(32)"`
|
||||||
|
// UserID string `gorm:"column:user_id;type:char(64)"`
|
||||||
|
// CreateTime time.Time `gorm:"index:,sort:desc"`
|
||||||
|
// Url string `gorm:"column:url;type varchar(255)"`
|
||||||
|
// FileName string `gorm:"column:filename;type varchar(255)"`
|
||||||
|
// SystemType string `gorm:"column:system_type;type varchar(255)"`
|
||||||
|
// Version string `gorm:"column:version;type varchar(255)"`
|
||||||
|
// Ex string `gorm:"column:ex;type varchar(255)"`
|
||||||
|
//}
|
||||||
|
|
||||||
type Log struct {
|
type Log struct {
|
||||||
LogID string `gorm:"column:log_id;primary_key;type:char(64)"`
|
LogID string `bson:"log_id"`
|
||||||
Platform string `gorm:"column:platform;type:varchar(32)"`
|
Platform string `bson:"platform"`
|
||||||
UserID string `gorm:"column:user_id;type:char(64)"`
|
UserID string `bson:"user_id"`
|
||||||
CreateTime time.Time `gorm:"index:,sort:desc"`
|
CreateTime time.Time `bson:"create_time"`
|
||||||
Url string `gorm:"column:url;type varchar(255)"`
|
Url string `bson:"url"`
|
||||||
FileName string `gorm:"column:filename;type varchar(255)"`
|
FileName string `bson:"file_name"`
|
||||||
SystemType string `gorm:"column:system_type;type varchar(255)"`
|
SystemType string `bson:"system_type"`
|
||||||
Version string `gorm:"column:version;type varchar(255)"`
|
Version string `bson:"version"`
|
||||||
Ex string `gorm:"column:ex;type varchar(255)"`
|
Ex string `bson:"ex"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type LogInterface interface {
|
type LogInterface interface {
|
||||||
Create(ctx context.Context, log []*Log) error
|
Create(ctx context.Context, log []*Log) error
|
||||||
Search(ctx context.Context, keyword string, start time.Time, end time.Time, pageNumber int32, showNumber int32) (uint32, []*Log, error)
|
Search(ctx context.Context, keyword string, start time.Time, end time.Time, pagination pagination.Pagination) (int64, []*Log, error)
|
||||||
Delete(ctx context.Context, logID []string, userID string) error
|
Delete(ctx context.Context, logID []string, userID string) error
|
||||||
Get(ctx context.Context, logIDs []string, userID string) ([]*Log, error)
|
Get(ctx context.Context, logIDs []string, userID string) ([]*Log, error)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -24,22 +24,35 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type ObjectModel struct {
|
type ObjectModel struct {
|
||||||
Name string `gorm:"column:name;primary_key"`
|
Name string `bson:"name"`
|
||||||
UserID string `gorm:"column:user_id"`
|
UserID string `bson:"user_id"`
|
||||||
Hash string `gorm:"column:hash"`
|
Hash string `bson:"hash"`
|
||||||
Key string `gorm:"column:key"`
|
Engine string `bson:"engine"`
|
||||||
Size int64 `gorm:"column:size"`
|
Key string `bson:"key"`
|
||||||
ContentType string `gorm:"column:content_type"`
|
Size int64 `bson:"size"`
|
||||||
Cause string `gorm:"column:cause"`
|
ContentType string `bson:"content_type"`
|
||||||
CreateTime time.Time `gorm:"column:create_time"`
|
Group string `bson:"group"`
|
||||||
|
CreateTime time.Time `bson:"create_time"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//type ObjectModel struct {
|
||||||
|
// Name string `gorm:"column:name;primary_key"`
|
||||||
|
// UserID string `gorm:"column:user_id"`
|
||||||
|
// Hash string `gorm:"column:hash"`
|
||||||
|
// Engine string `gorm:"column:engine"`
|
||||||
|
// Key string `gorm:"column:key"`
|
||||||
|
// Size int64 `gorm:"column:size"`
|
||||||
|
// ContentType string `gorm:"column:content_type"`
|
||||||
|
// Cause string `gorm:"column:cause"`
|
||||||
|
// CreateTime time.Time `gorm:"column:create_time"`
|
||||||
|
//}
|
||||||
|
|
||||||
func (ObjectModel) TableName() string {
|
func (ObjectModel) TableName() string {
|
||||||
return ObjectInfoModelTableName
|
return ObjectInfoModelTableName
|
||||||
}
|
}
|
||||||
|
|
||||||
type ObjectInfoModelInterface interface {
|
type ObjectInfoModelInterface interface {
|
||||||
NewTx(tx any) ObjectInfoModelInterface
|
|
||||||
SetObject(ctx context.Context, obj *ObjectModel) error
|
SetObject(ctx context.Context, obj *ObjectModel) error
|
||||||
Take(ctx context.Context, name string) (*ObjectModel, error)
|
Take(ctx context.Context, engine string, name string) (*ObjectModel, error)
|
||||||
|
Delete(ctx context.Context, engine string, name string) error
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,7 +16,7 @@ package relation
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/common/db/newmgo/mgotool"
|
"github.com/openimsdk/open-im-server/v3/pkg/common/pagination"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -51,9 +51,9 @@ type UserModelInterface interface {
|
|||||||
UpdateByMap(ctx context.Context, userID string, args map[string]any) (err error)
|
UpdateByMap(ctx context.Context, userID string, args map[string]any) (err error)
|
||||||
Find(ctx context.Context, userIDs []string) (users []*UserModel, err error)
|
Find(ctx context.Context, userIDs []string) (users []*UserModel, err error)
|
||||||
Take(ctx context.Context, userID string) (user *UserModel, err error)
|
Take(ctx context.Context, userID string) (user *UserModel, err error)
|
||||||
Page(ctx context.Context, pagination mgotool.Pagination) (count int64, users []*UserModel, err error)
|
Page(ctx context.Context, pagination pagination.Pagination) (count int64, users []*UserModel, err error)
|
||||||
Exist(ctx context.Context, userID string) (exist bool, err error)
|
Exist(ctx context.Context, userID string) (exist bool, err error)
|
||||||
GetAllUserID(ctx context.Context, pagination mgotool.Pagination) (count int64, userIDs []string, err error)
|
GetAllUserID(ctx context.Context, pagination pagination.Pagination) (count int64, userIDs []string, err error)
|
||||||
GetUserGlobalRecvMsgOpt(ctx context.Context, userID string) (opt int, err error)
|
GetUserGlobalRecvMsgOpt(ctx context.Context, userID string) (opt int, err error)
|
||||||
// 获取用户总数
|
// 获取用户总数
|
||||||
CountTotal(ctx context.Context, before *time.Time) (count int64, err error)
|
CountTotal(ctx context.Context, before *time.Time) (count int64, err error)
|
||||||
|
|||||||
6
pkg/common/pagination/pagination.go
Normal file
6
pkg/common/pagination/pagination.go
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
package pagination
|
||||||
|
|
||||||
|
type Pagination interface {
|
||||||
|
GetPageNumber() int32
|
||||||
|
GetShowNumber() int32
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user