Browse Source

增加多租户功能

boweniac 8 months ago
parent
commit
9da58f0873
92 changed files with 2749 additions and 745 deletions
  1. 9 0
      desc/wechat/label_relationship.api
  2. 3 0
      desc/wechat/message_records.api
  3. 3 0
      desc/wechat/sop_stage.api
  4. 3 0
      desc/wechat/wx.api
  5. 2 4
      ent/client.go
  6. 12 1
      ent/contact.go
  7. 10 0
      ent/contact/contact.go
  8. 55 0
      ent/contact/where.go
  9. 102 0
      ent/contact_create.go
  10. 72 0
      ent/contact_update.go
  11. 13 13
      ent/label.go
  12. 10 16
      ent/label/label.go
  13. 55 55
      ent/label/where.go
  14. 104 89
      ent/label_create.go
  15. 76 68
      ent/label_update.go
  16. 12 1
      ent/labelrelationship.go
  17. 10 0
      ent/labelrelationship/labelrelationship.go
  18. 55 0
      ent/labelrelationship/where.go
  19. 102 0
      ent/labelrelationship_create.go
  20. 72 0
      ent/labelrelationship_update.go
  21. 12 1
      ent/messagerecords.go
  22. 10 0
      ent/messagerecords/messagerecords.go
  23. 55 0
      ent/messagerecords/where.go
  24. 102 0
      ent/messagerecords_create.go
  25. 72 0
      ent/messagerecords_update.go
  26. 16 11
      ent/migrate/schema.go
  27. 519 92
      ent/mutation.go
  28. 24 4
      ent/runtime/runtime.go
  29. 3 0
      ent/schema/contact.go
  30. 3 3
      ent/schema/label.go
  31. 3 0
      ent/schema/label_relationship.go
  32. 3 0
      ent/schema/message_records.go
  33. 3 0
      ent/schema/sop_task.go
  34. 3 0
      ent/schema/wx.go
  35. 141 21
      ent/set_not_nil.go
  36. 12 1
      ent/soptask.go
  37. 10 0
      ent/soptask/soptask.go
  38. 55 0
      ent/soptask/where.go
  39. 102 0
      ent/soptask_create.go
  40. 72 0
      ent/soptask_update.go
  41. 12 1
      ent/wx.go
  42. 55 0
      ent/wx/where.go
  43. 10 0
      ent/wx/wx.go
  44. 102 0
      ent/wx_create.go
  45. 72 0
      ent/wx_update.go
  46. 2 1
      internal/logic/Wx/create_wx_logic.go
  47. 2 1
      internal/logic/Wx/delete_wx_logic.go
  48. 31 24
      internal/logic/Wx/get_wx_by_id_logic.go
  49. 23 19
      internal/logic/Wx/get_wx_list_logic.go
  50. 19 17
      internal/logic/Wx/update_wx_logic.go
  51. 2 1
      internal/logic/Wxhook/get_friends_and_groups_logic.go
  52. 2 2
      internal/logic/contact/add_new_friend_logic.go
  53. 24 22
      internal/logic/contact/create_contact_logic.go
  54. 10 9
      internal/logic/contact/delete_contact_logic.go
  55. 36 31
      internal/logic/contact/get_contact_by_id_logic.go
  56. 2 0
      internal/logic/contact/get_contact_list_logic.go
  57. 24 23
      internal/logic/contact/update_contact_logic.go
  58. 2 1
      internal/logic/label/create_label_logic.go
  59. 31 14
      internal/logic/label/delete_label_logic.go
  60. 26 21
      internal/logic/label/get_label_by_id_logic.go
  61. 2 0
      internal/logic/label/get_label_contacts_logic.go
  62. 2 0
      internal/logic/label/get_label_list_logic.go
  63. 2 0
      internal/logic/label/get_label_select_list_logic.go
  64. 14 13
      internal/logic/label/update_label_logic.go
  65. 11 9
      internal/logic/label_relationship/create_label_relationship_logic.go
  66. 10 10
      internal/logic/label_relationship/delete_label_relationship_logic.go
  67. 23 17
      internal/logic/label_relationship/get_label_relationship_by_id_logic.go
  68. 3 0
      internal/logic/label_relationship/get_label_relationship_list_logic.go
  69. 11 9
      internal/logic/label_relationship/update_label_relationship_logic.go
  70. 16 9
      internal/logic/label_relationship/update_label_relationships_logic.go
  71. 2 0
      internal/logic/message_records/create_message_records_logic.go
  72. 10 9
      internal/logic/message_records/delete_message_records_logic.go
  73. 32 26
      internal/logic/message_records/get_message_records_by_id_logic.go
  74. 22 21
      internal/logic/message_records/get_message_records_list_logic.go
  75. 20 18
      internal/logic/message_records/update_message_records_logic.go
  76. 2 1
      internal/logic/sop_node/create_sop_node_logic.go
  77. 2 1
      internal/logic/sop_node/delete_sop_node_logic.go
  78. 2 1
      internal/logic/sop_node/update_sop_node_logic.go
  79. 5 1
      internal/logic/sop_stage/create_sop_stage_logic.go
  80. 2 1
      internal/logic/sop_stage/delete_sop_stage_logic.go
  81. 2 1
      internal/logic/sop_stage/update_sop_stage_logic.go
  82. 4 0
      internal/logic/sop_task/create_sop_task_logic.go
  83. 10 9
      internal/logic/sop_task/delete_sop_task_logic.go
  84. 2 1
      internal/logic/sop_task/get_sop_task_by_id_logic.go
  85. 2 1
      internal/logic/sop_task/get_sop_task_detail_logic.go
  86. 2 3
      internal/logic/sop_task/get_sop_task_list_logic.go
  87. 13 4
      internal/logic/sop_task/publish_sop_task_logic.go
  88. 8 1
      internal/logic/sop_task/sop_task_start_logic.go
  89. 8 1
      internal/logic/sop_task/sop_task_stop_logic.go
  90. 4 10
      internal/logic/sop_task/update_sop_task_logic.go
  91. 2 1
      internal/middleware/authority_middleware.go
  92. 12 0
      internal/types/types.go

+ 9 - 0
desc/wechat/label_relationship.api

@@ -64,6 +64,9 @@ type (
 
         // Label Relationships | 标签关系
         LabelRelationships []ContactLabelList `json:"labelRelationships,optional"`
+
+        // 组织ID
+        OrganizationId *uint64 `json:"organizationId,optional"`
     }
     // The response data of label information | Label信息
     LabelInfo {
@@ -87,6 +90,9 @@ type (
         // 标签的触达条件
         Conditions  *string `json:"conditions,optional"`
 
+        // 组织ID
+        OrganizationId *uint64 `json:"organizationId,optional"`
+
         // Label Relationships | 标签关系
         LabelRelationships []LabelRelationshipInfo `json:"labelRelationships,optional"`
     }
@@ -108,6 +114,9 @@ type (
 
         // Label information | 标签信息
         Label LabelInfo `json:"label,optional"`
+
+        // 组织ID
+        OrganizationId *uint64 `json:"organizationId,optional"`
     }
     // The response data of label relationship information | LabelRelationship信息
     LabelRelationshipsInfo {

+ 3 - 0
desc/wechat/message_records.api

@@ -43,6 +43,9 @@ type (
 
         // 次源 ID 
         SubSourceId  *uint64 `json:"subSourceId,optional"`
+
+        // 组织ID
+        OrganizationId *uint64 `json:"organizationId,optional"`
     }
 
     // The response data of message records list | MessageRecords列表数据

+ 3 - 0
desc/wechat/sop_stage.api

@@ -66,6 +66,9 @@ type (
 
         // 阶段信息
         StageList  []SopStageInfo `json:"stageList,optional"`
+
+        // 组织ID
+        OrganizationId *uint64 `json:"organizationId,optional"`
     }
 
     // The response data of sop node information | SopNode信息

+ 3 - 0
desc/wechat/wx.api

@@ -34,6 +34,9 @@ type (
 
         // 微信头像 
         HeadBig  *string `json:"headBig,optional"`
+
+        // 组织ID
+        OrganizationId *uint64 `json:"organizationId,optional"`
     }
 
     // The response data of wx list | Wx列表数据

+ 2 - 4
ent/client.go

@@ -726,14 +726,12 @@ func (c *LabelClient) QueryLabelRelationships(l *Label) *LabelRelationshipQuery
 
 // Hooks returns the client hooks.
 func (c *LabelClient) Hooks() []Hook {
-	hooks := c.hooks.Label
-	return append(hooks[:len(hooks):len(hooks)], label.Hooks[:]...)
+	return c.hooks.Label
 }
 
 // Interceptors returns the client interceptors.
 func (c *LabelClient) Interceptors() []Interceptor {
-	inters := c.inters.Label
-	return append(inters[:len(inters):len(inters)], label.Interceptors[:]...)
+	return c.inters.Label
 }
 
 func (c *LabelClient) mutate(ctx context.Context, m *LabelMutation) (Value, error) {

+ 12 - 1
ent/contact.go

@@ -55,6 +55,8 @@ type Contact struct {
 	Gname string `json:"gname,omitempty"`
 	// v3数据
 	V3 string `json:"v3,omitempty"`
+	// 机构 ID
+	OrganizationID uint64 `json:"organization_id,omitempty"`
 	// Edges holds the relations/edges for other nodes in the graph.
 	// The values are being populated by the ContactQuery when eager-loading is set.
 	Edges        ContactEdges `json:"edges"`
@@ -95,7 +97,7 @@ func (*Contact) scanValues(columns []string) ([]any, error) {
 	values := make([]any, len(columns))
 	for i := range columns {
 		switch columns[i] {
-		case contact.FieldID, contact.FieldStatus, contact.FieldType, contact.FieldSex, contact.FieldDontseeit, contact.FieldDontseeme:
+		case contact.FieldID, contact.FieldStatus, contact.FieldType, contact.FieldSex, contact.FieldDontseeit, contact.FieldDontseeme, contact.FieldOrganizationID:
 			values[i] = new(sql.NullInt64)
 		case contact.FieldWxWxid, contact.FieldWxid, contact.FieldAccount, contact.FieldNickname, contact.FieldMarkname, contact.FieldHeadimg, contact.FieldStarrole, contact.FieldLag, contact.FieldGid, contact.FieldGname, contact.FieldV3:
 			values[i] = new(sql.NullString)
@@ -236,6 +238,12 @@ func (c *Contact) assignValues(columns []string, values []any) error {
 			} else if value.Valid {
 				c.V3 = value.String
 			}
+		case contact.FieldOrganizationID:
+			if value, ok := values[i].(*sql.NullInt64); !ok {
+				return fmt.Errorf("unexpected type %T for field organization_id", values[i])
+			} else if value.Valid {
+				c.OrganizationID = uint64(value.Int64)
+			}
 		default:
 			c.selectValues.Set(columns[i], values[i])
 		}
@@ -338,6 +346,9 @@ func (c *Contact) String() string {
 	builder.WriteString(", ")
 	builder.WriteString("v3=")
 	builder.WriteString(c.V3)
+	builder.WriteString(", ")
+	builder.WriteString("organization_id=")
+	builder.WriteString(fmt.Sprintf("%v", c.OrganizationID))
 	builder.WriteByte(')')
 	return builder.String()
 }

+ 10 - 0
ent/contact/contact.go

@@ -53,6 +53,8 @@ const (
 	FieldGname = "gname"
 	// FieldV3 holds the string denoting the v3 field in the database.
 	FieldV3 = "v3"
+	// FieldOrganizationID holds the string denoting the organization_id field in the database.
+	FieldOrganizationID = "organization_id"
 	// EdgeContactRelationships holds the string denoting the contact_relationships edge name in mutations.
 	EdgeContactRelationships = "contact_relationships"
 	// EdgeContactMessages holds the string denoting the contact_messages edge name in mutations.
@@ -97,6 +99,7 @@ var Columns = []string{
 	FieldGid,
 	FieldGname,
 	FieldV3,
+	FieldOrganizationID,
 }
 
 // ValidColumn reports if the column name is valid (part of the table columns).
@@ -155,6 +158,8 @@ var (
 	DefaultGname string
 	// DefaultV3 holds the default value on creation for the "v3" field.
 	DefaultV3 string
+	// DefaultOrganizationID holds the default value on creation for the "organization_id" field.
+	DefaultOrganizationID uint64
 )
 
 // OrderOption defines the ordering options for the Contact queries.
@@ -260,6 +265,11 @@ func ByV3(opts ...sql.OrderTermOption) OrderOption {
 	return sql.OrderByField(FieldV3, opts...).ToFunc()
 }
 
+// ByOrganizationID orders the results by the organization_id field.
+func ByOrganizationID(opts ...sql.OrderTermOption) OrderOption {
+	return sql.OrderByField(FieldOrganizationID, opts...).ToFunc()
+}
+
 // ByContactRelationshipsCount orders the results by contact_relationships count.
 func ByContactRelationshipsCount(opts ...sql.OrderTermOption) OrderOption {
 	return func(s *sql.Selector) {

+ 55 - 0
ent/contact/where.go

@@ -150,6 +150,11 @@ func V3(v string) predicate.Contact {
 	return predicate.Contact(sql.FieldEQ(FieldV3, v))
 }
 
+// OrganizationID applies equality check predicate on the "organization_id" field. It's identical to OrganizationIDEQ.
+func OrganizationID(v uint64) predicate.Contact {
+	return predicate.Contact(sql.FieldEQ(FieldOrganizationID, v))
+}
+
 // CreatedAtEQ applies the EQ predicate on the "created_at" field.
 func CreatedAtEQ(v time.Time) predicate.Contact {
 	return predicate.Contact(sql.FieldEQ(FieldCreatedAt, v))
@@ -1225,6 +1230,56 @@ func V3ContainsFold(v string) predicate.Contact {
 	return predicate.Contact(sql.FieldContainsFold(FieldV3, v))
 }
 
+// OrganizationIDEQ applies the EQ predicate on the "organization_id" field.
+func OrganizationIDEQ(v uint64) predicate.Contact {
+	return predicate.Contact(sql.FieldEQ(FieldOrganizationID, v))
+}
+
+// OrganizationIDNEQ applies the NEQ predicate on the "organization_id" field.
+func OrganizationIDNEQ(v uint64) predicate.Contact {
+	return predicate.Contact(sql.FieldNEQ(FieldOrganizationID, v))
+}
+
+// OrganizationIDIn applies the In predicate on the "organization_id" field.
+func OrganizationIDIn(vs ...uint64) predicate.Contact {
+	return predicate.Contact(sql.FieldIn(FieldOrganizationID, vs...))
+}
+
+// OrganizationIDNotIn applies the NotIn predicate on the "organization_id" field.
+func OrganizationIDNotIn(vs ...uint64) predicate.Contact {
+	return predicate.Contact(sql.FieldNotIn(FieldOrganizationID, vs...))
+}
+
+// OrganizationIDGT applies the GT predicate on the "organization_id" field.
+func OrganizationIDGT(v uint64) predicate.Contact {
+	return predicate.Contact(sql.FieldGT(FieldOrganizationID, v))
+}
+
+// OrganizationIDGTE applies the GTE predicate on the "organization_id" field.
+func OrganizationIDGTE(v uint64) predicate.Contact {
+	return predicate.Contact(sql.FieldGTE(FieldOrganizationID, v))
+}
+
+// OrganizationIDLT applies the LT predicate on the "organization_id" field.
+func OrganizationIDLT(v uint64) predicate.Contact {
+	return predicate.Contact(sql.FieldLT(FieldOrganizationID, v))
+}
+
+// OrganizationIDLTE applies the LTE predicate on the "organization_id" field.
+func OrganizationIDLTE(v uint64) predicate.Contact {
+	return predicate.Contact(sql.FieldLTE(FieldOrganizationID, v))
+}
+
+// OrganizationIDIsNil applies the IsNil predicate on the "organization_id" field.
+func OrganizationIDIsNil() predicate.Contact {
+	return predicate.Contact(sql.FieldIsNull(FieldOrganizationID))
+}
+
+// OrganizationIDNotNil applies the NotNil predicate on the "organization_id" field.
+func OrganizationIDNotNil() predicate.Contact {
+	return predicate.Contact(sql.FieldNotNull(FieldOrganizationID))
+}
+
 // HasContactRelationships applies the HasEdge predicate on the "contact_relationships" edge.
 func HasContactRelationships() predicate.Contact {
 	return predicate.Contact(func(s *sql.Selector) {

+ 102 - 0
ent/contact_create.go

@@ -290,6 +290,20 @@ func (cc *ContactCreate) SetNillableV3(s *string) *ContactCreate {
 	return cc
 }
 
+// SetOrganizationID sets the "organization_id" field.
+func (cc *ContactCreate) SetOrganizationID(u uint64) *ContactCreate {
+	cc.mutation.SetOrganizationID(u)
+	return cc
+}
+
+// SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
+func (cc *ContactCreate) SetNillableOrganizationID(u *uint64) *ContactCreate {
+	if u != nil {
+		cc.SetOrganizationID(*u)
+	}
+	return cc
+}
+
 // SetID sets the "id" field.
 func (cc *ContactCreate) SetID(u uint64) *ContactCreate {
 	cc.mutation.SetID(u)
@@ -441,6 +455,10 @@ func (cc *ContactCreate) defaults() error {
 		v := contact.DefaultV3
 		cc.mutation.SetV3(v)
 	}
+	if _, ok := cc.mutation.OrganizationID(); !ok {
+		v := contact.DefaultOrganizationID
+		cc.mutation.SetOrganizationID(v)
+	}
 	return nil
 }
 
@@ -600,6 +618,10 @@ func (cc *ContactCreate) createSpec() (*Contact, *sqlgraph.CreateSpec) {
 		_spec.SetField(contact.FieldV3, field.TypeString, value)
 		_node.V3 = value
 	}
+	if value, ok := cc.mutation.OrganizationID(); ok {
+		_spec.SetField(contact.FieldOrganizationID, field.TypeUint64, value)
+		_node.OrganizationID = value
+	}
 	if nodes := cc.mutation.ContactRelationshipsIDs(); len(nodes) > 0 {
 		edge := &sqlgraph.EdgeSpec{
 			Rel:     sqlgraph.O2M,
@@ -954,6 +976,30 @@ func (u *ContactUpsert) UpdateV3() *ContactUpsert {
 	return u
 }
 
+// SetOrganizationID sets the "organization_id" field.
+func (u *ContactUpsert) SetOrganizationID(v uint64) *ContactUpsert {
+	u.Set(contact.FieldOrganizationID, v)
+	return u
+}
+
+// UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
+func (u *ContactUpsert) UpdateOrganizationID() *ContactUpsert {
+	u.SetExcluded(contact.FieldOrganizationID)
+	return u
+}
+
+// AddOrganizationID adds v to the "organization_id" field.
+func (u *ContactUpsert) AddOrganizationID(v uint64) *ContactUpsert {
+	u.Add(contact.FieldOrganizationID, v)
+	return u
+}
+
+// ClearOrganizationID clears the value of the "organization_id" field.
+func (u *ContactUpsert) ClearOrganizationID() *ContactUpsert {
+	u.SetNull(contact.FieldOrganizationID)
+	return u
+}
+
 // UpdateNewValues updates the mutable fields using the new values that were set on create except the ID field.
 // Using this option is equivalent to using:
 //
@@ -1320,6 +1366,34 @@ func (u *ContactUpsertOne) UpdateV3() *ContactUpsertOne {
 	})
 }
 
+// SetOrganizationID sets the "organization_id" field.
+func (u *ContactUpsertOne) SetOrganizationID(v uint64) *ContactUpsertOne {
+	return u.Update(func(s *ContactUpsert) {
+		s.SetOrganizationID(v)
+	})
+}
+
+// AddOrganizationID adds v to the "organization_id" field.
+func (u *ContactUpsertOne) AddOrganizationID(v uint64) *ContactUpsertOne {
+	return u.Update(func(s *ContactUpsert) {
+		s.AddOrganizationID(v)
+	})
+}
+
+// UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
+func (u *ContactUpsertOne) UpdateOrganizationID() *ContactUpsertOne {
+	return u.Update(func(s *ContactUpsert) {
+		s.UpdateOrganizationID()
+	})
+}
+
+// ClearOrganizationID clears the value of the "organization_id" field.
+func (u *ContactUpsertOne) ClearOrganizationID() *ContactUpsertOne {
+	return u.Update(func(s *ContactUpsert) {
+		s.ClearOrganizationID()
+	})
+}
+
 // Exec executes the query.
 func (u *ContactUpsertOne) Exec(ctx context.Context) error {
 	if len(u.create.conflict) == 0 {
@@ -1852,6 +1926,34 @@ func (u *ContactUpsertBulk) UpdateV3() *ContactUpsertBulk {
 	})
 }
 
+// SetOrganizationID sets the "organization_id" field.
+func (u *ContactUpsertBulk) SetOrganizationID(v uint64) *ContactUpsertBulk {
+	return u.Update(func(s *ContactUpsert) {
+		s.SetOrganizationID(v)
+	})
+}
+
+// AddOrganizationID adds v to the "organization_id" field.
+func (u *ContactUpsertBulk) AddOrganizationID(v uint64) *ContactUpsertBulk {
+	return u.Update(func(s *ContactUpsert) {
+		s.AddOrganizationID(v)
+	})
+}
+
+// UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
+func (u *ContactUpsertBulk) UpdateOrganizationID() *ContactUpsertBulk {
+	return u.Update(func(s *ContactUpsert) {
+		s.UpdateOrganizationID()
+	})
+}
+
+// ClearOrganizationID clears the value of the "organization_id" field.
+func (u *ContactUpsertBulk) ClearOrganizationID() *ContactUpsertBulk {
+	return u.Update(func(s *ContactUpsert) {
+		s.ClearOrganizationID()
+	})
+}
+
 // Exec executes the query.
 func (u *ContactUpsertBulk) Exec(ctx context.Context) error {
 	if u.create.err != nil {

+ 72 - 0
ent/contact_update.go

@@ -333,6 +333,33 @@ func (cu *ContactUpdate) SetNillableV3(s *string) *ContactUpdate {
 	return cu
 }
 
+// SetOrganizationID sets the "organization_id" field.
+func (cu *ContactUpdate) SetOrganizationID(u uint64) *ContactUpdate {
+	cu.mutation.ResetOrganizationID()
+	cu.mutation.SetOrganizationID(u)
+	return cu
+}
+
+// SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
+func (cu *ContactUpdate) SetNillableOrganizationID(u *uint64) *ContactUpdate {
+	if u != nil {
+		cu.SetOrganizationID(*u)
+	}
+	return cu
+}
+
+// AddOrganizationID adds u to the "organization_id" field.
+func (cu *ContactUpdate) AddOrganizationID(u int64) *ContactUpdate {
+	cu.mutation.AddOrganizationID(u)
+	return cu
+}
+
+// ClearOrganizationID clears the value of the "organization_id" field.
+func (cu *ContactUpdate) ClearOrganizationID() *ContactUpdate {
+	cu.mutation.ClearOrganizationID()
+	return cu
+}
+
 // AddContactRelationshipIDs adds the "contact_relationships" edge to the LabelRelationship entity by IDs.
 func (cu *ContactUpdate) AddContactRelationshipIDs(ids ...uint64) *ContactUpdate {
 	cu.mutation.AddContactRelationshipIDs(ids...)
@@ -542,6 +569,15 @@ func (cu *ContactUpdate) sqlSave(ctx context.Context) (n int, err error) {
 	if value, ok := cu.mutation.V3(); ok {
 		_spec.SetField(contact.FieldV3, field.TypeString, value)
 	}
+	if value, ok := cu.mutation.OrganizationID(); ok {
+		_spec.SetField(contact.FieldOrganizationID, field.TypeUint64, value)
+	}
+	if value, ok := cu.mutation.AddedOrganizationID(); ok {
+		_spec.AddField(contact.FieldOrganizationID, field.TypeUint64, value)
+	}
+	if cu.mutation.OrganizationIDCleared() {
+		_spec.ClearField(contact.FieldOrganizationID, field.TypeUint64)
+	}
 	if cu.mutation.ContactRelationshipsCleared() {
 		edge := &sqlgraph.EdgeSpec{
 			Rel:     sqlgraph.O2M,
@@ -955,6 +991,33 @@ func (cuo *ContactUpdateOne) SetNillableV3(s *string) *ContactUpdateOne {
 	return cuo
 }
 
+// SetOrganizationID sets the "organization_id" field.
+func (cuo *ContactUpdateOne) SetOrganizationID(u uint64) *ContactUpdateOne {
+	cuo.mutation.ResetOrganizationID()
+	cuo.mutation.SetOrganizationID(u)
+	return cuo
+}
+
+// SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
+func (cuo *ContactUpdateOne) SetNillableOrganizationID(u *uint64) *ContactUpdateOne {
+	if u != nil {
+		cuo.SetOrganizationID(*u)
+	}
+	return cuo
+}
+
+// AddOrganizationID adds u to the "organization_id" field.
+func (cuo *ContactUpdateOne) AddOrganizationID(u int64) *ContactUpdateOne {
+	cuo.mutation.AddOrganizationID(u)
+	return cuo
+}
+
+// ClearOrganizationID clears the value of the "organization_id" field.
+func (cuo *ContactUpdateOne) ClearOrganizationID() *ContactUpdateOne {
+	cuo.mutation.ClearOrganizationID()
+	return cuo
+}
+
 // AddContactRelationshipIDs adds the "contact_relationships" edge to the LabelRelationship entity by IDs.
 func (cuo *ContactUpdateOne) AddContactRelationshipIDs(ids ...uint64) *ContactUpdateOne {
 	cuo.mutation.AddContactRelationshipIDs(ids...)
@@ -1194,6 +1257,15 @@ func (cuo *ContactUpdateOne) sqlSave(ctx context.Context) (_node *Contact, err e
 	if value, ok := cuo.mutation.V3(); ok {
 		_spec.SetField(contact.FieldV3, field.TypeString, value)
 	}
+	if value, ok := cuo.mutation.OrganizationID(); ok {
+		_spec.SetField(contact.FieldOrganizationID, field.TypeUint64, value)
+	}
+	if value, ok := cuo.mutation.AddedOrganizationID(); ok {
+		_spec.AddField(contact.FieldOrganizationID, field.TypeUint64, value)
+	}
+	if cuo.mutation.OrganizationIDCleared() {
+		_spec.ClearField(contact.FieldOrganizationID, field.TypeUint64)
+	}
 	if cuo.mutation.ContactRelationshipsCleared() {
 		edge := &sqlgraph.EdgeSpec{
 			Rel:     sqlgraph.O2M,

+ 13 - 13
ent/label.go

@@ -23,8 +23,6 @@ type Label struct {
 	UpdatedAt time.Time `json:"updated_at,omitempty"`
 	// Status 1: normal 2: ban | 状态 1 正常 2 禁用
 	Status uint8 `json:"status,omitempty"`
-	// Delete Time | 删除日期
-	DeletedAt time.Time `json:"deleted_at,omitempty"`
 	// 标签类型:1好友,2群组,3公众号,4企业微信联系人
 	Type int `json:"type,omitempty"`
 	// 标签名称
@@ -35,6 +33,8 @@ type Label struct {
 	Mode int `json:"mode,omitempty"`
 	// 标签的触达条件
 	Conditions string `json:"conditions,omitempty"`
+	// 机构 ID
+	OrganizationID uint64 `json:"organization_id,omitempty"`
 	// Edges holds the relations/edges for other nodes in the graph.
 	// The values are being populated by the LabelQuery when eager-loading is set.
 	Edges        LabelEdges `json:"edges"`
@@ -64,11 +64,11 @@ func (*Label) scanValues(columns []string) ([]any, error) {
 	values := make([]any, len(columns))
 	for i := range columns {
 		switch columns[i] {
-		case label.FieldID, label.FieldStatus, label.FieldType, label.FieldFrom, label.FieldMode:
+		case label.FieldID, label.FieldStatus, label.FieldType, label.FieldFrom, label.FieldMode, label.FieldOrganizationID:
 			values[i] = new(sql.NullInt64)
 		case label.FieldName, label.FieldConditions:
 			values[i] = new(sql.NullString)
-		case label.FieldCreatedAt, label.FieldUpdatedAt, label.FieldDeletedAt:
+		case label.FieldCreatedAt, label.FieldUpdatedAt:
 			values[i] = new(sql.NullTime)
 		default:
 			values[i] = new(sql.UnknownType)
@@ -109,12 +109,6 @@ func (l *Label) assignValues(columns []string, values []any) error {
 			} else if value.Valid {
 				l.Status = uint8(value.Int64)
 			}
-		case label.FieldDeletedAt:
-			if value, ok := values[i].(*sql.NullTime); !ok {
-				return fmt.Errorf("unexpected type %T for field deleted_at", values[i])
-			} else if value.Valid {
-				l.DeletedAt = value.Time
-			}
 		case label.FieldType:
 			if value, ok := values[i].(*sql.NullInt64); !ok {
 				return fmt.Errorf("unexpected type %T for field type", values[i])
@@ -145,6 +139,12 @@ func (l *Label) assignValues(columns []string, values []any) error {
 			} else if value.Valid {
 				l.Conditions = value.String
 			}
+		case label.FieldOrganizationID:
+			if value, ok := values[i].(*sql.NullInt64); !ok {
+				return fmt.Errorf("unexpected type %T for field organization_id", values[i])
+			} else if value.Valid {
+				l.OrganizationID = uint64(value.Int64)
+			}
 		default:
 			l.selectValues.Set(columns[i], values[i])
 		}
@@ -195,9 +195,6 @@ func (l *Label) String() string {
 	builder.WriteString("status=")
 	builder.WriteString(fmt.Sprintf("%v", l.Status))
 	builder.WriteString(", ")
-	builder.WriteString("deleted_at=")
-	builder.WriteString(l.DeletedAt.Format(time.ANSIC))
-	builder.WriteString(", ")
 	builder.WriteString("type=")
 	builder.WriteString(fmt.Sprintf("%v", l.Type))
 	builder.WriteString(", ")
@@ -212,6 +209,9 @@ func (l *Label) String() string {
 	builder.WriteString(", ")
 	builder.WriteString("conditions=")
 	builder.WriteString(l.Conditions)
+	builder.WriteString(", ")
+	builder.WriteString("organization_id=")
+	builder.WriteString(fmt.Sprintf("%v", l.OrganizationID))
 	builder.WriteByte(')')
 	return builder.String()
 }

+ 10 - 16
ent/label/label.go

@@ -5,7 +5,6 @@ package label
 import (
 	"time"
 
-	"entgo.io/ent"
 	"entgo.io/ent/dialect/sql"
 	"entgo.io/ent/dialect/sql/sqlgraph"
 )
@@ -21,8 +20,6 @@ const (
 	FieldUpdatedAt = "updated_at"
 	// FieldStatus holds the string denoting the status field in the database.
 	FieldStatus = "status"
-	// FieldDeletedAt holds the string denoting the deleted_at field in the database.
-	FieldDeletedAt = "deleted_at"
 	// FieldType holds the string denoting the type field in the database.
 	FieldType = "type"
 	// FieldName holds the string denoting the name field in the database.
@@ -33,6 +30,8 @@ const (
 	FieldMode = "mode"
 	// FieldConditions holds the string denoting the conditions field in the database.
 	FieldConditions = "conditions"
+	// FieldOrganizationID holds the string denoting the organization_id field in the database.
+	FieldOrganizationID = "organization_id"
 	// EdgeLabelRelationships holds the string denoting the label_relationships edge name in mutations.
 	EdgeLabelRelationships = "label_relationships"
 	// Table holds the table name of the label in the database.
@@ -52,12 +51,12 @@ var Columns = []string{
 	FieldCreatedAt,
 	FieldUpdatedAt,
 	FieldStatus,
-	FieldDeletedAt,
 	FieldType,
 	FieldName,
 	FieldFrom,
 	FieldMode,
 	FieldConditions,
+	FieldOrganizationID,
 }
 
 // ValidColumn reports if the column name is valid (part of the table columns).
@@ -70,14 +69,7 @@ func ValidColumn(column string) bool {
 	return false
 }
 
-// Note that the variables below are initialized by the runtime
-// package on the initialization of the application. Therefore,
-// it should be imported in the main as follows:
-//
-//	import _ "wechat-api/ent/runtime"
 var (
-	Hooks        [1]ent.Hook
-	Interceptors [1]ent.Interceptor
 	// DefaultCreatedAt holds the default value on creation for the "created_at" field.
 	DefaultCreatedAt func() time.Time
 	// DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
@@ -96,6 +88,8 @@ var (
 	DefaultMode int
 	// DefaultConditions holds the default value on creation for the "conditions" field.
 	DefaultConditions string
+	// DefaultOrganizationID holds the default value on creation for the "organization_id" field.
+	DefaultOrganizationID uint64
 )
 
 // OrderOption defines the ordering options for the Label queries.
@@ -121,11 +115,6 @@ func ByStatus(opts ...sql.OrderTermOption) OrderOption {
 	return sql.OrderByField(FieldStatus, opts...).ToFunc()
 }
 
-// ByDeletedAt orders the results by the deleted_at field.
-func ByDeletedAt(opts ...sql.OrderTermOption) OrderOption {
-	return sql.OrderByField(FieldDeletedAt, opts...).ToFunc()
-}
-
 // ByType orders the results by the type field.
 func ByType(opts ...sql.OrderTermOption) OrderOption {
 	return sql.OrderByField(FieldType, opts...).ToFunc()
@@ -151,6 +140,11 @@ func ByConditions(opts ...sql.OrderTermOption) OrderOption {
 	return sql.OrderByField(FieldConditions, opts...).ToFunc()
 }
 
+// ByOrganizationID orders the results by the organization_id field.
+func ByOrganizationID(opts ...sql.OrderTermOption) OrderOption {
+	return sql.OrderByField(FieldOrganizationID, opts...).ToFunc()
+}
+
 // ByLabelRelationshipsCount orders the results by label_relationships count.
 func ByLabelRelationshipsCount(opts ...sql.OrderTermOption) OrderOption {
 	return func(s *sql.Selector) {

+ 55 - 55
ent/label/where.go

@@ -70,11 +70,6 @@ func Status(v uint8) predicate.Label {
 	return predicate.Label(sql.FieldEQ(FieldStatus, v))
 }
 
-// DeletedAt applies equality check predicate on the "deleted_at" field. It's identical to DeletedAtEQ.
-func DeletedAt(v time.Time) predicate.Label {
-	return predicate.Label(sql.FieldEQ(FieldDeletedAt, v))
-}
-
 // Type applies equality check predicate on the "type" field. It's identical to TypeEQ.
 func Type(v int) predicate.Label {
 	return predicate.Label(sql.FieldEQ(FieldType, v))
@@ -100,6 +95,11 @@ func Conditions(v string) predicate.Label {
 	return predicate.Label(sql.FieldEQ(FieldConditions, v))
 }
 
+// OrganizationID applies equality check predicate on the "organization_id" field. It's identical to OrganizationIDEQ.
+func OrganizationID(v uint64) predicate.Label {
+	return predicate.Label(sql.FieldEQ(FieldOrganizationID, v))
+}
+
 // CreatedAtEQ applies the EQ predicate on the "created_at" field.
 func CreatedAtEQ(v time.Time) predicate.Label {
 	return predicate.Label(sql.FieldEQ(FieldCreatedAt, v))
@@ -230,56 +230,6 @@ func StatusNotNil() predicate.Label {
 	return predicate.Label(sql.FieldNotNull(FieldStatus))
 }
 
-// DeletedAtEQ applies the EQ predicate on the "deleted_at" field.
-func DeletedAtEQ(v time.Time) predicate.Label {
-	return predicate.Label(sql.FieldEQ(FieldDeletedAt, v))
-}
-
-// DeletedAtNEQ applies the NEQ predicate on the "deleted_at" field.
-func DeletedAtNEQ(v time.Time) predicate.Label {
-	return predicate.Label(sql.FieldNEQ(FieldDeletedAt, v))
-}
-
-// DeletedAtIn applies the In predicate on the "deleted_at" field.
-func DeletedAtIn(vs ...time.Time) predicate.Label {
-	return predicate.Label(sql.FieldIn(FieldDeletedAt, vs...))
-}
-
-// DeletedAtNotIn applies the NotIn predicate on the "deleted_at" field.
-func DeletedAtNotIn(vs ...time.Time) predicate.Label {
-	return predicate.Label(sql.FieldNotIn(FieldDeletedAt, vs...))
-}
-
-// DeletedAtGT applies the GT predicate on the "deleted_at" field.
-func DeletedAtGT(v time.Time) predicate.Label {
-	return predicate.Label(sql.FieldGT(FieldDeletedAt, v))
-}
-
-// DeletedAtGTE applies the GTE predicate on the "deleted_at" field.
-func DeletedAtGTE(v time.Time) predicate.Label {
-	return predicate.Label(sql.FieldGTE(FieldDeletedAt, v))
-}
-
-// DeletedAtLT applies the LT predicate on the "deleted_at" field.
-func DeletedAtLT(v time.Time) predicate.Label {
-	return predicate.Label(sql.FieldLT(FieldDeletedAt, v))
-}
-
-// DeletedAtLTE applies the LTE predicate on the "deleted_at" field.
-func DeletedAtLTE(v time.Time) predicate.Label {
-	return predicate.Label(sql.FieldLTE(FieldDeletedAt, v))
-}
-
-// DeletedAtIsNil applies the IsNil predicate on the "deleted_at" field.
-func DeletedAtIsNil() predicate.Label {
-	return predicate.Label(sql.FieldIsNull(FieldDeletedAt))
-}
-
-// DeletedAtNotNil applies the NotNil predicate on the "deleted_at" field.
-func DeletedAtNotNil() predicate.Label {
-	return predicate.Label(sql.FieldNotNull(FieldDeletedAt))
-}
-
 // TypeEQ applies the EQ predicate on the "type" field.
 func TypeEQ(v int) predicate.Label {
 	return predicate.Label(sql.FieldEQ(FieldType, v))
@@ -540,6 +490,56 @@ func ConditionsContainsFold(v string) predicate.Label {
 	return predicate.Label(sql.FieldContainsFold(FieldConditions, v))
 }
 
+// OrganizationIDEQ applies the EQ predicate on the "organization_id" field.
+func OrganizationIDEQ(v uint64) predicate.Label {
+	return predicate.Label(sql.FieldEQ(FieldOrganizationID, v))
+}
+
+// OrganizationIDNEQ applies the NEQ predicate on the "organization_id" field.
+func OrganizationIDNEQ(v uint64) predicate.Label {
+	return predicate.Label(sql.FieldNEQ(FieldOrganizationID, v))
+}
+
+// OrganizationIDIn applies the In predicate on the "organization_id" field.
+func OrganizationIDIn(vs ...uint64) predicate.Label {
+	return predicate.Label(sql.FieldIn(FieldOrganizationID, vs...))
+}
+
+// OrganizationIDNotIn applies the NotIn predicate on the "organization_id" field.
+func OrganizationIDNotIn(vs ...uint64) predicate.Label {
+	return predicate.Label(sql.FieldNotIn(FieldOrganizationID, vs...))
+}
+
+// OrganizationIDGT applies the GT predicate on the "organization_id" field.
+func OrganizationIDGT(v uint64) predicate.Label {
+	return predicate.Label(sql.FieldGT(FieldOrganizationID, v))
+}
+
+// OrganizationIDGTE applies the GTE predicate on the "organization_id" field.
+func OrganizationIDGTE(v uint64) predicate.Label {
+	return predicate.Label(sql.FieldGTE(FieldOrganizationID, v))
+}
+
+// OrganizationIDLT applies the LT predicate on the "organization_id" field.
+func OrganizationIDLT(v uint64) predicate.Label {
+	return predicate.Label(sql.FieldLT(FieldOrganizationID, v))
+}
+
+// OrganizationIDLTE applies the LTE predicate on the "organization_id" field.
+func OrganizationIDLTE(v uint64) predicate.Label {
+	return predicate.Label(sql.FieldLTE(FieldOrganizationID, v))
+}
+
+// OrganizationIDIsNil applies the IsNil predicate on the "organization_id" field.
+func OrganizationIDIsNil() predicate.Label {
+	return predicate.Label(sql.FieldIsNull(FieldOrganizationID))
+}
+
+// OrganizationIDNotNil applies the NotNil predicate on the "organization_id" field.
+func OrganizationIDNotNil() predicate.Label {
+	return predicate.Label(sql.FieldNotNull(FieldOrganizationID))
+}
+
 // HasLabelRelationships applies the HasEdge predicate on the "label_relationships" edge.
 func HasLabelRelationships() predicate.Label {
 	return predicate.Label(func(s *sql.Selector) {

+ 104 - 89
ent/label_create.go

@@ -65,20 +65,6 @@ func (lc *LabelCreate) SetNillableStatus(u *uint8) *LabelCreate {
 	return lc
 }
 
-// SetDeletedAt sets the "deleted_at" field.
-func (lc *LabelCreate) SetDeletedAt(t time.Time) *LabelCreate {
-	lc.mutation.SetDeletedAt(t)
-	return lc
-}
-
-// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
-func (lc *LabelCreate) SetNillableDeletedAt(t *time.Time) *LabelCreate {
-	if t != nil {
-		lc.SetDeletedAt(*t)
-	}
-	return lc
-}
-
 // SetType sets the "type" field.
 func (lc *LabelCreate) SetType(i int) *LabelCreate {
 	lc.mutation.SetType(i)
@@ -149,6 +135,20 @@ func (lc *LabelCreate) SetNillableConditions(s *string) *LabelCreate {
 	return lc
 }
 
+// SetOrganizationID sets the "organization_id" field.
+func (lc *LabelCreate) SetOrganizationID(u uint64) *LabelCreate {
+	lc.mutation.SetOrganizationID(u)
+	return lc
+}
+
+// SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
+func (lc *LabelCreate) SetNillableOrganizationID(u *uint64) *LabelCreate {
+	if u != nil {
+		lc.SetOrganizationID(*u)
+	}
+	return lc
+}
+
 // SetID sets the "id" field.
 func (lc *LabelCreate) SetID(u uint64) *LabelCreate {
 	lc.mutation.SetID(u)
@@ -177,9 +177,7 @@ func (lc *LabelCreate) Mutation() *LabelMutation {
 
 // Save creates the Label in the database.
 func (lc *LabelCreate) Save(ctx context.Context) (*Label, error) {
-	if err := lc.defaults(); err != nil {
-		return nil, err
-	}
+	lc.defaults()
 	return withHooks(ctx, lc.sqlSave, lc.mutation, lc.hooks)
 }
 
@@ -206,18 +204,12 @@ func (lc *LabelCreate) ExecX(ctx context.Context) {
 }
 
 // defaults sets the default values of the builder before save.
-func (lc *LabelCreate) defaults() error {
+func (lc *LabelCreate) defaults() {
 	if _, ok := lc.mutation.CreatedAt(); !ok {
-		if label.DefaultCreatedAt == nil {
-			return fmt.Errorf("ent: uninitialized label.DefaultCreatedAt (forgotten import ent/runtime?)")
-		}
 		v := label.DefaultCreatedAt()
 		lc.mutation.SetCreatedAt(v)
 	}
 	if _, ok := lc.mutation.UpdatedAt(); !ok {
-		if label.DefaultUpdatedAt == nil {
-			return fmt.Errorf("ent: uninitialized label.DefaultUpdatedAt (forgotten import ent/runtime?)")
-		}
 		v := label.DefaultUpdatedAt()
 		lc.mutation.SetUpdatedAt(v)
 	}
@@ -245,7 +237,10 @@ func (lc *LabelCreate) defaults() error {
 		v := label.DefaultConditions
 		lc.mutation.SetConditions(v)
 	}
-	return nil
+	if _, ok := lc.mutation.OrganizationID(); !ok {
+		v := label.DefaultOrganizationID
+		lc.mutation.SetOrganizationID(v)
+	}
 }
 
 // check runs all checks and user-defined validators on the builder.
@@ -313,10 +308,6 @@ func (lc *LabelCreate) createSpec() (*Label, *sqlgraph.CreateSpec) {
 		_spec.SetField(label.FieldStatus, field.TypeUint8, value)
 		_node.Status = value
 	}
-	if value, ok := lc.mutation.DeletedAt(); ok {
-		_spec.SetField(label.FieldDeletedAt, field.TypeTime, value)
-		_node.DeletedAt = value
-	}
 	if value, ok := lc.mutation.GetType(); ok {
 		_spec.SetField(label.FieldType, field.TypeInt, value)
 		_node.Type = value
@@ -337,6 +328,10 @@ func (lc *LabelCreate) createSpec() (*Label, *sqlgraph.CreateSpec) {
 		_spec.SetField(label.FieldConditions, field.TypeString, value)
 		_node.Conditions = value
 	}
+	if value, ok := lc.mutation.OrganizationID(); ok {
+		_spec.SetField(label.FieldOrganizationID, field.TypeUint64, value)
+		_node.OrganizationID = value
+	}
 	if nodes := lc.mutation.LabelRelationshipsIDs(); len(nodes) > 0 {
 		edge := &sqlgraph.EdgeSpec{
 			Rel:     sqlgraph.O2M,
@@ -441,24 +436,6 @@ func (u *LabelUpsert) ClearStatus() *LabelUpsert {
 	return u
 }
 
-// SetDeletedAt sets the "deleted_at" field.
-func (u *LabelUpsert) SetDeletedAt(v time.Time) *LabelUpsert {
-	u.Set(label.FieldDeletedAt, v)
-	return u
-}
-
-// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
-func (u *LabelUpsert) UpdateDeletedAt() *LabelUpsert {
-	u.SetExcluded(label.FieldDeletedAt)
-	return u
-}
-
-// ClearDeletedAt clears the value of the "deleted_at" field.
-func (u *LabelUpsert) ClearDeletedAt() *LabelUpsert {
-	u.SetNull(label.FieldDeletedAt)
-	return u
-}
-
 // SetType sets the "type" field.
 func (u *LabelUpsert) SetType(v int) *LabelUpsert {
 	u.Set(label.FieldType, v)
@@ -543,6 +520,30 @@ func (u *LabelUpsert) ClearConditions() *LabelUpsert {
 	return u
 }
 
+// SetOrganizationID sets the "organization_id" field.
+func (u *LabelUpsert) SetOrganizationID(v uint64) *LabelUpsert {
+	u.Set(label.FieldOrganizationID, v)
+	return u
+}
+
+// UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
+func (u *LabelUpsert) UpdateOrganizationID() *LabelUpsert {
+	u.SetExcluded(label.FieldOrganizationID)
+	return u
+}
+
+// AddOrganizationID adds v to the "organization_id" field.
+func (u *LabelUpsert) AddOrganizationID(v uint64) *LabelUpsert {
+	u.Add(label.FieldOrganizationID, v)
+	return u
+}
+
+// ClearOrganizationID clears the value of the "organization_id" field.
+func (u *LabelUpsert) ClearOrganizationID() *LabelUpsert {
+	u.SetNull(label.FieldOrganizationID)
+	return u
+}
+
 // UpdateNewValues updates the mutable fields using the new values that were set on create except the ID field.
 // Using this option is equivalent to using:
 //
@@ -636,27 +637,6 @@ func (u *LabelUpsertOne) ClearStatus() *LabelUpsertOne {
 	})
 }
 
-// SetDeletedAt sets the "deleted_at" field.
-func (u *LabelUpsertOne) SetDeletedAt(v time.Time) *LabelUpsertOne {
-	return u.Update(func(s *LabelUpsert) {
-		s.SetDeletedAt(v)
-	})
-}
-
-// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
-func (u *LabelUpsertOne) UpdateDeletedAt() *LabelUpsertOne {
-	return u.Update(func(s *LabelUpsert) {
-		s.UpdateDeletedAt()
-	})
-}
-
-// ClearDeletedAt clears the value of the "deleted_at" field.
-func (u *LabelUpsertOne) ClearDeletedAt() *LabelUpsertOne {
-	return u.Update(func(s *LabelUpsert) {
-		s.ClearDeletedAt()
-	})
-}
-
 // SetType sets the "type" field.
 func (u *LabelUpsertOne) SetType(v int) *LabelUpsertOne {
 	return u.Update(func(s *LabelUpsert) {
@@ -755,6 +735,34 @@ func (u *LabelUpsertOne) ClearConditions() *LabelUpsertOne {
 	})
 }
 
+// SetOrganizationID sets the "organization_id" field.
+func (u *LabelUpsertOne) SetOrganizationID(v uint64) *LabelUpsertOne {
+	return u.Update(func(s *LabelUpsert) {
+		s.SetOrganizationID(v)
+	})
+}
+
+// AddOrganizationID adds v to the "organization_id" field.
+func (u *LabelUpsertOne) AddOrganizationID(v uint64) *LabelUpsertOne {
+	return u.Update(func(s *LabelUpsert) {
+		s.AddOrganizationID(v)
+	})
+}
+
+// UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
+func (u *LabelUpsertOne) UpdateOrganizationID() *LabelUpsertOne {
+	return u.Update(func(s *LabelUpsert) {
+		s.UpdateOrganizationID()
+	})
+}
+
+// ClearOrganizationID clears the value of the "organization_id" field.
+func (u *LabelUpsertOne) ClearOrganizationID() *LabelUpsertOne {
+	return u.Update(func(s *LabelUpsert) {
+		s.ClearOrganizationID()
+	})
+}
+
 // Exec executes the query.
 func (u *LabelUpsertOne) Exec(ctx context.Context) error {
 	if len(u.create.conflict) == 0 {
@@ -1014,27 +1022,6 @@ func (u *LabelUpsertBulk) ClearStatus() *LabelUpsertBulk {
 	})
 }
 
-// SetDeletedAt sets the "deleted_at" field.
-func (u *LabelUpsertBulk) SetDeletedAt(v time.Time) *LabelUpsertBulk {
-	return u.Update(func(s *LabelUpsert) {
-		s.SetDeletedAt(v)
-	})
-}
-
-// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
-func (u *LabelUpsertBulk) UpdateDeletedAt() *LabelUpsertBulk {
-	return u.Update(func(s *LabelUpsert) {
-		s.UpdateDeletedAt()
-	})
-}
-
-// ClearDeletedAt clears the value of the "deleted_at" field.
-func (u *LabelUpsertBulk) ClearDeletedAt() *LabelUpsertBulk {
-	return u.Update(func(s *LabelUpsert) {
-		s.ClearDeletedAt()
-	})
-}
-
 // SetType sets the "type" field.
 func (u *LabelUpsertBulk) SetType(v int) *LabelUpsertBulk {
 	return u.Update(func(s *LabelUpsert) {
@@ -1133,6 +1120,34 @@ func (u *LabelUpsertBulk) ClearConditions() *LabelUpsertBulk {
 	})
 }
 
+// SetOrganizationID sets the "organization_id" field.
+func (u *LabelUpsertBulk) SetOrganizationID(v uint64) *LabelUpsertBulk {
+	return u.Update(func(s *LabelUpsert) {
+		s.SetOrganizationID(v)
+	})
+}
+
+// AddOrganizationID adds v to the "organization_id" field.
+func (u *LabelUpsertBulk) AddOrganizationID(v uint64) *LabelUpsertBulk {
+	return u.Update(func(s *LabelUpsert) {
+		s.AddOrganizationID(v)
+	})
+}
+
+// UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
+func (u *LabelUpsertBulk) UpdateOrganizationID() *LabelUpsertBulk {
+	return u.Update(func(s *LabelUpsert) {
+		s.UpdateOrganizationID()
+	})
+}
+
+// ClearOrganizationID clears the value of the "organization_id" field.
+func (u *LabelUpsertBulk) ClearOrganizationID() *LabelUpsertBulk {
+	return u.Update(func(s *LabelUpsert) {
+		s.ClearOrganizationID()
+	})
+}
+
 // Exec executes the query.
 func (u *LabelUpsertBulk) Exec(ctx context.Context) error {
 	if u.create.err != nil {

+ 76 - 68
ent/label_update.go

@@ -62,26 +62,6 @@ func (lu *LabelUpdate) ClearStatus() *LabelUpdate {
 	return lu
 }
 
-// SetDeletedAt sets the "deleted_at" field.
-func (lu *LabelUpdate) SetDeletedAt(t time.Time) *LabelUpdate {
-	lu.mutation.SetDeletedAt(t)
-	return lu
-}
-
-// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
-func (lu *LabelUpdate) SetNillableDeletedAt(t *time.Time) *LabelUpdate {
-	if t != nil {
-		lu.SetDeletedAt(*t)
-	}
-	return lu
-}
-
-// ClearDeletedAt clears the value of the "deleted_at" field.
-func (lu *LabelUpdate) ClearDeletedAt() *LabelUpdate {
-	lu.mutation.ClearDeletedAt()
-	return lu
-}
-
 // SetType sets the "type" field.
 func (lu *LabelUpdate) SetType(i int) *LabelUpdate {
 	lu.mutation.ResetType()
@@ -179,6 +159,33 @@ func (lu *LabelUpdate) ClearConditions() *LabelUpdate {
 	return lu
 }
 
+// SetOrganizationID sets the "organization_id" field.
+func (lu *LabelUpdate) SetOrganizationID(u uint64) *LabelUpdate {
+	lu.mutation.ResetOrganizationID()
+	lu.mutation.SetOrganizationID(u)
+	return lu
+}
+
+// SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
+func (lu *LabelUpdate) SetNillableOrganizationID(u *uint64) *LabelUpdate {
+	if u != nil {
+		lu.SetOrganizationID(*u)
+	}
+	return lu
+}
+
+// AddOrganizationID adds u to the "organization_id" field.
+func (lu *LabelUpdate) AddOrganizationID(u int64) *LabelUpdate {
+	lu.mutation.AddOrganizationID(u)
+	return lu
+}
+
+// ClearOrganizationID clears the value of the "organization_id" field.
+func (lu *LabelUpdate) ClearOrganizationID() *LabelUpdate {
+	lu.mutation.ClearOrganizationID()
+	return lu
+}
+
 // AddLabelRelationshipIDs adds the "label_relationships" edge to the LabelRelationship entity by IDs.
 func (lu *LabelUpdate) AddLabelRelationshipIDs(ids ...uint64) *LabelUpdate {
 	lu.mutation.AddLabelRelationshipIDs(ids...)
@@ -222,9 +229,7 @@ func (lu *LabelUpdate) RemoveLabelRelationships(l ...*LabelRelationship) *LabelU
 
 // Save executes the query and returns the number of nodes affected by the update operation.
 func (lu *LabelUpdate) Save(ctx context.Context) (int, error) {
-	if err := lu.defaults(); err != nil {
-		return 0, err
-	}
+	lu.defaults()
 	return withHooks(ctx, lu.sqlSave, lu.mutation, lu.hooks)
 }
 
@@ -251,15 +256,11 @@ func (lu *LabelUpdate) ExecX(ctx context.Context) {
 }
 
 // defaults sets the default values of the builder before save.
-func (lu *LabelUpdate) defaults() error {
+func (lu *LabelUpdate) defaults() {
 	if _, ok := lu.mutation.UpdatedAt(); !ok {
-		if label.UpdateDefaultUpdatedAt == nil {
-			return fmt.Errorf("ent: uninitialized label.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
-		}
 		v := label.UpdateDefaultUpdatedAt()
 		lu.mutation.SetUpdatedAt(v)
 	}
-	return nil
 }
 
 func (lu *LabelUpdate) sqlSave(ctx context.Context) (n int, err error) {
@@ -283,12 +284,6 @@ func (lu *LabelUpdate) sqlSave(ctx context.Context) (n int, err error) {
 	if lu.mutation.StatusCleared() {
 		_spec.ClearField(label.FieldStatus, field.TypeUint8)
 	}
-	if value, ok := lu.mutation.DeletedAt(); ok {
-		_spec.SetField(label.FieldDeletedAt, field.TypeTime, value)
-	}
-	if lu.mutation.DeletedAtCleared() {
-		_spec.ClearField(label.FieldDeletedAt, field.TypeTime)
-	}
 	if value, ok := lu.mutation.GetType(); ok {
 		_spec.SetField(label.FieldType, field.TypeInt, value)
 	}
@@ -316,6 +311,15 @@ func (lu *LabelUpdate) sqlSave(ctx context.Context) (n int, err error) {
 	if lu.mutation.ConditionsCleared() {
 		_spec.ClearField(label.FieldConditions, field.TypeString)
 	}
+	if value, ok := lu.mutation.OrganizationID(); ok {
+		_spec.SetField(label.FieldOrganizationID, field.TypeUint64, value)
+	}
+	if value, ok := lu.mutation.AddedOrganizationID(); ok {
+		_spec.AddField(label.FieldOrganizationID, field.TypeUint64, value)
+	}
+	if lu.mutation.OrganizationIDCleared() {
+		_spec.ClearField(label.FieldOrganizationID, field.TypeUint64)
+	}
 	if lu.mutation.LabelRelationshipsCleared() {
 		edge := &sqlgraph.EdgeSpec{
 			Rel:     sqlgraph.O2M,
@@ -414,26 +418,6 @@ func (luo *LabelUpdateOne) ClearStatus() *LabelUpdateOne {
 	return luo
 }
 
-// SetDeletedAt sets the "deleted_at" field.
-func (luo *LabelUpdateOne) SetDeletedAt(t time.Time) *LabelUpdateOne {
-	luo.mutation.SetDeletedAt(t)
-	return luo
-}
-
-// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
-func (luo *LabelUpdateOne) SetNillableDeletedAt(t *time.Time) *LabelUpdateOne {
-	if t != nil {
-		luo.SetDeletedAt(*t)
-	}
-	return luo
-}
-
-// ClearDeletedAt clears the value of the "deleted_at" field.
-func (luo *LabelUpdateOne) ClearDeletedAt() *LabelUpdateOne {
-	luo.mutation.ClearDeletedAt()
-	return luo
-}
-
 // SetType sets the "type" field.
 func (luo *LabelUpdateOne) SetType(i int) *LabelUpdateOne {
 	luo.mutation.ResetType()
@@ -531,6 +515,33 @@ func (luo *LabelUpdateOne) ClearConditions() *LabelUpdateOne {
 	return luo
 }
 
+// SetOrganizationID sets the "organization_id" field.
+func (luo *LabelUpdateOne) SetOrganizationID(u uint64) *LabelUpdateOne {
+	luo.mutation.ResetOrganizationID()
+	luo.mutation.SetOrganizationID(u)
+	return luo
+}
+
+// SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
+func (luo *LabelUpdateOne) SetNillableOrganizationID(u *uint64) *LabelUpdateOne {
+	if u != nil {
+		luo.SetOrganizationID(*u)
+	}
+	return luo
+}
+
+// AddOrganizationID adds u to the "organization_id" field.
+func (luo *LabelUpdateOne) AddOrganizationID(u int64) *LabelUpdateOne {
+	luo.mutation.AddOrganizationID(u)
+	return luo
+}
+
+// ClearOrganizationID clears the value of the "organization_id" field.
+func (luo *LabelUpdateOne) ClearOrganizationID() *LabelUpdateOne {
+	luo.mutation.ClearOrganizationID()
+	return luo
+}
+
 // AddLabelRelationshipIDs adds the "label_relationships" edge to the LabelRelationship entity by IDs.
 func (luo *LabelUpdateOne) AddLabelRelationshipIDs(ids ...uint64) *LabelUpdateOne {
 	luo.mutation.AddLabelRelationshipIDs(ids...)
@@ -587,9 +598,7 @@ func (luo *LabelUpdateOne) Select(field string, fields ...string) *LabelUpdateOn
 
 // Save executes the query and returns the updated Label entity.
 func (luo *LabelUpdateOne) Save(ctx context.Context) (*Label, error) {
-	if err := luo.defaults(); err != nil {
-		return nil, err
-	}
+	luo.defaults()
 	return withHooks(ctx, luo.sqlSave, luo.mutation, luo.hooks)
 }
 
@@ -616,15 +625,11 @@ func (luo *LabelUpdateOne) ExecX(ctx context.Context) {
 }
 
 // defaults sets the default values of the builder before save.
-func (luo *LabelUpdateOne) defaults() error {
+func (luo *LabelUpdateOne) defaults() {
 	if _, ok := luo.mutation.UpdatedAt(); !ok {
-		if label.UpdateDefaultUpdatedAt == nil {
-			return fmt.Errorf("ent: uninitialized label.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
-		}
 		v := label.UpdateDefaultUpdatedAt()
 		luo.mutation.SetUpdatedAt(v)
 	}
-	return nil
 }
 
 func (luo *LabelUpdateOne) sqlSave(ctx context.Context) (_node *Label, err error) {
@@ -665,12 +670,6 @@ func (luo *LabelUpdateOne) sqlSave(ctx context.Context) (_node *Label, err error
 	if luo.mutation.StatusCleared() {
 		_spec.ClearField(label.FieldStatus, field.TypeUint8)
 	}
-	if value, ok := luo.mutation.DeletedAt(); ok {
-		_spec.SetField(label.FieldDeletedAt, field.TypeTime, value)
-	}
-	if luo.mutation.DeletedAtCleared() {
-		_spec.ClearField(label.FieldDeletedAt, field.TypeTime)
-	}
 	if value, ok := luo.mutation.GetType(); ok {
 		_spec.SetField(label.FieldType, field.TypeInt, value)
 	}
@@ -698,6 +697,15 @@ func (luo *LabelUpdateOne) sqlSave(ctx context.Context) (_node *Label, err error
 	if luo.mutation.ConditionsCleared() {
 		_spec.ClearField(label.FieldConditions, field.TypeString)
 	}
+	if value, ok := luo.mutation.OrganizationID(); ok {
+		_spec.SetField(label.FieldOrganizationID, field.TypeUint64, value)
+	}
+	if value, ok := luo.mutation.AddedOrganizationID(); ok {
+		_spec.AddField(label.FieldOrganizationID, field.TypeUint64, value)
+	}
+	if luo.mutation.OrganizationIDCleared() {
+		_spec.ClearField(label.FieldOrganizationID, field.TypeUint64)
+	}
 	if luo.mutation.LabelRelationshipsCleared() {
 		edge := &sqlgraph.EdgeSpec{
 			Rel:     sqlgraph.O2M,

+ 12 - 1
ent/labelrelationship.go

@@ -31,6 +31,8 @@ type LabelRelationship struct {
 	LabelID uint64 `json:"label_id,omitempty"`
 	// 联系人 ID
 	ContactID uint64 `json:"contact_id,omitempty"`
+	// 机构 ID
+	OrganizationID uint64 `json:"organization_id,omitempty"`
 	// Edges holds the relations/edges for other nodes in the graph.
 	// The values are being populated by the LabelRelationshipQuery when eager-loading is set.
 	Edges        LabelRelationshipEdges `json:"edges"`
@@ -75,7 +77,7 @@ func (*LabelRelationship) scanValues(columns []string) ([]any, error) {
 	values := make([]any, len(columns))
 	for i := range columns {
 		switch columns[i] {
-		case labelrelationship.FieldID, labelrelationship.FieldStatus, labelrelationship.FieldLabelID, labelrelationship.FieldContactID:
+		case labelrelationship.FieldID, labelrelationship.FieldStatus, labelrelationship.FieldLabelID, labelrelationship.FieldContactID, labelrelationship.FieldOrganizationID:
 			values[i] = new(sql.NullInt64)
 		case labelrelationship.FieldCreatedAt, labelrelationship.FieldUpdatedAt, labelrelationship.FieldDeletedAt:
 			values[i] = new(sql.NullTime)
@@ -136,6 +138,12 @@ func (lr *LabelRelationship) assignValues(columns []string, values []any) error
 			} else if value.Valid {
 				lr.ContactID = uint64(value.Int64)
 			}
+		case labelrelationship.FieldOrganizationID:
+			if value, ok := values[i].(*sql.NullInt64); !ok {
+				return fmt.Errorf("unexpected type %T for field organization_id", values[i])
+			} else if value.Valid {
+				lr.OrganizationID = uint64(value.Int64)
+			}
 		default:
 			lr.selectValues.Set(columns[i], values[i])
 		}
@@ -199,6 +207,9 @@ func (lr *LabelRelationship) String() string {
 	builder.WriteString(", ")
 	builder.WriteString("contact_id=")
 	builder.WriteString(fmt.Sprintf("%v", lr.ContactID))
+	builder.WriteString(", ")
+	builder.WriteString("organization_id=")
+	builder.WriteString(fmt.Sprintf("%v", lr.OrganizationID))
 	builder.WriteByte(')')
 	return builder.String()
 }

+ 10 - 0
ent/labelrelationship/labelrelationship.go

@@ -27,6 +27,8 @@ const (
 	FieldLabelID = "label_id"
 	// FieldContactID holds the string denoting the contact_id field in the database.
 	FieldContactID = "contact_id"
+	// FieldOrganizationID holds the string denoting the organization_id field in the database.
+	FieldOrganizationID = "organization_id"
 	// EdgeContacts holds the string denoting the contacts edge name in mutations.
 	EdgeContacts = "contacts"
 	// EdgeLabels holds the string denoting the labels edge name in mutations.
@@ -58,6 +60,7 @@ var Columns = []string{
 	FieldDeletedAt,
 	FieldLabelID,
 	FieldContactID,
+	FieldOrganizationID,
 }
 
 // ValidColumn reports if the column name is valid (part of the table columns).
@@ -90,6 +93,8 @@ var (
 	DefaultLabelID uint64
 	// DefaultContactID holds the default value on creation for the "contact_id" field.
 	DefaultContactID uint64
+	// DefaultOrganizationID holds the default value on creation for the "organization_id" field.
+	DefaultOrganizationID uint64
 )
 
 // OrderOption defines the ordering options for the LabelRelationship queries.
@@ -130,6 +135,11 @@ func ByContactID(opts ...sql.OrderTermOption) OrderOption {
 	return sql.OrderByField(FieldContactID, opts...).ToFunc()
 }
 
+// ByOrganizationID orders the results by the organization_id field.
+func ByOrganizationID(opts ...sql.OrderTermOption) OrderOption {
+	return sql.OrderByField(FieldOrganizationID, opts...).ToFunc()
+}
+
 // ByContactsField orders the results by contacts field.
 func ByContactsField(field string, opts ...sql.OrderTermOption) OrderOption {
 	return func(s *sql.Selector) {

+ 55 - 0
ent/labelrelationship/where.go

@@ -85,6 +85,11 @@ func ContactID(v uint64) predicate.LabelRelationship {
 	return predicate.LabelRelationship(sql.FieldEQ(FieldContactID, v))
 }
 
+// OrganizationID applies equality check predicate on the "organization_id" field. It's identical to OrganizationIDEQ.
+func OrganizationID(v uint64) predicate.LabelRelationship {
+	return predicate.LabelRelationship(sql.FieldEQ(FieldOrganizationID, v))
+}
+
 // CreatedAtEQ applies the EQ predicate on the "created_at" field.
 func CreatedAtEQ(v time.Time) predicate.LabelRelationship {
 	return predicate.LabelRelationship(sql.FieldEQ(FieldCreatedAt, v))
@@ -305,6 +310,56 @@ func ContactIDNotIn(vs ...uint64) predicate.LabelRelationship {
 	return predicate.LabelRelationship(sql.FieldNotIn(FieldContactID, vs...))
 }
 
+// OrganizationIDEQ applies the EQ predicate on the "organization_id" field.
+func OrganizationIDEQ(v uint64) predicate.LabelRelationship {
+	return predicate.LabelRelationship(sql.FieldEQ(FieldOrganizationID, v))
+}
+
+// OrganizationIDNEQ applies the NEQ predicate on the "organization_id" field.
+func OrganizationIDNEQ(v uint64) predicate.LabelRelationship {
+	return predicate.LabelRelationship(sql.FieldNEQ(FieldOrganizationID, v))
+}
+
+// OrganizationIDIn applies the In predicate on the "organization_id" field.
+func OrganizationIDIn(vs ...uint64) predicate.LabelRelationship {
+	return predicate.LabelRelationship(sql.FieldIn(FieldOrganizationID, vs...))
+}
+
+// OrganizationIDNotIn applies the NotIn predicate on the "organization_id" field.
+func OrganizationIDNotIn(vs ...uint64) predicate.LabelRelationship {
+	return predicate.LabelRelationship(sql.FieldNotIn(FieldOrganizationID, vs...))
+}
+
+// OrganizationIDGT applies the GT predicate on the "organization_id" field.
+func OrganizationIDGT(v uint64) predicate.LabelRelationship {
+	return predicate.LabelRelationship(sql.FieldGT(FieldOrganizationID, v))
+}
+
+// OrganizationIDGTE applies the GTE predicate on the "organization_id" field.
+func OrganizationIDGTE(v uint64) predicate.LabelRelationship {
+	return predicate.LabelRelationship(sql.FieldGTE(FieldOrganizationID, v))
+}
+
+// OrganizationIDLT applies the LT predicate on the "organization_id" field.
+func OrganizationIDLT(v uint64) predicate.LabelRelationship {
+	return predicate.LabelRelationship(sql.FieldLT(FieldOrganizationID, v))
+}
+
+// OrganizationIDLTE applies the LTE predicate on the "organization_id" field.
+func OrganizationIDLTE(v uint64) predicate.LabelRelationship {
+	return predicate.LabelRelationship(sql.FieldLTE(FieldOrganizationID, v))
+}
+
+// OrganizationIDIsNil applies the IsNil predicate on the "organization_id" field.
+func OrganizationIDIsNil() predicate.LabelRelationship {
+	return predicate.LabelRelationship(sql.FieldIsNull(FieldOrganizationID))
+}
+
+// OrganizationIDNotNil applies the NotNil predicate on the "organization_id" field.
+func OrganizationIDNotNil() predicate.LabelRelationship {
+	return predicate.LabelRelationship(sql.FieldNotNull(FieldOrganizationID))
+}
+
 // HasContacts applies the HasEdge predicate on the "contacts" edge.
 func HasContacts() predicate.LabelRelationship {
 	return predicate.LabelRelationship(func(s *sql.Selector) {

+ 102 - 0
ent/labelrelationship_create.go

@@ -108,6 +108,20 @@ func (lrc *LabelRelationshipCreate) SetNillableContactID(u *uint64) *LabelRelati
 	return lrc
 }
 
+// SetOrganizationID sets the "organization_id" field.
+func (lrc *LabelRelationshipCreate) SetOrganizationID(u uint64) *LabelRelationshipCreate {
+	lrc.mutation.SetOrganizationID(u)
+	return lrc
+}
+
+// SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
+func (lrc *LabelRelationshipCreate) SetNillableOrganizationID(u *uint64) *LabelRelationshipCreate {
+	if u != nil {
+		lrc.SetOrganizationID(*u)
+	}
+	return lrc
+}
+
 // SetID sets the "id" field.
 func (lrc *LabelRelationshipCreate) SetID(u uint64) *LabelRelationshipCreate {
 	lrc.mutation.SetID(u)
@@ -199,6 +213,10 @@ func (lrc *LabelRelationshipCreate) defaults() error {
 		v := labelrelationship.DefaultContactID
 		lrc.mutation.SetContactID(v)
 	}
+	if _, ok := lrc.mutation.OrganizationID(); !ok {
+		v := labelrelationship.DefaultOrganizationID
+		lrc.mutation.SetOrganizationID(v)
+	}
 	return nil
 }
 
@@ -271,6 +289,10 @@ func (lrc *LabelRelationshipCreate) createSpec() (*LabelRelationship, *sqlgraph.
 		_spec.SetField(labelrelationship.FieldDeletedAt, field.TypeTime, value)
 		_node.DeletedAt = value
 	}
+	if value, ok := lrc.mutation.OrganizationID(); ok {
+		_spec.SetField(labelrelationship.FieldOrganizationID, field.TypeUint64, value)
+		_node.OrganizationID = value
+	}
 	if nodes := lrc.mutation.ContactsIDs(); len(nodes) > 0 {
 		edge := &sqlgraph.EdgeSpec{
 			Rel:     sqlgraph.M2O,
@@ -435,6 +457,30 @@ func (u *LabelRelationshipUpsert) UpdateContactID() *LabelRelationshipUpsert {
 	return u
 }
 
+// SetOrganizationID sets the "organization_id" field.
+func (u *LabelRelationshipUpsert) SetOrganizationID(v uint64) *LabelRelationshipUpsert {
+	u.Set(labelrelationship.FieldOrganizationID, v)
+	return u
+}
+
+// UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
+func (u *LabelRelationshipUpsert) UpdateOrganizationID() *LabelRelationshipUpsert {
+	u.SetExcluded(labelrelationship.FieldOrganizationID)
+	return u
+}
+
+// AddOrganizationID adds v to the "organization_id" field.
+func (u *LabelRelationshipUpsert) AddOrganizationID(v uint64) *LabelRelationshipUpsert {
+	u.Add(labelrelationship.FieldOrganizationID, v)
+	return u
+}
+
+// ClearOrganizationID clears the value of the "organization_id" field.
+func (u *LabelRelationshipUpsert) ClearOrganizationID() *LabelRelationshipUpsert {
+	u.SetNull(labelrelationship.FieldOrganizationID)
+	return u
+}
+
 // UpdateNewValues updates the mutable fields using the new values that were set on create except the ID field.
 // Using this option is equivalent to using:
 //
@@ -577,6 +623,34 @@ func (u *LabelRelationshipUpsertOne) UpdateContactID() *LabelRelationshipUpsertO
 	})
 }
 
+// SetOrganizationID sets the "organization_id" field.
+func (u *LabelRelationshipUpsertOne) SetOrganizationID(v uint64) *LabelRelationshipUpsertOne {
+	return u.Update(func(s *LabelRelationshipUpsert) {
+		s.SetOrganizationID(v)
+	})
+}
+
+// AddOrganizationID adds v to the "organization_id" field.
+func (u *LabelRelationshipUpsertOne) AddOrganizationID(v uint64) *LabelRelationshipUpsertOne {
+	return u.Update(func(s *LabelRelationshipUpsert) {
+		s.AddOrganizationID(v)
+	})
+}
+
+// UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
+func (u *LabelRelationshipUpsertOne) UpdateOrganizationID() *LabelRelationshipUpsertOne {
+	return u.Update(func(s *LabelRelationshipUpsert) {
+		s.UpdateOrganizationID()
+	})
+}
+
+// ClearOrganizationID clears the value of the "organization_id" field.
+func (u *LabelRelationshipUpsertOne) ClearOrganizationID() *LabelRelationshipUpsertOne {
+	return u.Update(func(s *LabelRelationshipUpsert) {
+		s.ClearOrganizationID()
+	})
+}
+
 // Exec executes the query.
 func (u *LabelRelationshipUpsertOne) Exec(ctx context.Context) error {
 	if len(u.create.conflict) == 0 {
@@ -885,6 +959,34 @@ func (u *LabelRelationshipUpsertBulk) UpdateContactID() *LabelRelationshipUpsert
 	})
 }
 
+// SetOrganizationID sets the "organization_id" field.
+func (u *LabelRelationshipUpsertBulk) SetOrganizationID(v uint64) *LabelRelationshipUpsertBulk {
+	return u.Update(func(s *LabelRelationshipUpsert) {
+		s.SetOrganizationID(v)
+	})
+}
+
+// AddOrganizationID adds v to the "organization_id" field.
+func (u *LabelRelationshipUpsertBulk) AddOrganizationID(v uint64) *LabelRelationshipUpsertBulk {
+	return u.Update(func(s *LabelRelationshipUpsert) {
+		s.AddOrganizationID(v)
+	})
+}
+
+// UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
+func (u *LabelRelationshipUpsertBulk) UpdateOrganizationID() *LabelRelationshipUpsertBulk {
+	return u.Update(func(s *LabelRelationshipUpsert) {
+		s.UpdateOrganizationID()
+	})
+}
+
+// ClearOrganizationID clears the value of the "organization_id" field.
+func (u *LabelRelationshipUpsertBulk) ClearOrganizationID() *LabelRelationshipUpsertBulk {
+	return u.Update(func(s *LabelRelationshipUpsert) {
+		s.ClearOrganizationID()
+	})
+}
+
 // Exec executes the query.
 func (u *LabelRelationshipUpsertBulk) Exec(ctx context.Context) error {
 	if u.create.err != nil {

+ 72 - 0
ent/labelrelationship_update.go

@@ -111,6 +111,33 @@ func (lru *LabelRelationshipUpdate) SetNillableContactID(u *uint64) *LabelRelati
 	return lru
 }
 
+// SetOrganizationID sets the "organization_id" field.
+func (lru *LabelRelationshipUpdate) SetOrganizationID(u uint64) *LabelRelationshipUpdate {
+	lru.mutation.ResetOrganizationID()
+	lru.mutation.SetOrganizationID(u)
+	return lru
+}
+
+// SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
+func (lru *LabelRelationshipUpdate) SetNillableOrganizationID(u *uint64) *LabelRelationshipUpdate {
+	if u != nil {
+		lru.SetOrganizationID(*u)
+	}
+	return lru
+}
+
+// AddOrganizationID adds u to the "organization_id" field.
+func (lru *LabelRelationshipUpdate) AddOrganizationID(u int64) *LabelRelationshipUpdate {
+	lru.mutation.AddOrganizationID(u)
+	return lru
+}
+
+// ClearOrganizationID clears the value of the "organization_id" field.
+func (lru *LabelRelationshipUpdate) ClearOrganizationID() *LabelRelationshipUpdate {
+	lru.mutation.ClearOrganizationID()
+	return lru
+}
+
 // SetContactsID sets the "contacts" edge to the Contact entity by ID.
 func (lru *LabelRelationshipUpdate) SetContactsID(id uint64) *LabelRelationshipUpdate {
 	lru.mutation.SetContactsID(id)
@@ -233,6 +260,15 @@ func (lru *LabelRelationshipUpdate) sqlSave(ctx context.Context) (n int, err err
 	if lru.mutation.DeletedAtCleared() {
 		_spec.ClearField(labelrelationship.FieldDeletedAt, field.TypeTime)
 	}
+	if value, ok := lru.mutation.OrganizationID(); ok {
+		_spec.SetField(labelrelationship.FieldOrganizationID, field.TypeUint64, value)
+	}
+	if value, ok := lru.mutation.AddedOrganizationID(); ok {
+		_spec.AddField(labelrelationship.FieldOrganizationID, field.TypeUint64, value)
+	}
+	if lru.mutation.OrganizationIDCleared() {
+		_spec.ClearField(labelrelationship.FieldOrganizationID, field.TypeUint64)
+	}
 	if lru.mutation.ContactsCleared() {
 		edge := &sqlgraph.EdgeSpec{
 			Rel:     sqlgraph.M2O,
@@ -392,6 +428,33 @@ func (lruo *LabelRelationshipUpdateOne) SetNillableContactID(u *uint64) *LabelRe
 	return lruo
 }
 
+// SetOrganizationID sets the "organization_id" field.
+func (lruo *LabelRelationshipUpdateOne) SetOrganizationID(u uint64) *LabelRelationshipUpdateOne {
+	lruo.mutation.ResetOrganizationID()
+	lruo.mutation.SetOrganizationID(u)
+	return lruo
+}
+
+// SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
+func (lruo *LabelRelationshipUpdateOne) SetNillableOrganizationID(u *uint64) *LabelRelationshipUpdateOne {
+	if u != nil {
+		lruo.SetOrganizationID(*u)
+	}
+	return lruo
+}
+
+// AddOrganizationID adds u to the "organization_id" field.
+func (lruo *LabelRelationshipUpdateOne) AddOrganizationID(u int64) *LabelRelationshipUpdateOne {
+	lruo.mutation.AddOrganizationID(u)
+	return lruo
+}
+
+// ClearOrganizationID clears the value of the "organization_id" field.
+func (lruo *LabelRelationshipUpdateOne) ClearOrganizationID() *LabelRelationshipUpdateOne {
+	lruo.mutation.ClearOrganizationID()
+	return lruo
+}
+
 // SetContactsID sets the "contacts" edge to the Contact entity by ID.
 func (lruo *LabelRelationshipUpdateOne) SetContactsID(id uint64) *LabelRelationshipUpdateOne {
 	lruo.mutation.SetContactsID(id)
@@ -544,6 +607,15 @@ func (lruo *LabelRelationshipUpdateOne) sqlSave(ctx context.Context) (_node *Lab
 	if lruo.mutation.DeletedAtCleared() {
 		_spec.ClearField(labelrelationship.FieldDeletedAt, field.TypeTime)
 	}
+	if value, ok := lruo.mutation.OrganizationID(); ok {
+		_spec.SetField(labelrelationship.FieldOrganizationID, field.TypeUint64, value)
+	}
+	if value, ok := lruo.mutation.AddedOrganizationID(); ok {
+		_spec.AddField(labelrelationship.FieldOrganizationID, field.TypeUint64, value)
+	}
+	if lruo.mutation.OrganizationIDCleared() {
+		_spec.ClearField(labelrelationship.FieldOrganizationID, field.TypeUint64)
+	}
 	if lruo.mutation.ContactsCleared() {
 		edge := &sqlgraph.EdgeSpec{
 			Rel:     sqlgraph.M2O,

+ 12 - 1
ent/messagerecords.go

@@ -54,6 +54,8 @@ type MessageRecords struct {
 	SourceID uint64 `json:"source_id,omitempty"`
 	// 次源 ID
 	SubSourceID uint64 `json:"sub_source_id,omitempty"`
+	// 机构 ID
+	OrganizationID uint64 `json:"organization_id,omitempty"`
 	// Edges holds the relations/edges for other nodes in the graph.
 	// The values are being populated by the MessageRecordsQuery when eager-loading is set.
 	Edges        MessageRecordsEdges `json:"edges"`
@@ -113,7 +115,7 @@ func (*MessageRecords) scanValues(columns []string) ([]any, error) {
 		switch columns[i] {
 		case messagerecords.FieldMeta:
 			values[i] = new([]byte)
-		case messagerecords.FieldID, messagerecords.FieldStatus, messagerecords.FieldContactID, messagerecords.FieldContactType, messagerecords.FieldContentType, messagerecords.FieldSourceType, messagerecords.FieldSourceID, messagerecords.FieldSubSourceID:
+		case messagerecords.FieldID, messagerecords.FieldStatus, messagerecords.FieldContactID, messagerecords.FieldContactType, messagerecords.FieldContentType, messagerecords.FieldSourceType, messagerecords.FieldSourceID, messagerecords.FieldSubSourceID, messagerecords.FieldOrganizationID:
 			values[i] = new(sql.NullInt64)
 		case messagerecords.FieldBotWxid, messagerecords.FieldContactWxid, messagerecords.FieldContent, messagerecords.FieldErrorDetail:
 			values[i] = new(sql.NullString)
@@ -238,6 +240,12 @@ func (mr *MessageRecords) assignValues(columns []string, values []any) error {
 			} else if value.Valid {
 				mr.SubSourceID = uint64(value.Int64)
 			}
+		case messagerecords.FieldOrganizationID:
+			if value, ok := values[i].(*sql.NullInt64); !ok {
+				return fmt.Errorf("unexpected type %T for field organization_id", values[i])
+			} else if value.Valid {
+				mr.OrganizationID = uint64(value.Int64)
+			}
 		default:
 			mr.selectValues.Set(columns[i], values[i])
 		}
@@ -336,6 +344,9 @@ func (mr *MessageRecords) String() string {
 	builder.WriteString(", ")
 	builder.WriteString("sub_source_id=")
 	builder.WriteString(fmt.Sprintf("%v", mr.SubSourceID))
+	builder.WriteString(", ")
+	builder.WriteString("organization_id=")
+	builder.WriteString(fmt.Sprintf("%v", mr.OrganizationID))
 	builder.WriteByte(')')
 	return builder.String()
 }

+ 10 - 0
ent/messagerecords/messagerecords.go

@@ -47,6 +47,8 @@ const (
 	FieldSourceID = "source_id"
 	// FieldSubSourceID holds the string denoting the sub_source_id field in the database.
 	FieldSubSourceID = "sub_source_id"
+	// FieldOrganizationID holds the string denoting the organization_id field in the database.
+	FieldOrganizationID = "organization_id"
 	// EdgeSopStage holds the string denoting the sop_stage edge name in mutations.
 	EdgeSopStage = "sop_stage"
 	// EdgeSopNode holds the string denoting the sop_node edge name in mutations.
@@ -97,6 +99,7 @@ var Columns = []string{
 	FieldSourceType,
 	FieldSourceID,
 	FieldSubSourceID,
+	FieldOrganizationID,
 }
 
 // ValidColumn reports if the column name is valid (part of the table columns).
@@ -141,6 +144,8 @@ var (
 	DefaultSourceID uint64
 	// DefaultSubSourceID holds the default value on creation for the "sub_source_id" field.
 	DefaultSubSourceID uint64
+	// DefaultOrganizationID holds the default value on creation for the "organization_id" field.
+	DefaultOrganizationID uint64
 )
 
 // OrderOption defines the ordering options for the MessageRecords queries.
@@ -226,6 +231,11 @@ func BySubSourceID(opts ...sql.OrderTermOption) OrderOption {
 	return sql.OrderByField(FieldSubSourceID, opts...).ToFunc()
 }
 
+// ByOrganizationID orders the results by the organization_id field.
+func ByOrganizationID(opts ...sql.OrderTermOption) OrderOption {
+	return sql.OrderByField(FieldOrganizationID, opts...).ToFunc()
+}
+
 // BySopStageField orders the results by sop_stage field.
 func BySopStageField(field string, opts ...sql.OrderTermOption) OrderOption {
 	return func(s *sql.Selector) {

+ 55 - 0
ent/messagerecords/where.go

@@ -130,6 +130,11 @@ func SubSourceID(v uint64) predicate.MessageRecords {
 	return predicate.MessageRecords(sql.FieldEQ(FieldSubSourceID, v))
 }
 
+// OrganizationID applies equality check predicate on the "organization_id" field. It's identical to OrganizationIDEQ.
+func OrganizationID(v uint64) predicate.MessageRecords {
+	return predicate.MessageRecords(sql.FieldEQ(FieldOrganizationID, v))
+}
+
 // CreatedAtEQ applies the EQ predicate on the "created_at" field.
 func CreatedAtEQ(v time.Time) predicate.MessageRecords {
 	return predicate.MessageRecords(sql.FieldEQ(FieldCreatedAt, v))
@@ -840,6 +845,56 @@ func SubSourceIDNotNil() predicate.MessageRecords {
 	return predicate.MessageRecords(sql.FieldNotNull(FieldSubSourceID))
 }
 
+// OrganizationIDEQ applies the EQ predicate on the "organization_id" field.
+func OrganizationIDEQ(v uint64) predicate.MessageRecords {
+	return predicate.MessageRecords(sql.FieldEQ(FieldOrganizationID, v))
+}
+
+// OrganizationIDNEQ applies the NEQ predicate on the "organization_id" field.
+func OrganizationIDNEQ(v uint64) predicate.MessageRecords {
+	return predicate.MessageRecords(sql.FieldNEQ(FieldOrganizationID, v))
+}
+
+// OrganizationIDIn applies the In predicate on the "organization_id" field.
+func OrganizationIDIn(vs ...uint64) predicate.MessageRecords {
+	return predicate.MessageRecords(sql.FieldIn(FieldOrganizationID, vs...))
+}
+
+// OrganizationIDNotIn applies the NotIn predicate on the "organization_id" field.
+func OrganizationIDNotIn(vs ...uint64) predicate.MessageRecords {
+	return predicate.MessageRecords(sql.FieldNotIn(FieldOrganizationID, vs...))
+}
+
+// OrganizationIDGT applies the GT predicate on the "organization_id" field.
+func OrganizationIDGT(v uint64) predicate.MessageRecords {
+	return predicate.MessageRecords(sql.FieldGT(FieldOrganizationID, v))
+}
+
+// OrganizationIDGTE applies the GTE predicate on the "organization_id" field.
+func OrganizationIDGTE(v uint64) predicate.MessageRecords {
+	return predicate.MessageRecords(sql.FieldGTE(FieldOrganizationID, v))
+}
+
+// OrganizationIDLT applies the LT predicate on the "organization_id" field.
+func OrganizationIDLT(v uint64) predicate.MessageRecords {
+	return predicate.MessageRecords(sql.FieldLT(FieldOrganizationID, v))
+}
+
+// OrganizationIDLTE applies the LTE predicate on the "organization_id" field.
+func OrganizationIDLTE(v uint64) predicate.MessageRecords {
+	return predicate.MessageRecords(sql.FieldLTE(FieldOrganizationID, v))
+}
+
+// OrganizationIDIsNil applies the IsNil predicate on the "organization_id" field.
+func OrganizationIDIsNil() predicate.MessageRecords {
+	return predicate.MessageRecords(sql.FieldIsNull(FieldOrganizationID))
+}
+
+// OrganizationIDNotNil applies the NotNil predicate on the "organization_id" field.
+func OrganizationIDNotNil() predicate.MessageRecords {
+	return predicate.MessageRecords(sql.FieldNotNull(FieldOrganizationID))
+}
+
 // HasSopStage applies the HasEdge predicate on the "sop_stage" edge.
 func HasSopStage() predicate.MessageRecords {
 	return predicate.MessageRecords(func(s *sql.Selector) {

+ 102 - 0
ent/messagerecords_create.go

@@ -242,6 +242,20 @@ func (mrc *MessageRecordsCreate) SetNillableSubSourceID(u *uint64) *MessageRecor
 	return mrc
 }
 
+// SetOrganizationID sets the "organization_id" field.
+func (mrc *MessageRecordsCreate) SetOrganizationID(u uint64) *MessageRecordsCreate {
+	mrc.mutation.SetOrganizationID(u)
+	return mrc
+}
+
+// SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
+func (mrc *MessageRecordsCreate) SetNillableOrganizationID(u *uint64) *MessageRecordsCreate {
+	if u != nil {
+		mrc.SetOrganizationID(*u)
+	}
+	return mrc
+}
+
 // SetID sets the "id" field.
 func (mrc *MessageRecordsCreate) SetID(u uint64) *MessageRecordsCreate {
 	mrc.mutation.SetID(u)
@@ -392,6 +406,10 @@ func (mrc *MessageRecordsCreate) defaults() error {
 		v := messagerecords.DefaultSubSourceID
 		mrc.mutation.SetSubSourceID(v)
 	}
+	if _, ok := mrc.mutation.OrganizationID(); !ok {
+		v := messagerecords.DefaultOrganizationID
+		mrc.mutation.SetOrganizationID(v)
+	}
 	return nil
 }
 
@@ -509,6 +527,10 @@ func (mrc *MessageRecordsCreate) createSpec() (*MessageRecords, *sqlgraph.Create
 		_spec.SetField(messagerecords.FieldSourceType, field.TypeInt, value)
 		_node.SourceType = value
 	}
+	if value, ok := mrc.mutation.OrganizationID(); ok {
+		_spec.SetField(messagerecords.FieldOrganizationID, field.TypeUint64, value)
+		_node.OrganizationID = value
+	}
 	if nodes := mrc.mutation.SopStageIDs(); len(nodes) > 0 {
 		edge := &sqlgraph.EdgeSpec{
 			Rel:     sqlgraph.M2O,
@@ -858,6 +880,30 @@ func (u *MessageRecordsUpsert) ClearSubSourceID() *MessageRecordsUpsert {
 	return u
 }
 
+// SetOrganizationID sets the "organization_id" field.
+func (u *MessageRecordsUpsert) SetOrganizationID(v uint64) *MessageRecordsUpsert {
+	u.Set(messagerecords.FieldOrganizationID, v)
+	return u
+}
+
+// UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
+func (u *MessageRecordsUpsert) UpdateOrganizationID() *MessageRecordsUpsert {
+	u.SetExcluded(messagerecords.FieldOrganizationID)
+	return u
+}
+
+// AddOrganizationID adds v to the "organization_id" field.
+func (u *MessageRecordsUpsert) AddOrganizationID(v uint64) *MessageRecordsUpsert {
+	u.Add(messagerecords.FieldOrganizationID, v)
+	return u
+}
+
+// ClearOrganizationID clears the value of the "organization_id" field.
+func (u *MessageRecordsUpsert) ClearOrganizationID() *MessageRecordsUpsert {
+	u.SetNull(messagerecords.FieldOrganizationID)
+	return u
+}
+
 // UpdateNewValues updates the mutable fields using the new values that were set on create except the ID field.
 // Using this option is equivalent to using:
 //
@@ -1196,6 +1242,34 @@ func (u *MessageRecordsUpsertOne) ClearSubSourceID() *MessageRecordsUpsertOne {
 	})
 }
 
+// SetOrganizationID sets the "organization_id" field.
+func (u *MessageRecordsUpsertOne) SetOrganizationID(v uint64) *MessageRecordsUpsertOne {
+	return u.Update(func(s *MessageRecordsUpsert) {
+		s.SetOrganizationID(v)
+	})
+}
+
+// AddOrganizationID adds v to the "organization_id" field.
+func (u *MessageRecordsUpsertOne) AddOrganizationID(v uint64) *MessageRecordsUpsertOne {
+	return u.Update(func(s *MessageRecordsUpsert) {
+		s.AddOrganizationID(v)
+	})
+}
+
+// UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
+func (u *MessageRecordsUpsertOne) UpdateOrganizationID() *MessageRecordsUpsertOne {
+	return u.Update(func(s *MessageRecordsUpsert) {
+		s.UpdateOrganizationID()
+	})
+}
+
+// ClearOrganizationID clears the value of the "organization_id" field.
+func (u *MessageRecordsUpsertOne) ClearOrganizationID() *MessageRecordsUpsertOne {
+	return u.Update(func(s *MessageRecordsUpsert) {
+		s.ClearOrganizationID()
+	})
+}
+
 // Exec executes the query.
 func (u *MessageRecordsUpsertOne) Exec(ctx context.Context) error {
 	if len(u.create.conflict) == 0 {
@@ -1700,6 +1774,34 @@ func (u *MessageRecordsUpsertBulk) ClearSubSourceID() *MessageRecordsUpsertBulk
 	})
 }
 
+// SetOrganizationID sets the "organization_id" field.
+func (u *MessageRecordsUpsertBulk) SetOrganizationID(v uint64) *MessageRecordsUpsertBulk {
+	return u.Update(func(s *MessageRecordsUpsert) {
+		s.SetOrganizationID(v)
+	})
+}
+
+// AddOrganizationID adds v to the "organization_id" field.
+func (u *MessageRecordsUpsertBulk) AddOrganizationID(v uint64) *MessageRecordsUpsertBulk {
+	return u.Update(func(s *MessageRecordsUpsert) {
+		s.AddOrganizationID(v)
+	})
+}
+
+// UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
+func (u *MessageRecordsUpsertBulk) UpdateOrganizationID() *MessageRecordsUpsertBulk {
+	return u.Update(func(s *MessageRecordsUpsert) {
+		s.UpdateOrganizationID()
+	})
+}
+
+// ClearOrganizationID clears the value of the "organization_id" field.
+func (u *MessageRecordsUpsertBulk) ClearOrganizationID() *MessageRecordsUpsertBulk {
+	return u.Update(func(s *MessageRecordsUpsert) {
+		s.ClearOrganizationID()
+	})
+}
+
 // Exec executes the query.
 func (u *MessageRecordsUpsertBulk) Exec(ctx context.Context) error {
 	if u.create.err != nil {

+ 72 - 0
ent/messagerecords_update.go

@@ -304,6 +304,33 @@ func (mru *MessageRecordsUpdate) ClearSubSourceID() *MessageRecordsUpdate {
 	return mru
 }
 
+// SetOrganizationID sets the "organization_id" field.
+func (mru *MessageRecordsUpdate) SetOrganizationID(u uint64) *MessageRecordsUpdate {
+	mru.mutation.ResetOrganizationID()
+	mru.mutation.SetOrganizationID(u)
+	return mru
+}
+
+// SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
+func (mru *MessageRecordsUpdate) SetNillableOrganizationID(u *uint64) *MessageRecordsUpdate {
+	if u != nil {
+		mru.SetOrganizationID(*u)
+	}
+	return mru
+}
+
+// AddOrganizationID adds u to the "organization_id" field.
+func (mru *MessageRecordsUpdate) AddOrganizationID(u int64) *MessageRecordsUpdate {
+	mru.mutation.AddOrganizationID(u)
+	return mru
+}
+
+// ClearOrganizationID clears the value of the "organization_id" field.
+func (mru *MessageRecordsUpdate) ClearOrganizationID() *MessageRecordsUpdate {
+	mru.mutation.ClearOrganizationID()
+	return mru
+}
+
 // SetSopStageID sets the "sop_stage" edge to the SopStage entity by ID.
 func (mru *MessageRecordsUpdate) SetSopStageID(id uint64) *MessageRecordsUpdate {
 	mru.mutation.SetSopStageID(id)
@@ -495,6 +522,15 @@ func (mru *MessageRecordsUpdate) sqlSave(ctx context.Context) (n int, err error)
 	if value, ok := mru.mutation.AddedSourceType(); ok {
 		_spec.AddField(messagerecords.FieldSourceType, field.TypeInt, value)
 	}
+	if value, ok := mru.mutation.OrganizationID(); ok {
+		_spec.SetField(messagerecords.FieldOrganizationID, field.TypeUint64, value)
+	}
+	if value, ok := mru.mutation.AddedOrganizationID(); ok {
+		_spec.AddField(messagerecords.FieldOrganizationID, field.TypeUint64, value)
+	}
+	if mru.mutation.OrganizationIDCleared() {
+		_spec.ClearField(messagerecords.FieldOrganizationID, field.TypeUint64)
+	}
 	if mru.mutation.SopStageCleared() {
 		edge := &sqlgraph.EdgeSpec{
 			Rel:     sqlgraph.M2O,
@@ -874,6 +910,33 @@ func (mruo *MessageRecordsUpdateOne) ClearSubSourceID() *MessageRecordsUpdateOne
 	return mruo
 }
 
+// SetOrganizationID sets the "organization_id" field.
+func (mruo *MessageRecordsUpdateOne) SetOrganizationID(u uint64) *MessageRecordsUpdateOne {
+	mruo.mutation.ResetOrganizationID()
+	mruo.mutation.SetOrganizationID(u)
+	return mruo
+}
+
+// SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
+func (mruo *MessageRecordsUpdateOne) SetNillableOrganizationID(u *uint64) *MessageRecordsUpdateOne {
+	if u != nil {
+		mruo.SetOrganizationID(*u)
+	}
+	return mruo
+}
+
+// AddOrganizationID adds u to the "organization_id" field.
+func (mruo *MessageRecordsUpdateOne) AddOrganizationID(u int64) *MessageRecordsUpdateOne {
+	mruo.mutation.AddOrganizationID(u)
+	return mruo
+}
+
+// ClearOrganizationID clears the value of the "organization_id" field.
+func (mruo *MessageRecordsUpdateOne) ClearOrganizationID() *MessageRecordsUpdateOne {
+	mruo.mutation.ClearOrganizationID()
+	return mruo
+}
+
 // SetSopStageID sets the "sop_stage" edge to the SopStage entity by ID.
 func (mruo *MessageRecordsUpdateOne) SetSopStageID(id uint64) *MessageRecordsUpdateOne {
 	mruo.mutation.SetSopStageID(id)
@@ -1095,6 +1158,15 @@ func (mruo *MessageRecordsUpdateOne) sqlSave(ctx context.Context) (_node *Messag
 	if value, ok := mruo.mutation.AddedSourceType(); ok {
 		_spec.AddField(messagerecords.FieldSourceType, field.TypeInt, value)
 	}
+	if value, ok := mruo.mutation.OrganizationID(); ok {
+		_spec.SetField(messagerecords.FieldOrganizationID, field.TypeUint64, value)
+	}
+	if value, ok := mruo.mutation.AddedOrganizationID(); ok {
+		_spec.AddField(messagerecords.FieldOrganizationID, field.TypeUint64, value)
+	}
+	if mruo.mutation.OrganizationIDCleared() {
+		_spec.ClearField(messagerecords.FieldOrganizationID, field.TypeUint64)
+	}
 	if mruo.mutation.SopStageCleared() {
 		edge := &sqlgraph.EdgeSpec{
 			Rel:     sqlgraph.M2O,

+ 16 - 11
ent/migrate/schema.go

@@ -61,6 +61,7 @@ var (
 		{Name: "gid", Type: field.TypeString, Comment: "群组id", Default: ""},
 		{Name: "gname", Type: field.TypeString, Comment: "群组名称", Default: ""},
 		{Name: "v3", Type: field.TypeString, Comment: "v3数据", Default: ""},
+		{Name: "organization_id", Type: field.TypeUint64, Nullable: true, Comment: "机构 ID", Default: 1},
 	}
 	// ContactTable holds the schema information for the "contact" table.
 	ContactTable = &schema.Table{
@@ -96,12 +97,12 @@ var (
 		{Name: "created_at", Type: field.TypeTime, Comment: "Create Time | 创建日期"},
 		{Name: "updated_at", Type: field.TypeTime, Comment: "Update Time | 修改日期"},
 		{Name: "status", Type: field.TypeUint8, Nullable: true, Comment: "Status 1: normal 2: ban | 状态 1 正常 2 禁用", Default: 1},
-		{Name: "deleted_at", Type: field.TypeTime, Nullable: true, Comment: "Delete Time | 删除日期"},
 		{Name: "type", Type: field.TypeInt, Comment: "标签类型:1好友,2群组,3公众号,4企业微信联系人", Default: 1},
 		{Name: "name", Type: field.TypeString, Comment: "标签名称", Default: ""},
 		{Name: "from", Type: field.TypeInt, Comment: "标签来源:1后台创建 2个微同步", Default: 1},
 		{Name: "mode", Type: field.TypeInt, Comment: "标签模式:1动态 2静态", Default: 1},
 		{Name: "conditions", Type: field.TypeString, Nullable: true, Comment: "标签的触达条件", Default: ""},
+		{Name: "organization_id", Type: field.TypeUint64, Nullable: true, Comment: "机构 ID", Default: 1},
 	}
 	// LabelTable holds the schema information for the "label" table.
 	LabelTable = &schema.Table{
@@ -112,7 +113,7 @@ var (
 			{
 				Name:    "label_name_from_mode",
 				Unique:  true,
-				Columns: []*schema.Column{LabelColumns[6], LabelColumns[7], LabelColumns[8]},
+				Columns: []*schema.Column{LabelColumns[5], LabelColumns[6], LabelColumns[7]},
 			},
 		},
 	}
@@ -123,6 +124,7 @@ var (
 		{Name: "updated_at", Type: field.TypeTime, Comment: "Update Time | 修改日期"},
 		{Name: "status", Type: field.TypeUint8, Nullable: true, Comment: "Status 1: normal 2: ban | 状态 1 正常 2 禁用", Default: 1},
 		{Name: "deleted_at", Type: field.TypeTime, Nullable: true, Comment: "Delete Time | 删除日期"},
+		{Name: "organization_id", Type: field.TypeUint64, Nullable: true, Comment: "机构 ID", Default: 1},
 		{Name: "contact_id", Type: field.TypeUint64, Comment: "联系人 ID", Default: 1},
 		{Name: "label_id", Type: field.TypeUint64, Comment: "标签 ID", Default: 1},
 	}
@@ -134,13 +136,13 @@ var (
 		ForeignKeys: []*schema.ForeignKey{
 			{
 				Symbol:     "label_relationship_contact_contact_relationships",
-				Columns:    []*schema.Column{LabelRelationshipColumns[5]},
+				Columns:    []*schema.Column{LabelRelationshipColumns[6]},
 				RefColumns: []*schema.Column{ContactColumns[0]},
 				OnDelete:   schema.NoAction,
 			},
 			{
 				Symbol:     "label_relationship_label_label_relationships",
-				Columns:    []*schema.Column{LabelRelationshipColumns[6]},
+				Columns:    []*schema.Column{LabelRelationshipColumns[7]},
 				RefColumns: []*schema.Column{LabelColumns[0]},
 				OnDelete:   schema.NoAction,
 			},
@@ -149,12 +151,12 @@ var (
 			{
 				Name:    "labelrelationship_label_id",
 				Unique:  false,
-				Columns: []*schema.Column{LabelRelationshipColumns[6]},
+				Columns: []*schema.Column{LabelRelationshipColumns[7]},
 			},
 			{
 				Name:    "labelrelationship_contact_id",
 				Unique:  false,
-				Columns: []*schema.Column{LabelRelationshipColumns[5]},
+				Columns: []*schema.Column{LabelRelationshipColumns[6]},
 			},
 		},
 	}
@@ -187,6 +189,7 @@ var (
 		{Name: "error_detail", Type: field.TypeString, Comment: "异常原因", Default: ""},
 		{Name: "send_time", Type: field.TypeTime, Nullable: true, Comment: "发送时间"},
 		{Name: "source_type", Type: field.TypeInt, Comment: "源类型 1 点发 2 群发 3 SOP", Default: 1},
+		{Name: "organization_id", Type: field.TypeUint64, Nullable: true, Comment: "机构 ID", Default: 1},
 		{Name: "contact_id", Type: field.TypeUint64, Nullable: true, Comment: "联系人 id"},
 		{Name: "sub_source_id", Type: field.TypeUint64, Nullable: true, Comment: "次源 ID", Default: 1},
 		{Name: "source_id", Type: field.TypeUint64, Nullable: true, Comment: "源 ID", Default: 1},
@@ -199,19 +202,19 @@ var (
 		ForeignKeys: []*schema.ForeignKey{
 			{
 				Symbol:     "message_records_contact_contact_messages",
-				Columns:    []*schema.Column{MessageRecordsColumns[14]},
+				Columns:    []*schema.Column{MessageRecordsColumns[15]},
 				RefColumns: []*schema.Column{ContactColumns[0]},
 				OnDelete:   schema.SetNull,
 			},
 			{
 				Symbol:     "message_records_sop_node_node_messages",
-				Columns:    []*schema.Column{MessageRecordsColumns[15]},
+				Columns:    []*schema.Column{MessageRecordsColumns[16]},
 				RefColumns: []*schema.Column{SopNodeColumns[0]},
 				OnDelete:   schema.SetNull,
 			},
 			{
 				Symbol:     "message_records_sop_stage_stage_messages",
-				Columns:    []*schema.Column{MessageRecordsColumns[16]},
+				Columns:    []*schema.Column{MessageRecordsColumns[17]},
 				RefColumns: []*schema.Column{SopStageColumns[0]},
 				OnDelete:   schema.SetNull,
 			},
@@ -382,6 +385,7 @@ var (
 		{Name: "plan_start_time", Type: field.TypeTime, Nullable: true, Comment: "任务计划开始时间"},
 		{Name: "plan_end_time", Type: field.TypeTime, Nullable: true, Comment: "任务计划结束时间"},
 		{Name: "creator_id", Type: field.TypeString, Nullable: true, Comment: "创建者 id"},
+		{Name: "organization_id", Type: field.TypeUint64, Nullable: true, Comment: "机构 ID", Default: 1},
 	}
 	// SopTaskTable holds the schema information for the "sop_task" table.
 	SopTaskTable = &schema.Table{
@@ -411,6 +415,7 @@ var (
 		{Name: "nickname", Type: field.TypeString, Comment: "微信昵称", Default: ""},
 		{Name: "tel", Type: field.TypeString, Comment: "手机号", Default: ""},
 		{Name: "head_big", Type: field.TypeString, Comment: "微信头像", Default: ""},
+		{Name: "organization_id", Type: field.TypeUint64, Nullable: true, Comment: "机构 ID", Default: 1},
 		{Name: "server_id", Type: field.TypeUint64, Nullable: true, Comment: "服务器id", Default: 0},
 	}
 	// WxTable holds the schema information for the "wx" table.
@@ -421,7 +426,7 @@ var (
 		ForeignKeys: []*schema.ForeignKey{
 			{
 				Symbol:     "wx_server_wxs",
-				Columns:    []*schema.Column{WxColumns[13]},
+				Columns:    []*schema.Column{WxColumns[14]},
 				RefColumns: []*schema.Column{ServerColumns[0]},
 				OnDelete:   schema.SetNull,
 			},
@@ -430,7 +435,7 @@ var (
 			{
 				Name:    "wx_server_id_port",
 				Unique:  true,
-				Columns: []*schema.Column{WxColumns[13], WxColumns[5]},
+				Columns: []*schema.Column{WxColumns[14], WxColumns[5]},
 			},
 			{
 				Name:    "wx_wxid",

File diff suppressed because it is too large
+ 519 - 92
ent/mutation.go


+ 24 - 4
ent/runtime/runtime.go

@@ -127,11 +127,11 @@ func init() {
 	contactDescV3 := contactFields[14].Descriptor()
 	// contact.DefaultV3 holds the default value on creation for the v3 field.
 	contact.DefaultV3 = contactDescV3.Default.(string)
+	// contactDescOrganizationID is the schema descriptor for organization_id field.
+	contactDescOrganizationID := contactFields[15].Descriptor()
+	// contact.DefaultOrganizationID holds the default value on creation for the organization_id field.
+	contact.DefaultOrganizationID = contactDescOrganizationID.Default.(uint64)
 	labelMixin := schema.Label{}.Mixin()
-	labelMixinHooks2 := labelMixin[2].Hooks()
-	label.Hooks[0] = labelMixinHooks2[0]
-	labelMixinInters2 := labelMixin[2].Interceptors()
-	label.Interceptors[0] = labelMixinInters2[0]
 	labelMixinFields0 := labelMixin[0].Fields()
 	_ = labelMixinFields0
 	labelMixinFields1 := labelMixin[1].Fields()
@@ -172,6 +172,10 @@ func init() {
 	labelDescConditions := labelFields[4].Descriptor()
 	// label.DefaultConditions holds the default value on creation for the conditions field.
 	label.DefaultConditions = labelDescConditions.Default.(string)
+	// labelDescOrganizationID is the schema descriptor for organization_id field.
+	labelDescOrganizationID := labelFields[5].Descriptor()
+	// label.DefaultOrganizationID holds the default value on creation for the organization_id field.
+	label.DefaultOrganizationID = labelDescOrganizationID.Default.(uint64)
 	labelrelationshipMixin := schema.LabelRelationship{}.Mixin()
 	labelrelationshipMixinHooks2 := labelrelationshipMixin[2].Hooks()
 	labelrelationship.Hooks[0] = labelrelationshipMixinHooks2[0]
@@ -205,6 +209,10 @@ func init() {
 	labelrelationshipDescContactID := labelrelationshipFields[1].Descriptor()
 	// labelrelationship.DefaultContactID holds the default value on creation for the contact_id field.
 	labelrelationship.DefaultContactID = labelrelationshipDescContactID.Default.(uint64)
+	// labelrelationshipDescOrganizationID is the schema descriptor for organization_id field.
+	labelrelationshipDescOrganizationID := labelrelationshipFields[2].Descriptor()
+	// labelrelationship.DefaultOrganizationID holds the default value on creation for the organization_id field.
+	labelrelationship.DefaultOrganizationID = labelrelationshipDescOrganizationID.Default.(uint64)
 	messageFields := schema.Message{}.Fields()
 	_ = messageFields
 	// messageDescWxWxid is the schema descriptor for wx_wxid field.
@@ -276,6 +284,10 @@ func init() {
 	messagerecordsDescSubSourceID := messagerecordsFields[11].Descriptor()
 	// messagerecords.DefaultSubSourceID holds the default value on creation for the sub_source_id field.
 	messagerecords.DefaultSubSourceID = messagerecordsDescSubSourceID.Default.(uint64)
+	// messagerecordsDescOrganizationID is the schema descriptor for organization_id field.
+	messagerecordsDescOrganizationID := messagerecordsFields[12].Descriptor()
+	// messagerecords.DefaultOrganizationID holds the default value on creation for the organization_id field.
+	messagerecords.DefaultOrganizationID = messagerecordsDescOrganizationID.Default.(uint64)
 	msgMixin := schema.Msg{}.Mixin()
 	msgMixinHooks1 := msgMixin[1].Hooks()
 	msg.Hooks[0] = msgMixinHooks1[0]
@@ -431,6 +443,10 @@ func init() {
 	soptaskDescType := soptaskFields[2].Descriptor()
 	// soptask.DefaultType holds the default value on creation for the type field.
 	soptask.DefaultType = soptaskDescType.Default.(int)
+	// soptaskDescOrganizationID is the schema descriptor for organization_id field.
+	soptaskDescOrganizationID := soptaskFields[6].Descriptor()
+	// soptask.DefaultOrganizationID holds the default value on creation for the organization_id field.
+	soptask.DefaultOrganizationID = soptaskDescOrganizationID.Default.(uint64)
 	wxMixin := schema.Wx{}.Mixin()
 	wxMixinHooks2 := wxMixin[2].Hooks()
 	wx.Hooks[0] = wxMixinHooks2[0]
@@ -492,6 +508,10 @@ func init() {
 	wxDescHeadBig := wxFields[8].Descriptor()
 	// wx.DefaultHeadBig holds the default value on creation for the head_big field.
 	wx.DefaultHeadBig = wxDescHeadBig.Default.(string)
+	// wxDescOrganizationID is the schema descriptor for organization_id field.
+	wxDescOrganizationID := wxFields[9].Descriptor()
+	// wx.DefaultOrganizationID holds the default value on creation for the organization_id field.
+	wx.DefaultOrganizationID = wxDescOrganizationID.Default.(uint64)
 }
 
 const (

+ 3 - 0
ent/schema/contact.go

@@ -63,6 +63,9 @@ func (Contact) Fields() []ent.Field {
 		field.String("v3").Default("").
 			Annotations(entsql.WithComments(true)).
 			Comment("v3数据"),
+		field.Uint64("organization_id").Optional().Default(1).
+			Comment("机构 ID").
+			Annotations(entsql.WithComments(true)),
 	}
 }
 

+ 3 - 3
ent/schema/label.go

@@ -1,8 +1,6 @@
 package schema
 
 import (
-	"wechat-api/ent/schema/localmixin"
-
 	"entgo.io/ent"
 	"entgo.io/ent/dialect/entsql"
 	"entgo.io/ent/schema"
@@ -33,6 +31,9 @@ func (Label) Fields() []ent.Field {
 		field.String("conditions").Optional().Default("").
 			Annotations(entsql.WithComments(true)).
 			Comment("标签的触达条件"),
+		field.Uint64("organization_id").Optional().Default(1).
+			Comment("机构 ID").
+			Annotations(entsql.WithComments(true)),
 	}
 }
 
@@ -40,7 +41,6 @@ func (Label) Mixin() []ent.Mixin {
 	return []ent.Mixin{
 		mixins.IDMixin{},
 		mixins.StatusMixin{},
-		localmixin.SoftDeleteMixin{},
 	}
 }
 

+ 3 - 0
ent/schema/label_relationship.go

@@ -24,6 +24,9 @@ func (LabelRelationship) Fields() []ent.Field {
 		field.Uint64("contact_id").Default(1).
 			Annotations(entsql.WithComments(true)).
 			Comment("联系人 ID"),
+		field.Uint64("organization_id").Optional().Default(1).
+			Comment("机构 ID").
+			Annotations(entsql.WithComments(true)),
 	}
 }
 

+ 3 - 0
ent/schema/message_records.go

@@ -55,6 +55,9 @@ func (MessageRecords) Fields() []ent.Field {
 		field.Uint64("sub_source_id").Default(1).Optional().
 			Annotations(entsql.WithComments(true)).
 			Comment("次源 ID"),
+		field.Uint64("organization_id").Optional().Default(1).
+			Comment("机构 ID").
+			Annotations(entsql.WithComments(true)),
 	}
 }
 

+ 3 - 0
ent/schema/sop_task.go

@@ -36,6 +36,9 @@ func (SopTask) Fields() []ent.Field {
 		field.String("creator_id").Optional().
 			Annotations(entsql.WithComments(true)).
 			Comment("创建者 id"),
+		field.Uint64("organization_id").Optional().Default(1).
+			Comment("机构 ID").
+			Annotations(entsql.WithComments(true)),
 	}
 }
 

+ 3 - 0
ent/schema/wx.go

@@ -46,6 +46,9 @@ func (Wx) Fields() []ent.Field {
 		field.String("head_big").Default("").
 			Annotations(entsql.WithComments(true)).
 			Comment("微信头像"),
+		field.Uint64("organization_id").Optional().Default(1).
+			Comment("机构 ID").
+			Annotations(entsql.WithComments(true)),
 	}
 }
 

+ 141 - 21
ent/set_not_nil.go

@@ -728,73 +728,73 @@ func (c *ContactCreate) SetNotNilV3(value *string) *ContactCreate {
 }
 
 // set field if value's pointer is not nil.
-func (l *LabelUpdate) SetNotNilUpdatedAt(value *time.Time) *LabelUpdate {
+func (c *ContactUpdate) SetNotNilOrganizationID(value *uint64) *ContactUpdate {
 	if value != nil {
-		return l.SetUpdatedAt(*value)
+		return c.SetOrganizationID(*value)
 	}
-	return l
+	return c
 }
 
 // set field if value's pointer is not nil.
-func (l *LabelUpdateOne) SetNotNilUpdatedAt(value *time.Time) *LabelUpdateOne {
+func (c *ContactUpdateOne) SetNotNilOrganizationID(value *uint64) *ContactUpdateOne {
 	if value != nil {
-		return l.SetUpdatedAt(*value)
+		return c.SetOrganizationID(*value)
 	}
-	return l
+	return c
 }
 
 // set field if value's pointer is not nil.
-func (l *LabelCreate) SetNotNilUpdatedAt(value *time.Time) *LabelCreate {
+func (c *ContactCreate) SetNotNilOrganizationID(value *uint64) *ContactCreate {
 	if value != nil {
-		return l.SetUpdatedAt(*value)
+		return c.SetOrganizationID(*value)
 	}
-	return l
+	return c
 }
 
 // set field if value's pointer is not nil.
-func (l *LabelUpdate) SetNotNilStatus(value *uint8) *LabelUpdate {
+func (l *LabelUpdate) SetNotNilUpdatedAt(value *time.Time) *LabelUpdate {
 	if value != nil {
-		return l.SetStatus(*value)
+		return l.SetUpdatedAt(*value)
 	}
 	return l
 }
 
 // set field if value's pointer is not nil.
-func (l *LabelUpdateOne) SetNotNilStatus(value *uint8) *LabelUpdateOne {
+func (l *LabelUpdateOne) SetNotNilUpdatedAt(value *time.Time) *LabelUpdateOne {
 	if value != nil {
-		return l.SetStatus(*value)
+		return l.SetUpdatedAt(*value)
 	}
 	return l
 }
 
 // set field if value's pointer is not nil.
-func (l *LabelCreate) SetNotNilStatus(value *uint8) *LabelCreate {
+func (l *LabelCreate) SetNotNilUpdatedAt(value *time.Time) *LabelCreate {
 	if value != nil {
-		return l.SetStatus(*value)
+		return l.SetUpdatedAt(*value)
 	}
 	return l
 }
 
 // set field if value's pointer is not nil.
-func (l *LabelUpdate) SetNotNilDeletedAt(value *time.Time) *LabelUpdate {
+func (l *LabelUpdate) SetNotNilStatus(value *uint8) *LabelUpdate {
 	if value != nil {
-		return l.SetDeletedAt(*value)
+		return l.SetStatus(*value)
 	}
 	return l
 }
 
 // set field if value's pointer is not nil.
-func (l *LabelUpdateOne) SetNotNilDeletedAt(value *time.Time) *LabelUpdateOne {
+func (l *LabelUpdateOne) SetNotNilStatus(value *uint8) *LabelUpdateOne {
 	if value != nil {
-		return l.SetDeletedAt(*value)
+		return l.SetStatus(*value)
 	}
 	return l
 }
 
 // set field if value's pointer is not nil.
-func (l *LabelCreate) SetNotNilDeletedAt(value *time.Time) *LabelCreate {
+func (l *LabelCreate) SetNotNilStatus(value *uint8) *LabelCreate {
 	if value != nil {
-		return l.SetDeletedAt(*value)
+		return l.SetStatus(*value)
 	}
 	return l
 }
@@ -920,6 +920,30 @@ func (l *LabelCreate) SetNotNilConditions(value *string) *LabelCreate {
 }
 
 // set field if value's pointer is not nil.
+func (l *LabelUpdate) SetNotNilOrganizationID(value *uint64) *LabelUpdate {
+	if value != nil {
+		return l.SetOrganizationID(*value)
+	}
+	return l
+}
+
+// set field if value's pointer is not nil.
+func (l *LabelUpdateOne) SetNotNilOrganizationID(value *uint64) *LabelUpdateOne {
+	if value != nil {
+		return l.SetOrganizationID(*value)
+	}
+	return l
+}
+
+// set field if value's pointer is not nil.
+func (l *LabelCreate) SetNotNilOrganizationID(value *uint64) *LabelCreate {
+	if value != nil {
+		return l.SetOrganizationID(*value)
+	}
+	return l
+}
+
+// set field if value's pointer is not nil.
 func (lr *LabelRelationshipUpdate) SetNotNilUpdatedAt(value *time.Time) *LabelRelationshipUpdate {
 	if value != nil {
 		return lr.SetUpdatedAt(*value)
@@ -1040,6 +1064,30 @@ func (lr *LabelRelationshipCreate) SetNotNilContactID(value *uint64) *LabelRelat
 }
 
 // set field if value's pointer is not nil.
+func (lr *LabelRelationshipUpdate) SetNotNilOrganizationID(value *uint64) *LabelRelationshipUpdate {
+	if value != nil {
+		return lr.SetOrganizationID(*value)
+	}
+	return lr
+}
+
+// set field if value's pointer is not nil.
+func (lr *LabelRelationshipUpdateOne) SetNotNilOrganizationID(value *uint64) *LabelRelationshipUpdateOne {
+	if value != nil {
+		return lr.SetOrganizationID(*value)
+	}
+	return lr
+}
+
+// set field if value's pointer is not nil.
+func (lr *LabelRelationshipCreate) SetNotNilOrganizationID(value *uint64) *LabelRelationshipCreate {
+	if value != nil {
+		return lr.SetOrganizationID(*value)
+	}
+	return lr
+}
+
+// set field if value's pointer is not nil.
 func (m *MessageUpdate) SetNotNilWxWxid(value *string) *MessageUpdate {
 	if value != nil {
 		return m.SetWxWxid(*value)
@@ -1472,6 +1520,30 @@ func (mr *MessageRecordsCreate) SetNotNilSubSourceID(value *uint64) *MessageReco
 }
 
 // set field if value's pointer is not nil.
+func (mr *MessageRecordsUpdate) SetNotNilOrganizationID(value *uint64) *MessageRecordsUpdate {
+	if value != nil {
+		return mr.SetOrganizationID(*value)
+	}
+	return mr
+}
+
+// set field if value's pointer is not nil.
+func (mr *MessageRecordsUpdateOne) SetNotNilOrganizationID(value *uint64) *MessageRecordsUpdateOne {
+	if value != nil {
+		return mr.SetOrganizationID(*value)
+	}
+	return mr
+}
+
+// set field if value's pointer is not nil.
+func (mr *MessageRecordsCreate) SetNotNilOrganizationID(value *uint64) *MessageRecordsCreate {
+	if value != nil {
+		return mr.SetOrganizationID(*value)
+	}
+	return mr
+}
+
+// set field if value's pointer is not nil.
 func (m *MsgUpdate) SetNotNilUpdatedAt(value *time.Time) *MsgUpdate {
 	if value != nil {
 		return m.SetUpdatedAt(*value)
@@ -2576,6 +2648,30 @@ func (st *SopTaskCreate) SetNotNilCreatorID(value *string) *SopTaskCreate {
 }
 
 // set field if value's pointer is not nil.
+func (st *SopTaskUpdate) SetNotNilOrganizationID(value *uint64) *SopTaskUpdate {
+	if value != nil {
+		return st.SetOrganizationID(*value)
+	}
+	return st
+}
+
+// set field if value's pointer is not nil.
+func (st *SopTaskUpdateOne) SetNotNilOrganizationID(value *uint64) *SopTaskUpdateOne {
+	if value != nil {
+		return st.SetOrganizationID(*value)
+	}
+	return st
+}
+
+// set field if value's pointer is not nil.
+func (st *SopTaskCreate) SetNotNilOrganizationID(value *uint64) *SopTaskCreate {
+	if value != nil {
+		return st.SetOrganizationID(*value)
+	}
+	return st
+}
+
+// set field if value's pointer is not nil.
 func (w *WxUpdate) SetNotNilUpdatedAt(value *time.Time) *WxUpdate {
 	if value != nil {
 		return w.SetUpdatedAt(*value)
@@ -2862,3 +2958,27 @@ func (w *WxCreate) SetNotNilHeadBig(value *string) *WxCreate {
 	}
 	return w
 }
+
+// set field if value's pointer is not nil.
+func (w *WxUpdate) SetNotNilOrganizationID(value *uint64) *WxUpdate {
+	if value != nil {
+		return w.SetOrganizationID(*value)
+	}
+	return w
+}
+
+// set field if value's pointer is not nil.
+func (w *WxUpdateOne) SetNotNilOrganizationID(value *uint64) *WxUpdateOne {
+	if value != nil {
+		return w.SetOrganizationID(*value)
+	}
+	return w
+}
+
+// set field if value's pointer is not nil.
+func (w *WxCreate) SetNotNilOrganizationID(value *uint64) *WxCreate {
+	if value != nil {
+		return w.SetOrganizationID(*value)
+	}
+	return w
+}

+ 12 - 1
ent/soptask.go

@@ -38,6 +38,8 @@ type SopTask struct {
 	PlanEndTime time.Time `json:"plan_end_time,omitempty"`
 	// 创建者 id
 	CreatorID string `json:"creator_id,omitempty"`
+	// 机构 ID
+	OrganizationID uint64 `json:"organization_id,omitempty"`
 	// Edges holds the relations/edges for other nodes in the graph.
 	// The values are being populated by the SopTaskQuery when eager-loading is set.
 	Edges        SopTaskEdges `json:"edges"`
@@ -69,7 +71,7 @@ func (*SopTask) scanValues(columns []string) ([]any, error) {
 		switch columns[i] {
 		case soptask.FieldBotWxidList:
 			values[i] = new([]byte)
-		case soptask.FieldID, soptask.FieldStatus, soptask.FieldType:
+		case soptask.FieldID, soptask.FieldStatus, soptask.FieldType, soptask.FieldOrganizationID:
 			values[i] = new(sql.NullInt64)
 		case soptask.FieldName, soptask.FieldCreatorID:
 			values[i] = new(sql.NullString)
@@ -158,6 +160,12 @@ func (st *SopTask) assignValues(columns []string, values []any) error {
 			} else if value.Valid {
 				st.CreatorID = value.String
 			}
+		case soptask.FieldOrganizationID:
+			if value, ok := values[i].(*sql.NullInt64); !ok {
+				return fmt.Errorf("unexpected type %T for field organization_id", values[i])
+			} else if value.Valid {
+				st.OrganizationID = uint64(value.Int64)
+			}
 		default:
 			st.selectValues.Set(columns[i], values[i])
 		}
@@ -228,6 +236,9 @@ func (st *SopTask) String() string {
 	builder.WriteString(", ")
 	builder.WriteString("creator_id=")
 	builder.WriteString(st.CreatorID)
+	builder.WriteString(", ")
+	builder.WriteString("organization_id=")
+	builder.WriteString(fmt.Sprintf("%v", st.OrganizationID))
 	builder.WriteByte(')')
 	return builder.String()
 }

+ 10 - 0
ent/soptask/soptask.go

@@ -35,6 +35,8 @@ const (
 	FieldPlanEndTime = "plan_end_time"
 	// FieldCreatorID holds the string denoting the creator_id field in the database.
 	FieldCreatorID = "creator_id"
+	// FieldOrganizationID holds the string denoting the organization_id field in the database.
+	FieldOrganizationID = "organization_id"
 	// EdgeTaskStages holds the string denoting the task_stages edge name in mutations.
 	EdgeTaskStages = "task_stages"
 	// Table holds the table name of the soptask in the database.
@@ -61,6 +63,7 @@ var Columns = []string{
 	FieldPlanStartTime,
 	FieldPlanEndTime,
 	FieldCreatorID,
+	FieldOrganizationID,
 }
 
 // ValidColumn reports if the column name is valid (part of the table columns).
@@ -93,6 +96,8 @@ var (
 	NameValidator func(string) error
 	// DefaultType holds the default value on creation for the "type" field.
 	DefaultType int
+	// DefaultOrganizationID holds the default value on creation for the "organization_id" field.
+	DefaultOrganizationID uint64
 )
 
 // OrderOption defines the ordering options for the SopTask queries.
@@ -148,6 +153,11 @@ func ByCreatorID(opts ...sql.OrderTermOption) OrderOption {
 	return sql.OrderByField(FieldCreatorID, opts...).ToFunc()
 }
 
+// ByOrganizationID orders the results by the organization_id field.
+func ByOrganizationID(opts ...sql.OrderTermOption) OrderOption {
+	return sql.OrderByField(FieldOrganizationID, opts...).ToFunc()
+}
+
 // ByTaskStagesCount orders the results by task_stages count.
 func ByTaskStagesCount(opts ...sql.OrderTermOption) OrderOption {
 	return func(s *sql.Selector) {

+ 55 - 0
ent/soptask/where.go

@@ -100,6 +100,11 @@ func CreatorID(v string) predicate.SopTask {
 	return predicate.SopTask(sql.FieldEQ(FieldCreatorID, v))
 }
 
+// OrganizationID applies equality check predicate on the "organization_id" field. It's identical to OrganizationIDEQ.
+func OrganizationID(v uint64) predicate.SopTask {
+	return predicate.SopTask(sql.FieldEQ(FieldOrganizationID, v))
+}
+
 // CreatedAtEQ applies the EQ predicate on the "created_at" field.
 func CreatedAtEQ(v time.Time) predicate.SopTask {
 	return predicate.SopTask(sql.FieldEQ(FieldCreatedAt, v))
@@ -570,6 +575,56 @@ func CreatorIDContainsFold(v string) predicate.SopTask {
 	return predicate.SopTask(sql.FieldContainsFold(FieldCreatorID, v))
 }
 
+// OrganizationIDEQ applies the EQ predicate on the "organization_id" field.
+func OrganizationIDEQ(v uint64) predicate.SopTask {
+	return predicate.SopTask(sql.FieldEQ(FieldOrganizationID, v))
+}
+
+// OrganizationIDNEQ applies the NEQ predicate on the "organization_id" field.
+func OrganizationIDNEQ(v uint64) predicate.SopTask {
+	return predicate.SopTask(sql.FieldNEQ(FieldOrganizationID, v))
+}
+
+// OrganizationIDIn applies the In predicate on the "organization_id" field.
+func OrganizationIDIn(vs ...uint64) predicate.SopTask {
+	return predicate.SopTask(sql.FieldIn(FieldOrganizationID, vs...))
+}
+
+// OrganizationIDNotIn applies the NotIn predicate on the "organization_id" field.
+func OrganizationIDNotIn(vs ...uint64) predicate.SopTask {
+	return predicate.SopTask(sql.FieldNotIn(FieldOrganizationID, vs...))
+}
+
+// OrganizationIDGT applies the GT predicate on the "organization_id" field.
+func OrganizationIDGT(v uint64) predicate.SopTask {
+	return predicate.SopTask(sql.FieldGT(FieldOrganizationID, v))
+}
+
+// OrganizationIDGTE applies the GTE predicate on the "organization_id" field.
+func OrganizationIDGTE(v uint64) predicate.SopTask {
+	return predicate.SopTask(sql.FieldGTE(FieldOrganizationID, v))
+}
+
+// OrganizationIDLT applies the LT predicate on the "organization_id" field.
+func OrganizationIDLT(v uint64) predicate.SopTask {
+	return predicate.SopTask(sql.FieldLT(FieldOrganizationID, v))
+}
+
+// OrganizationIDLTE applies the LTE predicate on the "organization_id" field.
+func OrganizationIDLTE(v uint64) predicate.SopTask {
+	return predicate.SopTask(sql.FieldLTE(FieldOrganizationID, v))
+}
+
+// OrganizationIDIsNil applies the IsNil predicate on the "organization_id" field.
+func OrganizationIDIsNil() predicate.SopTask {
+	return predicate.SopTask(sql.FieldIsNull(FieldOrganizationID))
+}
+
+// OrganizationIDNotNil applies the NotNil predicate on the "organization_id" field.
+func OrganizationIDNotNil() predicate.SopTask {
+	return predicate.SopTask(sql.FieldNotNull(FieldOrganizationID))
+}
+
 // HasTaskStages applies the HasEdge predicate on the "task_stages" edge.
 func HasTaskStages() predicate.SopTask {
 	return predicate.SopTask(func(s *sql.Selector) {

+ 102 - 0
ent/soptask_create.go

@@ -147,6 +147,20 @@ func (stc *SopTaskCreate) SetNillableCreatorID(s *string) *SopTaskCreate {
 	return stc
 }
 
+// SetOrganizationID sets the "organization_id" field.
+func (stc *SopTaskCreate) SetOrganizationID(u uint64) *SopTaskCreate {
+	stc.mutation.SetOrganizationID(u)
+	return stc
+}
+
+// SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
+func (stc *SopTaskCreate) SetNillableOrganizationID(u *uint64) *SopTaskCreate {
+	if u != nil {
+		stc.SetOrganizationID(*u)
+	}
+	return stc
+}
+
 // SetID sets the "id" field.
 func (stc *SopTaskCreate) SetID(u uint64) *SopTaskCreate {
 	stc.mutation.SetID(u)
@@ -227,6 +241,10 @@ func (stc *SopTaskCreate) defaults() error {
 		v := soptask.DefaultType
 		stc.mutation.SetType(v)
 	}
+	if _, ok := stc.mutation.OrganizationID(); !ok {
+		v := soptask.DefaultOrganizationID
+		stc.mutation.SetOrganizationID(v)
+	}
 	return nil
 }
 
@@ -322,6 +340,10 @@ func (stc *SopTaskCreate) createSpec() (*SopTask, *sqlgraph.CreateSpec) {
 		_spec.SetField(soptask.FieldCreatorID, field.TypeString, value)
 		_node.CreatorID = value
 	}
+	if value, ok := stc.mutation.OrganizationID(); ok {
+		_spec.SetField(soptask.FieldOrganizationID, field.TypeUint64, value)
+		_node.OrganizationID = value
+	}
 	if nodes := stc.mutation.TaskStagesIDs(); len(nodes) > 0 {
 		edge := &sqlgraph.EdgeSpec{
 			Rel:     sqlgraph.O2M,
@@ -546,6 +568,30 @@ func (u *SopTaskUpsert) ClearCreatorID() *SopTaskUpsert {
 	return u
 }
 
+// SetOrganizationID sets the "organization_id" field.
+func (u *SopTaskUpsert) SetOrganizationID(v uint64) *SopTaskUpsert {
+	u.Set(soptask.FieldOrganizationID, v)
+	return u
+}
+
+// UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
+func (u *SopTaskUpsert) UpdateOrganizationID() *SopTaskUpsert {
+	u.SetExcluded(soptask.FieldOrganizationID)
+	return u
+}
+
+// AddOrganizationID adds v to the "organization_id" field.
+func (u *SopTaskUpsert) AddOrganizationID(v uint64) *SopTaskUpsert {
+	u.Add(soptask.FieldOrganizationID, v)
+	return u
+}
+
+// ClearOrganizationID clears the value of the "organization_id" field.
+func (u *SopTaskUpsert) ClearOrganizationID() *SopTaskUpsert {
+	u.SetNull(soptask.FieldOrganizationID)
+	return u
+}
+
 // UpdateNewValues updates the mutable fields using the new values that were set on create except the ID field.
 // Using this option is equivalent to using:
 //
@@ -779,6 +825,34 @@ func (u *SopTaskUpsertOne) ClearCreatorID() *SopTaskUpsertOne {
 	})
 }
 
+// SetOrganizationID sets the "organization_id" field.
+func (u *SopTaskUpsertOne) SetOrganizationID(v uint64) *SopTaskUpsertOne {
+	return u.Update(func(s *SopTaskUpsert) {
+		s.SetOrganizationID(v)
+	})
+}
+
+// AddOrganizationID adds v to the "organization_id" field.
+func (u *SopTaskUpsertOne) AddOrganizationID(v uint64) *SopTaskUpsertOne {
+	return u.Update(func(s *SopTaskUpsert) {
+		s.AddOrganizationID(v)
+	})
+}
+
+// UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
+func (u *SopTaskUpsertOne) UpdateOrganizationID() *SopTaskUpsertOne {
+	return u.Update(func(s *SopTaskUpsert) {
+		s.UpdateOrganizationID()
+	})
+}
+
+// ClearOrganizationID clears the value of the "organization_id" field.
+func (u *SopTaskUpsertOne) ClearOrganizationID() *SopTaskUpsertOne {
+	return u.Update(func(s *SopTaskUpsert) {
+		s.ClearOrganizationID()
+	})
+}
+
 // Exec executes the query.
 func (u *SopTaskUpsertOne) Exec(ctx context.Context) error {
 	if len(u.create.conflict) == 0 {
@@ -1178,6 +1252,34 @@ func (u *SopTaskUpsertBulk) ClearCreatorID() *SopTaskUpsertBulk {
 	})
 }
 
+// SetOrganizationID sets the "organization_id" field.
+func (u *SopTaskUpsertBulk) SetOrganizationID(v uint64) *SopTaskUpsertBulk {
+	return u.Update(func(s *SopTaskUpsert) {
+		s.SetOrganizationID(v)
+	})
+}
+
+// AddOrganizationID adds v to the "organization_id" field.
+func (u *SopTaskUpsertBulk) AddOrganizationID(v uint64) *SopTaskUpsertBulk {
+	return u.Update(func(s *SopTaskUpsert) {
+		s.AddOrganizationID(v)
+	})
+}
+
+// UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
+func (u *SopTaskUpsertBulk) UpdateOrganizationID() *SopTaskUpsertBulk {
+	return u.Update(func(s *SopTaskUpsert) {
+		s.UpdateOrganizationID()
+	})
+}
+
+// ClearOrganizationID clears the value of the "organization_id" field.
+func (u *SopTaskUpsertBulk) ClearOrganizationID() *SopTaskUpsertBulk {
+	return u.Update(func(s *SopTaskUpsert) {
+		s.ClearOrganizationID()
+	})
+}
+
 // Exec executes the query.
 func (u *SopTaskUpsertBulk) Exec(ctx context.Context) error {
 	if u.create.err != nil {

+ 72 - 0
ent/soptask_update.go

@@ -196,6 +196,33 @@ func (stu *SopTaskUpdate) ClearCreatorID() *SopTaskUpdate {
 	return stu
 }
 
+// SetOrganizationID sets the "organization_id" field.
+func (stu *SopTaskUpdate) SetOrganizationID(u uint64) *SopTaskUpdate {
+	stu.mutation.ResetOrganizationID()
+	stu.mutation.SetOrganizationID(u)
+	return stu
+}
+
+// SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
+func (stu *SopTaskUpdate) SetNillableOrganizationID(u *uint64) *SopTaskUpdate {
+	if u != nil {
+		stu.SetOrganizationID(*u)
+	}
+	return stu
+}
+
+// AddOrganizationID adds u to the "organization_id" field.
+func (stu *SopTaskUpdate) AddOrganizationID(u int64) *SopTaskUpdate {
+	stu.mutation.AddOrganizationID(u)
+	return stu
+}
+
+// ClearOrganizationID clears the value of the "organization_id" field.
+func (stu *SopTaskUpdate) ClearOrganizationID() *SopTaskUpdate {
+	stu.mutation.ClearOrganizationID()
+	return stu
+}
+
 // AddTaskStageIDs adds the "task_stages" edge to the SopStage entity by IDs.
 func (stu *SopTaskUpdate) AddTaskStageIDs(ids ...uint64) *SopTaskUpdate {
 	stu.mutation.AddTaskStageIDs(ids...)
@@ -357,6 +384,15 @@ func (stu *SopTaskUpdate) sqlSave(ctx context.Context) (n int, err error) {
 	if stu.mutation.CreatorIDCleared() {
 		_spec.ClearField(soptask.FieldCreatorID, field.TypeString)
 	}
+	if value, ok := stu.mutation.OrganizationID(); ok {
+		_spec.SetField(soptask.FieldOrganizationID, field.TypeUint64, value)
+	}
+	if value, ok := stu.mutation.AddedOrganizationID(); ok {
+		_spec.AddField(soptask.FieldOrganizationID, field.TypeUint64, value)
+	}
+	if stu.mutation.OrganizationIDCleared() {
+		_spec.ClearField(soptask.FieldOrganizationID, field.TypeUint64)
+	}
 	if stu.mutation.TaskStagesCleared() {
 		edge := &sqlgraph.EdgeSpec{
 			Rel:     sqlgraph.O2M,
@@ -588,6 +624,33 @@ func (stuo *SopTaskUpdateOne) ClearCreatorID() *SopTaskUpdateOne {
 	return stuo
 }
 
+// SetOrganizationID sets the "organization_id" field.
+func (stuo *SopTaskUpdateOne) SetOrganizationID(u uint64) *SopTaskUpdateOne {
+	stuo.mutation.ResetOrganizationID()
+	stuo.mutation.SetOrganizationID(u)
+	return stuo
+}
+
+// SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
+func (stuo *SopTaskUpdateOne) SetNillableOrganizationID(u *uint64) *SopTaskUpdateOne {
+	if u != nil {
+		stuo.SetOrganizationID(*u)
+	}
+	return stuo
+}
+
+// AddOrganizationID adds u to the "organization_id" field.
+func (stuo *SopTaskUpdateOne) AddOrganizationID(u int64) *SopTaskUpdateOne {
+	stuo.mutation.AddOrganizationID(u)
+	return stuo
+}
+
+// ClearOrganizationID clears the value of the "organization_id" field.
+func (stuo *SopTaskUpdateOne) ClearOrganizationID() *SopTaskUpdateOne {
+	stuo.mutation.ClearOrganizationID()
+	return stuo
+}
+
 // AddTaskStageIDs adds the "task_stages" edge to the SopStage entity by IDs.
 func (stuo *SopTaskUpdateOne) AddTaskStageIDs(ids ...uint64) *SopTaskUpdateOne {
 	stuo.mutation.AddTaskStageIDs(ids...)
@@ -779,6 +842,15 @@ func (stuo *SopTaskUpdateOne) sqlSave(ctx context.Context) (_node *SopTask, err
 	if stuo.mutation.CreatorIDCleared() {
 		_spec.ClearField(soptask.FieldCreatorID, field.TypeString)
 	}
+	if value, ok := stuo.mutation.OrganizationID(); ok {
+		_spec.SetField(soptask.FieldOrganizationID, field.TypeUint64, value)
+	}
+	if value, ok := stuo.mutation.AddedOrganizationID(); ok {
+		_spec.AddField(soptask.FieldOrganizationID, field.TypeUint64, value)
+	}
+	if stuo.mutation.OrganizationIDCleared() {
+		_spec.ClearField(soptask.FieldOrganizationID, field.TypeUint64)
+	}
 	if stuo.mutation.TaskStagesCleared() {
 		edge := &sqlgraph.EdgeSpec{
 			Rel:     sqlgraph.O2M,

+ 12 - 1
ent/wx.go

@@ -44,6 +44,8 @@ type Wx struct {
 	Tel string `json:"tel,omitempty"`
 	// 微信头像
 	HeadBig string `json:"head_big,omitempty"`
+	// 机构 ID
+	OrganizationID uint64 `json:"organization_id,omitempty"`
 	// Edges holds the relations/edges for other nodes in the graph.
 	// The values are being populated by the WxQuery when eager-loading is set.
 	Edges        WxEdges `json:"edges"`
@@ -75,7 +77,7 @@ func (*Wx) scanValues(columns []string) ([]any, error) {
 	values := make([]any, len(columns))
 	for i := range columns {
 		switch columns[i] {
-		case wx.FieldID, wx.FieldStatus, wx.FieldServerID:
+		case wx.FieldID, wx.FieldStatus, wx.FieldServerID, wx.FieldOrganizationID:
 			values[i] = new(sql.NullInt64)
 		case wx.FieldPort, wx.FieldProcessID, wx.FieldCallback, wx.FieldWxid, wx.FieldAccount, wx.FieldNickname, wx.FieldTel, wx.FieldHeadBig:
 			values[i] = new(sql.NullString)
@@ -180,6 +182,12 @@ func (w *Wx) assignValues(columns []string, values []any) error {
 			} else if value.Valid {
 				w.HeadBig = value.String
 			}
+		case wx.FieldOrganizationID:
+			if value, ok := values[i].(*sql.NullInt64); !ok {
+				return fmt.Errorf("unexpected type %T for field organization_id", values[i])
+			} else if value.Valid {
+				w.OrganizationID = uint64(value.Int64)
+			}
 		default:
 			w.selectValues.Set(columns[i], values[i])
 		}
@@ -259,6 +267,9 @@ func (w *Wx) String() string {
 	builder.WriteString(", ")
 	builder.WriteString("head_big=")
 	builder.WriteString(w.HeadBig)
+	builder.WriteString(", ")
+	builder.WriteString("organization_id=")
+	builder.WriteString(fmt.Sprintf("%v", w.OrganizationID))
 	builder.WriteByte(')')
 	return builder.String()
 }

+ 55 - 0
ent/wx/where.go

@@ -120,6 +120,11 @@ func HeadBig(v string) predicate.Wx {
 	return predicate.Wx(sql.FieldEQ(FieldHeadBig, v))
 }
 
+// OrganizationID applies equality check predicate on the "organization_id" field. It's identical to OrganizationIDEQ.
+func OrganizationID(v uint64) predicate.Wx {
+	return predicate.Wx(sql.FieldEQ(FieldOrganizationID, v))
+}
+
 // CreatedAtEQ applies the EQ predicate on the "created_at" field.
 func CreatedAtEQ(v time.Time) predicate.Wx {
 	return predicate.Wx(sql.FieldEQ(FieldCreatedAt, v))
@@ -850,6 +855,56 @@ func HeadBigContainsFold(v string) predicate.Wx {
 	return predicate.Wx(sql.FieldContainsFold(FieldHeadBig, v))
 }
 
+// OrganizationIDEQ applies the EQ predicate on the "organization_id" field.
+func OrganizationIDEQ(v uint64) predicate.Wx {
+	return predicate.Wx(sql.FieldEQ(FieldOrganizationID, v))
+}
+
+// OrganizationIDNEQ applies the NEQ predicate on the "organization_id" field.
+func OrganizationIDNEQ(v uint64) predicate.Wx {
+	return predicate.Wx(sql.FieldNEQ(FieldOrganizationID, v))
+}
+
+// OrganizationIDIn applies the In predicate on the "organization_id" field.
+func OrganizationIDIn(vs ...uint64) predicate.Wx {
+	return predicate.Wx(sql.FieldIn(FieldOrganizationID, vs...))
+}
+
+// OrganizationIDNotIn applies the NotIn predicate on the "organization_id" field.
+func OrganizationIDNotIn(vs ...uint64) predicate.Wx {
+	return predicate.Wx(sql.FieldNotIn(FieldOrganizationID, vs...))
+}
+
+// OrganizationIDGT applies the GT predicate on the "organization_id" field.
+func OrganizationIDGT(v uint64) predicate.Wx {
+	return predicate.Wx(sql.FieldGT(FieldOrganizationID, v))
+}
+
+// OrganizationIDGTE applies the GTE predicate on the "organization_id" field.
+func OrganizationIDGTE(v uint64) predicate.Wx {
+	return predicate.Wx(sql.FieldGTE(FieldOrganizationID, v))
+}
+
+// OrganizationIDLT applies the LT predicate on the "organization_id" field.
+func OrganizationIDLT(v uint64) predicate.Wx {
+	return predicate.Wx(sql.FieldLT(FieldOrganizationID, v))
+}
+
+// OrganizationIDLTE applies the LTE predicate on the "organization_id" field.
+func OrganizationIDLTE(v uint64) predicate.Wx {
+	return predicate.Wx(sql.FieldLTE(FieldOrganizationID, v))
+}
+
+// OrganizationIDIsNil applies the IsNil predicate on the "organization_id" field.
+func OrganizationIDIsNil() predicate.Wx {
+	return predicate.Wx(sql.FieldIsNull(FieldOrganizationID))
+}
+
+// OrganizationIDNotNil applies the NotNil predicate on the "organization_id" field.
+func OrganizationIDNotNil() predicate.Wx {
+	return predicate.Wx(sql.FieldNotNull(FieldOrganizationID))
+}
+
 // HasServer applies the HasEdge predicate on the "server" edge.
 func HasServer() predicate.Wx {
 	return predicate.Wx(func(s *sql.Selector) {

+ 10 - 0
ent/wx/wx.go

@@ -41,6 +41,8 @@ const (
 	FieldTel = "tel"
 	// FieldHeadBig holds the string denoting the head_big field in the database.
 	FieldHeadBig = "head_big"
+	// FieldOrganizationID holds the string denoting the organization_id field in the database.
+	FieldOrganizationID = "organization_id"
 	// EdgeServer holds the string denoting the server edge name in mutations.
 	EdgeServer = "server"
 	// Table holds the table name of the wx in the database.
@@ -70,6 +72,7 @@ var Columns = []string{
 	FieldNickname,
 	FieldTel,
 	FieldHeadBig,
+	FieldOrganizationID,
 }
 
 // ValidColumn reports if the column name is valid (part of the table columns).
@@ -116,6 +119,8 @@ var (
 	DefaultTel string
 	// DefaultHeadBig holds the default value on creation for the "head_big" field.
 	DefaultHeadBig string
+	// DefaultOrganizationID holds the default value on creation for the "organization_id" field.
+	DefaultOrganizationID uint64
 )
 
 // OrderOption defines the ordering options for the Wx queries.
@@ -191,6 +196,11 @@ func ByHeadBig(opts ...sql.OrderTermOption) OrderOption {
 	return sql.OrderByField(FieldHeadBig, opts...).ToFunc()
 }
 
+// ByOrganizationID orders the results by the organization_id field.
+func ByOrganizationID(opts ...sql.OrderTermOption) OrderOption {
+	return sql.OrderByField(FieldOrganizationID, opts...).ToFunc()
+}
+
 // ByServerField orders the results by server field.
 func ByServerField(field string, opts ...sql.OrderTermOption) OrderOption {
 	return func(s *sql.Selector) {

+ 102 - 0
ent/wx_create.go

@@ -205,6 +205,20 @@ func (wc *WxCreate) SetNillableHeadBig(s *string) *WxCreate {
 	return wc
 }
 
+// SetOrganizationID sets the "organization_id" field.
+func (wc *WxCreate) SetOrganizationID(u uint64) *WxCreate {
+	wc.mutation.SetOrganizationID(u)
+	return wc
+}
+
+// SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
+func (wc *WxCreate) SetNillableOrganizationID(u *uint64) *WxCreate {
+	if u != nil {
+		wc.SetOrganizationID(*u)
+	}
+	return wc
+}
+
 // SetID sets the "id" field.
 func (wc *WxCreate) SetID(u uint64) *WxCreate {
 	wc.mutation.SetID(u)
@@ -307,6 +321,10 @@ func (wc *WxCreate) defaults() error {
 		v := wx.DefaultHeadBig
 		wc.mutation.SetHeadBig(v)
 	}
+	if _, ok := wc.mutation.OrganizationID(); !ok {
+		v := wx.DefaultOrganizationID
+		wc.mutation.SetOrganizationID(v)
+	}
 	return nil
 }
 
@@ -423,6 +441,10 @@ func (wc *WxCreate) createSpec() (*Wx, *sqlgraph.CreateSpec) {
 		_spec.SetField(wx.FieldHeadBig, field.TypeString, value)
 		_node.HeadBig = value
 	}
+	if value, ok := wc.mutation.OrganizationID(); ok {
+		_spec.SetField(wx.FieldOrganizationID, field.TypeUint64, value)
+		_node.OrganizationID = value
+	}
 	if nodes := wc.mutation.ServerIDs(); len(nodes) > 0 {
 		edge := &sqlgraph.EdgeSpec{
 			Rel:     sqlgraph.M2O,
@@ -660,6 +682,30 @@ func (u *WxUpsert) UpdateHeadBig() *WxUpsert {
 	return u
 }
 
+// SetOrganizationID sets the "organization_id" field.
+func (u *WxUpsert) SetOrganizationID(v uint64) *WxUpsert {
+	u.Set(wx.FieldOrganizationID, v)
+	return u
+}
+
+// UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
+func (u *WxUpsert) UpdateOrganizationID() *WxUpsert {
+	u.SetExcluded(wx.FieldOrganizationID)
+	return u
+}
+
+// AddOrganizationID adds v to the "organization_id" field.
+func (u *WxUpsert) AddOrganizationID(v uint64) *WxUpsert {
+	u.Add(wx.FieldOrganizationID, v)
+	return u
+}
+
+// ClearOrganizationID clears the value of the "organization_id" field.
+func (u *WxUpsert) ClearOrganizationID() *WxUpsert {
+	u.SetNull(wx.FieldOrganizationID)
+	return u
+}
+
 // UpdateNewValues updates the mutable fields using the new values that were set on create except the ID field.
 // Using this option is equivalent to using:
 //
@@ -907,6 +953,34 @@ func (u *WxUpsertOne) UpdateHeadBig() *WxUpsertOne {
 	})
 }
 
+// SetOrganizationID sets the "organization_id" field.
+func (u *WxUpsertOne) SetOrganizationID(v uint64) *WxUpsertOne {
+	return u.Update(func(s *WxUpsert) {
+		s.SetOrganizationID(v)
+	})
+}
+
+// AddOrganizationID adds v to the "organization_id" field.
+func (u *WxUpsertOne) AddOrganizationID(v uint64) *WxUpsertOne {
+	return u.Update(func(s *WxUpsert) {
+		s.AddOrganizationID(v)
+	})
+}
+
+// UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
+func (u *WxUpsertOne) UpdateOrganizationID() *WxUpsertOne {
+	return u.Update(func(s *WxUpsert) {
+		s.UpdateOrganizationID()
+	})
+}
+
+// ClearOrganizationID clears the value of the "organization_id" field.
+func (u *WxUpsertOne) ClearOrganizationID() *WxUpsertOne {
+	return u.Update(func(s *WxUpsert) {
+		s.ClearOrganizationID()
+	})
+}
+
 // Exec executes the query.
 func (u *WxUpsertOne) Exec(ctx context.Context) error {
 	if len(u.create.conflict) == 0 {
@@ -1320,6 +1394,34 @@ func (u *WxUpsertBulk) UpdateHeadBig() *WxUpsertBulk {
 	})
 }
 
+// SetOrganizationID sets the "organization_id" field.
+func (u *WxUpsertBulk) SetOrganizationID(v uint64) *WxUpsertBulk {
+	return u.Update(func(s *WxUpsert) {
+		s.SetOrganizationID(v)
+	})
+}
+
+// AddOrganizationID adds v to the "organization_id" field.
+func (u *WxUpsertBulk) AddOrganizationID(v uint64) *WxUpsertBulk {
+	return u.Update(func(s *WxUpsert) {
+		s.AddOrganizationID(v)
+	})
+}
+
+// UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
+func (u *WxUpsertBulk) UpdateOrganizationID() *WxUpsertBulk {
+	return u.Update(func(s *WxUpsert) {
+		s.UpdateOrganizationID()
+	})
+}
+
+// ClearOrganizationID clears the value of the "organization_id" field.
+func (u *WxUpsertBulk) ClearOrganizationID() *WxUpsertBulk {
+	return u.Update(func(s *WxUpsert) {
+		s.ClearOrganizationID()
+	})
+}
+
 // Exec executes the query.
 func (u *WxUpsertBulk) Exec(ctx context.Context) error {
 	if u.create.err != nil {

+ 72 - 0
ent/wx_update.go

@@ -214,6 +214,33 @@ func (wu *WxUpdate) SetNillableHeadBig(s *string) *WxUpdate {
 	return wu
 }
 
+// SetOrganizationID sets the "organization_id" field.
+func (wu *WxUpdate) SetOrganizationID(u uint64) *WxUpdate {
+	wu.mutation.ResetOrganizationID()
+	wu.mutation.SetOrganizationID(u)
+	return wu
+}
+
+// SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
+func (wu *WxUpdate) SetNillableOrganizationID(u *uint64) *WxUpdate {
+	if u != nil {
+		wu.SetOrganizationID(*u)
+	}
+	return wu
+}
+
+// AddOrganizationID adds u to the "organization_id" field.
+func (wu *WxUpdate) AddOrganizationID(u int64) *WxUpdate {
+	wu.mutation.AddOrganizationID(u)
+	return wu
+}
+
+// ClearOrganizationID clears the value of the "organization_id" field.
+func (wu *WxUpdate) ClearOrganizationID() *WxUpdate {
+	wu.mutation.ClearOrganizationID()
+	return wu
+}
+
 // SetServer sets the "server" edge to the Server entity.
 func (wu *WxUpdate) SetServer(s *Server) *WxUpdate {
 	return wu.SetServerID(s.ID)
@@ -323,6 +350,15 @@ func (wu *WxUpdate) sqlSave(ctx context.Context) (n int, err error) {
 	if value, ok := wu.mutation.HeadBig(); ok {
 		_spec.SetField(wx.FieldHeadBig, field.TypeString, value)
 	}
+	if value, ok := wu.mutation.OrganizationID(); ok {
+		_spec.SetField(wx.FieldOrganizationID, field.TypeUint64, value)
+	}
+	if value, ok := wu.mutation.AddedOrganizationID(); ok {
+		_spec.AddField(wx.FieldOrganizationID, field.TypeUint64, value)
+	}
+	if wu.mutation.OrganizationIDCleared() {
+		_spec.ClearField(wx.FieldOrganizationID, field.TypeUint64)
+	}
 	if wu.mutation.ServerCleared() {
 		edge := &sqlgraph.EdgeSpec{
 			Rel:     sqlgraph.M2O,
@@ -557,6 +593,33 @@ func (wuo *WxUpdateOne) SetNillableHeadBig(s *string) *WxUpdateOne {
 	return wuo
 }
 
+// SetOrganizationID sets the "organization_id" field.
+func (wuo *WxUpdateOne) SetOrganizationID(u uint64) *WxUpdateOne {
+	wuo.mutation.ResetOrganizationID()
+	wuo.mutation.SetOrganizationID(u)
+	return wuo
+}
+
+// SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
+func (wuo *WxUpdateOne) SetNillableOrganizationID(u *uint64) *WxUpdateOne {
+	if u != nil {
+		wuo.SetOrganizationID(*u)
+	}
+	return wuo
+}
+
+// AddOrganizationID adds u to the "organization_id" field.
+func (wuo *WxUpdateOne) AddOrganizationID(u int64) *WxUpdateOne {
+	wuo.mutation.AddOrganizationID(u)
+	return wuo
+}
+
+// ClearOrganizationID clears the value of the "organization_id" field.
+func (wuo *WxUpdateOne) ClearOrganizationID() *WxUpdateOne {
+	wuo.mutation.ClearOrganizationID()
+	return wuo
+}
+
 // SetServer sets the "server" edge to the Server entity.
 func (wuo *WxUpdateOne) SetServer(s *Server) *WxUpdateOne {
 	return wuo.SetServerID(s.ID)
@@ -696,6 +759,15 @@ func (wuo *WxUpdateOne) sqlSave(ctx context.Context) (_node *Wx, err error) {
 	if value, ok := wuo.mutation.HeadBig(); ok {
 		_spec.SetField(wx.FieldHeadBig, field.TypeString, value)
 	}
+	if value, ok := wuo.mutation.OrganizationID(); ok {
+		_spec.SetField(wx.FieldOrganizationID, field.TypeUint64, value)
+	}
+	if value, ok := wuo.mutation.AddedOrganizationID(); ok {
+		_spec.AddField(wx.FieldOrganizationID, field.TypeUint64, value)
+	}
+	if wuo.mutation.OrganizationIDCleared() {
+		_spec.ClearField(wx.FieldOrganizationID, field.TypeUint64)
+	}
 	if wuo.mutation.ServerCleared() {
 		edge := &sqlgraph.EdgeSpec{
 			Rel:     sqlgraph.M2O,

+ 2 - 1
internal/logic/Wx/create_wx_logic.go

@@ -30,7 +30,7 @@ func NewCreateWxLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateWx
 }
 
 func (l *CreateWxLogic) CreateWx(req *types.WxInfo) (*types.BaseMsgResp, error) {
-
+	organizationId := l.ctx.Value("organizationId").(uint64)
 	server, err := l.svcCtx.DB.Server.Get(l.ctx, *req.ServerId)
 	if err != nil {
 		l.Error("获取服务器信息失败", err)
@@ -83,6 +83,7 @@ func (l *CreateWxLogic) CreateWx(req *types.WxInfo) (*types.BaseMsgResp, error)
 				SetNotNilTel(&selfInfo.Tel).
 				SetNotNilHeadBig(&selfInfo.HeadBig).
 				SetStatus(1).
+				SetOrganizationID(organizationId).
 				Save(l.ctx)
 		} else {
 			if req.Callback != nil && *req.Callback != "" {

+ 2 - 1
internal/logic/Wx/delete_wx_logic.go

@@ -27,8 +27,9 @@ func NewDeleteWxLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteWx
 }
 
 func (l *DeleteWxLogic) DeleteWx(req *types.IDsReq) (*types.BaseMsgResp, error) {
+	organizationId := l.ctx.Value("organizationId").(uint64)
 
-	_, err := l.svcCtx.DB.Wx.Delete().Where(wx.IDIn(req.Ids...)).Exec(l.ctx)
+	_, err := l.svcCtx.DB.Wx.Delete().Where(wx.IDIn(req.Ids...), wx.OrganizationIDEQ(organizationId)).Exec(l.ctx)
 
 	if err != nil {
 		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)

+ 31 - 24
internal/logic/Wx/get_wx_by_id_logic.go

@@ -2,12 +2,13 @@ package Wx
 
 import (
 	"context"
+	"wechat-api/ent/wx"
 
 	"wechat-api/internal/svc"
 	"wechat-api/internal/types"
 	"wechat-api/internal/utils/dberrorhandler"
 
-    "github.com/suyuan32/simple-admin-common/msg/errormsg"
+	"github.com/suyuan32/simple-admin-common/msg/errormsg"
 
 	"github.com/suyuan32/simple-admin-common/utils/pointy"
 	"github.com/zeromicro/go-zero/core/logx"
@@ -28,33 +29,39 @@ func NewGetWxByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetWxBy
 }
 
 func (l *GetWxByIdLogic) GetWxById(req *types.IDReq) (*types.WxInfoResp, error) {
-	data, err := l.svcCtx.DB.Wx.Get(l.ctx, req.Id)
+	organizationId := l.ctx.Value("organizationId").(uint64)
+	data, err := l.svcCtx.DB.Wx.Query().
+		Where(
+			wx.IDEQ(req.Id),                   // Filter by ID
+			wx.OrganizationID(organizationId), // Additional filter by organizationId
+		).
+		Only(l.ctx)
 	if err != nil {
 		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
 	}
 
 	return &types.WxInfoResp{
-	    BaseDataInfo: types.BaseDataInfo{
-            Code: 0,
-            Msg:  errormsg.Success,
-        },
-        Data: types.WxInfo{
-            BaseIDInfo:    types.BaseIDInfo{
-				Id:          &data.ID,
-				CreatedAt:    pointy.GetPointer(data.CreatedAt.UnixMilli()),
-				UpdatedAt:    pointy.GetPointer(data.UpdatedAt.UnixMilli()),
-            },
-			Status:	&data.Status,
-			ServerId:	&data.ServerID,
-			Port:	&data.Port,
-			ProcessId:	&data.ProcessID,
-			Callback:	&data.Callback,
-			Wxid:	&data.Wxid,
-			Account:	&data.Account,
-			Nickname:	&data.Nickname,
-			Tel:	&data.Tel,
-			HeadBig:	&data.HeadBig,
-        },
+		BaseDataInfo: types.BaseDataInfo{
+			Code: 0,
+			Msg:  errormsg.Success,
+		},
+		Data: types.WxInfo{
+			BaseIDInfo: types.BaseIDInfo{
+				Id:        &data.ID,
+				CreatedAt: pointy.GetPointer(data.CreatedAt.UnixMilli()),
+				UpdatedAt: pointy.GetPointer(data.UpdatedAt.UnixMilli()),
+			},
+			Status:         &data.Status,
+			ServerId:       &data.ServerID,
+			Port:           &data.Port,
+			ProcessId:      &data.ProcessID,
+			Callback:       &data.Callback,
+			Wxid:           &data.Wxid,
+			Account:        &data.Account,
+			Nickname:       &data.Nickname,
+			Tel:            &data.Tel,
+			HeadBig:        &data.HeadBig,
+			OrganizationId: &data.OrganizationID,
+		},
 	}, nil
 }
-

+ 23 - 19
internal/logic/Wx/get_wx_list_logic.go

@@ -3,13 +3,13 @@ package Wx
 import (
 	"context"
 
-	"wechat-api/ent/wx"
 	"wechat-api/ent/predicate"
+	"wechat-api/ent/wx"
 	"wechat-api/internal/svc"
 	"wechat-api/internal/types"
 	"wechat-api/internal/utils/dberrorhandler"
 
-    "github.com/suyuan32/simple-admin-common/msg/errormsg"
+	"github.com/suyuan32/simple-admin-common/msg/errormsg"
 
 	"github.com/suyuan32/simple-admin-common/utils/pointy"
 	"github.com/zeromicro/go-zero/core/logx"
@@ -30,7 +30,10 @@ func NewGetWxListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetWxLi
 }
 
 func (l *GetWxListLogic) GetWxList(req *types.WxListReq) (*types.WxListResp, error) {
+	organizationId := l.ctx.Value("organizationId").(uint64)
+
 	var predicates []predicate.Wx
+	predicates = append(predicates, wx.OrganizationIDEQ(organizationId))
 	if req.Port != nil {
 		predicates = append(predicates, wx.PortContains(*req.Port))
 	}
@@ -52,23 +55,24 @@ func (l *GetWxListLogic) GetWxList(req *types.WxListReq) (*types.WxListResp, err
 
 	for _, v := range data.List {
 		resp.Data.Data = append(resp.Data.Data,
-		types.WxInfo{
-			BaseIDInfo:    types.BaseIDInfo{
-				Id:          &v.ID,
-				CreatedAt:    pointy.GetPointer(v.CreatedAt.UnixMilli()),
-				UpdatedAt:    pointy.GetPointer(v.UpdatedAt.UnixMilli()),
-            },
-			Status:	&v.Status,
-			ServerId:	&v.ServerID,
-			Port:	&v.Port,
-			ProcessId:	&v.ProcessID,
-			Callback:	&v.Callback,
-			Wxid:	&v.Wxid,
-			Account:	&v.Account,
-			Nickname:	&v.Nickname,
-			Tel:	&v.Tel,
-			HeadBig:	&v.HeadBig,
-		})
+			types.WxInfo{
+				BaseIDInfo: types.BaseIDInfo{
+					Id:        &v.ID,
+					CreatedAt: pointy.GetPointer(v.CreatedAt.UnixMilli()),
+					UpdatedAt: pointy.GetPointer(v.UpdatedAt.UnixMilli()),
+				},
+				Status:         &v.Status,
+				ServerId:       &v.ServerID,
+				Port:           &v.Port,
+				ProcessId:      &v.ProcessID,
+				Callback:       &v.Callback,
+				Wxid:           &v.Wxid,
+				Account:        &v.Account,
+				Nickname:       &v.Nickname,
+				Tel:            &v.Tel,
+				HeadBig:        &v.HeadBig,
+				OrganizationId: &v.OrganizationID,
+			})
 	}
 
 	return resp, nil

+ 19 - 17
internal/logic/Wx/update_wx_logic.go

@@ -2,12 +2,11 @@ package Wx
 
 import (
 	"context"
-
+	"wechat-api/ent/wx"
 	"wechat-api/internal/svc"
 	"wechat-api/internal/types"
 	"wechat-api/internal/utils/dberrorhandler"
 
-
 	"github.com/suyuan32/simple-admin-common/msg/errormsg"
 	"github.com/zeromicro/go-zero/core/logx"
 )
@@ -27,22 +26,25 @@ func NewUpdateWxLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateWx
 }
 
 func (l *UpdateWxLogic) UpdateWx(req *types.WxInfo) (*types.BaseMsgResp, error) {
-    err := l.svcCtx.DB.Wx.UpdateOneID(*req.Id).
-			SetNotNilStatus(req.Status).
-			SetNotNilServerID(req.ServerId).
-			SetNotNilPort(req.Port).
-			SetNotNilProcessID(req.ProcessId).
-			SetNotNilCallback(req.Callback).
-			SetNotNilWxid(req.Wxid).
-			SetNotNilAccount(req.Account).
-			SetNotNilNickname(req.Nickname).
-			SetNotNilTel(req.Tel).
-			SetNotNilHeadBig(req.HeadBig).
-			Exec(l.ctx)
-
-    if err != nil {
+	organizationId := l.ctx.Value("organizationId").(uint64)
+
+	err := l.svcCtx.DB.Wx.UpdateOneID(*req.Id).
+		Where(wx.OrganizationID(organizationId)).
+		SetNotNilStatus(req.Status).
+		SetNotNilServerID(req.ServerId).
+		SetNotNilPort(req.Port).
+		SetNotNilProcessID(req.ProcessId).
+		SetNotNilCallback(req.Callback).
+		SetNotNilWxid(req.Wxid).
+		SetNotNilAccount(req.Account).
+		SetNotNilNickname(req.Nickname).
+		SetNotNilTel(req.Tel).
+		SetNotNilHeadBig(req.HeadBig).
+		Exec(l.ctx)
+
+	if err != nil {
 		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
 	}
 
-    return &types.BaseMsgResp{Msg: errormsg.UpdateSuccess}, nil
+	return &types.BaseMsgResp{Msg: errormsg.UpdateSuccess}, nil
 }

+ 2 - 1
internal/logic/Wxhook/get_friends_and_groups_logic.go

@@ -27,7 +27,7 @@ func NewGetFriendsAndGroupsLogic(ctx context.Context, svcCtx *svc.ServiceContext
 }
 
 func (l *GetFriendsAndGroupsLogic) GetFriendsAndGroups(req *types.IDReq) (resp *types.BaseMsgResp, err error) {
-
+	organizationId := l.ctx.Value("organizationId").(uint64)
 	wxInfo, err := l.svcCtx.DB.Wx.Get(l.ctx, req.Id)
 	if err != nil {
 		l.Error("查询微信信息失败", err)
@@ -68,6 +68,7 @@ func (l *GetFriendsAndGroupsLogic) GetFriendsAndGroups(req *types.IDReq) (resp *
 				SetV3(friend.V3).
 				OnConflict().
 				UpdateNewValues().
+				SetOrganizationID(organizationId).
 				ID(l.ctx)
 		}
 	}

+ 2 - 2
internal/logic/contact/add_new_friend_logic.go

@@ -26,8 +26,8 @@ func NewAddNewFriendLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddN
 }
 
 func (l *AddNewFriendLogic) AddNewFriend(req *types.AddNewFriendReq) (resp *types.BaseMsgResp, err error) {
-
-	wxInfo, err := l.svcCtx.DB.Wx.Query().Where(wx.Wxid(req.OwnerWxid)).First(l.ctx)
+	organizationId := l.ctx.Value("organizationId").(uint64)
+	wxInfo, err := l.svcCtx.DB.Wx.Query().Where(wx.Wxid(req.OwnerWxid), wx.OrganizationIDEQ(organizationId)).First(l.ctx)
 	if err != nil {
 		l.Error("查询微信信息失败", err)
 		return

+ 24 - 22
internal/logic/contact/create_contact_logic.go

@@ -7,7 +7,7 @@ import (
 	"wechat-api/internal/types"
 	"wechat-api/internal/utils/dberrorhandler"
 
-    "github.com/suyuan32/simple-admin-common/msg/errormsg"
+	"github.com/suyuan32/simple-admin-common/msg/errormsg"
 
 	"github.com/zeromicro/go-zero/core/logx"
 )
@@ -27,28 +27,30 @@ func NewCreateContactLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Cre
 }
 
 func (l *CreateContactLogic) CreateContact(req *types.ContactInfo) (*types.BaseMsgResp, error) {
-    _, err := l.svcCtx.DB.Contact.Create().
-			SetNotNilStatus(req.Status).
-			SetNotNilWxWxid(req.WxWxid).
-			SetNotNilType(req.Type).
-			SetNotNilWxid(req.Wxid).
-			SetNotNilAccount(req.Account).
-			SetNotNilNickname(req.Nickname).
-			SetNotNilMarkname(req.Markname).
-			SetNotNilHeadimg(req.Headimg).
-			SetNotNilSex(req.Sex).
-			SetNotNilStarrole(req.Starrole).
-			SetNotNilDontseeit(req.Dontseeit).
-			SetNotNilDontseeme(req.Dontseeme).
-			SetNotNilLag(req.Lag).
-			SetNotNilGid(req.Gid).
-			SetNotNilGname(req.Gname).
-			SetNotNilV3(req.V3).
-			Save(l.ctx)
-
-    if err != nil {
+	organizationId := l.ctx.Value("organizationId").(uint64)
+	_, err := l.svcCtx.DB.Contact.Create().
+		SetNotNilStatus(req.Status).
+		SetNotNilWxWxid(req.WxWxid).
+		SetNotNilType(req.Type).
+		SetNotNilWxid(req.Wxid).
+		SetNotNilAccount(req.Account).
+		SetNotNilNickname(req.Nickname).
+		SetNotNilMarkname(req.Markname).
+		SetNotNilHeadimg(req.Headimg).
+		SetNotNilSex(req.Sex).
+		SetNotNilStarrole(req.Starrole).
+		SetNotNilDontseeit(req.Dontseeit).
+		SetNotNilDontseeme(req.Dontseeme).
+		SetNotNilLag(req.Lag).
+		SetNotNilGid(req.Gid).
+		SetNotNilGname(req.Gname).
+		SetNotNilV3(req.V3).
+		SetOrganizationID(organizationId).
+		Save(l.ctx)
+
+	if err != nil {
 		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
 	}
 
-    return &types.BaseMsgResp{Msg: errormsg.CreateSuccess}, nil
+	return &types.BaseMsgResp{Msg: errormsg.CreateSuccess}, nil
 }

+ 10 - 9
internal/logic/contact/delete_contact_logic.go

@@ -3,13 +3,13 @@ package contact
 import (
 	"context"
 
-    "wechat-api/ent/contact"
-    "wechat-api/internal/svc"
-    "wechat-api/internal/types"
-    "wechat-api/internal/utils/dberrorhandler"
+	"wechat-api/ent/contact"
+	"wechat-api/internal/svc"
+	"wechat-api/internal/types"
+	"wechat-api/internal/utils/dberrorhandler"
 
-    "github.com/suyuan32/simple-admin-common/msg/errormsg"
-    "github.com/zeromicro/go-zero/core/logx"
+	"github.com/suyuan32/simple-admin-common/msg/errormsg"
+	"github.com/zeromicro/go-zero/core/logx"
 )
 
 type DeleteContactLogic struct {
@@ -27,11 +27,12 @@ func NewDeleteContactLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Del
 }
 
 func (l *DeleteContactLogic) DeleteContact(req *types.IDsReq) (*types.BaseMsgResp, error) {
-	_, err := l.svcCtx.DB.Contact.Delete().Where(contact.IDIn(req.Ids...)).Exec(l.ctx)
+	organizationId := l.ctx.Value("organizationId").(uint64)
+	_, err := l.svcCtx.DB.Contact.Delete().Where(contact.IDIn(req.Ids...), contact.OrganizationIDEQ(organizationId)).Exec(l.ctx)
 
-    if err != nil {
+	if err != nil {
 		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
 	}
 
-    return &types.BaseMsgResp{Msg: errormsg.DeleteSuccess}, nil
+	return &types.BaseMsgResp{Msg: errormsg.DeleteSuccess}, nil
 }

+ 36 - 31
internal/logic/contact/get_contact_by_id_logic.go

@@ -2,12 +2,12 @@ package contact
 
 import (
 	"context"
-
+	"wechat-api/ent/contact"
 	"wechat-api/internal/svc"
 	"wechat-api/internal/types"
 	"wechat-api/internal/utils/dberrorhandler"
 
-    "github.com/suyuan32/simple-admin-common/msg/errormsg"
+	"github.com/suyuan32/simple-admin-common/msg/errormsg"
 
 	"github.com/suyuan32/simple-admin-common/utils/pointy"
 	"github.com/zeromicro/go-zero/core/logx"
@@ -28,39 +28,44 @@ func NewGetContactByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Ge
 }
 
 func (l *GetContactByIdLogic) GetContactById(req *types.IDReq) (*types.ContactInfoResp, error) {
-	data, err := l.svcCtx.DB.Contact.Get(l.ctx, req.Id)
+	organizationId := l.ctx.Value("organizationId").(uint64)
+	data, err := l.svcCtx.DB.Contact.Query().
+		Where(
+			contact.IDEQ(req.Id),                   // Filter by ID
+			contact.OrganizationID(organizationId), // Additional filter by organizationId
+		).
+		Only(l.ctx)
 	if err != nil {
 		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
 	}
 
 	return &types.ContactInfoResp{
-	    BaseDataInfo: types.BaseDataInfo{
-            Code: 0,
-            Msg:  errormsg.Success,
-        },
-        Data: types.ContactInfo{
-            BaseIDInfo:    types.BaseIDInfo{
-				Id:          &data.ID,
-				CreatedAt:    pointy.GetPointer(data.CreatedAt.UnixMilli()),
-				UpdatedAt:    pointy.GetPointer(data.UpdatedAt.UnixMilli()),
-            },
-			Status:	&data.Status,
-			WxWxid:	&data.WxWxid,
-			Type:	&data.Type,
-			Wxid:	&data.Wxid,
-			Account:	&data.Account,
-			Nickname:	&data.Nickname,
-			Markname:	&data.Markname,
-			Headimg:	&data.Headimg,
-			Sex:	&data.Sex,
-			Starrole:	&data.Starrole,
-			Dontseeit:	&data.Dontseeit,
-			Dontseeme:	&data.Dontseeme,
-			Lag:	&data.Lag,
-			Gid:	&data.Gid,
-			Gname:	&data.Gname,
-			V3:	&data.V3,
-        },
+		BaseDataInfo: types.BaseDataInfo{
+			Code: 0,
+			Msg:  errormsg.Success,
+		},
+		Data: types.ContactInfo{
+			BaseIDInfo: types.BaseIDInfo{
+				Id:        &data.ID,
+				CreatedAt: pointy.GetPointer(data.CreatedAt.UnixMilli()),
+				UpdatedAt: pointy.GetPointer(data.UpdatedAt.UnixMilli()),
+			},
+			Status:    &data.Status,
+			WxWxid:    &data.WxWxid,
+			Type:      &data.Type,
+			Wxid:      &data.Wxid,
+			Account:   &data.Account,
+			Nickname:  &data.Nickname,
+			Markname:  &data.Markname,
+			Headimg:   &data.Headimg,
+			Sex:       &data.Sex,
+			Starrole:  &data.Starrole,
+			Dontseeit: &data.Dontseeit,
+			Dontseeme: &data.Dontseeme,
+			Lag:       &data.Lag,
+			Gid:       &data.Gid,
+			Gname:     &data.Gname,
+			V3:        &data.V3,
+		},
 	}, nil
 }
-

+ 2 - 0
internal/logic/contact/get_contact_list_logic.go

@@ -49,7 +49,9 @@ func convertLabelToLabelInfo(label *ent.Label) types.LabelInfo {
 }
 
 func (l *GetContactListLogic) GetContactList(req *types.ContactListReq) (*types.ContactListResp, error) {
+	organizationId := l.ctx.Value("organizationId").(uint64)
 	var predicates []predicate.Contact
+	predicates = append(predicates, contact.OrganizationIDEQ(organizationId))
 	if len(req.LabelIDs) > 0 {
 		predicates = append(predicates, contact.HasContactRelationshipsWith(
 			labelrelationship.HasLabelsWith(

+ 24 - 23
internal/logic/contact/update_contact_logic.go

@@ -2,12 +2,11 @@ package contact
 
 import (
 	"context"
-
+	"wechat-api/ent/contact"
 	"wechat-api/internal/svc"
 	"wechat-api/internal/types"
 	"wechat-api/internal/utils/dberrorhandler"
 
-
 	"github.com/suyuan32/simple-admin-common/msg/errormsg"
 	"github.com/zeromicro/go-zero/core/logx"
 )
@@ -27,28 +26,30 @@ func NewUpdateContactLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Upd
 }
 
 func (l *UpdateContactLogic) UpdateContact(req *types.ContactInfo) (*types.BaseMsgResp, error) {
-    err := l.svcCtx.DB.Contact.UpdateOneID(*req.Id).
-			SetNotNilStatus(req.Status).
-			SetNotNilWxWxid(req.WxWxid).
-			SetNotNilType(req.Type).
-			SetNotNilWxid(req.Wxid).
-			SetNotNilAccount(req.Account).
-			SetNotNilNickname(req.Nickname).
-			SetNotNilMarkname(req.Markname).
-			SetNotNilHeadimg(req.Headimg).
-			SetNotNilSex(req.Sex).
-			SetNotNilStarrole(req.Starrole).
-			SetNotNilDontseeit(req.Dontseeit).
-			SetNotNilDontseeme(req.Dontseeme).
-			SetNotNilLag(req.Lag).
-			SetNotNilGid(req.Gid).
-			SetNotNilGname(req.Gname).
-			SetNotNilV3(req.V3).
-			Exec(l.ctx)
-
-    if err != nil {
+	organizationId := l.ctx.Value("organizationId").(uint64)
+	err := l.svcCtx.DB.Contact.UpdateOneID(*req.Id).
+		Where(contact.OrganizationID(organizationId)).
+		SetNotNilStatus(req.Status).
+		SetNotNilWxWxid(req.WxWxid).
+		SetNotNilType(req.Type).
+		SetNotNilWxid(req.Wxid).
+		SetNotNilAccount(req.Account).
+		SetNotNilNickname(req.Nickname).
+		SetNotNilMarkname(req.Markname).
+		SetNotNilHeadimg(req.Headimg).
+		SetNotNilSex(req.Sex).
+		SetNotNilStarrole(req.Starrole).
+		SetNotNilDontseeit(req.Dontseeit).
+		SetNotNilDontseeme(req.Dontseeme).
+		SetNotNilLag(req.Lag).
+		SetNotNilGid(req.Gid).
+		SetNotNilGname(req.Gname).
+		SetNotNilV3(req.V3).
+		Exec(l.ctx)
+
+	if err != nil {
 		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
 	}
 
-    return &types.BaseMsgResp{Msg: errormsg.UpdateSuccess}, nil
+	return &types.BaseMsgResp{Msg: errormsg.UpdateSuccess}, nil
 }

+ 2 - 1
internal/logic/label/create_label_logic.go

@@ -27,7 +27,7 @@ func NewCreateLabelLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Creat
 }
 
 func (l *CreateLabelLogic) CreateLabel(req *types.LabelInfo) (*types.BaseMsgResp, error) {
-	l.Logger.Infof("CreateLabel req: %v", req)
+	organizationId := l.ctx.Value("organizationId").(uint64)
 	var conditions = "{}"
 	//if *req.Conditions == "" {
 	//	conditions = "{}"
@@ -41,6 +41,7 @@ func (l *CreateLabelLogic) CreateLabel(req *types.LabelInfo) (*types.BaseMsgResp
 		SetNotNilFrom(req.From).
 		SetNotNilMode(req.Mode).
 		SetNotNilConditions(&conditions).
+		SetOrganizationID(organizationId).
 		Save(l.ctx)
 
 	if err != nil {

+ 31 - 14
internal/logic/label/delete_label_logic.go

@@ -2,14 +2,15 @@ package label
 
 import (
 	"context"
-
-    "wechat-api/ent/label"
-    "wechat-api/internal/svc"
-    "wechat-api/internal/types"
-    "wechat-api/internal/utils/dberrorhandler"
-
-    "github.com/suyuan32/simple-admin-common/msg/errormsg"
-    "github.com/zeromicro/go-zero/core/logx"
+	"github.com/zeromicro/go-zero/core/errorx"
+	"wechat-api/ent/label"
+	"wechat-api/ent/labelrelationship"
+	"wechat-api/internal/svc"
+	"wechat-api/internal/types"
+	"wechat-api/internal/utils/dberrorhandler"
+
+	"github.com/suyuan32/simple-admin-common/msg/errormsg"
+	"github.com/zeromicro/go-zero/core/logx"
 )
 
 type DeleteLabelLogic struct {
@@ -27,11 +28,27 @@ func NewDeleteLabelLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Delet
 }
 
 func (l *DeleteLabelLogic) DeleteLabel(req *types.IDsReq) (*types.BaseMsgResp, error) {
-	_, err := l.svcCtx.DB.Label.Delete().Where(label.IDIn(req.Ids...)).Exec(l.ctx)
-
-    if err != nil {
-		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
+	organizationId := l.ctx.Value("organizationId").(uint64)
+
+	data, err := l.svcCtx.DB.LabelRelationship.Query().
+		Where(
+			labelrelationship.LabelIDIn(req.Ids...),          // Filter by ID
+			labelrelationship.OrganizationID(organizationId), // Additional filter by organizationId
+		).
+		Only(l.ctx)
+	//if err != nil {
+	//	return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
+	//}
+	if data == nil {
+		_, err := l.svcCtx.DB.Label.Delete().Where(label.IDIn(req.Ids...), label.OrganizationIDEQ(organizationId)).Exec(l.ctx)
+
+		if err != nil {
+			return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
+		}
+
+		return &types.BaseMsgResp{Msg: errormsg.DeleteSuccess}, nil
+	} else {
+		err = errorx.NewDefaultError("标签已被使用,无法删除!")
+		return nil, err
 	}
-
-    return &types.BaseMsgResp{Msg: errormsg.DeleteSuccess}, nil
 }

+ 26 - 21
internal/logic/label/get_label_by_id_logic.go

@@ -2,12 +2,12 @@ package label
 
 import (
 	"context"
-
+	"wechat-api/ent/label"
 	"wechat-api/internal/svc"
 	"wechat-api/internal/types"
 	"wechat-api/internal/utils/dberrorhandler"
 
-    "github.com/suyuan32/simple-admin-common/msg/errormsg"
+	"github.com/suyuan32/simple-admin-common/msg/errormsg"
 
 	"github.com/suyuan32/simple-admin-common/utils/pointy"
 	"github.com/zeromicro/go-zero/core/logx"
@@ -28,29 +28,34 @@ func NewGetLabelByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetL
 }
 
 func (l *GetLabelByIdLogic) GetLabelById(req *types.IDReq) (*types.LabelInfoResp, error) {
-	data, err := l.svcCtx.DB.Label.Get(l.ctx, req.Id)
+	organizationId := l.ctx.Value("organizationId").(uint64)
+	data, err := l.svcCtx.DB.Label.Query().
+		Where(
+			label.IDEQ(req.Id),                   // Filter by ID
+			label.OrganizationID(organizationId), // Additional filter by organizationId
+		).
+		Only(l.ctx)
 	if err != nil {
 		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
 	}
 
 	return &types.LabelInfoResp{
-	    BaseDataInfo: types.BaseDataInfo{
-            Code: 0,
-            Msg:  errormsg.Success,
-        },
-        Data: types.LabelInfo{
-            BaseIDInfo:    types.BaseIDInfo{
-				Id:          &data.ID,
-				CreatedAt:    pointy.GetPointer(data.CreatedAt.UnixMilli()),
-				UpdatedAt:    pointy.GetPointer(data.UpdatedAt.UnixMilli()),
-            },
-			Status:	&data.Status,
-			Type:	&data.Type,
-			Name:	&data.Name,
-			From:	&data.From,
-			Mode:	&data.Mode,
-			Conditions:	&data.Conditions,
-        },
+		BaseDataInfo: types.BaseDataInfo{
+			Code: 0,
+			Msg:  errormsg.Success,
+		},
+		Data: types.LabelInfo{
+			BaseIDInfo: types.BaseIDInfo{
+				Id:        &data.ID,
+				CreatedAt: pointy.GetPointer(data.CreatedAt.UnixMilli()),
+				UpdatedAt: pointy.GetPointer(data.UpdatedAt.UnixMilli()),
+			},
+			Status:     &data.Status,
+			Type:       &data.Type,
+			Name:       &data.Name,
+			From:       &data.From,
+			Mode:       &data.Mode,
+			Conditions: &data.Conditions,
+		},
 	}, nil
 }
-

+ 2 - 0
internal/logic/label/get_label_contacts_logic.go

@@ -30,10 +30,12 @@ func NewGetLabelContactsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *
 }
 
 func (l *GetLabelContactsLogic) GetLabelContacts(req *types.LabelListReq) (*types.LabelListResp, error) {
+	organizationId := l.ctx.Value("organizationId").(uint64)
 	if len(req.LabelIDs) == 0 {
 		return nil, errors.New("label id list cannot be empty")
 	}
 	var predicates []predicate.Label
+	predicates = append(predicates, label.OrganizationIDEQ(organizationId))
 	if len(req.LabelIDs) > 0 {
 		predicates = append(predicates, label.IDIn(req.LabelIDs...))
 	}

+ 2 - 0
internal/logic/label/get_label_list_logic.go

@@ -57,7 +57,9 @@ func convertContactToContactInfo(label *ent.Contact) types.ContactInfo {
 }
 
 func (l *GetLabelListLogic) GetLabelList(req *types.LabelListReq) (*types.LabelListResp, error) {
+	organizationId := l.ctx.Value("organizationId").(uint64)
 	var predicates []predicate.Label
+	predicates = append(predicates, label.OrganizationIDEQ(organizationId))
 	if req.Type != nil {
 		predicates = append(predicates, label.TypeEQ(*req.Type))
 	}

+ 2 - 0
internal/logic/label/get_label_select_list_logic.go

@@ -27,7 +27,9 @@ func NewGetLabelSelectListLogic(ctx context.Context, svcCtx *svc.ServiceContext)
 }
 
 func (l *GetLabelSelectListLogic) GetLabelSelectList(req *types.LabelListReq) (*types.LabelSelectListResp, error) {
+	organizationId := l.ctx.Value("organizationId").(uint64)
 	var predicates []predicate.Label
+	predicates = append(predicates, label.OrganizationIDEQ(organizationId))
 	if req.Type != nil {
 		predicates = append(predicates, label.TypeEQ(*req.Type))
 	}

+ 14 - 13
internal/logic/label/update_label_logic.go

@@ -2,12 +2,11 @@ package label
 
 import (
 	"context"
-
+	"wechat-api/ent/label"
 	"wechat-api/internal/svc"
 	"wechat-api/internal/types"
 	"wechat-api/internal/utils/dberrorhandler"
 
-
 	"github.com/suyuan32/simple-admin-common/msg/errormsg"
 	"github.com/zeromicro/go-zero/core/logx"
 )
@@ -27,18 +26,20 @@ func NewUpdateLabelLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Updat
 }
 
 func (l *UpdateLabelLogic) UpdateLabel(req *types.LabelInfo) (*types.BaseMsgResp, error) {
-    err := l.svcCtx.DB.Label.UpdateOneID(*req.Id).
-			SetNotNilStatus(req.Status).
-			SetNotNilType(req.Type).
-			SetNotNilName(req.Name).
-			SetNotNilFrom(req.From).
-			SetNotNilMode(req.Mode).
-			SetNotNilConditions(req.Conditions).
-			Exec(l.ctx)
-
-    if err != nil {
+	organizationId := l.ctx.Value("organizationId").(uint64)
+	err := l.svcCtx.DB.Label.UpdateOneID(*req.Id).
+		Where(label.OrganizationID(organizationId)).
+		SetNotNilStatus(req.Status).
+		SetNotNilType(req.Type).
+		SetNotNilName(req.Name).
+		SetNotNilFrom(req.From).
+		SetNotNilMode(req.Mode).
+		SetNotNilConditions(req.Conditions).
+		Exec(l.ctx)
+
+	if err != nil {
 		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
 	}
 
-    return &types.BaseMsgResp{Msg: errormsg.UpdateSuccess}, nil
+	return &types.BaseMsgResp{Msg: errormsg.UpdateSuccess}, nil
 }

+ 11 - 9
internal/logic/label_relationship/create_label_relationship_logic.go

@@ -7,7 +7,7 @@ import (
 	"wechat-api/internal/types"
 	"wechat-api/internal/utils/dberrorhandler"
 
-    "github.com/suyuan32/simple-admin-common/msg/errormsg"
+	"github.com/suyuan32/simple-admin-common/msg/errormsg"
 
 	"github.com/zeromicro/go-zero/core/logx"
 )
@@ -27,15 +27,17 @@ func NewCreateLabelRelationshipLogic(ctx context.Context, svcCtx *svc.ServiceCon
 }
 
 func (l *CreateLabelRelationshipLogic) CreateLabelRelationship(req *types.LabelRelationshipInfo) (*types.BaseMsgResp, error) {
-    _, err := l.svcCtx.DB.LabelRelationship.Create().
-			SetNotNilStatus(req.Status).
-			SetNotNilLabelID(req.LabelId).
-			SetNotNilContactID(req.ContactId).
-			Save(l.ctx)
-
-    if err != nil {
+	organizationId := l.ctx.Value("organizationId").(uint64)
+	_, err := l.svcCtx.DB.LabelRelationship.Create().
+		SetNotNilStatus(req.Status).
+		SetNotNilLabelID(req.LabelId).
+		SetNotNilContactID(req.ContactId).
+		SetOrganizationID(organizationId).
+		Save(l.ctx)
+
+	if err != nil {
 		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
 	}
 
-    return &types.BaseMsgResp{Msg: errormsg.CreateSuccess}, nil
+	return &types.BaseMsgResp{Msg: errormsg.CreateSuccess}, nil
 }

+ 10 - 10
internal/logic/label_relationship/delete_label_relationship_logic.go

@@ -2,14 +2,13 @@ package label_relationship
 
 import (
 	"context"
+	"wechat-api/ent/labelrelationship"
+	"wechat-api/internal/svc"
+	"wechat-api/internal/types"
+	"wechat-api/internal/utils/dberrorhandler"
 
-    "wechat-api/ent/labelrelationship"
-    "wechat-api/internal/svc"
-    "wechat-api/internal/types"
-    "wechat-api/internal/utils/dberrorhandler"
-
-    "github.com/suyuan32/simple-admin-common/msg/errormsg"
-    "github.com/zeromicro/go-zero/core/logx"
+	"github.com/suyuan32/simple-admin-common/msg/errormsg"
+	"github.com/zeromicro/go-zero/core/logx"
 )
 
 type DeleteLabelRelationshipLogic struct {
@@ -27,11 +26,12 @@ func NewDeleteLabelRelationshipLogic(ctx context.Context, svcCtx *svc.ServiceCon
 }
 
 func (l *DeleteLabelRelationshipLogic) DeleteLabelRelationship(req *types.IDsReq) (*types.BaseMsgResp, error) {
-	_, err := l.svcCtx.DB.LabelRelationship.Delete().Where(labelrelationship.IDIn(req.Ids...)).Exec(l.ctx)
+	organizationId := l.ctx.Value("organizationId").(uint64)
+	_, err := l.svcCtx.DB.LabelRelationship.Delete().Where(labelrelationship.IDIn(req.Ids...), labelrelationship.OrganizationIDEQ(organizationId)).Exec(l.ctx)
 
-    if err != nil {
+	if err != nil {
 		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
 	}
 
-    return &types.BaseMsgResp{Msg: errormsg.DeleteSuccess}, nil
+	return &types.BaseMsgResp{Msg: errormsg.DeleteSuccess}, nil
 }

+ 23 - 17
internal/logic/label_relationship/get_label_relationship_by_id_logic.go

@@ -2,12 +2,13 @@ package label_relationship
 
 import (
 	"context"
+	"wechat-api/ent/labelrelationship"
 
 	"wechat-api/internal/svc"
 	"wechat-api/internal/types"
 	"wechat-api/internal/utils/dberrorhandler"
 
-    "github.com/suyuan32/simple-admin-common/msg/errormsg"
+	"github.com/suyuan32/simple-admin-common/msg/errormsg"
 
 	"github.com/suyuan32/simple-admin-common/utils/pointy"
 	"github.com/zeromicro/go-zero/core/logx"
@@ -28,26 +29,31 @@ func NewGetLabelRelationshipByIdLogic(ctx context.Context, svcCtx *svc.ServiceCo
 }
 
 func (l *GetLabelRelationshipByIdLogic) GetLabelRelationshipById(req *types.IDReq) (*types.LabelRelationshipInfoResp, error) {
-	data, err := l.svcCtx.DB.LabelRelationship.Get(l.ctx, req.Id)
+	organizationId := l.ctx.Value("organizationId").(uint64)
+	data, err := l.svcCtx.DB.LabelRelationship.Query().
+		Where(
+			labelrelationship.IDEQ(req.Id),                   // Filter by ID
+			labelrelationship.OrganizationID(organizationId), // Additional filter by organizationId
+		).
+		Only(l.ctx)
 	if err != nil {
 		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
 	}
 
 	return &types.LabelRelationshipInfoResp{
-	    BaseDataInfo: types.BaseDataInfo{
-            Code: 0,
-            Msg:  errormsg.Success,
-        },
-        Data: types.LabelRelationshipInfo{
-            BaseIDInfo:    types.BaseIDInfo{
-				Id:          &data.ID,
-				CreatedAt:    pointy.GetPointer(data.CreatedAt.UnixMilli()),
-				UpdatedAt:    pointy.GetPointer(data.UpdatedAt.UnixMilli()),
-            },
-			Status:	&data.Status,
-			LabelId:	&data.LabelID,
-			ContactId:	&data.ContactID,
-        },
+		BaseDataInfo: types.BaseDataInfo{
+			Code: 0,
+			Msg:  errormsg.Success,
+		},
+		Data: types.LabelRelationshipInfo{
+			BaseIDInfo: types.BaseIDInfo{
+				Id:        &data.ID,
+				CreatedAt: pointy.GetPointer(data.CreatedAt.UnixMilli()),
+				UpdatedAt: pointy.GetPointer(data.UpdatedAt.UnixMilli()),
+			},
+			Status:    &data.Status,
+			LabelId:   &data.LabelID,
+			ContactId: &data.ContactID,
+		},
 	}, nil
 }
-

+ 3 - 0
internal/logic/label_relationship/get_label_relationship_list_logic.go

@@ -2,6 +2,7 @@ package label_relationship
 
 import (
 	"context"
+	"wechat-api/ent/labelrelationship"
 
 	"wechat-api/ent/predicate"
 	"wechat-api/internal/svc"
@@ -29,7 +30,9 @@ func NewGetLabelRelationshipListLogic(ctx context.Context, svcCtx *svc.ServiceCo
 }
 
 func (l *GetLabelRelationshipListLogic) GetLabelRelationshipList(req *types.LabelRelationshipListReq) (*types.LabelRelationshipListResp, error) {
+	organizationId := l.ctx.Value("organizationId").(uint64)
 	var predicates []predicate.LabelRelationship
+	predicates = append(predicates, labelrelationship.OrganizationIDEQ(organizationId))
 	data, err := l.svcCtx.DB.LabelRelationship.Query().Where(predicates...).Page(l.ctx, req.Page, req.PageSize)
 
 	if err != nil {

+ 11 - 9
internal/logic/label_relationship/update_label_relationship_logic.go

@@ -2,12 +2,12 @@ package label_relationship
 
 import (
 	"context"
+	"wechat-api/ent/labelrelationship"
 
 	"wechat-api/internal/svc"
 	"wechat-api/internal/types"
 	"wechat-api/internal/utils/dberrorhandler"
 
-
 	"github.com/suyuan32/simple-admin-common/msg/errormsg"
 	"github.com/zeromicro/go-zero/core/logx"
 )
@@ -27,15 +27,17 @@ func NewUpdateLabelRelationshipLogic(ctx context.Context, svcCtx *svc.ServiceCon
 }
 
 func (l *UpdateLabelRelationshipLogic) UpdateLabelRelationship(req *types.LabelRelationshipInfo) (*types.BaseMsgResp, error) {
-    err := l.svcCtx.DB.LabelRelationship.UpdateOneID(*req.Id).
-			SetNotNilStatus(req.Status).
-			SetNotNilLabelID(req.LabelId).
-			SetNotNilContactID(req.ContactId).
-			Exec(l.ctx)
-
-    if err != nil {
+	organizationId := l.ctx.Value("organizationId").(uint64)
+	err := l.svcCtx.DB.LabelRelationship.UpdateOneID(*req.Id).
+		Where(labelrelationship.OrganizationID(organizationId)).
+		SetNotNilStatus(req.Status).
+		SetNotNilLabelID(req.LabelId).
+		SetNotNilContactID(req.ContactId).
+		Exec(l.ctx)
+
+	if err != nil {
 		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
 	}
 
-    return &types.BaseMsgResp{Msg: errormsg.UpdateSuccess}, nil
+	return &types.BaseMsgResp{Msg: errormsg.UpdateSuccess}, nil
 }

+ 16 - 9
internal/logic/label_relationship/update_label_relationships_logic.go

@@ -2,6 +2,7 @@ package label_relationship
 
 import (
 	"context"
+	"fmt"
 	"github.com/suyuan32/simple-admin-common/msg/errormsg"
 	"wechat-api/ent"
 	"wechat-api/ent/contact"
@@ -30,6 +31,7 @@ func NewUpdateLabelRelationshipsLogic(ctx context.Context, svcCtx *svc.ServiceCo
 }
 
 func (l *UpdateLabelRelationshipsLogic) UpdateLabelRelationships(req *types.LabelRelationshipsInfo) (resp *types.BaseMsgResp, err error) {
+	organizationId := l.ctx.Value("organizationId").(uint64)
 	// 开始事务
 	tx, err := l.svcCtx.DB.Tx(context.Background())
 	if err != nil {
@@ -37,7 +39,7 @@ func (l *UpdateLabelRelationshipsLogic) UpdateLabelRelationships(req *types.Labe
 	}
 
 	// 获取联系人信息
-	c, err := tx.Contact.Query().Where(contact.ID(*req.ContactId)).Only(l.ctx)
+	c, err := tx.Contact.Query().Where(contact.ID(*req.ContactId), contact.OrganizationIDEQ(organizationId)).Only(l.ctx)
 	// 获取联系人当前已关联的标签
 	currentLabelRelationships, err := tx.LabelRelationship.Query().Where(labelrelationship.ContactID(*req.ContactId)).All(l.ctx)
 	if err != nil {
@@ -77,6 +79,7 @@ func (l *UpdateLabelRelationshipsLogic) UpdateLabelRelationships(req *types.Labe
 		_, _ = tx.LabelRelationship.Create().
 			SetLabelID(id).
 			SetContactID(*req.ContactId).
+			SetOrganizationID(organizationId).
 			Save(l.ctx)
 		//if err != nil {
 		//	return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
@@ -84,7 +87,7 @@ func (l *UpdateLabelRelationshipsLogic) UpdateLabelRelationships(req *types.Labe
 	}
 
 	// 获取所有 status 为 3 且 bot_wxid_list 包含 c.wx_wxid 的 sop_task
-	sopTasks, err := tx.SopTask.Query().Where(soptask.Status(3)).All(l.ctx)
+	sopTasks, err := tx.SopTask.Query().Where(soptask.Status(3), soptask.OrganizationIDEQ(organizationId)).All(l.ctx)
 	if err != nil {
 		_ = tx.Rollback()
 		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
@@ -110,7 +113,7 @@ func (l *UpdateLabelRelationshipsLogic) UpdateLabelRelationships(req *types.Labe
 		}
 		sopStages = append(sopStages, stages...)
 	}
-	err = l.AddLabelRelationships(sopStages, *c, req.LabelIds)
+	err = l.AddLabelRelationships(sopStages, *c, req.LabelIds, organizationId)
 
 	if err != nil {
 		_ = tx.Rollback()
@@ -125,7 +128,7 @@ func (l *UpdateLabelRelationshipsLogic) UpdateLabelRelationships(req *types.Labe
 	return &types.BaseMsgResp{Msg: errormsg.UpdateSuccess}, nil
 }
 
-func (l *UpdateLabelRelationshipsLogic) AddLabelRelationships(sopStages []*ent.SopStage, contact ent.Contact, currentLabelIds []uint64) (err error) {
+func (l *UpdateLabelRelationshipsLogic) AddLabelRelationships(sopStages []*ent.SopStage, contact ent.Contact, currentLabelIds []uint64, organizationId uint64) (err error) {
 	//// 开始事务
 	//tx, err := l.svcCtx.DB.Tx(context.Background())
 	//if err != nil {
@@ -165,6 +168,7 @@ func (l *UpdateLabelRelationshipsLogic) AddLabelRelationships(sopStages []*ent.S
 						SetNotNilSourceType(&sourceType).
 						SetNotNilSourceID(&stage.ID).
 						SetSubSourceID(uint64(i)).
+						SetOrganizationID(organizationId).
 						Save(l.ctx)
 
 					//if err != nil {
@@ -173,6 +177,7 @@ func (l *UpdateLabelRelationshipsLogic) AddLabelRelationships(sopStages []*ent.S
 				}
 			}
 			if stage.ActionLabel != nil {
+				fmt.Printf("---------------stage.ActionLabel----------------: %+v\n\n", stage.ActionLabel)
 				// 获取 addLabelIds 中不在 currentLabelIds 中的标签ID
 				var newLabelIds []uint64
 				// 创建一个映射,用于快速查找 currentLabelIds 中的元素
@@ -192,19 +197,21 @@ func (l *UpdateLabelRelationshipsLogic) AddLabelRelationships(sopStages []*ent.S
 					return nil
 				}
 				// 创建需要新增的标签关系
+				fmt.Printf("---------------newLabelIds----------------: %+v\n\n", newLabelIds)
 				for _, id := range newLabelIds {
-					_, _ = l.svcCtx.DB.LabelRelationship.Create().
+					_, err = l.svcCtx.DB.LabelRelationship.Create().
 						SetLabelID(id).
 						SetContactID(contact.ID).
+						SetOrganizationID(organizationId).
 						Save(l.ctx)
-					//if err != nil {
-					//	return dberrorhandler.DefaultEntError(l.Logger, err, nil)
-					//}
+					if err != nil {
+						fmt.Printf("---------------err----------------: %+v\n\n", err)
+					}
 				}
 				// 合并 currentLabelIds 和 newLabelIds
 				currentLabelIds = append(currentLabelIds, newLabelIds...)
 				// 递归调用 AddLabelRelationships
-				_ = l.AddLabelRelationships(sopStages, contact, currentLabelIds)
+				_ = l.AddLabelRelationships(sopStages, contact, currentLabelIds, organizationId)
 				return
 			}
 		}

+ 2 - 0
internal/logic/message_records/create_message_records_logic.go

@@ -28,6 +28,7 @@ func NewCreateMessageRecordsLogic(ctx context.Context, svcCtx *svc.ServiceContex
 }
 
 func (l *CreateMessageRecordsLogic) CreateMessageRecords(req *types.MessageRecordsInfo) (*types.BaseMsgResp, error) {
+	organizationId := l.ctx.Value("organizationId").(uint64)
 	meta := custom_types.Meta{}
 	if req.Meta != nil {
 		meta.Filename = req.Meta.Filename
@@ -47,6 +48,7 @@ func (l *CreateMessageRecordsLogic) CreateMessageRecords(req *types.MessageRecor
 		SetNotNilSourceType(req.SourceType).
 		SetNotNilSourceID(req.SourceId).
 		SetNotNilSubSourceID(req.SubSourceId).
+		SetOrganizationID(organizationId).
 		Save(l.ctx)
 
 	if err != nil {

+ 10 - 9
internal/logic/message_records/delete_message_records_logic.go

@@ -3,13 +3,13 @@ package message_records
 import (
 	"context"
 
-    "wechat-api/ent/messagerecords"
-    "wechat-api/internal/svc"
-    "wechat-api/internal/types"
-    "wechat-api/internal/utils/dberrorhandler"
+	"wechat-api/ent/messagerecords"
+	"wechat-api/internal/svc"
+	"wechat-api/internal/types"
+	"wechat-api/internal/utils/dberrorhandler"
 
-    "github.com/suyuan32/simple-admin-common/msg/errormsg"
-    "github.com/zeromicro/go-zero/core/logx"
+	"github.com/suyuan32/simple-admin-common/msg/errormsg"
+	"github.com/zeromicro/go-zero/core/logx"
 )
 
 type DeleteMessageRecordsLogic struct {
@@ -27,11 +27,12 @@ func NewDeleteMessageRecordsLogic(ctx context.Context, svcCtx *svc.ServiceContex
 }
 
 func (l *DeleteMessageRecordsLogic) DeleteMessageRecords(req *types.IDsReq) (*types.BaseMsgResp, error) {
-	_, err := l.svcCtx.DB.MessageRecords.Delete().Where(messagerecords.IDIn(req.Ids...)).Exec(l.ctx)
+	organizationId := l.ctx.Value("organizationId").(uint64)
+	_, err := l.svcCtx.DB.MessageRecords.Delete().Where(messagerecords.IDIn(req.Ids...), messagerecords.OrganizationIDEQ(organizationId)).Exec(l.ctx)
 
-    if err != nil {
+	if err != nil {
 		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
 	}
 
-    return &types.BaseMsgResp{Msg: errormsg.DeleteSuccess}, nil
+	return &types.BaseMsgResp{Msg: errormsg.DeleteSuccess}, nil
 }

+ 32 - 26
internal/logic/message_records/get_message_records_by_id_logic.go

@@ -2,12 +2,13 @@ package message_records
 
 import (
 	"context"
+	"wechat-api/ent/messagerecords"
 
 	"wechat-api/internal/svc"
 	"wechat-api/internal/types"
 	"wechat-api/internal/utils/dberrorhandler"
 
-    "github.com/suyuan32/simple-admin-common/msg/errormsg"
+	"github.com/suyuan32/simple-admin-common/msg/errormsg"
 
 	"github.com/suyuan32/simple-admin-common/utils/pointy"
 	"github.com/zeromicro/go-zero/core/logx"
@@ -28,35 +29,40 @@ func NewGetMessageRecordsByIdLogic(ctx context.Context, svcCtx *svc.ServiceConte
 }
 
 func (l *GetMessageRecordsByIdLogic) GetMessageRecordsById(req *types.IDReq) (*types.MessageRecordsInfoResp, error) {
-	data, err := l.svcCtx.DB.MessageRecords.Get(l.ctx, req.Id)
+	organizationId := l.ctx.Value("organizationId").(uint64)
+	data, err := l.svcCtx.DB.MessageRecords.Query().
+		Where(
+			messagerecords.IDEQ(req.Id),                   // Filter by ID
+			messagerecords.OrganizationID(organizationId), // Additional filter by organizationId
+		).
+		Only(l.ctx)
 	if err != nil {
 		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
 	}
 
 	return &types.MessageRecordsInfoResp{
-	    BaseDataInfo: types.BaseDataInfo{
-            Code: 0,
-            Msg:  errormsg.Success,
-        },
-        Data: types.MessageRecordsInfo{
-            BaseIDInfo:    types.BaseIDInfo{
-				Id:          &data.ID,
-				CreatedAt:    pointy.GetPointer(data.CreatedAt.UnixMilli()),
-				UpdatedAt:    pointy.GetPointer(data.UpdatedAt.UnixMilli()),
-            },
-			Status:	&data.Status,
-			BotWxid:	&data.BotWxid,
-			ContactId:	&data.ContactID,
-			ContactType:	&data.ContactType,
-			ContactWxid:	&data.ContactWxid,
-			ContentType:	&data.ContentType,
-			Content:	&data.Content,
-			ErrorDetail:	&data.ErrorDetail,
-			SendTime:	pointy.GetUnixMilliPointer(data.SendTime.UnixMilli()),
-			SourceType:	&data.SourceType,
-			SourceId:	&data.SourceID,
-			SubSourceId:	&data.SubSourceID,
-        },
+		BaseDataInfo: types.BaseDataInfo{
+			Code: 0,
+			Msg:  errormsg.Success,
+		},
+		Data: types.MessageRecordsInfo{
+			BaseIDInfo: types.BaseIDInfo{
+				Id:        &data.ID,
+				CreatedAt: pointy.GetPointer(data.CreatedAt.UnixMilli()),
+				UpdatedAt: pointy.GetPointer(data.UpdatedAt.UnixMilli()),
+			},
+			Status:      &data.Status,
+			BotWxid:     &data.BotWxid,
+			ContactId:   &data.ContactID,
+			ContactType: &data.ContactType,
+			ContactWxid: &data.ContactWxid,
+			ContentType: &data.ContentType,
+			Content:     &data.Content,
+			ErrorDetail: &data.ErrorDetail,
+			SendTime:    pointy.GetUnixMilliPointer(data.SendTime.UnixMilli()),
+			SourceType:  &data.SourceType,
+			SourceId:    &data.SourceID,
+			SubSourceId: &data.SubSourceID,
+		},
 	}, nil
 }
-

+ 22 - 21
internal/logic/message_records/get_message_records_list_logic.go

@@ -2,14 +2,13 @@ package message_records
 
 import (
 	"context"
-
 	"wechat-api/ent/messagerecords"
 	"wechat-api/ent/predicate"
 	"wechat-api/internal/svc"
 	"wechat-api/internal/types"
 	"wechat-api/internal/utils/dberrorhandler"
 
-    "github.com/suyuan32/simple-admin-common/msg/errormsg"
+	"github.com/suyuan32/simple-admin-common/msg/errormsg"
 
 	"github.com/suyuan32/simple-admin-common/utils/pointy"
 	"github.com/zeromicro/go-zero/core/logx"
@@ -30,7 +29,9 @@ func NewGetMessageRecordsListLogic(ctx context.Context, svcCtx *svc.ServiceConte
 }
 
 func (l *GetMessageRecordsListLogic) GetMessageRecordsList(req *types.MessageRecordsListReq) (*types.MessageRecordsListResp, error) {
+	organizationId := l.ctx.Value("organizationId").(uint64)
 	var predicates []predicate.MessageRecords
+	predicates = append(predicates, messagerecords.OrganizationIDEQ(organizationId))
 	if req.BotWxid != nil {
 		predicates = append(predicates, messagerecords.BotWxidContains(*req.BotWxid))
 	}
@@ -52,25 +53,25 @@ func (l *GetMessageRecordsListLogic) GetMessageRecordsList(req *types.MessageRec
 
 	for _, v := range data.List {
 		resp.Data.Data = append(resp.Data.Data,
-		types.MessageRecordsInfo{
-			BaseIDInfo:    types.BaseIDInfo{
-				Id:          &v.ID,
-				CreatedAt:    pointy.GetPointer(v.CreatedAt.UnixMilli()),
-				UpdatedAt:    pointy.GetPointer(v.UpdatedAt.UnixMilli()),
-            },
-			Status:	&v.Status,
-			BotWxid:	&v.BotWxid,
-			ContactId:	&v.ContactID,
-			ContactType:	&v.ContactType,
-			ContactWxid:	&v.ContactWxid,
-			ContentType:	&v.ContentType,
-			Content:	&v.Content,
-			ErrorDetail:	&v.ErrorDetail,
-			SendTime:	pointy.GetUnixMilliPointer(v.SendTime.UnixMilli()),
-			SourceType:	&v.SourceType,
-			SourceId:	&v.SourceID,
-			SubSourceId:	&v.SubSourceID,
-		})
+			types.MessageRecordsInfo{
+				BaseIDInfo: types.BaseIDInfo{
+					Id:        &v.ID,
+					CreatedAt: pointy.GetPointer(v.CreatedAt.UnixMilli()),
+					UpdatedAt: pointy.GetPointer(v.UpdatedAt.UnixMilli()),
+				},
+				Status:      &v.Status,
+				BotWxid:     &v.BotWxid,
+				ContactId:   &v.ContactID,
+				ContactType: &v.ContactType,
+				ContactWxid: &v.ContactWxid,
+				ContentType: &v.ContentType,
+				Content:     &v.Content,
+				ErrorDetail: &v.ErrorDetail,
+				SendTime:    pointy.GetUnixMilliPointer(v.SendTime.UnixMilli()),
+				SourceType:  &v.SourceType,
+				SourceId:    &v.SourceID,
+				SubSourceId: &v.SubSourceID,
+			})
 	}
 
 	return resp, nil

+ 20 - 18
internal/logic/message_records/update_message_records_logic.go

@@ -2,12 +2,12 @@ package message_records
 
 import (
 	"context"
+	"wechat-api/ent/messagerecords"
 
 	"wechat-api/internal/svc"
 	"wechat-api/internal/types"
 	"wechat-api/internal/utils/dberrorhandler"
 
-
 	"github.com/suyuan32/simple-admin-common/msg/errormsg"
 	"github.com/suyuan32/simple-admin-common/utils/pointy"
 	"github.com/zeromicro/go-zero/core/logx"
@@ -28,24 +28,26 @@ func NewUpdateMessageRecordsLogic(ctx context.Context, svcCtx *svc.ServiceContex
 }
 
 func (l *UpdateMessageRecordsLogic) UpdateMessageRecords(req *types.MessageRecordsInfo) (*types.BaseMsgResp, error) {
-    err := l.svcCtx.DB.MessageRecords.UpdateOneID(*req.Id).
-			SetNotNilStatus(req.Status).
-			SetNotNilBotWxid(req.BotWxid).
-			SetNotNilContactID(req.ContactId).
-			SetNotNilContactType(req.ContactType).
-			SetNotNilContactWxid(req.ContactWxid).
-			SetNotNilContentType(req.ContentType).
-			SetNotNilContent(req.Content).
-			SetNotNilErrorDetail(req.ErrorDetail).
-			SetNotNilSendTime(pointy.GetTimeMilliPointer(req.SendTime)).
-			SetNotNilSourceType(req.SourceType).
-			SetNotNilSourceID(req.SourceId).
-			SetNotNilSubSourceID(req.SubSourceId).
-			Exec(l.ctx)
-
-    if err != nil {
+	organizationId := l.ctx.Value("organizationId").(uint64)
+	err := l.svcCtx.DB.MessageRecords.UpdateOneID(*req.Id).
+		Where(messagerecords.OrganizationID(organizationId)).
+		SetNotNilStatus(req.Status).
+		SetNotNilBotWxid(req.BotWxid).
+		SetNotNilContactID(req.ContactId).
+		SetNotNilContactType(req.ContactType).
+		SetNotNilContactWxid(req.ContactWxid).
+		SetNotNilContentType(req.ContentType).
+		SetNotNilContent(req.Content).
+		SetNotNilErrorDetail(req.ErrorDetail).
+		SetNotNilSendTime(pointy.GetTimeMilliPointer(req.SendTime)).
+		SetNotNilSourceType(req.SourceType).
+		SetNotNilSourceID(req.SourceId).
+		SetNotNilSubSourceID(req.SubSourceId).
+		Exec(l.ctx)
+
+	if err != nil {
 		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
 	}
 
-    return &types.BaseMsgResp{Msg: errormsg.UpdateSuccess}, nil
+	return &types.BaseMsgResp{Msg: errormsg.UpdateSuccess}, nil
 }

+ 2 - 1
internal/logic/sop_node/create_sop_node_logic.go

@@ -29,6 +29,7 @@ func NewCreateSopNodeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Cre
 }
 
 func (l *CreateSopNodeLogic) CreateSopNode(req *types.SopNodeInfo) (*types.SopNodeCreateResp, error) {
+	organizationId := l.ctx.Value("organizationId").(uint64)
 	// 根据 id 关联查询处 task 信息,并判断 status 是否为 1
 	data, err := l.svcCtx.DB.SopStage.Query().
 		Where(sopstage.ID(*req.StageId)).
@@ -38,7 +39,7 @@ func (l *CreateSopNodeLogic) CreateSopNode(req *types.SopNodeInfo) (*types.SopNo
 		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
 	}
 	task := data.Edges.SopTask
-	if task.Status != 1 {
+	if task.Status != 1 || task.OrganizationID != organizationId {
 		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
 	}
 	fmt.Printf("req.ActionMessage: %+v\n", req.ActionMessage)

+ 2 - 1
internal/logic/sop_node/delete_sop_node_logic.go

@@ -28,6 +28,7 @@ func NewDeleteSopNodeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Del
 }
 
 func (l *DeleteSopNodeLogic) DeleteSopNode(req *types.IDReq) (*types.BaseMsgResp, error) {
+	organizationId := l.ctx.Value("organizationId").(uint64)
 	// 根据 id 关联查询处 task 信息,并判断 status 是否为 1
 	data, err := l.svcCtx.DB.SopNode.Query().
 		Where(sopnode.ID(req.Id)).
@@ -39,7 +40,7 @@ func (l *DeleteSopNodeLogic) DeleteSopNode(req *types.IDReq) (*types.BaseMsgResp
 		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
 	}
 	task := data.Edges.SopStage.Edges.SopTask
-	if task.Status != 1 {
+	if task.Status != 1 || task.OrganizationID != organizationId {
 		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
 	}
 

+ 2 - 1
internal/logic/sop_node/update_sop_node_logic.go

@@ -29,6 +29,7 @@ func NewUpdateSopNodeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Upd
 }
 
 func (l *UpdateSopNodeLogic) UpdateSopNode(req *types.SopNodeInfo) (*types.BaseMsgResp, error) {
+	organizationId := l.ctx.Value("organizationId").(uint64)
 	// 根据 id 关联查询处 task 信息,并判断 status 是否为 1
 	data, err := l.svcCtx.DB.SopNode.Query().
 		Where(sopnode.ID(*req.Id)).
@@ -41,7 +42,7 @@ func (l *UpdateSopNodeLogic) UpdateSopNode(req *types.SopNodeInfo) (*types.BaseM
 	}
 
 	task := data.Edges.SopStage.Edges.SopTask
-	if task.Status != 1 {
+	if task.Status != 1 || task.OrganizationID != organizationId {
 		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
 	}
 

+ 5 - 1
internal/logic/sop_stage/create_sop_stage_logic.go

@@ -4,6 +4,7 @@ import (
 	"context"
 	"wechat-api/ent/custom_types"
 	"wechat-api/ent/sopstage"
+	"wechat-api/ent/soptask"
 
 	"wechat-api/internal/svc"
 	"wechat-api/internal/types"
@@ -29,8 +30,11 @@ func NewCreateSopStageLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Cr
 }
 
 func (l *CreateSopStageLogic) CreateSopStage(req *types.SopStageInfo) (*types.SopStageCreateResp, error) {
+	organizationId := l.ctx.Value("organizationId").(uint64)
 	// 根据 task_id 查询 task 是否存在
-	task, err := l.svcCtx.DB.SopTask.Get(l.ctx, *req.TaskId)
+	task, err := l.svcCtx.DB.SopTask.Query().
+		Where(soptask.ID(*req.TaskId), soptask.OrganizationIDEQ(organizationId)).
+		Only(l.ctx)
 	if err != nil {
 		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
 	}

+ 2 - 1
internal/logic/sop_stage/delete_sop_stage_logic.go

@@ -28,6 +28,7 @@ func NewDeleteSopStageLogic(ctx context.Context, svcCtx *svc.ServiceContext) *De
 }
 
 func (l *DeleteSopStageLogic) DeleteSopStage(req *types.IDReq) (*types.BaseMsgResp, error) {
+	organizationId := l.ctx.Value("organizationId").(uint64)
 	// 根据 id 关联查询 task 信息,并判断 task 的状态是否为 1
 	data, err := l.svcCtx.DB.SopStage.Query().
 		Where(sopstage.ID(req.Id)).
@@ -37,7 +38,7 @@ func (l *DeleteSopStageLogic) DeleteSopStage(req *types.IDReq) (*types.BaseMsgRe
 		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
 	}
 	task := data.Edges.SopTask
-	if task.Status != 1 {
+	if task.Status != 1 || task.OrganizationID != organizationId {
 		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
 	}
 

+ 2 - 1
internal/logic/sop_stage/update_sop_stage_logic.go

@@ -28,6 +28,7 @@ func NewUpdateSopStageLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Up
 }
 
 func (l *UpdateSopStageLogic) UpdateSopStage(req *types.SopStageInfo) (*types.BaseMsgResp, error) {
+	organizationId := l.ctx.Value("organizationId").(uint64)
 	// 根据 id 关联查询 task 信息,并判断 task 的状态是否为 1
 	data, err := l.svcCtx.DB.SopStage.Query().
 		Where(sopstage.ID(*req.Id)).
@@ -37,7 +38,7 @@ func (l *UpdateSopStageLogic) UpdateSopStage(req *types.SopStageInfo) (*types.Ba
 		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
 	}
 	task := data.Edges.SopTask
-	if task.Status != 1 {
+	if task.Status != 1 || task.OrganizationID != organizationId {
 		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
 	}
 

+ 4 - 0
internal/logic/sop_task/create_sop_task_logic.go

@@ -27,6 +27,9 @@ func NewCreateSopTaskLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Cre
 }
 
 func (l *CreateSopTaskLogic) CreateSopTask(req *types.SopTaskInfo) (*types.SopTaskCreateResp, error) {
+	organizationId := l.ctx.Value("organizationId").(uint64)
+	//departmentId := l.ctx.Value("departmentId").(uint64)
+
 	// 判断 planEndTime 和 planStartTime 是否非空,且 planEndTime 是否大于 planStartTime
 	if req.PlanEndTime != nil && req.PlanStartTime != nil && (*req.PlanEndTime <= *req.PlanStartTime) {
 		return nil, dberrorhandler.DefaultEntError(l.Logger, fmt.Errorf("planEndTime must be greater than planStartTime"), req)
@@ -42,6 +45,7 @@ func (l *CreateSopTaskLogic) CreateSopTask(req *types.SopTaskInfo) (*types.SopTa
 		SetNotNilPlanStartTime(pointy.GetTimeMilliPointer(req.PlanStartTime)).
 		SetNotNilPlanEndTime(pointy.GetTimeMilliPointer(req.PlanEndTime)).
 		SetNotNilCreatorID(&currentUserID).
+		SetOrganizationID(organizationId).
 		Save(l.ctx)
 
 	if err != nil {

+ 10 - 9
internal/logic/sop_task/delete_sop_task_logic.go

@@ -3,13 +3,13 @@ package sop_task
 import (
 	"context"
 
-    "wechat-api/ent/soptask"
-    "wechat-api/internal/svc"
-    "wechat-api/internal/types"
-    "wechat-api/internal/utils/dberrorhandler"
+	"wechat-api/ent/soptask"
+	"wechat-api/internal/svc"
+	"wechat-api/internal/types"
+	"wechat-api/internal/utils/dberrorhandler"
 
-    "github.com/suyuan32/simple-admin-common/msg/errormsg"
-    "github.com/zeromicro/go-zero/core/logx"
+	"github.com/suyuan32/simple-admin-common/msg/errormsg"
+	"github.com/zeromicro/go-zero/core/logx"
 )
 
 type DeleteSopTaskLogic struct {
@@ -27,11 +27,12 @@ func NewDeleteSopTaskLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Del
 }
 
 func (l *DeleteSopTaskLogic) DeleteSopTask(req *types.IDsReq) (*types.BaseMsgResp, error) {
-	_, err := l.svcCtx.DB.SopTask.Delete().Where(soptask.IDIn(req.Ids...)).Exec(l.ctx)
+	organizationId := l.ctx.Value("organizationId").(uint64)
+	_, err := l.svcCtx.DB.SopTask.Delete().Where(soptask.IDIn(req.Ids...), soptask.OrganizationIDEQ(organizationId)).Exec(l.ctx)
 
-    if err != nil {
+	if err != nil {
 		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
 	}
 
-    return &types.BaseMsgResp{Msg: errormsg.DeleteSuccess}, nil
+	return &types.BaseMsgResp{Msg: errormsg.DeleteSuccess}, nil
 }

+ 2 - 1
internal/logic/sop_task/get_sop_task_by_id_logic.go

@@ -29,8 +29,9 @@ func NewGetSopTaskByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Ge
 }
 
 func (l *GetSopTaskByIdLogic) GetSopTaskById(req *types.IDReq) (*types.SopTaskInfoResp, error) {
+	organizationId := l.ctx.Value("organizationId").(uint64)
 	data, err := l.svcCtx.DB.SopTask.Query().
-		Where(soptask.ID(req.Id)).
+		Where(soptask.ID(req.Id), soptask.OrganizationIDEQ(organizationId)).
 		WithTaskStages().
 		Only(l.ctx)
 	if err != nil {

+ 2 - 1
internal/logic/sop_task/get_sop_task_detail_logic.go

@@ -27,8 +27,9 @@ func NewGetSopTaskDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *
 }
 
 func (l *GetSopTaskDetailLogic) GetSopTaskDetail(req *types.IDReq) (resp *types.SopTaskInfoResp, err error) {
+	organizationId := l.ctx.Value("organizationId").(uint64)
 	data, err := l.svcCtx.DB.SopTask.Query().
-		Where(soptask.ID(req.Id)).
+		Where(soptask.ID(req.Id), soptask.OrganizationIDEQ(organizationId)).
 		WithTaskStages().
 		Only(l.ctx)
 	if err != nil {

+ 2 - 3
internal/logic/sop_task/get_sop_task_list_logic.go

@@ -2,7 +2,6 @@ package sop_task
 
 import (
 	"context"
-	"fmt"
 	"wechat-api/ent/predicate"
 	"wechat-api/ent/soptask"
 	"wechat-api/internal/svc"
@@ -30,9 +29,9 @@ func NewGetSopTaskListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Ge
 }
 
 func (l *GetSopTaskListLogic) GetSopTaskList(req *types.SopTaskListReq) (*types.SopTaskListResp, error) {
-	departmentId := l.ctx.Value("departmentId")
-	fmt.Printf("---------------departmentId2----------------: %d\n\n", departmentId)
+	organizationId := l.ctx.Value("organizationId").(uint64)
 	var predicates []predicate.SopTask
+	predicates = append(predicates, soptask.OrganizationIDEQ(organizationId))
 	if req.Name != nil {
 		predicates = append(predicates, soptask.NameContains(*req.Name))
 	}

+ 13 - 4
internal/logic/sop_task/publish_sop_task_logic.go

@@ -10,6 +10,7 @@ import (
 	"wechat-api/ent/labelrelationship"
 	"wechat-api/ent/messagerecords"
 	"wechat-api/ent/predicate"
+	"wechat-api/ent/sopstage"
 	"wechat-api/ent/soptask"
 	"wechat-api/internal/utils/dberrorhandler"
 
@@ -33,6 +34,7 @@ func NewPublishSopTaskLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Pu
 }
 
 func (l *PublishSopTaskLogic) PublishSopTask(req *types.IDReq) (resp *types.BaseMsgResp, err error) {
+	organizationId := l.ctx.Value("organizationId").(uint64)
 	// 开始事务
 	//tx, err := l.svcCtx.DB.Tx(context.Background())
 	//if err != nil {
@@ -44,6 +46,7 @@ func (l *PublishSopTaskLogic) PublishSopTask(req *types.IDReq) (resp *types.Base
 		Where(
 			soptask.ID(req.Id),
 			soptask.Status(1),
+			soptask.OrganizationIDEQ(organizationId),
 		).
 		WithTaskStages().
 		Only(l.ctx)
@@ -68,7 +71,9 @@ func (l *PublishSopTaskLogic) PublishSopTask(req *types.IDReq) (resp *types.Base
 			return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
 		}
 
-		sopStages, err := l.svcCtx.DB.SopStage.Query().All(l.ctx)
+		sopStages, err := l.svcCtx.DB.SopStage.Query().
+			Where(sopstage.HasSopTaskWith(soptask.OrganizationIDEQ(organizationId))).
+			All(l.ctx)
 		if err != nil {
 			//_ = tx.Rollback()
 			return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
@@ -84,6 +89,7 @@ func (l *PublishSopTaskLogic) PublishSopTask(req *types.IDReq) (resp *types.Base
 					subPredicate := contact.HasContactRelationshipsWith(
 						labelrelationship.LabelIDIn(condition.LabelIdList...),
 						labelrelationship.DeletedAtIsNil())
+					labelrelationship.OrganizationIDEQ(organizationId)
 					if condition.Equal == 2 {
 						subPredicate = contact.Not(subPredicate)
 					}
@@ -126,6 +132,7 @@ func (l *PublishSopTaskLogic) PublishSopTask(req *types.IDReq) (resp *types.Base
 								SetNotNilSourceType(&sourceType).
 								SetNotNilSourceID(&stage.ID).
 								SetSubSourceID(uint64(i)).
+								SetOrganizationID(organizationId).
 								Save(l.ctx)
 
 							//if err != nil {
@@ -148,7 +155,7 @@ func (l *PublishSopTaskLogic) PublishSopTask(req *types.IDReq) (resp *types.Base
 
 						if stage.ActionLabel != nil {
 							// 递归调用 AddLabelRelationships
-							err = l.AddLabelRelationships(sopStages, *c, currentLabelIds, stage.ActionLabel)
+							err = l.AddLabelRelationships(sopStages, *c, currentLabelIds, stage.ActionLabel, organizationId)
 							if err != nil {
 								//_ = tx.Rollback()
 								return nil, err
@@ -175,7 +182,7 @@ func (l *PublishSopTaskLogic) PublishSopTask(req *types.IDReq) (resp *types.Base
 	}
 }
 
-func (l *PublishSopTaskLogic) AddLabelRelationships(sopStages []*ent.SopStage, contact ent.Contact, currentLabelIds []uint64, addLabelIds []uint64) (err error) {
+func (l *PublishSopTaskLogic) AddLabelRelationships(sopStages []*ent.SopStage, contact ent.Contact, currentLabelIds []uint64, addLabelIds []uint64, organizationId uint64) (err error) {
 	//// 开始事务
 	//tx, err := l.svcCtx.DB.Tx(context.Background())
 	//if err != nil {
@@ -206,6 +213,7 @@ func (l *PublishSopTaskLogic) AddLabelRelationships(sopStages []*ent.SopStage, c
 		_, err = l.svcCtx.DB.LabelRelationship.Create().
 			SetLabelID(id).
 			SetContactID(contact.ID).
+			SetOrganizationID(organizationId).
 			Save(l.ctx)
 		if err != nil {
 			//_ = tx.Rollback()
@@ -250,6 +258,7 @@ func (l *PublishSopTaskLogic) AddLabelRelationships(sopStages []*ent.SopStage, c
 						SetNotNilSourceType(&sourceType).
 						SetNotNilSourceID(&stage.ID).
 						SetSubSourceID(uint64(i)).
+						SetOrganizationID(organizationId).
 						Save(l.ctx)
 
 					//if err != nil {
@@ -259,7 +268,7 @@ func (l *PublishSopTaskLogic) AddLabelRelationships(sopStages []*ent.SopStage, c
 			}
 			if stage.ActionLabel != nil {
 				// 递归调用 AddLabelRelationships
-				err = l.AddLabelRelationships(sopStages, contact, currentLabelIds, stage.ActionLabel)
+				err = l.AddLabelRelationships(sopStages, contact, currentLabelIds, stage.ActionLabel, organizationId)
 				if err != nil {
 					//_ = tx.Rollback()
 					return err

+ 8 - 1
internal/logic/sop_task/sop_task_start_logic.go

@@ -4,6 +4,7 @@ import (
 	"context"
 	"github.com/suyuan32/simple-admin-common/msg/errormsg"
 	"wechat-api/ent/messagerecords"
+	"wechat-api/ent/soptask"
 	"wechat-api/internal/utils/dberrorhandler"
 
 	"wechat-api/internal/svc"
@@ -26,6 +27,7 @@ func NewSopTaskStartLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SopT
 }
 
 func (l *SopTaskStartLogic) SopTaskStart(req *types.IDReq) (resp *types.BaseMsgResp, err error) {
+	organizationId := l.ctx.Value("organizationId").(uint64)
 	// 开始事务
 	tx, err := l.svcCtx.DB.Tx(context.Background())
 	if err != nil {
@@ -33,7 +35,12 @@ func (l *SopTaskStartLogic) SopTaskStart(req *types.IDReq) (resp *types.BaseMsgR
 	}
 
 	// 根据 id 查询 task 信息,如果 Status 的值不为 1,则不允许修改
-	task, err := tx.SopTask.Get(l.ctx, req.Id)
+	task, err := tx.SopTask.Query().
+		Where(
+			soptask.IDEQ(req.Id),                   // Filter by ID
+			soptask.OrganizationID(organizationId), // Additional filter by organizationId
+		).
+		Only(l.ctx)
 	if err != nil {
 		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
 	}

+ 8 - 1
internal/logic/sop_task/sop_task_stop_logic.go

@@ -4,6 +4,7 @@ import (
 	"context"
 	"github.com/suyuan32/simple-admin-common/msg/errormsg"
 	"wechat-api/ent/messagerecords"
+	"wechat-api/ent/soptask"
 	"wechat-api/internal/utils/dberrorhandler"
 
 	"wechat-api/internal/svc"
@@ -26,6 +27,7 @@ func NewSopTaskStopLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SopTa
 }
 
 func (l *SopTaskStopLogic) SopTaskStop(req *types.IDReq) (resp *types.BaseMsgResp, err error) {
+	organizationId := l.ctx.Value("organizationId").(uint64)
 	// 开始事务
 	tx, err := l.svcCtx.DB.Tx(context.Background())
 	if err != nil {
@@ -33,7 +35,12 @@ func (l *SopTaskStopLogic) SopTaskStop(req *types.IDReq) (resp *types.BaseMsgRes
 	}
 
 	// 根据 id 查询 task 信息,如果 Status 的值不为 1,则不允许修改
-	task, err := tx.SopTask.Get(l.ctx, req.Id)
+	task, err := tx.SopTask.Query().
+		Where(
+			soptask.IDEQ(req.Id),                   // Filter by ID
+			soptask.OrganizationID(organizationId), // Additional filter by organizationId
+		).
+		Only(l.ctx)
 	if err != nil {
 		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
 	}

+ 4 - 10
internal/logic/sop_task/update_sop_task_logic.go

@@ -3,6 +3,7 @@ package sop_task
 import (
 	"context"
 	"fmt"
+	"wechat-api/ent/soptask"
 	"wechat-api/internal/svc"
 	"wechat-api/internal/types"
 	"wechat-api/internal/utils/dberrorhandler"
@@ -27,21 +28,14 @@ func NewUpdateSopTaskLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Upd
 }
 
 func (l *UpdateSopTaskLogic) UpdateSopTask(req *types.SopTaskInfo) (*types.BaseMsgResp, error) {
+	organizationId := l.ctx.Value("organizationId").(uint64)
 	// 判断 planEndTime 和 planStartTime 是否非空,且 planEndTime 是否大于 planStartTime
 	if req.PlanEndTime != nil && req.PlanStartTime != nil && (*req.PlanEndTime <= *req.PlanStartTime) {
 		return nil, dberrorhandler.DefaultEntError(l.Logger, fmt.Errorf("planEndTime must be greater than planStartTime"), req)
 	}
 
-	// 根据 id 查询 task 信息,如果 Status 的值不为 1,则不允许修改
-	task, err := l.svcCtx.DB.SopTask.Get(l.ctx, *req.Id)
-	if err != nil {
-		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
-	}
-	if task.Status != 1 {
-		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
-	}
-
-	err = l.svcCtx.DB.SopTask.UpdateOneID(*req.Id).
+	err := l.svcCtx.DB.SopTask.UpdateOneID(*req.Id).
+		Where(soptask.StatusEQ(1), soptask.OrganizationID(organizationId)).
 		SetNotNilStatus(req.Status).
 		SetNotNilName(req.Name).
 		SetNotNilBotWxidList(req.BotWxidList).

+ 2 - 1
internal/middleware/authority_middleware.go

@@ -67,7 +67,8 @@ func (m *AuthorityMiddleware) Handle(next http.HandlerFunc) http.HandlerFunc {
 				return
 			}
 			// 将 data.DepartmentID 插入上下文,以供后续接口使用
-			r = r.WithContext(context.WithValue(r.Context(), "departmentId", *data.DepartmentId))
+			//fmt.Printf("---------------departmentId----------------: %d\n\n", *data.DepartmentId)
+			r = r.WithContext(context.WithValue(r.Context(), "organizationId", *data.DepartmentId))
 			next(w, r)
 			return
 		} else {

+ 12 - 0
internal/types/types.go

@@ -311,6 +311,8 @@ type WxInfo struct {
 	Tel *string `json:"tel,optional"`
 	// 微信头像
 	HeadBig *string `json:"headBig,optional"`
+	// 组织ID
+	OrganizationId *uint64 `json:"organizationId,optional"`
 }
 
 // The response data of wx list | Wx列表数据
@@ -507,6 +509,8 @@ type ContactInfo struct {
 	V3 *string `json:"v3,optional"`
 	// Label Relationships | 标签关系
 	LabelRelationships []ContactLabelList `json:"labelRelationships,optional"`
+	// 组织ID
+	OrganizationId *uint64 `json:"organizationId,optional"`
 }
 
 // The response data of label information | Label信息
@@ -525,6 +529,8 @@ type LabelInfo struct {
 	Mode *int `json:"mode,optional"`
 	// 标签的触达条件
 	Conditions *string `json:"conditions,optional"`
+	// 组织ID
+	OrganizationId *uint64 `json:"organizationId,optional"`
 	// Label Relationships | 标签关系
 	LabelRelationships []LabelRelationshipInfo `json:"labelRelationships,optional"`
 }
@@ -543,6 +549,8 @@ type LabelRelationshipInfo struct {
 	Contact ContactInfo `json:"contact,optional"`
 	// Label information | 标签信息
 	Label LabelInfo `json:"label,optional"`
+	// 组织ID
+	OrganizationId *uint64 `json:"organizationId,optional"`
 }
 
 // The response data of label relationship information | LabelRelationship信息
@@ -779,6 +787,8 @@ type SopTaskInfo struct {
 	CreatorId *string `json:"creatorId,optional"`
 	// 阶段信息
 	StageList []SopStageInfo `json:"stageList,optional"`
+	// 组织ID
+	OrganizationId *uint64 `json:"organizationId,optional"`
 }
 
 // The response data of sop node information | SopNode信息
@@ -931,6 +941,8 @@ type MessageRecordsInfo struct {
 	SourceId *uint64 `json:"sourceId,optional"`
 	// 次源 ID
 	SubSourceId *uint64 `json:"subSourceId,optional"`
+	// 组织ID
+	OrganizationId *uint64 `json:"organizationId,optional"`
 }
 
 // The response data of message records list | MessageRecords列表数据

Some files were not shown because too many files changed in this diff