label.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package schema
  2. import (
  3. "wechat-api/ent/schema/localmixin"
  4. "entgo.io/ent"
  5. "entgo.io/ent/dialect/entsql"
  6. "entgo.io/ent/schema"
  7. "entgo.io/ent/schema/edge"
  8. "entgo.io/ent/schema/field"
  9. "entgo.io/ent/schema/index"
  10. "github.com/suyuan32/simple-admin-common/orm/ent/mixins"
  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. }
  33. }
  34. func (Label) Mixin() []ent.Mixin {
  35. return []ent.Mixin{
  36. mixins.IDMixin{},
  37. mixins.StatusMixin{},
  38. localmixin.SoftDeleteMixin{},
  39. }
  40. }
  41. func (Label) Indexes() []ent.Index {
  42. return []ent.Index{
  43. index.Fields("name", "from", "mode").Unique(),
  44. }
  45. }
  46. func (Label) Edges() []ent.Edge {
  47. return []ent.Edge{
  48. edge.To("label_relationships", LabelRelationship.Type),
  49. }
  50. }
  51. func (Label) Annotations() []schema.Annotation {
  52. return []schema.Annotation{
  53. entsql.WithComments(true),
  54. entsql.Annotation{Table: "label"},
  55. }
  56. }