2025-06-06 18:30:12 +08:00
|
|
|
package domain
|
|
|
|
|
|
|
|
import (
|
|
|
|
"admin/apps/game/domain/entity"
|
|
|
|
"admin/apps/game/model"
|
|
|
|
"admin/internal/errcode"
|
|
|
|
"bytes"
|
2025-06-09 13:50:00 +08:00
|
|
|
"sort"
|
2025-06-06 18:30:12 +08:00
|
|
|
"strings"
|
|
|
|
"text/template"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
type CdnServerInfo struct {
|
|
|
|
Properties [8]struct {
|
|
|
|
Key string
|
|
|
|
Value string
|
|
|
|
}
|
|
|
|
}
|
|
|
|
type CdnNoticeInfo struct {
|
|
|
|
Sn int
|
|
|
|
UpdataMod string
|
|
|
|
Title string
|
|
|
|
Content string
|
|
|
|
}
|
|
|
|
type CdnServerNoticeInfo struct {
|
|
|
|
ServerList []*CdnServerInfo
|
|
|
|
NoticeVersion string
|
|
|
|
NoticeList []*CdnNoticeInfo
|
|
|
|
}
|
|
|
|
|
|
|
|
func genCdnServerListContent(serverList, noticeList []*entity.CommonResource) (string, error) {
|
|
|
|
info := &CdnServerNoticeInfo{}
|
|
|
|
for _, server := range serverList {
|
|
|
|
serverDbInfo := server.Po.(*model.Server)
|
|
|
|
serverInfo := &CdnServerInfo{}
|
|
|
|
serverInfo.Properties[0].Key = "id"
|
|
|
|
serverInfo.Properties[0].Value = serverDbInfo.ServerConfID
|
|
|
|
|
|
|
|
addr := strings.Split(serverDbInfo.ClientConnAddr, ":")
|
|
|
|
|
|
|
|
serverInfo.Properties[1].Key = "ip"
|
|
|
|
serverInfo.Properties[1].Value = ""
|
|
|
|
if len(addr) == 2 {
|
|
|
|
serverInfo.Properties[1].Value = addr[0]
|
|
|
|
}
|
|
|
|
|
|
|
|
serverInfo.Properties[2].Key = "name"
|
|
|
|
serverInfo.Properties[2].Value = serverDbInfo.Desc
|
|
|
|
|
|
|
|
serverInfo.Properties[3].Key = "port"
|
|
|
|
serverInfo.Properties[3].Value = ""
|
|
|
|
if len(addr) == 2 {
|
|
|
|
serverInfo.Properties[3].Value = addr[1]
|
|
|
|
}
|
|
|
|
|
|
|
|
serverInfo.Properties[4].Key = "recommend"
|
|
|
|
serverInfo.Properties[4].Value = "0"
|
|
|
|
|
|
|
|
serverInfo.Properties[5].Key = "status"
|
|
|
|
serverInfo.Properties[5].Value = "0"
|
|
|
|
|
|
|
|
serverInfo.Properties[6].Key = "area"
|
|
|
|
serverInfo.Properties[6].Value = "1区"
|
|
|
|
|
|
|
|
serverInfo.Properties[7].Key = "type"
|
|
|
|
serverInfo.Properties[7].Value = "1"
|
|
|
|
info.ServerList = append(info.ServerList, serverInfo)
|
|
|
|
}
|
|
|
|
|
|
|
|
info.NoticeVersion = time.Now().Format("200601021504")
|
2025-06-09 13:50:00 +08:00
|
|
|
|
|
|
|
sort.SliceStable(noticeList, func(i, j int) bool {
|
|
|
|
infoI := noticeList[i].Po.(*model.Notice)
|
|
|
|
infoJ := noticeList[j].Po.(*model.Notice)
|
|
|
|
return infoI.SortWeight > infoJ.SortWeight
|
|
|
|
})
|
|
|
|
|
2025-06-06 18:30:12 +08:00
|
|
|
for i, notice := range noticeList {
|
|
|
|
noticeDbInfo := notice.Po.(*model.Notice)
|
|
|
|
noticeInfo := &CdnNoticeInfo{}
|
|
|
|
noticeInfo.Sn = i + 1
|
|
|
|
noticeInfo.UpdataMod = noticeDbInfo.Mod
|
|
|
|
noticeInfo.Title = noticeDbInfo.Title
|
|
|
|
noticeInfo.Content = noticeDbInfo.Content
|
|
|
|
info.NoticeList = append(info.NoticeList, noticeInfo)
|
|
|
|
}
|
|
|
|
|
|
|
|
bytesBuffer := bytes.NewBufferString("")
|
|
|
|
tpl, err := template.New("").Parse(cdnServerListContentTemplate)
|
|
|
|
if err != nil {
|
|
|
|
return "", errcode.New(errcode.ServerError, "new render template error:%v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = tpl.Execute(bytesBuffer, info)
|
|
|
|
if err != nil {
|
|
|
|
return "", errcode.New(errcode.ServerError, "execute render template error:%v", err)
|
|
|
|
}
|
|
|
|
return bytesBuffer.String(), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
var cdnServerListContentTemplate = `
|
|
|
|
local Data = {}
|
|
|
|
|
|
|
|
Data.versionCode = "2.2.2"
|
|
|
|
Data.typenName = "iOS服务器"
|
|
|
|
|
|
|
|
--测试服务器
|
|
|
|
Data.apptest = {}
|
|
|
|
Data.zhuboAcount ={}
|
|
|
|
|
|
|
|
--正式服务器
|
|
|
|
Data.appOnline = {}
|
|
|
|
|
|
|
|
{{ range .ServerList }}
|
|
|
|
table.insert(Data.appOnline,{
|
|
|
|
{{- range .Properties }}
|
|
|
|
{{ .Key }} = "{{ .Value }}",
|
|
|
|
{{- end }}
|
|
|
|
})
|
|
|
|
{{- end }}
|
|
|
|
|
|
|
|
Data.notice = {}
|
|
|
|
Data.notice.version = "{{ .NoticeVersion }}"
|
|
|
|
Data.notice.info = {
|
|
|
|
{{- range .NoticeList }}
|
|
|
|
{sn={{.Sn}},updataMod="{{.UpdataMod}}",title="{{.Title}}",updataTxt="{{.Content}}"},
|
|
|
|
{{- end }}
|
|
|
|
}
|
|
|
|
|
|
|
|
Data.loginResult = {
|
|
|
|
Code1 = 99989,
|
|
|
|
Content1 = "服务器正在维护中",
|
|
|
|
Code2 = 99988,
|
|
|
|
Content2 = "服务器正在维护中",
|
|
|
|
}
|
|
|
|
|
|
|
|
return Data
|
|
|
|
`
|