Pārlūkot izejas kodu

Merge branch 'yhg_20250327' into debug

jimmyyem 4 nedēļas atpakaļ
vecāks
revīzija
14a94275cc

+ 4 - 4
crontask/init.go

@@ -43,8 +43,8 @@ func ScheduleRun(c *cron.Cron, serverCtx *svc.ServiceContext) {
 		computeStatistic.computeStatistic()
 	})
 
-	//syncWx := NewCronTask(context.Background(), serverCtx)
-	//c.AddFunc("*/30 * * * *", func() {
-	//	syncWx.syncWx()
-	//})
+	syncWx := NewCronTask(context.Background(), serverCtx)
+	c.AddFunc("*/30 * * * *", func() {
+		syncWx.syncWx()
+	})
 }

+ 3 - 1
desc/all.api

@@ -48,4 +48,6 @@ import "./wechat/xunji_service.api"
 import "./wp_wecom/send_msg.api"
 import "./wechat/fastgpt.api"
 import "./wechat/department.api"
-import "./wechat/api_key.api"
+import "./wechat/api_key.api"
+import "./wechat/xunji.api"
+import "./wechat/xunji_service.api"

+ 4 - 12
desc/wechat/xunji.api

@@ -20,20 +20,8 @@ type (
         // 加密key 
         EncodingKey  *string `json:"encodingKey,optional"`
 
-        // 角色ID 
-        AgentId  *uint64 `json:"agentId,optional"`
-
         // organization_id | 租户ID 
         OrganizationId  *uint64 `json:"organizationId,optional"`
-
-        // 微信ID 
-        Wxid  *string `json:"wxid,optional"`
-
-        // 大模型服务地址 
-        ApiBase  *string `json:"apiBase,optional"`
-
-        // 大模型服务密钥 
-        ApiKey  *string `json:"apiKey,optional"`
     }
 
     // The response data of xunji list | Xunji列表数据
@@ -101,4 +89,8 @@ service Wechat {
     // Get xunji by ID | 通过ID获取Xunji
     @handler getXunjiById
     post /xunji (IDReq) returns (XunjiInfoResp)
+
+	// Get xunji  | 通过机构ID获取Xunji
+	@handler getXunji
+	post /xunji/detail () returns (XunjiInfoResp)
 }

+ 16 - 0
ent/agent.go

@@ -57,6 +57,8 @@ type AgentEdges struct {
 	XjsAgent []*XunjiService `json:"xjs_agent,omitempty"`
 	// KeyAgent holds the value of the key_agent edge.
 	KeyAgent []*ApiKey `json:"key_agent,omitempty"`
+	// XjsAgent holds the value of the xjs_agent edge.
+	XjsAgent []*XunjiService `json:"xjs_agent,omitempty"`
 	// loadedTypes holds the information for reporting if a
 	// type was loaded (or requested) in eager-loading or not.
 	loadedTypes [5]bool
@@ -107,6 +109,15 @@ func (e AgentEdges) KeyAgentOrErr() ([]*ApiKey, error) {
 	return nil, &NotLoadedError{edge: "key_agent"}
 }
 
+// XjsAgentOrErr returns the XjsAgent value or an error if the edge
+// was not loaded in eager-loading.
+func (e AgentEdges) XjsAgentOrErr() ([]*XunjiService, error) {
+	if e.loadedTypes[4] {
+		return e.XjsAgent, nil
+	}
+	return nil, &NotLoadedError{edge: "xjs_agent"}
+}
+
 // scanValues returns the types for scanning values from sql.Rows.
 func (*Agent) scanValues(columns []string) ([]any, error) {
 	values := make([]any, len(columns))
@@ -243,6 +254,11 @@ func (a *Agent) QueryKeyAgent() *ApiKeyQuery {
 	return NewAgentClient(a.config).QueryKeyAgent(a)
 }
 
+// QueryXjsAgent queries the "xjs_agent" edge of the Agent entity.
+func (a *Agent) QueryXjsAgent() *XunjiServiceQuery {
+	return NewAgentClient(a.config).QueryXjsAgent(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.

+ 30 - 0
ent/agent/agent.go

@@ -47,6 +47,8 @@ const (
 	EdgeXjsAgent = "xjs_agent"
 	// EdgeKeyAgent holds the string denoting the key_agent edge name in mutations.
 	EdgeKeyAgent = "key_agent"
+	// EdgeXjsAgent holds the string denoting the xjs_agent edge name in mutations.
+	EdgeXjsAgent = "xjs_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.
@@ -84,6 +86,13 @@ const (
 	KeyAgentInverseTable = "api_key"
 	// KeyAgentColumn is the table column denoting the key_agent relation/edge.
 	KeyAgentColumn = "agent_id"
+	// XjsAgentTable is the table that holds the xjs_agent relation/edge.
+	XjsAgentTable = "xunji_service"
+	// XjsAgentInverseTable is the table name for the XunjiService entity.
+	// It exists in this package in order to avoid circular dependency with the "xunjiservice" package.
+	XjsAgentInverseTable = "xunji_service"
+	// XjsAgentColumn is the table column denoting the xjs_agent relation/edge.
+	XjsAgentColumn = "agent_id"
 )
 
 // Columns holds all SQL columns for agent fields.
@@ -280,6 +289,20 @@ func ByKeyAgent(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
 		sqlgraph.OrderByNeighborTerms(s, newKeyAgentStep(), append([]sql.OrderTerm{term}, terms...)...)
 	}
 }
+
+// ByXjsAgentCount orders the results by xjs_agent count.
+func ByXjsAgentCount(opts ...sql.OrderTermOption) OrderOption {
+	return func(s *sql.Selector) {
+		sqlgraph.OrderByNeighborsCount(s, newXjsAgentStep(), opts...)
+	}
+}
+
+// ByXjsAgent orders the results by xjs_agent terms.
+func ByXjsAgent(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
+	return func(s *sql.Selector) {
+		sqlgraph.OrderByNeighborTerms(s, newXjsAgentStep(), append([]sql.OrderTerm{term}, terms...)...)
+	}
+}
 func newWxAgentStep() *sqlgraph.Step {
 	return sqlgraph.NewStep(
 		sqlgraph.From(Table, FieldID),
@@ -315,3 +338,10 @@ func newKeyAgentStep() *sqlgraph.Step {
 		sqlgraph.Edge(sqlgraph.O2M, false, KeyAgentTable, KeyAgentColumn),
 	)
 }
+func newXjsAgentStep() *sqlgraph.Step {
+	return sqlgraph.NewStep(
+		sqlgraph.From(Table, FieldID),
+		sqlgraph.To(XjsAgentInverseTable, FieldID),
+		sqlgraph.Edge(sqlgraph.O2M, false, XjsAgentTable, XjsAgentColumn),
+	)
+}

+ 23 - 0
ent/agent/where.go

@@ -855,6 +855,29 @@ func HasKeyAgentWith(preds ...predicate.ApiKey) predicate.Agent {
 	})
 }
 
+// HasXjsAgent applies the HasEdge predicate on the "xjs_agent" edge.
+func HasXjsAgent() predicate.Agent {
+	return predicate.Agent(func(s *sql.Selector) {
+		step := sqlgraph.NewStep(
+			sqlgraph.From(Table, FieldID),
+			sqlgraph.Edge(sqlgraph.O2M, false, XjsAgentTable, XjsAgentColumn),
+		)
+		sqlgraph.HasNeighbors(s, step)
+	})
+}
+
+// HasXjsAgentWith applies the HasEdge predicate on the "xjs_agent" edge with a given conditions (other predicates).
+func HasXjsAgentWith(preds ...predicate.XunjiService) predicate.Agent {
+	return predicate.Agent(func(s *sql.Selector) {
+		step := newXjsAgentStep()
+		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...))

+ 31 - 0
ent/agent_create.go

@@ -238,6 +238,21 @@ func (ac *AgentCreate) AddKeyAgent(a ...*ApiKey) *AgentCreate {
 	return ac.AddKeyAgentIDs(ids...)
 }
 
+// AddXjsAgentIDs adds the "xjs_agent" edge to the XunjiService entity by IDs.
+func (ac *AgentCreate) AddXjsAgentIDs(ids ...uint64) *AgentCreate {
+	ac.mutation.AddXjsAgentIDs(ids...)
+	return ac
+}
+
+// AddXjsAgent adds the "xjs_agent" edges to the XunjiService entity.
+func (ac *AgentCreate) AddXjsAgent(x ...*XunjiService) *AgentCreate {
+	ids := make([]uint64, len(x))
+	for i := range x {
+		ids[i] = x[i].ID
+	}
+	return ac.AddXjsAgentIDs(ids...)
+}
+
 // Mutation returns the AgentMutation object of the builder.
 func (ac *AgentCreate) Mutation() *AgentMutation {
 	return ac.mutation
@@ -517,6 +532,22 @@ func (ac *AgentCreate) createSpec() (*Agent, *sqlgraph.CreateSpec) {
 		}
 		_spec.Edges = append(_spec.Edges, edge)
 	}
+	if nodes := ac.mutation.XjsAgentIDs(); len(nodes) > 0 {
+		edge := &sqlgraph.EdgeSpec{
+			Rel:     sqlgraph.O2M,
+			Inverse: false,
+			Table:   agent.XjsAgentTable,
+			Columns: []string{agent.XjsAgentColumn},
+			Bidi:    false,
+			Target: &sqlgraph.EdgeTarget{
+				IDSpec: sqlgraph.NewFieldSpec(xunjiservice.FieldID, field.TypeUint64),
+			},
+		}
+		for _, k := range nodes {
+			edge.Target.Nodes = append(edge.Target.Nodes, k)
+		}
+		_spec.Edges = append(_spec.Edges, edge)
+	}
 	return _node, _spec
 }
 

+ 73 - 0
ent/agent_query.go

@@ -32,6 +32,7 @@ type AgentQuery struct {
 	withWaAgent    *WhatsappQuery
 	withXjsAgent   *XunjiServiceQuery
 	withKeyAgent   *ApiKeyQuery
+	withXjsAgent   *XunjiServiceQuery
 	// intermediate query (i.e. traversal path).
 	sql  *sql.Selector
 	path func(context.Context) (*sql.Selector, error)
@@ -178,6 +179,28 @@ func (aq *AgentQuery) QueryKeyAgent() *ApiKeyQuery {
 	return query
 }
 
+// QueryXjsAgent chains the current query on the "xjs_agent" edge.
+func (aq *AgentQuery) QueryXjsAgent() *XunjiServiceQuery {
+	query := (&XunjiServiceClient{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(xunjiservice.Table, xunjiservice.FieldID),
+			sqlgraph.Edge(sqlgraph.O2M, false, agent.XjsAgentTable, agent.XjsAgentColumn),
+		)
+		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) {
@@ -375,6 +398,7 @@ func (aq *AgentQuery) Clone() *AgentQuery {
 		withWaAgent:    aq.withWaAgent.Clone(),
 		withXjsAgent:   aq.withXjsAgent.Clone(),
 		withKeyAgent:   aq.withKeyAgent.Clone(),
+		withXjsAgent:   aq.withXjsAgent.Clone(),
 		// clone intermediate query.
 		sql:  aq.sql.Clone(),
 		path: aq.path,
@@ -436,6 +460,17 @@ func (aq *AgentQuery) WithKeyAgent(opts ...func(*ApiKeyQuery)) *AgentQuery {
 	return aq
 }
 
+// WithXjsAgent tells the query-builder to eager-load the nodes that are connected to
+// the "xjs_agent" edge. The optional arguments are used to configure the query builder of the edge.
+func (aq *AgentQuery) WithXjsAgent(opts ...func(*XunjiServiceQuery)) *AgentQuery {
+	query := (&XunjiServiceClient{config: aq.config}).Query()
+	for _, opt := range opts {
+		opt(query)
+	}
+	aq.withXjsAgent = 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.
 //
@@ -520,6 +555,7 @@ func (aq *AgentQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Agent,
 			aq.withWaAgent != nil,
 			aq.withXjsAgent != nil,
 			aq.withKeyAgent != nil,
+			aq.withXjsAgent != nil,
 		}
 	)
 	_spec.ScanValues = func(columns []string) ([]any, error) {
@@ -575,6 +611,13 @@ func (aq *AgentQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Agent,
 			return nil, err
 		}
 	}
+	if query := aq.withXjsAgent; query != nil {
+		if err := aq.loadXjsAgent(ctx, query, nodes,
+			func(n *Agent) { n.Edges.XjsAgent = []*XunjiService{} },
+			func(n *Agent, e *XunjiService) { n.Edges.XjsAgent = append(n.Edges.XjsAgent, e) }); err != nil {
+			return nil, err
+		}
+	}
 	return nodes, nil
 }
 
@@ -729,6 +772,36 @@ func (aq *AgentQuery) loadKeyAgent(ctx context.Context, query *ApiKeyQuery, node
 	}
 	return nil
 }
+func (aq *AgentQuery) loadXjsAgent(ctx context.Context, query *XunjiServiceQuery, nodes []*Agent, init func(*Agent), assign func(*Agent, *XunjiService)) 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(xunjiservice.FieldAgentID)
+	}
+	query.Where(predicate.XunjiService(func(s *sql.Selector) {
+		s.Where(sql.InValues(s.C(agent.XjsAgentColumn), 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()

+ 162 - 0
ent/agent_update.go

@@ -278,6 +278,21 @@ func (au *AgentUpdate) AddKeyAgent(a ...*ApiKey) *AgentUpdate {
 	return au.AddKeyAgentIDs(ids...)
 }
 
+// AddXjsAgentIDs adds the "xjs_agent" edge to the XunjiService entity by IDs.
+func (au *AgentUpdate) AddXjsAgentIDs(ids ...uint64) *AgentUpdate {
+	au.mutation.AddXjsAgentIDs(ids...)
+	return au
+}
+
+// AddXjsAgent adds the "xjs_agent" edges to the XunjiService entity.
+func (au *AgentUpdate) AddXjsAgent(x ...*XunjiService) *AgentUpdate {
+	ids := make([]uint64, len(x))
+	for i := range x {
+		ids[i] = x[i].ID
+	}
+	return au.AddXjsAgentIDs(ids...)
+}
+
 // Mutation returns the AgentMutation object of the builder.
 func (au *AgentUpdate) Mutation() *AgentMutation {
 	return au.mutation
@@ -388,6 +403,27 @@ func (au *AgentUpdate) RemoveKeyAgent(a ...*ApiKey) *AgentUpdate {
 	return au.RemoveKeyAgentIDs(ids...)
 }
 
+// ClearXjsAgent clears all "xjs_agent" edges to the XunjiService entity.
+func (au *AgentUpdate) ClearXjsAgent() *AgentUpdate {
+	au.mutation.ClearXjsAgent()
+	return au
+}
+
+// RemoveXjsAgentIDs removes the "xjs_agent" edge to XunjiService entities by IDs.
+func (au *AgentUpdate) RemoveXjsAgentIDs(ids ...uint64) *AgentUpdate {
+	au.mutation.RemoveXjsAgentIDs(ids...)
+	return au
+}
+
+// RemoveXjsAgent removes "xjs_agent" edges to XunjiService entities.
+func (au *AgentUpdate) RemoveXjsAgent(x ...*XunjiService) *AgentUpdate {
+	ids := make([]uint64, len(x))
+	for i := range x {
+		ids[i] = x[i].ID
+	}
+	return au.RemoveXjsAgentIDs(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 {
@@ -745,6 +781,51 @@ func (au *AgentUpdate) sqlSave(ctx context.Context) (n int, err error) {
 		}
 		_spec.Edges.Add = append(_spec.Edges.Add, edge)
 	}
+	if au.mutation.XjsAgentCleared() {
+		edge := &sqlgraph.EdgeSpec{
+			Rel:     sqlgraph.O2M,
+			Inverse: false,
+			Table:   agent.XjsAgentTable,
+			Columns: []string{agent.XjsAgentColumn},
+			Bidi:    false,
+			Target: &sqlgraph.EdgeTarget{
+				IDSpec: sqlgraph.NewFieldSpec(xunjiservice.FieldID, field.TypeUint64),
+			},
+		}
+		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
+	}
+	if nodes := au.mutation.RemovedXjsAgentIDs(); len(nodes) > 0 && !au.mutation.XjsAgentCleared() {
+		edge := &sqlgraph.EdgeSpec{
+			Rel:     sqlgraph.O2M,
+			Inverse: false,
+			Table:   agent.XjsAgentTable,
+			Columns: []string{agent.XjsAgentColumn},
+			Bidi:    false,
+			Target: &sqlgraph.EdgeTarget{
+				IDSpec: sqlgraph.NewFieldSpec(xunjiservice.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.XjsAgentIDs(); len(nodes) > 0 {
+		edge := &sqlgraph.EdgeSpec{
+			Rel:     sqlgraph.O2M,
+			Inverse: false,
+			Table:   agent.XjsAgentTable,
+			Columns: []string{agent.XjsAgentColumn},
+			Bidi:    false,
+			Target: &sqlgraph.EdgeTarget{
+				IDSpec: sqlgraph.NewFieldSpec(xunjiservice.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}
@@ -1010,6 +1091,21 @@ func (auo *AgentUpdateOne) AddKeyAgent(a ...*ApiKey) *AgentUpdateOne {
 	return auo.AddKeyAgentIDs(ids...)
 }
 
+// AddXjsAgentIDs adds the "xjs_agent" edge to the XunjiService entity by IDs.
+func (auo *AgentUpdateOne) AddXjsAgentIDs(ids ...uint64) *AgentUpdateOne {
+	auo.mutation.AddXjsAgentIDs(ids...)
+	return auo
+}
+
+// AddXjsAgent adds the "xjs_agent" edges to the XunjiService entity.
+func (auo *AgentUpdateOne) AddXjsAgent(x ...*XunjiService) *AgentUpdateOne {
+	ids := make([]uint64, len(x))
+	for i := range x {
+		ids[i] = x[i].ID
+	}
+	return auo.AddXjsAgentIDs(ids...)
+}
+
 // Mutation returns the AgentMutation object of the builder.
 func (auo *AgentUpdateOne) Mutation() *AgentMutation {
 	return auo.mutation
@@ -1120,6 +1216,27 @@ func (auo *AgentUpdateOne) RemoveKeyAgent(a ...*ApiKey) *AgentUpdateOne {
 	return auo.RemoveKeyAgentIDs(ids...)
 }
 
+// ClearXjsAgent clears all "xjs_agent" edges to the XunjiService entity.
+func (auo *AgentUpdateOne) ClearXjsAgent() *AgentUpdateOne {
+	auo.mutation.ClearXjsAgent()
+	return auo
+}
+
+// RemoveXjsAgentIDs removes the "xjs_agent" edge to XunjiService entities by IDs.
+func (auo *AgentUpdateOne) RemoveXjsAgentIDs(ids ...uint64) *AgentUpdateOne {
+	auo.mutation.RemoveXjsAgentIDs(ids...)
+	return auo
+}
+
+// RemoveXjsAgent removes "xjs_agent" edges to XunjiService entities.
+func (auo *AgentUpdateOne) RemoveXjsAgent(x ...*XunjiService) *AgentUpdateOne {
+	ids := make([]uint64, len(x))
+	for i := range x {
+		ids[i] = x[i].ID
+	}
+	return auo.RemoveXjsAgentIDs(ids...)
+}
+
 // Where appends a list predicates to the AgentUpdate builder.
 func (auo *AgentUpdateOne) Where(ps ...predicate.Agent) *AgentUpdateOne {
 	auo.mutation.Where(ps...)
@@ -1507,6 +1624,51 @@ func (auo *AgentUpdateOne) sqlSave(ctx context.Context) (_node *Agent, err error
 		}
 		_spec.Edges.Add = append(_spec.Edges.Add, edge)
 	}
+	if auo.mutation.XjsAgentCleared() {
+		edge := &sqlgraph.EdgeSpec{
+			Rel:     sqlgraph.O2M,
+			Inverse: false,
+			Table:   agent.XjsAgentTable,
+			Columns: []string{agent.XjsAgentColumn},
+			Bidi:    false,
+			Target: &sqlgraph.EdgeTarget{
+				IDSpec: sqlgraph.NewFieldSpec(xunjiservice.FieldID, field.TypeUint64),
+			},
+		}
+		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
+	}
+	if nodes := auo.mutation.RemovedXjsAgentIDs(); len(nodes) > 0 && !auo.mutation.XjsAgentCleared() {
+		edge := &sqlgraph.EdgeSpec{
+			Rel:     sqlgraph.O2M,
+			Inverse: false,
+			Table:   agent.XjsAgentTable,
+			Columns: []string{agent.XjsAgentColumn},
+			Bidi:    false,
+			Target: &sqlgraph.EdgeTarget{
+				IDSpec: sqlgraph.NewFieldSpec(xunjiservice.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.XjsAgentIDs(); len(nodes) > 0 {
+		edge := &sqlgraph.EdgeSpec{
+			Rel:     sqlgraph.O2M,
+			Inverse: false,
+			Table:   agent.XjsAgentTable,
+			Columns: []string{agent.XjsAgentColumn},
+			Bidi:    false,
+			Target: &sqlgraph.EdgeTarget{
+				IDSpec: sqlgraph.NewFieldSpec(xunjiservice.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

+ 16 - 0
ent/client.go

@@ -748,6 +748,22 @@ func (c *AgentClient) QueryKeyAgent(a *Agent) *ApiKeyQuery {
 	return query
 }
 
+// QueryXjsAgent queries the xjs_agent edge of a Agent.
+func (c *AgentClient) QueryXjsAgent(a *Agent) *XunjiServiceQuery {
+	query := (&XunjiServiceClient{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(xunjiservice.Table, xunjiservice.FieldID),
+			sqlgraph.Edge(sqlgraph.O2M, false, agent.XjsAgentTable, agent.XjsAgentColumn),
+		)
+		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

+ 0 - 1
ent/migrate/schema.go

@@ -1423,7 +1423,6 @@ var (
 		{Name: "app_secret", Type: field.TypeString, Comment: "AppSecret"},
 		{Name: "token", Type: field.TypeString, Comment: "Token"},
 		{Name: "encoding_key", Type: field.TypeString, Comment: "加密key"},
-		{Name: "agent_id", Type: field.TypeUint64, Comment: "角色ID"},
 		{Name: "organization_id", Type: field.TypeUint64, Comment: "organization_id | 租户ID"},
 	}
 	// XunjiTable holds the schema information for the "xunji" table.

+ 84 - 88
ent/mutation.go

@@ -147,6 +147,9 @@ type AgentMutation struct {
 	key_agent          map[uint64]struct{}
 	removedkey_agent   map[uint64]struct{}
 	clearedkey_agent   bool
+	xjs_agent          map[uint64]struct{}
+	removedxjs_agent   map[uint64]struct{}
+	clearedxjs_agent   bool
 	done               bool
 	oldValue           func(context.Context) (*Agent, error)
 	predicates         []predicate.Agent
@@ -1015,6 +1018,60 @@ func (m *AgentMutation) ResetKeyAgent() {
 	m.removedkey_agent = nil
 }
 
+// AddXjsAgentIDs adds the "xjs_agent" edge to the XunjiService entity by ids.
+func (m *AgentMutation) AddXjsAgentIDs(ids ...uint64) {
+	if m.xjs_agent == nil {
+		m.xjs_agent = make(map[uint64]struct{})
+	}
+	for i := range ids {
+		m.xjs_agent[ids[i]] = struct{}{}
+	}
+}
+
+// ClearXjsAgent clears the "xjs_agent" edge to the XunjiService entity.
+func (m *AgentMutation) ClearXjsAgent() {
+	m.clearedxjs_agent = true
+}
+
+// XjsAgentCleared reports if the "xjs_agent" edge to the XunjiService entity was cleared.
+func (m *AgentMutation) XjsAgentCleared() bool {
+	return m.clearedxjs_agent
+}
+
+// RemoveXjsAgentIDs removes the "xjs_agent" edge to the XunjiService entity by IDs.
+func (m *AgentMutation) RemoveXjsAgentIDs(ids ...uint64) {
+	if m.removedxjs_agent == nil {
+		m.removedxjs_agent = make(map[uint64]struct{})
+	}
+	for i := range ids {
+		delete(m.xjs_agent, ids[i])
+		m.removedxjs_agent[ids[i]] = struct{}{}
+	}
+}
+
+// RemovedXjsAgent returns the removed IDs of the "xjs_agent" edge to the XunjiService entity.
+func (m *AgentMutation) RemovedXjsAgentIDs() (ids []uint64) {
+	for id := range m.removedxjs_agent {
+		ids = append(ids, id)
+	}
+	return
+}
+
+// XjsAgentIDs returns the "xjs_agent" edge IDs in the mutation.
+func (m *AgentMutation) XjsAgentIDs() (ids []uint64) {
+	for id := range m.xjs_agent {
+		ids = append(ids, id)
+	}
+	return
+}
+
+// ResetXjsAgent resets all changes to the "xjs_agent" edge.
+func (m *AgentMutation) ResetXjsAgent() {
+	m.xjs_agent = nil
+	m.clearedxjs_agent = false
+	m.removedxjs_agent = nil
+}
+
 // Where appends a list predicates to the AgentMutation builder.
 func (m *AgentMutation) Where(ps ...predicate.Agent) {
 	m.predicates = append(m.predicates, ps...)
@@ -1388,6 +1445,9 @@ func (m *AgentMutation) AddedEdges() []string {
 	if m.key_agent != nil {
 		edges = append(edges, agent.EdgeKeyAgent)
 	}
+	if m.xjs_agent != nil {
+		edges = append(edges, agent.EdgeXjsAgent)
+	}
 	return edges
 }
 
@@ -1425,6 +1485,12 @@ func (m *AgentMutation) AddedIDs(name string) []ent.Value {
 			ids = append(ids, id)
 		}
 		return ids
+	case agent.EdgeXjsAgent:
+		ids := make([]ent.Value, 0, len(m.xjs_agent))
+		for id := range m.xjs_agent {
+			ids = append(ids, id)
+		}
+		return ids
 	}
 	return nil
 }
@@ -1447,6 +1513,9 @@ func (m *AgentMutation) RemovedEdges() []string {
 	if m.removedkey_agent != nil {
 		edges = append(edges, agent.EdgeKeyAgent)
 	}
+	if m.removedxjs_agent != nil {
+		edges = append(edges, agent.EdgeXjsAgent)
+	}
 	return edges
 }
 
@@ -1484,6 +1553,12 @@ func (m *AgentMutation) RemovedIDs(name string) []ent.Value {
 			ids = append(ids, id)
 		}
 		return ids
+	case agent.EdgeXjsAgent:
+		ids := make([]ent.Value, 0, len(m.removedxjs_agent))
+		for id := range m.removedxjs_agent {
+			ids = append(ids, id)
+		}
+		return ids
 	}
 	return nil
 }
@@ -1506,6 +1581,9 @@ func (m *AgentMutation) ClearedEdges() []string {
 	if m.clearedkey_agent {
 		edges = append(edges, agent.EdgeKeyAgent)
 	}
+	if m.clearedxjs_agent {
+		edges = append(edges, agent.EdgeXjsAgent)
+	}
 	return edges
 }
 
@@ -1523,6 +1601,8 @@ func (m *AgentMutation) EdgeCleared(name string) bool {
 		return m.clearedxjs_agent
 	case agent.EdgeKeyAgent:
 		return m.clearedkey_agent
+	case agent.EdgeXjsAgent:
+		return m.clearedxjs_agent
 	}
 	return false
 }
@@ -1554,6 +1634,9 @@ func (m *AgentMutation) ResetEdge(name string) error {
 	case agent.EdgeKeyAgent:
 		m.ResetKeyAgent()
 		return nil
+	case agent.EdgeXjsAgent:
+		m.ResetXjsAgent()
+		return nil
 	}
 	return fmt.Errorf("unknown Agent edge %s", name)
 }
@@ -50047,8 +50130,6 @@ type XunjiMutation struct {
 	app_secret         *string
 	token              *string
 	encoding_key       *string
-	agent_id           *uint64
-	addagent_id        *int64
 	organization_id    *uint64
 	addorganization_id *int64
 	clearedFields      map[string]struct{}
@@ -50496,62 +50577,6 @@ func (m *XunjiMutation) ResetEncodingKey() {
 	m.encoding_key = nil
 }
 
-// SetAgentID sets the "agent_id" field.
-func (m *XunjiMutation) SetAgentID(u uint64) {
-	m.agent_id = &u
-	m.addagent_id = nil
-}
-
-// AgentID returns the value of the "agent_id" field in the mutation.
-func (m *XunjiMutation) AgentID() (r uint64, exists bool) {
-	v := m.agent_id
-	if v == nil {
-		return
-	}
-	return *v, true
-}
-
-// OldAgentID returns the old "agent_id" field's value of the Xunji entity.
-// If the Xunji 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 *XunjiMutation) 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
-}
-
-// AddAgentID adds u to the "agent_id" field.
-func (m *XunjiMutation) AddAgentID(u int64) {
-	if m.addagent_id != nil {
-		*m.addagent_id += u
-	} else {
-		m.addagent_id = &u
-	}
-}
-
-// AddedAgentID returns the value that was added to the "agent_id" field in this mutation.
-func (m *XunjiMutation) AddedAgentID() (r int64, exists bool) {
-	v := m.addagent_id
-	if v == nil {
-		return
-	}
-	return *v, true
-}
-
-// ResetAgentID resets all changes to the "agent_id" field.
-func (m *XunjiMutation) ResetAgentID() {
-	m.agent_id = nil
-	m.addagent_id = nil
-}
-
 // SetOrganizationID sets the "organization_id" field.
 func (m *XunjiMutation) SetOrganizationID(u uint64) {
 	m.organization_id = &u
@@ -50642,7 +50667,7 @@ func (m *XunjiMutation) Type() string {
 // order to get all numeric fields that were incremented/decremented, call
 // AddedFields().
 func (m *XunjiMutation) Fields() []string {
-	fields := make([]string, 0, 10)
+	fields := make([]string, 0, 9)
 	if m.created_at != nil {
 		fields = append(fields, xunji.FieldCreatedAt)
 	}
@@ -50667,9 +50692,6 @@ func (m *XunjiMutation) Fields() []string {
 	if m.encoding_key != nil {
 		fields = append(fields, xunji.FieldEncodingKey)
 	}
-	if m.agent_id != nil {
-		fields = append(fields, xunji.FieldAgentID)
-	}
 	if m.organization_id != nil {
 		fields = append(fields, xunji.FieldOrganizationID)
 	}
@@ -50697,8 +50719,6 @@ func (m *XunjiMutation) Field(name string) (ent.Value, bool) {
 		return m.Token()
 	case xunji.FieldEncodingKey:
 		return m.EncodingKey()
-	case xunji.FieldAgentID:
-		return m.AgentID()
 	case xunji.FieldOrganizationID:
 		return m.OrganizationID()
 	}
@@ -50726,8 +50746,6 @@ func (m *XunjiMutation) OldField(ctx context.Context, name string) (ent.Value, e
 		return m.OldToken(ctx)
 	case xunji.FieldEncodingKey:
 		return m.OldEncodingKey(ctx)
-	case xunji.FieldAgentID:
-		return m.OldAgentID(ctx)
 	case xunji.FieldOrganizationID:
 		return m.OldOrganizationID(ctx)
 	}
@@ -50795,13 +50813,6 @@ func (m *XunjiMutation) SetField(name string, value ent.Value) error {
 		}
 		m.SetEncodingKey(v)
 		return nil
-	case xunji.FieldAgentID:
-		v, ok := value.(uint64)
-		if !ok {
-			return fmt.Errorf("unexpected type %T for field %s", value, name)
-		}
-		m.SetAgentID(v)
-		return nil
 	case xunji.FieldOrganizationID:
 		v, ok := value.(uint64)
 		if !ok {
@@ -50820,9 +50831,6 @@ func (m *XunjiMutation) AddedFields() []string {
 	if m.addstatus != nil {
 		fields = append(fields, xunji.FieldStatus)
 	}
-	if m.addagent_id != nil {
-		fields = append(fields, xunji.FieldAgentID)
-	}
 	if m.addorganization_id != nil {
 		fields = append(fields, xunji.FieldOrganizationID)
 	}
@@ -50836,8 +50844,6 @@ func (m *XunjiMutation) AddedField(name string) (ent.Value, bool) {
 	switch name {
 	case xunji.FieldStatus:
 		return m.AddedStatus()
-	case xunji.FieldAgentID:
-		return m.AddedAgentID()
 	case xunji.FieldOrganizationID:
 		return m.AddedOrganizationID()
 	}
@@ -50856,13 +50862,6 @@ func (m *XunjiMutation) AddField(name string, value ent.Value) error {
 		}
 		m.AddStatus(v)
 		return nil
-	case xunji.FieldAgentID:
-		v, ok := value.(int64)
-		if !ok {
-			return fmt.Errorf("unexpected type %T for field %s", value, name)
-		}
-		m.AddAgentID(v)
-		return nil
 	case xunji.FieldOrganizationID:
 		v, ok := value.(int64)
 		if !ok {
@@ -50936,9 +50935,6 @@ func (m *XunjiMutation) ResetField(name string) error {
 	case xunji.FieldEncodingKey:
 		m.ResetEncodingKey()
 		return nil
-	case xunji.FieldAgentID:
-		m.ResetAgentID()
-		return nil
 	case xunji.FieldOrganizationID:
 		m.ResetOrganizationID()
 		return nil

+ 1 - 1
ent/runtime/runtime.go

@@ -1873,7 +1873,7 @@ func init() {
 	// xunji.DefaultStatus holds the default value on creation for the status field.
 	xunji.DefaultStatus = xunjiDescStatus.Default.(uint8)
 	// xunjiDescOrganizationID is the schema descriptor for organization_id field.
-	xunjiDescOrganizationID := xunjiFields[5].Descriptor()
+	xunjiDescOrganizationID := xunjiFields[4].Descriptor()
 	// xunji.OrganizationIDValidator is a validator for the "organization_id" field. It is called by the builders before save.
 	xunji.OrganizationIDValidator = xunjiDescOrganizationID.Validators[0].(func(uint64) error)
 	xunjiserviceMixin := schema.XunjiService{}.Mixin()

+ 1 - 0
ent/schema/agent.go

@@ -43,6 +43,7 @@ func (Agent) Edges() []ent.Edge {
 		edge.To("wa_agent", Whatsapp.Type),
 		edge.To("xjs_agent", XunjiService.Type),
 		edge.To("key_agent", ApiKey.Type),
+		edge.To("xjs_agent", XunjiService.Type),
 	}
 }
 

+ 0 - 1
ent/schema/xunji.go

@@ -21,7 +21,6 @@ func (Xunji) Fields() []ent.Field {
 		field.String("app_secret").Comment("AppSecret"),
 		field.String("token").Comment("Token"),
 		field.String("encoding_key").Comment("加密key"),
-		field.Uint64("agent_id").Comment("角色ID"),
 		field.Uint64("organization_id").Positive().Comment("organization_id | 租户ID"),
 	}
 }

+ 0 - 24
ent/set_not_nil.go

@@ -11192,30 +11192,6 @@ func (x *XunjiCreate) SetNotNilEncodingKey(value *string) *XunjiCreate {
 }
 
 // set field if value's pointer is not nil.
-func (x *XunjiUpdate) SetNotNilAgentID(value *uint64) *XunjiUpdate {
-	if value != nil {
-		return x.SetAgentID(*value)
-	}
-	return x
-}
-
-// set field if value's pointer is not nil.
-func (x *XunjiUpdateOne) SetNotNilAgentID(value *uint64) *XunjiUpdateOne {
-	if value != nil {
-		return x.SetAgentID(*value)
-	}
-	return x
-}
-
-// set field if value's pointer is not nil.
-func (x *XunjiCreate) SetNotNilAgentID(value *uint64) *XunjiCreate {
-	if value != nil {
-		return x.SetAgentID(*value)
-	}
-	return x
-}
-
-// set field if value's pointer is not nil.
 func (x *XunjiUpdate) SetNotNilOrganizationID(value *uint64) *XunjiUpdate {
 	if value != nil {
 		return x.SetOrganizationID(*value)

+ 1 - 12
ent/xunji.go

@@ -33,8 +33,6 @@ type Xunji struct {
 	Token string `json:"token,omitempty"`
 	// 加密key
 	EncodingKey string `json:"encoding_key,omitempty"`
-	// 角色ID
-	AgentID uint64 `json:"agent_id,omitempty"`
 	// organization_id | 租户ID
 	OrganizationID uint64 `json:"organization_id,omitempty"`
 	selectValues   sql.SelectValues
@@ -45,7 +43,7 @@ func (*Xunji) scanValues(columns []string) ([]any, error) {
 	values := make([]any, len(columns))
 	for i := range columns {
 		switch columns[i] {
-		case xunji.FieldID, xunji.FieldStatus, xunji.FieldAgentID, xunji.FieldOrganizationID:
+		case xunji.FieldID, xunji.FieldStatus, xunji.FieldOrganizationID:
 			values[i] = new(sql.NullInt64)
 		case xunji.FieldAppKey, xunji.FieldAppSecret, xunji.FieldToken, xunji.FieldEncodingKey:
 			values[i] = new(sql.NullString)
@@ -120,12 +118,6 @@ func (x *Xunji) assignValues(columns []string, values []any) error {
 			} else if value.Valid {
 				x.EncodingKey = value.String
 			}
-		case xunji.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 {
-				x.AgentID = uint64(value.Int64)
-			}
 		case xunji.FieldOrganizationID:
 			if value, ok := values[i].(*sql.NullInt64); !ok {
 				return fmt.Errorf("unexpected type %T for field organization_id", values[i])
@@ -192,9 +184,6 @@ func (x *Xunji) String() string {
 	builder.WriteString("encoding_key=")
 	builder.WriteString(x.EncodingKey)
 	builder.WriteString(", ")
-	builder.WriteString("agent_id=")
-	builder.WriteString(fmt.Sprintf("%v", x.AgentID))
-	builder.WriteString(", ")
 	builder.WriteString("organization_id=")
 	builder.WriteString(fmt.Sprintf("%v", x.OrganizationID))
 	builder.WriteByte(')')

+ 0 - 45
ent/xunji/where.go

@@ -94,11 +94,6 @@ func EncodingKey(v string) predicate.Xunji {
 	return predicate.Xunji(sql.FieldEQ(FieldEncodingKey, v))
 }
 
-// AgentID applies equality check predicate on the "agent_id" field. It's identical to AgentIDEQ.
-func AgentID(v uint64) predicate.Xunji {
-	return predicate.Xunji(sql.FieldEQ(FieldAgentID, v))
-}
-
 // OrganizationID applies equality check predicate on the "organization_id" field. It's identical to OrganizationIDEQ.
 func OrganizationID(v uint64) predicate.Xunji {
 	return predicate.Xunji(sql.FieldEQ(FieldOrganizationID, v))
@@ -544,46 +539,6 @@ func EncodingKeyContainsFold(v string) predicate.Xunji {
 	return predicate.Xunji(sql.FieldContainsFold(FieldEncodingKey, v))
 }
 
-// AgentIDEQ applies the EQ predicate on the "agent_id" field.
-func AgentIDEQ(v uint64) predicate.Xunji {
-	return predicate.Xunji(sql.FieldEQ(FieldAgentID, v))
-}
-
-// AgentIDNEQ applies the NEQ predicate on the "agent_id" field.
-func AgentIDNEQ(v uint64) predicate.Xunji {
-	return predicate.Xunji(sql.FieldNEQ(FieldAgentID, v))
-}
-
-// AgentIDIn applies the In predicate on the "agent_id" field.
-func AgentIDIn(vs ...uint64) predicate.Xunji {
-	return predicate.Xunji(sql.FieldIn(FieldAgentID, vs...))
-}
-
-// AgentIDNotIn applies the NotIn predicate on the "agent_id" field.
-func AgentIDNotIn(vs ...uint64) predicate.Xunji {
-	return predicate.Xunji(sql.FieldNotIn(FieldAgentID, vs...))
-}
-
-// AgentIDGT applies the GT predicate on the "agent_id" field.
-func AgentIDGT(v uint64) predicate.Xunji {
-	return predicate.Xunji(sql.FieldGT(FieldAgentID, v))
-}
-
-// AgentIDGTE applies the GTE predicate on the "agent_id" field.
-func AgentIDGTE(v uint64) predicate.Xunji {
-	return predicate.Xunji(sql.FieldGTE(FieldAgentID, v))
-}
-
-// AgentIDLT applies the LT predicate on the "agent_id" field.
-func AgentIDLT(v uint64) predicate.Xunji {
-	return predicate.Xunji(sql.FieldLT(FieldAgentID, v))
-}
-
-// AgentIDLTE applies the LTE predicate on the "agent_id" field.
-func AgentIDLTE(v uint64) predicate.Xunji {
-	return predicate.Xunji(sql.FieldLTE(FieldAgentID, v))
-}
-
 // OrganizationIDEQ applies the EQ predicate on the "organization_id" field.
 func OrganizationIDEQ(v uint64) predicate.Xunji {
 	return predicate.Xunji(sql.FieldEQ(FieldOrganizationID, v))

+ 0 - 8
ent/xunji/xunji.go

@@ -30,8 +30,6 @@ const (
 	FieldToken = "token"
 	// FieldEncodingKey holds the string denoting the encoding_key field in the database.
 	FieldEncodingKey = "encoding_key"
-	// FieldAgentID holds the string denoting the agent_id field in the database.
-	FieldAgentID = "agent_id"
 	// FieldOrganizationID holds the string denoting the organization_id field in the database.
 	FieldOrganizationID = "organization_id"
 	// Table holds the table name of the xunji in the database.
@@ -49,7 +47,6 @@ var Columns = []string{
 	FieldAppSecret,
 	FieldToken,
 	FieldEncodingKey,
-	FieldAgentID,
 	FieldOrganizationID,
 }
 
@@ -131,11 +128,6 @@ func ByEncodingKey(opts ...sql.OrderTermOption) OrderOption {
 	return sql.OrderByField(FieldEncodingKey, opts...).ToFunc()
 }
 
-// ByAgentID orders the results by the agent_id field.
-func ByAgentID(opts ...sql.OrderTermOption) OrderOption {
-	return sql.OrderByField(FieldAgentID, opts...).ToFunc()
-}
-
 // ByOrganizationID orders the results by the organization_id field.
 func ByOrganizationID(opts ...sql.OrderTermOption) OrderOption {
 	return sql.OrderByField(FieldOrganizationID, opts...).ToFunc()

+ 0 - 73
ent/xunji_create.go

@@ -102,12 +102,6 @@ func (xc *XunjiCreate) SetEncodingKey(s string) *XunjiCreate {
 	return xc
 }
 
-// SetAgentID sets the "agent_id" field.
-func (xc *XunjiCreate) SetAgentID(u uint64) *XunjiCreate {
-	xc.mutation.SetAgentID(u)
-	return xc
-}
-
 // SetOrganizationID sets the "organization_id" field.
 func (xc *XunjiCreate) SetOrganizationID(u uint64) *XunjiCreate {
 	xc.mutation.SetOrganizationID(u)
@@ -198,9 +192,6 @@ func (xc *XunjiCreate) check() error {
 	if _, ok := xc.mutation.EncodingKey(); !ok {
 		return &ValidationError{Name: "encoding_key", err: errors.New(`ent: missing required field "Xunji.encoding_key"`)}
 	}
-	if _, ok := xc.mutation.AgentID(); !ok {
-		return &ValidationError{Name: "agent_id", err: errors.New(`ent: missing required field "Xunji.agent_id"`)}
-	}
 	if _, ok := xc.mutation.OrganizationID(); !ok {
 		return &ValidationError{Name: "organization_id", err: errors.New(`ent: missing required field "Xunji.organization_id"`)}
 	}
@@ -274,10 +265,6 @@ func (xc *XunjiCreate) createSpec() (*Xunji, *sqlgraph.CreateSpec) {
 		_spec.SetField(xunji.FieldEncodingKey, field.TypeString, value)
 		_node.EncodingKey = value
 	}
-	if value, ok := xc.mutation.AgentID(); ok {
-		_spec.SetField(xunji.FieldAgentID, field.TypeUint64, value)
-		_node.AgentID = value
-	}
 	if value, ok := xc.mutation.OrganizationID(); ok {
 		_spec.SetField(xunji.FieldOrganizationID, field.TypeUint64, value)
 		_node.OrganizationID = value
@@ -436,24 +423,6 @@ func (u *XunjiUpsert) UpdateEncodingKey() *XunjiUpsert {
 	return u
 }
 
-// SetAgentID sets the "agent_id" field.
-func (u *XunjiUpsert) SetAgentID(v uint64) *XunjiUpsert {
-	u.Set(xunji.FieldAgentID, v)
-	return u
-}
-
-// UpdateAgentID sets the "agent_id" field to the value that was provided on create.
-func (u *XunjiUpsert) UpdateAgentID() *XunjiUpsert {
-	u.SetExcluded(xunji.FieldAgentID)
-	return u
-}
-
-// AddAgentID adds v to the "agent_id" field.
-func (u *XunjiUpsert) AddAgentID(v uint64) *XunjiUpsert {
-	u.Add(xunji.FieldAgentID, v)
-	return u
-}
-
 // SetOrganizationID sets the "organization_id" field.
 func (u *XunjiUpsert) SetOrganizationID(v uint64) *XunjiUpsert {
 	u.Set(xunji.FieldOrganizationID, v)
@@ -642,27 +611,6 @@ func (u *XunjiUpsertOne) UpdateEncodingKey() *XunjiUpsertOne {
 	})
 }
 
-// SetAgentID sets the "agent_id" field.
-func (u *XunjiUpsertOne) SetAgentID(v uint64) *XunjiUpsertOne {
-	return u.Update(func(s *XunjiUpsert) {
-		s.SetAgentID(v)
-	})
-}
-
-// AddAgentID adds v to the "agent_id" field.
-func (u *XunjiUpsertOne) AddAgentID(v uint64) *XunjiUpsertOne {
-	return u.Update(func(s *XunjiUpsert) {
-		s.AddAgentID(v)
-	})
-}
-
-// UpdateAgentID sets the "agent_id" field to the value that was provided on create.
-func (u *XunjiUpsertOne) UpdateAgentID() *XunjiUpsertOne {
-	return u.Update(func(s *XunjiUpsert) {
-		s.UpdateAgentID()
-	})
-}
-
 // SetOrganizationID sets the "organization_id" field.
 func (u *XunjiUpsertOne) SetOrganizationID(v uint64) *XunjiUpsertOne {
 	return u.Update(func(s *XunjiUpsert) {
@@ -1020,27 +968,6 @@ func (u *XunjiUpsertBulk) UpdateEncodingKey() *XunjiUpsertBulk {
 	})
 }
 
-// SetAgentID sets the "agent_id" field.
-func (u *XunjiUpsertBulk) SetAgentID(v uint64) *XunjiUpsertBulk {
-	return u.Update(func(s *XunjiUpsert) {
-		s.SetAgentID(v)
-	})
-}
-
-// AddAgentID adds v to the "agent_id" field.
-func (u *XunjiUpsertBulk) AddAgentID(v uint64) *XunjiUpsertBulk {
-	return u.Update(func(s *XunjiUpsert) {
-		s.AddAgentID(v)
-	})
-}
-
-// UpdateAgentID sets the "agent_id" field to the value that was provided on create.
-func (u *XunjiUpsertBulk) UpdateAgentID() *XunjiUpsertBulk {
-	return u.Update(func(s *XunjiUpsert) {
-		s.UpdateAgentID()
-	})
-}
-
 // SetOrganizationID sets the "organization_id" field.
 func (u *XunjiUpsertBulk) SetOrganizationID(v uint64) *XunjiUpsertBulk {
 	return u.Update(func(s *XunjiUpsert) {

+ 0 - 54
ent/xunji_update.go

@@ -137,27 +137,6 @@ func (xu *XunjiUpdate) SetNillableEncodingKey(s *string) *XunjiUpdate {
 	return xu
 }
 
-// SetAgentID sets the "agent_id" field.
-func (xu *XunjiUpdate) SetAgentID(u uint64) *XunjiUpdate {
-	xu.mutation.ResetAgentID()
-	xu.mutation.SetAgentID(u)
-	return xu
-}
-
-// SetNillableAgentID sets the "agent_id" field if the given value is not nil.
-func (xu *XunjiUpdate) SetNillableAgentID(u *uint64) *XunjiUpdate {
-	if u != nil {
-		xu.SetAgentID(*u)
-	}
-	return xu
-}
-
-// AddAgentID adds u to the "agent_id" field.
-func (xu *XunjiUpdate) AddAgentID(u int64) *XunjiUpdate {
-	xu.mutation.AddAgentID(u)
-	return xu
-}
-
 // SetOrganizationID sets the "organization_id" field.
 func (xu *XunjiUpdate) SetOrganizationID(u uint64) *XunjiUpdate {
 	xu.mutation.ResetOrganizationID()
@@ -278,12 +257,6 @@ func (xu *XunjiUpdate) sqlSave(ctx context.Context) (n int, err error) {
 	if value, ok := xu.mutation.EncodingKey(); ok {
 		_spec.SetField(xunji.FieldEncodingKey, field.TypeString, value)
 	}
-	if value, ok := xu.mutation.AgentID(); ok {
-		_spec.SetField(xunji.FieldAgentID, field.TypeUint64, value)
-	}
-	if value, ok := xu.mutation.AddedAgentID(); ok {
-		_spec.AddField(xunji.FieldAgentID, field.TypeUint64, value)
-	}
 	if value, ok := xu.mutation.OrganizationID(); ok {
 		_spec.SetField(xunji.FieldOrganizationID, field.TypeUint64, value)
 	}
@@ -419,27 +392,6 @@ func (xuo *XunjiUpdateOne) SetNillableEncodingKey(s *string) *XunjiUpdateOne {
 	return xuo
 }
 
-// SetAgentID sets the "agent_id" field.
-func (xuo *XunjiUpdateOne) SetAgentID(u uint64) *XunjiUpdateOne {
-	xuo.mutation.ResetAgentID()
-	xuo.mutation.SetAgentID(u)
-	return xuo
-}
-
-// SetNillableAgentID sets the "agent_id" field if the given value is not nil.
-func (xuo *XunjiUpdateOne) SetNillableAgentID(u *uint64) *XunjiUpdateOne {
-	if u != nil {
-		xuo.SetAgentID(*u)
-	}
-	return xuo
-}
-
-// AddAgentID adds u to the "agent_id" field.
-func (xuo *XunjiUpdateOne) AddAgentID(u int64) *XunjiUpdateOne {
-	xuo.mutation.AddAgentID(u)
-	return xuo
-}
-
 // SetOrganizationID sets the "organization_id" field.
 func (xuo *XunjiUpdateOne) SetOrganizationID(u uint64) *XunjiUpdateOne {
 	xuo.mutation.ResetOrganizationID()
@@ -590,12 +542,6 @@ func (xuo *XunjiUpdateOne) sqlSave(ctx context.Context) (_node *Xunji, err error
 	if value, ok := xuo.mutation.EncodingKey(); ok {
 		_spec.SetField(xunji.FieldEncodingKey, field.TypeString, value)
 	}
-	if value, ok := xuo.mutation.AgentID(); ok {
-		_spec.SetField(xunji.FieldAgentID, field.TypeUint64, value)
-	}
-	if value, ok := xuo.mutation.AddedAgentID(); ok {
-		_spec.AddField(xunji.FieldAgentID, field.TypeUint64, value)
-	}
 	if value, ok := xuo.mutation.OrganizationID(); ok {
 		_spec.SetField(xunji.FieldOrganizationID, field.TypeUint64, value)
 	}

+ 4 - 0
go.sum

@@ -472,6 +472,7 @@ github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Ky
 github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
 github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
 github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
+github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
 github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
 github.com/mattn/go-sqlite3 v1.14.6/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
 github.com/mattn/go-sqlite3 v1.14.8/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
@@ -510,6 +511,7 @@ github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLA
 github.com/nxadm/tail v1.4.4 h1:DQuhQpB1tVlglWS2hLQ5OV6B5r8aGxSrPc5Qo6uTN78=
 github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
 github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
+github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
 github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
 github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
 github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=
@@ -611,6 +613,8 @@ github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkU
 github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0=
 github.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
 github.com/spf13/cobra v1.1.3/go.mod h1:pGADOWyqRD/YMrPZigI/zbliZ2wVD/23d+is3pSWzOo=
+github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I=
+github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0=
 github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
 github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
 github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=

+ 73 - 0
internal/handler/routes.go

@@ -2266,4 +2266,77 @@ 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:    "/xunji/create",
+					Handler: xunji.CreateXunjiHandler(serverCtx),
+				},
+				{
+					Method:  http.MethodPost,
+					Path:    "/xunji/update",
+					Handler: xunji.UpdateXunjiHandler(serverCtx),
+				},
+				{
+					Method:  http.MethodPost,
+					Path:    "/xunji/delete",
+					Handler: xunji.DeleteXunjiHandler(serverCtx),
+				},
+				{
+					Method:  http.MethodPost,
+					Path:    "/xunji/list",
+					Handler: xunji.GetXunjiListHandler(serverCtx),
+				},
+				{
+					Method:  http.MethodPost,
+					Path:    "/xunji",
+					Handler: xunji.GetXunjiByIdHandler(serverCtx),
+				},
+				{
+					Method:  http.MethodPost,
+					Path:    "/xunji/detail",
+					Handler: xunji.GetXunjiHandler(serverCtx),
+				},
+			}...,
+		),
+		rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
+	)
+
+	server.AddRoutes(
+		rest.WithMiddlewares(
+			[]rest.Middleware{serverCtx.Authority},
+			[]rest.Route{
+				{
+					Method:  http.MethodPost,
+					Path:    "/xunji_service/create",
+					Handler: xunji_service.CreateXunjiServiceHandler(serverCtx),
+				},
+				{
+					Method:  http.MethodPost,
+					Path:    "/xunji_service/update",
+					Handler: xunji_service.UpdateXunjiServiceHandler(serverCtx),
+				},
+				{
+					Method:  http.MethodPost,
+					Path:    "/xunji_service/delete",
+					Handler: xunji_service.DeleteXunjiServiceHandler(serverCtx),
+				},
+				{
+					Method:  http.MethodPost,
+					Path:    "/xunji_service/list",
+					Handler: xunji_service.GetXunjiServiceListHandler(serverCtx),
+				},
+				{
+					Method:  http.MethodPost,
+					Path:    "/xunji_service",
+					Handler: xunji_service.GetXunjiServiceByIdHandler(serverCtx),
+				},
+			}...,
+		),
+		rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
+	)
 }

+ 31 - 0
internal/handler/xunji/get_xunji_handler.go

@@ -0,0 +1,31 @@
+package xunji
+
+import (
+	"net/http"
+
+	"github.com/zeromicro/go-zero/rest/httpx"
+
+	"wechat-api/internal/logic/xunji"
+	"wechat-api/internal/svc"
+)
+
+// swagger:route post /xunji/detail xunji GetXunji
+//
+// Get xunji  | 通过机构ID获取Xunji
+//
+// Get xunji  | 通过机构ID获取Xunji
+//
+// Responses:
+//  200: XunjiInfoResp
+
+func GetXunjiHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
+	return func(w http.ResponseWriter, r *http.Request) {
+		l := xunji.NewGetXunjiLogic(r.Context(), svcCtx)
+		resp, err := l.GetXunji()
+		if err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+		} else {
+			httpx.OkJsonCtx(r.Context(), w, resp)
+		}
+	}
+}

+ 5 - 8
internal/logic/xunji/create_xunji_logic.go

@@ -2,28 +2,26 @@ package xunji
 
 import (
 	"context"
+	"github.com/suyuan32/simple-admin-common/msg/errormsg"
+	"wechat-api/internal/utils/dberrorhandler"
 
 	"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 CreateXunjiLogic struct {
+	logx.Logger
 	ctx    context.Context
 	svcCtx *svc.ServiceContext
-	logx.Logger
 }
 
 func NewCreateXunjiLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateXunjiLogic {
 	return &CreateXunjiLogic{
-		ctx:    ctx,
-		svcCtx: svcCtx,
 		Logger: logx.WithContext(ctx),
-	}
+		ctx:    ctx,
+		svcCtx: svcCtx}
 }
 
 func (l *CreateXunjiLogic) CreateXunji(req *types.XunjiInfo) (*types.BaseMsgResp, error) {
@@ -35,7 +33,6 @@ func (l *CreateXunjiLogic) CreateXunji(req *types.XunjiInfo) (*types.BaseMsgResp
 		SetNotNilAppSecret(req.AppSecret).
 		SetNotNilToken(req.Token).
 		SetNotNilEncodingKey(req.EncodingKey).
-		SetNotNilAgentID(req.AgentId).
 		SetOrganizationID(organizationId).
 		Save(l.ctx)
 

+ 11 - 12
internal/logic/xunji/delete_xunji_logic.go

@@ -2,36 +2,35 @@ package xunji
 
 import (
 	"context"
+	"github.com/suyuan32/simple-admin-common/msg/errormsg"
+	"wechat-api/ent/xunji"
+	"wechat-api/internal/utils/dberrorhandler"
 
-    "wechat-api/ent/xunji"
-    "wechat-api/internal/svc"
-    "wechat-api/internal/types"
-    "wechat-api/internal/utils/dberrorhandler"
+	"wechat-api/internal/svc"
+	"wechat-api/internal/types"
 
-    "github.com/suyuan32/simple-admin-common/msg/errormsg"
-    "github.com/zeromicro/go-zero/core/logx"
+	"github.com/zeromicro/go-zero/core/logx"
 )
 
 type DeleteXunjiLogic struct {
+	logx.Logger
 	ctx    context.Context
 	svcCtx *svc.ServiceContext
-	logx.Logger
 }
 
 func NewDeleteXunjiLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteXunjiLogic {
 	return &DeleteXunjiLogic{
-		ctx:    ctx,
-		svcCtx: svcCtx,
 		Logger: logx.WithContext(ctx),
-	}
+		ctx:    ctx,
+		svcCtx: svcCtx}
 }
 
 func (l *DeleteXunjiLogic) DeleteXunji(req *types.IDsReq) (*types.BaseMsgResp, error) {
 	_, err := l.svcCtx.DB.Xunji.Delete().Where(xunji.IDIn(req.Ids...)).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
 }

+ 6 - 9
internal/logic/xunji/get_xunji_by_id_logic.go

@@ -2,29 +2,27 @@ package xunji
 
 import (
 	"context"
+	"github.com/suyuan32/simple-admin-common/msg/errormsg"
+	"github.com/suyuan32/simple-admin-common/utils/pointy"
+	"wechat-api/internal/utils/dberrorhandler"
 
 	"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"
 )
 
 type GetXunjiByIdLogic struct {
+	logx.Logger
 	ctx    context.Context
 	svcCtx *svc.ServiceContext
-	logx.Logger
 }
 
 func NewGetXunjiByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetXunjiByIdLogic {
 	return &GetXunjiByIdLogic{
-		ctx:    ctx,
-		svcCtx: svcCtx,
 		Logger: logx.WithContext(ctx),
-	}
+		ctx:    ctx,
+		svcCtx: svcCtx}
 }
 
 func (l *GetXunjiByIdLogic) GetXunjiById(req *types.IDReq) (*types.XunjiInfoResp, error) {
@@ -49,7 +47,6 @@ func (l *GetXunjiByIdLogic) GetXunjiById(req *types.IDReq) (*types.XunjiInfoResp
 			AppSecret:      &data.AppSecret,
 			Token:          &data.Token,
 			EncodingKey:    &data.EncodingKey,
-			AgentId:        &data.AgentID,
 			OrganizationId: &data.OrganizationID,
 		},
 	}, nil

+ 7 - 10
internal/logic/xunji/get_xunji_list_logic.go

@@ -2,31 +2,29 @@ package xunji
 
 import (
 	"context"
-
+	"github.com/suyuan32/simple-admin-common/msg/errormsg"
+	"github.com/suyuan32/simple-admin-common/utils/pointy"
 	"wechat-api/ent/predicate"
 	"wechat-api/ent/xunji"
-	"wechat-api/internal/svc"
-	"wechat-api/internal/types"
 	"wechat-api/internal/utils/dberrorhandler"
 
-	"github.com/suyuan32/simple-admin-common/msg/errormsg"
+	"wechat-api/internal/svc"
+	"wechat-api/internal/types"
 
-	"github.com/suyuan32/simple-admin-common/utils/pointy"
 	"github.com/zeromicro/go-zero/core/logx"
 )
 
 type GetXunjiListLogic struct {
+	logx.Logger
 	ctx    context.Context
 	svcCtx *svc.ServiceContext
-	logx.Logger
 }
 
 func NewGetXunjiListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetXunjiListLogic {
 	return &GetXunjiListLogic{
-		ctx:    ctx,
-		svcCtx: svcCtx,
 		Logger: logx.WithContext(ctx),
-	}
+		ctx:    ctx,
+		svcCtx: svcCtx}
 }
 
 func (l *GetXunjiListLogic) GetXunjiList(req *types.XunjiListReq) (*types.XunjiListResp, error) {
@@ -63,7 +61,6 @@ func (l *GetXunjiListLogic) GetXunjiList(req *types.XunjiListReq) (*types.XunjiL
 				AppSecret:      &v.AppSecret,
 				Token:          &v.Token,
 				EncodingKey:    &v.EncodingKey,
-				AgentId:        &v.AgentID,
 				OrganizationId: &v.OrganizationID,
 			})
 	}

+ 59 - 0
internal/logic/xunji/get_xunji_logic.go

@@ -0,0 +1,59 @@
+package xunji
+
+import (
+	"context"
+	"github.com/suyuan32/simple-admin-common/msg/errormsg"
+	"github.com/suyuan32/simple-admin-common/utils/pointy"
+	"wechat-api/ent"
+	"wechat-api/ent/xunji"
+	"wechat-api/internal/utils/dberrorhandler"
+
+	"wechat-api/internal/svc"
+	"wechat-api/internal/types"
+
+	"github.com/zeromicro/go-zero/core/logx"
+)
+
+type GetXunjiLogic struct {
+	logx.Logger
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+}
+
+func NewGetXunjiLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetXunjiLogic {
+	return &GetXunjiLogic{
+		Logger: logx.WithContext(ctx),
+		ctx:    ctx,
+		svcCtx: svcCtx}
+}
+
+func (l *GetXunjiLogic) GetXunji() (resp *types.XunjiInfoResp, err error) {
+	organizationId := l.ctx.Value("organizationId").(uint64)
+
+	data, err := l.svcCtx.DB.Xunji.Query().Where(
+		xunji.OrganizationID(organizationId),
+	).Order(ent.Desc(xunji.FieldCreatedAt)).First(l.ctx)
+	if err != nil {
+		return nil, dberrorhandler.DefaultEntError(l.Logger, err, nil)
+	}
+
+	return &types.XunjiInfoResp{
+		BaseDataInfo: types.BaseDataInfo{
+			Code: 0,
+			Msg:  errormsg.Success,
+		},
+		Data: types.XunjiInfo{
+			BaseIDInfo: types.BaseIDInfo{
+				Id:        &data.ID,
+				CreatedAt: pointy.GetPointer(data.CreatedAt.UnixMilli()),
+				UpdatedAt: pointy.GetPointer(data.UpdatedAt.UnixMilli()),
+			},
+			Status:         &data.Status,
+			AppKey:         &data.AppKey,
+			AppSecret:      &data.AppSecret,
+			Token:          &data.Token,
+			EncodingKey:    &data.EncodingKey,
+			OrganizationId: &data.OrganizationID,
+		},
+	}, nil
+}

+ 5 - 8
internal/logic/xunji/update_xunji_logic.go

@@ -2,27 +2,26 @@ package xunji
 
 import (
 	"context"
+	"github.com/suyuan32/simple-admin-common/msg/errormsg"
+	"wechat-api/internal/utils/dberrorhandler"
 
 	"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 UpdateXunjiLogic struct {
+	logx.Logger
 	ctx    context.Context
 	svcCtx *svc.ServiceContext
-	logx.Logger
 }
 
 func NewUpdateXunjiLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateXunjiLogic {
 	return &UpdateXunjiLogic{
-		ctx:    ctx,
-		svcCtx: svcCtx,
 		Logger: logx.WithContext(ctx),
-	}
+		ctx:    ctx,
+		svcCtx: svcCtx}
 }
 
 func (l *UpdateXunjiLogic) UpdateXunji(req *types.XunjiInfo) (*types.BaseMsgResp, error) {
@@ -32,8 +31,6 @@ func (l *UpdateXunjiLogic) UpdateXunji(req *types.XunjiInfo) (*types.BaseMsgResp
 		SetNotNilAppSecret(req.AppSecret).
 		SetNotNilToken(req.Token).
 		SetNotNilEncodingKey(req.EncodingKey).
-		SetNotNilAgentID(req.AgentId).
-		SetNotNilOrganizationID(req.OrganizationId).
 		Exec(l.ctx)
 
 	if err != nil {

+ 17 - 19
internal/logic/xunji_service/create_xunji_service_logic.go

@@ -2,44 +2,42 @@ package xunji_service
 
 import (
 	"context"
+	"github.com/suyuan32/simple-admin-common/msg/errormsg"
+	"wechat-api/internal/utils/dberrorhandler"
 
 	"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 CreateXunjiServiceLogic struct {
+	logx.Logger
 	ctx    context.Context
 	svcCtx *svc.ServiceContext
-	logx.Logger
 }
 
 func NewCreateXunjiServiceLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateXunjiServiceLogic {
 	return &CreateXunjiServiceLogic{
-		ctx:    ctx,
-		svcCtx: svcCtx,
 		Logger: logx.WithContext(ctx),
-	}
+		ctx:    ctx,
+		svcCtx: svcCtx}
 }
 
 func (l *CreateXunjiServiceLogic) CreateXunjiService(req *types.XunjiServiceInfo) (*types.BaseMsgResp, error) {
-    _, err := l.svcCtx.DB.XunjiService.Create().
-			SetNotNilStatus(req.Status).
-			SetNotNilXunjiID(req.XunjiId).
-			SetNotNilAgentID(req.AgentId).
-			SetNotNilOrganizationID(req.OrganizationId).
-			SetNotNilWxid(req.Wxid).
-			SetNotNilAPIBase(req.ApiBase).
-			SetNotNilAPIKey(req.ApiKey).
-			Save(l.ctx)
-
-    if err != nil {
+	_, err := l.svcCtx.DB.XunjiService.Create().
+		SetNotNilStatus(req.Status).
+		SetNotNilXunjiID(req.XunjiId).
+		SetNotNilAgentID(req.AgentId).
+		SetNotNilOrganizationID(req.OrganizationId).
+		SetNotNilWxid(req.Wxid).
+		SetNotNilAPIBase(req.ApiBase).
+		SetNotNilAPIKey(req.ApiKey).
+		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
 }

+ 11 - 12
internal/logic/xunji_service/delete_xunji_service_logic.go

@@ -2,36 +2,35 @@ package xunji_service
 
 import (
 	"context"
+	"github.com/suyuan32/simple-admin-common/msg/errormsg"
+	"wechat-api/ent/xunjiservice"
+	"wechat-api/internal/utils/dberrorhandler"
 
-    "wechat-api/ent/xunjiservice"
-    "wechat-api/internal/svc"
-    "wechat-api/internal/types"
-    "wechat-api/internal/utils/dberrorhandler"
+	"wechat-api/internal/svc"
+	"wechat-api/internal/types"
 
-    "github.com/suyuan32/simple-admin-common/msg/errormsg"
-    "github.com/zeromicro/go-zero/core/logx"
+	"github.com/zeromicro/go-zero/core/logx"
 )
 
 type DeleteXunjiServiceLogic struct {
+	logx.Logger
 	ctx    context.Context
 	svcCtx *svc.ServiceContext
-	logx.Logger
 }
 
 func NewDeleteXunjiServiceLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteXunjiServiceLogic {
 	return &DeleteXunjiServiceLogic{
-		ctx:    ctx,
-		svcCtx: svcCtx,
 		Logger: logx.WithContext(ctx),
-	}
+		ctx:    ctx,
+		svcCtx: svcCtx}
 }
 
 func (l *DeleteXunjiServiceLogic) DeleteXunjiService(req *types.IDsReq) (*types.BaseMsgResp, error) {
 	_, err := l.svcCtx.DB.XunjiService.Delete().Where(xunjiservice.IDIn(req.Ids...)).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
 }

+ 6 - 8
internal/logic/xunji_service/get_xunji_service_by_id_logic.go

@@ -2,30 +2,28 @@ package xunji_service
 
 import (
 	"context"
+	"github.com/suyuan32/simple-admin-common/msg/errormsg"
+	"github.com/suyuan32/simple-admin-common/utils/pointy"
 	"wechat-api/ent/xunjiservice"
+	"wechat-api/internal/utils/dberrorhandler"
 
 	"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"
 )
 
 type GetXunjiServiceByIdLogic struct {
+	logx.Logger
 	ctx    context.Context
 	svcCtx *svc.ServiceContext
-	logx.Logger
 }
 
 func NewGetXunjiServiceByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetXunjiServiceByIdLogic {
 	return &GetXunjiServiceByIdLogic{
-		ctx:    ctx,
-		svcCtx: svcCtx,
 		Logger: logx.WithContext(ctx),
-	}
+		ctx:    ctx,
+		svcCtx: svcCtx}
 }
 
 func (l *GetXunjiServiceByIdLogic) GetXunjiServiceById(req *types.IDReq) (*types.XunjiServiceInfoResp, error) {

+ 7 - 9
internal/logic/xunji_service/get_xunji_service_list_logic.go

@@ -2,32 +2,30 @@ package xunji_service
 
 import (
 	"context"
+	"github.com/suyuan32/simple-admin-common/msg/errormsg"
+	"github.com/suyuan32/simple-admin-common/utils/pointy"
 	"github.com/zeromicro/go-zero/core/errorx"
-
 	"wechat-api/ent/predicate"
 	"wechat-api/ent/xunjiservice"
-	"wechat-api/internal/svc"
-	"wechat-api/internal/types"
 	"wechat-api/internal/utils/dberrorhandler"
 
-	"github.com/suyuan32/simple-admin-common/msg/errormsg"
+	"wechat-api/internal/svc"
+	"wechat-api/internal/types"
 
-	"github.com/suyuan32/simple-admin-common/utils/pointy"
 	"github.com/zeromicro/go-zero/core/logx"
 )
 
 type GetXunjiServiceListLogic struct {
+	logx.Logger
 	ctx    context.Context
 	svcCtx *svc.ServiceContext
-	logx.Logger
 }
 
 func NewGetXunjiServiceListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetXunjiServiceListLogic {
 	return &GetXunjiServiceListLogic{
-		ctx:    ctx,
-		svcCtx: svcCtx,
 		Logger: logx.WithContext(ctx),
-	}
+		ctx:    ctx,
+		svcCtx: svcCtx}
 }
 
 func (l *GetXunjiServiceListLogic) GetXunjiServiceList(req *types.XunjiServiceListReq) (*types.XunjiServiceListResp, error) {

+ 16 - 19
internal/logic/xunji_service/update_xunji_service_logic.go

@@ -2,44 +2,41 @@ package xunji_service
 
 import (
 	"context"
+	"github.com/suyuan32/simple-admin-common/msg/errormsg"
+	"wechat-api/internal/utils/dberrorhandler"
 
 	"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 UpdateXunjiServiceLogic struct {
+	logx.Logger
 	ctx    context.Context
 	svcCtx *svc.ServiceContext
-	logx.Logger
 }
 
 func NewUpdateXunjiServiceLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateXunjiServiceLogic {
 	return &UpdateXunjiServiceLogic{
-		ctx:    ctx,
-		svcCtx: svcCtx,
 		Logger: logx.WithContext(ctx),
-	}
+		ctx:    ctx,
+		svcCtx: svcCtx}
 }
 
 func (l *UpdateXunjiServiceLogic) UpdateXunjiService(req *types.XunjiServiceInfo) (*types.BaseMsgResp, error) {
-    err := l.svcCtx.DB.XunjiService.UpdateOneID(*req.Id).
-			SetNotNilStatus(req.Status).
-			SetNotNilXunjiID(req.XunjiId).
-			SetNotNilAgentID(req.AgentId).
-			SetNotNilOrganizationID(req.OrganizationId).
-			SetNotNilWxid(req.Wxid).
-			SetNotNilAPIBase(req.ApiBase).
-			SetNotNilAPIKey(req.ApiKey).
-			Exec(l.ctx)
-
-    if err != nil {
+	err := l.svcCtx.DB.XunjiService.UpdateOneID(*req.Id).
+		SetNotNilStatus(req.Status).
+		SetNotNilXunjiID(req.XunjiId).
+		SetNotNilAgentID(req.AgentId).
+		SetNotNilWxid(req.Wxid).
+		SetNotNilAPIBase(req.ApiBase).
+		SetNotNilAPIKey(req.ApiKey).
+		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
 }

+ 107 - 0
internal/types/types.go

@@ -4498,3 +4498,110 @@ type ApiKeyListReq struct {
 	Key            *string `json:"key,optional"`
 	OrganizationId *uint64 `json:"organization_id,optional"`
 }
+
+// The data of xunji information | Xunji信息
+// swagger:model XunjiInfo
+type XunjiInfo struct {
+	BaseIDInfo
+	// Status 1: normal 2: ban | 状态 1 正常 2 禁用
+	Status *uint8 `json:"status,optional"`
+	// AppKey
+	AppKey *string `json:"appKey,optional"`
+	// AppSecret
+	AppSecret *string `json:"appSecret,optional"`
+	// Token
+	Token *string `json:"token,optional"`
+	// 加密key
+	EncodingKey *string `json:"encodingKey,optional"`
+	// organization_id | 租户ID
+	OrganizationId *uint64 `json:"organizationId,optional"`
+}
+
+// The response data of xunji list | Xunji列表数据
+// swagger:model XunjiListResp
+type XunjiListResp struct {
+	BaseDataInfo
+	// Xunji list data | Xunji列表数据
+	Data XunjiListInfo `json:"data"`
+}
+
+// Xunji list data | Xunji列表数据
+// swagger:model XunjiListInfo
+type XunjiListInfo struct {
+	BaseListInfo
+	// The API list data | Xunji列表数据
+	Data []XunjiInfo `json:"data"`
+}
+
+// Get xunji list request params | Xunji列表请求参数
+// swagger:model XunjiListReq
+type XunjiListReq struct {
+	PageInfo
+	// AppKey
+	AppKey *string `json:"appKey,optional"`
+	// AppSecret
+	AppSecret *string `json:"appSecret,optional"`
+	// Token
+	Token *string `json:"token,optional"`
+}
+
+// Xunji information response | Xunji信息返回体
+// swagger:model XunjiInfoResp
+type XunjiInfoResp struct {
+	BaseDataInfo
+	// Xunji information | Xunji数据
+	Data XunjiInfo `json:"data"`
+}
+
+// The data of xunji service information | XunjiService信息
+// swagger:model XunjiServiceInfo
+type XunjiServiceInfo struct {
+	BaseIDInfo
+	// Status 1: normal 2: ban | 状态 1 正常 2 禁用
+	Status *uint8 `json:"status,optional"`
+	// Xunji表ID
+	XunjiId *uint64 `json:"xunjiId,optional"`
+	// 智能体ID
+	AgentId *uint64 `json:"agentId,optional"`
+	// 模式信息
+	AgentInfo *AgentInfo `json:"agentInfo,optional"`
+	// organization_id | 租户ID
+	OrganizationId *uint64 `json:"organizationId,optional"`
+	// 微信ID
+	Wxid *string `json:"wxid,optional"`
+	// 大模型服务地址
+	ApiBase *string `json:"apiBase,optional"`
+	// 大模型服务密钥
+	ApiKey *string `json:"apiKey,optional"`
+}
+
+// The response data of xunji service list | XunjiService列表数据
+// swagger:model XunjiServiceListResp
+type XunjiServiceListResp struct {
+	BaseDataInfo
+	// XunjiService list data | XunjiService列表数据
+	Data XunjiServiceListInfo `json:"data"`
+}
+
+// XunjiService list data | XunjiService列表数据
+// swagger:model XunjiServiceListInfo
+type XunjiServiceListInfo struct {
+	BaseListInfo
+	// The API list data | XunjiService列表数据
+	Data []XunjiServiceInfo `json:"data"`
+}
+
+// Get xunji service list request params | XunjiService列表请求参数
+// swagger:model XunjiServiceListReq
+type XunjiServiceListReq struct {
+	PageInfo
+	XunjiID *uint64 `json:"configId,optional"`
+}
+
+// XunjiService information response | XunjiService信息返回体
+// swagger:model XunjiServiceInfoResp
+type XunjiServiceInfoResp struct {
+	BaseDataInfo
+	// XunjiService information | XunjiService数据
+	Data XunjiServiceInfo `json:"data"`
+}

+ 2 - 0
internal/utils/compapi/config.go

@@ -20,4 +20,6 @@ var fastgptWorkIdMap = map[string]workIdInfo{
 	"default":              {"fastgpt-jcDATa9aH4vtUsjDpCU773BxmLU50IxKUX9nUT0mCTLQkEoo1hPxPEdNQeOEWGTn", 0},
 	"OPTIMIZE_CALL_SCRIPT": {"fastgpt-bcQ9cWKd6y9a2LfizweeWEnukkQi1Oq46yoiRg9yDNLm8NPTWXsyFwcB", 1},
 	"TEST_DOUYIN":          {"fastgpt-bwt6oSGcjwJ1qBgT276oeFD34IAhfjEQBCZWJfJR1oj3WqJl7751ljSrc", 2},
+	"GENERALIZED_KEYWORDS": {"fastgpt-yefNCWpNtzY2Qn0xtJvKuvepOP9DR7BiXQwv5BiVP5JseP2IS92gE", 3},
+	"TEST_DOUYIN_CN":       {"fastgpt-jsMmQKEM5uX7tDimT1zHlZHkBhMHRT2k61YaxyDJRZTUHehID7sG8BKXADNIU", 4},
 }