label.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package schema
  2. import (
  3. "entgo.io/ent"
  4. "entgo.io/ent/dialect/entsql"
  5. "entgo.io/ent/schema"
  6. "entgo.io/ent/schema/edge"
  7. "entgo.io/ent/schema/field"
  8. "entgo.io/ent/schema/index"
  9. "github.com/suyuan32/simple-admin-common/orm/ent/mixins"
  10. "wechat-api/ent/schema/localmixin"
  11. )
  12. type Label struct {
  13. ent.Schema
  14. }
  15. func (Label) Fields() []ent.Field {
  16. return []ent.Field{
  17. field.Int("type").Default(1).
  18. Annotations(entsql.WithComments(true)).
  19. Comment("标签类型:1好友,2群组,3公众号,4企业微信联系人"),
  20. field.String("name").Default("").
  21. Annotations(entsql.WithComments(true)).
  22. Comment("标签名称"),
  23. field.Int("from").Default(1).
  24. Annotations(entsql.WithComments(true)).
  25. Comment("标签来源:1后台创建 2个微同步"),
  26. field.Int("mode").Default(1).
  27. Annotations(entsql.WithComments(true)).
  28. Comment("标签模式:1动态 2静态"),
  29. field.String("conditions").Optional().Default("").
  30. Annotations(entsql.WithComments(true)).
  31. Comment("标签的触达条件"),
  32. field.Uint64("organization_id").Optional().Default(1).
  33. Comment("机构 ID").
  34. Annotations(entsql.WithComments(true)),
  35. }
  36. }
  37. func (Label) Mixin() []ent.Mixin {
  38. return []ent.Mixin{
  39. mixins.IDMixin{},
  40. mixins.StatusMixin{},
  41. localmixin.SoftDeleteMixin{},
  42. }
  43. }
  44. func (Label) Indexes() []ent.Index {
  45. return []ent.Index{
  46. index.Fields("name", "organization_id").Unique(),
  47. }
  48. }
  49. func (Label) Edges() []ent.Edge {
  50. return []ent.Edge{
  51. edge.To("label_relationships", LabelRelationship.Type),
  52. }
  53. }
  54. func (Label) Annotations() []schema.Annotation {
  55. return []schema.Annotation{
  56. entsql.WithComments(true),
  57. entsql.Annotation{Table: "label"},
  58. }
  59. }