237 lines
9.1 KiB
Go
237 lines
9.1 KiB
Go
|
|
package responses
|
|||
|
|
|
|||
|
|
import (
|
|||
|
|
"time"
|
|||
|
|
|
|||
|
|
"hyapi-server/internal/domains/certification/entities/value_objects"
|
|||
|
|
"hyapi-server/internal/domains/certification/enums"
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
// CertificationResponse 认证响应
|
|||
|
|
type CertificationResponse struct {
|
|||
|
|
ID string `json:"id"`
|
|||
|
|
UserID string `json:"user_id"`
|
|||
|
|
Status enums.CertificationStatus `json:"status"`
|
|||
|
|
StatusName string `json:"status_name"`
|
|||
|
|
Progress int `json:"progress"`
|
|||
|
|
|
|||
|
|
// 企业信息
|
|||
|
|
EnterpriseInfo *value_objects.EnterpriseInfo `json:"enterprise_info,omitempty"`
|
|||
|
|
|
|||
|
|
// 合同信息
|
|||
|
|
ContractInfo *value_objects.ContractInfo `json:"contract_info,omitempty"`
|
|||
|
|
|
|||
|
|
// 时间戳
|
|||
|
|
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"`
|
|||
|
|
|
|||
|
|
// 业务状态
|
|||
|
|
IsCompleted bool `json:"is_completed"`
|
|||
|
|
IsFailed bool `json:"is_failed"`
|
|||
|
|
IsUserActionRequired bool `json:"is_user_action_required"`
|
|||
|
|
|
|||
|
|
// 失败信息
|
|||
|
|
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"`
|
|||
|
|
|
|||
|
|
// 用户操作提示
|
|||
|
|
NextAction string `json:"next_action,omitempty"`
|
|||
|
|
AvailableActions []string `json:"available_actions,omitempty"`
|
|||
|
|
|
|||
|
|
// 元数据
|
|||
|
|
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"`
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 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 {
|
|||
|
|
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"`
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// SystemMonitoringResponse 系统监控响应
|
|||
|
|
type SystemMonitoringResponse struct {
|
|||
|
|
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"`
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// SystemAlert 系统警告
|
|||
|
|
type SystemAlert struct {
|
|||
|
|
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"`
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// SystemHealthStatus 系统健康状态
|
|||
|
|
type SystemHealthStatus struct {
|
|||
|
|
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"`
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// AdminSubmitRecordItem 管理端提交记录列表项
|
|||
|
|
type AdminSubmitRecordItem struct {
|
|||
|
|
ID string `json:"id"`
|
|||
|
|
UserID string `json:"user_id"`
|
|||
|
|
CompanyName string `json:"company_name"`
|
|||
|
|
UnifiedSocialCode string `json:"unified_social_code"`
|
|||
|
|
LegalPersonName string `json:"legal_person_name"`
|
|||
|
|
SubmitAt time.Time `json:"submit_at"`
|
|||
|
|
Status string `json:"status"`
|
|||
|
|
CertificationStatus string `json:"certification_status,omitempty"` // 以状态机为准:info_pending_review/info_submitted/info_rejected 等
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// AdminSubmitRecordDetail 管理端提交记录详情(含完整信息与图片 URL)
|
|||
|
|
type AdminSubmitRecordDetail struct {
|
|||
|
|
ID string `json:"id"`
|
|||
|
|
UserID string `json:"user_id"`
|
|||
|
|
CompanyName string `json:"company_name"`
|
|||
|
|
UnifiedSocialCode string `json:"unified_social_code"`
|
|||
|
|
LegalPersonName string `json:"legal_person_name"`
|
|||
|
|
LegalPersonID string `json:"legal_person_id"`
|
|||
|
|
LegalPersonPhone string `json:"legal_person_phone"`
|
|||
|
|
EnterpriseAddress string `json:"enterprise_address"`
|
|||
|
|
AuthorizedRepName string `json:"authorized_rep_name"`
|
|||
|
|
AuthorizedRepID string `json:"authorized_rep_id"`
|
|||
|
|
AuthorizedRepPhone string `json:"authorized_rep_phone"`
|
|||
|
|
AuthorizedRepIDImageURLs string `json:"authorized_rep_id_image_urls"` // JSON 字符串或解析后数组
|
|||
|
|
BusinessLicenseImageURL string `json:"business_license_image_url"`
|
|||
|
|
OfficePlaceImageURLs string `json:"office_place_image_urls"` // JSON 数组字符串
|
|||
|
|
APIUsage string `json:"api_usage"`
|
|||
|
|
ScenarioAttachmentURLs string `json:"scenario_attachment_urls"`
|
|||
|
|
Status string `json:"status"`
|
|||
|
|
SubmitAt time.Time `json:"submit_at"`
|
|||
|
|
VerifiedAt *time.Time `json:"verified_at,omitempty"`
|
|||
|
|
FailedAt *time.Time `json:"failed_at,omitempty"`
|
|||
|
|
FailureReason string `json:"failure_reason,omitempty"`
|
|||
|
|
CertificationStatus string `json:"certification_status,omitempty"` // 以状态机为准
|
|||
|
|
CreatedAt time.Time `json:"created_at"`
|
|||
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// AdminSubmitRecordsListResponse 管理端提交记录列表响应
|
|||
|
|
type AdminSubmitRecordsListResponse struct {
|
|||
|
|
Items []*AdminSubmitRecordItem `json:"items"`
|
|||
|
|
Total int64 `json:"total"`
|
|||
|
|
Page int `json:"page"`
|
|||
|
|
PageSize int `json:"page_size"`
|
|||
|
|
TotalPages int `json:"total_pages"`
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// ================ 响应构建辅助方法 ================
|
|||
|
|
|
|||
|
|
// NewCertificationListResponse 创建认证列表响应
|
|||
|
|
func NewCertificationListResponse(items []*CertificationResponse, total int64, page, pageSize int) *CertificationListResponse {
|
|||
|
|
totalPages := int((total + int64(pageSize) - 1) / int64(pageSize))
|
|||
|
|
if totalPages == 0 {
|
|||
|
|
totalPages = 1
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
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,
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 设置过期时间(默认24小时)
|
|||
|
|
expireAt := time.Now().Add(24 * time.Hour)
|
|||
|
|
response.ExpireAt = &expireAt
|
|||
|
|
|
|||
|
|
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
|
|||
|
|
}
|