kra/internal/biz/system/operation_record.go

64 lines
2.0 KiB
Go

package system
import "context"
// OperationRecord 操作记录实体
type OperationRecord struct {
ID uint
IP string
Method string
Path string
Status int
Latency int64
Agent string
ErrorMessage string
Body string
Resp string
UserID uint
User *User
}
// OperationRecordRepo 操作记录仓储接口
type OperationRecordRepo interface {
Create(ctx context.Context, record *OperationRecord) error
Delete(ctx context.Context, id uint) error
DeleteByIds(ctx context.Context, ids []uint) error
FindByID(ctx context.Context, id uint) (*OperationRecord, error)
List(ctx context.Context, page, pageSize int, filters map[string]interface{}) ([]*OperationRecord, int64, error)
}
// OperationRecordUsecase 操作记录用例
type OperationRecordUsecase struct {
repo OperationRecordRepo
}
// NewOperationRecordUsecase 创建操作记录用例
func NewOperationRecordUsecase(repo OperationRecordRepo) *OperationRecordUsecase {
return &OperationRecordUsecase{repo: repo}
}
// CreateOperationRecord 创建操作记录
func (uc *OperationRecordUsecase) CreateOperationRecord(ctx context.Context, record *OperationRecord) error {
return uc.repo.Create(ctx, record)
}
// DeleteOperationRecord 删除操作记录
func (uc *OperationRecordUsecase) DeleteOperationRecord(ctx context.Context, id uint) error {
return uc.repo.Delete(ctx, id)
}
// DeleteOperationRecordByIds 批量删除操作记录
func (uc *OperationRecordUsecase) DeleteOperationRecordByIds(ctx context.Context, ids []uint) error {
return uc.repo.DeleteByIds(ctx, ids)
}
// GetOperationRecord 获取操作记录
func (uc *OperationRecordUsecase) GetOperationRecord(ctx context.Context, id uint) (*OperationRecord, error) {
return uc.repo.FindByID(ctx, id)
}
// GetOperationRecordList 获取操作记录列表
func (uc *OperationRecordUsecase) GetOperationRecordList(ctx context.Context, page, pageSize int, filters map[string]interface{}) ([]*OperationRecord, int64, error) {
return uc.repo.List(ctx, page, pageSize, filters)
}