2026-05-02 13:02:38 +08:00

201 lines
7.6 KiB
Go

package model
import "time"
const (
UserStatusActive = "active"
UserStatusLocked = "locked"
UserStatusDisabled = "disabled"
JobStatusPending = "pending"
JobStatusRunning = "running"
JobStatusSucceeded = "succeeded"
JobStatusFailed = "failed"
JobStatusCanceled = "canceled"
)
type User struct {
ID uint `gorm:"primaryKey" json:"id"`
Username string `gorm:"size:64;uniqueIndex;not null" json:"account"`
Name string `gorm:"size:80;not null" json:"name"`
PasswordHash string `gorm:"size:255;not null" json:"-"`
Team string `gorm:"size:80" json:"team"`
Status string `gorm:"size:24;index;not null;default:active" json:"status"`
MFAEnabled bool `gorm:"not null;default:false" json:"mfaEnabled"`
LastLoginAt *time.Time `json:"lastLoginAt"`
Roles []Role `gorm:"many2many:admin_user_roles;" json:"roles"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
func (User) TableName() string {
return "admin_users"
}
type Role struct {
ID uint `gorm:"primaryKey" json:"id"`
Name string `gorm:"size:80;uniqueIndex;not null" json:"name"`
Code string `gorm:"size:80;uniqueIndex;not null" json:"code"`
Description string `gorm:"size:255" json:"description"`
Users []User `gorm:"many2many:admin_user_roles;" json:"-"`
Permissions []Permission `gorm:"many2many:admin_role_permissions;" json:"permissions"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
func (Role) TableName() string {
return "admin_roles"
}
type Permission struct {
ID uint `gorm:"primaryKey" json:"id"`
Name string `gorm:"size:100;not null" json:"name"`
Code string `gorm:"size:100;uniqueIndex;not null" json:"code"`
Kind string `gorm:"size:32;index;not null" json:"kind"`
Description string `gorm:"size:255" json:"description"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
func (Permission) TableName() string {
return "admin_permissions"
}
type Menu struct {
ID uint `gorm:"primaryKey" json:"id"`
ParentID *uint `gorm:"index" json:"parentId"`
Title string `gorm:"size:80;not null" json:"label"`
Code string `gorm:"size:100;uniqueIndex;not null" json:"code"`
Path string `gorm:"size:160" json:"path"`
Icon string `gorm:"size:64" json:"icon"`
PermissionCode string `gorm:"size:100;index" json:"permissionCode"`
Sort int `gorm:"not null;default:0" json:"sort"`
Visible bool `gorm:"not null;default:true" json:"visible"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
func (Menu) TableName() string {
return "admin_menus"
}
type AppConfig struct {
ID uint `gorm:"primaryKey" json:"id"`
Group string `gorm:"size:64;index:idx_admin_app_config_group_key,unique;not null" json:"group"`
Key string `gorm:"size:100;index:idx_admin_app_config_group_key,unique;not null" json:"key"`
Value string `gorm:"type:text" json:"value"`
Description string `gorm:"size:255" json:"description"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
func (AppConfig) TableName() string {
return "admin_app_configs"
}
type RefreshToken struct {
ID uint `gorm:"primaryKey" json:"id"`
UserID uint `gorm:"index;not null" json:"userId"`
TokenHash string `gorm:"size:128;uniqueIndex;not null" json:"-"`
UserAgent string `gorm:"size:255" json:"userAgent"`
IP string `gorm:"size:64" json:"ip"`
ExpiresAt time.Time `gorm:"index;not null" json:"expiresAt"`
RevokedAt *time.Time `json:"revokedAt"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
func (RefreshToken) TableName() string {
return "admin_refresh_tokens"
}
type LoginLog struct {
ID uint `gorm:"primaryKey" json:"id"`
Username string `gorm:"size:64;index" json:"username"`
UserID *uint `gorm:"index" json:"userId"`
IP string `gorm:"size:64" json:"ip"`
UserAgent string `gorm:"size:255" json:"userAgent"`
Status string `gorm:"size:32;index;not null" json:"status"`
Message string `gorm:"size:255" json:"message"`
CreatedAt time.Time `json:"createdAt"`
}
func (LoginLog) TableName() string {
return "admin_login_logs"
}
type OperationLog struct {
ID uint `gorm:"primaryKey" json:"id"`
RequestID string `gorm:"size:64;index;not null;default:''" json:"requestId"`
UserID uint `gorm:"index;not null" json:"userId"`
Username string `gorm:"size:64;index;not null" json:"username"`
Action string `gorm:"size:80;index;not null" json:"action"`
Resource string `gorm:"size:120;index" json:"resource"`
ResourceID string `gorm:"size:80;index;not null;default:''" json:"resourceId"`
Method string `gorm:"size:12" json:"method"`
Path string `gorm:"size:180" json:"path"`
IP string `gorm:"size:64" json:"ip"`
UserAgent string `gorm:"size:255;not null;default:''" json:"userAgent"`
Status string `gorm:"size:32;index;not null" json:"status"`
HTTPStatus int `gorm:"not null;default:0" json:"httpStatus"`
RiskLevel string `gorm:"size:24;index;not null;default:normal" json:"riskLevel"`
LatencyMS int64 `gorm:"not null;default:0" json:"latencyMs"`
Detail string `gorm:"type:text" json:"detail"`
CreatedAt time.Time `json:"createdAt"`
}
func (OperationLog) TableName() string {
return "admin_operation_logs"
}
type Notification struct {
ID uint `gorm:"primaryKey" json:"id"`
Title string `gorm:"size:120;not null" json:"title"`
Content string `gorm:"size:500" json:"content"`
Level string `gorm:"size:24;index;not null;default:info" json:"level"`
ReadAt *time.Time `json:"readAt"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
func (Notification) TableName() string {
return "admin_notifications"
}
type DataScope struct {
ID uint `gorm:"primaryKey" json:"id"`
RoleID uint `gorm:"index;not null" json:"roleId"`
ScopeType string `gorm:"size:40;index;not null" json:"scopeType"`
ScopeValue string `gorm:"size:120;index;not null" json:"scopeValue"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
func (DataScope) TableName() string {
return "admin_data_scopes"
}
type AdminJob struct {
ID uint `gorm:"primaryKey" json:"id"`
Type string `gorm:"size:80;index;not null" json:"type"`
Status string `gorm:"size:32;index;not null" json:"status"`
PayloadJSON string `gorm:"type:text" json:"payload"`
ResultJSON string `gorm:"type:text" json:"result"`
Error string `gorm:"type:text" json:"error"`
Attempt int `gorm:"not null;default:0" json:"attempt"`
MaxAttempts int `gorm:"not null;default:3" json:"maxAttempts"`
LockedBy string `gorm:"size:120;index;not null;default:''" json:"lockedBy"`
LockedUntil *time.Time `gorm:"index" json:"lockedUntil"`
ArtifactPath string `gorm:"size:255;not null;default:''" json:"artifactPath"`
CreatedBy uint `gorm:"index;not null" json:"createdBy"`
CreatedByName string `gorm:"size:64;index;not null" json:"createdByName"`
StartedAt *time.Time `json:"startedAt"`
FinishedAt *time.Time `json:"finishedAt"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
func (AdminJob) TableName() string {
return "admin_jobs"
}