优化结构

This commit is contained in:
Yvan
2026-08-22 12:13:16 +08:00
parent d987244d0e
commit b27a66e9d3
200 changed files with 1794 additions and 1715 deletions
+7 -7
View File
@@ -2,9 +2,9 @@ package system
import (
"context"
"kra/internal/biz/system"
"time"
"kra/internal/biz"
"kra/pkg/database/pagination"
"gorm.io/gorm"
@@ -23,7 +23,7 @@ type loginLogPO struct {
func (loginLogPO) TableName() string { return "sys_login_logs" }
func (r *auditRecorderRepo) RecordLogin(ctx context.Context, v *biz.LoginLog) error {
func (r *auditRecorderRepo) RecordLogin(ctx context.Context, v *system.LoginLog) error {
if !r.data.DatabaseReady() {
// The login endpoint remains reachable before database initialization;
// skip the audit write until storage is ready.
@@ -31,10 +31,10 @@ func (r *auditRecorderRepo) RecordLogin(ctx context.Context, v *biz.LoginLog) er
}
return r.data.DB().WithContext(ctx).Create(&loginLogPO{Username: v.Username, IP: v.IP, Status: v.Status, ErrorMessage: v.ErrorMessage, Agent: v.Agent, UserID: v.UserID}).Error
}
func loginFromPO(v loginLogPO) *biz.LoginLog {
return &biz.LoginLog{ID: v.ID, CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt, Username: v.Username, IP: v.IP, Status: v.Status, ErrorMessage: v.ErrorMessage, Agent: v.Agent, UserID: v.UserID}
func loginFromPO(v loginLogPO) *system.LoginLog {
return &system.LoginLog{ID: v.ID, CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt, Username: v.Username, IP: v.IP, Status: v.Status, ErrorMessage: v.ErrorMessage, Agent: v.Agent, UserID: v.UserID}
}
func (r *auditQueryRepo) ListLogins(ctx context.Context, page, size int, q *biz.LoginLog) ([]*biz.LoginLog, int64, error) {
func (r *auditQueryRepo) ListLogins(ctx context.Context, page, size int, q *system.LoginLog) ([]*system.LoginLog, int64, error) {
db := r.data.DB().WithContext(ctx).Model(&loginLogPO{})
if q != nil {
if q.Username != "" {
@@ -59,7 +59,7 @@ func (r *auditQueryRepo) ListLogins(ctx context.Context, page, size int, q *biz.
}
}
users := auditUsers(ctx, r.data.DB().WithContext(ctx), ids)
out := make([]*biz.LoginLog, 0, len(pos))
out := make([]*system.LoginLog, 0, len(pos))
for _, po := range pos {
value := loginFromPO(po)
value.User = users[po.UserID]
@@ -67,7 +67,7 @@ func (r *auditQueryRepo) ListLogins(ctx context.Context, page, size int, q *biz.
}
return out, total, nil
}
func (r *auditQueryRepo) FindLogin(ctx context.Context, id uint) (*biz.LoginLog, error) {
func (r *auditQueryRepo) FindLogin(ctx context.Context, id uint) (*system.LoginLog, error) {
var po loginLogPO
if err := r.data.DB().WithContext(ctx).First(&po, id).Error; err != nil {
return nil, err