@@ -0,0 +1,39 @@
|
||||
package operationlogser
|
||||
|
||||
import (
|
||||
"91porn-server/common/stderr"
|
||||
"91porn-server/models/v/operationlogmod"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
func GetOperationLogList(req GetOperationLogListReq) (*GetOperationLogListResp, stderr.Code) {
|
||||
data := new(GetOperationLogListResp)
|
||||
filter := bson.M{}
|
||||
if req.UserID != nil && *req.UserID > 0 {
|
||||
filter["userID"] = *req.UserID
|
||||
}
|
||||
if req.CreatedUser != nil && len(*req.CreatedUser) > 0 {
|
||||
filter["createdUser"] = *req.CreatedUser
|
||||
}
|
||||
if req.Content != nil && len(*req.Content) > 0 {
|
||||
filter["afterContent"] = *req.Content
|
||||
}
|
||||
if req.Start != nil && !req.Start.IsZero() && req.End != nil && !req.End.IsZero() {
|
||||
filter["createdAt"] = bson.M{"$gte": req.Start, "$lt": req.End}
|
||||
}
|
||||
if req.OperationType != nil && *req.OperationType > 0 {
|
||||
filter["operationType"] = *req.OperationType
|
||||
}
|
||||
count := operationlogmod.Count(filter)
|
||||
data.Total = count
|
||||
opts := (&options.FindOptions{}).
|
||||
SetSort(bson.D{{Key: "createdAt", Value: -1}}).SetLimit(int64(req.PageSize)).SetSkip(int64((req.PageNumber - 1) * req.PageSize))
|
||||
operationlogList, serr := operationlogmod.FindManyOperationLog(filter, opts)
|
||||
if serr != nil {
|
||||
return data, stderr.ErrDbQueryError
|
||||
}
|
||||
data.List = operationlogList
|
||||
return data, stderr.Success
|
||||
}
|
||||
Reference in New Issue
Block a user