优化mongo,封装count逻辑,处理objectId
This commit is contained in:
@@ -2,7 +2,6 @@ package controller
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
"gitee.com/red-future---jilin-g/common/log/model/dto"
|
||||
"gitee.com/red-future---jilin-g/common/log/service"
|
||||
@@ -32,13 +31,7 @@ func (c *operationLog) GetByID(ctx context.Context, req *dto.GetLogReq) (res *dt
|
||||
// @Summary 查询操作日志列表
|
||||
// @Description 根据多个条件查询操作日志列表
|
||||
func (c *operationLog) List(ctx context.Context, req *dto.ListLogsReq) (res *dto.ListLogsResp, err error) {
|
||||
// 处理排序字段
|
||||
var sortFields []string
|
||||
if req.SortFields != "" {
|
||||
sortFields = strings.Split(req.SortFields, ",")
|
||||
}
|
||||
|
||||
logs, total, err := service.OperationLog.List(ctx, req, sortFields...)
|
||||
logs, total, err := service.OperationLog.List(ctx, req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ func (d *log) List(ctx context.Context, filter *dto.ListLogsReq, sortFields ...s
|
||||
}
|
||||
|
||||
var logs []*entity.OperationLog
|
||||
err = mongo.DB().Find(ctx, bsonFilter, &logs, consts.OperationLogCollection, findOptions...)
|
||||
err = mongo.DB().Find(ctx, bsonFilter, &logs, consts.OperationLogCollection, nil, nil)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
@@ -34,13 +34,13 @@ type OperationLogInfo struct {
|
||||
type ListLogsReq struct {
|
||||
g.Meta `path:"/listLogs" method:"get" tags:"操作日志" summary:"查询操作日志列表" dc:"根据多个条件查询操作日志列表"`
|
||||
beans.Page
|
||||
ServiceName string `json:"service_name" dc:"服务名(可选)"`
|
||||
Collection string `json:"collection" dc:"数据所在集合名称(可选)"`
|
||||
CollectionID string `json:"collection_id" dc:"数据ID(可选)"`
|
||||
Operation string `json:"operation" dc:"操作类型(可选)"`
|
||||
StartTime string `json:"start_time" dc:"开始时间(可选)"`
|
||||
EndTime string `json:"end_time" dc:"结束时间(可选)"`
|
||||
SortFields string `json:"sort_fields" dc:"排序字段,多个用逗号分隔,如:-createdAt"`
|
||||
ServiceName string `json:"service_name" dc:"服务名(可选)"`
|
||||
Collection string `json:"collection" dc:"数据所在集合名称(可选)"`
|
||||
CollectionID string `json:"collection_id" dc:"数据ID(可选)"`
|
||||
Operation string `json:"operation" dc:"操作类型(可选)"`
|
||||
StartTime string `json:"start_time" dc:"开始时间(可选)"`
|
||||
EndTime string `json:"end_time" dc:"结束时间(可选)"`
|
||||
OrderBy []beans.OrderBy `json:"orderBy" dc:"排序字段"`
|
||||
}
|
||||
|
||||
// ListLogsResp 查询操作日志列表响应
|
||||
|
||||
@@ -53,8 +53,8 @@ func (s *operationLog) GetByID(ctx context.Context, id string) (*dto.OperationLo
|
||||
}
|
||||
|
||||
// List 查询操作日志列表
|
||||
func (s *operationLog) List(ctx context.Context, filter *dto.ListLogsReq, sortFields ...string) ([]dto.OperationLogInfo, int64, error) {
|
||||
logs, total, err := dao.Log.List(ctx, filter, sortFields...)
|
||||
func (s *operationLog) List(ctx context.Context, req *dto.ListLogsReq) ([]dto.OperationLogInfo, int64, error) {
|
||||
logs, total, err := dao.Log.List(ctx, req)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user