fix: rebuild MES as compilable go-zero+ent backend (renamed bj_power_mes), restore 3 workstation projects from pristine original, align naming; all Go projects go build clean
This commit is contained in:
+39
-21
@@ -12,67 +12,85 @@ import (
|
||||
"entgo.io/ent/schema/index"
|
||||
)
|
||||
|
||||
// User 系统用户,包含登录凭据、个人信息及组织归属
|
||||
// User holds the schema definition for the User entity.
|
||||
type User struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
func (User) Annotations() []schema.Annotation {
|
||||
return []schema.Annotation{
|
||||
entsql.Annotation{
|
||||
Table: "user",
|
||||
Options: "COMMENT='用户表,存储系统用户登录凭据、个人信息、角色及部门归属'",
|
||||
},
|
||||
entsql.Annotation{Table: "user"},
|
||||
entsql.WithComments(true),
|
||||
}
|
||||
}
|
||||
|
||||
// Fields of the User.
|
||||
func (User) Fields() []ent.Field {
|
||||
|
||||
//`name` varchar(64) NOT NULL DEFAULT '' COMMENT '姓名, 不能超过64个字符',
|
||||
// `mobile` varchar(15) NULL COMMENT '手机号',
|
||||
// `username` varchar(20) NULL COMMENT '用户名',
|
||||
// `password` varchar(60) NOT NULL DEFAULT '' COMMENT '用户密码',
|
||||
// `gender` int(1) NOT NULL DEFAULT 0 COMMENT '0:未知|1:男|2:女',
|
||||
// `avatar` varchar(255) NOT NULL DEFAULT '' COMMENT '用户头像地址',
|
||||
// `position` varchar(128) NOT NULL DEFAULT '' COMMENT '职位, 不能超过128个字符',
|
||||
// `mail` varchar(64) NOT NULL DEFAULT '' COMMENT '邮箱, 长度不超过64个字节',
|
||||
// `main_department` int(10) NOT NULL DEFAULT 0 COMMENT '主部门',
|
||||
// `status` tinyint(1) NOT NULL DEFAULT 0 COMMENT '企业微信激活状态: 1:已激活|2:已禁用|4:未激活|5:退出企业',
|
||||
// `active` bool NOT NULL DEFAULT false COMMENT '激活',
|
||||
// `active_at` timestamp NULL COMMENT '激活时间',
|
||||
// `disabled_at` timestamp NULL COMMENT '禁用时间',
|
||||
// `last_login_ip` varchar(20) NOT NULL DEFAULT '' COMMENT '最后登录IP',
|
||||
// `last_login_at` timestamp NULL COMMENT '最后登录时间',
|
||||
// `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
// `updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
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("id").Positive(),
|
||||
field.String("name").MaxLen(64).NotEmpty().Comment("姓名"),
|
||||
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("Role 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个字符"),
|
||||
}).Comment("0:未知|1:男|2:女"),
|
||||
field.String("position").MaxLen(20).Optional().Comment("职位"),
|
||||
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("更新时间,每次修改自动更新"),
|
||||
}).Comment("启用状态: 1:已激活|0:已禁用"),
|
||||
field.Int("deptId").Default(1),
|
||||
field.Time("createdAt").Default(time.Now).Immutable().Comment("创建时间"), // 创建时间
|
||||
field.Time("updatedAt").Default(time.Now).UpdateDefault(time.Now).Comment("更新时间"), // 更新时间
|
||||
}
|
||||
}
|
||||
|
||||
// Edges of the User.
|
||||
|
||||
func (User) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.From("role", Role.Type).
|
||||
Ref("users").
|
||||
Unique().
|
||||
Field("roleId").
|
||||
Required().
|
||||
Comment("所属角色"),
|
||||
Required(),
|
||||
edge.From("dept", Department.Type).
|
||||
Ref("users").
|
||||
Unique().
|
||||
Field("deptId").
|
||||
Required().
|
||||
Comment("所属部门"),
|
||||
Required(),
|
||||
}
|
||||
}
|
||||
|
||||
// Indexes of the User.
|
||||
func (User) Indexes() []ent.Index {
|
||||
return []ent.Index{
|
||||
// 非唯一约束索引
|
||||
index.Fields("name"),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user