This commit is contained in:
2025-12-06 15:46:46 +08:00
parent 89367fb2ee
commit af88bcc8eb
4 changed files with 55 additions and 16 deletions

View File

@@ -431,10 +431,11 @@ func (r *GormApiCallRepository) GetSystemTotalCalls(ctx context.Context) (int64,
}
// GetSystemCallsByDateRange 获取系统指定时间范围内的API调用次数
// endDate 应该是结束日期当天的次日00:00:00日统计或下个月1号00:00:00月统计使用 < 而不是 <=
func (r *GormApiCallRepository) GetSystemCallsByDateRange(ctx context.Context, startDate, endDate time.Time) (int64, error) {
var count int64
err := r.GetDB(ctx).Model(&entities.ApiCall{}).
Where("created_at >= ? AND created_at <= ?", startDate, endDate).
Where("created_at >= ? AND created_at < ?", startDate, endDate).
Count(&count).Error
return count, err
}
@@ -472,7 +473,7 @@ func (r *GormApiCallRepository) GetSystemMonthlyStats(ctx context.Context, start
COUNT(*) as calls
FROM api_calls
WHERE created_at >= $1
AND created_at <= $2
AND created_at < $2
GROUP BY TO_CHAR(created_at, 'YYYY-MM')
ORDER BY month ASC
`