Files
bj_power/bj_power_wms/schema/user.go
T

36 lines
1.1 KiB
Go
Raw Normal View History

2026-08-28 15:06:01 +08:00
package schema
import (
"entgo.io/ent"
"entgo.io/ent/schema/field"
"entgo.io/ent/schema/index"
)
// User 系统用户(账号与权限)
// 角色 role 控制功能权限:admin(管理员) / operator(库房保管员) / inspector(质检员)。
// 密码以 bcrypt 哈希存储,登录走 JWT。
2026-08-28 15:06:01 +08:00
type User struct {
ent.Schema
}
func (User) Fields() []ent.Field {
return []ent.Field{
field.String("username").Unique().Comment("登录名"),
field.String("password").Comment("密码(哈希)"),
field.String("real_name").Optional().Comment("姓名"),
field.String("role").Default("operator").Comment("角色 admin/operator/inspector"),
field.String("dept").Optional().Comment("部门"),
field.String("phone").Optional().Comment("电话"),
field.Bool("is_active").Default(true).Comment("是否启用"),
field.Int64("last_login_at").Optional().Comment("最近登录时间"),
field.Int64("created_at").DefaultFunc(nowUnix),
field.Int64("updated_at").DefaultFunc(nowUnix),
}
}
func (User) Indexes() []ent.Index {
return []ent.Index{
index.Fields("role"),
}
}