66 lines
1.9 KiB
Go
66 lines
1.9 KiB
Go
package smdl
|
|
|
|
import (
|
|
"admin/apps/game/domain/entity"
|
|
"admin/apps/game/model"
|
|
"admin/apps/game/model/dto"
|
|
"admin/internal/errcode"
|
|
"admin/lib/httpclient"
|
|
"admin/lib/utils"
|
|
)
|
|
|
|
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, pageNo, pageLen int, fields []*dto.CommonDtoFieldDesc, rows []dto.CommonDtoValues, extraQuery string, args ...any) (
|
|
[]*dto.CommonDtoFieldDesc, []dto.CommonDtoValues, error) {
|
|
alisrvAddr := projectInfo.GetApiAddr()
|
|
if alisrvAddr == "" {
|
|
return nil, nil, errcode.New(errcode.ServerError, "项目%v没有配置api服务器地址", projectInfo.ProjectPo.Name)
|
|
}
|
|
|
|
type RspData struct {
|
|
Code int `json:"code"`
|
|
Msg string `json:"msg"`
|
|
Data struct {
|
|
Data []*Role `json:"data"`
|
|
} `json:"data"`
|
|
}
|
|
|
|
rsp := &RspData{}
|
|
err := httpclient.Request(alisrvAddr+"/rolelist", "get", nil, rsp)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
|
|
for _, role := range rsp.Data.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),
|
|
CreateTime: utils.ParseUnixTimestamp2LocalTime(role.CreateTime),
|
|
}
|
|
et := (&entity.CommonResource{}).FromPo(rolePo)
|
|
rows = append(rows, et.ToCommonDto())
|
|
}
|
|
|
|
return fields, rows, nil
|
|
}
|