104 lines
2.9 KiB
Go
104 lines
2.9 KiB
Go
package smdl
|
|
|
|
import (
|
|
"admin/apps/game/domain/entity"
|
|
"admin/apps/game/domain/projects/smdl/internal"
|
|
"admin/apps/game/model"
|
|
"admin/internal/errcode"
|
|
dto2 "admin/internal/model/dto"
|
|
"admin/lib/httpclient"
|
|
"admin/lib/utils"
|
|
"net/url"
|
|
"sort"
|
|
"strconv"
|
|
)
|
|
|
|
type Role struct {
|
|
RoleId string `json:"roleId"`
|
|
Account string `json:"account"`
|
|
ServerConfId string `json:"serverId"`
|
|
Name string `json:"roleName"`
|
|
Status string `json:"status"`
|
|
Level int `json:"roleLevel"`
|
|
Profession string `json:"profession"`
|
|
LatestLoginTime int64 `json:"latestLoginAt"`
|
|
CreateTime int64 `json:"createAt"`
|
|
}
|
|
|
|
type RoleHook struct {
|
|
}
|
|
|
|
func (hook *RoleHook) List(projectInfo *entity.Project, resource string, params *dto2.CommonListReq,
|
|
fields []*dto2.CommonDtoFieldDesc, totalCount int, rows []dto2.CommonDtoValues) (
|
|
int, []*dto2.CommonDtoFieldDesc, []dto2.CommonDtoValues, error) {
|
|
alisrvAddr := projectInfo.GetApiAddr()
|
|
if alisrvAddr == "" {
|
|
return 0, nil, nil, errcode.New(errcode.ServerError, "项目%v没有配置api服务器地址", projectInfo.Po.Name)
|
|
}
|
|
|
|
serverList, err := getAllRunningServers(projectInfo)
|
|
if err != nil {
|
|
return 0, nil, nil, err
|
|
}
|
|
|
|
totalCount, reqPageServerList, err := getPaginationServerReqList(projectInfo, serverList, params, func(info *internal.ServerInfo) int { return info.TotalRoleCount })
|
|
if err != nil {
|
|
return 0, nil, nil, err
|
|
}
|
|
|
|
type RspData struct {
|
|
State struct {
|
|
Code int `json:"code"`
|
|
Msg string `json:"msg"`
|
|
} `json:"state"`
|
|
Data []*Role `json:"data"`
|
|
}
|
|
|
|
body := &url.Values{}
|
|
|
|
for _, cond := range params.ParsedWhereConditions.Conditions {
|
|
if cond.Key == "Account" {
|
|
// 按账号查询
|
|
body.Set("userId", cond.Value1.(string))
|
|
} else if cond.Key == "RoleId" {
|
|
body.Set("roleId", cond.Value1.(string))
|
|
} else if cond.Key == "Name" {
|
|
body.Set("name", cond.Value1.(string))
|
|
}
|
|
}
|
|
|
|
for _, reqServer := range reqPageServerList {
|
|
body.Set("serverid", reqServer.RawInfo.ServerId)
|
|
body.Set("offset", strconv.Itoa(reqServer.Offset))
|
|
body.Set("count", strconv.Itoa(reqServer.Count))
|
|
|
|
rsp := &RspData{}
|
|
err := httpclient.Request(alisrvAddr+"/rolelist", "get", body, rsp)
|
|
if err != nil {
|
|
return 0, nil, nil, err
|
|
}
|
|
|
|
for _, role := range rsp.Data {
|
|
rolePo := &model.Role{
|
|
RoleId: role.RoleId,
|
|
Account: role.Account,
|
|
ServerConfId: role.ServerConfId,
|
|
Name: role.Name,
|
|
Status: role.Status,
|
|
Level: role.Level,
|
|
Profession: role.Profession,
|
|
LatestLoginTime: utils.ParseUnixTimestamp2LocalTime(role.LatestLoginTime),
|
|
CreatedAt: utils.ParseUnixTimestamp2LocalTime(role.CreateTime),
|
|
}
|
|
et := (&entity.CommonResource{}).FromPo(rolePo)
|
|
rows = append(rows, et.ToCommonDto())
|
|
}
|
|
}
|
|
|
|
sort.SliceStable(rows, func(i, j int) bool {
|
|
return rows[i]["Status"].(string) < rows[j]["Status"].(string)
|
|
})
|
|
|
|
return totalCount, fields, rows, nil
|
|
}
|