53 lines
1.3 KiB
Go
53 lines
1.3 KiB
Go
|
|
package logic
|
||
|
|
|
||
|
|
import (
|
||
|
|
"context"
|
||
|
|
"database/sql"
|
||
|
|
|
||
|
|
"muyu-apiserver/model"
|
||
|
|
"muyu-apiserver/pkg/uid"
|
||
|
|
"muyu-apiserver/rpc/system/internal/svc"
|
||
|
|
"muyu-apiserver/rpc/system/pb"
|
||
|
|
|
||
|
|
"github.com/zeromicro/go-zero/core/logx"
|
||
|
|
"google.golang.org/grpc/codes"
|
||
|
|
"google.golang.org/grpc/status"
|
||
|
|
)
|
||
|
|
|
||
|
|
type CreateOperationLogLogic struct {
|
||
|
|
ctx context.Context
|
||
|
|
svcCtx *svc.ServiceContext
|
||
|
|
logx.Logger
|
||
|
|
}
|
||
|
|
|
||
|
|
func NewCreateOperationLogLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateOperationLogLogic {
|
||
|
|
return &CreateOperationLogLogic{
|
||
|
|
ctx: ctx,
|
||
|
|
svcCtx: svcCtx,
|
||
|
|
Logger: logx.WithContext(ctx),
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func (l *CreateOperationLogLogic) CreateOperationLog(in *pb.CreateLogReq) (*pb.Empty, error) {
|
||
|
|
_, err := l.svcCtx.LogModel.Insert(l.ctx, &model.SysOperationLog{
|
||
|
|
LogId: uid.Generate(),
|
||
|
|
UserId: in.UserId,
|
||
|
|
Username: in.Username,
|
||
|
|
Module: in.Module,
|
||
|
|
Operation: in.Operation,
|
||
|
|
Method: in.Method,
|
||
|
|
Path: in.Path,
|
||
|
|
RequestBody: sql.NullString{String: in.RequestBody, Valid: in.RequestBody != ""},
|
||
|
|
ResponseBody: sql.NullString{String: in.ResponseBody, Valid: in.ResponseBody != ""},
|
||
|
|
Ip: in.Ip,
|
||
|
|
UserAgent: in.UserAgent,
|
||
|
|
Duration: in.Duration,
|
||
|
|
Status: in.Status,
|
||
|
|
})
|
||
|
|
if err != nil {
|
||
|
|
return nil, status.Error(codes.Internal, err.Error())
|
||
|
|
}
|
||
|
|
|
||
|
|
return &pb.Empty{}, nil
|
||
|
|
}
|