-
-
Notifications
You must be signed in to change notification settings - Fork 281
/
department.go
61 lines (55 loc) · 1.6 KB
/
department.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package schema
import (
"entgo.io/ent"
"entgo.io/ent/dialect/entsql"
"entgo.io/ent/schema"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
"github.com/suyuan32/simple-admin-common/orm/ent/mixins"
)
type Department struct {
ent.Schema
}
func (Department) Fields() []ent.Field {
return []ent.Field{
field.String("name").
Comment("Department name | 部门名称").
Annotations(entsql.WithComments(true)),
field.String("ancestors").
Comment("Parents' IDs | 父级列表").
Annotations(entsql.WithComments(true)),
field.String("leader").
Comment("Department leader | 部门负责人").
Annotations(entsql.WithComments(true)),
field.String("phone").
Comment("Leader's phone number | 负责人电话").
Annotations(entsql.WithComments(true)),
field.String("email").
Comment("Leader's email | 部门负责人电子邮箱").
Annotations(entsql.WithComments(true)),
field.String("remark").
Comment("Remark | 备注").
Annotations(entsql.WithComments(true)),
field.Uint64("parent_id").Optional().Default(0).
Comment("Parent department ID | 父级部门ID").
Annotations(entsql.WithComments(true)),
}
}
func (Department) Mixin() []ent.Mixin {
return []ent.Mixin{
mixins.BaseIDMixin{},
mixins.StatusMixin{},
mixins.SortMixin{},
}
}
func (Department) Edges() []ent.Edge {
return []ent.Edge{
edge.To("children", Department.Type).From("parent").Unique().Field("parent_id"),
edge.From("users", User.Type).Ref("departments"),
}
}
func (Department) Annotations() []schema.Annotation {
return []schema.Annotation{
entsql.Annotation{Table: "sys_departments"},
}
}