128 lines
3.3 KiB
Go
128 lines
3.3 KiB
Go
package server
|
|
|
|
import (
|
|
"admin/internal/consts"
|
|
"admin/internal/context"
|
|
"admin/internal/errcode"
|
|
"admin/internal/model/dto"
|
|
"admin/lib/httpclient"
|
|
"admin/lib/xlog"
|
|
"strconv"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
func (ctl *controller) CommandList(ctx *context.WebContext, params *dto.CommandListReq, rsp *dto.CommandListRsp) error {
|
|
|
|
url := params.Addr + "/api/commandlist"
|
|
|
|
xlog.Debugf("request url:%v command list", url)
|
|
|
|
cmdListRsp := make(map[string]any)
|
|
err := httpclient.Request(url, "get", nil, &cmdListRsp)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
xlog.Debugf("command list rsp:%+v", cmdListRsp)
|
|
|
|
ctx.Ok(cmdListRsp)
|
|
|
|
return nil
|
|
}
|
|
|
|
func (ctl *controller) ProjectResourceList(ctx *context.WebContext, params *dto.CommonListReq, rsp *dto.CommonListRsp) error {
|
|
projectId := getCtxURIProjectId(ctx)
|
|
resource := getCtxURIResource(ctx)
|
|
|
|
apiAddr, err := ctl.svc.GetProjectInvokeApiAddr(projectId, nil)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
url := apiAddr[0] + "/api/" + resource
|
|
|
|
listRsp := make(map[string]any)
|
|
err = httpclient.Request(url, "get", nil, &listRsp)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
xlog.Debugf("receive project %v resource %v list", "projectId", resource)
|
|
return nil
|
|
}
|
|
|
|
func (ctl *controller) ProjectResourcePost(ctx *context.WebContext, params *dto.CommonPostReq, rsp *dto.CommonPostRsp) error {
|
|
|
|
return nil
|
|
}
|
|
|
|
func (ctl *controller) ProjectResourcePut(ctx *context.WebContext, params *dto.CommonPutReq, rsp *dto.CommonPutRsp) error {
|
|
|
|
return nil
|
|
}
|
|
|
|
func (ctl *controller) ProjectResourceDelete(ctx *context.WebContext, params *dto.CommonDeleteReq, rsp *dto.CommonDeleteRsp) error {
|
|
|
|
return nil
|
|
}
|
|
|
|
func (ctl *controller) GameLogEventList(ctx *context.WebContext, params *dto.GameLogEventListReq, rsp *dto.GameLogEventListRsp) error {
|
|
projectId := getCtxURIProjectId(ctx)
|
|
|
|
ds, _ := time.ParseInLocation("2006-01-02 15:04:05", params.DateStart, time.Local)
|
|
de, _ := time.ParseInLocation("2006-01-02 15:04:05", params.DateEnd, time.Local)
|
|
if ds.IsZero() {
|
|
ds = time.Now().Add(-time.Hour * 24 * 7)
|
|
}
|
|
if de.IsZero() {
|
|
de = time.Now().Add(time.Hour)
|
|
}
|
|
|
|
var eventList []string
|
|
if params.EventName != "" {
|
|
eventList = strings.Split(params.EventName, ",")
|
|
for _, en := range eventList {
|
|
if en == "" {
|
|
return errcode.New(errcode.ParamsInvalid, "event name invalid:[%v]", params.EventName)
|
|
}
|
|
}
|
|
}
|
|
|
|
var err error
|
|
rsp.TotalCount, rsp.FieldsDescInfo, rsp.Rows, err =
|
|
ctl.svc.GameLogSvc.QueryEventList(projectId,
|
|
eventList, params.ServerId, params.Account, params.RoleId, params.PageNo, params.PageLen, ds, de)
|
|
return err
|
|
}
|
|
|
|
func (ctl *controller) getProjectResourceCommandApiAddr(ctx *context.WebContext) ([]string, error) {
|
|
projectId := getCtxURIProjectId(ctx)
|
|
//resouce := getCtxURIResource(ctx)
|
|
return ctl.svc.GetProjectInvokeApiAddr(projectId, nil)
|
|
}
|
|
|
|
func getCtxURIProjectIdAndResource(ctx *context.WebContext) (int, string) {
|
|
return getCtxURIProjectId(ctx), getCtxURIResource(ctx)
|
|
}
|
|
|
|
func getCtxURIResource(ctx *context.WebContext) string {
|
|
resource := ctx.GinCtx().Param("resource")
|
|
if resource == "" {
|
|
if strings.HasPrefix(ctx.GinCtx().Request.RequestURI, "/api/"+consts.ResourcesName_Project) {
|
|
return consts.ResourcesName_Project
|
|
}
|
|
}
|
|
return resource
|
|
}
|
|
|
|
func getCtxURIProjectId(ctx *context.WebContext) int {
|
|
projectId := ctx.GinCtx().Param("projectId")
|
|
projectId1, _ := strconv.Atoi(projectId)
|
|
return projectId1
|
|
}
|
|
|
|
func (ctl *controller) apiRequest() {
|
|
|
|
}
|