refactor(usage): 移动 usage 查询到 services

This commit is contained in:
Forest
2025-12-24 08:41:31 +08:00
parent 5831eb8a6a
commit bbf4024dc7
14 changed files with 430 additions and 218 deletions

View File

@@ -8,6 +8,7 @@ import (
"time"
"sub2api/internal/model"
"sub2api/internal/pkg/usagestats"
"sub2api/internal/service/ports"
)
@@ -176,6 +177,14 @@ func (s *AccountUsageService) GetTodayStats(ctx context.Context, accountID int64
}, nil
}
func (s *AccountUsageService) GetAccountUsageStats(ctx context.Context, accountID int64, startTime, endTime time.Time) (*usagestats.AccountUsageStatsResponse, error) {
stats, err := s.usageLogRepo.GetAccountUsageStats(ctx, accountID, startTime, endTime)
if err != nil {
return nil, fmt.Errorf("get account usage stats failed: %w", err)
}
return stats, nil
}
// fetchOAuthUsage 从Anthropic API获取OAuth账号的使用量
func (s *AccountUsageService) fetchOAuthUsage(ctx context.Context, account *model.Account) (*UsageInfo, error) {
accessToken := account.GetCredential("access_token")