feat(admin): 新增用户 Token 使用排行榜#2924
Open
bwliangc wants to merge 1 commit into
Open
Conversation
Contributor
|
All contributors have signed the CLA. ✅ |
Author
|
I have read the CLA Document and I hereby sign the CLA |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概述
新增管理端 用户 Token 使用排行榜,可按可选时间范围对用户进行 Token 用量 / 请求数 / 消费的排名,并支持筛选。该功能复用已有的
GetUserBreakdown聚合逻辑,在其基础上扩展了可配置排序和一个额外的计费模式(billing_mode)过滤条件。改动内容
后端
dashboard_handler.go:GetUserBreakdown新增sort_by查询参数(actual_cost|tokens|requests|cost|account_cost),通过parseUserBreakdownSortBy校验,非法值返回400。request_type解析:支持通过service.ParseUsageRequestType解析命名值,并用RequestType.IsValid()校验数值,而非直接强转。billing_mode查询过滤,贯通到 repository 层。usage_log_repo.go:新增resolveUserBreakdownOrderBy,按排序键生成确定性的ORDER BY(以user_id ASC作为稳定的并列兜底);并应用可选的billing_modeWHERE 条件。前端
views/admin/UserTokenLeaderboardView.vue和组件components/admin/usage/UserTokenLeaderboard.vue,渲染排名表格(排名 / 用户 / Token / 请求 / 消费),支持时间范围、数量和筛选条件。/admin/token-leaderboard(requiresAuth+requiresAdmin)。api/admin/dashboard.ts:UserBreakdownParams扩展sort_by和billing_mode;request_type类型改为UsageRequestType;导出getUserBreakdown。en、zh国际化文案。说明
sort_by默认为actual_cost,保持原有默认排序不变,已有的GetUserBreakdown调用方不受影响。