label.go 1.6 KB

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