2026-08-28 15:06:01 +08:00
|
|
|
package schema
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"entgo.io/ent"
|
|
|
|
|
"entgo.io/ent/schema/field"
|
|
|
|
|
"entgo.io/ent/schema/index"
|
|
|
|
|
)
|
|
|
|
|
|
2026-09-02 08:21:11 +08:00
|
|
|
// 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("姓名"),
|
2026-09-03 14:20:37 +08:00
|
|
|
field.String("role").Default("operator").Comment("角色 admin/operator/inspector(旧字段,权限数据化后由 role_id 决定,此字段仅作兼容/展示)"),
|
|
|
|
|
field.Int("role_id").Optional().Comment("角色ID,关联 roles 表;为空时回退按 role 字符串取权限"),
|
2026-08-28 15:06:01 +08:00
|
|
|
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"),
|
|
|
|
|
}
|
|
|
|
|
}
|