From a47c306c87cc35dee58782eb3e32ac63b8653acb Mon Sep 17 00:00:00 2001 From: 18278715334 <18278715334@163.com> Date: Mon, 8 Dec 2025 14:03:14 +0800 Subject: [PATCH] 18278715334@163.com --- .../statistics_application_service_impl.go | 74 ++++++++++++++----- .../api/services/form_config_service.go | 2 +- .../processors/qygl/qygl2s0w_processor.go | 18 ++--- .../repositories/user_repository_interface.go | 2 + .../repositories/user/gorm_user_repository.go | 48 ++++++++++++ 5 files changed, 111 insertions(+), 33 deletions(-) diff --git a/internal/application/statistics/statistics_application_service_impl.go b/internal/application/statistics/statistics_application_service_impl.go index a0c0cf3..5cc1d19 100644 --- a/internal/application/statistics/statistics_application_service_impl.go +++ b/internal/application/statistics/statistics_application_service_impl.go @@ -1301,8 +1301,10 @@ func (s *StatisticsApplicationServiceImpl) getUserApiCallsStats(ctx context.Cont } // 获取今日调用次数 - today := time.Now().Truncate(24 * time.Hour) - tomorrow := today.Add(24 * time.Hour) + loc, _ := time.LoadLocation("Asia/Shanghai") // 东八时区 + now := time.Now().In(loc) + today := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, loc) // 当天0点 + tomorrow := today.AddDate(0, 0, 1) // 次日0点 todayCalls, err := s.getApiCallsCountByDateRange(ctx, userID, today, tomorrow) if err != nil { s.logger.Error("获取今日API调用次数失败", zap.String("user_id", userID), zap.Error(err)) @@ -1356,8 +1358,10 @@ func (s *StatisticsApplicationServiceImpl) getUserConsumptionStats(ctx context.C } // 获取今日消费金额 - today := time.Now().Truncate(24 * time.Hour) - tomorrow := today.Add(24 * time.Hour) + loc, _ := time.LoadLocation("Asia/Shanghai") // 东八时区 + now := time.Now().In(loc) + today := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, loc) // 当天0点 + tomorrow := today.AddDate(0, 0, 1) // 次日0点 todayAmount, err := s.getWalletTransactionsByDateRange(ctx, userID, today, tomorrow) if err != nil { s.logger.Error("获取今日消费金额失败", zap.String("user_id", userID), zap.Error(err)) @@ -1411,8 +1415,10 @@ func (s *StatisticsApplicationServiceImpl) getUserRechargeStats(ctx context.Cont } // 获取今日充值金额 - today := time.Now().Truncate(24 * time.Hour) - tomorrow := today.Add(24 * time.Hour) + loc, _ := time.LoadLocation("Asia/Shanghai") // 东八时区 + now := time.Now().In(loc) + today := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, loc) // 当天0点 + tomorrow := today.AddDate(0, 0, 1) // 次日0点 todayAmount, err := s.getRechargeRecordsByDateRange(ctx, userID, today, tomorrow) if err != nil { s.logger.Error("获取今日充值金额失败", zap.String("user_id", userID), zap.Error(err)) @@ -1682,13 +1688,13 @@ func (s *StatisticsApplicationServiceImpl) getCertificationStats(ctx context.Con successRate = float64(userStats.CertifiedUsers) / float64(userStats.TotalUsers) } - // 根据时间范围获取趋势数据 + // 根据时间范围获取认证趋势数据(基于is_certified字段) var trendData []map[string]interface{} if !startTime.IsZero() && !endTime.IsZero() { if period == "day" { - trendData, err = s.userRepo.GetSystemDailyUserStats(ctx, startTime, endTime) + trendData, err = s.userRepo.GetSystemDailyCertificationStats(ctx, startTime, endTime) } else if period == "month" { - trendData, err = s.userRepo.GetSystemMonthlyUserStats(ctx, startTime, endTime) + trendData, err = s.userRepo.GetSystemMonthlyCertificationStats(ctx, startTime, endTime) } if err != nil { s.logger.Error("获取认证趋势数据失败", zap.Error(err)) @@ -1698,16 +1704,35 @@ func (s *StatisticsApplicationServiceImpl) getCertificationStats(ctx context.Con // 默认获取最近7天的数据 endDate := time.Now() startDate := endDate.AddDate(0, 0, -7) - trendData, err = s.userRepo.GetSystemDailyUserStats(ctx, startDate, endDate) + trendData, err = s.userRepo.GetSystemDailyCertificationStats(ctx, startDate, endDate) if err != nil { s.logger.Error("获取认证每日趋势失败", zap.Error(err)) return nil, err } } + // 获取今日认证用户数(基于is_certified字段,东八时区) + loc, _ := time.LoadLocation("Asia/Shanghai") // 东八时区 + now := time.Now().In(loc) + today := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, loc) // 当天0点 + tomorrow := today.AddDate(0, 0, 1) // 次日0点 + + var certifiedToday int64 + todayCertStats, err := s.userRepo.GetSystemDailyCertificationStats(ctx, today, tomorrow) + if err == nil && len(todayCertStats) > 0 { + // 累加今日所有认证用户数 + for _, stat := range todayCertStats { + if count, ok := stat["count"].(int64); ok { + certifiedToday += count + } else if count, ok := stat["count"].(int); ok { + certifiedToday += int64(count) + } + } + } + stats := map[string]interface{}{ "total_certified": userStats.CertifiedUsers, - "certified_today": userStats.TodayRegistrations, // 今日注册的用户 + "certified_today": certifiedToday, // 今日认证的用户数(基于is_certified字段) "success_rate": successRate, "daily_trend": trendData, } @@ -1723,9 +1748,11 @@ func (s *StatisticsApplicationServiceImpl) getSystemApiCallStats(ctx context.Con return nil, err } - // 获取今日API调用次数 - today := time.Now().Truncate(24 * time.Hour) - tomorrow := today.Add(24 * time.Hour) + // 获取今日API调用次数(东八时区) + loc, _ := time.LoadLocation("Asia/Shanghai") // 东八时区 + now := time.Now().In(loc) + today := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, loc) // 当天0点 + tomorrow := today.AddDate(0, 0, 1) // 次日0点 todayCalls, err := s.apiCallRepo.GetSystemCallsByDateRange(ctx, today, tomorrow) if err != nil { s.logger.Error("获取今日API调用次数失败", zap.Error(err)) @@ -1780,8 +1807,11 @@ func (s *StatisticsApplicationServiceImpl) getSystemFinanceStats(ctx context.Con } // 获取今日消费金额 - today := time.Now().Truncate(24 * time.Hour) - tomorrow := today.Add(24 * time.Hour) + loc, _ := time.LoadLocation("Asia/Shanghai") // 东八时区 + now := time.Now().In(loc) + today := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, loc) // 当天0点 + tomorrow := today.AddDate(0, 0, 1) // 次日0点 + todayConsumption, err := s.walletTransactionRepo.GetSystemAmountByDateRange(ctx, today, tomorrow) if err != nil { s.logger.Error("获取今日消费金额失败", zap.Error(err)) @@ -2359,8 +2389,10 @@ func (s *StatisticsApplicationServiceImpl) AdminGetConsumptionDomainStatistics(c } // 获取今日消费金额 - today := time.Now().Truncate(24 * time.Hour) - tomorrow := today.Add(24 * time.Hour) + loc, _ := time.LoadLocation("Asia/Shanghai") // 东八时区 + now := time.Now().In(loc) + today := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, loc) // 当天0点 + tomorrow := today.AddDate(0, 0, 1) // 次日0点 todayConsumption, err := s.walletTransactionRepo.GetSystemAmountByDateRange(ctx, today, tomorrow) if err != nil { s.logger.Error("获取今日消费金额失败", zap.Error(err)) @@ -2459,8 +2491,10 @@ func (s *StatisticsApplicationServiceImpl) AdminGetRechargeDomainStatistics(ctx } // 获取今日充值金额 - today := time.Now().Truncate(24 * time.Hour) - tomorrow := today.Add(24 * time.Hour) + loc, _ := time.LoadLocation("Asia/Shanghai") // 东八时区 + now := time.Now().In(loc) + today := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, loc) // 当天0点 + tomorrow := today.AddDate(0, 0, 1) // 次日0点 todayRecharge, err := s.rechargeRecordRepo.GetSystemAmountByDateRange(ctx, today, tomorrow) if err != nil { s.logger.Error("获取今日充值金额失败", zap.Error(err)) diff --git a/internal/domains/api/services/form_config_service.go b/internal/domains/api/services/form_config_service.go index 41a8632..5e94f91 100644 --- a/internal/domains/api/services/form_config_service.go +++ b/internal/domains/api/services/form_config_service.go @@ -551,7 +551,7 @@ func (s *FormConfigServiceImpl) generateDescription(jsonTag string, validation s "return_type": "返回类型:1-专业和学校名称数据返回编码形式(默认);2-专业和学校名称数据返回中文名称", "photo_data": "人脸图片(必填):base64编码的图片数据,仅支持JPG、BMP、PNG三种格式", "owner_type": "企业主类型编码:1-法定代表人;2-主要人员;3-自然人股东;4-法定代表人及自然人股东;5-其他", - "type": "查询类型:per-人员,ent-企业 1", + "type": "查询类型:per-人员,ent-企业 目前只能选择企业 ", "query_reason_id": "查询原因ID:1-授信审批;2-贷中管理;3-贷后管理;4-异议处理;5-担保查询;6-租赁资质审查;7-融资租赁审批;8-借贷撮合查询;9-保险审批;10-资质审核;11-风控审核;12-企业背调", } diff --git a/internal/domains/api/services/processors/qygl/qygl2s0w_processor.go b/internal/domains/api/services/processors/qygl/qygl2s0w_processor.go index 5e493d6..cb892c6 100644 --- a/internal/domains/api/services/processors/qygl/qygl2s0w_processor.go +++ b/internal/domains/api/services/processors/qygl/qygl2s0w_processor.go @@ -26,31 +26,25 @@ func ProcessQYGL2S0WRequest(ctx context.Context, params []byte, deps *processors var nameValue string if paramsDto.Type == "per" { // 个人查询:idCardNum 必填 - fmt.Print("个人") nameValue = paramsDto.Name - fmt.Println("nameValue", nameValue) if paramsDto.IDCard == "" { fmt.Print("个人身份证件号不能为空") return nil, fmt.Errorf("%s: %w", processors.ErrInvalidParam, errors.New("当失信被执行人类型为个人时,身份证件号不能为空")) - } } else if paramsDto.Type == "ent" { // 企业查询:name 和 entMark 两者必填其一 + nameValue = paramsDto.EntName if paramsDto.EntName == "" && paramsDto.EntCode == "" { return nil, fmt.Errorf("%s: %w", processors.ErrInvalidParam, errors.New("当查询为企业时,企业名称和企业标识统一代码注册号两者必填其一")) + } // 确定使用哪个值作为 name + if paramsDto.EntName != "" { + nameValue = paramsDto.EntName + } else { + nameValue = paramsDto.EntCode } - - } - - // 确定使用哪个值作为 name - if paramsDto.Type == "ent" && paramsDto.EntName != "" { - nameValue = paramsDto.EntName - } else { - nameValue = paramsDto.EntCode } fmt.Println("dto2s0w", paramsDto) - // 构建请求数据(不传的参数也需要添加,值为空字符串) reqData := map[string]interface{}{ "idCardNum": paramsDto.IDCard, diff --git a/internal/domains/user/repositories/user_repository_interface.go b/internal/domains/user/repositories/user_repository_interface.go index 3ebeaa8..8386ff6 100644 --- a/internal/domains/user/repositories/user_repository_interface.go +++ b/internal/domains/user/repositories/user_repository_interface.go @@ -54,6 +54,8 @@ type UserRepository interface { GetSystemUserStatsByDateRange(ctx context.Context, startDate, endDate time.Time) (*UserStats, error) GetSystemDailyUserStats(ctx context.Context, startDate, endDate time.Time) ([]map[string]interface{}, error) GetSystemMonthlyUserStats(ctx context.Context, startDate, endDate time.Time) ([]map[string]interface{}, error) + GetSystemDailyCertificationStats(ctx context.Context, startDate, endDate time.Time) ([]map[string]interface{}, error) + GetSystemMonthlyCertificationStats(ctx context.Context, startDate, endDate time.Time) ([]map[string]interface{}, error) // 排行榜查询方法 GetUserCallRankingByCalls(ctx context.Context, period string, limit int) ([]map[string]interface{}, error) diff --git a/internal/infrastructure/database/repositories/user/gorm_user_repository.go b/internal/infrastructure/database/repositories/user/gorm_user_repository.go index 2d85a89..dee6ea7 100644 --- a/internal/infrastructure/database/repositories/user/gorm_user_repository.go +++ b/internal/infrastructure/database/repositories/user/gorm_user_repository.go @@ -458,6 +458,54 @@ func (r *GormUserRepository) GetSystemMonthlyUserStats(ctx context.Context, star 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, + COUNT(*) as count + FROM users + WHERE is_certified = true + AND DATE(updated_at) >= $1 + AND DATE(updated_at) <= $2 + 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, + COUNT(*) as count + FROM users + WHERE is_certified = true + AND updated_at >= $1 + AND updated_at <= $2 + 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 +} + // GetUserCallRankingByCalls 按调用次数获取用户排行 func (r *GormUserRepository) GetUserCallRankingByCalls(ctx context.Context, period string, limit int) ([]map[string]interface{}, error) { var sql string