42 lines
1.4 KiB
Go
42 lines
1.4 KiB
Go
package schema
|
||||
|
|
|
|||
|
|
import (
|
|||
|
|
"entgo.io/ent"
|
|||
|
|
"entgo.io/ent/dialect"
|
|||
|
|
"entgo.io/ent/dialect/entsql"
|
|||
|
|
"entgo.io/ent/schema"
|
|||
|
|
"entgo.io/ent/schema/field"
|
|||
|
|
"entgo.io/ent/schema/index"
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
// Role 角色:承载菜单/按钮权限
|
|||
|
|
// 模型移植自 MES(schema/role.go),但按 WMS 约定调整:
|
|||
|
|
// - 字段名 snake_case(由 tools/generate.go 统一转 camelCase 输出 JSON)
|
|||
|
|
// - 时间字段用 Int64 unix 秒,与 WMS 其余表保持一致
|
|||
|
|
// - 与 MES 的差异:MES 的角色/权限为"系统预置只读",WMS 要求可维护,故支持增删改
|
|||
|
|
type Role struct {
|
|||
|
|
ent.Schema
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
func (Role) Annotations() []schema.Annotation {
|
|||
|
|
return []schema.Annotation{entsql.Annotation{Table: "roles"}}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
func (Role) Fields() []ent.Field {
|
|||
|
|
return []ent.Field{
|
|||
|
|
field.String("name").MaxLen(64).Comment("角色名称"),
|
|||
|
|
field.String("code").Unique().MaxLen(64).Comment("角色编码,如 admin/operator/inspector"),
|
|||
|
|
field.String("remark").Default("").MaxLen(255).Optional().Comment("备注"),
|
|||
|
|
// 权限编码列表,如 inbound:view / inbound:create
|
|||
|
|
field.JSON("permission_codes", []string{}).Optional().SchemaType(map[string]string{
|
|||
|
|
dialect.Postgres: "jsonb",
|
|||
|
|
}).Comment("权限编码列表"),
|
|||
|
|
field.Int64("created_at").DefaultFunc(nowUnix).Comment("创建时间"),
|
|||
|
|
field.Int64("updated_at").DefaultFunc(nowUnix).Comment("更新时间"),
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
func (Role) Indexes() []ent.Index {
|
|||
|
|
return []ent.Index{index.Fields("code").Unique()}
|
|||
|
|
}
|