From 1dabf7f67bf64a5b91bac5f2eba0ce0900ce2634 Mon Sep 17 00:00:00 2001 From: cialloo Date: Sat, 4 Oct 2025 13:19:43 +0800 Subject: [PATCH] update --- api/ServerStatistics.api | 53 +++++++++++++++++++ .../handler/recentchatmessagehandler.go | 29 ++++++++++ src/internal/handler/recentplayhandler.go | 29 ++++++++++ src/internal/handler/routes.go | 18 +++++++ src/internal/handler/topplaytimehandler.go | 29 ++++++++++ src/internal/logic/recentchatmessagelogic.go | 31 +++++++++++ src/internal/logic/recentplaylogic.go | 31 +++++++++++ src/internal/logic/topplaytimelogic.go | 31 +++++++++++ src/internal/types/types.go | 32 +++++++++++ 9 files changed, 283 insertions(+) create mode 100644 src/internal/handler/recentchatmessagehandler.go create mode 100644 src/internal/handler/recentplayhandler.go create mode 100644 src/internal/handler/topplaytimehandler.go create mode 100644 src/internal/logic/recentchatmessagelogic.go create mode 100644 src/internal/logic/recentplaylogic.go create mode 100644 src/internal/logic/topplaytimelogic.go diff --git a/api/ServerStatistics.api b/api/ServerStatistics.api index 9bce4a9..d284234 100644 --- a/api/ServerStatistics.api +++ b/api/ServerStatistics.api @@ -123,6 +123,38 @@ type ( } ) +type ( + RecentPlayReq { + TimeRangeStart int64 `json:"timeRangeStart"` // Unix timestamp in milliseconds + TimeRangeEnd int64 `json:"timeRangeEnd"` // Unix timestamp in milliseconds + LeastPlayTime int64 `json:"leastPlayTime"` // Least playtime in seconds to filter by + } + RecentPlayResp { + Players []RecentPlayRespPlayer `json:"players"` // List of players who played in the time range + } + RecentPlayRespPlayer { + SteamID64 string `json:"steamID64"` // Player's SteamID64 + UserName string `json:"userName"` // Player's username at the time of playing + MapName string `json:"mapName"` // Map name where the player played + PlayTime int64 `json:"playTime"` // Playtime in seconds during the time range + } +) + +type ( + TopPlayTimeReq { + TimeRangeStart int64 `json:"timeRangeStart"` // Unix timestamp in milliseconds + TimeRangeEnd int64 `json:"timeRangeEnd"` // Unix timestamp in milliseconds + } + TopPlayTimeResp { + Players []TopPlayTimeRespPlayer `json:"players"` // List of top players by playtime + } + TopPlayTimeRespPlayer { + SteamID64 string `json:"steamID64"` // Player's SteamID64 + UserName string `json:"userName"` // Player's username at the time of playing + PlayTime int64 `json:"playTime"` // Playtime in seconds during the time range + } +) + @server ( prefix: /api/server/statistics ) @@ -189,5 +221,26 @@ service ServerStatistics { ) @handler recentJoinPlayerHandler post /recent-join-player (RecentJoinPlayerReq) returns (RecentJoinPlayerResp) + + @doc ( + summary: "Get recent chat messages within a specified time range" + description: "Get recent chat messages within a specified time range" + ) + @handler recentChatMessageHandler + post /recent-chat-message (RecentChatMessageReq) returns (RecentChatMessageResp) + + @doc ( + summary: "Get recent players who played within a specified time range" + description: "Get recent players who played within a specified time range" + ) + @handler recentPlayHandler + post /recent-play (RecentPlayReq) returns (RecentPlayResp) + + @doc ( + summary: "Get top players by playtime within a specified time range" + description: "Get top players by playtime within a specified time range" + ) + @handler topPlayTimeHandler + post /top-play-time (TopPlayTimeReq) returns (TopPlayTimeResp) } diff --git a/src/internal/handler/recentchatmessagehandler.go b/src/internal/handler/recentchatmessagehandler.go new file mode 100644 index 0000000..881ef09 --- /dev/null +++ b/src/internal/handler/recentchatmessagehandler.go @@ -0,0 +1,29 @@ +package handler + +import ( + "net/http" + + "github.com/zeromicro/go-zero/rest/httpx" + "src/internal/logic" + "src/internal/svc" + "src/internal/types" +) + +// Get recent chat messages within a specified time range +func recentChatMessageHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + var req types.RecentChatMessageReq + if err := httpx.Parse(r, &req); err != nil { + httpx.ErrorCtx(r.Context(), w, err) + return + } + + l := logic.NewRecentChatMessageLogic(r.Context(), svcCtx) + resp, err := l.RecentChatMessage(&req) + if err != nil { + httpx.ErrorCtx(r.Context(), w, err) + } else { + httpx.OkJsonCtx(r.Context(), w, resp) + } + } +} diff --git a/src/internal/handler/recentplayhandler.go b/src/internal/handler/recentplayhandler.go new file mode 100644 index 0000000..e2cab21 --- /dev/null +++ b/src/internal/handler/recentplayhandler.go @@ -0,0 +1,29 @@ +package handler + +import ( + "net/http" + + "github.com/zeromicro/go-zero/rest/httpx" + "src/internal/logic" + "src/internal/svc" + "src/internal/types" +) + +// Get recent players who played within a specified time range +func recentPlayHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + var req types.RecentPlayReq + if err := httpx.Parse(r, &req); err != nil { + httpx.ErrorCtx(r.Context(), w, err) + return + } + + l := logic.NewRecentPlayLogic(r.Context(), svcCtx) + resp, err := l.RecentPlay(&req) + if err != nil { + httpx.ErrorCtx(r.Context(), w, err) + } else { + httpx.OkJsonCtx(r.Context(), w, resp) + } + } +} diff --git a/src/internal/handler/routes.go b/src/internal/handler/routes.go index 0059d9e..f8a7048 100644 --- a/src/internal/handler/routes.go +++ b/src/internal/handler/routes.go @@ -20,18 +20,36 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { Path: "/ping", Handler: pingHandler(serverCtx), }, + { + // Get recent chat messages within a specified time range + Method: http.MethodPost, + Path: "/recent-chat-message", + Handler: recentChatMessageHandler(serverCtx), + }, { // Get recent players who joined within a specified time range Method: http.MethodPost, Path: "/recent-join-player", Handler: recentJoinPlayerHandler(serverCtx), }, + { + // Get recent players who played within a specified time range + Method: http.MethodPost, + Path: "/recent-play", + Handler: recentPlayHandler(serverCtx), + }, { // Get recent player joins within a specified time range Method: http.MethodPost, Path: "/recent-player-join", Handler: recentPlayerJoinHandler(serverCtx), }, + { + // Get top players by playtime within a specified time range + Method: http.MethodPost, + Path: "/top-play-time", + Handler: topPlayTimeHandler(serverCtx), + }, { // Get total chat message count within a specified time range Method: http.MethodPost, diff --git a/src/internal/handler/topplaytimehandler.go b/src/internal/handler/topplaytimehandler.go new file mode 100644 index 0000000..400caaa --- /dev/null +++ b/src/internal/handler/topplaytimehandler.go @@ -0,0 +1,29 @@ +package handler + +import ( + "net/http" + + "github.com/zeromicro/go-zero/rest/httpx" + "src/internal/logic" + "src/internal/svc" + "src/internal/types" +) + +// Get top players by playtime within a specified time range +func topPlayTimeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + var req types.TopPlayTimeReq + if err := httpx.Parse(r, &req); err != nil { + httpx.ErrorCtx(r.Context(), w, err) + return + } + + l := logic.NewTopPlayTimeLogic(r.Context(), svcCtx) + resp, err := l.TopPlayTime(&req) + if err != nil { + httpx.ErrorCtx(r.Context(), w, err) + } else { + httpx.OkJsonCtx(r.Context(), w, resp) + } + } +} diff --git a/src/internal/logic/recentchatmessagelogic.go b/src/internal/logic/recentchatmessagelogic.go new file mode 100644 index 0000000..ceac8ac --- /dev/null +++ b/src/internal/logic/recentchatmessagelogic.go @@ -0,0 +1,31 @@ +package logic + +import ( + "context" + + "src/internal/svc" + "src/internal/types" + + "github.com/zeromicro/go-zero/core/logx" +) + +type RecentChatMessageLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +// Get recent chat messages within a specified time range +func NewRecentChatMessageLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RecentChatMessageLogic { + return &RecentChatMessageLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *RecentChatMessageLogic) RecentChatMessage(req *types.RecentChatMessageReq) (resp *types.RecentChatMessageResp, err error) { + // todo: add your logic here and delete this line + + return +} diff --git a/src/internal/logic/recentplaylogic.go b/src/internal/logic/recentplaylogic.go new file mode 100644 index 0000000..0b9deae --- /dev/null +++ b/src/internal/logic/recentplaylogic.go @@ -0,0 +1,31 @@ +package logic + +import ( + "context" + + "src/internal/svc" + "src/internal/types" + + "github.com/zeromicro/go-zero/core/logx" +) + +type RecentPlayLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +// Get recent players who played within a specified time range +func NewRecentPlayLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RecentPlayLogic { + return &RecentPlayLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *RecentPlayLogic) RecentPlay(req *types.RecentPlayReq) (resp *types.RecentPlayResp, err error) { + // todo: add your logic here and delete this line + + return +} diff --git a/src/internal/logic/topplaytimelogic.go b/src/internal/logic/topplaytimelogic.go new file mode 100644 index 0000000..62437bd --- /dev/null +++ b/src/internal/logic/topplaytimelogic.go @@ -0,0 +1,31 @@ +package logic + +import ( + "context" + + "src/internal/svc" + "src/internal/types" + + "github.com/zeromicro/go-zero/core/logx" +) + +type TopPlayTimeLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +// Get top players by playtime within a specified time range +func NewTopPlayTimeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *TopPlayTimeLogic { + return &TopPlayTimeLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *TopPlayTimeLogic) TopPlayTime(req *types.TopPlayTimeReq) (resp *types.TopPlayTimeResp, err error) { + // todo: add your logic here and delete this line + + return +} diff --git a/src/internal/types/types.go b/src/internal/types/types.go index 1dd67eb..1785dd9 100644 --- a/src/internal/types/types.go +++ b/src/internal/types/types.go @@ -42,6 +42,38 @@ type RecentJoinPlayerRespPlayer struct { PlayTime int64 `json:"playTime"` // Playtime in seconds since joining } +type RecentPlayReq struct { + TimeRangeStart int64 `json:"timeRangeStart"` // Unix timestamp in milliseconds + TimeRangeEnd int64 `json:"timeRangeEnd"` // Unix timestamp in milliseconds + LeastPlayTime int64 `json:"leastPlayTime"` // Least playtime in seconds to filter by +} + +type RecentPlayResp struct { + Players []RecentPlayRespPlayer `json:"players"` // List of players who played in the time range +} + +type RecentPlayRespPlayer struct { + SteamID64 string `json:"steamID64"` // Player's SteamID64 + UserName string `json:"userName"` // Player's username at the time of playing + MapName string `json:"mapName"` // Map name where the player played + PlayTime int64 `json:"playTime"` // Playtime in seconds during the time range +} + +type TopPlayTimeReq struct { + TimeRangeStart int64 `json:"timeRangeStart"` // Unix timestamp in milliseconds + TimeRangeEnd int64 `json:"timeRangeEnd"` // Unix timestamp in milliseconds +} + +type TopPlayTimeResp struct { + Players []TopPlayTimeRespPlayer `json:"players"` // List of top players by playtime +} + +type TopPlayTimeRespPlayer struct { + SteamID64 string `json:"steamID64"` // Player's SteamID64 + UserName string `json:"userName"` // Player's username at the time of playing + PlayTime int64 `json:"playTime"` // Playtime in seconds during the time range +} + type TotalChatMessageCountReq struct { TimeRangeStart int64 `json:"timeRangeStart"` // Unix timestamp in milliseconds TimeRangeEnd int64 `json:"timeRangeEnd"` // Unix timestamp in milliseconds