Initial commit
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
package srv_acc
|
||||
|
||||
import (
|
||||
"videoweb/pub/models/oplog"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
// constructFilterAndOpts 根据搜索参数构建查询filter和options
|
||||
func constructFilterAndOpts(param *OpLogSearch) (
|
||||
bson.M, *options.FindOptions) {
|
||||
|
||||
filter := bson.M{}
|
||||
if param.Path != nil && *param.Path != "" {
|
||||
filter[oplog.FN.OpLog.Path] = bson.M{"$regex": param.Path}
|
||||
}
|
||||
if param.Action != nil && *param.Action != "" {
|
||||
filter[oplog.FN.OpLog.Action] = param.Action
|
||||
}
|
||||
if param.ActId != nil && *param.ActId > 0 {
|
||||
filter[oplog.FN.OpLog.ActId] = param.ActId
|
||||
}
|
||||
if param.StartTime != nil && param.EndTime != nil {
|
||||
filter[oplog.FN.OpLog.CreatedAt] = bson.M{"$gte": param.StartTime, "$lt": param.EndTime}
|
||||
}
|
||||
sort := bson.M{oplog.FN.OpLog.CreatedAt: -1}
|
||||
opt := &options.FindOptions{}
|
||||
opt.SetSort(sort)
|
||||
skip := (param.PageNum - 1) * param.PageSize
|
||||
opt.SetSkip(skip)
|
||||
opt.SetLimit(param.PageSize)
|
||||
return filter, opt
|
||||
}
|
||||
Reference in New Issue
Block a user