2025-06-09 13:50:00 +08:00
|
|
|
|
package domain
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"admin/apps/game/domain/entity"
|
|
|
|
|
"admin/apps/game/domain/projects"
|
2025-07-04 15:24:46 +08:00
|
|
|
|
"admin/apps/game/model"
|
2025-07-07 17:07:58 +08:00
|
|
|
|
"admin/internal/errcode"
|
2025-06-09 13:50:00 +08:00
|
|
|
|
dto2 "admin/internal/model/dto"
|
2025-07-07 17:07:58 +08:00
|
|
|
|
"admin/lib/dfs"
|
|
|
|
|
"admin/lib/xlog"
|
2025-07-04 15:24:46 +08:00
|
|
|
|
"bytes"
|
|
|
|
|
"fmt"
|
|
|
|
|
"strings"
|
|
|
|
|
"time"
|
2025-06-09 13:50:00 +08:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func (svc *CommonResourceService) handleServerUpOrDown(projectEt *entity.Project, resourceName string, params *dto2.CommonRowsSelectionReq) (*dto2.CommonRowsSelectionRsp, error) {
|
|
|
|
|
if hook, ok := projects.GetProjectResourceHook(projectEt, resourceName).(projects.IPostResourceOpRowsHook); ok {
|
|
|
|
|
rsp, err := hook.RowsSelection(projectEt, resourceName, params.BtnKey, params.Rows)
|
|
|
|
|
return rsp, err
|
|
|
|
|
}
|
|
|
|
|
return nil, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (svc *CommonResourceService) handleServerExportCdn(projectEt *entity.Project, resourceName string, params *dto2.CommonRowsSelectionReq) (*dto2.CommonRowsSelectionRsp, error) {
|
|
|
|
|
// 导出cdn,聚合公告信息一起导
|
|
|
|
|
serverList, err := svc.serverRepo.List(projectEt.GetProjectPo().ID)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
noticeList, err := svc.noticeRepo.List(projectEt.GetProjectPo().ID)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
content, err := genCdnServerListContent(serverList, noticeList)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
2025-07-07 17:07:58 +08:00
|
|
|
|
|
|
|
|
|
cosClient := dfs.NewDfsCos("AKIDqZ6SbXGsX6UffS4VnskRvEQXWLzQ2Xpu", "BDBlGajfQ2ShjZCbnv581jEZiy3vZ4MR", "ttsj-1359624709", "ap-chengdu")
|
|
|
|
|
|
|
|
|
|
opFilePathList := []string{
|
|
|
|
|
"Default_Update/AndroidTest/REMAIN-ServerList.bytes",
|
|
|
|
|
"Default_Update/iPhoneTest/REMAIN-ServerList.bytes",
|
|
|
|
|
}
|
|
|
|
|
for _, opFile := range opFilePathList {
|
|
|
|
|
oldFileContent, err := cosClient.GetObj(opFile)
|
|
|
|
|
if err != nil {
|
|
|
|
|
xlog.Errorf("get dfs file %v content error:%v", opFile, err)
|
|
|
|
|
return nil, errcode.New(errcode.DBError, "get obj %v error:%v", opFile, err)
|
|
|
|
|
}
|
|
|
|
|
xlog.Infof("prepare write dfs server list file %v content:%v", opFile, oldFileContent)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
xlog.Infof("new dfs server list file content:%v", content)
|
|
|
|
|
|
|
|
|
|
for _, opFile := range opFilePathList {
|
|
|
|
|
err := cosClient.PutObj(opFile, []byte(content))
|
|
|
|
|
if err != nil {
|
|
|
|
|
xlog.Errorf("write dfs file %v content error:%v", opFile, err)
|
|
|
|
|
return nil, errcode.New(errcode.DBError, "write obj %v error:%v", opFile, err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return &dto2.CommonRowsSelectionRsp{
|
|
|
|
|
Msg: "推送服务器列表文件到分布式存储成功!",
|
|
|
|
|
NeedRefresh: false,
|
|
|
|
|
FileName: "",
|
|
|
|
|
}, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (svc *CommonResourceService) handleServerPrepareShowExportCdn(projectEt *entity.Project, resourceName string, params *dto2.CommonRowsSelectionReq) (*dto2.CommonRowsSelectionRsp, error) {
|
|
|
|
|
// 导出cdn,聚合公告信息一起导
|
|
|
|
|
serverList, err := svc.serverRepo.List(projectEt.GetProjectPo().ID)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
noticeList, err := svc.noticeRepo.List(projectEt.GetProjectPo().ID)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
content, err := genCdnServerListContent(serverList, noticeList)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-09 13:50:00 +08:00
|
|
|
|
return &dto2.CommonRowsSelectionRsp{
|
|
|
|
|
Msg: content,
|
|
|
|
|
NeedRefresh: false,
|
|
|
|
|
FileName: projectEt.GetProjectPo().Name + "-区服公告信息.txt",
|
|
|
|
|
}, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (svc *CommonResourceService) handleNoticeDisable(projectEt *entity.Project, resourceName string, params *dto2.CommonRowsSelectionReq) (*dto2.CommonRowsSelectionRsp, error) {
|
|
|
|
|
var err error
|
|
|
|
|
if len(params.Rows) == 0 {
|
|
|
|
|
// 禁用所有
|
|
|
|
|
err = svc.noticeRepo.DisableAll(projectEt.GetProjectID())
|
|
|
|
|
} else {
|
|
|
|
|
ids := make([]int, 0, len(params.Rows))
|
|
|
|
|
for _, v := range params.Rows {
|
|
|
|
|
ids = append(ids, int(v["ID"].(float64)))
|
|
|
|
|
}
|
|
|
|
|
err = svc.noticeRepo.DisableSome(projectEt.GetProjectID(), ids)
|
|
|
|
|
}
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
return &dto2.CommonRowsSelectionRsp{
|
|
|
|
|
Msg: "禁用成功!",
|
|
|
|
|
NeedRefresh: true,
|
|
|
|
|
}, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (svc *CommonResourceService) handleNoticeEnable(projectEt *entity.Project, resourceName string, params *dto2.CommonRowsSelectionReq) (*dto2.CommonRowsSelectionRsp, error) {
|
|
|
|
|
var err error
|
|
|
|
|
if len(params.Rows) == 0 {
|
|
|
|
|
// 禁用所有
|
|
|
|
|
err = svc.noticeRepo.EnableAll(projectEt.GetProjectID())
|
|
|
|
|
} else {
|
|
|
|
|
ids := make([]int, 0, len(params.Rows))
|
|
|
|
|
for _, v := range params.Rows {
|
|
|
|
|
ids = append(ids, int(v["ID"].(float64)))
|
|
|
|
|
}
|
|
|
|
|
err = svc.noticeRepo.EnableSome(projectEt.GetProjectID(), ids)
|
|
|
|
|
}
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
return &dto2.CommonRowsSelectionRsp{
|
|
|
|
|
Msg: "启用成功!",
|
|
|
|
|
NeedRefresh: true,
|
|
|
|
|
}, nil
|
|
|
|
|
}
|
2025-07-04 15:24:46 +08:00
|
|
|
|
|
|
|
|
|
func (svc *CommonResourceService) handleGenAccountExport(projectEt *entity.Project, resourceName string, params *dto2.CommonRowsSelectionReq) (*dto2.CommonRowsSelectionRsp, error) {
|
|
|
|
|
|
|
|
|
|
fileContent := bytes.NewBuffer(nil)
|
|
|
|
|
|
|
|
|
|
getContentFun := func(po *model.GenAccount) {
|
|
|
|
|
buf := bytes.NewBuffer(nil)
|
|
|
|
|
|
|
|
|
|
accounts := strings.Split(po.AccountList, ",")
|
|
|
|
|
buf.WriteString(fmt.Sprintf("id:%v\n", po.ID))
|
|
|
|
|
buf.WriteString(fmt.Sprintf("区服:%v\n", po.ServerConfID))
|
|
|
|
|
buf.WriteString(fmt.Sprintf("创建时间:%v\n", po.CreatedAt.Format(time.DateTime)))
|
|
|
|
|
buf.WriteString(fmt.Sprintf("账号数量:%v\n", len(accounts)))
|
|
|
|
|
buf.WriteString(fmt.Sprintf("账号列表:\n"))
|
|
|
|
|
for _, account := range accounts {
|
|
|
|
|
buf.WriteString(fmt.Sprintf("%v\n", account))
|
|
|
|
|
}
|
|
|
|
|
buf.WriteString(fmt.Sprintf("\n"))
|
|
|
|
|
fileContent.WriteString(buf.String())
|
|
|
|
|
}
|
|
|
|
|
if len(params.Rows) == 0 {
|
|
|
|
|
poList, err := svc.genAccountRepo.ListAll(projectEt.GetProjectID())
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
for _, po := range poList {
|
|
|
|
|
getContentFun(po)
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
for _, dtoObj := range params.Rows {
|
|
|
|
|
et := new(entity.CommonResource).FromPo(&model.GenAccount{}).FromDto(dtoObj)
|
|
|
|
|
po := et.Po.(*model.GenAccount)
|
|
|
|
|
getContentFun(po)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return &dto2.CommonRowsSelectionRsp{
|
|
|
|
|
Msg: fileContent.String(),
|
|
|
|
|
NeedRefresh: false,
|
|
|
|
|
FileName: projectEt.GetProjectPo().Name + "-登录白名单账号列表.txt",
|
|
|
|
|
}, nil
|
|
|
|
|
}
|