123 lines
4.4 KiB
Go
123 lines
4.4 KiB
Go
package model
|
||
|
||
import (
|
||
"time"
|
||
)
|
||
|
||
// Role 角色
|
||
type Role struct {
|
||
ID uint `json:"id" gorm:"primaryKey;autoIncrement"`
|
||
Name string `json:"name" gorm:"size:50;not null;uniqueIndex"`
|
||
DisplayName string `json:"display_name" gorm:"size:100;not null"`
|
||
Description string `json:"description" gorm:"size:255"`
|
||
Status int `json:"status" gorm:"default:1"` // 0禁用,1正常
|
||
CreatedAt time.Time `json:"created_at"`
|
||
UpdatedAt time.Time `json:"updated_at"`
|
||
|
||
// 关联数据
|
||
Permissions []Permission `json:"permissions,omitempty" gorm:"many2many:ai_role_permissions;"`
|
||
Users []User `json:"users,omitempty" gorm:"many2many:ai_user_roles;"`
|
||
}
|
||
|
||
// Permission 权限
|
||
type Permission struct {
|
||
ID uint `json:"id" gorm:"primaryKey;autoIncrement"`
|
||
Name string `json:"name" gorm:"size:50;not null;uniqueIndex"`
|
||
DisplayName string `json:"display_name" gorm:"size:100;not null"`
|
||
Description string `json:"description" gorm:"size:255"`
|
||
Module string `json:"module" gorm:"size:50;not null"` // 模块名称,如:user, product, order
|
||
Action string `json:"action" gorm:"size:50;not null"` // 操作名称,如:create, read, update, delete
|
||
Resource string `json:"resource" gorm:"size:50"` // 资源名称
|
||
Status int `json:"status" gorm:"default:1"` // 0禁用,1正常
|
||
CreatedAt time.Time `json:"created_at"`
|
||
UpdatedAt time.Time `json:"updated_at"`
|
||
|
||
// 关联数据
|
||
Roles []Role `json:"roles,omitempty" gorm:"many2many:ai_role_permissions;"`
|
||
}
|
||
|
||
// UserRole 用户角色关联
|
||
type UserRole struct {
|
||
ID uint `json:"id" gorm:"primaryKey;autoIncrement"`
|
||
UserID uint `json:"user_id" gorm:"not null"`
|
||
RoleID uint `json:"role_id" gorm:"not null"`
|
||
CreatedAt time.Time `json:"created_at"`
|
||
UpdatedAt time.Time `json:"updated_at"`
|
||
|
||
// 关联数据
|
||
User User `json:"user,omitempty" gorm:"foreignKey:UserID"`
|
||
Role Role `json:"role,omitempty" gorm:"foreignKey:RoleID"`
|
||
}
|
||
|
||
// RolePermission 角色权限关联
|
||
type RolePermission struct {
|
||
ID uint `json:"id" gorm:"primaryKey;autoIncrement"`
|
||
RoleID uint `json:"role_id" gorm:"not null"`
|
||
PermissionID uint `json:"permission_id" gorm:"not null"`
|
||
CreatedAt time.Time `json:"created_at"`
|
||
UpdatedAt time.Time `json:"updated_at"`
|
||
|
||
// 关联数据
|
||
Role Role `json:"role,omitempty" gorm:"foreignKey:RoleID"`
|
||
Permission Permission `json:"permission,omitempty" gorm:"foreignKey:PermissionID"`
|
||
}
|
||
|
||
// UserLoginLog 用户登录日志
|
||
type UserLoginLog struct {
|
||
ID uint `json:"id" gorm:"primaryKey;autoIncrement"`
|
||
UserID uint `json:"user_id" gorm:"not null"`
|
||
LoginIP string `json:"login_ip" gorm:"size:45"`
|
||
UserAgent string `json:"user_agent" gorm:"size:500"`
|
||
LoginTime time.Time `json:"login_time"`
|
||
Status int `json:"status" gorm:"default:1"` // 1成功,0失败
|
||
Remark string `json:"remark" gorm:"size:255"`
|
||
|
||
// 关联数据
|
||
User User `json:"user,omitempty" gorm:"foreignKey:UserID"`
|
||
}
|
||
|
||
// UserOperationLog 用户操作日志
|
||
type UserOperationLog struct {
|
||
ID uint `json:"id" gorm:"primaryKey;autoIncrement"`
|
||
UserID uint `json:"user_id" gorm:"not null"`
|
||
Module string `json:"module" gorm:"size:50;not null"` // 模块名称
|
||
Action string `json:"action" gorm:"size:50;not null"` // 操作名称
|
||
Description string `json:"description" gorm:"size:255"` // 操作描述
|
||
IP string `json:"ip" gorm:"size:45"` // 操作IP
|
||
UserAgent string `json:"user_agent" gorm:"size:500"` // 用户代理
|
||
RequestData string `json:"request_data" gorm:"type:text"` // 请求数据
|
||
CreatedAt time.Time `json:"created_at"`
|
||
|
||
// 关联数据
|
||
User User `json:"user,omitempty" gorm:"foreignKey:UserID"`
|
||
}
|
||
|
||
// TableName 指定表名
|
||
func (Role) TableName() string {
|
||
return "ai_roles"
|
||
}
|
||
|
||
// TableName 指定表名
|
||
func (Permission) TableName() string {
|
||
return "ai_permissions"
|
||
}
|
||
|
||
// TableName 指定表名
|
||
func (UserRole) TableName() string {
|
||
return "ai_user_roles"
|
||
}
|
||
|
||
// TableName 指定表名
|
||
func (RolePermission) TableName() string {
|
||
return "ai_role_permissions"
|
||
}
|
||
|
||
// TableName 指定表名
|
||
func (UserLoginLog) TableName() string {
|
||
return "ai_user_login_logs"
|
||
}
|
||
|
||
// TableName 指定表名
|
||
func (UserOperationLog) TableName() string {
|
||
return "ai_user_operation_logs"
|
||
} |