优化mongo,封装count逻辑,处理objectId

This commit is contained in:
2026-01-07 18:27:43 +08:00
parent 07b4240226
commit b5697d72ff
4 changed files with 38 additions and 80 deletions

View File

@@ -7,7 +7,6 @@ import (
"gitee.com/red-future---jilin-g/common/log/dao"
"gitee.com/red-future---jilin-g/common/log/model/dto"
logEntity "gitee.com/red-future---jilin-g/common/log/model/entity"
"gitee.com/red-future---jilin-g/common/utils"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/util/gconv"
)
@@ -75,26 +74,14 @@ func (s *operationLog) List(ctx context.Context, req *dto.ListLogsReq) ([]dto.Op
// record 记录操作日志的通用方法
func (s *operationLog) record(ctx context.Context, serviceName, collection, collectionID, operation string, data map[string]interface{}) error {
// 获取用户信息
user, err := utils.GetUserInfo(ctx)
if err != nil {
return err
}
// 获取请求信息
ipAddress := getHTTPRequestInfo(ctx)
var userName string
if user.UserName != nil {
userName = gconv.String(user.UserName)
}
log := &logEntity.OperationLog{
ServiceName: serviceName,
Collection: collection,
CollectionID: collectionID,
Operation: operation,
UserName: userName,
IPAddress: ipAddress,
Data: data,
}