2025-07-28 01:46:39 +08:00
|
|
|
|
package repositories
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
|
"context"
|
2025-09-12 01:15:09 +08:00
|
|
|
|
"time"
|
2025-07-28 01:46:39 +08:00
|
|
|
|
"tyapi-server/internal/domains/api/entities"
|
|
|
|
|
|
"tyapi-server/internal/shared/interfaces"
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
type ApiCallRepository interface {
|
|
|
|
|
|
Create(ctx context.Context, call *entities.ApiCall) error
|
|
|
|
|
|
Update(ctx context.Context, call *entities.ApiCall) error
|
|
|
|
|
|
FindById(ctx context.Context, id string) (*entities.ApiCall, error)
|
|
|
|
|
|
FindByUserId(ctx context.Context, userId string, limit, offset int) ([]*entities.ApiCall, error)
|
2025-07-28 23:44:01 +08:00
|
|
|
|
|
2025-07-28 01:46:39 +08:00
|
|
|
|
// 新增:分页查询用户API调用记录
|
|
|
|
|
|
ListByUserId(ctx context.Context, userId string, options interfaces.ListOptions) ([]*entities.ApiCall, int64, error)
|
2025-07-28 23:44:01 +08:00
|
|
|
|
|
2025-07-28 01:46:39 +08:00
|
|
|
|
// 新增:根据条件筛选API调用记录
|
|
|
|
|
|
ListByUserIdWithFilters(ctx context.Context, userId string, filters map[string]interface{}, options interfaces.ListOptions) ([]*entities.ApiCall, int64, error)
|
2025-07-28 23:44:01 +08:00
|
|
|
|
|
2025-07-28 01:46:39 +08:00
|
|
|
|
// 新增:根据条件筛选API调用记录(包含产品名称)
|
|
|
|
|
|
ListByUserIdWithFiltersAndProductName(ctx context.Context, userId string, filters map[string]interface{}, options interfaces.ListOptions) (map[string]string, []*entities.ApiCall, int64, error)
|
2025-07-28 23:44:01 +08:00
|
|
|
|
|
2025-07-28 01:46:39 +08:00
|
|
|
|
// 新增:统计用户API调用次数
|
|
|
|
|
|
CountByUserId(ctx context.Context, userId string) (int64, error)
|
2025-07-28 23:44:01 +08:00
|
|
|
|
|
2025-07-28 01:46:39 +08:00
|
|
|
|
// 新增:根据TransactionID查询
|
|
|
|
|
|
FindByTransactionId(ctx context.Context, transactionId string) (*entities.ApiCall, error)
|
2025-08-02 02:54:21 +08:00
|
|
|
|
|
2025-09-12 01:15:09 +08:00
|
|
|
|
// 统计相关方法
|
|
|
|
|
|
CountByUserIdAndDateRange(ctx context.Context, userId string, startDate, endDate time.Time) (int64, error)
|
|
|
|
|
|
GetDailyStatsByUserId(ctx context.Context, userId string, startDate, endDate time.Time) ([]map[string]interface{}, error)
|
|
|
|
|
|
GetMonthlyStatsByUserId(ctx context.Context, userId string, startDate, endDate time.Time) ([]map[string]interface{}, error)
|
|
|
|
|
|
|
2025-08-02 02:54:21 +08:00
|
|
|
|
// 管理端:根据条件筛选所有API调用记录(包含产品名称)
|
|
|
|
|
|
ListWithFiltersAndProductName(ctx context.Context, filters map[string]interface{}, options interfaces.ListOptions) (map[string]string, []*entities.ApiCall, int64, error)
|
2025-09-12 01:15:09 +08:00
|
|
|
|
|
|
|
|
|
|
// 系统级别统计方法
|
|
|
|
|
|
GetSystemTotalCalls(ctx context.Context) (int64, error)
|
|
|
|
|
|
GetSystemCallsByDateRange(ctx context.Context, startDate, endDate time.Time) (int64, error)
|
|
|
|
|
|
GetSystemDailyStats(ctx context.Context, startDate, endDate time.Time) ([]map[string]interface{}, error)
|
|
|
|
|
|
GetSystemMonthlyStats(ctx context.Context, startDate, endDate time.Time) ([]map[string]interface{}, error)
|
|
|
|
|
|
|
|
|
|
|
|
// API受欢迎程度排行榜
|
|
|
|
|
|
GetApiPopularityRanking(ctx context.Context, period string, limit int) ([]map[string]interface{}, error)
|
2025-07-28 23:44:01 +08:00
|
|
|
|
}
|