Package com.bytedesk.ai.statistic
Class StatisticRobotService
java.lang.Object
com.bytedesk.ai.statistic.StatisticRobotService
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final DateTimeFormatter
private final StatisticRobotRepository
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
archiveStatistics
(LocalDate beforeDate) 归档指定日期之前的统计数据double
calculateSuccessRate
(String userUid, LocalDate startDate, LocalDate endDate) 计算用户在指定日期范围内的成功率calculateUserTotalCost
(String userUid, LocalDate startDate, LocalDate endDate) 获取用户在指定日期范围内的总消费long
calculateUserTotalTokens
(String userUid, LocalDate startDate, LocalDate endDate) 获取用户在指定日期范围内的总token使用量getCurrentPeriodStatistic
(String userUid) 获取用户当前计费周期的统计信息org.springframework.data.domain.Page<StatisticRobotEntity>
getRobotStatistics
(String robotUid, LocalDate startDate, LocalDate endDate, org.springframework.data.domain.Pageable pageable) 获取机器人在指定日期范围内的统计数据org.springframework.data.domain.Page<StatisticRobotEntity>
getUserStatistics
(String userUid, LocalDate startDate, LocalDate endDate, org.springframework.data.domain.Pageable pageable) 获取用户在指定日期范围内的统计数据void
recordTokenUsage
(String robotUid, String userUid, String modelType, long promptTokens, long completionTokens, boolean success, long responseTime, BigDecimal tokenUnitPrice) 记录单次请求的token使用情况
-
Field Details
-
statisticRobotRepository
-
DATE_FORMATTER
-
-
Constructor Details
-
StatisticRobotService
public StatisticRobotService()
-
-
Method Details
-
recordTokenUsage
@Transactional public void recordTokenUsage(String robotUid, String userUid, String modelType, long promptTokens, long completionTokens, boolean success, long responseTime, BigDecimal tokenUnitPrice) 记录单次请求的token使用情况- Parameters:
robotUid
- 机器人IDuserUid
- 用户IDmodelType
- 模型类型promptTokens
- 输入tokenscompletionTokens
- 输出tokenssuccess
- 请求是否成功responseTime
- 响应时间(ms)tokenUnitPrice
- token单价
-
calculateUserTotalCost
获取用户在指定日期范围内的总消费 -
calculateUserTotalTokens
获取用户在指定日期范围内的总token使用量 -
getRobotStatistics
public org.springframework.data.domain.Page<StatisticRobotEntity> getRobotStatistics(String robotUid, LocalDate startDate, LocalDate endDate, org.springframework.data.domain.Pageable pageable) 获取机器人在指定日期范围内的统计数据 -
getUserStatistics
public org.springframework.data.domain.Page<StatisticRobotEntity> getUserStatistics(String userUid, LocalDate startDate, LocalDate endDate, org.springframework.data.domain.Pageable pageable) 获取用户在指定日期范围内的统计数据 -
calculateSuccessRate
计算用户在指定日期范围内的成功率 -
getCurrentPeriodStatistic
获取用户当前计费周期的统计信息 -
archiveStatistics
归档指定日期之前的统计数据
-