195 lines
		
	
	
		
			7.0 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			195 lines
		
	
	
		
			7.0 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package queries
 | |
| 
 | |
| import (
 | |
| 	"time"
 | |
| 
 | |
| 	"tyapi-server/internal/domains/certification/enums"
 | |
| 	domainQueries "tyapi-server/internal/domains/certification/repositories/queries"
 | |
| )
 | |
| 
 | |
| // GetCertificationQuery 获取认证详情查询
 | |
| type GetCertificationQuery struct {
 | |
| 	UserID string `json:"user_id,omitempty"` // 用于权限验证
 | |
| }
 | |
| 
 | |
| // ConfirmAuthCommand 确认认证状态命令
 | |
| type ConfirmAuthCommand struct {
 | |
| 	UserID string `json:"-"`
 | |
| }
 | |
| 
 | |
| // ConfirmSignCommand 确认签署状态命令
 | |
| type ConfirmSignCommand struct {
 | |
| 	UserID string `json:"-"`
 | |
| }
 | |
| 
 | |
| // GetUserCertificationsQuery 获取用户认证列表查询
 | |
| type GetUserCertificationsQuery struct {
 | |
| 	UserID           string                    `json:"user_id" validate:"required"`
 | |
| 	Status           enums.CertificationStatus `json:"status,omitempty"`
 | |
| 	IncludeCompleted bool                      `json:"include_completed,omitempty"`
 | |
| 	IncludeFailed    bool                      `json:"include_failed,omitempty"`
 | |
| 	Page             int                       `json:"page"`
 | |
| 	PageSize         int                       `json:"page_size"`
 | |
| }
 | |
| 
 | |
| // ToDomainQuery 转换为领域查询对象
 | |
| func (q *GetUserCertificationsQuery) ToDomainQuery() *domainQueries.UserCertificationsQuery {
 | |
| 	domainQuery := &domainQueries.UserCertificationsQuery{
 | |
| 		UserID:           q.UserID,
 | |
| 		Status:           q.Status,
 | |
| 		IncludeCompleted: q.IncludeCompleted,
 | |
| 		IncludeFailed:    q.IncludeFailed,
 | |
| 		Page:             q.Page,
 | |
| 		PageSize:         q.PageSize,
 | |
| 	}
 | |
| 	domainQuery.DefaultValues()
 | |
| 	return domainQuery
 | |
| }
 | |
| 
 | |
| // ListCertificationsQuery 认证列表查询(管理员)
 | |
| type ListCertificationsQuery struct {
 | |
| 	Page            int                         `json:"page"`
 | |
| 	PageSize        int                         `json:"page_size"`
 | |
| 	SortBy          string                      `json:"sort_by"`
 | |
| 	SortOrder       string                      `json:"sort_order"`
 | |
| 	UserID          string                      `json:"user_id,omitempty"`
 | |
| 	Status          enums.CertificationStatus   `json:"status,omitempty"`
 | |
| 	Statuses        []enums.CertificationStatus `json:"statuses,omitempty"`
 | |
| 	FailureReason   enums.FailureReason         `json:"failure_reason,omitempty"`
 | |
| 	CreatedAfter    *time.Time                  `json:"created_after,omitempty"`
 | |
| 	CreatedBefore   *time.Time                  `json:"created_before,omitempty"`
 | |
| 	CompanyName     string                      `json:"company_name,omitempty"`
 | |
| 	LegalPersonName string                      `json:"legal_person_name,omitempty"`
 | |
| 	SearchKeyword   string                      `json:"search_keyword,omitempty"`
 | |
| }
 | |
| 
 | |
| // ToDomainQuery 转换为领域查询对象
 | |
| func (q *ListCertificationsQuery) ToDomainQuery() *domainQueries.ListCertificationsQuery {
 | |
| 	domainQuery := &domainQueries.ListCertificationsQuery{
 | |
| 		Page:            q.Page,
 | |
| 		PageSize:        q.PageSize,
 | |
| 		SortBy:          q.SortBy,
 | |
| 		SortOrder:       q.SortOrder,
 | |
| 		UserID:          q.UserID,
 | |
| 		Status:          q.Status,
 | |
| 		Statuses:        q.Statuses,
 | |
| 		FailureReason:   q.FailureReason,
 | |
| 		CreatedAfter:    q.CreatedAfter,
 | |
| 		CreatedBefore:   q.CreatedBefore,
 | |
| 		CompanyName:     q.CompanyName,
 | |
| 		LegalPersonName: q.LegalPersonName,
 | |
| 		SearchKeyword:   q.SearchKeyword,
 | |
| 	}
 | |
| 	domainQuery.DefaultValues()
 | |
| 	return domainQuery
 | |
| }
 | |
| 
 | |
| // SearchCertificationsQuery 搜索认证查询
 | |
| type SearchCertificationsQuery struct {
 | |
| 	Keyword      string                      `json:"keyword" validate:"required,min=2"`
 | |
| 	SearchFields []string                    `json:"search_fields,omitempty"`
 | |
| 	Statuses     []enums.CertificationStatus `json:"statuses,omitempty"`
 | |
| 	UserID       string                      `json:"user_id,omitempty"`
 | |
| 	Page         int                         `json:"page"`
 | |
| 	PageSize     int                         `json:"page_size"`
 | |
| 	SortBy       string                      `json:"sort_by"`
 | |
| 	SortOrder    string                      `json:"sort_order"`
 | |
| 	ExactMatch   bool                        `json:"exact_match,omitempty"`
 | |
| }
 | |
| 
 | |
| // ToDomainQuery 转换为领域查询对象
 | |
| func (q *SearchCertificationsQuery) ToDomainQuery() *domainQueries.SearchCertificationsQuery {
 | |
| 	domainQuery := &domainQueries.SearchCertificationsQuery{
 | |
| 		Keyword:      q.Keyword,
 | |
| 		SearchFields: q.SearchFields,
 | |
| 		Statuses:     q.Statuses,
 | |
| 		UserID:       q.UserID,
 | |
| 		Page:         q.Page,
 | |
| 		PageSize:     q.PageSize,
 | |
| 		SortBy:       q.SortBy,
 | |
| 		SortOrder:    q.SortOrder,
 | |
| 		ExactMatch:   q.ExactMatch,
 | |
| 	}
 | |
| 	domainQuery.DefaultValues()
 | |
| 	return domainQuery
 | |
| }
 | |
| 
 | |
| // GetCertificationStatisticsQuery 认证统计查询
 | |
| type GetCertificationStatisticsQuery struct {
 | |
| 	StartDate            time.Time                   `json:"start_date" validate:"required"`
 | |
| 	EndDate              time.Time                   `json:"end_date" validate:"required"`
 | |
| 	Period               string                      `json:"period" validate:"oneof=daily weekly monthly yearly"`
 | |
| 	GroupBy              []string                    `json:"group_by,omitempty"`
 | |
| 	UserIDs              []string                    `json:"user_ids,omitempty"`
 | |
| 	Statuses             []enums.CertificationStatus `json:"statuses,omitempty"`
 | |
| 	IncludeProgressStats bool                        `json:"include_progress_stats,omitempty"`
 | |
| 	IncludeRetryStats    bool                        `json:"include_retry_stats,omitempty"`
 | |
| 	IncludeTimeStats     bool                        `json:"include_time_stats,omitempty"`
 | |
| }
 | |
| 
 | |
| // ToDomainQuery 转换为领域查询对象
 | |
| func (q *GetCertificationStatisticsQuery) ToDomainQuery() *domainQueries.CertificationStatisticsQuery {
 | |
| 	return &domainQueries.CertificationStatisticsQuery{
 | |
| 		StartDate:            q.StartDate,
 | |
| 		EndDate:              q.EndDate,
 | |
| 		Period:               q.Period,
 | |
| 		GroupBy:              q.GroupBy,
 | |
| 		UserIDs:              q.UserIDs,
 | |
| 		Statuses:             q.Statuses,
 | |
| 		IncludeProgressStats: q.IncludeProgressStats,
 | |
| 		IncludeRetryStats:    q.IncludeRetryStats,
 | |
| 		IncludeTimeStats:     q.IncludeTimeStats,
 | |
| 	}
 | |
| }
 | |
| 
 | |
| // GetSystemMonitoringQuery 系统监控查询
 | |
| type GetSystemMonitoringQuery struct {
 | |
| 	TimeRange string   `json:"time_range" validate:"oneof=1h 6h 24h 7d 30d"`
 | |
| 	Metrics   []string `json:"metrics,omitempty"` // 指定要获取的指标类型
 | |
| }
 | |
| 
 | |
| // GetAvailableMetrics 获取可用的监控指标
 | |
| func (q *GetSystemMonitoringQuery) GetAvailableMetrics() []string {
 | |
| 	return []string{
 | |
| 		"certification_count",
 | |
| 		"success_rate",
 | |
| 		"failure_rate",
 | |
| 		"avg_processing_time",
 | |
| 		"status_distribution",
 | |
| 		"retry_count",
 | |
| 		"esign_callback_success_rate",
 | |
| 	}
 | |
| }
 | |
| 
 | |
| // GetTimeRangeDuration 获取时间范围对应的持续时间
 | |
| func (q *GetSystemMonitoringQuery) GetTimeRangeDuration() time.Duration {
 | |
| 	switch q.TimeRange {
 | |
| 	case "1h":
 | |
| 		return time.Hour
 | |
| 	case "6h":
 | |
| 		return 6 * time.Hour
 | |
| 	case "24h":
 | |
| 		return 24 * time.Hour
 | |
| 	case "7d":
 | |
| 		return 7 * 24 * time.Hour
 | |
| 	case "30d":
 | |
| 		return 30 * 24 * time.Hour
 | |
| 	default:
 | |
| 		return 24 * time.Hour // 默认24小时
 | |
| 	}
 | |
| }
 | |
| 
 | |
| // ShouldIncludeMetric 检查是否应该包含指定指标
 | |
| func (q *GetSystemMonitoringQuery) ShouldIncludeMetric(metric string) bool {
 | |
| 	if len(q.Metrics) == 0 {
 | |
| 		return true // 如果没有指定,包含所有指标
 | |
| 	}
 | |
| 
 | |
| 	for _, m := range q.Metrics {
 | |
| 		if m == metric {
 | |
| 			return true
 | |
| 		}
 | |
| 	}
 | |
| 	return false
 | |
| }
 |