package smdl import ( "admin/apps/game/domain/entity" "admin/apps/game/model" "admin/apps/game/model/dto" "admin/internal/errcode" "admin/lib/httpclient" ) type ServerHook struct { } func (hook *ServerHook) List(projectInfo *entity.Project, resource string, params *dto.CommonListReq, fields []*dto.CommonDtoFieldDesc, totalCount int, rows []dto.CommonDtoValues) ( int, []*dto.CommonDtoFieldDesc, []dto.CommonDtoValues, error) { alisrvAddr := projectInfo.GetApiAddr() if alisrvAddr == "" { return 0, nil, nil, errcode.New(errcode.ServerError, "项目%v没有配置api服务器地址", projectInfo.Po.Name) } fields = append(fields, getAttachFields()...) serverInfoList, err := getRemoteServerInfoList(alisrvAddr) if err != nil { return 0, nil, nil, err } for _, row := range rows { var findRemoteServerInfo *ServerInfo for _, curRunning := range serverInfoList { et := (&entity.CommonResource{}).FromPo(&model.Server{}).FromDto(row) if et.ToPo().(*model.Server).ServerConfID == curRunning.ServerId { // 运行中,给描述信息添加运行信息 findRemoteServerInfo = curRunning break } } if findRemoteServerInfo != nil { row["RunningStatus"] = "运行中" row["Ccu"] = findRemoteServerInfo.Ccu row["TotalRoleCount"] = findRemoteServerInfo.TotalRoleCount row["TotalAccountCount"] = findRemoteServerInfo.TotalAccountCount if findRemoteServerInfo.OpenWhitelistLogin { row["IsWhitelistLogin"] = "是" } else { row["IsWhitelistLogin"] = "否" } } else { row["RunningStatus"] = "未知" row["Ccu"] = 0 row["TotalRoleCount"] = 0 row["TotalAccountCount"] = 0 row["IsWhitelistLogin"] = "否" } } return totalCount, fields, rows, nil } type ServerInfo struct { ServerId string `json:"serverId"` ServerName string `json:"serverName"` Ccu int `json:"ccu"` TotalRoleCount int `json:"total_role_count"` TotalAccountCount int `json:"total_account_count"` Addr string `json:"addr"` OpenWhitelistLogin bool `json:"open_whitelist_login"` } type RspData struct { Code int `json:"code"` Msg string `json:"msg"` Data struct { List []*ServerInfo `json:"list"` } `json:"data"` } func getRemoteServerInfoList(alisrvAddr string) ([]*ServerInfo, error) { rsp := &RspData{} err := httpclient.Request(alisrvAddr+"/server", "get", nil, rsp) if err != nil { return nil, err } return rsp.Data.List, nil } func getAttachFields() []*dto.CommonDtoFieldDesc { return []*dto.CommonDtoFieldDesc{ { Name: "进程运行状态", Key: "RunningStatus", Type: "string", HelpText: "进程运行状态:未知、运行中、停止", Readonly: true, Required: false, Choices: make([]*dto.CommonDtoFieldChoice, 0), MultiChoice: false, Uneditable: true, }, { Name: "实时在线", Key: "Ccu", Type: "int", HelpText: "ccu", Readonly: true, Required: false, Choices: make([]*dto.CommonDtoFieldChoice, 0), MultiChoice: false, Uneditable: true, }, { Name: "总角色数", Key: "TotalRoleCount", Type: "int", HelpText: "", Readonly: true, Required: false, Choices: make([]*dto.CommonDtoFieldChoice, 0), MultiChoice: false, Uneditable: true, }, { Name: "总账号数", Key: "TotalAccountCount", Type: "int", HelpText: "进程运行状态:未知、运行中、停止", Readonly: true, Required: false, Choices: make([]*dto.CommonDtoFieldChoice, 0), MultiChoice: false, Uneditable: true, }, { Name: "是否只允许白名单登录", Key: "IsWhitelistLogin", Type: "bool", HelpText: "打开就是相当于停服维护中了", Readonly: true, Required: false, Choices: make([]*dto.CommonDtoFieldChoice, 0), MultiChoice: false, Uneditable: true, }, } }