This commit is contained in:
Mrx
2026-03-02 19:21:23 +08:00
parent 9f36cd8b63
commit c885d562ee
7 changed files with 88 additions and 35 deletions

View File

@@ -20,7 +20,7 @@ import (
)
const (
UsersTable = "users"
UsersTable = "users"
UserCacheTTL = 30 * 60 // 30分钟
)
@@ -415,7 +415,7 @@ func (r *GormUserRepository) GetSystemUserStatsByDateRange(ctx context.Context,
// GetSystemDailyUserStats 获取系统每日用户统计
func (r *GormUserRepository) GetSystemDailyUserStats(ctx context.Context, startDate, endDate time.Time) ([]map[string]interface{}, error) {
var results []map[string]interface{}
sql := `
SELECT
DATE(created_at) as date,
@@ -426,19 +426,19 @@ func (r *GormUserRepository) GetSystemDailyUserStats(ctx context.Context, startD
GROUP BY DATE(created_at)
ORDER BY date ASC
`
err := r.GetDB(ctx).Raw(sql, startDate.Format("2006-01-02"), endDate.Format("2006-01-02")).Scan(&results).Error
if err != nil {
return nil, err
}
return results, nil
}
// GetSystemMonthlyUserStats 获取系统每月用户统计
func (r *GormUserRepository) GetSystemMonthlyUserStats(ctx context.Context, startDate, endDate time.Time) ([]map[string]interface{}, error) {
var results []map[string]interface{}
sql := `
SELECT
TO_CHAR(created_at, 'YYYY-MM') as month,
@@ -449,19 +449,19 @@ func (r *GormUserRepository) GetSystemMonthlyUserStats(ctx context.Context, star
GROUP BY TO_CHAR(created_at, 'YYYY-MM')
ORDER BY month ASC
`
err := r.GetDB(ctx).Raw(sql, startDate, endDate).Scan(&results).Error
if err != nil {
return nil, err
}
return results, nil
}
// GetSystemDailyCertificationStats 获取系统每日认证用户统计基于is_certified字段
func (r *GormUserRepository) GetSystemDailyCertificationStats(ctx context.Context, startDate, endDate time.Time) ([]map[string]interface{}, error) {
var results []map[string]interface{}
sql := `
SELECT
DATE(updated_at) as date,
@@ -473,19 +473,19 @@ func (r *GormUserRepository) GetSystemDailyCertificationStats(ctx context.Contex
GROUP BY DATE(updated_at)
ORDER BY date ASC
`
err := r.GetDB(ctx).Raw(sql, startDate.Format("2006-01-02"), endDate.Format("2006-01-02")).Scan(&results).Error
if err != nil {
return nil, err
}
return results, nil
}
// GetSystemMonthlyCertificationStats 获取系统每月认证用户统计基于is_certified字段
func (r *GormUserRepository) GetSystemMonthlyCertificationStats(ctx context.Context, startDate, endDate time.Time) ([]map[string]interface{}, error) {
var results []map[string]interface{}
sql := `
SELECT
TO_CHAR(updated_at, 'YYYY-MM') as month,
@@ -497,12 +497,12 @@ func (r *GormUserRepository) GetSystemMonthlyCertificationStats(ctx context.Cont
GROUP BY TO_CHAR(updated_at, 'YYYY-MM')
ORDER BY month ASC
`
err := r.GetDB(ctx).Raw(sql, startDate, endDate).Scan(&results).Error
if err != nil {
return nil, err
}
return results, nil
}
@@ -510,7 +510,7 @@ func (r *GormUserRepository) GetSystemMonthlyCertificationStats(ctx context.Cont
func (r *GormUserRepository) GetUserCallRankingByCalls(ctx context.Context, period string, limit int) ([]map[string]interface{}, error) {
var sql string
var args []interface{}
switch period {
case "today":
sql = `
@@ -565,13 +565,13 @@ func (r *GormUserRepository) GetUserCallRankingByCalls(ctx context.Context, peri
default:
return nil, fmt.Errorf("不支持的时间周期: %s", period)
}
var results []map[string]interface{}
err := r.GetDB(ctx).Raw(sql, args...).Scan(&results).Error
if err != nil {
return nil, err
}
return results, nil
}
@@ -579,7 +579,7 @@ func (r *GormUserRepository) GetUserCallRankingByCalls(ctx context.Context, peri
func (r *GormUserRepository) GetUserCallRankingByConsumption(ctx context.Context, period string, limit int) ([]map[string]interface{}, error) {
var sql string
var args []interface{}
switch period {
case "today":
sql = `
@@ -634,13 +634,13 @@ func (r *GormUserRepository) GetUserCallRankingByConsumption(ctx context.Context
default:
return nil, fmt.Errorf("不支持的时间周期: %s", period)
}
var results []map[string]interface{}
err := r.GetDB(ctx).Raw(sql, args...).Scan(&results).Error
if err != nil {
return nil, err
}
return results, nil
}
@@ -648,7 +648,7 @@ func (r *GormUserRepository) GetUserCallRankingByConsumption(ctx context.Context
func (r *GormUserRepository) GetRechargeRanking(ctx context.Context, period string, limit int) ([]map[string]interface{}, error) {
var sql string
var args []interface{}
switch period {
case "today":
sql = `
@@ -709,12 +709,12 @@ func (r *GormUserRepository) GetRechargeRanking(ctx context.Context, period stri
default:
return nil, fmt.Errorf("不支持的时间周期: %s", period)
}
var results []map[string]interface{}
err := r.GetDB(ctx).Raw(sql, args...).Scan(&results).Error
if err != nil {
return nil, err
}
return results, nil
}
}