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, 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) } fields = append(fields, &dto.CommonDtoFieldDesc{ Name: "进程运行状态", Key: "RunningStatus", Type: "string", HelpText: "进程运行状态:未知、运行中、停止", Readonly: false, Required: false, Choices: nil, MultiChoice: false, }) type ServerInfo struct { ServerId string `json:"serverId"` ServerName string `json:"serverName"` } type RspData struct { Code int `json:"code"` Msg string `json:"msg"` Data struct { List []*ServerInfo `json:"list"` } `json:"data"` } rsp := &RspData{} err := httpclient.Request(alisrvAddr+"/"+resource, "get", nil, rsp) if err != nil { return nil, nil, err } for _, row := range rows { findRunning := false for _, curRunning := range rsp.Data.List { et := (&entity.CommonResource{}).FromPo(&model.Server{}).FromDto(row) if et.ToPo().(*model.Server).ServerConfID == curRunning.ServerId { // 运行中,给描述信息添加运行信息 findRunning = true break } } if findRunning { row["RunningStatus"] = "运行中" } else { row["RunningStatus"] = "未知" } } return fields, rows, nil }