org 模块: - tenants 表 (UUID PK, name, slug, status, settings) - 完整 CRUD API: /api/v1/org/tenants - 多租户隔离 audit 模块: - audit_logs 表 (actor, action, resource, IP, 时间) - 查询 API: /api/v1/audit/logs (支持分页+筛选) - 按 tenant_id/user_id/action/resource 过滤
55 lines
1.4 KiB
Go
55 lines
1.4 KiB
Go
package domain
|
|
|
|
import "time"
|
|
|
|
type AuditLog struct {
|
|
ID uint `json:"id" gorm:"primaryKey"`
|
|
TenantID string `json:"tenant_id" gorm:"type:uuid;index;not null"`
|
|
UserID uint `json:"user_id" gorm:"index;not null"`
|
|
Action string `json:"action" gorm:"size:64;not null;index"`
|
|
Resource string `json:"resource" gorm:"size:128;not null;index"`
|
|
ResourceID string `json:"resource_id" gorm:"size:128"`
|
|
Detail string `json:"detail" gorm:"type:text"`
|
|
IP string `json:"ip" gorm:"size:64"`
|
|
CreatedAt time.Time `json:"created_at" gorm:"index"`
|
|
}
|
|
|
|
func (AuditLog) TableName() string {
|
|
return "audit_logs"
|
|
}
|
|
|
|
type AuditLogDTO struct {
|
|
ID uint `json:"id"`
|
|
TenantID string `json:"tenant_id"`
|
|
UserID uint `json:"user_id"`
|
|
Action string `json:"action"`
|
|
Resource string `json:"resource"`
|
|
ResourceID string `json:"resource_id"`
|
|
Detail string `json:"detail"`
|
|
IP string `json:"ip"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
}
|
|
|
|
func ToAuditLogDTO(l *AuditLog) AuditLogDTO {
|
|
return AuditLogDTO{
|
|
ID: l.ID,
|
|
TenantID: l.TenantID,
|
|
UserID: l.UserID,
|
|
Action: l.Action,
|
|
Resource: l.Resource,
|
|
ResourceID: l.ResourceID,
|
|
Detail: l.Detail,
|
|
IP: l.IP,
|
|
CreatedAt: l.CreatedAt,
|
|
}
|
|
}
|
|
|
|
type AuditQuery struct {
|
|
TenantID string
|
|
UserID uint
|
|
Action string
|
|
Resource string
|
|
Page int
|
|
PageSize int
|
|
}
|