feat: backend core - auth, user, role, permission, device, webhook, monitoring, cache, repository, service, middleware, API handlers
This commit is contained in:
57
internal/domain/role.go
Normal file
57
internal/domain/role.go
Normal file
@@ -0,0 +1,57 @@
|
||||
package domain
|
||||
|
||||
import "time"
|
||||
|
||||
// RoleStatus 角色状态
|
||||
type RoleStatus int
|
||||
|
||||
const (
|
||||
RoleStatusDisabled RoleStatus = 0 // 禁用
|
||||
RoleStatusEnabled RoleStatus = 1 // 启用
|
||||
)
|
||||
|
||||
// Role 角色模型
|
||||
type Role struct {
|
||||
ID int64 `gorm:"primaryKey;autoIncrement" json:"id"`
|
||||
Name string `gorm:"type:varchar(50);uniqueIndex;not null" json:"name"`
|
||||
Code string `gorm:"type:varchar(50);uniqueIndex;not null" json:"code"`
|
||||
Description string `gorm:"type:varchar(200)" json:"description"`
|
||||
ParentID *int64 `gorm:"index" json:"parent_id,omitempty"`
|
||||
Level int `gorm:"default:1;index" json:"level"`
|
||||
IsSystem bool `gorm:"default:false" json:"is_system"` // 是否系统角色
|
||||
IsDefault bool `gorm:"default:false;index" json:"is_default"` // 是否默认角色
|
||||
Status RoleStatus `gorm:"type:int;default:1" json:"status"`
|
||||
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at"`
|
||||
}
|
||||
|
||||
// TableName 指定表名
|
||||
func (Role) TableName() string {
|
||||
return "roles"
|
||||
}
|
||||
|
||||
// PredefinedRoles 预定义角色
|
||||
var PredefinedRoles = []Role{
|
||||
{
|
||||
ID: 1,
|
||||
Name: "管理员",
|
||||
Code: "admin",
|
||||
Description: "系统管理员角色,拥有所有权限",
|
||||
ParentID: nil,
|
||||
Level: 1,
|
||||
IsSystem: true,
|
||||
IsDefault: false,
|
||||
Status: RoleStatusEnabled,
|
||||
},
|
||||
{
|
||||
ID: 2,
|
||||
Name: "普通用户",
|
||||
Code: "user",
|
||||
Description: "普通用户角色,基本权限",
|
||||
ParentID: nil,
|
||||
Level: 1,
|
||||
IsSystem: true,
|
||||
IsDefault: true,
|
||||
Status: RoleStatusEnabled,
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user