parent
050ad7fa70
commit
358f70895d
@ -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})
|
||||||
|
}
|
@ -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)
|
|
||||||
//}
|
|
@ -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}
|
||||||
}
|
//}
|
||||||
|
@ -0,0 +1,6 @@
|
|||||||
|
package pagination
|
||||||
|
|
||||||
|
type Pagination interface {
|
||||||
|
GetPageNumber() int32
|
||||||
|
GetShowNumber() int32
|
||||||
|
}
|
Loading…
Reference in new issue