2023-10-20 07:14:48 +00:00
|
|
|
package logic
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fusenapi/utils/auth"
|
|
|
|
"fusenapi/utils/basic"
|
2023-11-01 06:48:50 +00:00
|
|
|
"strings"
|
2023-10-31 06:47:56 +00:00
|
|
|
"sync"
|
2023-10-20 07:14:48 +00:00
|
|
|
|
|
|
|
"fusenapi/server/websocket/internal/svc"
|
|
|
|
"fusenapi/server/websocket/internal/types"
|
|
|
|
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
|
|
)
|
|
|
|
|
|
|
|
type GetStatLogic struct {
|
|
|
|
logx.Logger
|
|
|
|
ctx context.Context
|
|
|
|
svcCtx *svc.ServiceContext
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewGetStatLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetStatLogic {
|
|
|
|
return &GetStatLogic{
|
|
|
|
Logger: logx.WithContext(ctx),
|
|
|
|
ctx: ctx,
|
|
|
|
svcCtx: svcCtx,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 处理进入前逻辑w,r
|
|
|
|
// func (l *GetStatLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
|
|
|
|
// }
|
2023-10-31 06:47:56 +00:00
|
|
|
var GetStatMutex sync.Mutex
|
2023-10-20 07:14:48 +00:00
|
|
|
|
|
|
|
func (l *GetStatLogic) GetStat(req *types.GetStatReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
|
|
|
if req.Password != "fusen1314" {
|
|
|
|
return resp.SetStatusWithMessage(basic.CodeOK, "你干嘛,哎哟")
|
|
|
|
}
|
2023-10-31 06:47:56 +00:00
|
|
|
GetStatMutex.Lock()
|
|
|
|
defer GetStatMutex.Unlock()
|
2023-10-31 07:03:15 +00:00
|
|
|
userStat := make(map[string]interface{})
|
2023-11-01 06:48:50 +00:00
|
|
|
req.UserKeys = strings.Trim(req.UserKeys, " ")
|
|
|
|
if req.UserKeys != "" { //指定用户群体
|
|
|
|
reqUserList := strings.Split(req.UserKeys, ",")
|
|
|
|
for _, key := range reqUserList {
|
2023-11-01 06:35:37 +00:00
|
|
|
value, ok := mapUserWsStat.Load(key)
|
|
|
|
if ok { //存在就累加
|
2023-11-01 06:56:36 +00:00
|
|
|
userStat[key] = value
|
|
|
|
} else {
|
|
|
|
userStat[key] = mapUserWsStatItem{}
|
2023-11-01 06:35:37 +00:00
|
|
|
}
|
2023-10-31 07:03:15 +00:00
|
|
|
}
|
2023-11-01 06:48:50 +00:00
|
|
|
} else { //不指定用户
|
2023-11-03 06:05:17 +00:00
|
|
|
i := 0
|
2023-11-01 06:48:50 +00:00
|
|
|
mapUserWsStat.Range(func(key, value any) bool {
|
2023-11-03 06:05:17 +00:00
|
|
|
//不指定最多获取1000个用户
|
|
|
|
if i > 1000 {
|
|
|
|
return false
|
|
|
|
}
|
2023-11-01 06:48:50 +00:00
|
|
|
userStat[key.(string)] = value
|
2023-11-03 06:05:17 +00:00
|
|
|
i++
|
2023-11-01 06:48:50 +00:00
|
|
|
return true
|
|
|
|
})
|
2023-11-01 06:35:37 +00:00
|
|
|
}
|
2023-10-20 07:14:48 +00:00
|
|
|
return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetStatRsp{
|
2023-11-01 07:09:53 +00:00
|
|
|
WsTotalCount: curWsTotalCount,
|
|
|
|
CurCombineCount: curCombineTotalCount,
|
|
|
|
CurUnityHandleCount: curUnityHandleTotalCount,
|
|
|
|
CombineErrorCount: combineErrTotalCount,
|
2023-11-01 07:43:25 +00:00
|
|
|
UnityErrorCount: unityErrTotalCount,
|
2023-11-01 03:22:29 +00:00
|
|
|
UserWsStat: userStat,
|
2023-10-20 07:14:48 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
|
|
|
|
// func (l *GetStatLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
|
|
|
|
// // httpx.OkJsonCtx(r.Context(), w, resp)
|
|
|
|
// }
|