Class StatisticRobotService

java.lang.Object
com.bytedesk.ai.statistic.StatisticRobotService

@Service public class StatisticRobotService extends Object
  • Field Details

  • 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 - 机器人ID
      userUid - 用户ID
      modelType - 模型类型
      promptTokens - 输入tokens
      completionTokens - 输出tokens
      success - 请求是否成功
      responseTime - 响应时间(ms)
      tokenUnitPrice - token单价
    • calculateUserTotalCost

      public BigDecimal calculateUserTotalCost(String userUid, LocalDate startDate, LocalDate endDate)
      获取用户在指定日期范围内的总消费
    • calculateUserTotalTokens

      public long calculateUserTotalTokens(String userUid, LocalDate startDate, LocalDate endDate)
      获取用户在指定日期范围内的总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

      public double calculateSuccessRate(String userUid, LocalDate startDate, LocalDate endDate)
      计算用户在指定日期范围内的成功率
    • getCurrentPeriodStatistic

      public Optional<StatisticRobotEntity> getCurrentPeriodStatistic(String userUid)
      获取用户当前计费周期的统计信息
    • archiveStatistics

      @Transactional public void archiveStatistics(LocalDate beforeDate)
      归档指定日期之前的统计数据