| 
									
										
										
										
											2025-07-13 16:36:20 +08:00
										 |  |  |  | package responses | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | import ( | 
					
						
							|  |  |  |  | 	"time" | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-21 15:13:26 +08:00
										 |  |  |  | 	"tyapi-server/internal/domains/certification/entities/value_objects" | 
					
						
							| 
									
										
										
										
											2025-07-13 16:36:20 +08:00
										 |  |  |  | 	"tyapi-server/internal/domains/certification/enums" | 
					
						
							|  |  |  |  | ) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | // CertificationResponse 认证响应 | 
					
						
							|  |  |  |  | type CertificationResponse struct { | 
					
						
							| 
									
										
										
										
											2025-07-28 01:46:39 +08:00
										 |  |  |  | 	ID         string                    `json:"id"` | 
					
						
							|  |  |  |  | 	UserID     string                    `json:"user_id"` | 
					
						
							|  |  |  |  | 	Status     enums.CertificationStatus `json:"status"` | 
					
						
							|  |  |  |  | 	StatusName string                    `json:"status_name"` | 
					
						
							|  |  |  |  | 	Progress   int                       `json:"progress"` | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-21 15:13:26 +08:00
										 |  |  |  | 	// 企业信息 | 
					
						
							| 
									
										
										
										
											2025-07-28 01:46:39 +08:00
										 |  |  |  | 	EnterpriseInfo *value_objects.EnterpriseInfo `json:"enterprise_info,omitempty"` | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-21 15:13:26 +08:00
										 |  |  |  | 	// 合同信息 | 
					
						
							| 
									
										
										
										
											2025-07-28 01:46:39 +08:00
										 |  |  |  | 	ContractInfo *value_objects.ContractInfo `json:"contract_info,omitempty"` | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-21 15:13:26 +08:00
										 |  |  |  | 	// 时间戳 | 
					
						
							| 
									
										
										
										
											2025-07-28 01:46:39 +08:00
										 |  |  |  | 	CreatedAt            time.Time  `json:"created_at"` | 
					
						
							|  |  |  |  | 	UpdatedAt            time.Time  `json:"updated_at"` | 
					
						
							|  |  |  |  | 	InfoSubmittedAt      *time.Time `json:"info_submitted_at,omitempty"` | 
					
						
							|  |  |  |  | 	EnterpriseVerifiedAt *time.Time `json:"enterprise_verified_at,omitempty"` | 
					
						
							|  |  |  |  | 	ContractAppliedAt    *time.Time `json:"contract_applied_at,omitempty"` | 
					
						
							|  |  |  |  | 	ContractSignedAt     *time.Time `json:"contract_signed_at,omitempty"` | 
					
						
							|  |  |  |  | 	CompletedAt          *time.Time `json:"completed_at,omitempty"` | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-21 15:13:26 +08:00
										 |  |  |  | 	// 业务状态 | 
					
						
							| 
									
										
										
										
											2025-07-28 01:46:39 +08:00
										 |  |  |  | 	IsCompleted          bool `json:"is_completed"` | 
					
						
							|  |  |  |  | 	IsFailed             bool `json:"is_failed"` | 
					
						
							|  |  |  |  | 	IsUserActionRequired bool `json:"is_user_action_required"` | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-21 15:13:26 +08:00
										 |  |  |  | 	// 失败信息 | 
					
						
							| 
									
										
										
										
											2025-07-28 01:46:39 +08:00
										 |  |  |  | 	FailureReason     enums.FailureReason `json:"failure_reason,omitempty"` | 
					
						
							|  |  |  |  | 	FailureReasonName string              `json:"failure_reason_name,omitempty"` | 
					
						
							|  |  |  |  | 	FailureMessage    string              `json:"failure_message,omitempty"` | 
					
						
							|  |  |  |  | 	CanRetry          bool                `json:"can_retry,omitempty"` | 
					
						
							|  |  |  |  | 	RetryCount        int                 `json:"retry_count,omitempty"` | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-21 15:13:26 +08:00
										 |  |  |  | 	// 用户操作提示 | 
					
						
							| 
									
										
										
										
											2025-07-28 01:46:39 +08:00
										 |  |  |  | 	NextAction       string   `json:"next_action,omitempty"` | 
					
						
							|  |  |  |  | 	AvailableActions []string `json:"available_actions,omitempty"` | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-21 15:13:26 +08:00
										 |  |  |  | 	// 元数据 | 
					
						
							| 
									
										
										
										
											2025-07-28 01:46:39 +08:00
										 |  |  |  | 	Metadata map[string]interface{} `json:"metadata,omitempty"` | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | // ConfirmAuthResponse 确认认证状态响应 | 
					
						
							|  |  |  |  | type ConfirmAuthResponse struct { | 
					
						
							|  |  |  |  | 	Status enums.CertificationStatus `json:"status"` | 
					
						
							|  |  |  |  | 	Reason string `json:"reason"` | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | // ConfirmSignResponse 确认签署状态响应 | 
					
						
							|  |  |  |  | type ConfirmSignResponse struct { | 
					
						
							|  |  |  |  | 	Status enums.CertificationStatus `json:"status"` | 
					
						
							|  |  |  |  | 	Reason string `json:"reason"` | 
					
						
							| 
									
										
										
										
											2025-07-21 15:13:26 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | // CertificationListResponse 认证列表响应 | 
					
						
							|  |  |  |  | type CertificationListResponse struct { | 
					
						
							|  |  |  |  | 	Items      []*CertificationResponse `json:"items"` | 
					
						
							|  |  |  |  | 	Total      int64                    `json:"total"` | 
					
						
							|  |  |  |  | 	Page       int                      `json:"page"` | 
					
						
							|  |  |  |  | 	PageSize   int                      `json:"page_size"` | 
					
						
							|  |  |  |  | 	TotalPages int                      `json:"total_pages"` | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | // ContractSignUrlResponse 合同签署URL响应 | 
					
						
							|  |  |  |  | type ContractSignUrlResponse struct { | 
					
						
							| 
									
										
										
										
											2025-07-28 01:46:39 +08:00
										 |  |  |  | 	CertificationID string     `json:"certification_id"` | 
					
						
							|  |  |  |  | 	ContractSignURL string     `json:"contract_sign_url"` | 
					
						
							|  |  |  |  | 	ContractURL     string     `json:"contract_url,omitempty"` | 
					
						
							|  |  |  |  | 	ExpireAt        *time.Time `json:"expire_at,omitempty"` | 
					
						
							|  |  |  |  | 	NextAction      string     `json:"next_action"` | 
					
						
							|  |  |  |  | 	Message         string     `json:"message"` | 
					
						
							| 
									
										
										
										
											2025-07-21 15:13:26 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | // SystemMonitoringResponse 系统监控响应 | 
					
						
							|  |  |  |  | type SystemMonitoringResponse struct { | 
					
						
							| 
									
										
										
										
											2025-07-28 01:46:39 +08:00
										 |  |  |  | 	TimeRange     string                 `json:"time_range"` | 
					
						
							|  |  |  |  | 	Metrics       map[string]interface{} `json:"metrics"` | 
					
						
							|  |  |  |  | 	Alerts        []SystemAlert          `json:"alerts,omitempty"` | 
					
						
							|  |  |  |  | 	SystemHealth  SystemHealthStatus     `json:"system_health"` | 
					
						
							|  |  |  |  | 	LastUpdatedAt time.Time              `json:"last_updated_at"` | 
					
						
							| 
									
										
										
										
											2025-07-21 15:13:26 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | // SystemAlert 系统警告 | 
					
						
							|  |  |  |  | type SystemAlert struct { | 
					
						
							| 
									
										
										
										
											2025-07-28 01:46:39 +08:00
										 |  |  |  | 	Level     string                 `json:"level"`     // info, warning, error, critical | 
					
						
							|  |  |  |  | 	Type      string                 `json:"type"`      // 警告类型 | 
					
						
							|  |  |  |  | 	Message   string                 `json:"message"`   // 警告消息 | 
					
						
							|  |  |  |  | 	Metric    string                 `json:"metric"`    // 相关指标 | 
					
						
							|  |  |  |  | 	Value     interface{}            `json:"value"`     // 当前值 | 
					
						
							|  |  |  |  | 	Threshold interface{}            `json:"threshold"` // 阈值 | 
					
						
							|  |  |  |  | 	CreatedAt time.Time              `json:"created_at"` | 
					
						
							|  |  |  |  | 	Metadata  map[string]interface{} `json:"metadata,omitempty"` | 
					
						
							| 
									
										
										
										
											2025-07-21 15:13:26 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | // SystemHealthStatus 系统健康状态 | 
					
						
							|  |  |  |  | type SystemHealthStatus struct { | 
					
						
							| 
									
										
										
										
											2025-07-28 01:46:39 +08:00
										 |  |  |  | 	Overall    string                 `json:"overall"`    // healthy, warning, critical | 
					
						
							|  |  |  |  | 	Components map[string]string      `json:"components"` // 各组件状态 | 
					
						
							|  |  |  |  | 	LastCheck  time.Time              `json:"last_check"` | 
					
						
							|  |  |  |  | 	Details    map[string]interface{} `json:"details,omitempty"` | 
					
						
							| 
									
										
										
										
											2025-07-21 15:13:26 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | // ================ 响应构建辅助方法 ================ | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | // NewCertificationListResponse 创建认证列表响应 | 
					
						
							|  |  |  |  | func NewCertificationListResponse(items []*CertificationResponse, total int64, page, pageSize int) *CertificationListResponse { | 
					
						
							|  |  |  |  | 	totalPages := int((total + int64(pageSize) - 1) / int64(pageSize)) | 
					
						
							|  |  |  |  | 	if totalPages == 0 { | 
					
						
							|  |  |  |  | 		totalPages = 1 | 
					
						
							|  |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2025-07-28 01:46:39 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-21 15:13:26 +08:00
										 |  |  |  | 	return &CertificationListResponse{ | 
					
						
							|  |  |  |  | 		Items:      items, | 
					
						
							|  |  |  |  | 		Total:      total, | 
					
						
							|  |  |  |  | 		Page:       page, | 
					
						
							|  |  |  |  | 		PageSize:   pageSize, | 
					
						
							|  |  |  |  | 		TotalPages: totalPages, | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | // NewContractSignUrlResponse 创建合同签署URL响应 | 
					
						
							|  |  |  |  | func NewContractSignUrlResponse(certificationID, signURL, contractURL, nextAction, message string) *ContractSignUrlResponse { | 
					
						
							|  |  |  |  | 	response := &ContractSignUrlResponse{ | 
					
						
							|  |  |  |  | 		CertificationID: certificationID, | 
					
						
							|  |  |  |  | 		ContractSignURL: signURL, | 
					
						
							|  |  |  |  | 		ContractURL:     contractURL, | 
					
						
							|  |  |  |  | 		NextAction:      nextAction, | 
					
						
							|  |  |  |  | 		Message:         message, | 
					
						
							|  |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2025-07-28 01:46:39 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-21 15:13:26 +08:00
										 |  |  |  | 	// 设置过期时间(默认24小时) | 
					
						
							|  |  |  |  | 	expireAt := time.Now().Add(24 * time.Hour) | 
					
						
							|  |  |  |  | 	response.ExpireAt = &expireAt | 
					
						
							| 
									
										
										
										
											2025-07-28 01:46:39 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-21 15:13:26 +08:00
										 |  |  |  | 	return response | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | // NewSystemAlert 创建系统警告 | 
					
						
							|  |  |  |  | func NewSystemAlert(level, alertType, message, metric string, value, threshold interface{}) *SystemAlert { | 
					
						
							|  |  |  |  | 	return &SystemAlert{ | 
					
						
							|  |  |  |  | 		Level:     level, | 
					
						
							|  |  |  |  | 		Type:      alertType, | 
					
						
							|  |  |  |  | 		Message:   message, | 
					
						
							|  |  |  |  | 		Metric:    metric, | 
					
						
							|  |  |  |  | 		Value:     value, | 
					
						
							|  |  |  |  | 		Threshold: threshold, | 
					
						
							|  |  |  |  | 		CreatedAt: time.Now(), | 
					
						
							|  |  |  |  | 		Metadata:  make(map[string]interface{}), | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | // IsHealthy 检查系统是否健康 | 
					
						
							|  |  |  |  | func (r *SystemMonitoringResponse) IsHealthy() bool { | 
					
						
							|  |  |  |  | 	return r.SystemHealth.Overall == "healthy" | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | // GetCriticalAlerts 获取严重警告 | 
					
						
							|  |  |  |  | func (r *SystemMonitoringResponse) GetCriticalAlerts() []*SystemAlert { | 
					
						
							|  |  |  |  | 	var criticalAlerts []*SystemAlert | 
					
						
							|  |  |  |  | 	for i := range r.Alerts { | 
					
						
							|  |  |  |  | 		if r.Alerts[i].Level == "critical" { | 
					
						
							|  |  |  |  | 			criticalAlerts = append(criticalAlerts, &r.Alerts[i]) | 
					
						
							|  |  |  |  | 		} | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 	return criticalAlerts | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | // HasAlerts 检查是否有警告 | 
					
						
							|  |  |  |  | func (r *SystemMonitoringResponse) HasAlerts() bool { | 
					
						
							|  |  |  |  | 	return len(r.Alerts) > 0 | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | // GetMetricValue 获取指标值 | 
					
						
							|  |  |  |  | func (r *SystemMonitoringResponse) GetMetricValue(metric string) (interface{}, bool) { | 
					
						
							|  |  |  |  | 	value, exists := r.Metrics[metric] | 
					
						
							|  |  |  |  | 	return value, exists | 
					
						
							| 
									
										
										
										
											2025-07-13 16:36:20 +08:00
										 |  |  |  | } |