优化结构
This commit is contained in:
@@ -2,9 +2,9 @@ package system
|
||||
|
||||
import (
|
||||
"context"
|
||||
"kra/internal/biz/system"
|
||||
"time"
|
||||
|
||||
"kra/internal/biz"
|
||||
"kra/pkg/database/pagination"
|
||||
|
||||
"gorm.io/gorm"
|
||||
@@ -30,13 +30,13 @@ type operationPO struct {
|
||||
|
||||
func (operationPO) TableName() string { return "sys_operation_records" }
|
||||
|
||||
func (r *auditRecorderRepo) RecordOperation(ctx context.Context, v *biz.OperationRecord) error {
|
||||
func (r *auditRecorderRepo) RecordOperation(ctx context.Context, v *system.OperationRecord) error {
|
||||
return r.data.DB().WithContext(ctx).Create(&operationPO{IP: v.IP, Method: v.Method, Path: v.Path, Status: v.Status, LatencyMS: v.LatencyMS, Agent: v.Agent, ErrorMessage: v.ErrorMessage, Body: v.Body, Response: v.Response, UserID: v.UserID, RequestID: v.RequestID, TraceID: v.TraceID, DeviceID: v.DeviceID}).Error
|
||||
}
|
||||
func opFromPO(v operationPO) *biz.OperationRecord {
|
||||
return &biz.OperationRecord{ID: v.ID, CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt, IP: v.IP, Method: v.Method, Path: v.Path, Status: v.Status, LatencyMS: v.LatencyMS, Agent: v.Agent, ErrorMessage: v.ErrorMessage, Body: v.Body, Response: v.Response, UserID: v.UserID, RequestID: v.RequestID, TraceID: v.TraceID, DeviceID: v.DeviceID}
|
||||
func opFromPO(v operationPO) *system.OperationRecord {
|
||||
return &system.OperationRecord{ID: v.ID, CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt, IP: v.IP, Method: v.Method, Path: v.Path, Status: v.Status, LatencyMS: v.LatencyMS, Agent: v.Agent, ErrorMessage: v.ErrorMessage, Body: v.Body, Response: v.Response, UserID: v.UserID, RequestID: v.RequestID, TraceID: v.TraceID, DeviceID: v.DeviceID}
|
||||
}
|
||||
func (r *auditQueryRepo) ListOperations(ctx context.Context, page, size int, q *biz.OperationRecord) ([]*biz.OperationRecord, int64, error) {
|
||||
func (r *auditQueryRepo) ListOperations(ctx context.Context, page, size int, q *system.OperationRecord) ([]*system.OperationRecord, int64, error) {
|
||||
db := r.data.DB().WithContext(ctx).Model(&operationPO{})
|
||||
if q != nil {
|
||||
if q.Path != "" {
|
||||
@@ -58,7 +58,7 @@ func (r *auditQueryRepo) ListOperations(ctx context.Context, page, size int, q *
|
||||
return nil, 0, err
|
||||
}
|
||||
users := auditUsers(ctx, r.data.DB().WithContext(ctx), operationUserIDs(pos))
|
||||
out := make([]*biz.OperationRecord, 0, len(pos))
|
||||
out := make([]*system.OperationRecord, 0, len(pos))
|
||||
for _, po := range pos {
|
||||
value := opFromPO(po)
|
||||
value.User = users[po.UserID]
|
||||
@@ -77,8 +77,8 @@ func operationUserIDs(values []operationPO) []uint {
|
||||
return ids
|
||||
}
|
||||
|
||||
func auditUsers(ctx context.Context, db *gorm.DB, ids []uint) map[uint]*biz.User {
|
||||
result := make(map[uint]*biz.User)
|
||||
func auditUsers(ctx context.Context, db *gorm.DB, ids []uint) map[uint]*system.User {
|
||||
result := make(map[uint]*system.User)
|
||||
if len(ids) == 0 {
|
||||
return result
|
||||
}
|
||||
@@ -87,11 +87,11 @@ func auditUsers(ctx context.Context, db *gorm.DB, ids []uint) map[uint]*biz.User
|
||||
return result
|
||||
}
|
||||
for _, value := range users {
|
||||
result[value.ID] = &biz.User{ID: value.ID, CreatedAt: value.CreatedAt, UpdatedAt: value.UpdatedAt, UUID: value.UUID, Username: value.Username, NickName: value.NickName, HeaderImg: value.HeaderImg, AuthorityID: value.AuthorityID, DeptID: value.DeptID, Phone: value.Phone, Email: value.Email, Enable: value.Enable}
|
||||
result[value.ID] = &system.User{ID: value.ID, CreatedAt: value.CreatedAt, UpdatedAt: value.UpdatedAt, UUID: value.UUID, Username: value.Username, NickName: value.NickName, HeaderImg: value.HeaderImg, AuthorityID: value.AuthorityID, DeptID: value.DeptID, Phone: value.Phone, Email: value.Email, Enable: value.Enable}
|
||||
}
|
||||
return result
|
||||
}
|
||||
func (r *auditQueryRepo) FindOperation(ctx context.Context, id uint) (*biz.OperationRecord, error) {
|
||||
func (r *auditQueryRepo) FindOperation(ctx context.Context, id uint) (*system.OperationRecord, error) {
|
||||
var po operationPO
|
||||
if err := r.data.DB().WithContext(ctx).First(&po, id).Error; err != nil {
|
||||
return nil, err
|
||||
|
||||
Reference in New Issue
Block a user