- 新增 ai_usage_records.user_id 与 (user_id, occurred_at) 索引,NULL 表示未归属 - 归属标记跟着请求走:AiServiceClient 提交任务时带上顶层 callerRef(当前用户 id), lpt-ai 原样透传,上报后落到 user_id。取不到身份就不带,绝不让 AI 调用因此失败 - breakdown 支持 groupBy=user,新增 label(登录名,未归属为「未归属」); summary/series/breakdown 支持 userId 过滤
42 lines
1.1 KiB
Java
42 lines
1.1 KiB
Java
package com.guo.learningprogresstracker.dto;
|
|
|
|
import lombok.Data;
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
/**
|
|
* 用量按任务类型 / 模型 / 用户分组的一项(契约 2.4、v2 第 4.2 节,{@code GET /ai/usage/breakdown})。
|
|
*/
|
|
@Data
|
|
public class AiUsageBreakdownItem {
|
|
|
|
/**
|
|
* 分组键:{@code groupBy=taskType} 时是任务类型,{@code groupBy=model} 时是模型名,
|
|
* {@code groupBy=user} 时是用户 id(未归属的记录为 null)。
|
|
*/
|
|
private String key;
|
|
|
|
/**
|
|
* 展示名:{@code groupBy=user} 时是登录名(未归属为「未归属」,查不到登录名时回退为 {@code key}),
|
|
* 其它分组维度下等于 {@code key}——前端统一渲染 {@code label} 即可,不必按维度分支。
|
|
*/
|
|
private String label;
|
|
|
|
private Long calls;
|
|
|
|
private Long successCalls;
|
|
|
|
private Long failedCalls;
|
|
|
|
private Long promptTokens;
|
|
|
|
private Long completionTokens;
|
|
|
|
private Long cacheHitTokens;
|
|
|
|
private BigDecimal costUsd;
|
|
|
|
/** 平均调用耗时(毫秒);该分组无调用时为 null */
|
|
private Long avgDurationMs;
|
|
}
|