fix
This commit is contained in:
@@ -28,23 +28,24 @@ import (
|
|||||||
// StatisticsApplicationServiceImpl 统计应用服务实现
|
// StatisticsApplicationServiceImpl 统计应用服务实现
|
||||||
type StatisticsApplicationServiceImpl struct {
|
type StatisticsApplicationServiceImpl struct {
|
||||||
// 领域服务
|
// 领域服务
|
||||||
aggregateService services.StatisticsAggregateService
|
aggregateService services.StatisticsAggregateService
|
||||||
calculationService services.StatisticsCalculationService
|
calculationService services.StatisticsCalculationService
|
||||||
reportService services.StatisticsReportService
|
reportService services.StatisticsReportService
|
||||||
|
|
||||||
// 统计仓储
|
// 统计仓储
|
||||||
metricRepo repositories.StatisticsRepository
|
metricRepo repositories.StatisticsRepository
|
||||||
reportRepo repositories.StatisticsReportRepository
|
reportRepo repositories.StatisticsReportRepository
|
||||||
dashboardRepo repositories.StatisticsDashboardRepository
|
dashboardRepo repositories.StatisticsDashboardRepository
|
||||||
|
|
||||||
// 其他领域仓储
|
// 其他领域仓储
|
||||||
userRepo userRepos.UserRepository
|
userRepo userRepos.UserRepository
|
||||||
apiCallRepo apiRepos.ApiCallRepository
|
enterpriseInfoRepo userRepos.EnterpriseInfoRepository
|
||||||
|
apiCallRepo apiRepos.ApiCallRepository
|
||||||
walletTransactionRepo financeRepos.WalletTransactionRepository
|
walletTransactionRepo financeRepos.WalletTransactionRepository
|
||||||
rechargeRecordRepo financeRepos.RechargeRecordRepository
|
rechargeRecordRepo financeRepos.RechargeRecordRepository
|
||||||
productRepo productRepos.ProductRepository
|
productRepo productRepos.ProductRepository
|
||||||
certificationRepo certificationRepos.CertificationQueryRepository
|
certificationRepo certificationRepos.CertificationQueryRepository
|
||||||
|
|
||||||
// 日志
|
// 日志
|
||||||
logger *zap.Logger
|
logger *zap.Logger
|
||||||
}
|
}
|
||||||
@@ -58,6 +59,7 @@ func NewStatisticsApplicationService(
|
|||||||
reportRepo repositories.StatisticsReportRepository,
|
reportRepo repositories.StatisticsReportRepository,
|
||||||
dashboardRepo repositories.StatisticsDashboardRepository,
|
dashboardRepo repositories.StatisticsDashboardRepository,
|
||||||
userRepo userRepos.UserRepository,
|
userRepo userRepos.UserRepository,
|
||||||
|
enterpriseInfoRepo userRepos.EnterpriseInfoRepository,
|
||||||
apiCallRepo apiRepos.ApiCallRepository,
|
apiCallRepo apiRepos.ApiCallRepository,
|
||||||
walletTransactionRepo financeRepos.WalletTransactionRepository,
|
walletTransactionRepo financeRepos.WalletTransactionRepository,
|
||||||
rechargeRecordRepo financeRepos.RechargeRecordRepository,
|
rechargeRecordRepo financeRepos.RechargeRecordRepository,
|
||||||
@@ -73,6 +75,7 @@ func NewStatisticsApplicationService(
|
|||||||
reportRepo: reportRepo,
|
reportRepo: reportRepo,
|
||||||
dashboardRepo: dashboardRepo,
|
dashboardRepo: dashboardRepo,
|
||||||
userRepo: userRepo,
|
userRepo: userRepo,
|
||||||
|
enterpriseInfoRepo: enterpriseInfoRepo,
|
||||||
apiCallRepo: apiCallRepo,
|
apiCallRepo: apiCallRepo,
|
||||||
walletTransactionRepo: walletTransactionRepo,
|
walletTransactionRepo: walletTransactionRepo,
|
||||||
rechargeRecordRepo: rechargeRecordRepo,
|
rechargeRecordRepo: rechargeRecordRepo,
|
||||||
@@ -540,10 +543,10 @@ func (s *StatisticsApplicationServiceImpl) GetDashboardData(ctx context.Context,
|
|||||||
query.StartDate = now.Truncate(24 * time.Hour)
|
query.StartDate = now.Truncate(24 * time.Hour)
|
||||||
query.EndDate = query.StartDate.Add(24 * time.Hour)
|
query.EndDate = query.StartDate.Add(24 * time.Hour)
|
||||||
case "week":
|
case "week":
|
||||||
query.StartDate = now.Truncate(24 * time.Hour).AddDate(0, 0, -7)
|
query.StartDate = now.Truncate(24*time.Hour).AddDate(0, 0, -7)
|
||||||
query.EndDate = now
|
query.EndDate = now
|
||||||
case "month":
|
case "month":
|
||||||
query.StartDate = now.Truncate(24 * time.Hour).AddDate(0, 0, -30)
|
query.StartDate = now.Truncate(24*time.Hour).AddDate(0, 0, -30)
|
||||||
query.EndDate = now
|
query.EndDate = now
|
||||||
default:
|
default:
|
||||||
query.StartDate = now.Truncate(24 * time.Hour)
|
query.StartDate = now.Truncate(24 * time.Hour)
|
||||||
@@ -1074,7 +1077,7 @@ func (s *StatisticsApplicationServiceImpl) AdminGetSystemStatistics(ctx context.
|
|||||||
// 解析时间参数
|
// 解析时间参数
|
||||||
var startTime, endTime time.Time
|
var startTime, endTime time.Time
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
if startDate != "" {
|
if startDate != "" {
|
||||||
startTime, err = time.Parse("2006-01-02", startDate)
|
startTime, err = time.Parse("2006-01-02", startDate)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -1086,7 +1089,7 @@ func (s *StatisticsApplicationServiceImpl) AdminGetSystemStatistics(ctx context.
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if endDate != "" {
|
if endDate != "" {
|
||||||
endTime, err = time.Parse("2006-01-02", endDate)
|
endTime, err = time.Parse("2006-01-02", endDate)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -1168,7 +1171,7 @@ func (s *StatisticsApplicationServiceImpl) AdminTriggerAggregation(ctx context.C
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
s.logger.Info("管理员触发聚合成功",
|
s.logger.Info("管理员触发聚合成功",
|
||||||
zap.String("metric_type", cmd.MetricType),
|
zap.String("metric_type", cmd.MetricType),
|
||||||
zap.String("period", cmd.Period),
|
zap.String("period", cmd.Period),
|
||||||
zap.String("triggered_by", cmd.TriggeredBy))
|
zap.String("triggered_by", cmd.TriggeredBy))
|
||||||
@@ -1307,7 +1310,7 @@ func (s *StatisticsApplicationServiceImpl) getUserApiCallsStats(ctx context.Cont
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 获取本月调用次数
|
// 获取本月调用次数
|
||||||
monthStart := time.Now().Truncate(24 * time.Hour).AddDate(0, 0, -time.Now().Day()+1)
|
monthStart := time.Now().Truncate(24*time.Hour).AddDate(0, 0, -time.Now().Day()+1)
|
||||||
monthEnd := monthStart.AddDate(0, 1, 0)
|
monthEnd := monthStart.AddDate(0, 1, 0)
|
||||||
monthCalls, err := s.getApiCallsCountByDateRange(ctx, userID, monthStart, monthEnd)
|
monthCalls, err := s.getApiCallsCountByDateRange(ctx, userID, monthStart, monthEnd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -1362,7 +1365,7 @@ func (s *StatisticsApplicationServiceImpl) getUserConsumptionStats(ctx context.C
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 获取本月消费金额
|
// 获取本月消费金额
|
||||||
monthStart := time.Now().Truncate(24 * time.Hour).AddDate(0, 0, -time.Now().Day()+1)
|
monthStart := time.Now().Truncate(24*time.Hour).AddDate(0, 0, -time.Now().Day()+1)
|
||||||
monthEnd := monthStart.AddDate(0, 1, 0)
|
monthEnd := monthStart.AddDate(0, 1, 0)
|
||||||
monthAmount, err := s.getWalletTransactionsByDateRange(ctx, userID, monthStart, monthEnd)
|
monthAmount, err := s.getWalletTransactionsByDateRange(ctx, userID, monthStart, monthEnd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -1417,7 +1420,7 @@ func (s *StatisticsApplicationServiceImpl) getUserRechargeStats(ctx context.Cont
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 获取本月充值金额
|
// 获取本月充值金额
|
||||||
monthStart := time.Now().Truncate(24 * time.Hour).AddDate(0, 0, -time.Now().Day()+1)
|
monthStart := time.Now().Truncate(24*time.Hour).AddDate(0, 0, -time.Now().Day()+1)
|
||||||
monthEnd := monthStart.AddDate(0, 1, 0)
|
monthEnd := monthStart.AddDate(0, 1, 0)
|
||||||
monthAmount, err := s.getRechargeRecordsByDateRange(ctx, userID, monthStart, monthEnd)
|
monthAmount, err := s.getRechargeRecordsByDateRange(ctx, userID, monthStart, monthEnd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -1656,10 +1659,10 @@ func (s *StatisticsApplicationServiceImpl) getUserStats(ctx context.Context, per
|
|||||||
}
|
}
|
||||||
|
|
||||||
stats := map[string]interface{}{
|
stats := map[string]interface{}{
|
||||||
"total_users": userStats.TotalUsers,
|
"total_users": userStats.TotalUsers,
|
||||||
"new_today": userStats.TodayRegistrations,
|
"new_today": userStats.TodayRegistrations,
|
||||||
"new_in_range": newInRange,
|
"new_in_range": newInRange,
|
||||||
"daily_trend": trendData,
|
"daily_trend": trendData,
|
||||||
}
|
}
|
||||||
return stats, nil
|
return stats, nil
|
||||||
}
|
}
|
||||||
@@ -1703,10 +1706,10 @@ func (s *StatisticsApplicationServiceImpl) getCertificationStats(ctx context.Con
|
|||||||
}
|
}
|
||||||
|
|
||||||
stats := map[string]interface{}{
|
stats := map[string]interface{}{
|
||||||
"total_certified": userStats.CertifiedUsers,
|
"total_certified": userStats.CertifiedUsers,
|
||||||
"certified_today": userStats.TodayRegistrations, // 今日注册的用户
|
"certified_today": userStats.TodayRegistrations, // 今日注册的用户
|
||||||
"success_rate": successRate,
|
"success_rate": successRate,
|
||||||
"daily_trend": trendData,
|
"daily_trend": trendData,
|
||||||
}
|
}
|
||||||
return stats, nil
|
return stats, nil
|
||||||
}
|
}
|
||||||
@@ -1753,9 +1756,9 @@ func (s *StatisticsApplicationServiceImpl) getSystemApiCallStats(ctx context.Con
|
|||||||
}
|
}
|
||||||
|
|
||||||
stats := map[string]interface{}{
|
stats := map[string]interface{}{
|
||||||
"total_calls": totalCalls,
|
"total_calls": totalCalls,
|
||||||
"calls_today": todayCalls,
|
"calls_today": todayCalls,
|
||||||
"daily_trend": trendData,
|
"daily_trend": trendData,
|
||||||
}
|
}
|
||||||
return stats, nil
|
return stats, nil
|
||||||
}
|
}
|
||||||
@@ -1844,11 +1847,11 @@ func (s *StatisticsApplicationServiceImpl) getSystemFinanceStats(ctx context.Con
|
|||||||
}
|
}
|
||||||
|
|
||||||
stats := map[string]interface{}{
|
stats := map[string]interface{}{
|
||||||
"total_deduct": totalConsumption,
|
"total_deduct": totalConsumption,
|
||||||
"deduct_today": todayConsumption,
|
"deduct_today": todayConsumption,
|
||||||
"total_recharge": totalRecharge,
|
"total_recharge": totalRecharge,
|
||||||
"recharge_today": todayRecharge,
|
"recharge_today": todayRecharge,
|
||||||
"daily_trend": trendData,
|
"daily_trend": trendData,
|
||||||
}
|
}
|
||||||
return stats, nil
|
return stats, nil
|
||||||
}
|
}
|
||||||
@@ -1858,12 +1861,12 @@ func (s *StatisticsApplicationServiceImpl) mergeFinanceTrends(consumptionTrend,
|
|||||||
// 创建日期到数据的映射
|
// 创建日期到数据的映射
|
||||||
consumptionMap := make(map[string]float64)
|
consumptionMap := make(map[string]float64)
|
||||||
rechargeMap := make(map[string]float64)
|
rechargeMap := make(map[string]float64)
|
||||||
|
|
||||||
// 处理消费数据
|
// 处理消费数据
|
||||||
for _, item := range consumptionTrend {
|
for _, item := range consumptionTrend {
|
||||||
var dateKey string
|
var dateKey string
|
||||||
var amount float64
|
var amount float64
|
||||||
|
|
||||||
if period == "day" {
|
if period == "day" {
|
||||||
if date, ok := item["date"].(string); ok {
|
if date, ok := item["date"].(string); ok {
|
||||||
dateKey = date
|
dateKey = date
|
||||||
@@ -1879,17 +1882,17 @@ func (s *StatisticsApplicationServiceImpl) mergeFinanceTrends(consumptionTrend,
|
|||||||
amount = amt
|
amount = amt
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if dateKey != "" {
|
if dateKey != "" {
|
||||||
consumptionMap[dateKey] = amount
|
consumptionMap[dateKey] = amount
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 处理充值数据
|
// 处理充值数据
|
||||||
for _, item := range rechargeTrend {
|
for _, item := range rechargeTrend {
|
||||||
var dateKey string
|
var dateKey string
|
||||||
var amount float64
|
var amount float64
|
||||||
|
|
||||||
if period == "day" {
|
if period == "day" {
|
||||||
if date, ok := item["date"].(string); ok {
|
if date, ok := item["date"].(string); ok {
|
||||||
dateKey = date
|
dateKey = date
|
||||||
@@ -1905,16 +1908,16 @@ func (s *StatisticsApplicationServiceImpl) mergeFinanceTrends(consumptionTrend,
|
|||||||
amount = amt
|
amount = amt
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if dateKey != "" {
|
if dateKey != "" {
|
||||||
rechargeMap[dateKey] = amount
|
rechargeMap[dateKey] = amount
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 合并数据
|
// 合并数据
|
||||||
var mergedTrend []map[string]interface{}
|
var mergedTrend []map[string]interface{}
|
||||||
allDates := make(map[string]bool)
|
allDates := make(map[string]bool)
|
||||||
|
|
||||||
// 收集所有日期
|
// 收集所有日期
|
||||||
for date := range consumptionMap {
|
for date := range consumptionMap {
|
||||||
allDates[date] = true
|
allDates[date] = true
|
||||||
@@ -1922,12 +1925,12 @@ func (s *StatisticsApplicationServiceImpl) mergeFinanceTrends(consumptionTrend,
|
|||||||
for date := range rechargeMap {
|
for date := range rechargeMap {
|
||||||
allDates[date] = true
|
allDates[date] = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// 按日期排序并合并
|
// 按日期排序并合并
|
||||||
for date := range allDates {
|
for date := range allDates {
|
||||||
consumption := consumptionMap[date]
|
consumption := consumptionMap[date]
|
||||||
recharge := rechargeMap[date]
|
recharge := rechargeMap[date]
|
||||||
|
|
||||||
item := map[string]interface{}{
|
item := map[string]interface{}{
|
||||||
"date": date,
|
"date": date,
|
||||||
"deduct": consumption,
|
"deduct": consumption,
|
||||||
@@ -1935,7 +1938,7 @@ func (s *StatisticsApplicationServiceImpl) mergeFinanceTrends(consumptionTrend,
|
|||||||
}
|
}
|
||||||
mergedTrend = append(mergedTrend, item)
|
mergedTrend = append(mergedTrend, item)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 简单排序(按日期字符串)
|
// 简单排序(按日期字符串)
|
||||||
for i := 0; i < len(mergedTrend)-1; i++ {
|
for i := 0; i < len(mergedTrend)-1; i++ {
|
||||||
for j := i + 1; j < len(mergedTrend); j++ {
|
for j := i + 1; j < len(mergedTrend); j++ {
|
||||||
@@ -1944,7 +1947,7 @@ func (s *StatisticsApplicationServiceImpl) mergeFinanceTrends(consumptionTrend,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return mergedTrend
|
return mergedTrend
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1953,20 +1956,20 @@ func (s *StatisticsApplicationServiceImpl) getUserDailyTrend(ctx context.Context
|
|||||||
// 生成最近N天的日期列表
|
// 生成最近N天的日期列表
|
||||||
var trend []map[string]interface{}
|
var trend []map[string]interface{}
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
|
|
||||||
for i := days - 1; i >= 0; i-- {
|
for i := days - 1; i >= 0; i-- {
|
||||||
date := now.AddDate(0, 0, -i).Truncate(24 * time.Hour)
|
date := now.AddDate(0, 0, -i).Truncate(24 * time.Hour)
|
||||||
|
|
||||||
// 这里需要实现按日期查询用户注册数的逻辑
|
// 这里需要实现按日期查询用户注册数的逻辑
|
||||||
// 暂时使用模拟数据
|
// 暂时使用模拟数据
|
||||||
count := int64(10 + i*2) // 模拟数据
|
count := int64(10 + i*2) // 模拟数据
|
||||||
|
|
||||||
trend = append(trend, map[string]interface{}{
|
trend = append(trend, map[string]interface{}{
|
||||||
"date": date.Format("2006-01-02"),
|
"date": date.Format("2006-01-02"),
|
||||||
"count": count,
|
"count": count,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return trend, nil
|
return trend, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1975,20 +1978,20 @@ func (s *StatisticsApplicationServiceImpl) getCertificationDailyTrend(ctx contex
|
|||||||
// 生成最近N天的日期列表
|
// 生成最近N天的日期列表
|
||||||
var trend []map[string]interface{}
|
var trend []map[string]interface{}
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
|
|
||||||
for i := days - 1; i >= 0; i-- {
|
for i := days - 1; i >= 0; i-- {
|
||||||
date := now.AddDate(0, 0, -i).Truncate(24 * time.Hour)
|
date := now.AddDate(0, 0, -i).Truncate(24 * time.Hour)
|
||||||
|
|
||||||
// 这里需要实现按日期查询认证数的逻辑
|
// 这里需要实现按日期查询认证数的逻辑
|
||||||
// 暂时使用模拟数据
|
// 暂时使用模拟数据
|
||||||
count := int64(5 + i) // 模拟数据
|
count := int64(5 + i) // 模拟数据
|
||||||
|
|
||||||
trend = append(trend, map[string]interface{}{
|
trend = append(trend, map[string]interface{}{
|
||||||
"date": date.Format("2006-01-02"),
|
"date": date.Format("2006-01-02"),
|
||||||
"count": count,
|
"count": count,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return trend, nil
|
return trend, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2010,7 +2013,7 @@ func (s *StatisticsApplicationServiceImpl) getRechargeRecordsByDateRange(ctx con
|
|||||||
|
|
||||||
// GetApiCallsStatistics 获取API调用统计
|
// GetApiCallsStatistics 获取API调用统计
|
||||||
func (s *StatisticsApplicationServiceImpl) GetApiCallsStatistics(ctx context.Context, userID string, startDate, endDate time.Time, unit string) (*QueryResponse, error) {
|
func (s *StatisticsApplicationServiceImpl) GetApiCallsStatistics(ctx context.Context, userID string, startDate, endDate time.Time, unit string) (*QueryResponse, error) {
|
||||||
s.logger.Info("获取API调用统计",
|
s.logger.Info("获取API调用统计",
|
||||||
zap.String("user_id", userID),
|
zap.String("user_id", userID),
|
||||||
zap.Time("start_date", startDate),
|
zap.Time("start_date", startDate),
|
||||||
zap.Time("end_date", endDate),
|
zap.Time("end_date", endDate),
|
||||||
@@ -2061,7 +2064,7 @@ func (s *StatisticsApplicationServiceImpl) GetApiCallsStatistics(ctx context.Con
|
|||||||
|
|
||||||
// GetConsumptionStatistics 获取消费统计
|
// GetConsumptionStatistics 获取消费统计
|
||||||
func (s *StatisticsApplicationServiceImpl) GetConsumptionStatistics(ctx context.Context, userID string, startDate, endDate time.Time, unit string) (*QueryResponse, error) {
|
func (s *StatisticsApplicationServiceImpl) GetConsumptionStatistics(ctx context.Context, userID string, startDate, endDate time.Time, unit string) (*QueryResponse, error) {
|
||||||
s.logger.Info("获取消费统计",
|
s.logger.Info("获取消费统计",
|
||||||
zap.String("user_id", userID),
|
zap.String("user_id", userID),
|
||||||
zap.Time("start_date", startDate),
|
zap.Time("start_date", startDate),
|
||||||
zap.Time("end_date", endDate),
|
zap.Time("end_date", endDate),
|
||||||
@@ -2112,7 +2115,7 @@ func (s *StatisticsApplicationServiceImpl) GetConsumptionStatistics(ctx context.
|
|||||||
|
|
||||||
// GetRechargeStatistics 获取充值统计
|
// GetRechargeStatistics 获取充值统计
|
||||||
func (s *StatisticsApplicationServiceImpl) GetRechargeStatistics(ctx context.Context, userID string, startDate, endDate time.Time, unit string) (*QueryResponse, error) {
|
func (s *StatisticsApplicationServiceImpl) GetRechargeStatistics(ctx context.Context, userID string, startDate, endDate time.Time, unit string) (*QueryResponse, error) {
|
||||||
s.logger.Info("获取充值统计",
|
s.logger.Info("获取充值统计",
|
||||||
zap.String("user_id", userID),
|
zap.String("user_id", userID),
|
||||||
zap.Time("start_date", startDate),
|
zap.Time("start_date", startDate),
|
||||||
zap.Time("end_date", endDate),
|
zap.Time("end_date", endDate),
|
||||||
@@ -2174,7 +2177,7 @@ func (s *StatisticsApplicationServiceImpl) GetLatestProducts(ctx context.Context
|
|||||||
SortBy: "created_at",
|
SortBy: "created_at",
|
||||||
SortOrder: "desc",
|
SortOrder: "desc",
|
||||||
}
|
}
|
||||||
|
|
||||||
productsList, _, err := s.productRepo.ListProducts(ctx, query)
|
productsList, _, err := s.productRepo.ListProducts(ctx, query)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.logger.Error("获取最新产品失败", zap.Error(err))
|
s.logger.Error("获取最新产品失败", zap.Error(err))
|
||||||
@@ -2247,11 +2250,11 @@ func (s *StatisticsApplicationServiceImpl) AdminGetUserDomainStatistics(ctx cont
|
|||||||
}
|
}
|
||||||
|
|
||||||
result := map[string]interface{}{
|
result := map[string]interface{}{
|
||||||
"user_stats": userStats,
|
"user_stats": userStats,
|
||||||
"certification_stats": certificationStats,
|
"certification_stats": certificationStats,
|
||||||
"period": period,
|
"period": period,
|
||||||
"start_date": startDate,
|
"start_date": startDate,
|
||||||
"end_date": endDate,
|
"end_date": endDate,
|
||||||
}
|
}
|
||||||
|
|
||||||
return &QueryResponse{
|
return &QueryResponse{
|
||||||
@@ -2333,9 +2336,19 @@ func (s *StatisticsApplicationServiceImpl) AdminGetConsumptionDomainStatistics(c
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
todayConsumption := float64(0)
|
// 获取今日消费金额
|
||||||
|
today := time.Now().Truncate(24 * time.Hour)
|
||||||
|
tomorrow := today.Add(24 * time.Hour)
|
||||||
|
todayConsumption, err := s.walletTransactionRepo.GetSystemAmountByDateRange(ctx, today, tomorrow)
|
||||||
|
if err != nil {
|
||||||
|
s.logger.Error("获取今日消费金额失败", zap.Error(err))
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取指定时间范围内的消费金额
|
||||||
|
rangeConsumption := float64(0)
|
||||||
if !startTime.IsZero() && !endTime.IsZero() {
|
if !startTime.IsZero() && !endTime.IsZero() {
|
||||||
todayConsumption, err = s.walletTransactionRepo.GetSystemAmountByDateRange(ctx, startTime, endTime)
|
rangeConsumption, err = s.walletTransactionRepo.GetSystemAmountByDateRange(ctx, startTime, endTime)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.logger.Error("获取指定时间范围消费金额失败", zap.Error(err))
|
s.logger.Error("获取指定时间范围消费金额失败", zap.Error(err))
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -2355,12 +2368,13 @@ func (s *StatisticsApplicationServiceImpl) AdminGetConsumptionDomainStatistics(c
|
|||||||
}
|
}
|
||||||
|
|
||||||
result := map[string]interface{}{
|
result := map[string]interface{}{
|
||||||
"total_consumption": totalConsumption,
|
"total_consumption": totalConsumption,
|
||||||
"range_consumption": todayConsumption,
|
"today_consumption": todayConsumption,
|
||||||
"consumption_trend": consumptionTrend,
|
"range_consumption": rangeConsumption,
|
||||||
"period": period,
|
"consumption_trend": consumptionTrend,
|
||||||
"start_date": startDate,
|
"period": period,
|
||||||
"end_date": endDate,
|
"start_date": startDate,
|
||||||
|
"end_date": endDate,
|
||||||
}
|
}
|
||||||
|
|
||||||
return &QueryResponse{
|
return &QueryResponse{
|
||||||
@@ -2399,9 +2413,19 @@ func (s *StatisticsApplicationServiceImpl) AdminGetRechargeDomainStatistics(ctx
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
todayRecharge := float64(0)
|
// 获取今日充值金额
|
||||||
|
today := time.Now().Truncate(24 * time.Hour)
|
||||||
|
tomorrow := today.Add(24 * time.Hour)
|
||||||
|
todayRecharge, err := s.rechargeRecordRepo.GetSystemAmountByDateRange(ctx, today, tomorrow)
|
||||||
|
if err != nil {
|
||||||
|
s.logger.Error("获取今日充值金额失败", zap.Error(err))
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取指定时间范围内的充值金额
|
||||||
|
rangeRecharge := float64(0)
|
||||||
if !startTime.IsZero() && !endTime.IsZero() {
|
if !startTime.IsZero() && !endTime.IsZero() {
|
||||||
todayRecharge, err = s.rechargeRecordRepo.GetSystemAmountByDateRange(ctx, startTime, endTime)
|
rangeRecharge, err = s.rechargeRecordRepo.GetSystemAmountByDateRange(ctx, startTime, endTime)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.logger.Error("获取指定时间范围充值金额失败", zap.Error(err))
|
s.logger.Error("获取指定时间范围充值金额失败", zap.Error(err))
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -2421,12 +2445,13 @@ func (s *StatisticsApplicationServiceImpl) AdminGetRechargeDomainStatistics(ctx
|
|||||||
}
|
}
|
||||||
|
|
||||||
result := map[string]interface{}{
|
result := map[string]interface{}{
|
||||||
"total_recharge": totalRecharge,
|
"total_recharge": totalRecharge,
|
||||||
"range_recharge": todayRecharge,
|
"today_recharge": todayRecharge,
|
||||||
"recharge_trend": rechargeTrend,
|
"range_recharge": rangeRecharge,
|
||||||
"period": period,
|
"recharge_trend": rechargeTrend,
|
||||||
"start_date": startDate,
|
"period": period,
|
||||||
"end_date": endDate,
|
"start_date": startDate,
|
||||||
|
"end_date": endDate,
|
||||||
}
|
}
|
||||||
|
|
||||||
return &QueryResponse{
|
return &QueryResponse{
|
||||||
@@ -2535,12 +2560,12 @@ func (s *StatisticsApplicationServiceImpl) getUserCallRankingByCalls(ctx context
|
|||||||
s.logger.Error("获取用户调用次数排行失败", zap.Error(err))
|
s.logger.Error("获取用户调用次数排行失败", zap.Error(err))
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 添加排名信息
|
// 添加排名信息
|
||||||
for i, ranking := range rankings {
|
for i, ranking := range rankings {
|
||||||
ranking["rank"] = i + 1
|
ranking["rank"] = i + 1
|
||||||
}
|
}
|
||||||
|
|
||||||
return rankings, nil
|
return rankings, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2552,12 +2577,12 @@ func (s *StatisticsApplicationServiceImpl) getUserCallRankingByConsumption(ctx c
|
|||||||
s.logger.Error("获取用户消费金额排行失败", zap.Error(err))
|
s.logger.Error("获取用户消费金额排行失败", zap.Error(err))
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 添加排名信息
|
// 添加排名信息
|
||||||
for i, ranking := range rankings {
|
for i, ranking := range rankings {
|
||||||
ranking["rank"] = i + 1
|
ranking["rank"] = i + 1
|
||||||
}
|
}
|
||||||
|
|
||||||
return rankings, nil
|
return rankings, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2569,12 +2594,12 @@ func (s *StatisticsApplicationServiceImpl) getRechargeRanking(ctx context.Contex
|
|||||||
s.logger.Error("获取充值排行失败", zap.Error(err))
|
s.logger.Error("获取充值排行失败", zap.Error(err))
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 添加排名信息
|
// 添加排名信息
|
||||||
for i, ranking := range rankings {
|
for i, ranking := range rankings {
|
||||||
ranking["rank"] = i + 1
|
ranking["rank"] = i + 1
|
||||||
}
|
}
|
||||||
|
|
||||||
return rankings, nil
|
return rankings, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2588,7 +2613,7 @@ func (s *StatisticsApplicationServiceImpl) AdminGetApiPopularityRanking(ctx cont
|
|||||||
s.logger.Error("获取API受欢迎程度排行榜失败", zap.Error(err))
|
s.logger.Error("获取API受欢迎程度排行榜失败", zap.Error(err))
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 添加排名信息
|
// 添加排名信息
|
||||||
for i, ranking := range rankings {
|
for i, ranking := range rankings {
|
||||||
ranking["rank"] = i + 1
|
ranking["rank"] = i + 1
|
||||||
@@ -2616,11 +2641,11 @@ func (s *StatisticsApplicationServiceImpl) AdminGetTodayCertifiedEnterprises(ctx
|
|||||||
|
|
||||||
// 查询所有已完成的认证,然后过滤今日完成的
|
// 查询所有已完成的认证,然后过滤今日完成的
|
||||||
query := &certificationQueries.ListCertificationsQuery{
|
query := &certificationQueries.ListCertificationsQuery{
|
||||||
Page: 1,
|
Page: 1,
|
||||||
PageSize: 1000, // 设置较大的页面大小以获取所有数据
|
PageSize: 1000, // 设置较大的页面大小以获取所有数据
|
||||||
SortBy: "updated_at",
|
SortBy: "updated_at",
|
||||||
SortOrder: "desc",
|
SortOrder: "desc",
|
||||||
Status: certificationEnums.StatusCompleted,
|
Status: certificationEnums.StatusCompleted,
|
||||||
}
|
}
|
||||||
|
|
||||||
certifications, _, err := s.certificationRepo.List(ctx, query)
|
certifications, _, err := s.certificationRepo.List(ctx, query)
|
||||||
@@ -2632,9 +2657,9 @@ func (s *StatisticsApplicationServiceImpl) AdminGetTodayCertifiedEnterprises(ctx
|
|||||||
// 过滤出今日完成的认证(基于completed_at字段)
|
// 过滤出今日完成的认证(基于completed_at字段)
|
||||||
var completedCertifications []*certificationEntities.Certification
|
var completedCertifications []*certificationEntities.Certification
|
||||||
for _, cert := range certifications {
|
for _, cert := range certifications {
|
||||||
if cert.CompletedAt != nil &&
|
if cert.CompletedAt != nil &&
|
||||||
cert.CompletedAt.After(todayStart) &&
|
cert.CompletedAt.After(todayStart) &&
|
||||||
cert.CompletedAt.Before(todayEnd) {
|
cert.CompletedAt.Before(todayEnd) {
|
||||||
completedCertifications = append(completedCertifications, cert)
|
completedCertifications = append(completedCertifications, cert)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2653,26 +2678,33 @@ func (s *StatisticsApplicationServiceImpl) AdminGetTodayCertifiedEnterprises(ctx
|
|||||||
completedCertifications = completedCertifications[:limit]
|
completedCertifications = completedCertifications[:limit]
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取用户信息
|
// 直接从企业信息表获取数据
|
||||||
var enterprises []map[string]interface{}
|
var enterprises []map[string]interface{}
|
||||||
for _, cert := range completedCertifications {
|
for _, cert := range completedCertifications {
|
||||||
|
// 获取企业信息
|
||||||
|
enterpriseInfo, err := s.enterpriseInfoRepo.GetByUserID(ctx, cert.UserID)
|
||||||
|
if err != nil {
|
||||||
|
s.logger.Warn("获取企业信息失败", zap.String("user_id", cert.UserID), zap.Error(err))
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取用户基本信息(仅需要用户名)
|
||||||
user, err := s.userRepo.GetByID(ctx, cert.UserID)
|
user, err := s.userRepo.GetByID(ctx, cert.UserID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.logger.Warn("获取用户信息失败", zap.String("user_id", cert.UserID), zap.Error(err))
|
s.logger.Warn("获取用户信息失败", zap.String("user_id", cert.UserID), zap.Error(err))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
enterpriseName := ""
|
|
||||||
if user.EnterpriseInfo != nil {
|
|
||||||
enterpriseName = user.EnterpriseInfo.CompanyName
|
|
||||||
}
|
|
||||||
|
|
||||||
enterprise := map[string]interface{}{
|
enterprise := map[string]interface{}{
|
||||||
"id": cert.ID,
|
"id": cert.ID,
|
||||||
"user_id": cert.UserID,
|
"user_id": cert.UserID,
|
||||||
"username": user.Username,
|
"username": user.Username,
|
||||||
"enterprise_name": enterpriseName,
|
"enterprise_name": enterpriseInfo.CompanyName,
|
||||||
"certified_at": cert.CompletedAt.Format(time.RFC3339),
|
"legal_person_name": enterpriseInfo.LegalPersonName,
|
||||||
|
"legal_person_phone": enterpriseInfo.LegalPersonPhone,
|
||||||
|
"unified_social_code": enterpriseInfo.UnifiedSocialCode,
|
||||||
|
"enterprise_address": enterpriseInfo.EnterpriseAddress,
|
||||||
|
"certified_at": cert.CompletedAt.Format(time.RFC3339),
|
||||||
}
|
}
|
||||||
enterprises = append(enterprises, enterprise)
|
enterprises = append(enterprises, enterprise)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -925,6 +925,7 @@ func NewContainer() *Container {
|
|||||||
reportRepo domain_statistics_repo.StatisticsReportRepository,
|
reportRepo domain_statistics_repo.StatisticsReportRepository,
|
||||||
dashboardRepo domain_statistics_repo.StatisticsDashboardRepository,
|
dashboardRepo domain_statistics_repo.StatisticsDashboardRepository,
|
||||||
userRepo domain_user_repo.UserRepository,
|
userRepo domain_user_repo.UserRepository,
|
||||||
|
enterpriseInfoRepo domain_user_repo.EnterpriseInfoRepository,
|
||||||
apiCallRepo domain_api_repo.ApiCallRepository,
|
apiCallRepo domain_api_repo.ApiCallRepository,
|
||||||
walletTransactionRepo domain_finance_repo.WalletTransactionRepository,
|
walletTransactionRepo domain_finance_repo.WalletTransactionRepository,
|
||||||
rechargeRecordRepo domain_finance_repo.RechargeRecordRepository,
|
rechargeRecordRepo domain_finance_repo.RechargeRecordRepository,
|
||||||
@@ -940,6 +941,7 @@ func NewContainer() *Container {
|
|||||||
reportRepo,
|
reportRepo,
|
||||||
dashboardRepo,
|
dashboardRepo,
|
||||||
userRepo,
|
userRepo,
|
||||||
|
enterpriseInfoRepo,
|
||||||
apiCallRepo,
|
apiCallRepo,
|
||||||
walletTransactionRepo,
|
walletTransactionRepo,
|
||||||
rechargeRecordRepo,
|
rechargeRecordRepo,
|
||||||
|
|||||||
Reference in New Issue
Block a user