Browse Source

fix:submit

jimmyyem 7 months ago
parent
commit
567712580a

+ 3 - 0
desc/wechat/agent.api

@@ -49,6 +49,9 @@ type (
 
         // background | 背景介绍 
         Background  *string `json:"background,optional"`
+
+		// status | 状态 1-可用 2-不可用
+		Status  *int `json:"status,optional"`
     }
 
     // Agent information response | Agent信息返回体

+ 7 - 0
desc/wechat/wx.api

@@ -1,4 +1,5 @@
 import "../base.api"
+import "./agent.api"
 
 type (
     // The response data of wx information | Wx信息
@@ -37,6 +38,12 @@ type (
 
         // 组织ID
         OrganizationId *uint64 `json:"organizationId,optional"`
+
+		// 模式ID
+		AgentId *uint64 `json:"agentId"`
+
+		// 模式信息
+		AgentInfo *AgentInfo `json:"agentInfo,optional"`
     }
 
     // The response data of wx list | Wx列表数据

+ 27 - 1
ent/agent.go

@@ -35,7 +35,28 @@ type Agent struct {
 	Examples string `json:"examples,omitempty"`
 	// organization_id | 租户ID
 	OrganizationID uint64 `json:"organization_id,omitempty"`
-	selectValues   sql.SelectValues
+	// Edges holds the relations/edges for other nodes in the graph.
+	// The values are being populated by the AgentQuery when eager-loading is set.
+	Edges        AgentEdges `json:"edges"`
+	selectValues sql.SelectValues
+}
+
+// AgentEdges holds the relations/edges for other nodes in the graph.
+type AgentEdges struct {
+	// WxAgent holds the value of the wx_agent edge.
+	WxAgent []*Wx `json:"wx_agent,omitempty"`
+	// loadedTypes holds the information for reporting if a
+	// type was loaded (or requested) in eager-loading or not.
+	loadedTypes [1]bool
+}
+
+// WxAgentOrErr returns the WxAgent value or an error if the edge
+// was not loaded in eager-loading.
+func (e AgentEdges) WxAgentOrErr() ([]*Wx, error) {
+	if e.loadedTypes[0] {
+		return e.WxAgent, nil
+	}
+	return nil, &NotLoadedError{edge: "wx_agent"}
 }
 
 // scanValues returns the types for scanning values from sql.Rows.
@@ -137,6 +158,11 @@ func (a *Agent) Value(name string) (ent.Value, error) {
 	return a.selectValues.Get(name)
 }
 
+// QueryWxAgent queries the "wx_agent" edge of the Agent entity.
+func (a *Agent) QueryWxAgent() *WxQuery {
+	return NewAgentClient(a.config).QueryWxAgent(a)
+}
+
 // Update returns a builder for updating this Agent.
 // Note that you need to call Agent.Unwrap() before calling this method if this Agent
 // was returned from a transaction, and the transaction was committed or rolled back.

+ 35 - 0
ent/agent/agent.go

@@ -7,6 +7,7 @@ import (
 
 	"entgo.io/ent"
 	"entgo.io/ent/dialect/sql"
+	"entgo.io/ent/dialect/sql/sqlgraph"
 )
 
 const (
@@ -32,8 +33,17 @@ const (
 	FieldExamples = "examples"
 	// FieldOrganizationID holds the string denoting the organization_id field in the database.
 	FieldOrganizationID = "organization_id"
+	// EdgeWxAgent holds the string denoting the wx_agent edge name in mutations.
+	EdgeWxAgent = "wx_agent"
 	// Table holds the table name of the agent in the database.
 	Table = "agent"
+	// WxAgentTable is the table that holds the wx_agent relation/edge.
+	WxAgentTable = "wx"
+	// WxAgentInverseTable is the table name for the Wx entity.
+	// It exists in this package in order to avoid circular dependency with the "wx" package.
+	WxAgentInverseTable = "wx"
+	// WxAgentColumn is the table column denoting the wx_agent relation/edge.
+	WxAgentColumn = "agent_id"
 )
 
 // Columns holds all SQL columns for agent fields.
@@ -80,10 +90,14 @@ var (
 	RoleValidator func(string) error
 	// DefaultStatus holds the default value on creation for the "status" field.
 	DefaultStatus int
+	// StatusValidator is a validator for the "status" field. It is called by the builders before save.
+	StatusValidator func(int) error
 	// BackgroundValidator is a validator for the "background" field. It is called by the builders before save.
 	BackgroundValidator func(string) error
 	// ExamplesValidator is a validator for the "examples" field. It is called by the builders before save.
 	ExamplesValidator func(string) error
+	// OrganizationIDValidator is a validator for the "organization_id" field. It is called by the builders before save.
+	OrganizationIDValidator func(uint64) error
 )
 
 // OrderOption defines the ordering options for the Agent queries.
@@ -138,3 +152,24 @@ func ByExamples(opts ...sql.OrderTermOption) OrderOption {
 func ByOrganizationID(opts ...sql.OrderTermOption) OrderOption {
 	return sql.OrderByField(FieldOrganizationID, opts...).ToFunc()
 }
+
+// ByWxAgentCount orders the results by wx_agent count.
+func ByWxAgentCount(opts ...sql.OrderTermOption) OrderOption {
+	return func(s *sql.Selector) {
+		sqlgraph.OrderByNeighborsCount(s, newWxAgentStep(), opts...)
+	}
+}
+
+// ByWxAgent orders the results by wx_agent terms.
+func ByWxAgent(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
+	return func(s *sql.Selector) {
+		sqlgraph.OrderByNeighborTerms(s, newWxAgentStep(), append([]sql.OrderTerm{term}, terms...)...)
+	}
+}
+func newWxAgentStep() *sqlgraph.Step {
+	return sqlgraph.NewStep(
+		sqlgraph.From(Table, FieldID),
+		sqlgraph.To(WxAgentInverseTable, FieldID),
+		sqlgraph.Edge(sqlgraph.O2M, false, WxAgentTable, WxAgentColumn),
+	)
+}

+ 24 - 0
ent/agent/where.go

@@ -7,6 +7,7 @@ import (
 	"wechat-api/ent/predicate"
 
 	"entgo.io/ent/dialect/sql"
+	"entgo.io/ent/dialect/sql/sqlgraph"
 )
 
 // ID filters vertices based on their ID field.
@@ -579,6 +580,29 @@ func OrganizationIDLTE(v uint64) predicate.Agent {
 	return predicate.Agent(sql.FieldLTE(FieldOrganizationID, v))
 }
 
+// HasWxAgent applies the HasEdge predicate on the "wx_agent" edge.
+func HasWxAgent() predicate.Agent {
+	return predicate.Agent(func(s *sql.Selector) {
+		step := sqlgraph.NewStep(
+			sqlgraph.From(Table, FieldID),
+			sqlgraph.Edge(sqlgraph.O2M, false, WxAgentTable, WxAgentColumn),
+		)
+		sqlgraph.HasNeighbors(s, step)
+	})
+}
+
+// HasWxAgentWith applies the HasEdge predicate on the "wx_agent" edge with a given conditions (other predicates).
+func HasWxAgentWith(preds ...predicate.Wx) predicate.Agent {
+	return predicate.Agent(func(s *sql.Selector) {
+		step := newWxAgentStep()
+		sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
+			for _, p := range preds {
+				p(s)
+			}
+		})
+	})
+}
+
 // And groups predicates with the AND operator between them.
 func And(predicates ...predicate.Agent) predicate.Agent {
 	return predicate.Agent(sql.AndPredicates(predicates...))

+ 42 - 0
ent/agent_create.go

@@ -8,6 +8,7 @@ import (
 	"fmt"
 	"time"
 	"wechat-api/ent/agent"
+	"wechat-api/ent/wx"
 
 	"entgo.io/ent/dialect/sql"
 	"entgo.io/ent/dialect/sql/sqlgraph"
@@ -114,6 +115,21 @@ func (ac *AgentCreate) SetID(u uint64) *AgentCreate {
 	return ac
 }
 
+// AddWxAgentIDs adds the "wx_agent" edge to the Wx entity by IDs.
+func (ac *AgentCreate) AddWxAgentIDs(ids ...uint64) *AgentCreate {
+	ac.mutation.AddWxAgentIDs(ids...)
+	return ac
+}
+
+// AddWxAgent adds the "wx_agent" edges to the Wx entity.
+func (ac *AgentCreate) AddWxAgent(w ...*Wx) *AgentCreate {
+	ids := make([]uint64, len(w))
+	for i := range w {
+		ids[i] = w[i].ID
+	}
+	return ac.AddWxAgentIDs(ids...)
+}
+
 // Mutation returns the AgentMutation object of the builder.
 func (ac *AgentCreate) Mutation() *AgentMutation {
 	return ac.mutation
@@ -196,6 +212,11 @@ func (ac *AgentCreate) check() error {
 			return &ValidationError{Name: "role", err: fmt.Errorf(`ent: validator failed for field "Agent.role": %w`, err)}
 		}
 	}
+	if v, ok := ac.mutation.Status(); ok {
+		if err := agent.StatusValidator(v); err != nil {
+			return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "Agent.status": %w`, err)}
+		}
+	}
 	if _, ok := ac.mutation.Background(); !ok {
 		return &ValidationError{Name: "background", err: errors.New(`ent: missing required field "Agent.background"`)}
 	}
@@ -215,6 +236,11 @@ func (ac *AgentCreate) check() error {
 	if _, ok := ac.mutation.OrganizationID(); !ok {
 		return &ValidationError{Name: "organization_id", err: errors.New(`ent: missing required field "Agent.organization_id"`)}
 	}
+	if v, ok := ac.mutation.OrganizationID(); ok {
+		if err := agent.OrganizationIDValidator(v); err != nil {
+			return &ValidationError{Name: "organization_id", err: fmt.Errorf(`ent: validator failed for field "Agent.organization_id": %w`, err)}
+		}
+	}
 	return nil
 }
 
@@ -284,6 +310,22 @@ func (ac *AgentCreate) createSpec() (*Agent, *sqlgraph.CreateSpec) {
 		_spec.SetField(agent.FieldOrganizationID, field.TypeUint64, value)
 		_node.OrganizationID = value
 	}
+	if nodes := ac.mutation.WxAgentIDs(); len(nodes) > 0 {
+		edge := &sqlgraph.EdgeSpec{
+			Rel:     sqlgraph.O2M,
+			Inverse: false,
+			Table:   agent.WxAgentTable,
+			Columns: []string{agent.WxAgentColumn},
+			Bidi:    false,
+			Target: &sqlgraph.EdgeTarget{
+				IDSpec: sqlgraph.NewFieldSpec(wx.FieldID, field.TypeUint64),
+			},
+		}
+		for _, k := range nodes {
+			edge.Target.Nodes = append(edge.Target.Nodes, k)
+		}
+		_spec.Edges = append(_spec.Edges, edge)
+	}
 	return _node, _spec
 }
 

+ 90 - 11
ent/agent_query.go

@@ -4,10 +4,12 @@ package ent
 
 import (
 	"context"
+	"database/sql/driver"
 	"fmt"
 	"math"
 	"wechat-api/ent/agent"
 	"wechat-api/ent/predicate"
+	"wechat-api/ent/wx"
 
 	"entgo.io/ent/dialect/sql"
 	"entgo.io/ent/dialect/sql/sqlgraph"
@@ -17,10 +19,11 @@ import (
 // AgentQuery is the builder for querying Agent entities.
 type AgentQuery struct {
 	config
-	ctx        *QueryContext
-	order      []agent.OrderOption
-	inters     []Interceptor
-	predicates []predicate.Agent
+	ctx         *QueryContext
+	order       []agent.OrderOption
+	inters      []Interceptor
+	predicates  []predicate.Agent
+	withWxAgent *WxQuery
 	// intermediate query (i.e. traversal path).
 	sql  *sql.Selector
 	path func(context.Context) (*sql.Selector, error)
@@ -57,6 +60,28 @@ func (aq *AgentQuery) Order(o ...agent.OrderOption) *AgentQuery {
 	return aq
 }
 
+// QueryWxAgent chains the current query on the "wx_agent" edge.
+func (aq *AgentQuery) QueryWxAgent() *WxQuery {
+	query := (&WxClient{config: aq.config}).Query()
+	query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
+		if err := aq.prepareQuery(ctx); err != nil {
+			return nil, err
+		}
+		selector := aq.sqlQuery(ctx)
+		if err := selector.Err(); err != nil {
+			return nil, err
+		}
+		step := sqlgraph.NewStep(
+			sqlgraph.From(agent.Table, agent.FieldID, selector),
+			sqlgraph.To(wx.Table, wx.FieldID),
+			sqlgraph.Edge(sqlgraph.O2M, false, agent.WxAgentTable, agent.WxAgentColumn),
+		)
+		fromU = sqlgraph.SetNeighbors(aq.driver.Dialect(), step)
+		return fromU, nil
+	}
+	return query
+}
+
 // First returns the first Agent entity from the query.
 // Returns a *NotFoundError when no Agent was found.
 func (aq *AgentQuery) First(ctx context.Context) (*Agent, error) {
@@ -244,17 +269,29 @@ func (aq *AgentQuery) Clone() *AgentQuery {
 		return nil
 	}
 	return &AgentQuery{
-		config:     aq.config,
-		ctx:        aq.ctx.Clone(),
-		order:      append([]agent.OrderOption{}, aq.order...),
-		inters:     append([]Interceptor{}, aq.inters...),
-		predicates: append([]predicate.Agent{}, aq.predicates...),
+		config:      aq.config,
+		ctx:         aq.ctx.Clone(),
+		order:       append([]agent.OrderOption{}, aq.order...),
+		inters:      append([]Interceptor{}, aq.inters...),
+		predicates:  append([]predicate.Agent{}, aq.predicates...),
+		withWxAgent: aq.withWxAgent.Clone(),
 		// clone intermediate query.
 		sql:  aq.sql.Clone(),
 		path: aq.path,
 	}
 }
 
+// WithWxAgent tells the query-builder to eager-load the nodes that are connected to
+// the "wx_agent" edge. The optional arguments are used to configure the query builder of the edge.
+func (aq *AgentQuery) WithWxAgent(opts ...func(*WxQuery)) *AgentQuery {
+	query := (&WxClient{config: aq.config}).Query()
+	for _, opt := range opts {
+		opt(query)
+	}
+	aq.withWxAgent = query
+	return aq
+}
+
 // GroupBy is used to group vertices by one or more fields/columns.
 // It is often used with aggregate functions, like: count, max, mean, min, sum.
 //
@@ -331,8 +368,11 @@ func (aq *AgentQuery) prepareQuery(ctx context.Context) error {
 
 func (aq *AgentQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Agent, error) {
 	var (
-		nodes = []*Agent{}
-		_spec = aq.querySpec()
+		nodes       = []*Agent{}
+		_spec       = aq.querySpec()
+		loadedTypes = [1]bool{
+			aq.withWxAgent != nil,
+		}
 	)
 	_spec.ScanValues = func(columns []string) ([]any, error) {
 		return (*Agent).scanValues(nil, columns)
@@ -340,6 +380,7 @@ func (aq *AgentQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Agent,
 	_spec.Assign = func(columns []string, values []any) error {
 		node := &Agent{config: aq.config}
 		nodes = append(nodes, node)
+		node.Edges.loadedTypes = loadedTypes
 		return node.assignValues(columns, values)
 	}
 	for i := range hooks {
@@ -351,9 +392,47 @@ func (aq *AgentQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Agent,
 	if len(nodes) == 0 {
 		return nodes, nil
 	}
+	if query := aq.withWxAgent; query != nil {
+		if err := aq.loadWxAgent(ctx, query, nodes,
+			func(n *Agent) { n.Edges.WxAgent = []*Wx{} },
+			func(n *Agent, e *Wx) { n.Edges.WxAgent = append(n.Edges.WxAgent, e) }); err != nil {
+			return nil, err
+		}
+	}
 	return nodes, nil
 }
 
+func (aq *AgentQuery) loadWxAgent(ctx context.Context, query *WxQuery, nodes []*Agent, init func(*Agent), assign func(*Agent, *Wx)) error {
+	fks := make([]driver.Value, 0, len(nodes))
+	nodeids := make(map[uint64]*Agent)
+	for i := range nodes {
+		fks = append(fks, nodes[i].ID)
+		nodeids[nodes[i].ID] = nodes[i]
+		if init != nil {
+			init(nodes[i])
+		}
+	}
+	if len(query.ctx.Fields) > 0 {
+		query.ctx.AppendFieldOnce(wx.FieldAgentID)
+	}
+	query.Where(predicate.Wx(func(s *sql.Selector) {
+		s.Where(sql.InValues(s.C(agent.WxAgentColumn), fks...))
+	}))
+	neighbors, err := query.All(ctx)
+	if err != nil {
+		return err
+	}
+	for _, n := range neighbors {
+		fk := n.AgentID
+		node, ok := nodeids[fk]
+		if !ok {
+			return fmt.Errorf(`unexpected referenced foreign-key "agent_id" returned %v for node %v`, fk, n.ID)
+		}
+		assign(node, n)
+	}
+	return nil
+}
+
 func (aq *AgentQuery) sqlCount(ctx context.Context) (int, error) {
 	_spec := aq.querySpec()
 	_spec.Node.Columns = aq.ctx.Fields

+ 183 - 0
ent/agent_update.go

@@ -9,6 +9,7 @@ import (
 	"time"
 	"wechat-api/ent/agent"
 	"wechat-api/ent/predicate"
+	"wechat-api/ent/wx"
 
 	"entgo.io/ent/dialect/sql"
 	"entgo.io/ent/dialect/sql/sqlgraph"
@@ -158,11 +159,47 @@ func (au *AgentUpdate) AddOrganizationID(u int64) *AgentUpdate {
 	return au
 }
 
+// AddWxAgentIDs adds the "wx_agent" edge to the Wx entity by IDs.
+func (au *AgentUpdate) AddWxAgentIDs(ids ...uint64) *AgentUpdate {
+	au.mutation.AddWxAgentIDs(ids...)
+	return au
+}
+
+// AddWxAgent adds the "wx_agent" edges to the Wx entity.
+func (au *AgentUpdate) AddWxAgent(w ...*Wx) *AgentUpdate {
+	ids := make([]uint64, len(w))
+	for i := range w {
+		ids[i] = w[i].ID
+	}
+	return au.AddWxAgentIDs(ids...)
+}
+
 // Mutation returns the AgentMutation object of the builder.
 func (au *AgentUpdate) Mutation() *AgentMutation {
 	return au.mutation
 }
 
+// ClearWxAgent clears all "wx_agent" edges to the Wx entity.
+func (au *AgentUpdate) ClearWxAgent() *AgentUpdate {
+	au.mutation.ClearWxAgent()
+	return au
+}
+
+// RemoveWxAgentIDs removes the "wx_agent" edge to Wx entities by IDs.
+func (au *AgentUpdate) RemoveWxAgentIDs(ids ...uint64) *AgentUpdate {
+	au.mutation.RemoveWxAgentIDs(ids...)
+	return au
+}
+
+// RemoveWxAgent removes "wx_agent" edges to Wx entities.
+func (au *AgentUpdate) RemoveWxAgent(w ...*Wx) *AgentUpdate {
+	ids := make([]uint64, len(w))
+	for i := range w {
+		ids[i] = w[i].ID
+	}
+	return au.RemoveWxAgentIDs(ids...)
+}
+
 // Save executes the query and returns the number of nodes affected by the update operation.
 func (au *AgentUpdate) Save(ctx context.Context) (int, error) {
 	if err := au.defaults(); err != nil {
@@ -217,6 +254,11 @@ func (au *AgentUpdate) check() error {
 			return &ValidationError{Name: "role", err: fmt.Errorf(`ent: validator failed for field "Agent.role": %w`, err)}
 		}
 	}
+	if v, ok := au.mutation.Status(); ok {
+		if err := agent.StatusValidator(v); err != nil {
+			return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "Agent.status": %w`, err)}
+		}
+	}
 	if v, ok := au.mutation.Background(); ok {
 		if err := agent.BackgroundValidator(v); err != nil {
 			return &ValidationError{Name: "background", err: fmt.Errorf(`ent: validator failed for field "Agent.background": %w`, err)}
@@ -227,6 +269,11 @@ func (au *AgentUpdate) check() error {
 			return &ValidationError{Name: "examples", err: fmt.Errorf(`ent: validator failed for field "Agent.examples": %w`, err)}
 		}
 	}
+	if v, ok := au.mutation.OrganizationID(); ok {
+		if err := agent.OrganizationIDValidator(v); err != nil {
+			return &ValidationError{Name: "organization_id", err: fmt.Errorf(`ent: validator failed for field "Agent.organization_id": %w`, err)}
+		}
+	}
 	return nil
 }
 
@@ -278,6 +325,51 @@ func (au *AgentUpdate) sqlSave(ctx context.Context) (n int, err error) {
 	if value, ok := au.mutation.AddedOrganizationID(); ok {
 		_spec.AddField(agent.FieldOrganizationID, field.TypeUint64, value)
 	}
+	if au.mutation.WxAgentCleared() {
+		edge := &sqlgraph.EdgeSpec{
+			Rel:     sqlgraph.O2M,
+			Inverse: false,
+			Table:   agent.WxAgentTable,
+			Columns: []string{agent.WxAgentColumn},
+			Bidi:    false,
+			Target: &sqlgraph.EdgeTarget{
+				IDSpec: sqlgraph.NewFieldSpec(wx.FieldID, field.TypeUint64),
+			},
+		}
+		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
+	}
+	if nodes := au.mutation.RemovedWxAgentIDs(); len(nodes) > 0 && !au.mutation.WxAgentCleared() {
+		edge := &sqlgraph.EdgeSpec{
+			Rel:     sqlgraph.O2M,
+			Inverse: false,
+			Table:   agent.WxAgentTable,
+			Columns: []string{agent.WxAgentColumn},
+			Bidi:    false,
+			Target: &sqlgraph.EdgeTarget{
+				IDSpec: sqlgraph.NewFieldSpec(wx.FieldID, field.TypeUint64),
+			},
+		}
+		for _, k := range nodes {
+			edge.Target.Nodes = append(edge.Target.Nodes, k)
+		}
+		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
+	}
+	if nodes := au.mutation.WxAgentIDs(); len(nodes) > 0 {
+		edge := &sqlgraph.EdgeSpec{
+			Rel:     sqlgraph.O2M,
+			Inverse: false,
+			Table:   agent.WxAgentTable,
+			Columns: []string{agent.WxAgentColumn},
+			Bidi:    false,
+			Target: &sqlgraph.EdgeTarget{
+				IDSpec: sqlgraph.NewFieldSpec(wx.FieldID, field.TypeUint64),
+			},
+		}
+		for _, k := range nodes {
+			edge.Target.Nodes = append(edge.Target.Nodes, k)
+		}
+		_spec.Edges.Add = append(_spec.Edges.Add, edge)
+	}
 	if n, err = sqlgraph.UpdateNodes(ctx, au.driver, _spec); err != nil {
 		if _, ok := err.(*sqlgraph.NotFoundError); ok {
 			err = &NotFoundError{agent.Label}
@@ -428,11 +520,47 @@ func (auo *AgentUpdateOne) AddOrganizationID(u int64) *AgentUpdateOne {
 	return auo
 }
 
+// AddWxAgentIDs adds the "wx_agent" edge to the Wx entity by IDs.
+func (auo *AgentUpdateOne) AddWxAgentIDs(ids ...uint64) *AgentUpdateOne {
+	auo.mutation.AddWxAgentIDs(ids...)
+	return auo
+}
+
+// AddWxAgent adds the "wx_agent" edges to the Wx entity.
+func (auo *AgentUpdateOne) AddWxAgent(w ...*Wx) *AgentUpdateOne {
+	ids := make([]uint64, len(w))
+	for i := range w {
+		ids[i] = w[i].ID
+	}
+	return auo.AddWxAgentIDs(ids...)
+}
+
 // Mutation returns the AgentMutation object of the builder.
 func (auo *AgentUpdateOne) Mutation() *AgentMutation {
 	return auo.mutation
 }
 
+// ClearWxAgent clears all "wx_agent" edges to the Wx entity.
+func (auo *AgentUpdateOne) ClearWxAgent() *AgentUpdateOne {
+	auo.mutation.ClearWxAgent()
+	return auo
+}
+
+// RemoveWxAgentIDs removes the "wx_agent" edge to Wx entities by IDs.
+func (auo *AgentUpdateOne) RemoveWxAgentIDs(ids ...uint64) *AgentUpdateOne {
+	auo.mutation.RemoveWxAgentIDs(ids...)
+	return auo
+}
+
+// RemoveWxAgent removes "wx_agent" edges to Wx entities.
+func (auo *AgentUpdateOne) RemoveWxAgent(w ...*Wx) *AgentUpdateOne {
+	ids := make([]uint64, len(w))
+	for i := range w {
+		ids[i] = w[i].ID
+	}
+	return auo.RemoveWxAgentIDs(ids...)
+}
+
 // Where appends a list predicates to the AgentUpdate builder.
 func (auo *AgentUpdateOne) Where(ps ...predicate.Agent) *AgentUpdateOne {
 	auo.mutation.Where(ps...)
@@ -500,6 +628,11 @@ func (auo *AgentUpdateOne) check() error {
 			return &ValidationError{Name: "role", err: fmt.Errorf(`ent: validator failed for field "Agent.role": %w`, err)}
 		}
 	}
+	if v, ok := auo.mutation.Status(); ok {
+		if err := agent.StatusValidator(v); err != nil {
+			return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "Agent.status": %w`, err)}
+		}
+	}
 	if v, ok := auo.mutation.Background(); ok {
 		if err := agent.BackgroundValidator(v); err != nil {
 			return &ValidationError{Name: "background", err: fmt.Errorf(`ent: validator failed for field "Agent.background": %w`, err)}
@@ -510,6 +643,11 @@ func (auo *AgentUpdateOne) check() error {
 			return &ValidationError{Name: "examples", err: fmt.Errorf(`ent: validator failed for field "Agent.examples": %w`, err)}
 		}
 	}
+	if v, ok := auo.mutation.OrganizationID(); ok {
+		if err := agent.OrganizationIDValidator(v); err != nil {
+			return &ValidationError{Name: "organization_id", err: fmt.Errorf(`ent: validator failed for field "Agent.organization_id": %w`, err)}
+		}
+	}
 	return nil
 }
 
@@ -578,6 +716,51 @@ func (auo *AgentUpdateOne) sqlSave(ctx context.Context) (_node *Agent, err error
 	if value, ok := auo.mutation.AddedOrganizationID(); ok {
 		_spec.AddField(agent.FieldOrganizationID, field.TypeUint64, value)
 	}
+	if auo.mutation.WxAgentCleared() {
+		edge := &sqlgraph.EdgeSpec{
+			Rel:     sqlgraph.O2M,
+			Inverse: false,
+			Table:   agent.WxAgentTable,
+			Columns: []string{agent.WxAgentColumn},
+			Bidi:    false,
+			Target: &sqlgraph.EdgeTarget{
+				IDSpec: sqlgraph.NewFieldSpec(wx.FieldID, field.TypeUint64),
+			},
+		}
+		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
+	}
+	if nodes := auo.mutation.RemovedWxAgentIDs(); len(nodes) > 0 && !auo.mutation.WxAgentCleared() {
+		edge := &sqlgraph.EdgeSpec{
+			Rel:     sqlgraph.O2M,
+			Inverse: false,
+			Table:   agent.WxAgentTable,
+			Columns: []string{agent.WxAgentColumn},
+			Bidi:    false,
+			Target: &sqlgraph.EdgeTarget{
+				IDSpec: sqlgraph.NewFieldSpec(wx.FieldID, field.TypeUint64),
+			},
+		}
+		for _, k := range nodes {
+			edge.Target.Nodes = append(edge.Target.Nodes, k)
+		}
+		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
+	}
+	if nodes := auo.mutation.WxAgentIDs(); len(nodes) > 0 {
+		edge := &sqlgraph.EdgeSpec{
+			Rel:     sqlgraph.O2M,
+			Inverse: false,
+			Table:   agent.WxAgentTable,
+			Columns: []string{agent.WxAgentColumn},
+			Bidi:    false,
+			Target: &sqlgraph.EdgeTarget{
+				IDSpec: sqlgraph.NewFieldSpec(wx.FieldID, field.TypeUint64),
+			},
+		}
+		for _, k := range nodes {
+			edge.Target.Nodes = append(edge.Target.Nodes, k)
+		}
+		_spec.Edges.Add = append(_spec.Edges.Add, edge)
+	}
 	_node = &Agent{config: auo.config}
 	_spec.Assign = _node.assignValues
 	_spec.ScanValues = _node.scanValues

+ 32 - 0
ent/client.go

@@ -414,6 +414,22 @@ func (c *AgentClient) GetX(ctx context.Context, id uint64) *Agent {
 	return obj
 }
 
+// QueryWxAgent queries the wx_agent edge of a Agent.
+func (c *AgentClient) QueryWxAgent(a *Agent) *WxQuery {
+	query := (&WxClient{config: c.config}).Query()
+	query.path = func(context.Context) (fromV *sql.Selector, _ error) {
+		id := a.ID
+		step := sqlgraph.NewStep(
+			sqlgraph.From(agent.Table, agent.FieldID, id),
+			sqlgraph.To(wx.Table, wx.FieldID),
+			sqlgraph.Edge(sqlgraph.O2M, false, agent.WxAgentTable, agent.WxAgentColumn),
+		)
+		fromV = sqlgraph.Neighbors(a.driver.Dialect(), step)
+		return fromV, nil
+	}
+	return query
+}
+
 // Hooks returns the client hooks.
 func (c *AgentClient) Hooks() []Hook {
 	hooks := c.hooks.Agent
@@ -2286,6 +2302,22 @@ func (c *WxClient) QueryServer(w *Wx) *ServerQuery {
 	return query
 }
 
+// QueryAgent queries the agent edge of a Wx.
+func (c *WxClient) QueryAgent(w *Wx) *AgentQuery {
+	query := (&AgentClient{config: c.config}).Query()
+	query.path = func(context.Context) (fromV *sql.Selector, _ error) {
+		id := w.ID
+		step := sqlgraph.NewStep(
+			sqlgraph.From(wx.Table, wx.FieldID, id),
+			sqlgraph.To(agent.Table, agent.FieldID),
+			sqlgraph.Edge(sqlgraph.M2O, true, wx.AgentTable, wx.AgentColumn),
+		)
+		fromV = sqlgraph.Neighbors(w.driver.Dialect(), step)
+		return fromV, nil
+	}
+	return query
+}
+
 // Hooks returns the client hooks.
 func (c *WxClient) Hooks() []Hook {
 	hooks := c.hooks.Wx

+ 18 - 3
ent/migrate/schema.go

@@ -27,6 +27,13 @@ var (
 		Name:       "agent",
 		Columns:    AgentColumns,
 		PrimaryKey: []*schema.Column{AgentColumns[0]},
+		Indexes: []*schema.Index{
+			{
+				Name:    "agent_organization_id",
+				Unique:  false,
+				Columns: []*schema.Column{AgentColumns[9]},
+			},
+		},
 	}
 	// BatchMsgColumns holds the columns for the "batch_msg" table.
 	BatchMsgColumns = []*schema.Column{
@@ -435,6 +442,7 @@ var (
 		{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: "agent_id", Type: field.TypeUint64, Comment: "模式ID", Default: 0},
 		{Name: "server_id", Type: field.TypeUint64, Nullable: true, Comment: "服务器id", Default: 0},
 	}
 	// WxTable holds the schema information for the "wx" table.
@@ -444,8 +452,14 @@ var (
 		PrimaryKey: []*schema.Column{WxColumns[0]},
 		ForeignKeys: []*schema.ForeignKey{
 			{
-				Symbol:     "wx_server_wxs",
+				Symbol:     "wx_agent_wx_agent",
 				Columns:    []*schema.Column{WxColumns[14]},
+				RefColumns: []*schema.Column{AgentColumns[0]},
+				OnDelete:   schema.NoAction,
+			},
+			{
+				Symbol:     "wx_server_wxs",
+				Columns:    []*schema.Column{WxColumns[15]},
 				RefColumns: []*schema.Column{ServerColumns[0]},
 				OnDelete:   schema.SetNull,
 			},
@@ -454,7 +468,7 @@ var (
 			{
 				Name:    "wx_server_id_port",
 				Unique:  true,
-				Columns: []*schema.Column{WxColumns[14], WxColumns[5]},
+				Columns: []*schema.Column{WxColumns[15], WxColumns[5]},
 			},
 			{
 				Name:    "wx_wxid",
@@ -540,7 +554,8 @@ func init() {
 	SopTaskTable.Annotation = &entsql.Annotation{
 		Table: "sop_task",
 	}
-	WxTable.ForeignKeys[0].RefTable = ServerTable
+	WxTable.ForeignKeys[0].RefTable = AgentTable
+	WxTable.ForeignKeys[1].RefTable = ServerTable
 	WxTable.Annotation = &entsql.Annotation{
 		Table: "wx",
 	}

+ 200 - 7
ent/mutation.go

@@ -70,6 +70,9 @@ type AgentMutation struct {
 	organization_id    *uint64
 	addorganization_id *int64
 	clearedFields      map[string]struct{}
+	wx_agent           map[uint64]struct{}
+	removedwx_agent    map[uint64]struct{}
+	clearedwx_agent    bool
 	done               bool
 	oldValue           func(context.Context) (*Agent, error)
 	predicates         []predicate.Agent
@@ -570,6 +573,60 @@ func (m *AgentMutation) ResetOrganizationID() {
 	m.addorganization_id = nil
 }
 
+// AddWxAgentIDs adds the "wx_agent" edge to the Wx entity by ids.
+func (m *AgentMutation) AddWxAgentIDs(ids ...uint64) {
+	if m.wx_agent == nil {
+		m.wx_agent = make(map[uint64]struct{})
+	}
+	for i := range ids {
+		m.wx_agent[ids[i]] = struct{}{}
+	}
+}
+
+// ClearWxAgent clears the "wx_agent" edge to the Wx entity.
+func (m *AgentMutation) ClearWxAgent() {
+	m.clearedwx_agent = true
+}
+
+// WxAgentCleared reports if the "wx_agent" edge to the Wx entity was cleared.
+func (m *AgentMutation) WxAgentCleared() bool {
+	return m.clearedwx_agent
+}
+
+// RemoveWxAgentIDs removes the "wx_agent" edge to the Wx entity by IDs.
+func (m *AgentMutation) RemoveWxAgentIDs(ids ...uint64) {
+	if m.removedwx_agent == nil {
+		m.removedwx_agent = make(map[uint64]struct{})
+	}
+	for i := range ids {
+		delete(m.wx_agent, ids[i])
+		m.removedwx_agent[ids[i]] = struct{}{}
+	}
+}
+
+// RemovedWxAgent returns the removed IDs of the "wx_agent" edge to the Wx entity.
+func (m *AgentMutation) RemovedWxAgentIDs() (ids []uint64) {
+	for id := range m.removedwx_agent {
+		ids = append(ids, id)
+	}
+	return
+}
+
+// WxAgentIDs returns the "wx_agent" edge IDs in the mutation.
+func (m *AgentMutation) WxAgentIDs() (ids []uint64) {
+	for id := range m.wx_agent {
+		ids = append(ids, id)
+	}
+	return
+}
+
+// ResetWxAgent resets all changes to the "wx_agent" edge.
+func (m *AgentMutation) ResetWxAgent() {
+	m.wx_agent = nil
+	m.clearedwx_agent = false
+	m.removedwx_agent = nil
+}
+
 // Where appends a list predicates to the AgentMutation builder.
 func (m *AgentMutation) Where(ps ...predicate.Agent) {
 	m.predicates = append(m.predicates, ps...)
@@ -881,49 +938,85 @@ func (m *AgentMutation) ResetField(name string) error {
 
 // AddedEdges returns all edge names that were set/added in this mutation.
 func (m *AgentMutation) AddedEdges() []string {
-	edges := make([]string, 0, 0)
+	edges := make([]string, 0, 1)
+	if m.wx_agent != nil {
+		edges = append(edges, agent.EdgeWxAgent)
+	}
 	return edges
 }
 
 // AddedIDs returns all IDs (to other nodes) that were added for the given edge
 // name in this mutation.
 func (m *AgentMutation) AddedIDs(name string) []ent.Value {
+	switch name {
+	case agent.EdgeWxAgent:
+		ids := make([]ent.Value, 0, len(m.wx_agent))
+		for id := range m.wx_agent {
+			ids = append(ids, id)
+		}
+		return ids
+	}
 	return nil
 }
 
 // RemovedEdges returns all edge names that were removed in this mutation.
 func (m *AgentMutation) RemovedEdges() []string {
-	edges := make([]string, 0, 0)
+	edges := make([]string, 0, 1)
+	if m.removedwx_agent != nil {
+		edges = append(edges, agent.EdgeWxAgent)
+	}
 	return edges
 }
 
 // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
 // the given name in this mutation.
 func (m *AgentMutation) RemovedIDs(name string) []ent.Value {
+	switch name {
+	case agent.EdgeWxAgent:
+		ids := make([]ent.Value, 0, len(m.removedwx_agent))
+		for id := range m.removedwx_agent {
+			ids = append(ids, id)
+		}
+		return ids
+	}
 	return nil
 }
 
 // ClearedEdges returns all edge names that were cleared in this mutation.
 func (m *AgentMutation) ClearedEdges() []string {
-	edges := make([]string, 0, 0)
+	edges := make([]string, 0, 1)
+	if m.clearedwx_agent {
+		edges = append(edges, agent.EdgeWxAgent)
+	}
 	return edges
 }
 
 // EdgeCleared returns a boolean which indicates if the edge with the given name
 // was cleared in this mutation.
 func (m *AgentMutation) EdgeCleared(name string) bool {
+	switch name {
+	case agent.EdgeWxAgent:
+		return m.clearedwx_agent
+	}
 	return false
 }
 
 // ClearEdge clears the value of the edge with the given name. It returns an error
 // if that edge is not defined in the schema.
 func (m *AgentMutation) ClearEdge(name string) error {
+	switch name {
+	}
 	return fmt.Errorf("unknown Agent unique edge %s", name)
 }
 
 // ResetEdge resets all changes to the edge with the given name in this mutation.
 // It returns an error if the edge is not defined in the schema.
 func (m *AgentMutation) ResetEdge(name string) error {
+	switch name {
+	case agent.EdgeWxAgent:
+		m.ResetWxAgent()
+		return nil
+	}
 	return fmt.Errorf("unknown Agent edge %s", name)
 }
 
@@ -14163,6 +14256,8 @@ type WxMutation struct {
 	clearedFields      map[string]struct{}
 	server             *uint64
 	clearedserver      bool
+	agent              *uint64
+	clearedagent       bool
 	done               bool
 	oldValue           func(context.Context) (*Wx, error)
 	predicates         []predicate.Wx
@@ -14870,6 +14965,42 @@ func (m *WxMutation) ResetOrganizationID() {
 	delete(m.clearedFields, wx.FieldOrganizationID)
 }
 
+// SetAgentID sets the "agent_id" field.
+func (m *WxMutation) SetAgentID(u uint64) {
+	m.agent = &u
+}
+
+// AgentID returns the value of the "agent_id" field in the mutation.
+func (m *WxMutation) AgentID() (r uint64, exists bool) {
+	v := m.agent
+	if v == nil {
+		return
+	}
+	return *v, true
+}
+
+// OldAgentID returns the old "agent_id" field's value of the Wx entity.
+// If the Wx object wasn't provided to the builder, the object is fetched from the database.
+// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
+func (m *WxMutation) OldAgentID(ctx context.Context) (v uint64, err error) {
+	if !m.op.Is(OpUpdateOne) {
+		return v, errors.New("OldAgentID is only allowed on UpdateOne operations")
+	}
+	if m.id == nil || m.oldValue == nil {
+		return v, errors.New("OldAgentID requires an ID field in the mutation")
+	}
+	oldValue, err := m.oldValue(ctx)
+	if err != nil {
+		return v, fmt.Errorf("querying old value for OldAgentID: %w", err)
+	}
+	return oldValue.AgentID, nil
+}
+
+// ResetAgentID resets all changes to the "agent_id" field.
+func (m *WxMutation) ResetAgentID() {
+	m.agent = nil
+}
+
 // ClearServer clears the "server" edge to the Server entity.
 func (m *WxMutation) ClearServer() {
 	m.clearedserver = true
@@ -14897,6 +15028,33 @@ func (m *WxMutation) ResetServer() {
 	m.clearedserver = false
 }
 
+// ClearAgent clears the "agent" edge to the Agent entity.
+func (m *WxMutation) ClearAgent() {
+	m.clearedagent = true
+	m.clearedFields[wx.FieldAgentID] = struct{}{}
+}
+
+// AgentCleared reports if the "agent" edge to the Agent entity was cleared.
+func (m *WxMutation) AgentCleared() bool {
+	return m.clearedagent
+}
+
+// AgentIDs returns the "agent" edge IDs in the mutation.
+// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
+// AgentID instead. It exists only for internal usage by the builders.
+func (m *WxMutation) AgentIDs() (ids []uint64) {
+	if id := m.agent; id != nil {
+		ids = append(ids, *id)
+	}
+	return
+}
+
+// ResetAgent resets all changes to the "agent" edge.
+func (m *WxMutation) ResetAgent() {
+	m.agent = nil
+	m.clearedagent = false
+}
+
 // Where appends a list predicates to the WxMutation builder.
 func (m *WxMutation) Where(ps ...predicate.Wx) {
 	m.predicates = append(m.predicates, ps...)
@@ -14931,7 +15089,7 @@ func (m *WxMutation) Type() string {
 // order to get all numeric fields that were incremented/decremented, call
 // AddedFields().
 func (m *WxMutation) Fields() []string {
-	fields := make([]string, 0, 14)
+	fields := make([]string, 0, 15)
 	if m.created_at != nil {
 		fields = append(fields, wx.FieldCreatedAt)
 	}
@@ -14974,6 +15132,9 @@ func (m *WxMutation) Fields() []string {
 	if m.organization_id != nil {
 		fields = append(fields, wx.FieldOrganizationID)
 	}
+	if m.agent != nil {
+		fields = append(fields, wx.FieldAgentID)
+	}
 	return fields
 }
 
@@ -15010,6 +15171,8 @@ func (m *WxMutation) Field(name string) (ent.Value, bool) {
 		return m.HeadBig()
 	case wx.FieldOrganizationID:
 		return m.OrganizationID()
+	case wx.FieldAgentID:
+		return m.AgentID()
 	}
 	return nil, false
 }
@@ -15047,6 +15210,8 @@ func (m *WxMutation) OldField(ctx context.Context, name string) (ent.Value, erro
 		return m.OldHeadBig(ctx)
 	case wx.FieldOrganizationID:
 		return m.OldOrganizationID(ctx)
+	case wx.FieldAgentID:
+		return m.OldAgentID(ctx)
 	}
 	return nil, fmt.Errorf("unknown Wx field %s", name)
 }
@@ -15154,6 +15319,13 @@ func (m *WxMutation) SetField(name string, value ent.Value) error {
 		}
 		m.SetOrganizationID(v)
 		return nil
+	case wx.FieldAgentID:
+		v, ok := value.(uint64)
+		if !ok {
+			return fmt.Errorf("unexpected type %T for field %s", value, name)
+		}
+		m.SetAgentID(v)
+		return nil
 	}
 	return fmt.Errorf("unknown Wx field %s", name)
 }
@@ -15299,16 +15471,22 @@ func (m *WxMutation) ResetField(name string) error {
 	case wx.FieldOrganizationID:
 		m.ResetOrganizationID()
 		return nil
+	case wx.FieldAgentID:
+		m.ResetAgentID()
+		return nil
 	}
 	return fmt.Errorf("unknown Wx field %s", name)
 }
 
 // AddedEdges returns all edge names that were set/added in this mutation.
 func (m *WxMutation) AddedEdges() []string {
-	edges := make([]string, 0, 1)
+	edges := make([]string, 0, 2)
 	if m.server != nil {
 		edges = append(edges, wx.EdgeServer)
 	}
+	if m.agent != nil {
+		edges = append(edges, wx.EdgeAgent)
+	}
 	return edges
 }
 
@@ -15320,13 +15498,17 @@ func (m *WxMutation) AddedIDs(name string) []ent.Value {
 		if id := m.server; id != nil {
 			return []ent.Value{*id}
 		}
+	case wx.EdgeAgent:
+		if id := m.agent; id != nil {
+			return []ent.Value{*id}
+		}
 	}
 	return nil
 }
 
 // RemovedEdges returns all edge names that were removed in this mutation.
 func (m *WxMutation) RemovedEdges() []string {
-	edges := make([]string, 0, 1)
+	edges := make([]string, 0, 2)
 	return edges
 }
 
@@ -15338,10 +15520,13 @@ func (m *WxMutation) RemovedIDs(name string) []ent.Value {
 
 // ClearedEdges returns all edge names that were cleared in this mutation.
 func (m *WxMutation) ClearedEdges() []string {
-	edges := make([]string, 0, 1)
+	edges := make([]string, 0, 2)
 	if m.clearedserver {
 		edges = append(edges, wx.EdgeServer)
 	}
+	if m.clearedagent {
+		edges = append(edges, wx.EdgeAgent)
+	}
 	return edges
 }
 
@@ -15351,6 +15536,8 @@ func (m *WxMutation) EdgeCleared(name string) bool {
 	switch name {
 	case wx.EdgeServer:
 		return m.clearedserver
+	case wx.EdgeAgent:
+		return m.clearedagent
 	}
 	return false
 }
@@ -15362,6 +15549,9 @@ func (m *WxMutation) ClearEdge(name string) error {
 	case wx.EdgeServer:
 		m.ClearServer()
 		return nil
+	case wx.EdgeAgent:
+		m.ClearAgent()
+		return nil
 	}
 	return fmt.Errorf("unknown Wx unique edge %s", name)
 }
@@ -15373,6 +15563,9 @@ func (m *WxMutation) ResetEdge(name string) error {
 	case wx.EdgeServer:
 		m.ResetServer()
 		return nil
+	case wx.EdgeAgent:
+		m.ResetAgent()
+		return nil
 	}
 	return fmt.Errorf("unknown Wx edge %s", name)
 }

+ 10 - 0
ent/runtime/runtime.go

@@ -55,6 +55,8 @@ func init() {
 	agentDescStatus := agentFields[2].Descriptor()
 	// agent.DefaultStatus holds the default value on creation for the status field.
 	agent.DefaultStatus = agentDescStatus.Default.(int)
+	// agent.StatusValidator is a validator for the "status" field. It is called by the builders before save.
+	agent.StatusValidator = agentDescStatus.Validators[0].(func(int) error)
 	// agentDescBackground is the schema descriptor for background field.
 	agentDescBackground := agentFields[3].Descriptor()
 	// agent.BackgroundValidator is a validator for the "background" field. It is called by the builders before save.
@@ -63,6 +65,10 @@ func init() {
 	agentDescExamples := agentFields[4].Descriptor()
 	// agent.ExamplesValidator is a validator for the "examples" field. It is called by the builders before save.
 	agent.ExamplesValidator = agentDescExamples.Validators[0].(func(string) error)
+	// agentDescOrganizationID is the schema descriptor for organization_id field.
+	agentDescOrganizationID := agentFields[5].Descriptor()
+	// agent.OrganizationIDValidator is a validator for the "organization_id" field. It is called by the builders before save.
+	agent.OrganizationIDValidator = agentDescOrganizationID.Validators[0].(func(uint64) error)
 	batchmsgMixin := schema.BatchMsg{}.Mixin()
 	batchmsgMixinHooks1 := batchmsgMixin[1].Hooks()
 	batchmsg.Hooks[0] = batchmsgMixinHooks1[0]
@@ -552,6 +558,10 @@ func init() {
 	wxDescOrganizationID := wxFields[9].Descriptor()
 	// wx.DefaultOrganizationID holds the default value on creation for the organization_id field.
 	wx.DefaultOrganizationID = wxDescOrganizationID.Default.(uint64)
+	// wxDescAgentID is the schema descriptor for agent_id field.
+	wxDescAgentID := wxFields[10].Descriptor()
+	// wx.DefaultAgentID holds the default value on creation for the agent_id field.
+	wx.DefaultAgentID = wxDescAgentID.Default.(uint64)
 }
 
 const (

+ 6 - 3
ent/schema/agent.go

@@ -1,6 +1,7 @@
 package schema
 
 import (
+	"entgo.io/ent/schema/edge"
 	"entgo.io/ent/schema/index"
 	"wechat-api/ent/schema/localmixin"
 
@@ -19,10 +20,10 @@ func (Agent) Fields() []ent.Field {
 	return []ent.Field{
 		field.String("name").MaxLen(20).Comment("name | 角色名称"),
 		field.String("role").MaxLen(1000).Comment("role | 角色设定"),
-		field.Int("status").Optional().Default(1).Comment("status | 状态 1-正常 2-禁用"),
+		field.Int("status").Optional().Range(1, 2).Default(1).Comment("status | 状态 1-正常 2-禁用"),
 		field.String("background").MaxLen(1000).Comment("background | 背景介绍"),
 		field.String("examples").MaxLen(5000).Comment("examples | 对话案例"),
-		field.Uint64("organization_id").Comment("organization_id | 租户ID"),
+		field.Uint64("organization_id").Positive().Comment("organization_id | 租户ID"),
 	}
 }
 
@@ -34,7 +35,9 @@ func (Agent) Mixin() []ent.Mixin {
 }
 
 func (Agent) Edges() []ent.Edge {
-	return nil
+	return []ent.Edge{
+		edge.To("wx_agent", Wx.Type),
+	}
 }
 
 func (Agent) Indexes() []ent.Index {

+ 8 - 0
ent/schema/wx.go

@@ -49,6 +49,9 @@ func (Wx) Fields() []ent.Field {
 		field.Uint64("organization_id").Optional().Default(1).
 			Comment("机构 ID").
 			Annotations(entsql.WithComments(true)),
+		field.Uint64("agent_id").Default(0).
+			Comment("模式ID").
+			Annotations(entsql.WithComments(true)),
 	}
 }
 
@@ -73,6 +76,11 @@ func (Wx) Indexes() []ent.Index {
 func (Wx) Edges() []ent.Edge {
 	return []ent.Edge{
 		edge.From("server", Server.Type).Ref("wxs").Unique().Field("server_id"),
+		edge.From("agent", Agent.Type).
+			Ref("wx_agent").
+			Unique().
+			Field("agent_id").
+			Required(),
 	}
 }
 

+ 24 - 0
ent/set_not_nil.go

@@ -3174,3 +3174,27 @@ func (w *WxCreate) SetNotNilOrganizationID(value *uint64) *WxCreate {
 	}
 	return w
 }
+
+// set field if value's pointer is not nil.
+func (w *WxUpdate) SetNotNilAgentID(value *uint64) *WxUpdate {
+	if value != nil {
+		return w.SetAgentID(*value)
+	}
+	return w
+}
+
+// set field if value's pointer is not nil.
+func (w *WxUpdateOne) SetNotNilAgentID(value *uint64) *WxUpdateOne {
+	if value != nil {
+		return w.SetAgentID(*value)
+	}
+	return w
+}
+
+// set field if value's pointer is not nil.
+func (w *WxCreate) SetNotNilAgentID(value *uint64) *WxCreate {
+	if value != nil {
+		return w.SetAgentID(*value)
+	}
+	return w
+}

+ 32 - 2
ent/wx.go

@@ -6,6 +6,7 @@ import (
 	"fmt"
 	"strings"
 	"time"
+	"wechat-api/ent/agent"
 	"wechat-api/ent/server"
 	"wechat-api/ent/wx"
 
@@ -46,6 +47,8 @@ type Wx struct {
 	HeadBig string `json:"head_big,omitempty"`
 	// 机构 ID
 	OrganizationID uint64 `json:"organization_id,omitempty"`
+	// 模式ID
+	AgentID uint64 `json:"agent_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"`
@@ -56,9 +59,11 @@ type Wx struct {
 type WxEdges struct {
 	// Server holds the value of the server edge.
 	Server *Server `json:"server,omitempty"`
+	// Agent holds the value of the agent edge.
+	Agent *Agent `json:"agent,omitempty"`
 	// loadedTypes holds the information for reporting if a
 	// type was loaded (or requested) in eager-loading or not.
-	loadedTypes [1]bool
+	loadedTypes [2]bool
 }
 
 // ServerOrErr returns the Server value or an error if the edge
@@ -72,12 +77,23 @@ func (e WxEdges) ServerOrErr() (*Server, error) {
 	return nil, &NotLoadedError{edge: "server"}
 }
 
+// AgentOrErr returns the Agent value or an error if the edge
+// was not loaded in eager-loading, or loaded but was not found.
+func (e WxEdges) AgentOrErr() (*Agent, error) {
+	if e.Agent != nil {
+		return e.Agent, nil
+	} else if e.loadedTypes[1] {
+		return nil, &NotFoundError{label: agent.Label}
+	}
+	return nil, &NotLoadedError{edge: "agent"}
+}
+
 // scanValues returns the types for scanning values from sql.Rows.
 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, wx.FieldOrganizationID:
+		case wx.FieldID, wx.FieldStatus, wx.FieldServerID, wx.FieldOrganizationID, wx.FieldAgentID:
 			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)
@@ -188,6 +204,12 @@ func (w *Wx) assignValues(columns []string, values []any) error {
 			} else if value.Valid {
 				w.OrganizationID = uint64(value.Int64)
 			}
+		case wx.FieldAgentID:
+			if value, ok := values[i].(*sql.NullInt64); !ok {
+				return fmt.Errorf("unexpected type %T for field agent_id", values[i])
+			} else if value.Valid {
+				w.AgentID = uint64(value.Int64)
+			}
 		default:
 			w.selectValues.Set(columns[i], values[i])
 		}
@@ -206,6 +228,11 @@ func (w *Wx) QueryServer() *ServerQuery {
 	return NewWxClient(w.config).QueryServer(w)
 }
 
+// QueryAgent queries the "agent" edge of the Wx entity.
+func (w *Wx) QueryAgent() *AgentQuery {
+	return NewWxClient(w.config).QueryAgent(w)
+}
+
 // Update returns a builder for updating this Wx.
 // Note that you need to call Wx.Unwrap() before calling this method if this Wx
 // was returned from a transaction, and the transaction was committed or rolled back.
@@ -270,6 +297,9 @@ func (w *Wx) String() string {
 	builder.WriteString(", ")
 	builder.WriteString("organization_id=")
 	builder.WriteString(fmt.Sprintf("%v", w.OrganizationID))
+	builder.WriteString(", ")
+	builder.WriteString("agent_id=")
+	builder.WriteString(fmt.Sprintf("%v", w.AgentID))
 	builder.WriteByte(')')
 	return builder.String()
 }

+ 48 - 0
ent/wx/where.go

@@ -125,6 +125,11 @@ func OrganizationID(v uint64) predicate.Wx {
 	return predicate.Wx(sql.FieldEQ(FieldOrganizationID, v))
 }
 
+// AgentID applies equality check predicate on the "agent_id" field. It's identical to AgentIDEQ.
+func AgentID(v uint64) predicate.Wx {
+	return predicate.Wx(sql.FieldEQ(FieldAgentID, 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))
@@ -905,6 +910,26 @@ func OrganizationIDNotNil() predicate.Wx {
 	return predicate.Wx(sql.FieldNotNull(FieldOrganizationID))
 }
 
+// AgentIDEQ applies the EQ predicate on the "agent_id" field.
+func AgentIDEQ(v uint64) predicate.Wx {
+	return predicate.Wx(sql.FieldEQ(FieldAgentID, v))
+}
+
+// AgentIDNEQ applies the NEQ predicate on the "agent_id" field.
+func AgentIDNEQ(v uint64) predicate.Wx {
+	return predicate.Wx(sql.FieldNEQ(FieldAgentID, v))
+}
+
+// AgentIDIn applies the In predicate on the "agent_id" field.
+func AgentIDIn(vs ...uint64) predicate.Wx {
+	return predicate.Wx(sql.FieldIn(FieldAgentID, vs...))
+}
+
+// AgentIDNotIn applies the NotIn predicate on the "agent_id" field.
+func AgentIDNotIn(vs ...uint64) predicate.Wx {
+	return predicate.Wx(sql.FieldNotIn(FieldAgentID, vs...))
+}
+
 // HasServer applies the HasEdge predicate on the "server" edge.
 func HasServer() predicate.Wx {
 	return predicate.Wx(func(s *sql.Selector) {
@@ -928,6 +953,29 @@ func HasServerWith(preds ...predicate.Server) predicate.Wx {
 	})
 }
 
+// HasAgent applies the HasEdge predicate on the "agent" edge.
+func HasAgent() predicate.Wx {
+	return predicate.Wx(func(s *sql.Selector) {
+		step := sqlgraph.NewStep(
+			sqlgraph.From(Table, FieldID),
+			sqlgraph.Edge(sqlgraph.M2O, true, AgentTable, AgentColumn),
+		)
+		sqlgraph.HasNeighbors(s, step)
+	})
+}
+
+// HasAgentWith applies the HasEdge predicate on the "agent" edge with a given conditions (other predicates).
+func HasAgentWith(preds ...predicate.Agent) predicate.Wx {
+	return predicate.Wx(func(s *sql.Selector) {
+		step := newAgentStep()
+		sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
+			for _, p := range preds {
+				p(s)
+			}
+		})
+	})
+}
+
 // And groups predicates with the AND operator between them.
 func And(predicates ...predicate.Wx) predicate.Wx {
 	return predicate.Wx(sql.AndPredicates(predicates...))

+ 33 - 0
ent/wx/wx.go

@@ -43,8 +43,12 @@ const (
 	FieldHeadBig = "head_big"
 	// FieldOrganizationID holds the string denoting the organization_id field in the database.
 	FieldOrganizationID = "organization_id"
+	// FieldAgentID holds the string denoting the agent_id field in the database.
+	FieldAgentID = "agent_id"
 	// EdgeServer holds the string denoting the server edge name in mutations.
 	EdgeServer = "server"
+	// EdgeAgent holds the string denoting the agent edge name in mutations.
+	EdgeAgent = "agent"
 	// Table holds the table name of the wx in the database.
 	Table = "wx"
 	// ServerTable is the table that holds the server relation/edge.
@@ -54,6 +58,13 @@ const (
 	ServerInverseTable = "server"
 	// ServerColumn is the table column denoting the server relation/edge.
 	ServerColumn = "server_id"
+	// AgentTable is the table that holds the agent relation/edge.
+	AgentTable = "wx"
+	// AgentInverseTable is the table name for the Agent entity.
+	// It exists in this package in order to avoid circular dependency with the "agent" package.
+	AgentInverseTable = "agent"
+	// AgentColumn is the table column denoting the agent relation/edge.
+	AgentColumn = "agent_id"
 )
 
 // Columns holds all SQL columns for wx fields.
@@ -73,6 +84,7 @@ var Columns = []string{
 	FieldTel,
 	FieldHeadBig,
 	FieldOrganizationID,
+	FieldAgentID,
 }
 
 // ValidColumn reports if the column name is valid (part of the table columns).
@@ -121,6 +133,8 @@ var (
 	DefaultHeadBig string
 	// DefaultOrganizationID holds the default value on creation for the "organization_id" field.
 	DefaultOrganizationID uint64
+	// DefaultAgentID holds the default value on creation for the "agent_id" field.
+	DefaultAgentID uint64
 )
 
 // OrderOption defines the ordering options for the Wx queries.
@@ -201,12 +215,24 @@ func ByOrganizationID(opts ...sql.OrderTermOption) OrderOption {
 	return sql.OrderByField(FieldOrganizationID, opts...).ToFunc()
 }
 
+// ByAgentID orders the results by the agent_id field.
+func ByAgentID(opts ...sql.OrderTermOption) OrderOption {
+	return sql.OrderByField(FieldAgentID, opts...).ToFunc()
+}
+
 // ByServerField orders the results by server field.
 func ByServerField(field string, opts ...sql.OrderTermOption) OrderOption {
 	return func(s *sql.Selector) {
 		sqlgraph.OrderByNeighborTerms(s, newServerStep(), sql.OrderByField(field, opts...))
 	}
 }
+
+// ByAgentField orders the results by agent field.
+func ByAgentField(field string, opts ...sql.OrderTermOption) OrderOption {
+	return func(s *sql.Selector) {
+		sqlgraph.OrderByNeighborTerms(s, newAgentStep(), sql.OrderByField(field, opts...))
+	}
+}
 func newServerStep() *sqlgraph.Step {
 	return sqlgraph.NewStep(
 		sqlgraph.From(Table, FieldID),
@@ -214,3 +240,10 @@ func newServerStep() *sqlgraph.Step {
 		sqlgraph.Edge(sqlgraph.M2O, true, ServerTable, ServerColumn),
 	)
 }
+func newAgentStep() *sqlgraph.Step {
+	return sqlgraph.NewStep(
+		sqlgraph.From(Table, FieldID),
+		sqlgraph.To(AgentInverseTable, FieldID),
+		sqlgraph.Edge(sqlgraph.M2O, true, AgentTable, AgentColumn),
+	)
+}

+ 87 - 0
ent/wx_create.go

@@ -7,6 +7,7 @@ import (
 	"errors"
 	"fmt"
 	"time"
+	"wechat-api/ent/agent"
 	"wechat-api/ent/server"
 	"wechat-api/ent/wx"
 
@@ -219,6 +220,20 @@ func (wc *WxCreate) SetNillableOrganizationID(u *uint64) *WxCreate {
 	return wc
 }
 
+// SetAgentID sets the "agent_id" field.
+func (wc *WxCreate) SetAgentID(u uint64) *WxCreate {
+	wc.mutation.SetAgentID(u)
+	return wc
+}
+
+// SetNillableAgentID sets the "agent_id" field if the given value is not nil.
+func (wc *WxCreate) SetNillableAgentID(u *uint64) *WxCreate {
+	if u != nil {
+		wc.SetAgentID(*u)
+	}
+	return wc
+}
+
 // SetID sets the "id" field.
 func (wc *WxCreate) SetID(u uint64) *WxCreate {
 	wc.mutation.SetID(u)
@@ -230,6 +245,11 @@ func (wc *WxCreate) SetServer(s *Server) *WxCreate {
 	return wc.SetServerID(s.ID)
 }
 
+// SetAgent sets the "agent" edge to the Agent entity.
+func (wc *WxCreate) SetAgent(a *Agent) *WxCreate {
+	return wc.SetAgentID(a.ID)
+}
+
 // Mutation returns the WxMutation object of the builder.
 func (wc *WxCreate) Mutation() *WxMutation {
 	return wc.mutation
@@ -325,6 +345,10 @@ func (wc *WxCreate) defaults() error {
 		v := wx.DefaultOrganizationID
 		wc.mutation.SetOrganizationID(v)
 	}
+	if _, ok := wc.mutation.AgentID(); !ok {
+		v := wx.DefaultAgentID
+		wc.mutation.SetAgentID(v)
+	}
 	return nil
 }
 
@@ -360,6 +384,12 @@ func (wc *WxCreate) check() error {
 	if _, ok := wc.mutation.HeadBig(); !ok {
 		return &ValidationError{Name: "head_big", err: errors.New(`ent: missing required field "Wx.head_big"`)}
 	}
+	if _, ok := wc.mutation.AgentID(); !ok {
+		return &ValidationError{Name: "agent_id", err: errors.New(`ent: missing required field "Wx.agent_id"`)}
+	}
+	if _, ok := wc.mutation.AgentID(); !ok {
+		return &ValidationError{Name: "agent", err: errors.New(`ent: missing required edge "Wx.agent"`)}
+	}
 	return nil
 }
 
@@ -462,6 +492,23 @@ func (wc *WxCreate) createSpec() (*Wx, *sqlgraph.CreateSpec) {
 		_node.ServerID = nodes[0]
 		_spec.Edges = append(_spec.Edges, edge)
 	}
+	if nodes := wc.mutation.AgentIDs(); len(nodes) > 0 {
+		edge := &sqlgraph.EdgeSpec{
+			Rel:     sqlgraph.M2O,
+			Inverse: true,
+			Table:   wx.AgentTable,
+			Columns: []string{wx.AgentColumn},
+			Bidi:    false,
+			Target: &sqlgraph.EdgeTarget{
+				IDSpec: sqlgraph.NewFieldSpec(agent.FieldID, field.TypeUint64),
+			},
+		}
+		for _, k := range nodes {
+			edge.Target.Nodes = append(edge.Target.Nodes, k)
+		}
+		_node.AgentID = nodes[0]
+		_spec.Edges = append(_spec.Edges, edge)
+	}
 	return _node, _spec
 }
 
@@ -706,6 +753,18 @@ func (u *WxUpsert) ClearOrganizationID() *WxUpsert {
 	return u
 }
 
+// SetAgentID sets the "agent_id" field.
+func (u *WxUpsert) SetAgentID(v uint64) *WxUpsert {
+	u.Set(wx.FieldAgentID, v)
+	return u
+}
+
+// UpdateAgentID sets the "agent_id" field to the value that was provided on create.
+func (u *WxUpsert) UpdateAgentID() *WxUpsert {
+	u.SetExcluded(wx.FieldAgentID)
+	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:
 //
@@ -981,6 +1040,20 @@ func (u *WxUpsertOne) ClearOrganizationID() *WxUpsertOne {
 	})
 }
 
+// SetAgentID sets the "agent_id" field.
+func (u *WxUpsertOne) SetAgentID(v uint64) *WxUpsertOne {
+	return u.Update(func(s *WxUpsert) {
+		s.SetAgentID(v)
+	})
+}
+
+// UpdateAgentID sets the "agent_id" field to the value that was provided on create.
+func (u *WxUpsertOne) UpdateAgentID() *WxUpsertOne {
+	return u.Update(func(s *WxUpsert) {
+		s.UpdateAgentID()
+	})
+}
+
 // Exec executes the query.
 func (u *WxUpsertOne) Exec(ctx context.Context) error {
 	if len(u.create.conflict) == 0 {
@@ -1422,6 +1495,20 @@ func (u *WxUpsertBulk) ClearOrganizationID() *WxUpsertBulk {
 	})
 }
 
+// SetAgentID sets the "agent_id" field.
+func (u *WxUpsertBulk) SetAgentID(v uint64) *WxUpsertBulk {
+	return u.Update(func(s *WxUpsert) {
+		s.SetAgentID(v)
+	})
+}
+
+// UpdateAgentID sets the "agent_id" field to the value that was provided on create.
+func (u *WxUpsertBulk) UpdateAgentID() *WxUpsertBulk {
+	return u.Update(func(s *WxUpsert) {
+		s.UpdateAgentID()
+	})
+}
+
 // Exec executes the query.
 func (u *WxUpsertBulk) Exec(ctx context.Context) error {
 	if u.create.err != nil {

+ 76 - 1
ent/wx_query.go

@@ -6,6 +6,7 @@ import (
 	"context"
 	"fmt"
 	"math"
+	"wechat-api/ent/agent"
 	"wechat-api/ent/predicate"
 	"wechat-api/ent/server"
 	"wechat-api/ent/wx"
@@ -23,6 +24,7 @@ type WxQuery struct {
 	inters     []Interceptor
 	predicates []predicate.Wx
 	withServer *ServerQuery
+	withAgent  *AgentQuery
 	// intermediate query (i.e. traversal path).
 	sql  *sql.Selector
 	path func(context.Context) (*sql.Selector, error)
@@ -81,6 +83,28 @@ func (wq *WxQuery) QueryServer() *ServerQuery {
 	return query
 }
 
+// QueryAgent chains the current query on the "agent" edge.
+func (wq *WxQuery) QueryAgent() *AgentQuery {
+	query := (&AgentClient{config: wq.config}).Query()
+	query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
+		if err := wq.prepareQuery(ctx); err != nil {
+			return nil, err
+		}
+		selector := wq.sqlQuery(ctx)
+		if err := selector.Err(); err != nil {
+			return nil, err
+		}
+		step := sqlgraph.NewStep(
+			sqlgraph.From(wx.Table, wx.FieldID, selector),
+			sqlgraph.To(agent.Table, agent.FieldID),
+			sqlgraph.Edge(sqlgraph.M2O, true, wx.AgentTable, wx.AgentColumn),
+		)
+		fromU = sqlgraph.SetNeighbors(wq.driver.Dialect(), step)
+		return fromU, nil
+	}
+	return query
+}
+
 // First returns the first Wx entity from the query.
 // Returns a *NotFoundError when no Wx was found.
 func (wq *WxQuery) First(ctx context.Context) (*Wx, error) {
@@ -274,6 +298,7 @@ func (wq *WxQuery) Clone() *WxQuery {
 		inters:     append([]Interceptor{}, wq.inters...),
 		predicates: append([]predicate.Wx{}, wq.predicates...),
 		withServer: wq.withServer.Clone(),
+		withAgent:  wq.withAgent.Clone(),
 		// clone intermediate query.
 		sql:  wq.sql.Clone(),
 		path: wq.path,
@@ -291,6 +316,17 @@ func (wq *WxQuery) WithServer(opts ...func(*ServerQuery)) *WxQuery {
 	return wq
 }
 
+// WithAgent tells the query-builder to eager-load the nodes that are connected to
+// the "agent" edge. The optional arguments are used to configure the query builder of the edge.
+func (wq *WxQuery) WithAgent(opts ...func(*AgentQuery)) *WxQuery {
+	query := (&AgentClient{config: wq.config}).Query()
+	for _, opt := range opts {
+		opt(query)
+	}
+	wq.withAgent = query
+	return wq
+}
+
 // GroupBy is used to group vertices by one or more fields/columns.
 // It is often used with aggregate functions, like: count, max, mean, min, sum.
 //
@@ -369,8 +405,9 @@ func (wq *WxQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Wx, error
 	var (
 		nodes       = []*Wx{}
 		_spec       = wq.querySpec()
-		loadedTypes = [1]bool{
+		loadedTypes = [2]bool{
 			wq.withServer != nil,
+			wq.withAgent != nil,
 		}
 	)
 	_spec.ScanValues = func(columns []string) ([]any, error) {
@@ -397,6 +434,12 @@ func (wq *WxQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Wx, error
 			return nil, err
 		}
 	}
+	if query := wq.withAgent; query != nil {
+		if err := wq.loadAgent(ctx, query, nodes, nil,
+			func(n *Wx, e *Agent) { n.Edges.Agent = e }); err != nil {
+			return nil, err
+		}
+	}
 	return nodes, nil
 }
 
@@ -429,6 +472,35 @@ func (wq *WxQuery) loadServer(ctx context.Context, query *ServerQuery, nodes []*
 	}
 	return nil
 }
+func (wq *WxQuery) loadAgent(ctx context.Context, query *AgentQuery, nodes []*Wx, init func(*Wx), assign func(*Wx, *Agent)) error {
+	ids := make([]uint64, 0, len(nodes))
+	nodeids := make(map[uint64][]*Wx)
+	for i := range nodes {
+		fk := nodes[i].AgentID
+		if _, ok := nodeids[fk]; !ok {
+			ids = append(ids, fk)
+		}
+		nodeids[fk] = append(nodeids[fk], nodes[i])
+	}
+	if len(ids) == 0 {
+		return nil
+	}
+	query.Where(agent.IDIn(ids...))
+	neighbors, err := query.All(ctx)
+	if err != nil {
+		return err
+	}
+	for _, n := range neighbors {
+		nodes, ok := nodeids[n.ID]
+		if !ok {
+			return fmt.Errorf(`unexpected foreign-key "agent_id" returned %v`, n.ID)
+		}
+		for i := range nodes {
+			assign(nodes[i], n)
+		}
+	}
+	return nil
+}
 
 func (wq *WxQuery) sqlCount(ctx context.Context) (int, error) {
 	_spec := wq.querySpec()
@@ -458,6 +530,9 @@ func (wq *WxQuery) querySpec() *sqlgraph.QuerySpec {
 		if wq.withServer != nil {
 			_spec.Node.AddColumnOnce(wx.FieldServerID)
 		}
+		if wq.withAgent != nil {
+			_spec.Node.AddColumnOnce(wx.FieldAgentID)
+		}
 	}
 	if ps := wq.predicates; len(ps) > 0 {
 		_spec.Predicate = func(selector *sql.Selector) {

+ 131 - 0
ent/wx_update.go

@@ -7,6 +7,7 @@ import (
 	"errors"
 	"fmt"
 	"time"
+	"wechat-api/ent/agent"
 	"wechat-api/ent/predicate"
 	"wechat-api/ent/server"
 	"wechat-api/ent/wx"
@@ -241,11 +242,30 @@ func (wu *WxUpdate) ClearOrganizationID() *WxUpdate {
 	return wu
 }
 
+// SetAgentID sets the "agent_id" field.
+func (wu *WxUpdate) SetAgentID(u uint64) *WxUpdate {
+	wu.mutation.SetAgentID(u)
+	return wu
+}
+
+// SetNillableAgentID sets the "agent_id" field if the given value is not nil.
+func (wu *WxUpdate) SetNillableAgentID(u *uint64) *WxUpdate {
+	if u != nil {
+		wu.SetAgentID(*u)
+	}
+	return wu
+}
+
 // SetServer sets the "server" edge to the Server entity.
 func (wu *WxUpdate) SetServer(s *Server) *WxUpdate {
 	return wu.SetServerID(s.ID)
 }
 
+// SetAgent sets the "agent" edge to the Agent entity.
+func (wu *WxUpdate) SetAgent(a *Agent) *WxUpdate {
+	return wu.SetAgentID(a.ID)
+}
+
 // Mutation returns the WxMutation object of the builder.
 func (wu *WxUpdate) Mutation() *WxMutation {
 	return wu.mutation
@@ -257,6 +277,12 @@ func (wu *WxUpdate) ClearServer() *WxUpdate {
 	return wu
 }
 
+// ClearAgent clears the "agent" edge to the Agent entity.
+func (wu *WxUpdate) ClearAgent() *WxUpdate {
+	wu.mutation.ClearAgent()
+	return wu
+}
+
 // Save executes the query and returns the number of nodes affected by the update operation.
 func (wu *WxUpdate) Save(ctx context.Context) (int, error) {
 	if err := wu.defaults(); err != nil {
@@ -299,7 +325,18 @@ func (wu *WxUpdate) defaults() error {
 	return nil
 }
 
+// check runs all checks and user-defined validators on the builder.
+func (wu *WxUpdate) check() error {
+	if _, ok := wu.mutation.AgentID(); wu.mutation.AgentCleared() && !ok {
+		return errors.New(`ent: clearing a required unique edge "Wx.agent"`)
+	}
+	return nil
+}
+
 func (wu *WxUpdate) sqlSave(ctx context.Context) (n int, err error) {
+	if err := wu.check(); err != nil {
+		return n, err
+	}
 	_spec := sqlgraph.NewUpdateSpec(wx.Table, wx.Columns, sqlgraph.NewFieldSpec(wx.FieldID, field.TypeUint64))
 	if ps := wu.mutation.predicates; len(ps) > 0 {
 		_spec.Predicate = func(selector *sql.Selector) {
@@ -388,6 +425,35 @@ func (wu *WxUpdate) sqlSave(ctx context.Context) (n int, err error) {
 		}
 		_spec.Edges.Add = append(_spec.Edges.Add, edge)
 	}
+	if wu.mutation.AgentCleared() {
+		edge := &sqlgraph.EdgeSpec{
+			Rel:     sqlgraph.M2O,
+			Inverse: true,
+			Table:   wx.AgentTable,
+			Columns: []string{wx.AgentColumn},
+			Bidi:    false,
+			Target: &sqlgraph.EdgeTarget{
+				IDSpec: sqlgraph.NewFieldSpec(agent.FieldID, field.TypeUint64),
+			},
+		}
+		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
+	}
+	if nodes := wu.mutation.AgentIDs(); len(nodes) > 0 {
+		edge := &sqlgraph.EdgeSpec{
+			Rel:     sqlgraph.M2O,
+			Inverse: true,
+			Table:   wx.AgentTable,
+			Columns: []string{wx.AgentColumn},
+			Bidi:    false,
+			Target: &sqlgraph.EdgeTarget{
+				IDSpec: sqlgraph.NewFieldSpec(agent.FieldID, field.TypeUint64),
+			},
+		}
+		for _, k := range nodes {
+			edge.Target.Nodes = append(edge.Target.Nodes, k)
+		}
+		_spec.Edges.Add = append(_spec.Edges.Add, edge)
+	}
 	if n, err = sqlgraph.UpdateNodes(ctx, wu.driver, _spec); err != nil {
 		if _, ok := err.(*sqlgraph.NotFoundError); ok {
 			err = &NotFoundError{wx.Label}
@@ -620,11 +686,30 @@ func (wuo *WxUpdateOne) ClearOrganizationID() *WxUpdateOne {
 	return wuo
 }
 
+// SetAgentID sets the "agent_id" field.
+func (wuo *WxUpdateOne) SetAgentID(u uint64) *WxUpdateOne {
+	wuo.mutation.SetAgentID(u)
+	return wuo
+}
+
+// SetNillableAgentID sets the "agent_id" field if the given value is not nil.
+func (wuo *WxUpdateOne) SetNillableAgentID(u *uint64) *WxUpdateOne {
+	if u != nil {
+		wuo.SetAgentID(*u)
+	}
+	return wuo
+}
+
 // SetServer sets the "server" edge to the Server entity.
 func (wuo *WxUpdateOne) SetServer(s *Server) *WxUpdateOne {
 	return wuo.SetServerID(s.ID)
 }
 
+// SetAgent sets the "agent" edge to the Agent entity.
+func (wuo *WxUpdateOne) SetAgent(a *Agent) *WxUpdateOne {
+	return wuo.SetAgentID(a.ID)
+}
+
 // Mutation returns the WxMutation object of the builder.
 func (wuo *WxUpdateOne) Mutation() *WxMutation {
 	return wuo.mutation
@@ -636,6 +721,12 @@ func (wuo *WxUpdateOne) ClearServer() *WxUpdateOne {
 	return wuo
 }
 
+// ClearAgent clears the "agent" edge to the Agent entity.
+func (wuo *WxUpdateOne) ClearAgent() *WxUpdateOne {
+	wuo.mutation.ClearAgent()
+	return wuo
+}
+
 // Where appends a list predicates to the WxUpdate builder.
 func (wuo *WxUpdateOne) Where(ps ...predicate.Wx) *WxUpdateOne {
 	wuo.mutation.Where(ps...)
@@ -691,7 +782,18 @@ func (wuo *WxUpdateOne) defaults() error {
 	return nil
 }
 
+// check runs all checks and user-defined validators on the builder.
+func (wuo *WxUpdateOne) check() error {
+	if _, ok := wuo.mutation.AgentID(); wuo.mutation.AgentCleared() && !ok {
+		return errors.New(`ent: clearing a required unique edge "Wx.agent"`)
+	}
+	return nil
+}
+
 func (wuo *WxUpdateOne) sqlSave(ctx context.Context) (_node *Wx, err error) {
+	if err := wuo.check(); err != nil {
+		return _node, err
+	}
 	_spec := sqlgraph.NewUpdateSpec(wx.Table, wx.Columns, sqlgraph.NewFieldSpec(wx.FieldID, field.TypeUint64))
 	id, ok := wuo.mutation.ID()
 	if !ok {
@@ -797,6 +899,35 @@ func (wuo *WxUpdateOne) sqlSave(ctx context.Context) (_node *Wx, err error) {
 		}
 		_spec.Edges.Add = append(_spec.Edges.Add, edge)
 	}
+	if wuo.mutation.AgentCleared() {
+		edge := &sqlgraph.EdgeSpec{
+			Rel:     sqlgraph.M2O,
+			Inverse: true,
+			Table:   wx.AgentTable,
+			Columns: []string{wx.AgentColumn},
+			Bidi:    false,
+			Target: &sqlgraph.EdgeTarget{
+				IDSpec: sqlgraph.NewFieldSpec(agent.FieldID, field.TypeUint64),
+			},
+		}
+		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
+	}
+	if nodes := wuo.mutation.AgentIDs(); len(nodes) > 0 {
+		edge := &sqlgraph.EdgeSpec{
+			Rel:     sqlgraph.M2O,
+			Inverse: true,
+			Table:   wx.AgentTable,
+			Columns: []string{wx.AgentColumn},
+			Bidi:    false,
+			Target: &sqlgraph.EdgeTarget{
+				IDSpec: sqlgraph.NewFieldSpec(agent.FieldID, field.TypeUint64),
+			},
+		}
+		for _, k := range nodes {
+			edge.Target.Nodes = append(edge.Target.Nodes, k)
+		}
+		_spec.Edges.Add = append(_spec.Edges.Add, edge)
+	}
 	_node = &Wx{config: wuo.config}
 	_spec.Assign = _node.assignValues
 	_spec.ScanValues = _node.scanValues

+ 34 - 34
internal/handler/routes.go

@@ -105,6 +105,40 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
 	)
 
 	server.AddRoutes(
+		rest.WithMiddlewares(
+			[]rest.Middleware{serverCtx.Authority},
+			[]rest.Route{
+				{
+					Method:  http.MethodPost,
+					Path:    "/agent/create",
+					Handler: agent.CreateAgentHandler(serverCtx),
+				},
+				{
+					Method:  http.MethodPost,
+					Path:    "/agent/update",
+					Handler: agent.UpdateAgentHandler(serverCtx),
+				},
+				{
+					Method:  http.MethodPost,
+					Path:    "/agent/delete",
+					Handler: agent.DeleteAgentHandler(serverCtx),
+				},
+				{
+					Method:  http.MethodPost,
+					Path:    "/agent/list",
+					Handler: agent.GetAgentListHandler(serverCtx),
+				},
+				{
+					Method:  http.MethodPost,
+					Path:    "/agent",
+					Handler: agent.GetAgentByIdHandler(serverCtx),
+				},
+			}...,
+		),
+		rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
+	)
+
+	server.AddRoutes(
 		[]rest.Route{
 			{
 				Method:  http.MethodPost,
@@ -538,38 +572,4 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
 		),
 		rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
 	)
-
-	server.AddRoutes(
-		rest.WithMiddlewares(
-			[]rest.Middleware{serverCtx.Authority},
-			[]rest.Route{
-				{
-					Method:  http.MethodPost,
-					Path:    "/agent/create",
-					Handler: agent.CreateAgentHandler(serverCtx),
-				},
-				{
-					Method:  http.MethodPost,
-					Path:    "/agent/update",
-					Handler: agent.UpdateAgentHandler(serverCtx),
-				},
-				{
-					Method:  http.MethodPost,
-					Path:    "/agent/delete",
-					Handler: agent.DeleteAgentHandler(serverCtx),
-				},
-				{
-					Method:  http.MethodPost,
-					Path:    "/agent/list",
-					Handler: agent.GetAgentListHandler(serverCtx),
-				},
-				{
-					Method:  http.MethodPost,
-					Path:    "/agent",
-					Handler: agent.GetAgentByIdHandler(serverCtx),
-				},
-			}...,
-		),
-		rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
-	)
 }

+ 9 - 0
internal/logic/Wx/create_wx_logic.go

@@ -2,8 +2,10 @@ package Wx
 
 import (
 	"context"
+	"errors"
 	"github.com/zeromicro/go-zero/core/errorx"
 	"wechat-api/ent"
+	agentModel "wechat-api/ent/agent"
 	"wechat-api/ent/wx"
 	"wechat-api/hook"
 	"wechat-api/internal/utils/dberrorhandler"
@@ -50,6 +52,12 @@ func (l *CreateWxLogic) CreateWx(req *types.WxInfo) (*types.BaseMsgResp, error)
 		return nil, err
 	}
 
+	// 判断所选模式是否可用
+	agent, err := l.svcCtx.DB.Agent.Query().Where(agentModel.Status(1), agentModel.ID(*req.AgentId)).First(l.ctx)
+	if err != nil && ent.IsNotFound(err) || agent == nil {
+		return nil, errors.New("所选模式不存在或者已被禁用,请选择其他模式")
+	}
+
 	loginStatus, err := hook.IsLoginStatus()
 	if err != nil {
 		return nil, err
@@ -84,6 +92,7 @@ func (l *CreateWxLogic) CreateWx(req *types.WxInfo) (*types.BaseMsgResp, error)
 				SetNotNilHeadBig(&selfInfo.HeadBig).
 				SetStatus(1).
 				SetOrganizationID(organizationId).
+				SetAgentID(*req.AgentId).
 				Save(l.ctx)
 		} else {
 			if req.Callback != nil && *req.Callback != "" {

+ 16 - 0
internal/logic/Wx/get_wx_by_id_logic.go

@@ -35,11 +35,25 @@ func (l *GetWxByIdLogic) GetWxById(req *types.IDReq) (*types.WxInfoResp, error)
 			wx.IDEQ(req.Id),                   // Filter by ID
 			wx.OrganizationID(organizationId), // Additional filter by organizationId
 		).
+		WithAgent().
 		Only(l.ctx)
 	if err != nil {
 		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
 	}
 
+	agent := types.AgentInfo{
+		BaseIDInfo: types.BaseIDInfo{
+			Id:        &data.AgentID,
+			CreatedAt: pointy.GetPointer(data.Edges.Agent.CreatedAt.UnixMilli()),
+			UpdatedAt: pointy.GetPointer(data.Edges.Agent.UpdatedAt.UnixMilli()),
+		},
+		Name:       &data.Edges.Agent.Name,
+		Role:       &data.Edges.Agent.Role,
+		Status:     &data.Edges.Agent.Status,
+		Background: &data.Edges.Agent.Background,
+		Examples:   &data.Edges.Agent.Examples,
+	}
+
 	return &types.WxInfoResp{
 		BaseDataInfo: types.BaseDataInfo{
 			Code: 0,
@@ -62,6 +76,8 @@ func (l *GetWxByIdLogic) GetWxById(req *types.IDReq) (*types.WxInfoResp, error)
 			Tel:            &data.Tel,
 			HeadBig:        &data.HeadBig,
 			OrganizationId: &data.OrganizationID,
+			AgentId:        &data.AgentID,
+			AgentInfo:      &agent,
 		},
 	}, nil
 }

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

@@ -2,7 +2,6 @@ package Wx
 
 import (
 	"context"
-
 	"wechat-api/ent/predicate"
 	"wechat-api/ent/wx"
 	"wechat-api/internal/svc"
@@ -43,7 +42,7 @@ func (l *GetWxListLogic) GetWxList(req *types.WxListReq) (*types.WxListResp, err
 	if req.Callback != nil {
 		predicates = append(predicates, wx.CallbackContains(*req.Callback))
 	}
-	data, err := l.svcCtx.DB.Wx.Query().Where(predicates...).Page(l.ctx, req.Page, req.PageSize)
+	data, err := l.svcCtx.DB.Wx.Query().Where(predicates...).WithAgent().Page(l.ctx, req.Page, req.PageSize)
 
 	if err != nil {
 		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
@@ -54,6 +53,22 @@ func (l *GetWxListLogic) GetWxList(req *types.WxListReq) (*types.WxListResp, err
 	resp.Data.Total = data.PageDetails.Total
 
 	for _, v := range data.List {
+		var agent types.AgentInfo
+		if v.Edges.Agent != nil {
+			agent = types.AgentInfo{
+				BaseIDInfo: types.BaseIDInfo{
+					Id:        &v.AgentID,
+					CreatedAt: pointy.GetPointer(v.Edges.Agent.CreatedAt.UnixMilli()),
+					UpdatedAt: pointy.GetPointer(v.Edges.Agent.UpdatedAt.UnixMilli()),
+				},
+				Name:       &v.Edges.Agent.Name,
+				Role:       &v.Edges.Agent.Role,
+				Status:     &v.Edges.Agent.Status,
+				Background: &v.Edges.Agent.Background,
+				Examples:   &v.Edges.Agent.Examples,
+			}
+		}
+
 		resp.Data.Data = append(resp.Data.Data,
 			types.WxInfo{
 				BaseIDInfo: types.BaseIDInfo{
@@ -72,6 +87,8 @@ func (l *GetWxListLogic) GetWxList(req *types.WxListReq) (*types.WxListResp, err
 				Tel:            &v.Tel,
 				HeadBig:        &v.HeadBig,
 				OrganizationId: &v.OrganizationID,
+				AgentId:        &v.AgentID,
+				AgentInfo:      &agent,
 			})
 	}
 

+ 1 - 0
internal/logic/Wx/update_wx_logic.go

@@ -40,6 +40,7 @@ func (l *UpdateWxLogic) UpdateWx(req *types.WxInfo) (*types.BaseMsgResp, error)
 		SetNotNilNickname(req.Nickname).
 		SetNotNilTel(req.Tel).
 		SetNotNilHeadBig(req.HeadBig).
+		SetNotNilAgentID(req.AgentId).
 		Exec(l.ctx)
 
 	if err != nil {

+ 7 - 0
internal/logic/agent/delete_agent_logic.go

@@ -3,6 +3,7 @@ package agent
 import (
 	"context"
 	"errors"
+	"wechat-api/ent/wx"
 
 	"wechat-api/ent/agent"
 	"wechat-api/internal/svc"
@@ -33,6 +34,12 @@ func (l *DeleteAgentLogic) DeleteAgent(req *types.IDsReq) (*types.BaseMsgResp, e
 		return nil, errors.New("ids参数不能为空")
 	}
 
+	// 删除AI角色之前要检查他是否被某账号所使用
+	count, _ := l.svcCtx.DB.Wx.Query().Where(wx.AgentIDIn(req.Ids...)).Count(l.ctx)
+	if count > 0 {
+		return nil, errors.New("有账号在使用该AI角色,请取消关联后再尝试删除")
+	}
+
 	_, err := l.svcCtx.DB.Agent.Delete().Where(agent.IDIn(req.Ids...), agent.OrganizationID(organizationId)).Exec(l.ctx)
 
 	if err != nil {

+ 3 - 0
internal/logic/agent/get_agent_list_logic.go

@@ -42,6 +42,9 @@ func (l *GetAgentListLogic) GetAgentList(req *types.AgentListReq) (*types.AgentL
 	if req.Background != nil {
 		predicates = append(predicates, agent.BackgroundContains(*req.Background))
 	}
+	if req.Status != nil {
+		predicates = append(predicates, agent.Status(*req.Status))
+	}
 	data, err := l.svcCtx.DB.Agent.Query().Where(predicates...).Page(l.ctx, req.Page, req.PageSize)
 
 	if err != nil {

+ 10 - 1
internal/logic/agent/update_agent_logic.go

@@ -5,6 +5,7 @@ import (
 	"errors"
 	"wechat-api/ent"
 	"wechat-api/ent/agent"
+	"wechat-api/ent/wx"
 
 	"wechat-api/internal/svc"
 	"wechat-api/internal/types"
@@ -36,11 +37,19 @@ func (l *UpdateAgentLogic) UpdateAgent(req *types.AgentInfo) (*types.BaseMsgResp
 		return nil, errors.New("记录ID不存在")
 	}
 
-	_, err := l.svcCtx.DB.Agent.Query().Where(agent.ID(*req.Id), agent.OrganizationID(organizationId)).First(l.ctx)
+	item, err := l.svcCtx.DB.Agent.Query().Where(agent.ID(*req.Id), agent.OrganizationID(organizationId)).First(l.ctx)
 	if err != nil && ent.IsNotFound(err) {
 		return nil, errors.New("记录不存在")
 	}
 
+	// 如果是下架AI角色,则需要判断是否有账号在关联该AI角色,如果有不让修改
+	if item.Status == 1 && *req.Status == 2 {
+		count, _ := l.svcCtx.DB.Wx.Query().Where(wx.AgentID(*req.Id)).Count(l.ctx)
+		if count > 0 {
+			return nil, errors.New("有账号在使用该AI角色,请取消关联后再尝试禁用")
+		}
+	}
+
 	err = l.svcCtx.DB.Agent.UpdateOneID(*req.Id).
 		SetNotNilName(req.Name).
 		SetNotNilRole(req.Role).

+ 58 - 52
internal/types/types.go

@@ -313,6 +313,10 @@ type WxInfo struct {
 	HeadBig *string `json:"headBig,optional"`
 	// 组织ID
 	OrganizationId *uint64 `json:"organizationId,optional"`
+	// 模式ID
+	AgentId *uint64 `json:"agentId"`
+	// 模式信息
+	AgentInfo *AgentInfo `json:"agentInfo,optional"`
 }
 
 // The response data of wx list | Wx列表数据
@@ -351,6 +355,60 @@ type WxInfoResp struct {
 	Data WxInfo `json:"data"`
 }
 
+// The data of agent information | Agent信息
+// swagger:model AgentInfo
+type AgentInfo struct {
+	BaseIDInfo
+	// name | 角色名称
+	Name *string `json:"name,optional"`
+	// role | 角色设定
+	Role *string `json:"role,optional"`
+	// status | 状态 1-正常 2-禁用
+	Status *int `json:"status,optional"`
+	// background | 背景介绍
+	Background *string `json:"background,optional"`
+	// examples | 对话案例
+	Examples *string `json:"examples,optional"`
+}
+
+// The response data of agent list | Agent列表数据
+// swagger:model AgentListResp
+type AgentListResp struct {
+	BaseDataInfo
+	// Agent list data | Agent列表数据
+	Data AgentListInfo `json:"data"`
+}
+
+// Agent list data | Agent列表数据
+// swagger:model AgentListInfo
+type AgentListInfo struct {
+	BaseListInfo
+	// The API list data | Agent列表数据
+	Data []AgentInfo `json:"data"`
+}
+
+// Get agent list request params | Agent列表请求参数
+// swagger:model AgentListReq
+type AgentListReq struct {
+	PageInfo
+	// name | 角色名称
+	Name *string `json:"name,optional"`
+	// role | 角色设定
+	Role *string `json:"role,optional"`
+	// background | 背景介绍
+	Background *string `json:"background,optional"`
+	// status | 状态 1-可用 2-不可用
+	Status *int `json:"status,optional"`
+}
+
+// Agent information response | Agent信息返回体
+// swagger:model AgentInfoResp
+type AgentInfoResp struct {
+	BaseDataInfo
+	// Agent information | Agent数据
+	Data AgentInfo `json:"data"`
+}
+
 type LoginQRStatus struct {
 	// 登陆二维码
 	QRCode string `json:"qRCode,optional"`
@@ -1128,55 +1186,3 @@ type BatchMsgInfoResp struct {
 	// BatchMsg information | BatchMsg数据
 	Data BatchMsgInfo `json:"data"`
 }
-
-// The data of agent information | Agent信息
-// swagger:model AgentInfo
-type AgentInfo struct {
-	BaseIDInfo
-	// name | 角色名称
-	Name *string `json:"name,optional"`
-	// role | 角色设定
-	Role *string `json:"role,optional"`
-	// status | 状态 1-正常 2-禁用
-	Status *int `json:"status,optional"`
-	// background | 背景介绍
-	Background *string `json:"background,optional"`
-	// examples | 对话案例
-	Examples *string `json:"examples,optional"`
-}
-
-// The response data of agent list | Agent列表数据
-// swagger:model AgentListResp
-type AgentListResp struct {
-	BaseDataInfo
-	// Agent list data | Agent列表数据
-	Data AgentListInfo `json:"data"`
-}
-
-// Agent list data | Agent列表数据
-// swagger:model AgentListInfo
-type AgentListInfo struct {
-	BaseListInfo
-	// The API list data | Agent列表数据
-	Data []AgentInfo `json:"data"`
-}
-
-// Get agent list request params | Agent列表请求参数
-// swagger:model AgentListReq
-type AgentListReq struct {
-	PageInfo
-	// name | 角色名称
-	Name *string `json:"name,optional"`
-	// role | 角色设定
-	Role *string `json:"role,optional"`
-	// background | 背景介绍
-	Background *string `json:"background,optional"`
-}
-
-// Agent information response | Agent信息返回体
-// swagger:model AgentInfoResp
-type AgentInfoResp struct {
-	BaseDataInfo
-	// Agent information | Agent数据
-	Data AgentInfo `json:"data"`
-}