Browse Source

fix:edit token/api/list

jimmyyem 4 months ago
parent
commit
857251a49a
1 changed files with 40 additions and 10 deletions
  1. 40 10
      internal/logic/token/get_api_token_list_logic.go

+ 40 - 10
internal/logic/token/get_api_token_list_logic.go

@@ -4,6 +4,7 @@ import (
 	"context"
 	"github.com/suyuan32/simple-admin-common/msg/errormsg"
 	"github.com/suyuan32/simple-admin-common/utils/pointy"
+	"github.com/suyuan32/simple-admin-core/rpc/types/core"
 	"wechat-api/ent/predicate"
 	"wechat-api/ent/token"
 	"wechat-api/internal/utils/dberrorhandler"
@@ -44,6 +45,33 @@ func (l *GetApiTokenListLogic) GetApiTokenList(req *types.TokenListReq) (*types.
 	resp.Data.Total = data.PageDetails.Total
 
 	for _, v := range data.List {
+		departmentInfo, err := l.svcCtx.CoreRpc.GetDepartmentById(l.ctx, &core.IDReq{Id: v.OrganizationID})
+		if err != nil {
+			l.Error("获取部门信息失败", err)
+		}
+		var agent types.AgentInfo
+		if v.AgentID == 0 {
+			agentName := "定制 AI 角色"
+			agent = types.AgentInfo{
+				Name: &agentName,
+			}
+		} else {
+			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,
+				}
+			}
+		}
+
 		expireAtStr := v.ExpireAt.Format("2006-01-02 15:04:05")
 		resp.Data.Data = append(resp.Data.Data,
 			types.TokenInfo{
@@ -52,16 +80,18 @@ func (l *GetApiTokenListLogic) GetApiTokenList(req *types.TokenListReq) (*types.
 					CreatedAt: pointy.GetPointer(v.CreatedAt.UnixMilli()),
 					UpdatedAt: pointy.GetPointer(v.UpdatedAt.UnixMilli()),
 				},
-				ExpireAt:        pointy.GetUnixMilliPointer(v.ExpireAt.UnixMilli()),
-				ExpireAtStr:     &expireAtStr,
-				Token:           &v.Token,
-				Mac:             &v.MAC,
-				OrganizationId:  &v.OrganizationID,
-				AgentId:         &v.AgentID,
-				CustomAgentBase: &v.CustomAgentBase,
-				CustomAgentKey:  &v.CustomAgentKey,
-				OpenaiBase:      &v.OpenaiBase,
-				OpenaiKey:       &v.OpenaiKey,
+				ExpireAt:         pointy.GetUnixMilliPointer(v.ExpireAt.UnixMilli()),
+				ExpireAtStr:      &expireAtStr,
+				Token:            &v.Token,
+				Mac:              &v.MAC,
+				OrganizationId:   &v.OrganizationID,
+				OrganizationName: departmentInfo.Name,
+				AgentId:          &v.AgentID,
+				AgentInfo:        &agent,
+				CustomAgentBase:  &v.CustomAgentBase,
+				CustomAgentKey:   &v.CustomAgentKey,
+				OpenaiBase:       &v.OpenaiBase,
+				OpenaiKey:        &v.OpenaiKey,
 			})
 	}