chore: init bj_power monorepo (dashboard/mes/wms/wms_client/workstation), clear subproject git metadata and align naming to folder names
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/entsql"
|
||||
"entgo.io/ent/schema"
|
||||
"entgo.io/ent/schema/edge"
|
||||
"entgo.io/ent/schema/field"
|
||||
"entgo.io/ent/schema/index"
|
||||
)
|
||||
|
||||
// User 系统用户,包含登录凭据、个人信息及组织归属
|
||||
type User struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
func (User) Annotations() []schema.Annotation {
|
||||
return []schema.Annotation{
|
||||
entsql.Annotation{
|
||||
Table: "user",
|
||||
Options: "COMMENT='用户表,存储系统用户登录凭据、个人信息、角色及部门归属'",
|
||||
},
|
||||
entsql.WithComments(true),
|
||||
}
|
||||
}
|
||||
|
||||
func (User) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.Int("id").Positive().Comment("主键ID"),
|
||||
field.String("name").MaxLen(64).NotEmpty().Comment("姓名,不超过64个字符"),
|
||||
field.String("mobile").MaxLen(15).NotEmpty().Unique().Comment("手机号,唯一,用于登录和通知"),
|
||||
field.String("username").MaxLen(20).NotEmpty().Unique().Comment("用户名,唯一,用于系统登录"),
|
||||
field.String("password").MaxLen(60).NotEmpty().Comment("登录密码,bcrypt 哈希存储"),
|
||||
field.Int("roleId").Comment("角色ID,关联角色表"),
|
||||
field.Int("gender").Default(0).Validate(func(i int) error {
|
||||
if i != 0 && i != 1 && i != 2 {
|
||||
return fmt.Errorf("invalid gender value: %d", i)
|
||||
}
|
||||
return nil
|
||||
}).Comment("性别:0=未知 / 1=男 / 2=女"),
|
||||
field.String("position").MaxLen(20).Optional().Comment("职位名称,不超过20个字符"),
|
||||
field.Int("status").Validate(func(i int) error {
|
||||
if i != 0 && i != 1 {
|
||||
return fmt.Errorf("status must be 0 or 1, got %d", i)
|
||||
}
|
||||
return nil
|
||||
}).Comment("启用状态:0=已禁用 / 1=已激活"),
|
||||
field.Int("deptId").Default(1).Comment("所属部门ID,关联部门表"),
|
||||
field.Time("createdAt").Default(time.Now).Immutable().Comment("创建时间"),
|
||||
field.Time("updatedAt").Default(time.Now).UpdateDefault(time.Now).Comment("更新时间,每次修改自动更新"),
|
||||
}
|
||||
}
|
||||
|
||||
func (User) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.From("role", Role.Type).
|
||||
Ref("users").
|
||||
Unique().
|
||||
Field("roleId").
|
||||
Required().
|
||||
Comment("所属角色"),
|
||||
edge.From("dept", Department.Type).
|
||||
Ref("users").
|
||||
Unique().
|
||||
Field("deptId").
|
||||
Required().
|
||||
Comment("所属部门"),
|
||||
}
|
||||
}
|
||||
|
||||
func (User) Indexes() []ent.Index {
|
||||
return []ent.Index{
|
||||
index.Fields("name"),
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user