Quellcode durchsuchen

优化账号列表接口

boweniac vor 8 Monaten
Ursprung
Commit
5020f67418
3 geänderte Dateien mit 51 neuen und 32 gelöschten Zeilen
  1. 12 0
      desc/wechat/wx.api
  2. 31 32
      internal/logic/Wx/get_wx_list_logic.go
  3. 8 0
      internal/types/types.go

+ 12 - 0
desc/wechat/wx.api

@@ -12,6 +12,9 @@ type (
         // 服务器id 
         ServerId  *uint64 `json:"serverId,optional"`
 
+        // 服务器名称
+        ServerName  *string `json:"serverName,optional"`
+
         // 端口号 
         Port  *string `json:"port,optional"`
 
@@ -39,6 +42,9 @@ type (
         // 组织ID
         OrganizationId *uint64 `json:"organizationId,optional"`
 
+        // 组织名称
+        OrganizationName *string `json:"organizationName,optional"`
+
 		// 模式ID
 		AgentId *uint64 `json:"agentId,optional"`
 
@@ -66,6 +72,12 @@ type (
     WxListReq {
         PageInfo
 
+        // 服务器id
+        ServerId  *uint64 `json:"serverId,optional"`
+
+        // 租户id
+        OrganizationId  *uint64 `json:"organizationId,optional"`
+
         // 端口号 
         Port  *string `json:"port,optional"`
 

+ 31 - 32
internal/logic/Wx/get_wx_list_logic.go

@@ -2,7 +2,7 @@ package Wx
 
 import (
 	"context"
-	"fmt"
+	"github.com/suyuan32/simple-admin-core/rpc/types/core"
 	"math/rand"
 	"strconv"
 	"time"
@@ -46,6 +46,13 @@ func (l *GetWxListLogic) GetWxList(req *types.WxListReq) (*types.WxListResp, err
 	var predicates []predicate.Wx
 	if !isAdmin {
 		predicates = append(predicates, wx.OrganizationIDEQ(organizationId))
+	} else {
+		if req.OrganizationId != nil {
+			predicates = append(predicates, wx.OrganizationIDEQ(*req.OrganizationId))
+		}
+	}
+	if req.ServerId != nil {
+		predicates = append(predicates, wx.ServerIDEQ(*req.ServerId))
 	}
 	if req.Port != nil {
 		predicates = append(predicates, wx.PortContains(*req.Port))
@@ -56,7 +63,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...).WithAgent().Page(l.ctx, req.Page, req.PageSize)
+	data, err := l.svcCtx.DB.Wx.Query().Where(predicates...).Order(ent.Desc(wx.FieldOrganizationID)).WithAgent().WithServer().Page(l.ctx, req.Page, req.PageSize)
 
 	if err != nil {
 		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
@@ -70,6 +77,7 @@ func (l *GetWxListLogic) GetWxList(req *types.WxListReq) (*types.WxListResp, err
 		// 创建 hookClient 客户端
 		serverInfo := serverSet[v.ServerID]
 		hookClient := hook.NewHook(serverInfo.PrivateIP, serverInfo.AdminPort, v.Port)
+
 		// 获取登录状态
 		loginInfo, err := hookClient.IsLoginStatus()
 		var loginStatus uint8 = 0
@@ -88,11 +96,16 @@ func (l *GetWxListLogic) GetWxList(req *types.WxListReq) (*types.WxListResp, err
 		tel := v.Tel
 		headBig := v.HeadBig
 
+		departmentInfo, err := l.svcCtx.CoreRpc.GetDepartmentById(l.ctx, &core.IDReq{Id: v.OrganizationID})
+		if err != nil {
+			l.Error("获取部门信息失败", err)
+		}
+
 		if loginStatus == 1 {
 			// 如果处于登录状态,获取登录信息
 			wxInfo, _ := hookClient.GetSelfLoginInfo()
 			if err != nil {
-				l.Error("退出登录失败", err)
+				l.Error("获取登录信息失败", err)
 			} else {
 				processID = wxInfo.ProcessID
 				wxid = wxInfo.Wxid
@@ -135,19 +148,6 @@ func (l *GetWxListLogic) GetWxList(req *types.WxListReq) (*types.WxListResp, err
 				Examples:   &v.Edges.Agent.Examples,
 			}
 		}
-		fmt.Printf("---------------------v.ID-------------------: %v\n", v.ID)
-		fmt.Printf("---------------------v.ServerID-------------------: %v\n", v.ServerID)
-		fmt.Printf("---------------------v.Port-------------------: %v\n", v.Port)
-		fmt.Printf("---------------------processID-------------------: %v\n", processID)
-		fmt.Printf("---------------------v.Callback-------------------: %v\n", v.Callback)
-		fmt.Printf("---------------------wxid-------------------: %v\n", wxid)
-		fmt.Printf("---------------------account-------------------: %v\n", account)
-		fmt.Printf("---------------------nickname-------------------: %v\n", nickname)
-		fmt.Printf("---------------------tel-------------------: %v\n", tel)
-		fmt.Printf("---------------------headBig-------------------: %v\n", headBig)
-		fmt.Printf("---------------------v.OrganizationID-------------------: %v\n", v.OrganizationID)
-		fmt.Printf("---------------------v.AgentID-------------------: %v\n", v.AgentID)
-		fmt.Printf("---------------------agent-------------------: %v\n", agent)
 		resp.Data.Data = append(resp.Data.Data,
 			types.WxInfo{
 				BaseIDInfo: types.BaseIDInfo{
@@ -155,23 +155,22 @@ func (l *GetWxListLogic) GetWxList(req *types.WxListReq) (*types.WxListResp, err
 					CreatedAt: pointy.GetPointer(v.CreatedAt.UnixMilli()),
 					UpdatedAt: pointy.GetPointer(v.UpdatedAt.UnixMilli()),
 				},
-				Status:         &loginStatus,
-				ServerId:       &v.ServerID,
-				Port:           &v.Port,
-				ProcessId:      &processID,
-				Callback:       &v.Callback,
-				Wxid:           &wxid,
-				Account:        &account,
-				Nickname:       &nickname,
-				Tel:            &tel,
-				HeadBig:        &headBig,
-				OrganizationId: &v.OrganizationID,
-				AgentId:        &v.AgentID,
-				AgentInfo:      &agent,
+				Status:           &loginStatus,
+				ServerId:         &v.ServerID,
+				ServerName:       &serverInfo.Name,
+				Port:             &v.Port,
+				ProcessId:        &processID,
+				Callback:         &v.Callback,
+				Wxid:             &wxid,
+				Account:          &account,
+				Nickname:         &nickname,
+				Tel:              &tel,
+				HeadBig:          &headBig,
+				OrganizationId:   &v.OrganizationID,
+				OrganizationName: departmentInfo.Name,
+				AgentId:          &v.AgentID,
+				AgentInfo:        &agent,
 			})
-		fmt.Printf("---------------------v.Port-------------------: %v\n", v.Port)
-		fmt.Printf("---------------------loginInfo.Onlinestatus-------------------: %v\n", loginInfo.Onlinestatus)
-		fmt.Printf("---------------------loginStatus-------------------: %v\n", loginStatus)
 	}
 
 	return resp, nil

+ 8 - 0
internal/types/types.go

@@ -295,6 +295,8 @@ type WxInfo struct {
 	Status *uint8 `json:"status,optional"`
 	// 服务器id
 	ServerId *uint64 `json:"serverId,optional"`
+	// 服务器名称
+	ServerName *string `json:"serverName,optional"`
 	// 端口号
 	Port *string `json:"port,optional"`
 	// 进程号
@@ -313,6 +315,8 @@ type WxInfo struct {
 	HeadBig *string `json:"headBig,optional"`
 	// 组织ID
 	OrganizationId *uint64 `json:"organizationId,optional"`
+	// 组织名称
+	OrganizationName *string `json:"organizationName,optional"`
 	// 模式ID
 	AgentId *uint64 `json:"agentId,optional"`
 	// 模式信息
@@ -339,6 +343,10 @@ type WxListInfo struct {
 // swagger:model WxListReq
 type WxListReq struct {
 	PageInfo
+	// 服务器id
+	ServerId *uint64 `json:"serverId,optional"`
+	// 租户id
+	OrganizationId *uint64 `json:"organizationId,optional"`
 	// 端口号
 	Port *string `json:"port,optional"`
 	// 进程号