68 lines
2.7 KiB
Go
68 lines
2.7 KiB
Go
package model
|
||
|
||
import (
|
||
"admin/internal/db"
|
||
"admin/internal/global"
|
||
"admin/internal/model/dto"
|
||
"time"
|
||
)
|
||
|
||
func init() {
|
||
db.RegisterTableModels(Server{})
|
||
}
|
||
|
||
// Server 逻辑服
|
||
type Server struct {
|
||
ID int `gorm:"primarykey" readonly:"true"`
|
||
ProjectId int `gorm:"uniqueIndex:idx_server"`
|
||
ServerConfID string `gorm:"type:varchar(200);uniqueIndex:idx_server" name:"区服id" required:"true" uneditable:"true"`
|
||
Desc string `name:"描述"`
|
||
ClientConnAddr string `name:"客户端连接地址" desc:"填 公网ip:公网端口" required:"true"`
|
||
RunningStatus string `name:"进程运行状态" desc:"进程运行状态:未知、运行中、停止" readonly:"true" uneditable:"true" type:"tagStatus" choices:"GetRunningStatusChoices"`
|
||
Ccu int `name:"实时在线" desc:"ccu" readonly:"true" uneditable:"true"`
|
||
TotalRoleCount int `name:"总角色数" desc:"" readonly:"true" uneditable:"true"`
|
||
TotalAccountCount int `name:"总账号数" desc:"" readonly:"true" uneditable:"true"`
|
||
IsServerDown bool `name:"停服维护中" desc:"" readonly:"true" uneditable:"true" type:"tagStatus" choices:"GetServerDownStatusChoices"`
|
||
// command_list接口服务器地址,为空代表由由项目统一提供command_list.
|
||
// 取决于每个项目改造难度:
|
||
// 为空就代表项目要实现一个自己统一对外暴露的gm调用服务对内聚合、分发指令执行,本后台执行指令只调用一次;
|
||
// 不为空就代表command_list实现在各个逻辑服,由本后台系统在执行指令时聚合、分发指令
|
||
// 调用各个逻辑服执行,本后台执行指令需要根据逻辑服数量调用;
|
||
//ApiAddr string
|
||
|
||
CreatedAt time.Time `readonly:"true"`
|
||
UpdatedAt time.Time `readonly:"true"`
|
||
}
|
||
|
||
func (lm *Server) TableName() string {
|
||
return "server"
|
||
}
|
||
|
||
func (m *Server) GetId() int {
|
||
return m.ID
|
||
}
|
||
|
||
func (m *Server) GetShowKey() string {
|
||
return m.ServerConfID
|
||
}
|
||
|
||
func (m *Server) ListByProjectId(projectId int) ([]*Server, error) {
|
||
list := make([]*Server, 0)
|
||
err := global.GLOB_DB.Where("project_id=?", projectId).Find(&list).Error
|
||
return list, err
|
||
}
|
||
|
||
func (m *Server) GetRunningStatusChoices(project *Project) []*dto.CommonDtoFieldChoice {
|
||
return []*dto.CommonDtoFieldChoice{
|
||
{Desc: "失联", Value: "失联", Type: 3}, // type: 0:plain 1:primary 2:success 3:info 4:warning 5:danger
|
||
{Desc: "运行中", Value: "运行中", Type: 2},
|
||
}
|
||
}
|
||
|
||
func (m *Server) GetServerDownStatusChoices(project *Project) []*dto.CommonDtoFieldChoice {
|
||
return []*dto.CommonDtoFieldChoice{
|
||
{Desc: "否", Value: false, Type: 3}, // type: 0:plain 1:primary 2:success 3:info 4:warning 5:danger
|
||
{Desc: "是", Value: true, Type: 2},
|
||
}
|
||
}
|